From 1ae464e09376853c52075ec4d8a6bfc4b4036d0c Mon Sep 17 00:00:00 2001 From: Thomas Hindoe Paaboel Andersen Date: Mon, 2 Dec 2013 22:42:01 +0100 Subject: Use assert_return in more of the public API --- src/journal/journal-send.c | 34 ++--- src/journal/sd-journal.c | 281 +++++++++++++--------------------------- src/libsystemd-id128/sd-id128.c | 18 +-- src/login/sd-login.c | 76 ++++------- 4 files changed, 135 insertions(+), 274 deletions(-) (limited to 'src') diff --git a/src/journal/journal-send.c b/src/journal/journal-send.c index 52f9905c4e..931c1e7330 100644 --- a/src/journal/journal-send.c +++ b/src/journal/journal-send.c @@ -91,11 +91,9 @@ _public_ int sd_journal_printv(int priority, const char *format, va_list ap) { char buffer[8 + LINE_MAX], p[11]; struct iovec iov[2]; - if (priority < 0 || priority > 7) - return -EINVAL; - - if (!format) - return -EINVAL; + assert_return(priority >= 0, -EINVAL); + assert_return(priority <= 7, -EINVAL); + assert_return(format, -EINVAL); snprintf(p, sizeof(p), "PRIORITY=%i", priority & LOG_PRIMASK); char_array_0(p); @@ -224,11 +222,8 @@ _public_ int sd_journal_sendv(const struct iovec *iov, int n) { char path[] = "/dev/shm/journal.XXXXXX"; bool have_syslog_identifier = false; - if (_unlikely_(!iov)) - return -EINVAL; - - if (_unlikely_(n <= 0)) - return -EINVAL; + assert_return(iov, -EINVAL); + assert_return(n > 0, -EINVAL); w = alloca(sizeof(struct iovec) * n * 5 + 3); l = alloca(sizeof(uint64_t) * n); @@ -410,8 +405,8 @@ _public_ int sd_journal_stream_fd(const char *identifier, int priority, int leve size_t l; ssize_t r; - if (priority < 0 || priority > 7) - return -EINVAL; + assert_return(priority >= 0, -EINVAL); + assert_return(priority <= 7, -EINVAL); fd = socket(AF_UNIX, SOCK_STREAM|SOCK_CLOEXEC, 0); if (fd < 0) @@ -480,11 +475,9 @@ _public_ int sd_journal_printv_with_location(int priority, const char *file, con struct iovec iov[5]; char *f; - if (priority < 0 || priority > 7) - return -EINVAL; - - if (_unlikely_(!format)) - return -EINVAL; + assert_return(priority >= 0, -EINVAL); + assert_return(priority <= 7, -EINVAL); + assert_return(format, -EINVAL); snprintf(p, sizeof(p), "PRIORITY=%i", priority & LOG_PRIMASK); char_array_0(p); @@ -548,11 +541,8 @@ _public_ int sd_journal_sendv_with_location( struct iovec *niov; char *f; - if (_unlikely_(!iov)) - return -EINVAL; - - if (_unlikely_(n <= 0)) - return -EINVAL; + assert_return(iov, -EINVAL); + assert_return(n > 0, -EINVAL); niov = alloca(sizeof(struct iovec) * (n + 3)); memcpy(niov, iov, sizeof(struct iovec) * n); diff --git a/src/journal/sd-journal.c b/src/journal/sd-journal.c index 1c91f007b7..2ba7ca4559 100644 --- a/src/journal/sd-journal.c +++ b/src/journal/sd-journal.c @@ -216,19 +216,14 @@ _public_ int sd_journal_add_match(sd_journal *j, const void *data, size_t size) Match *l3, *l4, *add_here = NULL, *m; le64_t le_hash; - if (!j) - return -EINVAL; - if (journal_pid_changed(j)) - return -ECHILD; - - if (!data) - return -EINVAL; + assert_return(j, -EINVAL); + assert_return(!journal_pid_changed(j), -ECHILD); + assert_return(data, -EINVAL); if (size == 0) size = strlen(data); - if (!match_is_valid(data, size)) - return -EINVAL; + assert_return(match_is_valid(data, size), -EINVAL); /* level 0: AND term * level 1: OR terms @@ -314,10 +309,8 @@ fail: } _public_ int sd_journal_add_conjunction(sd_journal *j) { - if (!j) - return -EINVAL; - if (journal_pid_changed(j)) - return -ECHILD; + assert_return(j, -EINVAL); + assert_return(!journal_pid_changed(j), -ECHILD); if (!j->level0) return 0; @@ -335,10 +328,8 @@ _public_ int sd_journal_add_conjunction(sd_journal *j) { } _public_ int sd_journal_add_disjunction(sd_journal *j) { - if (!j) - return -EINVAL; - if (journal_pid_changed(j)) - return -ECHILD; + assert_return(j, -EINVAL); + assert_return(!journal_pid_changed(j), -ECHILD); if (!j->level0) return 0; @@ -884,10 +875,8 @@ static int real_journal_next(sd_journal *j, direction_t direction) { Iterator i; int r; - if (!j) - return -EINVAL; - if (journal_pid_changed(j)) - return -ECHILD; + assert_return(j, -EINVAL); + assert_return(!journal_pid_changed(j), -ECHILD); HASHMAP_FOREACH(f, j->files, i) { bool found; @@ -938,10 +927,8 @@ _public_ int sd_journal_previous(sd_journal *j) { static int real_journal_next_skip(sd_journal *j, direction_t direction, uint64_t skip) { int c = 0, r; - if (!j) - return -EINVAL; - if (journal_pid_changed(j)) - return -ECHILD; + assert_return(j, -EINVAL); + assert_return(!journal_pid_changed(j), -ECHILD); if (skip == 0) { /* If this is not a discrete skip, then at least @@ -980,12 +967,9 @@ _public_ int sd_journal_get_cursor(sd_journal *j, char **cursor) { int r; char bid[33], sid[33]; - if (!j) - return -EINVAL; - if (journal_pid_changed(j)) - return -ECHILD; - if (!cursor) - return -EINVAL; + assert_return(j, -EINVAL); + assert_return(!journal_pid_changed(j), -ECHILD); + assert_return(cursor, -EINVAL); if (!j->current_file || j->current_file->current_offset <= 0) return -EADDRNOTAVAIL; @@ -1021,12 +1005,9 @@ _public_ int sd_journal_seek_cursor(sd_journal *j, const char *cursor) { xor_hash_set = false; sd_id128_t seqnum_id, boot_id; - if (!j) - return -EINVAL; - if (journal_pid_changed(j)) - return -ECHILD; - if (isempty(cursor)) - return -EINVAL; + assert_return(j, -EINVAL); + assert_return(!journal_pid_changed(j), -ECHILD); + assert_return(!isempty(cursor), -EINVAL); FOREACH_WORD_SEPARATOR(w, l, cursor, ";", state) { char *item; @@ -1122,12 +1103,9 @@ _public_ int sd_journal_test_cursor(sd_journal *j, const char *cursor) { size_t l; Object *o; - if (!j) - return -EINVAL; - if (journal_pid_changed(j)) - return -ECHILD; - if (isempty(cursor)) - return -EINVAL; + assert_return(j, -EINVAL); + assert_return(!journal_pid_changed(j), -ECHILD); + assert_return(!isempty(cursor), -EINVAL); if (!j->current_file || j->current_file->current_offset <= 0) return -EADDRNOTAVAIL; @@ -1202,10 +1180,8 @@ _public_ int sd_journal_test_cursor(sd_journal *j, const char *cursor) { _public_ int sd_journal_seek_monotonic_usec(sd_journal *j, sd_id128_t boot_id, uint64_t usec) { - if (!j) - return -EINVAL; - if (journal_pid_changed(j)) - return -ECHILD; + assert_return(j, -EINVAL); + assert_return(!journal_pid_changed(j), -ECHILD); reset_location(j); j->current_location.type = LOCATION_SEEK; @@ -1217,10 +1193,8 @@ _public_ int sd_journal_seek_monotonic_usec(sd_journal *j, sd_id128_t boot_id, u } _public_ int sd_journal_seek_realtime_usec(sd_journal *j, uint64_t usec) { - if (!j) - return -EINVAL; - if (journal_pid_changed(j)) - return -ECHILD; + assert_return(j, -EINVAL); + assert_return(!journal_pid_changed(j), -ECHILD); reset_location(j); j->current_location.type = LOCATION_SEEK; @@ -1231,10 +1205,8 @@ _public_ int sd_journal_seek_realtime_usec(sd_journal *j, uint64_t usec) { } _public_ int sd_journal_seek_head(sd_journal *j) { - if (!j) - return -EINVAL; - if (journal_pid_changed(j)) - return -ECHILD; + assert_return(j, -EINVAL); + assert_return(!journal_pid_changed(j), -ECHILD); reset_location(j); j->current_location.type = LOCATION_HEAD; @@ -1243,10 +1215,8 @@ _public_ int sd_journal_seek_head(sd_journal *j) { } _public_ int sd_journal_seek_tail(sd_journal *j) { - if (!j) - return -EINVAL; - if (journal_pid_changed(j)) - return -ECHILD; + assert_return(j, -EINVAL); + assert_return(!journal_pid_changed(j), -ECHILD); reset_location(j); j->current_location.type = LOCATION_TAIL; @@ -1713,8 +1683,7 @@ _public_ int sd_journal_open(sd_journal **ret, int flags) { sd_journal *j; int r; - if (!ret) - return -EINVAL; + assert_return(ret, -EINVAL); if (flags & ~(SD_JOURNAL_LOCAL_ONLY| SD_JOURNAL_RUNTIME_ONLY| @@ -1743,14 +1712,9 @@ _public_ int sd_journal_open_directory(sd_journal **ret, const char *path, int f sd_journal *j; int r; - if (!ret) - return -EINVAL; - - if (!path) - return -EINVAL; - - if (flags != 0) - return -EINVAL; + assert_return(ret, -EINVAL); + assert_return(path, -EINVAL); + assert_return(flags == 0, -EINVAL); j = journal_new(flags, path); if (!j) @@ -1776,11 +1740,8 @@ _public_ int sd_journal_open_files(sd_journal **ret, const char **paths, int fla const char **path; int r; - if (!ret) - return -EINVAL; - - if (flags != 0) - return -EINVAL; + assert_return(ret, -EINVAL); + assert_return(flags == 0, -EINVAL); j = journal_new(flags, NULL); if (!j) @@ -1847,12 +1808,9 @@ _public_ int sd_journal_get_realtime_usec(sd_journal *j, uint64_t *ret) { JournalFile *f; int r; - if (!j) - return -EINVAL; - if (journal_pid_changed(j)) - return -ECHILD; - if (!ret) - return -EINVAL; + assert_return(j, -EINVAL); + assert_return(!journal_pid_changed(j), -ECHILD); + assert_return(ret, -EINVAL); f = j->current_file; if (!f) @@ -1875,10 +1833,8 @@ _public_ int sd_journal_get_monotonic_usec(sd_journal *j, uint64_t *ret, sd_id12 int r; sd_id128_t id; - if (!j) - return -EINVAL; - if (journal_pid_changed(j)) - return -ECHILD; + assert_return(j, -EINVAL); + assert_return(!journal_pid_changed(j), -ECHILD); f = j->current_file; if (!f) @@ -1943,19 +1899,12 @@ _public_ int sd_journal_get_data(sd_journal *j, const char *field, const void ** int r; Object *o; - if (!j) - return -EINVAL; - if (journal_pid_changed(j)) - return -ECHILD; - if (!field) - return -EINVAL; - if (!data) - return -EINVAL; - if (!size) - return -EINVAL; - - if (!field_is_valid(field)) - return -EINVAL; + assert_return(j, -EINVAL); + assert_return(!journal_pid_changed(j), -ECHILD); + assert_return(field, -EINVAL); + assert_return(data, -EINVAL); + assert_return(size, -EINVAL); + assert_return(field_is_valid(field), -EINVAL); f = j->current_file; if (!f) @@ -2071,14 +2020,10 @@ _public_ int sd_journal_enumerate_data(sd_journal *j, const void **data, size_t int r; Object *o; - if (!j) - return -EINVAL; - if (journal_pid_changed(j)) - return -ECHILD; - if (!data) - return -EINVAL; - if (!size) - return -EINVAL; + assert_return(j, -EINVAL); + assert_return(!journal_pid_changed(j), -ECHILD); + assert_return(data, -EINVAL); + assert_return(size, -EINVAL); f = j->current_file; if (!f) @@ -2123,10 +2068,8 @@ _public_ void sd_journal_restart_data(sd_journal *j) { _public_ int sd_journal_get_fd(sd_journal *j) { int r; - if (!j) - return -EINVAL; - if (journal_pid_changed(j)) - return -ECHILD; + assert_return(j, -EINVAL); + assert_return(!journal_pid_changed(j), -ECHILD); if (j->inotify_fd >= 0) return j->inotify_fd; @@ -2152,10 +2095,8 @@ _public_ int sd_journal_get_fd(sd_journal *j) { _public_ int sd_journal_get_events(sd_journal *j) { int fd; - if (!j) - return -EINVAL; - if (journal_pid_changed(j)) - return -ECHILD; + assert_return(j, -EINVAL); + assert_return(!journal_pid_changed(j), -ECHILD); fd = sd_journal_get_fd(j); if (fd < 0) @@ -2167,12 +2108,9 @@ _public_ int sd_journal_get_events(sd_journal *j) { _public_ int sd_journal_get_timeout(sd_journal *j, uint64_t *timeout_usec) { int fd; - if (!j) - return -EINVAL; - if (journal_pid_changed(j)) - return -ECHILD; - if (!timeout_usec) - return -EINVAL; + assert_return(j, -EINVAL); + assert_return(!journal_pid_changed(j), -ECHILD); + assert_return(timeout_usec, -EINVAL); fd = sd_journal_get_fd(j); if (fd < 0) @@ -2269,10 +2207,8 @@ _public_ int sd_journal_process(sd_journal *j) { uint8_t buffer[sizeof(struct inotify_event) + FILENAME_MAX] _alignas_(struct inotify_event); bool got_something = false; - if (!j) - return -EINVAL; - if (journal_pid_changed(j)) - return -ECHILD; + assert_return(j, -EINVAL); + assert_return(!journal_pid_changed(j), -ECHILD); j->last_process_usec = now(CLOCK_MONOTONIC); @@ -2311,10 +2247,8 @@ _public_ int sd_journal_wait(sd_journal *j, uint64_t timeout_usec) { int r; uint64_t t; - if (!j) - return -EINVAL; - if (journal_pid_changed(j)) - return -ECHILD; + assert_return(j, -EINVAL); + assert_return(!journal_pid_changed(j), -ECHILD); if (j->inotify_fd < 0) { @@ -2361,14 +2295,10 @@ _public_ int sd_journal_get_cutoff_realtime_usec(sd_journal *j, uint64_t *from, bool first = true; int r; - if (!j) - return -EINVAL; - if (journal_pid_changed(j)) - return -ECHILD; - if (!from && !to) - return -EINVAL; - if (from == to) - return -EINVAL; + assert_return(j, -EINVAL); + assert_return(!journal_pid_changed(j), -ECHILD); + assert_return(from || to, -EINVAL); + assert_return(from != to, -EINVAL); HASHMAP_FOREACH(f, j->files, i) { usec_t fr, t; @@ -2404,14 +2334,10 @@ _public_ int sd_journal_get_cutoff_monotonic_usec(sd_journal *j, sd_id128_t boot bool first = true; int r; - if (!j) - return -EINVAL; - if (journal_pid_changed(j)) - return -ECHILD; - if (!from && !to) - return -EINVAL; - if (from == to) - return -EINVAL; + assert_return(j, -EINVAL); + assert_return(!journal_pid_changed(j), -ECHILD); + assert_return(from || to, -EINVAL); + assert_return(from != to, -EINVAL); HASHMAP_FOREACH(f, j->files, i) { usec_t fr, t; @@ -2463,12 +2389,9 @@ _public_ int sd_journal_get_usage(sd_journal *j, uint64_t *bytes) { JournalFile *f; uint64_t sum = 0; - if (!j) - return -EINVAL; - if (journal_pid_changed(j)) - return -ECHILD; - if (!bytes) - return -EINVAL; + assert_return(j, -EINVAL); + assert_return(!journal_pid_changed(j), -ECHILD); + assert_return(bytes, -EINVAL); HASHMAP_FOREACH(f, j->files, i) { struct stat st; @@ -2486,14 +2409,10 @@ _public_ int sd_journal_get_usage(sd_journal *j, uint64_t *bytes) { _public_ int sd_journal_query_unique(sd_journal *j, const char *field) { char *f; - if (!j) - return -EINVAL; - if (journal_pid_changed(j)) - return -ECHILD; - if (isempty(field)) - return -EINVAL; - if (!field_is_valid(field)) - return -EINVAL; + assert_return(j, -EINVAL); + assert_return(!journal_pid_changed(j), -ECHILD); + assert_return(!isempty(field), -EINVAL); + assert_return(field_is_valid(field), -EINVAL); f = strdup(field); if (!f) @@ -2512,16 +2431,11 @@ _public_ int sd_journal_enumerate_unique(sd_journal *j, const void **data, size_ size_t k; int r; - if (!j) - return -EINVAL; - if (journal_pid_changed(j)) - return -ECHILD; - if (!data) - return -EINVAL; - if (!l) - return -EINVAL; - if (!j->unique_field) - return -EINVAL; + assert_return(j, -EINVAL); + assert_return(!journal_pid_changed(j), -ECHILD); + assert_return(data, -EINVAL); + assert_return(l, -EINVAL); + assert_return(j->unique_field, -EINVAL); k = strlen(j->unique_field); @@ -2626,10 +2540,8 @@ _public_ void sd_journal_restart_unique(sd_journal *j) { } _public_ int sd_journal_reliable_fd(sd_journal *j) { - if (!j) - return -EINVAL; - if (journal_pid_changed(j)) - return -ECHILD; + assert_return(j, -EINVAL); + assert_return(!journal_pid_changed(j), -ECHILD); return !j->on_network; } @@ -2661,12 +2573,9 @@ _public_ int sd_journal_get_catalog(sd_journal *j, char **ret) { char *t; int r; - if (!j) - return -EINVAL; - if (journal_pid_changed(j)) - return -ECHILD; - if (!ret) - return -EINVAL; + assert_return(j, -EINVAL); + assert_return(!journal_pid_changed(j), -ECHILD); + assert_return(ret, -EINVAL); r = sd_journal_get_data(j, "MESSAGE_ID", &data, &size); if (r < 0) @@ -2693,29 +2602,23 @@ _public_ int sd_journal_get_catalog(sd_journal *j, char **ret) { } _public_ int sd_journal_get_catalog_for_message_id(sd_id128_t id, char **ret) { - if (!ret) - return -EINVAL; + assert_return(ret, -EINVAL); return catalog_get(CATALOG_DATABASE, id, ret); } _public_ int sd_journal_set_data_threshold(sd_journal *j, size_t sz) { - if (!j) - return -EINVAL; - if (journal_pid_changed(j)) - return -ECHILD; + assert_return(j, -EINVAL); + assert_return(!journal_pid_changed(j), -ECHILD); j->data_threshold = sz; return 0; } _public_ int sd_journal_get_data_threshold(sd_journal *j, size_t *sz) { - if (!j) - return -EINVAL; - if (journal_pid_changed(j)) - return -ECHILD; - if (!sz) - return -EINVAL; + assert_return(j, -EINVAL); + assert_return(!journal_pid_changed(j), -ECHILD); + assert_return(sz, -EINVAL); *sz = j->data_threshold; return 0; diff --git a/src/libsystemd-id128/sd-id128.c b/src/libsystemd-id128/sd-id128.c index 64ddd09236..3fbad71a52 100644 --- a/src/libsystemd-id128/sd-id128.c +++ b/src/libsystemd-id128/sd-id128.c @@ -31,8 +31,7 @@ _public_ char *sd_id128_to_string(sd_id128_t id, char s[33]) { unsigned n; - if (!s) - return NULL; + assert_return(s, NULL); for (n = 0; n < 16; n++) { s[n*2] = hexchar(id.bytes[n] >> 4); @@ -49,10 +48,8 @@ _public_ int sd_id128_from_string(const char s[], sd_id128_t *ret) { sd_id128_t t; bool is_guid = false; - if (!s) - return -EINVAL; - if (!ret) - return -EINVAL; + assert_return(s, -EINVAL); + assert_return(ret, -EINVAL); for (n = 0, i = 0; n < 16;) { int a, b; @@ -116,8 +113,7 @@ _public_ int sd_id128_get_machine(sd_id128_t *ret) { unsigned j; sd_id128_t t; - if (!ret) - return -EINVAL; + assert_return(ret, -EINVAL); if (saved_machine_id_valid) { *ret = saved_machine_id; @@ -167,8 +163,7 @@ _public_ int sd_id128_get_boot(sd_id128_t *ret) { sd_id128_t t; char *p; - if (!ret) - return -EINVAL; + assert_return(ret, -EINVAL); if (saved_boot_id_valid) { *ret = saved_boot_id; @@ -218,8 +213,7 @@ _public_ int sd_id128_randomize(sd_id128_t *ret) { sd_id128_t t; ssize_t k; - if (!ret) - return -EINVAL; + assert_return(ret, -EINVAL); fd = open("/dev/urandom", O_RDONLY|O_CLOEXEC|O_NOCTTY); if (fd < 0) diff --git a/src/login/sd-login.c b/src/login/sd-login.c index 7e25041f6d..7ae3db0397 100644 --- a/src/login/sd-login.c +++ b/src/login/sd-login.c @@ -34,62 +34,49 @@ #include "login-shared.h" _public_ int sd_pid_get_session(pid_t pid, char **session) { - if (pid < 0) - return -EINVAL; - if (!session) - return -EINVAL; + assert_return(pid >= 0, -EINVAL); + assert_return(session, -EINVAL); return cg_pid_get_session(pid, session); } _public_ int sd_pid_get_unit(pid_t pid, char **unit) { - if (pid < 0) - return -EINVAL; - if (!unit) - return -EINVAL; + assert_return(pid >= 0, -EINVAL); + assert_return(unit, -EINVAL); return cg_pid_get_unit(pid, unit); } _public_ int sd_pid_get_user_unit(pid_t pid, char **unit) { - if (pid < 0) - return -EINVAL; - if (!unit) - return -EINVAL; + assert_return(pid >= 0, -EINVAL); + assert_return(unit, -EINVAL); return cg_pid_get_user_unit(pid, unit); } _public_ int sd_pid_get_machine_name(pid_t pid, char **name) { - if (pid < 0) - return -EINVAL; - if (!name) - return -EINVAL; + assert_return(pid >= 0, -EINVAL); + assert_return(name, -EINVAL); return cg_pid_get_machine_name(pid, name); } _public_ int sd_pid_get_slice(pid_t pid, char **slice) { - if (pid < 0) - return -EINVAL; - if (!slice) - return -EINVAL; + assert_return(pid >= 0, -EINVAL); + assert_return(slice, -EINVAL); return cg_pid_get_slice(pid, slice); } _public_ int sd_pid_get_owner_uid(pid_t pid, uid_t *uid) { - if (pid < 0) - return -EINVAL; - - if (!uid) - return -EINVAL; + assert_return(pid >= 0, -EINVAL); + assert_return(uid, -EINVAL); return cg_pid_get_owner_uid(pid, uid); } @@ -98,8 +85,7 @@ _public_ int sd_uid_get_state(uid_t uid, char**state) { char *p, *s = NULL; int r; - if (!state) - return -EINVAL; + assert_return(state, -EINVAL); if (asprintf(&p, "/run/systemd/users/%lu", (unsigned long) uid) < 0) return -ENOMEM; @@ -132,8 +118,7 @@ _public_ int sd_uid_is_on_seat(uid_t uid, int require_active, const char *seat) int r; const char *variable; - if (!seat) - return -EINVAL; + assert_return(seat, -EINVAL); variable = require_active ? "ACTIVE_UID" : "UIDS"; @@ -273,8 +258,7 @@ _public_ int sd_session_get_state(const char *session, char **state) { _cleanup_free_ char *p = NULL, *s = NULL; int r; - if (!state) - return -EINVAL; + assert_return(state, -EINVAL); r = file_of_session(session, &p); if (r < 0) @@ -297,8 +281,7 @@ _public_ int sd_session_get_uid(const char *session, uid_t *uid) { int r; _cleanup_free_ char *p = NULL, *s = NULL; - if (!uid) - return -EINVAL; + assert_return(uid, -EINVAL); r = file_of_session(session, &p); if (r < 0) @@ -321,8 +304,7 @@ static int session_get_string(const char *session, const char *field, char **val _cleanup_free_ char *p = NULL, *s = NULL; int r; - if (!value) - return -EINVAL; + assert_return(value, -EINVAL); r = file_of_session(session, &p); if (r < 0) @@ -412,8 +394,7 @@ _public_ int sd_seat_get_active(const char *seat, char **session, uid_t *uid) { _cleanup_free_ char *p = NULL, *s = NULL, *t = NULL; int r; - if (!session && !uid) - return -EINVAL; + assert_return(session || uid, -EINVAL); r = file_of_seat(seat, &p); if (r < 0) @@ -636,8 +617,7 @@ _public_ int sd_login_monitor_new(const char *category, sd_login_monitor **m) { int fd, k; bool good = false; - if (!m) - return -EINVAL; + assert_return(m, -EINVAL); fd = inotify_init1(IN_NONBLOCK|IN_CLOEXEC); if (fd < 0) @@ -695,8 +675,7 @@ _public_ int sd_login_monitor_new(const char *category, sd_login_monitor **m) { _public_ sd_login_monitor* sd_login_monitor_unref(sd_login_monitor *m) { int fd; - if (!m) - return NULL; + assert_return(m, NULL); fd = MONITOR_TO_FD(m); close_nointr(fd); @@ -706,24 +685,21 @@ _public_ sd_login_monitor* sd_login_monitor_unref(sd_login_monitor *m) { _public_ int sd_login_monitor_flush(sd_login_monitor *m) { - if (!m) - return -EINVAL; + assert_return(m, -EINVAL); return flush_fd(MONITOR_TO_FD(m)); } _public_ int sd_login_monitor_get_fd(sd_login_monitor *m) { - if (!m) - return -EINVAL; + assert_return(m, -EINVAL); return MONITOR_TO_FD(m); } _public_ int sd_login_monitor_get_events(sd_login_monitor *m) { - if (!m) - return -EINVAL; + assert_return(m, -EINVAL); /* For now we will only return POLLIN here, since we don't * need anything else ever for inotify. However, let's have @@ -734,10 +710,8 @@ _public_ int sd_login_monitor_get_events(sd_login_monitor *m) { _public_ int sd_login_monitor_get_timeout(sd_login_monitor *m, uint64_t *timeout_usec) { - if (!m) - return -EINVAL; - if (!timeout_usec) - return -EINVAL; + assert_return(m, -EINVAL); + assert_return(timeout_usec, -EINVAL); /* For now we will only return (uint64_t) -1, since we don't * need any timeout. However, let's have this API to keep our -- cgit v1.2.3-54-g00ecf