Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 1 | /* |
| 2 | * builtin-probe.c |
| 3 | * |
| 4 | * Builtin probe command: Set up probe events by C expression |
| 5 | * |
| 6 | * Written by Masami Hiramatsu <mhiramat@redhat.com> |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 21 | * |
| 22 | */ |
| 23 | #define _GNU_SOURCE |
| 24 | #include <sys/utsname.h> |
| 25 | #include <sys/types.h> |
| 26 | #include <sys/stat.h> |
| 27 | #include <fcntl.h> |
| 28 | #include <errno.h> |
| 29 | #include <stdio.h> |
| 30 | #include <unistd.h> |
| 31 | #include <stdlib.h> |
| 32 | #include <string.h> |
| 33 | |
| 34 | #undef _GNU_SOURCE |
| 35 | #include "perf.h" |
| 36 | #include "builtin.h" |
| 37 | #include "util/util.h" |
Masami Hiramatsu | 89c69c0 | 2009-10-16 20:08:10 -0400 | [diff] [blame] | 38 | #include "util/event.h" |
| 39 | #include "util/debug.h" |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 40 | #include "util/parse-options.h" |
| 41 | #include "util/parse-events.h" /* For debugfs_path */ |
| 42 | #include "util/probe-finder.h" |
| 43 | |
| 44 | /* Default vmlinux search paths */ |
| 45 | #define NR_SEARCH_PATH 3 |
| 46 | const char *default_search_path[NR_SEARCH_PATH] = { |
| 47 | "/lib/modules/%s/build/vmlinux", /* Custom build kernel */ |
| 48 | "/usr/lib/debug/lib/modules/%s/vmlinux", /* Red Hat debuginfo */ |
| 49 | "/boot/vmlinux-debug-%s", /* Ubuntu */ |
| 50 | }; |
| 51 | |
| 52 | #define MAX_PATH_LEN 256 |
| 53 | #define MAX_PROBES 128 |
Masami Hiramatsu | 074fc0e | 2009-10-16 20:08:01 -0400 | [diff] [blame] | 54 | #define MAX_PROBE_ARGS 128 |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 55 | |
| 56 | /* Session management structure */ |
| 57 | static struct { |
| 58 | char *vmlinux; |
| 59 | char *release; |
Masami Hiramatsu | 23e8ec0 | 2009-10-07 18:28:30 -0400 | [diff] [blame] | 60 | int need_dwarf; |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 61 | int nr_probe; |
| 62 | struct probe_point probes[MAX_PROBES]; |
| 63 | char *events[MAX_PROBES]; |
| 64 | } session; |
| 65 | |
Masami Hiramatsu | 074fc0e | 2009-10-16 20:08:01 -0400 | [diff] [blame] | 66 | #define semantic_error(msg ...) die("Semantic error :" msg) |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 67 | |
| 68 | static int parse_probepoint(const struct option *opt __used, |
| 69 | const char *str, int unset __used) |
| 70 | { |
| 71 | char *argv[MAX_PROBE_ARGS + 2]; /* Event + probe + args */ |
| 72 | int argc, i; |
| 73 | char *arg, *ptr; |
| 74 | struct probe_point *pp = &session.probes[session.nr_probe]; |
| 75 | char **event = &session.events[session.nr_probe]; |
| 76 | int retp = 0; |
| 77 | |
| 78 | if (!str) /* The end of probe points */ |
| 79 | return 0; |
| 80 | |
Arnaldo Carvalho de Melo | b7cb10e | 2009-10-21 17:34:06 -0200 | [diff] [blame^] | 81 | pr_debug("probe-definition(%d): %s\n", session.nr_probe, str); |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 82 | if (++session.nr_probe == MAX_PROBES) |
| 83 | semantic_error("Too many probes"); |
| 84 | |
| 85 | /* Separate arguments, similar to argv_split */ |
| 86 | argc = 0; |
| 87 | do { |
| 88 | /* Skip separators */ |
| 89 | while (isspace(*str)) |
| 90 | str++; |
| 91 | |
| 92 | /* Add an argument */ |
| 93 | if (*str != '\0') { |
| 94 | const char *s = str; |
| 95 | |
| 96 | /* Skip the argument */ |
| 97 | while (!isspace(*str) && *str != '\0') |
| 98 | str++; |
| 99 | |
| 100 | /* Duplicate the argument */ |
| 101 | argv[argc] = strndup(s, str - s); |
| 102 | if (argv[argc] == NULL) |
Masami Hiramatsu | 074fc0e | 2009-10-16 20:08:01 -0400 | [diff] [blame] | 103 | die("strndup"); |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 104 | if (++argc == MAX_PROBE_ARGS) |
| 105 | semantic_error("Too many arguments"); |
Arnaldo Carvalho de Melo | b7cb10e | 2009-10-21 17:34:06 -0200 | [diff] [blame^] | 106 | pr_debug("argv[%d]=%s\n", argc, argv[argc - 1]); |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 107 | } |
| 108 | } while (*str != '\0'); |
| 109 | if (argc < 2) |
| 110 | semantic_error("Need event-name and probe-point at least."); |
| 111 | |
| 112 | /* Parse the event name */ |
| 113 | if (argv[0][0] == 'r') |
| 114 | retp = 1; |
| 115 | else if (argv[0][0] != 'p') |
| 116 | semantic_error("You must specify 'p'(kprobe) or" |
| 117 | " 'r'(kretprobe) first."); |
| 118 | /* TODO: check event name */ |
| 119 | *event = argv[0]; |
| 120 | |
| 121 | /* Parse probe point */ |
| 122 | arg = argv[1]; |
| 123 | if (arg[0] == '@') { |
| 124 | /* Source Line */ |
| 125 | arg++; |
| 126 | ptr = strchr(arg, ':'); |
| 127 | if (!ptr || !isdigit(ptr[1])) |
| 128 | semantic_error("Line number is required."); |
| 129 | *ptr++ = '\0'; |
| 130 | if (strlen(arg) == 0) |
| 131 | semantic_error("No file name."); |
| 132 | pp->file = strdup(arg); |
| 133 | pp->line = atoi(ptr); |
| 134 | if (!pp->file || !pp->line) |
| 135 | semantic_error("Failed to parse line."); |
Arnaldo Carvalho de Melo | b7cb10e | 2009-10-21 17:34:06 -0200 | [diff] [blame^] | 136 | pr_debug("file:%s line:%d\n", pp->file, pp->line); |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 137 | } else { |
| 138 | /* Function name */ |
| 139 | ptr = strchr(arg, '+'); |
| 140 | if (ptr) { |
| 141 | if (!isdigit(ptr[1])) |
| 142 | semantic_error("Offset is required."); |
| 143 | *ptr++ = '\0'; |
| 144 | pp->offset = atoi(ptr); |
| 145 | } else |
| 146 | ptr = arg; |
| 147 | ptr = strchr(ptr, '@'); |
| 148 | if (ptr) { |
| 149 | *ptr++ = '\0'; |
| 150 | pp->file = strdup(ptr); |
| 151 | } |
| 152 | pp->function = strdup(arg); |
Arnaldo Carvalho de Melo | b7cb10e | 2009-10-21 17:34:06 -0200 | [diff] [blame^] | 153 | pr_debug("symbol:%s file:%s offset:%d\n", |
| 154 | pp->function, pp->file, pp->offset); |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 155 | } |
| 156 | free(argv[1]); |
Masami Hiramatsu | 23e8ec0 | 2009-10-07 18:28:30 -0400 | [diff] [blame] | 157 | if (pp->file) |
| 158 | session.need_dwarf = 1; |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 159 | |
| 160 | /* Copy arguments */ |
| 161 | pp->nr_args = argc - 2; |
| 162 | if (pp->nr_args > 0) { |
| 163 | pp->args = (char **)malloc(sizeof(char *) * pp->nr_args); |
| 164 | if (!pp->args) |
Masami Hiramatsu | 074fc0e | 2009-10-16 20:08:01 -0400 | [diff] [blame] | 165 | die("malloc"); |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 166 | memcpy(pp->args, &argv[2], sizeof(char *) * pp->nr_args); |
| 167 | } |
| 168 | |
| 169 | /* Ensure return probe has no C argument */ |
Masami Hiramatsu | 23e8ec0 | 2009-10-07 18:28:30 -0400 | [diff] [blame] | 170 | for (i = 0; i < pp->nr_args; i++) |
| 171 | if (is_c_varname(pp->args[i])) { |
| 172 | if (retp) |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 173 | semantic_error("You can't specify local" |
| 174 | " variable for kretprobe"); |
Masami Hiramatsu | 23e8ec0 | 2009-10-07 18:28:30 -0400 | [diff] [blame] | 175 | session.need_dwarf = 1; |
| 176 | } |
| 177 | |
Arnaldo Carvalho de Melo | b7cb10e | 2009-10-21 17:34:06 -0200 | [diff] [blame^] | 178 | pr_debug("%d arguments\n", pp->nr_args); |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 179 | return 0; |
| 180 | } |
| 181 | |
Masami Hiramatsu | 23e8ec0 | 2009-10-07 18:28:30 -0400 | [diff] [blame] | 182 | #ifndef NO_LIBDWARF |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 183 | static int open_default_vmlinux(void) |
| 184 | { |
| 185 | struct utsname uts; |
| 186 | char fname[MAX_PATH_LEN]; |
| 187 | int fd, ret, i; |
| 188 | |
| 189 | ret = uname(&uts); |
| 190 | if (ret) { |
Arnaldo Carvalho de Melo | b7cb10e | 2009-10-21 17:34:06 -0200 | [diff] [blame^] | 191 | pr_debug("uname() failed.\n"); |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 192 | return -errno; |
| 193 | } |
| 194 | session.release = uts.release; |
| 195 | for (i = 0; i < NR_SEARCH_PATH; i++) { |
| 196 | ret = snprintf(fname, MAX_PATH_LEN, |
| 197 | default_search_path[i], session.release); |
| 198 | if (ret >= MAX_PATH_LEN || ret < 0) { |
Arnaldo Carvalho de Melo | b7cb10e | 2009-10-21 17:34:06 -0200 | [diff] [blame^] | 199 | pr_debug("Filename(%d,%s) is too long.\n", i, |
Masami Hiramatsu | 89c69c0 | 2009-10-16 20:08:10 -0400 | [diff] [blame] | 200 | uts.release); |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 201 | errno = E2BIG; |
| 202 | return -E2BIG; |
| 203 | } |
Arnaldo Carvalho de Melo | b7cb10e | 2009-10-21 17:34:06 -0200 | [diff] [blame^] | 204 | pr_debug("try to open %s\n", fname); |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 205 | fd = open(fname, O_RDONLY); |
| 206 | if (fd >= 0) |
| 207 | break; |
| 208 | } |
| 209 | return fd; |
| 210 | } |
Masami Hiramatsu | 23e8ec0 | 2009-10-07 18:28:30 -0400 | [diff] [blame] | 211 | #endif |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 212 | |
| 213 | static const char * const probe_usage[] = { |
| 214 | "perf probe [<options>] -P 'PROBEDEF' [-P 'PROBEDEF' ...]", |
| 215 | NULL |
| 216 | }; |
| 217 | |
| 218 | static const struct option options[] = { |
Masami Hiramatsu | 89c69c0 | 2009-10-16 20:08:10 -0400 | [diff] [blame] | 219 | OPT_BOOLEAN('v', "verbose", &verbose, |
| 220 | "be more verbose (show parsed arguments, etc)"), |
Masami Hiramatsu | 23e8ec0 | 2009-10-07 18:28:30 -0400 | [diff] [blame] | 221 | #ifndef NO_LIBDWARF |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 222 | OPT_STRING('k', "vmlinux", &session.vmlinux, "file", |
| 223 | "vmlinux/module pathname"), |
Masami Hiramatsu | 23e8ec0 | 2009-10-07 18:28:30 -0400 | [diff] [blame] | 224 | #endif |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 225 | OPT_CALLBACK('P', "probe", NULL, |
Masami Hiramatsu | 23e8ec0 | 2009-10-07 18:28:30 -0400 | [diff] [blame] | 226 | #ifdef NO_LIBDWARF |
| 227 | "p|r:[GRP/]NAME FUNC[+OFFS] [ARG ...]", |
| 228 | #else |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 229 | "p|r:[GRP/]NAME FUNC[+OFFS][@SRC]|@SRC:LINE [ARG ...]", |
Masami Hiramatsu | 23e8ec0 | 2009-10-07 18:28:30 -0400 | [diff] [blame] | 230 | #endif |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 231 | "probe point definition, where\n" |
| 232 | "\t\tp:\tkprobe probe\n" |
| 233 | "\t\tr:\tkretprobe probe\n" |
| 234 | "\t\tGRP:\tGroup name (optional)\n" |
| 235 | "\t\tNAME:\tEvent name\n" |
| 236 | "\t\tFUNC:\tFunction name\n" |
| 237 | "\t\tOFFS:\tOffset from function entry (in byte)\n" |
Masami Hiramatsu | 23e8ec0 | 2009-10-07 18:28:30 -0400 | [diff] [blame] | 238 | #ifdef NO_LIBDWARF |
| 239 | "\t\tARG:\tProbe argument (only \n" |
| 240 | #else |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 241 | "\t\tSRC:\tSource code path\n" |
| 242 | "\t\tLINE:\tLine number\n" |
| 243 | "\t\tARG:\tProbe argument (local variable name or\n" |
Masami Hiramatsu | 23e8ec0 | 2009-10-07 18:28:30 -0400 | [diff] [blame] | 244 | #endif |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 245 | "\t\t\tkprobe-tracer argument format is supported.)\n", |
| 246 | parse_probepoint), |
| 247 | OPT_END() |
| 248 | }; |
| 249 | |
| 250 | static int write_new_event(int fd, const char *buf) |
| 251 | { |
| 252 | int ret; |
| 253 | |
| 254 | printf("Adding new event: %s\n", buf); |
| 255 | ret = write(fd, buf, strlen(buf)); |
| 256 | if (ret <= 0) |
Masami Hiramatsu | 074fc0e | 2009-10-16 20:08:01 -0400 | [diff] [blame] | 257 | die("failed to create event."); |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 258 | |
| 259 | return ret; |
| 260 | } |
| 261 | |
| 262 | #define MAX_CMDLEN 256 |
| 263 | |
| 264 | static int synthesize_probepoint(struct probe_point *pp) |
| 265 | { |
| 266 | char *buf; |
| 267 | int i, len, ret; |
| 268 | pp->probes[0] = buf = (char *)calloc(MAX_CMDLEN, sizeof(char)); |
| 269 | if (!buf) |
Masami Hiramatsu | 074fc0e | 2009-10-16 20:08:01 -0400 | [diff] [blame] | 270 | die("calloc"); |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 271 | ret = snprintf(buf, MAX_CMDLEN, "%s+%d", pp->function, pp->offset); |
| 272 | if (ret <= 0 || ret >= MAX_CMDLEN) |
| 273 | goto error; |
| 274 | len = ret; |
| 275 | |
| 276 | for (i = 0; i < pp->nr_args; i++) { |
| 277 | ret = snprintf(&buf[len], MAX_CMDLEN - len, " %s", |
| 278 | pp->args[i]); |
| 279 | if (ret <= 0 || ret >= MAX_CMDLEN - len) |
| 280 | goto error; |
| 281 | len += ret; |
| 282 | } |
| 283 | pp->found = 1; |
| 284 | return pp->found; |
| 285 | error: |
| 286 | free(pp->probes[0]); |
| 287 | if (ret > 0) |
| 288 | ret = -E2BIG; |
| 289 | return ret; |
| 290 | } |
| 291 | |
| 292 | int cmd_probe(int argc, const char **argv, const char *prefix __used) |
| 293 | { |
Masami Hiramatsu | 23e8ec0 | 2009-10-07 18:28:30 -0400 | [diff] [blame] | 294 | int i, j, fd, ret; |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 295 | struct probe_point *pp; |
| 296 | char buf[MAX_CMDLEN]; |
| 297 | |
| 298 | argc = parse_options(argc, argv, options, probe_usage, |
| 299 | PARSE_OPT_STOP_AT_NON_OPTION); |
| 300 | if (argc || session.nr_probe == 0) |
| 301 | usage_with_options(probe_usage, options); |
| 302 | |
Masami Hiramatsu | 23e8ec0 | 2009-10-07 18:28:30 -0400 | [diff] [blame] | 303 | #ifdef NO_LIBDWARF |
| 304 | if (session.need_dwarf) |
| 305 | semantic_error("Dwarf-analysis is not supported"); |
| 306 | #endif |
| 307 | |
| 308 | /* Synthesize probes without dwarf */ |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 309 | for (j = 0; j < session.nr_probe; j++) { |
Masami Hiramatsu | 23e8ec0 | 2009-10-07 18:28:30 -0400 | [diff] [blame] | 310 | #ifndef NO_LIBDWARF |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 311 | if (session.events[j][0] != 'r') { |
Masami Hiramatsu | 23e8ec0 | 2009-10-07 18:28:30 -0400 | [diff] [blame] | 312 | session.need_dwarf = 1; |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 313 | continue; |
| 314 | } |
Masami Hiramatsu | 23e8ec0 | 2009-10-07 18:28:30 -0400 | [diff] [blame] | 315 | #endif |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 316 | ret = synthesize_probepoint(&session.probes[j]); |
| 317 | if (ret == -E2BIG) |
| 318 | semantic_error("probe point is too long."); |
Masami Hiramatsu | 074fc0e | 2009-10-16 20:08:01 -0400 | [diff] [blame] | 319 | else if (ret < 0) |
| 320 | die("snprintf"); |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 321 | } |
| 322 | |
Masami Hiramatsu | 23e8ec0 | 2009-10-07 18:28:30 -0400 | [diff] [blame] | 323 | #ifndef NO_LIBDWARF |
| 324 | if (!session.need_dwarf) |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 325 | goto setup_probes; |
| 326 | |
| 327 | if (session.vmlinux) |
| 328 | fd = open(session.vmlinux, O_RDONLY); |
| 329 | else |
| 330 | fd = open_default_vmlinux(); |
Masami Hiramatsu | 074fc0e | 2009-10-16 20:08:01 -0400 | [diff] [blame] | 331 | if (fd < 0) |
| 332 | die("vmlinux/module file open"); |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 333 | |
| 334 | /* Searching probe points */ |
| 335 | for (j = 0; j < session.nr_probe; j++) { |
| 336 | pp = &session.probes[j]; |
| 337 | if (pp->found) |
| 338 | continue; |
| 339 | |
| 340 | lseek(fd, SEEK_SET, 0); |
| 341 | ret = find_probepoint(fd, pp); |
Masami Hiramatsu | 074fc0e | 2009-10-16 20:08:01 -0400 | [diff] [blame] | 342 | if (ret <= 0) |
| 343 | die("No probe point found.\n"); |
Arnaldo Carvalho de Melo | b7cb10e | 2009-10-21 17:34:06 -0200 | [diff] [blame^] | 344 | pr_debug("probe event %s found\n", session.events[j]); |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 345 | } |
| 346 | close(fd); |
| 347 | |
| 348 | setup_probes: |
Masami Hiramatsu | 23e8ec0 | 2009-10-07 18:28:30 -0400 | [diff] [blame] | 349 | #endif /* !NO_LIBDWARF */ |
| 350 | |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 351 | /* Settng up probe points */ |
| 352 | snprintf(buf, MAX_CMDLEN, "%s/../kprobe_events", debugfs_path); |
| 353 | fd = open(buf, O_WRONLY, O_APPEND); |
Masami Hiramatsu | 074fc0e | 2009-10-16 20:08:01 -0400 | [diff] [blame] | 354 | if (fd < 0) |
| 355 | die("kprobe_events open"); |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 356 | for (j = 0; j < session.nr_probe; j++) { |
| 357 | pp = &session.probes[j]; |
| 358 | if (pp->found == 1) { |
| 359 | snprintf(buf, MAX_CMDLEN, "%s %s\n", |
| 360 | session.events[j], pp->probes[0]); |
| 361 | write_new_event(fd, buf); |
| 362 | } else |
| 363 | for (i = 0; i < pp->found; i++) { |
| 364 | snprintf(buf, MAX_CMDLEN, "%s%d %s\n", |
| 365 | session.events[j], i, pp->probes[i]); |
| 366 | write_new_event(fd, buf); |
| 367 | } |
| 368 | } |
| 369 | close(fd); |
| 370 | return 0; |
| 371 | } |
| 372 | |