X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=src%2Fbin%2Flttng-sessiond%2Fmain.c;h=57324820bd6aa2c3e09da7f3d0106c8f80c5b89d;hb=2a85be8e0e679da996b48252b1d9aebb9bb29126;hp=7f66a7271222d16b11dbb501ddf7dd5c0e291fb2;hpb=0d64e8fbee878b0de2c0bbe819d5e40790112a01;p=lttng-tools.git diff --git a/src/bin/lttng-sessiond/main.c b/src/bin/lttng-sessiond/main.c index 7f66a7271..57324820b 100644 --- a/src/bin/lttng-sessiond/main.c +++ b/src/bin/lttng-sessiond/main.c @@ -1023,7 +1023,11 @@ static int set_permissions(char *rundir) int ret; gid_t gid; - gid = utils_get_group_id(config.tracing_group_name.value); + ret = utils_get_group_id(config.tracing_group_name.value, true, &gid); + if (ret) { + /* Default to root group. */ + gid = 0; + } /* Set lttng run dir */ ret = chown(rundir, 0, gid); @@ -1134,7 +1138,16 @@ static int set_consumer_sockets(struct consumer_data *consumer_data) goto error; } if (is_root) { - ret = chown(path, 0, utils_get_group_id(config.tracing_group_name.value)); + gid_t gid; + + ret = utils_get_group_id(config.tracing_group_name.value, true, + &gid); + if (ret) { + /* Default to root group. */ + gid = 0; + } + + ret = chown(path, 0, gid); if (ret < 0) { ERR("Unable to set group on %s", path); PERROR("chown"); @@ -1336,6 +1349,26 @@ static void destroy_all_sessions_and_wait(void) DBG("Destruction of all sessions completed"); } +static int run_as_worker_post_fork_cleanup(void *data) +{ + struct sessiond_config *sessiond_config = data; + + sessiond_config_fini(sessiond_config); + return 0; +} + +static int launch_run_as_worker(const char *procname) +{ + /* + * Clean-up before forking the run-as worker. Any dynamically + * allocated memory of which the worker is not aware will + * be leaked as the process forks a run-as worker (and performs + * no exec*()). The same would apply to any opened fd. + */ + return run_as_create_worker(procname, run_as_worker_post_fork_cleanup, + &config); +} + /* * main */ @@ -1469,7 +1502,7 @@ int main(int argc, char **argv) } } - if (run_as_create_worker(argv[0]) < 0) { + if (launch_run_as_worker(argv[0]) < 0) { goto exit_create_run_as_worker_cleanup; } @@ -1626,12 +1659,6 @@ int main(int argc, char **argv) goto stop_threads; } - /* Set credentials to socket */ - if (is_root && set_permissions(config.rundir.value)) { - retval = -1; - goto stop_threads; - } - /* Get parent pid if -S, --sig-parent is specified. */ if (config.sig_parent) { ppid = getppid(); @@ -1741,6 +1768,12 @@ int main(int argc, char **argv) goto stop_threads; } + /* Set credentials of the client socket and rundir */ + if (is_root && set_permissions(config.rundir.value)) { + retval = -1; + goto stop_threads; + } + if (!launch_ust_dispatch_thread(&ust_cmd_queue, apps_cmd_pipe[1], apps_cmd_notify_pipe[1])) { retval = -1;