#include "bus-error.h"
#include "bus-locator.h"
#include "errno-util.h"
+#include "json-util.h"
#include "log.h"
+#include "pidref.h"
#include "process-util.h"
#include "socket-util.h"
#include "string-util.h"
const char *machine_name,
sd_id128_t uuid,
const char *service,
+ const PidRef *pidref,
const char *directory,
unsigned cid,
const char *address,
SD_BUS_MESSAGE_APPEND_ID128(uuid),
service,
"vm",
- (uint32_t) getpid_cached(),
+ (uint32_t) (pidref_is_set(pidref) ? pidref->pid : 0),
strempty(directory));
if (r < 0)
return log_error_errno(r, "Failed to register machine: %s", bus_error_message(&error, r));
SD_JSON_BUILD_PAIR_CONDITION(!!address, "sshAddress", SD_JSON_BUILD_STRING(address)),
SD_JSON_BUILD_PAIR_CONDITION(!!key_path, "sshPrivateKeyPath", SD_JSON_BUILD_STRING(key_path)),
SD_JSON_BUILD_PAIR_CONDITION(isatty_safe(STDIN_FILENO), "allowInteractiveAuthentication", SD_JSON_BUILD_BOOLEAN(true)),
- SD_JSON_BUILD_PAIR_CONDITION(!keep_unit, "allocateUnit", SD_JSON_BUILD_BOOLEAN(true)));
+ SD_JSON_BUILD_PAIR_CONDITION(!keep_unit, "allocateUnit", SD_JSON_BUILD_BOOLEAN(true)),
+ SD_JSON_BUILD_PAIR_CONDITION(pidref_is_set(pidref), "leaderProcessId", JSON_BUILD_PIDREF(pidref)));
}
int unregister_machine(sd_bus *bus, const char *machine_name) {
log_debug("Executing: %s", joined);
}
- if (arg_register) {
- char vm_address[STRLEN("vsock/") + DECIMAL_STR_MAX(unsigned)];
-
- xsprintf(vm_address, "vsock/%u", child_cid);
- r = register_machine(
- bus,
- arg_machine,
- arg_uuid,
- "systemd-vmspawn",
- arg_directory,
- child_cid,
- child_cid != VMADDR_CID_ANY ? vm_address : NULL,
- ssh_private_key_path,
- arg_keep_unit);
- if (r < 0)
- return r;
- }
-
assert_se(sigprocmask_many(SIG_BLOCK, /* ret_old_mask=*/ NULL, SIGCHLD) >= 0);
- _cleanup_(sd_event_source_unrefp) sd_event_source *notify_event_source = NULL;
- _cleanup_(sd_event_unrefp) sd_event *event = NULL;
- r = sd_event_new(&event);
- if (r < 0)
- return log_error_errno(r, "Failed to get default event source: %m");
-
- (void) sd_event_set_watchdog(event, true);
-
_cleanup_(pidref_done) PidRef child_pidref = PIDREF_NULL;
r = pidref_safe_fork_full(
child_vsock_fd = safe_close(child_vsock_fd);
tap_fd = safe_close(tap_fd);
+ if (arg_register) {
+ char vm_address[STRLEN("vsock/") + DECIMAL_STR_MAX(unsigned)];
+ xsprintf(vm_address, "vsock/%u", child_cid);
+ r = register_machine(
+ bus,
+ arg_machine,
+ arg_uuid,
+ "systemd-vmspawn",
+ &child_pidref,
+ arg_directory,
+ child_cid,
+ child_cid != VMADDR_CID_ANY ? vm_address : NULL,
+ ssh_private_key_path,
+ arg_keep_unit);
+ if (r < 0)
+ return r;
+ }
+
+ _cleanup_(sd_event_source_unrefp) sd_event_source *notify_event_source = NULL;
+ _cleanup_(sd_event_unrefp) sd_event *event = NULL;
+ r = sd_event_new(&event);
+ if (r < 0)
+ return log_error_errno(r, "Failed to get default event source: %m");
+
+ (void) sd_event_set_watchdog(event, true);
+
int exit_status = INT_MAX;
if (use_vsock) {
r = setup_notify_parent(event, notify_sock_fd, &exit_status, ¬ify_event_source);