#include "cgroup-util.h"
#include "dirent-util.h"
#include "dlfcn-util.h"
-#include "env-file.h"
#include "errno-util.h"
#include "escape.h"
#include "fd-util.h"
#include "fileio.h"
#include "fs-util.h"
-#include "hostname-util.h"
#include "io-util.h"
#include "iovec-util.h"
#include "locale-util.h"
#include "stdio-util.h"
#include "string-table.h"
#include "string-util.h"
+#include "strv.h"
#include "time-util.h"
#include "user-util.h"
return 0;
}
-int container_get_leader(const char *machine, pid_t *pid) {
- _cleanup_free_ char *s = NULL, *class = NULL;
- const char *p;
- pid_t leader;
- int r;
-
- assert(machine);
- assert(pid);
-
- if (streq(machine, ".host")) {
- *pid = 1;
- return 0;
- }
-
- if (!hostname_is_valid(machine, 0))
- return -EINVAL;
-
- p = strjoina("/run/systemd/machines/", machine);
- r = parse_env_file(NULL, p,
- "LEADER", &s,
- "CLASS", &class);
- if (r == -ENOENT)
- return -EHOSTDOWN;
- if (r < 0)
- return r;
- if (!s)
- return -EIO;
-
- if (!streq_ptr(class, "container"))
- return -EIO;
-
- r = parse_pid(s, &leader);
- if (r < 0)
- return r;
- if (leader <= 1)
- return -EIO;
-
- *pid = leader;
- return 0;
-}
-
int pid_is_kernel_thread(pid_t pid) {
int r;
int pidref_get_start_time(const PidRef *pid, usec_t *ret);
int get_process_umask(pid_t pid, mode_t *ret);
-int container_get_leader(const char *machine, pid_t *pid);
-
static inline bool SIGINFO_CODE_IS_DEAD(int code) {
return IN_SET(code, CLD_EXITED, CLD_KILLED, CLD_DUMPED);
}
#include "bus-container.h"
#include "bus-internal.h"
#include "bus-socket.h"
+#include "env-file.h"
#include "fd-util.h"
#include "format-util.h"
+#include "hostname-util.h"
#include "log.h"
#include "namespace-util.h"
+#include "parse-util.h"
+#include "path-lookup.h"
+#include "path-util.h"
#include "pidref.h"
#include "process-util.h"
#include "string-util.h"
+int container_get_leader(RuntimeScope scope, const char *machine, pid_t *ret) {
+ _cleanup_free_ char *p = NULL, *s = NULL, *class = NULL;
+ pid_t leader;
+ int r;
+
+ assert(machine);
+ assert(ret);
+
+ if (streq(machine, ".host")) {
+ if (scope == RUNTIME_SCOPE_USER)
+ return -EHOSTDOWN;
+
+ *ret = 1;
+ return 0;
+ }
+
+ if (!hostname_is_valid(machine, 0))
+ return -EINVAL;
+
+ r = runtime_directory_generic(scope, "systemd/machines", &p);
+ if (r < 0)
+ return r;
+
+ if (!path_extend(&p, machine))
+ return -ENOMEM;
+
+ r = parse_env_file(NULL, p,
+ "LEADER", &s,
+ "CLASS", &class);
+ if (r == -ENOENT)
+ return -EHOSTDOWN;
+ if (r < 0)
+ return r;
+ if (!s)
+ return -ESRCH;
+
+ if (!streq_ptr(class, "container"))
+ return -EMEDIUMTYPE;
+
+ r = parse_pid(s, &leader);
+ if (r < 0)
+ return r;
+ if (leader <= 1)
+ return -EBADMSG;
+
+ *ret = leader;
+ return 0;
+}
+
int bus_container_connect_socket(sd_bus *b) {
_cleanup_close_ int pidnsfd = -EBADF, mntnsfd = -EBADF, usernsfd = -EBADF, rootfd = -EBADF;
_cleanup_(pidref_done) PidRef child = PIDREF_NULL;
log_debug("sd-bus: connecting bus%s%s to machine %s...",
b->description ? " " : "", strempty(b->description), b->machine);
- r = container_get_leader(b->machine, &b->nspid);
+ r = container_get_leader(RUNTIME_SCOPE_USER, b->machine, &b->nspid);
+ if (IN_SET(r, -EHOSTDOWN, -ENXIO))
+ r = container_get_leader(RUNTIME_SCOPE_SYSTEM, b->machine, &b->nspid);
if (r < 0)
return r;
} else
#include <sys/socket.h>
#include <unistd.h>
+#include "bus-container.h"
#include "fd-util.h"
#include "fs-util.h"
#include "hash-funcs.h"
#include "namespace-util.h"
#include "pidref.h"
#include "process-util.h"
+#include "runtime-scope.h"
#include "sha256.h"
#include "siphash24.h"
#include "string-util.h"
if (isempty(machine))
return sd_id128_get_boot(ret);
- r = container_get_leader(machine, &pid);
+ r = container_get_leader(RUNTIME_SCOPE_SYSTEM, machine, &pid);
if (r < 0)
return r;