X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=lttng-sessiond%2Fmain.c;h=227f0c2f7f41a0cac7325248d1f5072e6f07494d;hb=3ffdb6251a74cd118b910249bde37e7c355941aa;hp=dda9168bb48222c3f9b5081baaadc6f4eb8cc48b;hpb=f806231fd652854bdf797fe6b129953b946e32f1;p=lttng-tools.git diff --git a/lttng-sessiond/main.c b/lttng-sessiond/main.c index dda9168bb..227f0c2f7 100644 --- a/lttng-sessiond/main.c +++ b/lttng-sessiond/main.c @@ -94,6 +94,7 @@ static int opt_sig_parent; static int opt_daemon; static int is_root; /* Set to 1 if the daemon is running as root */ static pid_t ppid; /* Parent PID for --sig-parent option */ +static char *rundir; /* Consumer daemon specific control data */ static struct consumer_data kconsumer_data = { @@ -423,19 +424,18 @@ static void cleanup(void) DBG("Cleaning up"); - if (is_root) { - DBG("Removing %s directory", LTTNG_RUNDIR); - ret = asprintf(&cmd, "rm -rf " LTTNG_RUNDIR); - if (ret < 0) { - ERR("asprintf failed. Something is really wrong!"); - } + DBG("Removing %s directory", rundir); + ret = asprintf(&cmd, "rm -rf %s", rundir); + if (ret < 0) { + ERR("asprintf failed. Something is really wrong!"); + } - /* Remove lttng run directory */ - ret = system(cmd); - if (ret < 0) { - ERR("Unable to clean " LTTNG_RUNDIR); - } + /* Remove lttng run directory */ + ret = system(cmd); + if (ret < 0) { + ERR("Unable to clean %s", rundir); } + free(cmd); DBG("Cleaning up all session"); @@ -2205,29 +2205,20 @@ static int cmd_disable_channel(struct ltt_session *session, case LTTNG_DOMAIN_UST: { struct ltt_ust_channel *uchan; + struct cds_lfht *chan_ht; - /* Get channel in global UST domain HT */ - uchan = trace_ust_find_channel_by_name(usess->domain_global.channels, - channel_name); + chan_ht = usess->domain_global.channels; + + uchan = trace_ust_find_channel_by_name(chan_ht, channel_name); if (uchan == NULL) { ret = LTTCOMM_UST_CHAN_NOT_FOUND; goto error; } - /* Already disabled */ - if (!uchan->enabled) { - DBG2("UST channel %s already disabled", channel_name); - break; - } - - ret = ust_app_disable_channel_glb(usess, uchan); - if (ret < 0) { - ret = LTTCOMM_UST_DISABLE_FAIL; + ret = channel_ust_disable(usess, domain, uchan); + if (ret != LTTCOMM_OK) { goto error; } - - uchan->enabled = 0; - break; } case LTTNG_DOMAIN_UST_PID_FOLLOW_CHILDREN: @@ -2246,40 +2237,6 @@ error: return ret; } -/* - * Copy channel from attributes and set it in the application channel list. - */ -/* -static int copy_ust_channel_to_app(struct ltt_ust_session *usess, - struct lttng_channel *attr, struct ust_app *app) -{ - int ret; - struct ltt_ust_channel *uchan, *new_chan; - - uchan = trace_ust_get_channel_by_key(usess->channels, attr->name); - if (uchan == NULL) { - ret = LTTCOMM_FATAL; - goto error; - } - - new_chan = trace_ust_create_channel(attr, usess->path); - if (new_chan == NULL) { - PERROR("malloc ltt_ust_channel"); - ret = LTTCOMM_FATAL; - goto error; - } - - ret = channel_ust_copy(new_chan, uchan); - if (ret < 0) { - ret = LTTCOMM_FATAL; - goto error; - } - -error: - return ret; -} -*/ - /* * Command LTTNG_ENABLE_CHANNEL processed by the client thread. */ @@ -2288,6 +2245,7 @@ static int cmd_enable_channel(struct ltt_session *session, { int ret; struct ltt_ust_session *usess = session->ust_session; + struct cds_lfht *chan_ht; DBG("Enabling channel %s for session %s", attr->name, session->name); @@ -2316,49 +2274,14 @@ static int cmd_enable_channel(struct ltt_session *session, { struct ltt_ust_channel *uchan; - DBG2("Enabling channel for LTTNG_DOMAIN_UST"); + chan_ht = usess->domain_global.channels; - /* Get channel in global UST domain HT */ - uchan = trace_ust_find_channel_by_name(usess->domain_global.channels, - attr->name); + uchan = trace_ust_find_channel_by_name(chan_ht, attr->name); if (uchan == NULL) { - uchan = trace_ust_create_channel(attr, usess->pathname); - if (uchan == NULL) { - ret = LTTCOMM_UST_CHAN_FAIL; - goto error; - } - - /* Add channel to all registered applications */ - ret = ust_app_create_channel_glb(usess, uchan); - if (ret != 0) { - ret = LTTCOMM_UST_CHAN_FAIL; - goto error; - } - - rcu_read_lock(); - hashtable_add_unique(usess->domain_global.channels, &uchan->node); - rcu_read_unlock(); - - DBG2("UST channel %s added to global domain HT", attr->name); + ret = channel_ust_create(usess, domain, attr); } else { - /* If already enabled, everything is OK */ - if (uchan->enabled) { - break; - } - - ret = ust_app_enable_channel_glb(usess, uchan); - if (ret < 0) { - if (ret != -EEXIST) { - ret = LTTCOMM_UST_CHAN_ENABLE_FAIL; - goto error; - } else { - ret = LTTCOMM_OK; - } - } + ret = channel_ust_enable(usess, domain, uchan); } - - uchan->enabled = 1; - break; } case LTTNG_DOMAIN_UST_PID_FOLLOW_CHILDREN: @@ -2371,8 +2294,6 @@ static int cmd_enable_channel(struct ltt_session *session, goto error; } - ret = LTTCOMM_OK; - error: return ret; } @@ -2409,9 +2330,8 @@ static int cmd_disable_event(struct ltt_session *session, int domain, } case LTTNG_DOMAIN_UST: { - struct ltt_ust_session *usess; struct ltt_ust_channel *uchan; - struct ltt_ust_event *uevent; + struct ltt_ust_session *usess; usess = session->ust_session; @@ -2422,23 +2342,13 @@ static int cmd_disable_event(struct ltt_session *session, int domain, goto error; } - uevent = trace_ust_find_event_by_name(uchan->events, event_name); - if (uevent == NULL) { - ret = LTTCOMM_UST_EVENT_NOT_FOUND; - goto error; - } - - ret = ust_app_disable_event_glb(usess, uchan, uevent); - if (ret < 0) { - ret = LTTCOMM_UST_DISABLE_FAIL; + ret = event_ust_disable_tracepoint(usess, domain, uchan, event_name); + if (ret != LTTCOMM_OK) { goto error; } - uevent->enabled = 0; - - DBG2("Disable UST event %s in channel %s completed", event_name, + DBG3("Disable UST event %s in channel %s completed", event_name, channel_name); - break; } case LTTNG_DOMAIN_UST_EXEC_NAME: @@ -2499,13 +2409,12 @@ static int cmd_disable_event_all(struct ltt_session *session, int domain, goto error; } - ret = ust_app_disable_all_event_glb(usess, uchan); - if (ret < 0) { - ret = LTTCOMM_UST_DISABLE_FAIL; + ret = event_ust_disable_all_tracepoints(usess, domain, uchan); + if (ret != 0) { goto error; } - DBG2("Disable all UST event in channel %s completed", channel_name); + DBG3("Disable all UST events in channel %s completed", channel_name); break; } @@ -2641,8 +2550,7 @@ static int cmd_enable_event(struct ltt_session *session, int domain, snprintf(attr->name, NAME_MAX, "%s", channel_name); attr->name[NAME_MAX - 1] = '\0'; - /* Use the internal command enable channel */ - ret = cmd_enable_channel(session, domain, attr); + ret = channel_ust_create(usess, domain, attr); if (ret != LTTCOMM_OK) { free(attr); goto error; @@ -2763,7 +2671,7 @@ static int cmd_enable_event_all(struct ltt_session *session, int domain, attr->name[NAME_MAX - 1] = '\0'; /* Use the internal command enable channel */ - ret = cmd_enable_channel(session, domain, attr); + ret = channel_ust_create(usess, domain, attr); if (ret != LTTCOMM_OK) { free(attr); goto error; @@ -4088,14 +3996,16 @@ static int create_apps_cmd_pipe(void) /* * Create the lttng run directory needed for all global sockets and pipe. */ -static int create_lttng_rundir(void) +static int create_lttng_rundir(const char *rundir) { int ret; - ret = mkdir(LTTNG_RUNDIR, S_IRWXU | S_IRWXG ); + DBG3("Creating LTTng run directory: %s", rundir); + + ret = mkdir(rundir, S_IRWXU | S_IRWXG ); if (ret < 0) { if (errno != EEXIST) { - ERR("Unable to create " LTTNG_RUNDIR); + ERR("Unable to create %s", rundir); goto error; } else { ret = 0; @@ -4110,20 +4020,21 @@ error: * Setup sockets and directory needed by the kconsumerd communication with the * session daemon. */ -static int set_consumer_sockets(struct consumer_data *consumer_data) +static int set_consumer_sockets(struct consumer_data *consumer_data, + const char *rundir) { int ret; - const char *path; + char path[PATH_MAX]; - switch (consumer_data->type) { + switch (consumer_data->type) { case LTTNG_CONSUMER_KERNEL: - path = KCONSUMERD_PATH; + snprintf(path, PATH_MAX, KCONSUMERD_PATH, rundir); break; case LTTNG_CONSUMER64_UST: - path = USTCONSUMERD64_PATH; + snprintf(path, PATH_MAX, USTCONSUMERD64_PATH, rundir); break; case LTTNG_CONSUMER32_UST: - path = USTCONSUMERD32_PATH; + snprintf(path, PATH_MAX, USTCONSUMERD32_PATH, rundir); break; default: ERR("Consumer type unknown"); @@ -4131,6 +4042,8 @@ static int set_consumer_sockets(struct consumer_data *consumer_data) goto error; } + DBG2("Creating consumer directory: %s", path); + ret = mkdir(path, S_IRWXU | S_IRWXG); if (ret < 0) { if (errno != EEXIST) { @@ -4154,7 +4067,7 @@ static int set_consumer_sockets(struct consumer_data *consumer_data) S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP); if (ret < 0) { ERR("Set file permissions failed: %s", consumer_data->err_unix_sock_path); - perror("chmod"); + PERROR("chmod"); goto error; } @@ -4281,7 +4194,10 @@ int main(int argc, char **argv) is_root = !getuid(); if (is_root) { - ret = create_lttng_rundir(); + rundir = strdup(LTTNG_RUNDIR); + + /* Create global run dir with root access */ + ret = create_lttng_rundir(rundir); if (ret < 0) { goto error; } @@ -4301,6 +4217,17 @@ int main(int argc, char **argv) snprintf(wait_shm_path, PATH_MAX, DEFAULT_GLOBAL_APPS_WAIT_SHM_PATH); } + + /* Setup kernel consumerd path */ + snprintf(kconsumer_data.err_unix_sock_path, PATH_MAX, + KCONSUMERD_ERR_SOCK_PATH, rundir); + snprintf(kconsumer_data.cmd_unix_sock_path, PATH_MAX, + KCONSUMERD_CMD_SOCK_PATH, rundir); + + DBG2("Kernel consumer err path: %s", + kconsumer_data.err_unix_sock_path); + DBG2("Kernel consumer cmd path: %s", + kconsumer_data.cmd_unix_sock_path); } else { home_path = get_home_dir(); if (home_path == NULL) { @@ -4310,6 +4237,21 @@ int main(int argc, char **argv) goto error; } + /* + * Create rundir from home path. This will create something like + * $HOME/.lttng + */ + ret = asprintf(&rundir, LTTNG_HOME_RUNDIR, home_path); + if (ret < 0) { + ret = -ENOMEM; + goto error; + } + + ret = create_lttng_rundir(rundir); + if (ret < 0) { + goto error; + } + if (strlen(apps_unix_sock_path) == 0) { snprintf(apps_unix_sock_path, PATH_MAX, DEFAULT_HOME_APPS_UNIX_SOCK, home_path); @@ -4330,6 +4272,29 @@ int main(int argc, char **argv) DBG("Client socket path %s", client_unix_sock_path); DBG("Application socket path %s", apps_unix_sock_path); + DBG("LTTng run directory path: %s", rundir); + + /* 32 bits consumerd path setup */ + snprintf(ustconsumer32_data.err_unix_sock_path, PATH_MAX, + USTCONSUMERD32_ERR_SOCK_PATH, rundir); + snprintf(ustconsumer32_data.cmd_unix_sock_path, PATH_MAX, + USTCONSUMERD32_CMD_SOCK_PATH, rundir); + + DBG2("UST consumer 32 bits err path: %s", + ustconsumer32_data.err_unix_sock_path); + DBG2("UST consumer 32 bits cmd path: %s", + ustconsumer32_data.cmd_unix_sock_path); + + /* 64 bits consumerd path setup */ + snprintf(ustconsumer64_data.err_unix_sock_path, PATH_MAX, + USTCONSUMERD64_ERR_SOCK_PATH, rundir); + snprintf(ustconsumer64_data.cmd_unix_sock_path, PATH_MAX, + USTCONSUMERD64_CMD_SOCK_PATH, rundir); + + DBG2("UST consumer 64 bits err path: %s", + ustconsumer64_data.err_unix_sock_path); + DBG2("UST consumer 64 bits cmd path: %s", + ustconsumer64_data.cmd_unix_sock_path); /* * See if daemon already exist. @@ -4352,17 +4317,7 @@ int main(int argc, char **argv) * kernel tracer. */ if (is_root) { - ret = set_consumer_sockets(&kconsumer_data); - if (ret < 0) { - goto exit; - } - - ret = set_consumer_sockets(&ustconsumer64_data); - if (ret < 0) { - goto exit; - } - - ret = set_consumer_sockets(&ustconsumer32_data); + ret = set_consumer_sockets(&kconsumer_data, rundir); if (ret < 0) { goto exit; } @@ -4374,6 +4329,16 @@ int main(int argc, char **argv) set_ulimit(); } + ret = set_consumer_sockets(&ustconsumer64_data, rundir); + if (ret < 0) { + goto exit; + } + + ret = set_consumer_sockets(&ustconsumer32_data, rundir); + if (ret < 0) { + goto exit; + } + if ((ret = set_signal_handler()) < 0) { goto exit; } @@ -4507,8 +4472,9 @@ exit: cleanup(); rcu_thread_offline(); rcu_unregister_thread(); - if (!ret) + if (!ret) { exit(EXIT_SUCCESS); + } error: exit(EXIT_FAILURE); }