mirror of
https://github.com/systemd/systemd-stable.git
synced 2025-01-12 09:17:44 +03:00
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
This commit is contained in:
parent
0565120f00
commit
00f8eea8fc
@ -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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user