#!/bin/sh
# Copyright (c) 2012-2013 National Instruments.
# All rights reserved.

permissions_string="a+w"
debugfs_path="/sys/kernel/debug"
tracefs_path="/sys/kernel/debug/tracing"

# If not mounted, mount the debugfs so we can use ftrace
grep -qs '/sys/kernel/debug' /proc/mounts || mount -t debugfs nodev $debugfs_path

# tracefs is created in a weird state; poke it to make it real
touch -c $tracefs_path/dummy

# Change the permissions so a non-root user can control ftrace
chmod a+rx $debugfs_path
chmod a+rx $tracefs_path
chmod -R $permissions_string $tracefs_path/events
chmod $permissions_string $tracefs_path/tracing_on
[ -e $tracefs_path/tracing_enabled ] && chmod $permissions_string $tracefs_path/tracing_enabled
chmod $permissions_string $tracefs_path/trace
chmod $permissions_string $tracefs_path/trace_marker
chmod $permissions_string $tracefs_path/trace_ni_ett_marker
chmod $permissions_string $tracefs_path/buffer_size_kb
