summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2014-03-19 22:46:45 +0100
committerLennart Poettering <lennart@poettering.net>2014-03-19 22:46:45 +0100
commit7181dbdb2e3112858d62bdaea4f0ad2ed685ccba (patch)
tree8a82b0e03b0d122eb7530b55405f79aa6f2838a3
parent907afa0682c8d6f00937b11b04be6b8a26a3cd41 (diff)
core: move notify sockets to /run and $XDG_RUNTIME_DIR
A service with PrivateNetwork= cannot access abstract namespace sockets of the host anymore, hence let's better not use abstract namespace sockets for this, since we want to make sure that PrivateNetwork= is useful and doesn't break sd_notify().
-rw-r--r--src/core/manager.c46
1 files changed, 25 insertions, 21 deletions
diff --git a/src/core/manager.c b/src/core/manager.c
index 632ce74ac2..fd22d4863b 100644
--- a/src/core/manager.c
+++ b/src/core/manager.c
@@ -84,9 +84,6 @@
#define JOBS_IN_PROGRESS_PERIOD_USEC (USEC_PER_SEC / 3)
#define JOBS_IN_PROGRESS_PERIOD_DIVISOR 3
-/* Where clients shall send notification messages to */
-#define NOTIFY_SOCKET "@/org/freedesktop/systemd1/notify"
-
#define TIME_T_MAX (time_t)((1UL << ((sizeof(time_t) << 3) - 1)) - 1)
static int manager_dispatch_notify_fd(sd_event_source *source, int fd, uint32_t revents, void *userdata);
@@ -505,16 +502,17 @@ fail:
}
static int manager_setup_notify(Manager *m) {
- union {
- struct sockaddr sa;
- struct sockaddr_un un;
- } sa = {
- .sa.sa_family = AF_UNIX,
- };
- int one = 1, r;
+ int r;
if (m->notify_fd < 0) {
_cleanup_close_ int fd = -1;
+ union {
+ struct sockaddr sa;
+ struct sockaddr_un un;
+ } sa = {
+ .sa.sa_family = AF_UNIX,
+ };
+ int one = 1;
/* First free all secondary fields */
free(m->notify_socket);
@@ -527,13 +525,24 @@ static int manager_setup_notify(Manager *m) {
return -errno;
}
- if (getpid() != 1 || detect_container(NULL) > 0)
- snprintf(sa.un.sun_path, sizeof(sa.un.sun_path), NOTIFY_SOCKET "/%" PRIx64, random_u64());
- else
- strncpy(sa.un.sun_path, NOTIFY_SOCKET, sizeof(sa.un.sun_path));
- sa.un.sun_path[0] = 0;
+ if (m->running_as == SYSTEMD_SYSTEM)
+ m->notify_socket = strdup("/run/systemd/notify");
+ else {
+ const char *e;
+
+ e = getenv("XDG_RUNTIME_DIR");
+ if (!e) {
+ log_error("XDG_RUNTIME_DIR is not set: %m");
+ return -EINVAL;
+ }
- r = bind(fd, &sa.sa, offsetof(struct sockaddr_un, sun_path) + 1 + strlen(sa.un.sun_path+1));
+ m->notify_socket = strappend(e, "/systemd/notify");
+ }
+ if (!m->notify_socket)
+ return log_oom();
+
+ strncpy(sa.un.sun_path, m->notify_socket, sizeof(sa.un.sun_path)-1);
+ r = bind(fd, &sa.sa, offsetof(struct sockaddr_un, sun_path) + strlen(sa.un.sun_path));
if (r < 0) {
log_error("bind() failed: %m");
return -errno;
@@ -545,11 +554,6 @@ static int manager_setup_notify(Manager *m) {
return -errno;
}
- sa.un.sun_path[0] = '@';
- m->notify_socket = strdup(sa.un.sun_path);
- if (!m->notify_socket)
- return log_oom();
-
m->notify_fd = fd;
fd = -1;