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
}
_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;
}
_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;
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;
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
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;
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;
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;
_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;
}
_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;
}
_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;
}
_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;
sd_journal *j;
int r;
- if (!ret)
- return -EINVAL;
+ assert_return(ret, -EINVAL);
if (flags & ~(SD_JOURNAL_LOCAL_ONLY|
SD_JOURNAL_RUNTIME_ONLY|
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)
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)
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)
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)
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)
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)
_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;
_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)
_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)
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);
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) {
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;
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;
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;
_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)
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);
}
_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;
}
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)
}
_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;
#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);
}
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;
int r;
const char *variable;
- if (!seat)
- return -EINVAL;
+ assert_return(seat, -EINVAL);
variable = require_active ? "ACTIVE_UID" : "UIDS";
_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)
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)
_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)
_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)
int fd, k;
bool good = false;
- if (!m)
- return -EINVAL;
+ assert_return(m, -EINVAL);
fd = inotify_init1(IN_NONBLOCK|IN_CLOEXEC);
if (fd < 0)
_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);
_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
_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