X-Git-Url: http://git.lttng.org/?a=blobdiff_plain;f=src%2Fbin%2Flttng-sessiond%2Fust-app.c;h=56860d714e3a6e5a605e75c56a1fb200037fd1bb;hb=3b9677124ab48bddc945ca67947c49b87b5853e0;hp=42a9b407ea78c7d42b134bc17af7346a89778bc5;hpb=d295668767ac8234e83984e1812d342d03293d88;p=lttng-tools.git diff --git a/src/bin/lttng-sessiond/ust-app.c b/src/bin/lttng-sessiond/ust-app.c index 42a9b407e..56860d714 100644 --- a/src/bin/lttng-sessiond/ust-app.c +++ b/src/bin/lttng-sessiond/ust-app.c @@ -250,7 +250,8 @@ static struct ust_registry_session *get_session_registry( case LTTNG_BUFFER_PER_UID: { struct buffer_reg_uid *reg_uid = buffer_reg_uid_find( - ua_sess->tracing_id, ua_sess->bits_per_long, ua_sess->uid); + ua_sess->tracing_id, ua_sess->bits_per_long, + ua_sess->real_credentials.uid); if (!reg_uid) { goto error; } @@ -1831,25 +1832,22 @@ static void shadow_copy_channel(struct ust_app_channel *ua_chan, static void shadow_copy_session(struct ust_app_session *ua_sess, struct ltt_ust_session *usess, struct ust_app *app) { - time_t rawtime; struct tm *timeinfo; char datetime[16]; int ret; char tmp_shm_path[PATH_MAX]; - /* Get date and time for unique app path */ - time(&rawtime); - timeinfo = localtime(&rawtime); + timeinfo = localtime(&app->registration_time); strftime(datetime, sizeof(datetime), "%Y%m%d-%H%M%S", timeinfo); DBG2("Shadow copy of session handle %d", ua_sess->handle); ua_sess->tracing_id = usess->id; ua_sess->id = get_next_session_id(); - ua_sess->uid = app->uid; - ua_sess->gid = app->gid; - ua_sess->euid = usess->uid; - ua_sess->egid = usess->gid; + ua_sess->real_credentials.uid = app->uid; + ua_sess->real_credentials.gid = app->gid; + ua_sess->effective_credentials.uid = usess->uid; + ua_sess->effective_credentials.gid = usess->gid; ua_sess->buffer_type = usess->buffer_type; ua_sess->bits_per_long = app->bits_per_long; @@ -1870,7 +1868,9 @@ static void shadow_copy_session(struct ust_app_session *ua_sess, break; case LTTNG_BUFFER_PER_UID: ret = snprintf(ua_sess->path, sizeof(ua_sess->path), - DEFAULT_UST_TRACE_UID_PATH, ua_sess->uid, app->bits_per_long); + DEFAULT_UST_TRACE_UID_PATH, + ua_sess->real_credentials.uid, + app->bits_per_long); break; default: assert(0); @@ -1990,10 +1990,10 @@ static int setup_buffer_reg_pid(struct ust_app_session *ua_sess, app->bits_per_long, app->uint8_t_alignment, app->uint16_t_alignment, app->uint32_t_alignment, app->uint64_t_alignment, app->long_alignment, - app->byte_order, app->version.major, - app->version.minor, reg_pid->root_shm_path, - reg_pid->shm_path, - ua_sess->euid, ua_sess->egid); + app->byte_order, app->version.major, app->version.minor, + reg_pid->root_shm_path, reg_pid->shm_path, + ua_sess->effective_credentials.uid, + ua_sess->effective_credentials.gid); if (ret < 0) { /* * reg_pid->registry->reg.ust is NULL upon error, so we need to @@ -2882,10 +2882,9 @@ static int create_channel_per_uid(struct ust_app *app, notification_ret = notification_thread_command_add_channel( notification_thread_handle, session->name, - ua_sess->euid, ua_sess->egid, - ua_chan->name, - ua_chan->key, - LTTNG_DOMAIN_UST, + ua_sess->effective_credentials.uid, + ua_sess->effective_credentials.gid, ua_chan->name, + ua_chan->key, LTTNG_DOMAIN_UST, ua_chan->attr.subbuf_size * ua_chan->attr.num_subbuf); if (notification_ret != LTTNG_OK) { ret = - (int) notification_ret; @@ -2983,10 +2982,9 @@ static int create_channel_per_pid(struct ust_app *app, cmd_ret = notification_thread_command_add_channel( notification_thread_handle, session->name, - ua_sess->euid, ua_sess->egid, - ua_chan->name, - ua_chan->key, - LTTNG_DOMAIN_UST, + ua_sess->effective_credentials.uid, + ua_sess->effective_credentials.gid, ua_chan->name, + ua_chan->key, LTTNG_DOMAIN_UST, ua_chan->attr.subbuf_size * ua_chan->attr.num_subbuf); if (cmd_ret != LTTNG_OK) { ret = - (int) cmd_ret; @@ -3376,6 +3374,8 @@ void ust_app_add(struct ust_app *app) assert(app); assert(app->notify_sock >= 0); + app->registration_time = time(NULL); + rcu_read_lock(); /* @@ -5876,14 +5876,13 @@ void ust_app_destroy(struct ust_app *app) */ enum lttng_error_code ust_app_snapshot_record( const struct ltt_ust_session *usess, - const struct snapshot_output *output, int wait, + const struct consumer_output *output, int wait, uint64_t nb_packets_per_stream) { int ret = 0; enum lttng_error_code status = LTTNG_OK; struct lttng_ht_iter iter; struct ust_app *app; - char pathname[PATH_MAX]; assert(usess); assert(output); @@ -5898,6 +5897,8 @@ enum lttng_error_code ust_app_snapshot_record( cds_list_for_each_entry(reg, &usess->buffer_reg_uid_list, lnode) { struct buffer_reg_channel *reg_chan; struct consumer_socket *socket; + char *trace_path = NULL; + char pathname[PATH_MAX]; if (!reg->registry->reg.ust->metadata_key) { /* Skip since no metadata is present */ @@ -5925,22 +5926,28 @@ enum lttng_error_code ust_app_snapshot_record( status = LTTNG_ERR_INVALID; goto error; } - + trace_path = setup_channel_trace_path(usess->consumer, pathname); + if (!trace_path) { + status = LTTNG_ERR_INVALID; + goto error; + } /* Add the UST default trace dir to path. */ cds_lfht_for_each_entry(reg->registry->channels->ht, &iter.iter, reg_chan, node.node) { status = consumer_snapshot_channel(socket, reg_chan->consumer_key, output, 0, usess->uid, - usess->gid, pathname, wait, + usess->gid, trace_path, wait, nb_packets_per_stream); if (status != LTTNG_OK) { + free(trace_path); goto error; } } status = consumer_snapshot_channel(socket, reg->registry->reg.ust->metadata_key, output, 1, - usess->uid, usess->gid, pathname, wait, 0); + usess->uid, usess->gid, trace_path, wait, 0); + free(trace_path); if (status != LTTNG_OK) { goto error; } @@ -5955,6 +5962,8 @@ enum lttng_error_code ust_app_snapshot_record( struct ust_app_channel *ua_chan; struct ust_app_session *ua_sess; struct ust_registry_session *registry; + char *trace_path = NULL; + char pathname[PATH_MAX]; ua_sess = lookup_session_by_app(usess, app); if (!ua_sess) { @@ -5964,7 +5973,7 @@ enum lttng_error_code ust_app_snapshot_record( /* Get the right consumer socket for the application. */ socket = consumer_find_socket_by_bitness(app->bits_per_long, - output->consumer); + output); if (!socket) { status = LTTNG_ERR_INVALID; goto error; @@ -5979,20 +5988,29 @@ enum lttng_error_code ust_app_snapshot_record( PERROR("snprintf snapshot path"); goto error; } - + trace_path = setup_channel_trace_path(usess->consumer, pathname); + if (!trace_path) { + status = LTTNG_ERR_INVALID; + goto error; + } cds_lfht_for_each_entry(ua_sess->channels->ht, &chan_iter.iter, ua_chan, node.node) { status = consumer_snapshot_channel(socket, - ua_chan->key, output, - 0, ua_sess->euid, ua_sess->egid, - pathname, wait, + ua_chan->key, output, 0, + ua_sess->effective_credentials + .uid, + ua_sess->effective_credentials + .gid, + trace_path, wait, nb_packets_per_stream); switch (status) { case LTTNG_OK: break; case LTTNG_ERR_CHAN_NOT_FOUND: + free(trace_path); continue; default: + free(trace_path); goto error; } } @@ -6003,9 +6021,11 @@ enum lttng_error_code ust_app_snapshot_record( continue; } status = consumer_snapshot_channel(socket, - registry->metadata_key, output, - 1, ua_sess->euid, ua_sess->egid, - pathname, wait, 0); + registry->metadata_key, output, 1, + ua_sess->effective_credentials.uid, + ua_sess->effective_credentials.gid, + trace_path, wait, 0); + free(trace_path); switch (status) { case LTTNG_OK: break; @@ -6352,8 +6372,12 @@ enum lttng_error_code ust_app_rotate_session(struct ltt_session *session) /* Rotate the data channels. */ cds_lfht_for_each_entry(ua_sess->channels->ht, &chan_iter.iter, ua_chan, node.node) { - ret = consumer_rotate_channel(socket, ua_chan->key, - ua_sess->euid, ua_sess->egid, + ret = consumer_rotate_channel(socket, + ua_chan->key, + ua_sess->effective_credentials + .uid, + ua_sess->effective_credentials + .gid, ua_sess->consumer, /* is_metadata_channel */ false); if (ret < 0) { @@ -6367,8 +6391,10 @@ enum lttng_error_code ust_app_rotate_session(struct ltt_session *session) /* Rotate the metadata channel. */ (void) push_metadata(registry, usess->consumer); - ret = consumer_rotate_channel(socket, registry->metadata_key, - ua_sess->euid, ua_sess->egid, + ret = consumer_rotate_channel(socket, + registry->metadata_key, + ua_sess->effective_credentials.uid, + ua_sess->effective_credentials.gid, ua_sess->consumer, /* is_metadata_channel */ true); if (ret < 0) {