X-Git-Url: http://git.lttng.org./?a=blobdiff_plain;f=ltt%2Fbranches%2Fpoly%2Flttd%2Flttd.c;h=02724ce5285f6d10bdedfff992510f2a6b0dd93b;hb=ce2b5176f95e595c37ca7c21d31b51865fa58a87;hp=ebd8a2d9270d17ee8848470d9675995a37424ae8;hpb=3357d3607442bf3047a4862d0368ea039bc2dba8;p=ltt-control.git diff --git a/ltt/branches/poly/lttd/lttd.c b/ltt/branches/poly/lttd/lttd.c index ebd8a2d..02724ce 100644 --- a/ltt/branches/poly/lttd/lttd.c +++ b/ltt/branches/poly/lttd/lttd.c @@ -10,6 +10,10 @@ * Mathieu Desnoyers */ +#ifdef HAVE_CONFIG_H +#include +#endif + #define _GNU_SOURCE #include #include @@ -71,6 +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 SIGUSR1 to parent when ready for IO. */ void show_arguments(void) { @@ -188,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; } } @@ -248,6 +254,8 @@ int open_channel_trace_pairs(char *subchannel_name, char *subtrace_name, open(path_channel, O_RDONLY | O_NONBLOCK); if(fd_pairs->pair[fd_pairs->num_pairs-1].channel == -1) { perror(path_channel); + fd_pairs->num_pairs--; + continue; } /* Open the trace in write mode, only append if append_mode */ ret = stat(path_trace, &stat_buf); @@ -264,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) { @@ -279,44 +288,49 @@ int open_channel_trace_pairs(char *subchannel_name, char *subtrace_name, } } +end: closedir(channel_dir); - return 0; + return open_ret; } int read_subbuffer(struct fd_pair *pair) { unsigned int subbuf_index; - int ret; + int err, ret; - ret = ioctl(pair->channel, RELAYFS_GET_SUBBUF, + err = ioctl(pair->channel, RELAYFS_GET_SUBBUF, &subbuf_index); - if(ret != 0) { + printf("index : %u\n", subbuf_index); + if(err != 0) { perror("Error in reserving sub buffer"); - goto error; + ret = -EPERM; + goto get_error; } - - ret = TEMP_FAILURE_RETRY(write(pair->trace, + + err = TEMP_FAILURE_RETRY(write(pair->trace, pair->mmap + (subbuf_index * pair->subbuf_size), pair->subbuf_size)); - - if(ret < 0) { + + if(err < 0) { perror("Error in writing to file"); - goto error; + ret = err; + goto write_error; } - ret = ioctl(pair->channel, RELAYFS_PUT_SUBBUF); - if(ret != 0) { +write_error: + err = ioctl(pair->channel, RELAYFS_PUT_SUBBUF); + if(err != 0) { perror("Error in unreserving sub buffer"); - goto error; + ret = -EPERM; + goto get_error; } - return 0; -error: - return -1; +get_error: + return ret; } @@ -344,6 +358,11 @@ int read_channels(struct channel_trace_fd *fd_pairs) int high_prio; int ret; + if(fd_pairs->num_pairs <= 0) { + printf("No channel to read\n"); + goto end; + } + /* Get the subbuf sizes and number */ for(i=0;inum_pairs;i++) { @@ -393,7 +412,7 @@ int read_channels(struct channel_trace_fd *fd_pairs) printf("Press a key for next poll...\n"); char buf[1]; read(STDIN_FILENO, &buf, 1); - printf("Next poll :\n"); + printf("Next poll (polling %d fd) :\n", fd_pairs->num_pairs); #endif //DEBUG /* Have we received a signal ? */ @@ -486,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; @@ -499,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;