X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=src%2Fbin%2Flttng-sessiond%2Fmain.c;h=4ebd1e7d6c50d89da95aae89ff7e4d7b1ea77c59;hb=b51ec5b4b698a201dbd081ed5104591db44e38e9;hp=a117a1f1cfc8dd12cd02049455dbe82384825e04;hpb=e975f9f8a83cb33d228739ac3c3cebda10cb0598;p=lttng-tools.git diff --git a/src/bin/lttng-sessiond/main.c b/src/bin/lttng-sessiond/main.c index a117a1f1c..4ebd1e7d6 100644 --- a/src/bin/lttng-sessiond/main.c +++ b/src/bin/lttng-sessiond/main.c @@ -406,13 +406,13 @@ static void close_consumer_sockets(void) if (ustconsumer32_data.err_sock >= 0) { ret = close(ustconsumer32_data.err_sock); if (ret < 0) { - PERROR("UST consumer32 err_sock close"); + PERROR("UST consumerd32 err_sock close"); } } if (ustconsumer64_data.err_sock >= 0) { ret = close(ustconsumer64_data.err_sock); if (ret < 0) { - PERROR("UST consumer64 err_sock close"); + PERROR("UST consumerd64 err_sock close"); } } if (kconsumer_data.cmd_sock >= 0) { @@ -424,13 +424,13 @@ static void close_consumer_sockets(void) if (ustconsumer32_data.cmd_sock >= 0) { ret = close(ustconsumer32_data.cmd_sock); if (ret < 0) { - PERROR("UST consumer32 cmd_sock close"); + PERROR("UST consumerd32 cmd_sock close"); } } if (ustconsumer64_data.cmd_sock >= 0) { ret = close(ustconsumer64_data.cmd_sock); if (ret < 0) { - PERROR("UST consumer64 cmd_sock close"); + PERROR("UST consumerd64 cmd_sock close"); } } } @@ -446,7 +446,10 @@ static void cleanup(void) DBG("Cleaning up"); - /* First thing first, stop all threads */ + /* + * Close the thread quit pipe. It has already done its job, + * since we are now called. + */ utils_close_pipe(thread_quit_pipe); /* @@ -675,6 +678,8 @@ static int update_kernel_stream(struct consumer_data *consumer_data, int fd) if (ret < 0) { goto error; } + /* Update the stream global counter */ + ksess->stream_count_global += ret; /* * Have we already sent fds to the consumer? If yes, it means @@ -1149,12 +1154,14 @@ error: if (ret) { PERROR("close"); } + consumer_data->err_sock = -1; } if (consumer_data->cmd_sock >= 0) { ret = close(consumer_data->cmd_sock); if (ret) { PERROR("close"); } + consumer_data->cmd_sock = -1; } if (consumer_data->metadata_sock.fd >= 0) { ret = close(consumer_data->metadata_sock.fd); @@ -1291,11 +1298,17 @@ static void *thread_manage_apps(void *data) goto error; } - /* Set socket timeout for both receiving and ending */ + /* + * Set socket timeout for both receiving and ending. + * app_socket_timeout is in seconds, whereas + * lttcomm_setsockopt_rcv_timeout and + * lttcomm_setsockopt_snd_timeout expect msec as + * parameter. + */ (void) lttcomm_setsockopt_rcv_timeout(sock, - app_socket_timeout); + app_socket_timeout * 1000); (void) lttcomm_setsockopt_snd_timeout(sock, - app_socket_timeout); + app_socket_timeout * 1000); DBG("Apps with sock %d added to poll set", sock); @@ -2426,6 +2439,7 @@ static int create_ust_session(struct ltt_session *session, lus->uid = session->uid; lus->gid = session->gid; lus->output_traces = session->output_traces; + lus->snapshot_mode = session->snapshot_mode; session->ust_session = lus; /* Copy session output to the newly created UST session */ @@ -2483,6 +2497,7 @@ static int create_kernel_session(struct ltt_session *session) session->kernel_session->uid = session->uid; session->kernel_session->gid = session->gid; session->kernel_session->output_traces = session->output_traces; + session->kernel_session->snapshot_mode = session->snapshot_mode; return LTTNG_OK; @@ -2538,6 +2553,7 @@ static int process_client_msg(struct command_ctx *cmd_ctx, int sock, switch (cmd_ctx->lsm->cmd_type) { case LTTNG_CREATE_SESSION: + case LTTNG_CREATE_SESSION_SNAPSHOT: case LTTNG_DESTROY_SESSION: case LTTNG_LIST_SESSIONS: case LTTNG_LIST_DOMAINS: @@ -2600,6 +2616,7 @@ static int process_client_msg(struct command_ctx *cmd_ctx, int sock, /* Commands that DO NOT need a session. */ switch (cmd_ctx->lsm->cmd_type) { case LTTNG_CREATE_SESSION: + case LTTNG_CREATE_SESSION_SNAPSHOT: case LTTNG_CALIBRATE: case LTTNG_LIST_SESSIONS: case LTTNG_LIST_TRACEPOINTS: @@ -2693,6 +2710,10 @@ static int process_client_msg(struct command_ctx *cmd_ctx, int sock, break; case LTTNG_DOMAIN_UST: { + if (!ust_app_supported()) { + ret = LTTNG_ERR_NO_UST; + goto error; + } /* Consumer is in an ERROR state. Report back to client */ if (uatomic_read(&ust_consumerd_state) == CONSUMER_ERROR) { ret = LTTNG_ERR_NO_USTCONSUMERD; @@ -3291,6 +3312,45 @@ skip_domain: cmd_ctx->lsm->u.snapshot_record.wait); break; } + case LTTNG_CREATE_SESSION_SNAPSHOT: + { + size_t nb_uri, len; + struct lttng_uri *uris = NULL; + + nb_uri = cmd_ctx->lsm->u.uri.size; + len = nb_uri * sizeof(struct lttng_uri); + + if (nb_uri > 0) { + uris = zmalloc(len); + if (uris == NULL) { + ret = LTTNG_ERR_FATAL; + goto error; + } + + /* Receive variable len data */ + DBG("Waiting for %zu URIs from client ...", nb_uri); + ret = lttcomm_recv_unix_sock(sock, uris, len); + if (ret <= 0) { + DBG("No URIs received from client... continuing"); + *sock_error = 1; + ret = LTTNG_ERR_SESSION_FAIL; + free(uris); + goto error; + } + + if (nb_uri == 1 && uris[0].dtype != LTTNG_DST_PATH) { + DBG("Creating session with ONE network URI is a bad call"); + ret = LTTNG_ERR_SESSION_FAIL; + free(uris); + goto error; + } + } + + ret = cmd_create_session_snapshot(cmd_ctx->lsm->session.name, uris, + nb_uri, &cmd_ctx->creds); + free(uris); + break; + } default: ret = LTTNG_ERR_UND; break; @@ -4019,12 +4079,12 @@ static int set_permissions(char *rundir) ret = allowed_group(); if (ret < 0) { WARN("No tracing group detected"); - ret = 0; - goto end; + /* Setting gid to 0 if no tracing group is found */ + gid = 0; + } else { + gid = ret; } - gid = ret; - /* Set lttng run dir */ ret = chown(rundir, 0, gid); if (ret < 0) { @@ -4032,7 +4092,7 @@ static int set_permissions(char *rundir) PERROR("chown"); } - /* Ensure tracing group can search the run dir */ + /* Ensure all applications and tracing group can search the run dir */ ret = chmod(rundir, S_IRWXU | S_IXGRP | S_IXOTH); if (ret < 0) { ERR("Unable to set permissions on %s", rundir); @@ -4069,7 +4129,6 @@ static int set_permissions(char *rundir) DBG("All permissions are set"); -end: return ret; } @@ -4143,6 +4202,16 @@ static int set_consumer_sockets(struct consumer_data *consumer_data, goto error; } + /* + * Set the CLOEXEC flag. Return code is useless because either way, the + * show must go on. + */ + ret = utils_set_fd_cloexec(consumer_data->err_sock); + if (ret < 0) { + PERROR("utils_set_fd_cloexec"); + /* continue anyway */ + } + /* File permission MUST be 660 */ ret = chmod(consumer_data->err_unix_sock_path, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP); @@ -4571,6 +4640,9 @@ int main(int argc, char **argv) write_pidfile(); + /* Initialize communication library */ + lttcomm_init(); + /* Create thread to manage the client socket */ ret = pthread_create(&ht_cleanup_thread, NULL, thread_ht_cleanup, (void *) NULL);