Fix comments and usage output
[lttng-tools.git] / src / bin / lttng / lttng.c
index e60b694e43729ab1c7ced011e11c2cae3a5e5433..5988c419d5febc17cf1856f66b6ced21b4d80ef5 100644 (file)
@@ -316,19 +316,20 @@ static int spawn_sessiond(char *pathname)
        } else if (pid > 0) {
                sessiond_pid = pid;
                /*
-                * Wait for lttng-sessiond to start. We need to use a
-                * flag to check if the signal has been sent to us,
-                * because the child can be scheduled before the parent,
-                * and thus send the signal before this check. In the
-                * signal handler, we set the recv_child_signal flag, so
-                * anytime we check it after the fork is fine. Note that
-                * sleep() is interrupted before the 1 second delay as
-                * soon as the signal is received, so it will not cause
-                * visible delay for the user.
+                * Wait for lttng-sessiond to start. We need to use a flag to check if
+                * the signal has been sent to us, because the child can be scheduled
+                * before the parent, and thus send the signal before this check. In
+                * the signal handler, we set the recv_child_signal flag, so anytime we
+                * check it after the fork is fine. Note that sleep() is interrupted
+                * before the 1 second delay as soon as the signal is received, so it
+                * will not cause visible delay for the user.
                 */
                while (!recv_child_signal) {
                        sleep(1);
                }
+               /*
+                * The signal handler will nullify sessiond_pid on SIGCHLD
+                */
                if (!sessiond_pid) {
                        exit(EXIT_FAILURE);
                }
@@ -361,7 +362,7 @@ static int check_sessiond(void)
                if (opt_sessiond_path != NULL) {
                        ret = access(opt_sessiond_path, F_OK | X_OK);
                        if (ret < 0) {
-                               ERR("No such file: %s", opt_sessiond_path);
+                               ERR("No such file or access denied: %s", opt_sessiond_path);
                                goto end;
                        }
                        pathname = opt_sessiond_path;
@@ -383,7 +384,7 @@ static int check_sessiond(void)
                ret = spawn_sessiond(pathname);
                free(alloc_pathname);
                if (ret < 0) {
-                       ERR("Problem occurs when starting %s", pathname);
+                       ERR("Problem occurred when starting %s", pathname);
                        goto end;
                }
        }
@@ -405,7 +406,8 @@ static int check_args_no_sessiond(int argc, char **argv)
        for (i = 0; i < argc; i++) {
                if ((strncmp(argv[i], "-h", sizeof("-h")) == 0) ||
                                strncmp(argv[i], "--h", sizeof("--h")) == 0 ||
-                               strncmp(argv[i], "--list-options", sizeof("--list-options")) == 0) {
+                               strncmp(argv[i], "--list-options", sizeof("--list-options")) == 0 ||
+                               strncmp(argv[i], "--list-commands", sizeof("--list-commands")) == 0) {
                        return 1;
                }
        }
@@ -414,10 +416,9 @@ static int check_args_no_sessiond(int argc, char **argv)
 }
 
 /*
- *  parse_args
+ * Parse command line arguments.
  *
- *  Parse command line arguments.
- *  Return 0 if OK, else -1
+ * Return 0 if OK, else -1
  */
 static int parse_args(int argc, char **argv)
 {
@@ -431,8 +432,8 @@ static int parse_args(int argc, char **argv)
        while ((opt = getopt_long(argc, argv, "+hnvqg:", long_options, NULL)) != -1) {
                switch (opt) {
                case 'h':
-                       usage(stderr);
-                       goto error;
+                       usage(stdout);
+                       goto end;
                case 'v':
                        opt_verbose += 1;
                        break;
@@ -451,11 +452,11 @@ static int parse_args(int argc, char **argv)
                case OPT_DUMP_OPTIONS:
                        list_options(stdout);
                        ret = 0;
-                       goto error;
+                       goto end;
                case OPT_DUMP_COMMANDS:
                        list_commands(stdout);
                        ret = 0;
-                       goto error;
+                       goto end;
                default:
                        usage(stderr);
                        goto error;
@@ -493,6 +494,7 @@ static int parse_args(int argc, char **argv)
                goto error;
        }
 
+end:
        return 0;
 
 error:
This page took 0.027628 seconds and 5 git commands to generate.