diff options
| author | Steven Rostedt <srostedt@redhat.com> | 2011-01-17 18:50:50 -0500 |
|---|---|---|
| committer | Steven Rostedt <rostedt@goodmis.org> | 2011-02-01 21:00:59 -0500 |
| commit | e941806a43c2eb46769959e44b3c54f332d4418b (patch) | |
| tree | bccb43e908ef42df53ab6dbfa906b8fcb1d43b57 | |
| parent | 495ceddac0cfbf4e859badd3619cb5d5bccbdb3d (diff) | |
trace-cmd: Null end the filter string
After reading the filter, make sure to zero out the end of
the filter string.
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
| -rw-r--r-- | trace-cmd.c | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/trace-cmd.c b/trace-cmd.c index e1341bf..9965428 100644 --- a/trace-cmd.c +++ b/trace-cmd.c | |||
| @@ -891,6 +891,11 @@ static void update_filter(const char *event_name, const char *field, | |||
| 891 | die("Can't read %s", path); | 891 | die("Can't read %s", path); |
| 892 | close(fd); | 892 | close(fd); |
| 893 | 893 | ||
| 894 | if (ret >= BUFSIZ) | ||
| 895 | ret = BUFSIZ - 1; | ||
| 896 | |||
| 897 | buf[ret] = 0; | ||
| 898 | |||
| 894 | /* append unless there is currently no filter */ | 899 | /* append unless there is currently no filter */ |
| 895 | if (strncmp(buf, "none", 4) == 0) { | 900 | if (strncmp(buf, "none", 4) == 0) { |
| 896 | filter = malloc_or_die(strlen(pid) + strlen(field) + | 901 | filter = malloc_or_die(strlen(pid) + strlen(field) + |
| @@ -902,14 +907,7 @@ static void update_filter(const char *event_name, const char *field, | |||
| 902 | sprintf(filter, "(%s)||(%s==%s)", buf, field, pid); | 907 | sprintf(filter, "(%s)||(%s==%s)", buf, field, pid); |
| 903 | } | 908 | } |
| 904 | 909 | ||
| 905 | fd = open(path, O_WRONLY); | 910 | write_filter(path, filter); |
| 906 | if (fd < 0) | ||
| 907 | die("can't open %s", path); | ||
| 908 | |||
| 909 | ret = write(fd, filter, strlen(filter)); | ||
| 910 | if (ret < 0) | ||
| 911 | warning("Can't write to %s", path); | ||
| 912 | close(fd); | ||
| 913 | 911 | ||
| 914 | free(filter); | 912 | free(filter); |
| 915 | 913 | ||
