10 #ifndef STAP_SCRIPT_FILENAME
11 #error "STAP_SCRIPT_FILENAME is required"
14 #define STRINGIFY1(lit) #lit
15 #define STRINGIFY(lit) STRINGIFY1 (lit)
16 #define _(x) gettext (x)
18 static int opt_d, opt_f, opt_q, opt_p;
20 /* Script filename. */
21 static char *opt_Z = STRINGIFY (STAP_SCRIPT_FILENAME);
26 void *retval = malloc (size);
29 error (EXIT_FAILURE, errno, _("memory allocation of %zu bytes"), size);
38 usage: staptrace [-dfq] [-o file] [-p pid] [command [arg ...]]\n\
48 dump_args (char **args)
52 for (argp = args; *argp; argp++)
56 fputs (*argp, stderr);
62 main (int argc, char **argv)
66 args = xmalloc (sizeof (*args) * argc * 2 + 32);
74 i = getopt (argc, argv, "+dfqo:p:hZ:");
84 error (EXIT_FAILURE, 0, _("-ff is unsupported"));
107 usage (EXIT_SUCCESS);
109 usage (EXIT_FAILURE);
113 if ((optind == argc) == !opt_p)
114 usage (EXIT_FAILURE);
120 static char kill_s[64];
121 static char opt_s[64];
127 error (EXIT_FAILURE, errno, _("Error calling fork"));
131 error (EXIT_FAILURE, errno, _("Error calling raise (SIGSTOP)"));
133 execvp (argv[optind], &argv[optind]);
134 error (EXIT_FAILURE, errno, "Error executing child command");
139 /* FIXME: Call `kill -CONT' from the systamtap script. How? */
140 i = sprintf (kill_s, "kill -CONT %lu; "
141 "while [ -e /proc/%lu/root ]; do sleep 0.1; done",
142 (unsigned long) child, (unsigned long) child);
144 error (EXIT_FAILURE, errno, _("Error calling sprintf"));
147 i = sprintf (opt_s, "opt_child=%lu", (unsigned long) child);
149 error (EXIT_FAILURE, errno, _("Error calling sprintf"));
158 execvp ("stap", args);
162 error (EXIT_FAILURE, errno, "Error executing stap");