X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fcore%2Fsocket.c;h=05af8fe9d25e4bee0f4928843bdcf35fe291a0ee;hb=4e595329a93ed190795c2e24bf132d5028ec6a72;hp=7c18a2b75c17898676df6b6e7c79b33fe5bbabb6;hpb=6a0f1f6d5af7c7300d3db7a0ba2b068f8abd222b;p=elogind.git diff --git a/src/core/socket.c b/src/core/socket.c index 7c18a2b75..05af8fe9d 100644 --- a/src/core/socket.c +++ b/src/core/socket.c @@ -470,8 +470,8 @@ static void socket_dump(Unit *u, FILE *f, const char *prefix) { if (s->control_pid > 0) fprintf(f, - "%sControl PID: %lu\n", - prefix, (unsigned long) s->control_pid); + "%sControl PID: "PID_FMT"\n", + prefix, s->control_pid); if (s->bind_to_device) fprintf(f, @@ -663,16 +663,22 @@ static int instance_from_socket(int fd, unsigned nr, char **instance) { int k; k = getpeercred(fd, &ucred); - if (k < 0) + if (k >= 0) { + if (asprintf(&r, + "%u-"PID_FMT"-"UID_FMT, + nr, ucred.pid, ucred.uid) < 0) + return -ENOMEM; + } else if (k == -ENODATA) { + /* This handles the case where somebody is + * connecting from another pid/uid namespace + * (e.g. from outside of our container). */ + if (asprintf(&r, + "%u-unknown", + nr) < 0) + return -ENOMEM; + } else return k; - if (asprintf(&r, - "%u-%lu-%lu", - nr, - (unsigned long) ucred.pid, - (unsigned long) ucred.uid) < 0) - return -ENOMEM; - break; } @@ -1704,7 +1710,7 @@ static int socket_serialize(Unit *u, FILE *f, FDSet *fds) { unit_serialize_item_format(u, f, "n-accepted", "%u", s->n_accepted); if (s->control_pid > 0) - unit_serialize_item_format(u, f, "control-pid", "%lu", (unsigned long) s->control_pid); + unit_serialize_item_format(u, f, "control-pid", PID_FMT, s->control_pid); if (s->control_command_id >= 0) unit_serialize_item(u, f, "control-command", socket_exec_command_to_string(s->control_command_id));