execute: make some code shorter

Let's simplify some lines to make it shorter.
This commit is contained in:
Lennart Poettering 2017-07-14 18:58:57 +02:00
parent 54191eb3e7
commit 92a17af991

View file

@ -278,7 +278,7 @@ static int open_null_as(int flags, int nfd) {
} }
static int connect_journal_socket(int fd, uid_t uid, gid_t gid) { static int connect_journal_socket(int fd, uid_t uid, gid_t gid) {
union sockaddr_union sa = { static const union sockaddr_union sa = {
.un.sun_family = AF_UNIX, .un.sun_family = AF_UNIX,
.un.sun_path = "/run/systemd/journal/stdout", .un.sun_path = "/run/systemd/journal/stdout",
}; };
@ -289,24 +289,20 @@ static int connect_journal_socket(int fd, uid_t uid, gid_t gid) {
if (gid_is_valid(gid)) { if (gid_is_valid(gid)) {
oldgid = getgid(); oldgid = getgid();
r = setegid(gid); if (setegid(gid) < 0)
if (r < 0)
return -errno; return -errno;
} }
if (uid_is_valid(uid)) { if (uid_is_valid(uid)) {
olduid = getuid(); olduid = getuid();
r = seteuid(uid); if (seteuid(uid) < 0) {
if (r < 0) {
r = -errno; r = -errno;
goto restore_gid; goto restore_gid;
} }
} }
r = connect(fd, &sa.sa, SOCKADDR_UN_LEN(sa.un)); r = connect(fd, &sa.sa, SOCKADDR_UN_LEN(sa.un)) < 0 ? -errno : 0;
if (r < 0)
r = -errno;
/* If we fail to restore the uid or gid, things will likely /* If we fail to restore the uid or gid, things will likely
fail later on. This should only happen if an LSM interferes. */ fail later on. This should only happen if an LSM interferes. */