}
static int parse_container_unix_address(sd_bus *b, const char **p, char **guid) {
- _cleanup_free_ char *machine = NULL;
+ _cleanup_free_ char *machine = NULL, *pid = NULL;
int r;
assert(b);
else if (r > 0)
continue;
+ r = parse_address_key(p, "pid", &pid);
+ if (r < 0)
+ return r;
+ else if (r > 0)
+ continue;
+
skip_address_key(p);
}
- if (!machine)
+ if (!machine == !pid)
return -EINVAL;
- if (!machine_name_is_valid(machine))
- return -EINVAL;
+ if (machine) {
+ if (!machine_name_is_valid(machine))
+ return -EINVAL;
- free(b->machine);
- b->machine = machine;
- machine = NULL;
+ free(b->machine);
+ b->machine = machine;
+ machine = NULL;
+ } else {
+ free(b->machine);
+ b->machine = NULL;
+ }
+
+ if (pid) {
+ r = parse_pid(pid, &b->nspid);
+ if (r < 0)
+ return r;
+ } else
+ b->nspid = 0;
b->sockaddr.un.sun_family = AF_UNIX;
strncpy(b->sockaddr.un.sun_path, "/var/run/dbus/system_bus_socket", sizeof(b->sockaddr.un.sun_path));
}
static int parse_container_kernel_address(sd_bus *b, const char **p, char **guid) {
- _cleanup_free_ char *machine = NULL;
+ _cleanup_free_ char *machine = NULL, *pid = NULL;
int r;
assert(b);
else if (r > 0)
continue;
+ r = parse_address_key(p, "pid", &pid);
+ if (r < 0)
+ return r;
+ else if (r > 0)
+ continue;
+
skip_address_key(p);
}
- if (!machine)
+ if (!machine == !pid)
return -EINVAL;
- if (!machine_name_is_valid(machine))
- return -EINVAL;
+ if (machine) {
+ if (!machine_name_is_valid(machine))
+ return -EINVAL;
- free(b->machine);
- b->machine = machine;
- machine = NULL;
+ free(b->machine);
+ b->machine = machine;
+ machine = NULL;
+ } else {
+ free(b->machine);
+ b->machine = NULL;
+ }
+
+ if (pid) {
+ r = parse_pid(pid, &b->nspid);
+ if (r < 0)
+ return r;
+ } else
+ b->nspid = 0;
free(b->kernel);
b->kernel = strdup("/sys/fs/kdbus/0-system/bus");
b->kernel = NULL;
free(b->machine);
b->machine = NULL;
+ b->nspid = 0;
}
static int bus_parse_next_address(sd_bus *b) {
return r;
break;
- } else if (startswith(a, "x-container-unix:")) {
+ } else if (startswith(a, "x-machine-unix:")) {
a += 17;
r = parse_container_unix_address(b, &a, &guid);
return r;
break;
- } else if (startswith(a, "x-container-kernel:")) {
+ } else if (startswith(a, "x-machine-kernel:")) {
a += 19;
r = parse_container_kernel_address(b, &a, &guid);
if (b->exec_path)
r = bus_socket_exec(b);
- else if (b->machine && b->kernel)
+ else if ((b->nspid > 0 || b->machine) && b->kernel)
r = bus_container_connect_kernel(b);
- else if (b->machine && b->sockaddr.sa.sa_family != AF_UNSPEC)
+ else if ((b->nspid > 0 || b->machine) && b->sockaddr.sa.sa_family != AF_UNSPEC)
r = bus_container_connect_socket(b);
else if (b->kernel)
r = bus_kernel_connect(b);
return r;
}
-int bus_set_address_system_container(sd_bus *b, const char *machine) {
+int bus_set_address_system_machine(sd_bus *b, const char *machine) {
_cleanup_free_ char *e = NULL;
assert(b);
return -ENOMEM;
#ifdef ENABLE_KDBUS
- b->address = strjoin("x-container-kernel:machine=", e, ";x-container-unix:machine=", e, NULL);
+ b->address = strjoin("x-machine-kernel:machine=", e, ";x-machine-unix:machine=", e, NULL);
#else
- b->address = strjoin("x-container-unix:machine=", e, NULL);
+ b->address = strjoin("x-machine-unix:machine=", e, NULL);
#endif
if (!b->address)
return -ENOMEM;
return 0;
}
-_public_ int sd_bus_open_system_container(sd_bus **ret, const char *machine) {
+_public_ int sd_bus_open_system_machine(sd_bus **ret, const char *machine) {
sd_bus *bus;
int r;
if (r < 0)
return r;
- r = bus_set_address_system_container(bus, machine);
+ r = bus_set_address_system_machine(bus, machine);
if (r < 0)
goto fail;