X-Git-Url: http://git.lttng.org./?a=blobdiff_plain;f=ltt%2Fbranches%2Fpoly%2Flttd%2Flttd.c;h=02724ce5285f6d10bdedfff992510f2a6b0dd93b;hb=ce2b5176f95e595c37ca7c21d31b51865fa58a87;hp=63d483b6e67b9f7946818b4f0af98272761f323d;hpb=469206ed6916b3e84c0f7d5c6d8f01c19b31349c;p=ltt-control.git diff --git a/ltt/branches/poly/lttd/lttd.c b/ltt/branches/poly/lttd/lttd.c index 63d483b..02724ce 100644 --- a/ltt/branches/poly/lttd/lttd.c +++ b/ltt/branches/poly/lttd/lttd.c @@ -10,8 +10,11 @@ * Mathieu Desnoyers */ -#define _GNU_SOURCE +#ifdef HAVE_CONFIG_H #include +#endif + +#define _GNU_SOURCE #include #include #include @@ -64,7 +67,6 @@ static char *trace_name = NULL; static char *channel_name = NULL; static int daemon_mode = 0; static int append_mode = 0; -static int sig_parent = 0; volatile static int quit_program = 0; /* For signal handler */ /* Args : @@ -73,7 +75,7 @@ volatile static int quit_program = 0; /* For signal handler */ * -c directory Root directory of the relayfs trace channels. * -d Run in background (daemon). * -a Trace append mode. - * -s Send SIGIO to parent when ready for IO. + * -s Send SIGUSR1 to parent when ready for IO. */ void show_arguments(void) { @@ -84,7 +86,6 @@ void show_arguments(void) printf("-c directory Root directory of the relayfs trace channels.\n"); printf("-d Run in background (daemon).\n"); printf("-a Append to an possibly existing trace.\n"); - printf("-s Send SIGIO to parent when ready for IO.\n"); printf("\n"); } @@ -130,9 +131,6 @@ int parse_arguments(int argc, char **argv) case 'a': append_mode = 1; break; - case 's': - sig_parent = 1; - break; default: printf("Invalid argument '%s'.\n", argv[argn]); printf("\n"); @@ -195,20 +193,21 @@ int open_channel_trace_pairs(char *subchannel_name, char *subtrace_name, char path_trace[PATH_MAX]; int path_trace_len; char *path_trace_ptr; + int open_ret = 0; if(channel_dir == NULL) { perror(subchannel_name); - return ENOENT; + open_ret = ENOENT; + goto end; } printf("Creating trace subdirectory %s\n", subtrace_name); ret = mkdir(subtrace_name, S_IRWXU|S_IRWXG|S_IRWXO); if(ret == -1) { - if(errno == EEXIST && append_mode) { - printf("Appending to directory %s as resquested\n", subtrace_name); - } else { + if(errno != EEXIST) { perror(subtrace_name); - return -1; + open_ret = -1; + goto end; } } @@ -273,7 +272,8 @@ int open_channel_trace_pairs(char *subchannel_name, char *subtrace_name, } } else { printf("File %s exists, cannot open. Try append mode.\n", path_trace); - return -1; + open_ret = -1; + goto end; } } else { if(errno == ENOENT) { @@ -288,9 +288,10 @@ int open_channel_trace_pairs(char *subchannel_name, char *subtrace_name, } } +end: closedir(channel_dir); - return 0; + return open_ret; } @@ -404,9 +405,6 @@ int read_channels(struct channel_trace_fd *fd_pairs) pollfd[i].events = POLLIN|POLLPRI; } - /* Signal the parent that ready for IO */ - if(sig_parent) kill(getppid(), SIGIO); - while(1) { high_prio = 0; num_hup = 0; @@ -507,7 +505,6 @@ void close_channel_trace_pairs(struct channel_trace_fd *fd_pairs) int main(int argc, char ** argv) { int ret; - pid_t pid; struct channel_trace_fd fd_pairs = { NULL, 0 }; struct sigaction act; @@ -520,18 +517,13 @@ int main(int argc, char ** argv) show_info(); if(daemon_mode) { - pid = fork(); - - if(pid > 0) { - /* parent */ - return 0; - } else if(pid < 0) { - /* error */ - printf("An error occured while forking.\n"); - return -1; - } - /* else, we are the child, continue... */ - } + ret = daemon(0, 0); + + if(ret == -1) { + perror("An error occured while daemonizing."); + exit(-1); + } + } /* Connect the signal handlers */ act.sa_handler = handler;