X-Git-Url: http://git.lttng.org./?a=blobdiff_plain;f=ltt%2Fbranches%2Fpoly%2Flttctl%2Flttctl.c;h=5b8c262d862881bb7e66f7730707ed6d6f48d4c4;hb=63eeefc358a5e7d651a21c0f8fff160a0a2017a5;hp=19605c2e55888f86cf6cef78db4bce75058ff168;hpb=86a65fdbbfe799d8a31d1fcfa6774ce9366054d4;p=lttv.git diff --git a/ltt/branches/poly/lttctl/lttctl.c b/ltt/branches/poly/lttctl/lttctl.c index 19605c2e..5b8c262d 100644 --- a/ltt/branches/poly/lttctl/lttctl.c +++ b/ltt/branches/poly/lttctl/lttctl.c @@ -12,7 +12,7 @@ #include #endif -#include +#include #include #include #include @@ -43,6 +43,7 @@ static char *trace_name = NULL; static char *mode_name = NULL; static unsigned subbuf_size = 0; static unsigned n_subbufs = 0; +static unsigned append_trace = 0; static enum trace_mode mode = LTT_TRACE_NORMAL; static enum trace_ctl_op op = CTL_OP_NONE; static char *channel_root = NULL; @@ -83,6 +84,7 @@ void show_arguments(void) printf("-z Size of the subbuffers (will be rounded to next page size)\n"); printf("-x Number of subbuffers\n"); printf("-e Get XML facilities description\n"); + printf("-a Append to trace\n"); printf("\n"); } @@ -91,8 +93,8 @@ void show_arguments(void) * * Parses the command line arguments. * - * Returns 1 if the arguments were correct, but doesn't ask for program - * continuation. Returns -1 if the arguments are incorrect, or 0 if OK. + * Returns -1 if the arguments were correct, but doesn't ask for program + * continuation. Returns EINVAL if the arguments are incorrect, or 0 if OK. */ int parse_arguments(int argc, char **argv) { @@ -101,7 +103,7 @@ int parse_arguments(int argc, char **argv) if(argc == 2) { if(strcmp(argv[1], "-h") == 0) { - return 1; + return -1; } } @@ -115,9 +117,9 @@ int parse_arguments(int argc, char **argv) trace_name = argv[argn+1]; argn++; } else { - printf("Specify a trace name after -n.\n", argv[argn]); + printf("Specify a trace name after -n.\n"); printf("\n"); - ret = -1; + ret = EINVAL; } break; @@ -137,12 +139,12 @@ int parse_arguments(int argc, char **argv) else { printf("Invalid mode '%s'.\n", argv[argn]); printf("\n"); - ret = -1; + ret = EINVAL; } } else { printf("Specify a mode after -m.\n"); printf("\n"); - ret = -1; + ret = EINVAL; } break; case 'r': @@ -164,7 +166,7 @@ int parse_arguments(int argc, char **argv) } else { printf("Specify a number of subbuffers after -z.\n"); printf("\n"); - ret = -1; + ret = EINVAL; } break; case 'x': @@ -174,7 +176,7 @@ int parse_arguments(int argc, char **argv) } else { printf("Specify a subbuffer size after -x.\n"); printf("\n"); - ret = -1; + ret = EINVAL; } break; case 'd': @@ -190,7 +192,7 @@ int parse_arguments(int argc, char **argv) } else { printf("Specify a trace root path after -t.\n"); printf("\n"); - ret = -1; + ret = EINVAL; } break; case 'l': @@ -200,19 +202,22 @@ int parse_arguments(int argc, char **argv) } else { printf("Specify a channel root path after -l.\n"); printf("\n"); - ret = -1; + ret = EINVAL; } break; + case 'a': + append_trace = 1; + break; default: printf("Invalid argument '%s'.\n", argv[argn]); printf("\n"); - ret = -1; + ret = EINVAL; } break; default: printf("Invalid argument '%s'.\n", argv[argn]); printf("\n"); - ret = -1; + ret = EINVAL; } argn++; } @@ -220,25 +225,25 @@ int parse_arguments(int argc, char **argv) if(op != CTL_OP_DESCRIPTION && trace_name == NULL) { printf("Please specify a trace name.\n"); printf("\n"); - ret = -1; + ret = EINVAL; } if(op == CTL_OP_NONE) { printf("Please specify an operation.\n"); printf("\n"); - ret = -1; + ret = EINVAL; } if(op == CTL_OP_DAEMON) { if(trace_root == NULL) { printf("Please specify -t trace_root_path with the -d option.\n"); printf("\n"); - ret = -1; + ret = EINVAL; } if(channel_root == NULL) { printf("Please specify -l ltt_root_path with the -d option.\n"); printf("\n"); - ret = -1; + ret = EINVAL; } } @@ -246,7 +251,7 @@ int parse_arguments(int argc, char **argv) if(trace_root == NULL) { printf("Please specify -t trace_root_path with the -e option.\n"); printf("\n"); - ret = -1; + ret = EINVAL; } } @@ -277,6 +282,7 @@ int create_eventdefs(void) ret = mkdir(trace_root, S_IRWXU|S_IRWXG|S_IRWXO); if(ret == -1 && errno != EEXIST) { + ret = errno; perror("Cannot create trace_root directory"); printf("trace_root is %s\n", trace_root); goto error; @@ -288,7 +294,8 @@ int create_eventdefs(void) strncat(eventdefs_path, "/eventdefs/", PATH_MAX - trace_root_len); size_t eventdefs_path_len = strlen(eventdefs_path); ret = mkdir(eventdefs_path, S_IRWXU|S_IRWXG|S_IRWXO); - if(ret == -1 && errno != EEXIST) { + if(ret == -1 && (!append_trace || errno != EEXIST)) { + ret = errno; perror("Cannot create eventdefs directory"); goto error; } @@ -298,7 +305,7 @@ int create_eventdefs(void) if(facilities_dir == NULL) { perror("Cannot open facilities directory"); - ret = -1; + ret = EEXIST; goto error; } @@ -320,6 +327,7 @@ int create_eventdefs(void) strncat(facilities_file, entry->d_name, PATH_MAX - facilities_dir_len-1); FILE *src = fopen(facilities_file, "r"); if(!src) { + ret = errno; perror("Cannot open eventdefs file for reading"); goto close_dest; } @@ -328,11 +336,13 @@ int create_eventdefs(void) size_t read_size, write_size; read_size = fread(read_buf, sizeof(char), BUF_SIZE, src); if(ferror(src)) { + ret = errno; perror("Cannot read eventdefs file"); goto close_src; } write_size = fwrite(read_buf, sizeof(char), read_size, dest); if(ferror(dest)) { + ret = errno; perror("Cannot write eventdefs file"); goto close_src; } @@ -398,17 +408,21 @@ int lttctl_daemon(struct lttctl_handle *handle, char *trace_name) } else if(pid == 0) { /* child */ - - int ret = execlp(lttd_path, lttd_path, "-t", trace_root, "-c", - channel_path, "-d", NULL); + int ret; + if(append_trace) + ret = execlp(lttd_path, lttd_path, "-t", trace_root, "-c", + channel_path, "-d", "-a", NULL); + else + ret = execlp(lttd_path, lttd_path, "-t", trace_root, "-c", + channel_path, "-d", NULL); if(ret) { + ret = errno; perror("Error in executing the lttd daemon"); - exit(-1); + exit(ret); } } else { /* error */ perror("Error in forking for lttd daemon"); - } ret = lttctl_start(handle, trace_name); @@ -432,8 +446,8 @@ int main(int argc, char ** argv) ret = parse_arguments(argc, argv); if(ret != 0) show_arguments(); - if(ret < 0) return EINVAL; - if(ret > 0) return 0; + if(ret == EINVAL) return EINVAL; + if(ret == -1) return 0; show_info();