summaryrefslogtreecommitdiff
path: root/src/run
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2018-11-22 20:40:00 +0100
committerLennart Poettering <lennart@poettering.net>2018-11-23 12:49:00 +0100
commit00f8eea8fccbcc6d97171a13c776cd835a0b4580 (patch)
tree4cd91712d66a3615f3ce2acf0bed74c220f28356 /src/run
parent0565120f004f129bec67b9e92c805c6493b71fa2 (diff)
downloadsystemd-00f8eea8fccbcc6d97171a13c776cd835a0b4580.tar.gz
run: set $INVOCATION_ID for scope units
Services invoked by PID1 have $INVOCATION_ID initialized, hence let's do that for scope units (where the payload process is invoked by us on the client side) too, to minimize needless differences. Fixes: #8082
Diffstat (limited to 'src/run')
-rw-r--r--src/run/run.c58
1 files changed, 49 insertions, 9 deletions
diff --git a/src/run/run.c b/src/run/run.c
index daf9451c0b..0475156a43 100644
--- a/src/run/run.c
+++ b/src/run/run.c
@@ -1247,14 +1247,46 @@ static int start_transient_service(
return 0;
}
-static int start_transient_scope(sd_bus *bus) {
+static int acquire_invocation_id(sd_bus *bus, sd_id128_t *ret) {
+ _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
+ _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
+ const void *p;
+ size_t l;
+ int r;
+
+ assert(bus);
+ assert(ret);
+ r = sd_bus_get_property(bus,
+ "org.freedesktop.systemd1",
+ "/org/freedesktop/systemd1/unit/self",
+ "org.freedesktop.systemd1.Unit",
+ "InvocationID",
+ &error,
+ &reply,
+ "ay");
+ if (r < 0)
+ return log_error_errno(r, "Failed to request invocation ID for scope: %s", bus_error_message(&error, r));
+
+ r = sd_bus_message_read_array(reply, 'y', &p, &l);
+ if (r < 0)
+ return bus_log_parse_error(r);
+
+ if (l != sizeof(sd_id128_t))
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Invalid UUID size, %zu != %zu.", l, sizeof(sd_id128_t));
+
+ memcpy(ret, p, l);
+ return 0;
+}
+
+static int start_transient_scope(sd_bus *bus) {
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
_cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL, *reply = NULL;
_cleanup_(bus_wait_for_jobs_freep) BusWaitForJobs *w = NULL;
_cleanup_strv_free_ char **env = NULL, **user_env = NULL;
_cleanup_free_ char *scope = NULL;
const char *object = NULL;
+ sd_id128_t invocation_id;
int r;
assert(bus);
@@ -1317,6 +1349,22 @@ static int start_transient_scope(sd_bus *bus) {
if (r < 0)
return log_error_errno(r, "Failed to start transient scope unit: %s", bus_error_message(&error, -r));
+ r = sd_bus_message_read(reply, "o", &object);
+ if (r < 0)
+ return bus_log_parse_error(r);
+
+ r = bus_wait_for_jobs_one(w, object, arg_quiet);
+ if (r < 0)
+ return r;
+
+ r = acquire_invocation_id(bus, &invocation_id);
+ if (r < 0)
+ return r;
+
+ r = strv_extendf(&user_env, "INVOCATION_ID=" SD_ID128_FORMAT_STR, SD_ID128_FORMAT_VAL(invocation_id));
+ if (r < 0)
+ return log_oom();
+
if (arg_nice_set) {
if (setpriority(PRIO_PROCESS, 0, arg_nice) < 0)
return log_error_errno(errno, "Failed to set nice level: %m");
@@ -1375,14 +1423,6 @@ static int start_transient_scope(sd_bus *bus) {
if (!env)
return log_oom();
- r = sd_bus_message_read(reply, "o", &object);
- if (r < 0)
- return bus_log_parse_error(r);
-
- r = bus_wait_for_jobs_one(w, object, arg_quiet);
- if (r < 0)
- return r;
-
if (!arg_quiet)
log_info("Running scope as unit: %s", scope);