15 Process *list_of_processes = NULL;
17 int exiting = 0; /* =1 if a SIGINT or SIGTERM has been received */
20 signal_alarm(int sig) {
21 Process *tmp = list_of_processes;
23 signal(SIGALRM, SIG_DFL);
25 struct opt_p_t *tmp2 = opt_p;
27 if (tmp->pid == tmp2->pid) {
37 debug(2, "Sending SIGSTOP to process %u\n", tmp->pid);
38 kill(tmp->pid, SIGSTOP);
44 signal_exit(int sig) {
46 debug(1, "Received interrupt signal; exiting...");
47 signal(SIGINT, SIG_IGN);
48 signal(SIGTERM, SIG_IGN);
49 signal(SIGALRM, signal_alarm);
51 struct opt_p_t *tmp = opt_p;
53 debug(2, "Sending SIGSTOP to process %u\n", tmp->pid);
54 kill(tmp->pid, SIGSTOP);
64 if (options.summary) {
68 fclose(options.output);
69 options.output = NULL;
74 ltrace_init(int argc, char **argv) {
75 struct opt_p_t *opt_p_tmp;
78 signal(SIGINT, signal_exit); /* Detach processes when interrupted */
79 signal(SIGTERM, signal_exit); /* ... or killed */
81 argv = process_options(argc, argv);
83 /* If filename begins with ~, expand it to the user's home */
84 /* directory. This does not correctly handle ~yoda, but that */
85 /* isn't as bad as it seems because the shell will normally */
86 /* be doing the expansion for us; only the hardcoded */
87 /* ~/.ltrace.conf should ever use this code. */
88 if (opt_F->filename[0] == '~') {
90 char *home_dir = getenv("HOME");
92 strncpy(path, home_dir, PATH_MAX - 1);
93 path[PATH_MAX - 1] = '\0';
94 strncat(path, opt_F->filename + 1,
95 PATH_MAX - strlen(path) - 1);
96 read_config_file(path);
99 read_config_file(opt_F->filename);
104 struct opt_e_t *tmp = opt_e;
106 debug(1, "Option -e: %s\n", tmp->name);
111 execute_program(open_program(command, 0), argv);
115 open_pid(opt_p_tmp->pid);
116 opt_p_tmp = opt_p_tmp->next;
120 static int num_ltrace_callbacks[EVENT_MAX];
121 static callback_func * ltrace_callbacks[EVENT_MAX];
124 ltrace_add_callback(callback_func func, Event_type type) {
125 ltrace_callbacks[type] = realloc(ltrace_callbacks[type], (num_ltrace_callbacks[type]+1)*sizeof(callback_func));
126 ltrace_callbacks[type][num_ltrace_callbacks[type]++] = func;
130 dispatch_callbacks(Event * ev) {
132 /* Ignoring case 1: signal into a dying tracer */
133 if (ev->type==EVENT_SIGNAL &&
134 exiting && ev->e_un.signum == SIGSTOP) {
137 /* Ignoring case 2: process being born before a clone event */
138 if (ev->proc && ev->proc->state == STATE_IGNORED) {
141 for (i=0; i<num_ltrace_callbacks[ev->type]; i++) {
142 ltrace_callbacks[ev->type][i](ev);
151 dispatch_callbacks(ev);