X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=lttng-sessiond%2Fust-app.c;h=5976270604cd0ffd9e271a38c669bbbe8f956c6f;hb=d1f1c568e4e28b57156da4fce6b815a56166ecc6;hp=913d2de27acde8c3e276a488430def604f2a1842;hpb=fc34caaa25f9780eb8509f243f910c3f2aaa5a69;p=lttng-tools.git diff --git a/lttng-sessiond/ust-app.c b/lttng-sessiond/ust-app.c index 913d2de27..597627060 100644 --- a/lttng-sessiond/ust-app.c +++ b/lttng-sessiond/ust-app.c @@ -25,15 +25,14 @@ #include #include #include -#include #include #include #include #include -#include +#include "common/runas.h" #include "ust-app.h" #include "ust-consumer.h" #include "ust-ctl.h" @@ -1178,8 +1177,15 @@ static int create_ust_app_metadata(struct ust_app_session *ua_sess, ret = open_ust_metadata(app, ua_sess); if (ret < 0) { + DBG3("Opening metadata failed. Cleaning up memory"); + /* Cleanup failed metadata struct */ free(ua_sess->metadata); + /* + * This is very important because delete_ust_app_session check if + * the pointer is null or not in order to delete the metadata. + */ + ua_sess->metadata = NULL; goto error; } @@ -1193,7 +1199,7 @@ static int create_ust_app_metadata(struct ust_app_session *ua_sess, goto error; } - ret = mkdir_run_as(ua_sess->path, S_IRWXU | S_IRWXG, + ret = run_as_mkdir(ua_sess->path, S_IRWXU | S_IRWXG, ua_sess->uid, ua_sess->gid); if (ret < 0) { PERROR("mkdir UST metadata"); @@ -1959,6 +1965,11 @@ int ust_app_stop_trace(struct ltt_ust_session *usess, struct ust_app *app) goto error_rcu_unlock; } + /* Not started, continuing. */ + if (ua_sess->started == 0) { + goto end; + } + /* This inhibits UST tracing */ ret = ustctl_stop_session(app->key.sock, ua_sess->handle); if (ret < 0) { @@ -1974,9 +1985,8 @@ int ust_app_stop_trace(struct ltt_ust_session *usess, struct ust_app *app) node.node) { ret = ustctl_sock_flush_buffer(app->key.sock, ua_chan->obj); if (ret < 0) { - ERR("UST app PID %d channel %s flush failed", - app->key.pid, ua_chan->name); - ERR("Ended with ret %d", ret); + ERR("UST app PID %d channel %s flush failed with ret %d", + app->key.pid, ua_chan->name, ret); /* Continuing flushing all buffers */ continue; } @@ -1985,12 +1995,14 @@ int ust_app_stop_trace(struct ltt_ust_session *usess, struct ust_app *app) /* Flush all buffers before stopping */ ret = ustctl_sock_flush_buffer(app->key.sock, ua_sess->metadata->obj); if (ret < 0) { - ERR("UST app PID %d metadata flush failed", app->key.pid); - ERR("Ended with ret %d", ret); + ERR("UST app PID %d metadata flush failed with ret %d", app->key.pid, + ret); } - rcu_read_unlock(); + ua_sess->started = 0; +end: + rcu_read_unlock(); return 0; error_rcu_unlock: @@ -2022,13 +2034,14 @@ int ust_app_destroy_trace(struct ltt_ust_session *usess, struct ust_app *app) ua_sess = caa_container_of(node, struct ust_app_session, node); ret = lttng_ht_del(app->sessions, &iter); assert(!ret); - delete_ust_app_session(app->key.sock, ua_sess); obj.handle = ua_sess->handle; obj.shm_fd = -1; obj.wait_fd = -1; obj.memory_map_size = 0; ustctl_release_object(app->key.sock, &obj); + delete_ust_app_session(app->key.sock, ua_sess); + rcu_read_unlock(); /* Quiescent wait after stopping trace */