aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathan Lynch <ntl@pobox.com>2011-05-20 14:22:09 -0400
committerSteven Rostedt <rostedt@goodmis.org>2011-07-29 12:43:19 -0400
commitcfe801ca40be87a83ddba54dc0bffbd5b3ba840a (patch)
tree8ae4f819952c7878d339b9c268b423dfbaf2d2fa
parent5040a618353d685c4441b8e64b28d4d248a032d0 (diff)
trace-cmd: Close open fds on exec
trace-cmd's record mode allows child processes to inherit tracing-related file descriptors: $ trace-cmd record -esched: ls -l /proc/self/fd total 0 lrwx------. 1 root root 64 May 20 12:44 0 -> /dev/pts/11 lrwx------. 1 root root 64 May 20 12:44 1 -> /dev/pts/11 lrwx------. 1 root root 64 May 20 12:44 2 -> /dev/pts/11 lrwx------. 1 root root 64 May 20 12:44 3 -> /sys/kernel/debug/tracing/tracing_on l-wx------. 1 root root 64 May 20 12:44 4 -> /sys/kernel/debug/tracing/set_ftrace_pid l-wx------. 1 root root 64 May 20 12:44 5 -> /sys/kernel/debug/tracing/tracing_enabled lr-x------. 1 root root 64 May 20 12:44 6 -> /proc/31036/fd This can be problematic for applications (such as lxc) that interrogate their open file descriptors. Open these with O_CLOEXEC so they are not inherited. Signed-off-by: Nathan Lynch <ntl@pobox.com> Link: http://lkml.kernel.org/r/1305915732.2429.4.camel@orca.stoopid.dyndns.org Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
-rw-r--r--trace-record.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/trace-record.c b/trace-record.c
index 9b331ef..62758e8 100644
--- a/trace-record.c
+++ b/trace-record.c
@@ -343,7 +343,7 @@ static void update_ftrace_pid(const char *pid, int reset)
343 path = tracecmd_get_tracing_file("set_ftrace_pid"); 343 path = tracecmd_get_tracing_file("set_ftrace_pid");
344 if (!path) 344 if (!path)
345 return; 345 return;
346 fd = open(path, O_WRONLY | (reset ? O_TRUNC : 0)); 346 fd = open(path, O_WRONLY | O_CLOEXEC | (reset ? O_TRUNC : 0));
347 if (fd < 0) 347 if (fd < 0)
348 return; 348 return;
349 } 349 }
@@ -795,7 +795,7 @@ static void check_tracing_enabled(void)
795 795
796 if (fd < 0) { 796 if (fd < 0) {
797 path = tracecmd_get_tracing_file("tracing_enabled"); 797 path = tracecmd_get_tracing_file("tracing_enabled");
798 fd = open(path, O_WRONLY); 798 fd = open(path, O_WRONLY | O_CLOEXEC);
799 tracecmd_put_tracing_file(path); 799 tracecmd_put_tracing_file(path);
800 800
801 if (fd < 0) 801 if (fd < 0)
@@ -815,7 +815,7 @@ static int open_tracing_on(void)
815 return fd; 815 return fd;
816 816
817 path = tracecmd_get_tracing_file("tracing_on"); 817 path = tracecmd_get_tracing_file("tracing_on");
818 fd = open(path, O_RDWR); 818 fd = open(path, O_RDWR | O_CLOEXEC);
819 if (fd < 0) 819 if (fd < 0)
820 die("opening '%s'", path); 820 die("opening '%s'", path);
821 tracecmd_put_tracing_file(path); 821 tracecmd_put_tracing_file(path);