Add verbose option to session daemon
[lttng-tools.git] / ltt-sessiond / main.c
index 56266db3ce429bb6074bf34af85391ce6e7b865e..450a6ffc8c075c4f905fd465f6298c8add38a760 100644 (file)
@@ -322,6 +322,42 @@ error:
        return ret;
 }
 
+/*
+ *  ust_start_trace
+ *
+ *  Start a trace. This trace, identified by the pid, must be
+ *  in the current session ust_traces list.
+ */
+static int ust_start_trace(pid_t pid)
+{
+       int sock, ret;
+       struct ltt_ust_trace *trace;
+
+       DBG("Starting trace for pid %d", pid);
+
+       trace = find_session_ust_trace_by_pid(current_session, pid);
+       if (trace == NULL) {
+               ret = LTTCOMM_NO_TRACE;
+               goto error;
+       }
+
+       /* Connect to app using ustctl API */
+       sock = connect_app(pid);
+       if (sock < 0) {
+               ret = LTTCOMM_NO_TRACEABLE;
+               goto error;
+       }
+
+       ret = ustctl_start_trace(sock, "auto");
+       if (ret < 0) {
+               ret = LTTCOMM_START_FAIL;
+               goto error;
+       }
+
+error:
+       return ret;
+}
+
 /*
  *  copy_common_data
  *
@@ -453,7 +489,10 @@ static int process_client_msg(int sock, struct lttcomm_session_msg *lsm)
                {
                        ret = ust_create_trace(lsm->pid);
                        if (ret < 0) {
-                               ret = LTTCOMM_CREATE_FAIL;
+                               /* If -1 is returned from ust_create_trace, malloc
+                                * failed so it's pretty much a fatal error.
+                                */
+                               ret = LTTCOMM_FATAL;
                                goto end;
                        }
 
@@ -481,6 +520,13 @@ static int process_client_msg(int sock, struct lttcomm_session_msg *lsm)
 
                        break;
                }
+               case UST_START_TRACE:
+               {
+                       ret = ust_start_trace(lsm->pid);
+
+                       /* No auxiliary data so only send the llm struct. */
+                       goto end;
+               }
                case LTTNG_LIST_SESSIONS:
                {
                        unsigned int session_count = get_session_count();
@@ -541,6 +587,7 @@ static void usage(void)
        fprintf(stderr, "  -V, --version             Show version number.\n");
        fprintf(stderr, "  -S, --sig-parent          Send SIGCHLD to parent pid to notify readiness.\n");
        fprintf(stderr, "  -q, --quiet               No output at all.\n");
+       fprintf(stderr, "  -v, --verbose             Verbose mode. Activate DBG() macro.\n");
 }
 
 /*
@@ -559,12 +606,13 @@ static int parse_args(int argc, char **argv)
                { "group", 1, 0, 'g' },
                { "version", 0, 0, 'V' },
                { "quiet", 0, 0, 'q' },
+               { "verbose", 0, 0, 'v' },
                { NULL, 0, 0, 0 }
        };
 
        while (1) {
                int option_index = 0;
-               c = getopt_long(argc, argv, "dhqVS" "a:c:g:s:", long_options, &option_index);
+               c = getopt_long(argc, argv, "dhqvVS" "a:c:g:s:", long_options, &option_index);
                if (c == -1) {
                        break;
                }
@@ -600,6 +648,9 @@ static int parse_args(int argc, char **argv)
                case 'q':
                        opt_quiet = 1;
                        break;
+               case 'v':
+                       opt_verbose = 1;
+                       break;
                default:
                        /* Unknown option or other error.
                         * Error is printed by getopt, just return */
This page took 0.023915 seconds and 4 git commands to generate.