diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2014-02-02 23:58:16 -0500 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2014-03-04 10:02:09 -0500 |
commit | 61376f96a98291b5421bfd79a15ca4db50c2a3fe (patch) | |
tree | d271e8833fe9f87e09f48f46ce2418bec6ce6a76 /src/login/logind-core.c | |
parent | 21491585780b71010b7ee2138fa394680b2de340 (diff) |
logind: small simplifications
Diffstat (limited to 'src/login/logind-core.c')
-rw-r--r-- | src/login/logind-core.c | 78 |
1 files changed, 25 insertions, 53 deletions
diff --git a/src/login/logind-core.c b/src/login/logind-core.c index b8d03c3a59..ca34d378ff 100644 --- a/src/login/logind-core.c +++ b/src/login/logind-core.c @@ -42,20 +42,15 @@ int manager_add_device(Manager *m, const char *sysfs, bool master, Device **_dev assert(sysfs); d = hashmap_get(m->devices, sysfs); - if (d) { - if (_device) - *_device = d; - + if (d) /* we support adding master-flags, but not removing them */ d->master = d->master || master; - - return 0; + else { + d = device_new(m, sysfs, master); + if (!d) + return -ENOMEM; } - d = device_new(m, sysfs, master); - if (!d) - return -ENOMEM; - if (_device) *_device = d; @@ -69,17 +64,12 @@ int manager_add_seat(Manager *m, const char *id, Seat **_seat) { assert(id); s = hashmap_get(m->seats, id); - if (s) { - if (_seat) - *_seat = s; - - return 0; + if (!s) { + s = seat_new(m, id); + if (!s) + return -ENOMEM; } - s = seat_new(m, id); - if (!s) - return -ENOMEM; - if (_seat) *_seat = s; @@ -93,17 +83,12 @@ int manager_add_session(Manager *m, const char *id, Session **_session) { assert(id); s = hashmap_get(m->sessions, id); - if (s) { - if (_session) - *_session = s; - - return 0; + if (!s) { + s = session_new(m, id); + if (!s) + return -ENOMEM; } - s = session_new(m, id); - if (!s) - return -ENOMEM; - if (_session) *_session = s; @@ -117,17 +102,12 @@ int manager_add_user(Manager *m, uid_t uid, gid_t gid, const char *name, User ** assert(name); u = hashmap_get(m->users, ULONG_TO_PTR((unsigned long) uid)); - if (u) { - if (_user) - *_user = u; - - return 0; + if (!u) { + u = user_new(m, uid, gid, name); + if (!u) + return -ENOMEM; } - u = user_new(m, uid, gid, name); - if (!u) - return -ENOMEM; - if (_user) *_user = u; @@ -193,17 +173,12 @@ int manager_add_button(Manager *m, const char *name, Button **_button) { assert(name); b = hashmap_get(m->buttons, name); - if (b) { - if (_button) - *_button = b; - - return 0; + if (!b) { + b = button_new(m, name); + if (!b) + return -ENOMEM; } - b = button_new(m, name); - if (!b) - return -ENOMEM; - if (_button) *_button = b; @@ -441,7 +416,8 @@ bool manager_shall_kill(Manager *m, const char *user) { static int vt_is_busy(unsigned int vtnr) { struct vt_stat vt_stat; - int r = 0, fd; + int r = 0; + _cleanup_close_ int fd; assert(vtnr >= 1); @@ -460,14 +436,12 @@ static int vt_is_busy(unsigned int vtnr) { else r = !!(vt_stat.v_state & (1 << vtnr)); - close_nointr_nofail(fd); - return r; } int manager_spawn_autovt(Manager *m, unsigned int vtnr) { _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL; - _cleanup_free_ char *name = NULL; + char name[sizeof("autovt@tty.service") + DECIMAL_STR_MAX(unsigned int)]; int r; assert(m); @@ -489,9 +463,7 @@ int manager_spawn_autovt(Manager *m, unsigned int vtnr) { return -EBUSY; } - if (asprintf(&name, "autovt@tty%u.service", vtnr) < 0) - return log_oom(); - + snprintf(name, sizeof(name), "autovt@tty%u.service", vtnr); r = sd_bus_call_method( m->bus, "org.freedesktop.systemd1", |