api: in constructor function calls, always put the returned object pointer first (or second)
Previously the returned object of constructor functions where sometimes returned as last, sometimes as first and sometimes as second parameter. Let's clean this up a bit. Here are the new rules: 1. The object the new object is derived from is put first, if there is any 2. The object we are creating will be returned in the next arguments 3. This is followed by any additional arguments Rationale: For functions that operate on an object we always put that object first. Constructors should probably not be too different in this regard. Also, if the additional parameters might want to use varargs which suggests to put them last. Note that this new scheme only applies to constructor functions, not to all other functions. We do give a lot of freedom for those. Note that this commit only changes the order of the new functions we added, for old ones we accept the wrong order and leave it like that.
This commit is contained in:
@@ -256,7 +256,7 @@ static int automount_coldplug(Unit *u) {
|
||||
|
||||
assert(a->pipe_fd >= 0);
|
||||
|
||||
r = sd_event_add_io(u->manager->event, a->pipe_fd, EPOLLIN, automount_dispatch_io, u, &a->pipe_event_source);
|
||||
r = sd_event_add_io(u->manager->event, &a->pipe_event_source, a->pipe_fd, EPOLLIN, automount_dispatch_io, u);
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
@@ -531,7 +531,7 @@ static void automount_enter_waiting(Automount *a) {
|
||||
close_nointr_nofail(ioctl_fd);
|
||||
ioctl_fd = -1;
|
||||
|
||||
r = sd_event_add_io(UNIT(a)->manager->event, p[0], EPOLLIN, automount_dispatch_io, a, &a->pipe_event_source);
|
||||
r = sd_event_add_io(UNIT(a)->manager->event, &a->pipe_event_source, p[0], EPOLLIN, automount_dispatch_io, a);
|
||||
if (r < 0)
|
||||
goto fail;
|
||||
|
||||
|
||||
+1
-1
@@ -217,7 +217,7 @@ static int busname_watch_fd(BusName *n) {
|
||||
if (n->event_source)
|
||||
r = sd_event_source_set_enabled(n->event_source, SD_EVENT_ON);
|
||||
else
|
||||
r = sd_event_add_io(UNIT(n)->manager->event, n->starter_fd, EPOLLIN, busname_dispatch_io, n, &n->event_source);
|
||||
r = sd_event_add_io(UNIT(n)->manager->event, &n->event_source, n->starter_fd, EPOLLIN, busname_dispatch_io, n);
|
||||
if (r < 0) {
|
||||
log_warning_unit(UNIT(n)->id, "Failed to watch starter fd: %s", strerror(-r));
|
||||
busname_unwatch_fd(n);
|
||||
|
||||
+4
-4
@@ -137,10 +137,10 @@ static int send_new_signal(sd_bus *bus, const char *destination, Job *j) {
|
||||
|
||||
r = sd_bus_message_new_signal(
|
||||
bus,
|
||||
&m,
|
||||
"/org/freedesktop/systemd1",
|
||||
"org.freedesktop.systemd1.Manager",
|
||||
"JobNew",
|
||||
&m);
|
||||
"JobNew");
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
@@ -196,10 +196,10 @@ static int send_removed_signal(sd_bus *bus, const char *destination, Job *j) {
|
||||
|
||||
r = sd_bus_message_new_signal(
|
||||
bus,
|
||||
&m,
|
||||
"/org/freedesktop/systemd1",
|
||||
"org.freedesktop.systemd1.Manager",
|
||||
"JobRemoved",
|
||||
&m);
|
||||
"JobRemoved");
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
|
||||
@@ -1338,7 +1338,7 @@ static int send_unit_files_changed(sd_bus *bus, const char *destination, void *u
|
||||
|
||||
assert(bus);
|
||||
|
||||
r = sd_bus_message_new_signal(bus, "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", "UnitFilesChanged", &message);
|
||||
r = sd_bus_message_new_signal(bus, &message, "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", "UnitFilesChanged");
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
@@ -1680,7 +1680,7 @@ static int send_finished(sd_bus *bus, const char *destination, void *userdata) {
|
||||
assert(bus);
|
||||
assert(times);
|
||||
|
||||
r = sd_bus_message_new_signal(bus, "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", "StartupFinished", &message);
|
||||
r = sd_bus_message_new_signal(bus, &message, "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", "StartupFinished");
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
@@ -1716,7 +1716,7 @@ static int send_reloading(sd_bus *bus, const char *destination, void *userdata)
|
||||
|
||||
assert(bus);
|
||||
|
||||
r = sd_bus_message_new_signal(bus, "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", "Reloading", &message);
|
||||
r = sd_bus_message_new_signal(bus, &message, "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", "Reloading");
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
|
||||
@@ -209,10 +209,10 @@ int bus_scope_send_request_stop(Scope *s) {
|
||||
|
||||
r = sd_bus_message_new_signal(
|
||||
UNIT(s)->manager->api_bus,
|
||||
&m,
|
||||
p,
|
||||
"org.freedesktop.systemd1.Scope",
|
||||
"RequestStop",
|
||||
&m);
|
||||
"RequestStop");
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
|
||||
@@ -604,10 +604,10 @@ static int send_new_signal(sd_bus *bus, const char *destination, void *userdata)
|
||||
|
||||
r = sd_bus_message_new_signal(
|
||||
bus,
|
||||
&m,
|
||||
"/org/freedesktop/systemd1",
|
||||
"org.freedesktop.systemd1.Manager",
|
||||
"UnitNew",
|
||||
&m);
|
||||
"UnitNew");
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
@@ -689,10 +689,10 @@ static int send_removed_signal(sd_bus *bus, const char *destination, void *userd
|
||||
|
||||
r = sd_bus_message_new_signal(
|
||||
bus,
|
||||
&m,
|
||||
"/org/freedesktop/systemd1",
|
||||
"org.freedesktop.systemd1.Manager",
|
||||
"UnitRemoved",
|
||||
&m);
|
||||
"UnitRemoved");
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
|
||||
+2
-2
@@ -190,7 +190,7 @@ failed:
|
||||
|
||||
log_debug("D-Bus activation failed for %s: %s", name, bus_error_message(&error, r));
|
||||
|
||||
r = sd_bus_message_new_signal(bus, "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Activator", "ActivationFailure", &reply);
|
||||
r = sd_bus_message_new_signal(bus, &reply, "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Activator", "ActivationFailure");
|
||||
if (r < 0) {
|
||||
bus_log_create_error(r);
|
||||
return 0;
|
||||
@@ -994,7 +994,7 @@ static int bus_init_private(Manager *m) {
|
||||
return -errno;
|
||||
}
|
||||
|
||||
r = sd_event_add_io(m->event, fd, EPOLLIN, bus_on_connection, m, &s);
|
||||
r = sd_event_add_io(m->event, &s, fd, EPOLLIN, bus_on_connection, m);
|
||||
if (r < 0) {
|
||||
log_error("Failed to allocate event source: %s", strerror(-r));
|
||||
return r;
|
||||
|
||||
+1
-1
@@ -534,7 +534,7 @@ static int device_enumerate(Manager *m) {
|
||||
if (r < 0)
|
||||
goto fail;
|
||||
|
||||
r = sd_event_add_io(m->event, udev_monitor_get_fd(m->udev_monitor), EPOLLIN, device_dispatch_io, m, &m->udev_event_source);
|
||||
r = sd_event_add_io(m->event, &m->udev_event_source, udev_monitor_get_fd(m->udev_monitor), EPOLLIN, device_dispatch_io, m);
|
||||
if (r < 0)
|
||||
goto fail;
|
||||
}
|
||||
|
||||
+2
-2
@@ -872,7 +872,7 @@ int job_start_timer(Job *j) {
|
||||
if (j->unit->job_timeout <= 0)
|
||||
return 0;
|
||||
|
||||
r = sd_event_add_monotonic(j->manager->event, j->begin_usec + j->unit->job_timeout, 0, job_dispatch_timer, j, &j->timer_event_source);
|
||||
r = sd_event_add_monotonic(j->manager->event, &j->timer_event_source, j->begin_usec + j->unit->job_timeout, 0, job_dispatch_timer, j);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
@@ -1057,7 +1057,7 @@ int job_coldplug(Job *j) {
|
||||
if (j->timer_event_source)
|
||||
j->timer_event_source = sd_event_source_unref(j->timer_event_source);
|
||||
|
||||
r = sd_event_add_monotonic(j->manager->event, j->begin_usec + j->unit->job_timeout, 0, job_dispatch_timer, j, &j->timer_event_source);
|
||||
r = sd_event_add_monotonic(j->manager->event, &j->timer_event_source, j->begin_usec + j->unit->job_timeout, 0, job_dispatch_timer, j);
|
||||
if (r < 0)
|
||||
log_debug("Failed to restart timeout for job: %s", strerror(-r));
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ static int add_addresses(sd_rtnl *rtnl, int if_loopback, struct in_addr *ipv4_ad
|
||||
_cleanup_rtnl_message_unref_ sd_rtnl_message *ipv4 = NULL, *ipv6 = NULL;
|
||||
int r;
|
||||
|
||||
r = sd_rtnl_message_new_addr(rtnl, RTM_NEWADDR, if_loopback, AF_INET, &ipv4);
|
||||
r = sd_rtnl_message_new_addr(rtnl, &ipv4, RTM_NEWADDR, if_loopback, AF_INET);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
@@ -79,7 +79,7 @@ static int add_addresses(sd_rtnl *rtnl, int if_loopback, struct in_addr *ipv4_ad
|
||||
if (!socket_ipv6_is_supported())
|
||||
return 0;
|
||||
|
||||
r = sd_rtnl_message_new_addr(rtnl, RTM_NEWADDR, if_loopback, AF_INET6, &ipv6);
|
||||
r = sd_rtnl_message_new_addr(rtnl, &ipv6, RTM_NEWADDR, if_loopback, AF_INET6);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
@@ -112,7 +112,7 @@ static int start_interface(sd_rtnl *rtnl, int if_loopback, struct in_addr *ipv4_
|
||||
_cleanup_rtnl_message_unref_ sd_rtnl_message *req = NULL;
|
||||
int r;
|
||||
|
||||
r = sd_rtnl_message_new_link(rtnl, RTM_SETLINK, if_loopback, &req);
|
||||
r = sd_rtnl_message_new_link(rtnl, &req, RTM_SETLINK, if_loopback);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
@@ -168,7 +168,7 @@ int loopback_setup(void) {
|
||||
|
||||
ipv4_address.s_addr = htonl(INADDR_LOOPBACK);
|
||||
|
||||
r = sd_rtnl_open(0, &rtnl);
|
||||
r = sd_rtnl_open(&rtnl, 0);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
|
||||
+6
-6
@@ -105,7 +105,7 @@ static int manager_watch_jobs_in_progress(Manager *m) {
|
||||
return 0;
|
||||
|
||||
next = now(CLOCK_MONOTONIC) + JOBS_IN_PROGRESS_WAIT_USEC;
|
||||
return sd_event_add_monotonic(m->event, next, 0, manager_dispatch_jobs_in_progress, m, &m->jobs_in_progress_event_source);
|
||||
return sd_event_add_monotonic(m->event, &m->jobs_in_progress_event_source, next, 0, manager_dispatch_jobs_in_progress, m);
|
||||
}
|
||||
|
||||
#define CYLON_BUFFER_EXTRA (2*(sizeof(ANSI_RED_ON)-1) + sizeof(ANSI_HIGHLIGHT_RED_ON)-1 + 2*(sizeof(ANSI_HIGHLIGHT_OFF)-1))
|
||||
@@ -209,7 +209,7 @@ static int manager_watch_idle_pipe(Manager *m) {
|
||||
if (m->idle_pipe[2] < 0)
|
||||
return 0;
|
||||
|
||||
r = sd_event_add_io(m->event, m->idle_pipe[2], EPOLLIN, manager_dispatch_idle_pipe_fd, m, &m->idle_pipe_event_source);
|
||||
r = sd_event_add_io(m->event, &m->idle_pipe_event_source, m->idle_pipe[2], EPOLLIN, manager_dispatch_idle_pipe_fd, m);
|
||||
if (r < 0) {
|
||||
log_error("Failed to watch idle pipe: %s", strerror(-r));
|
||||
return r;
|
||||
@@ -253,7 +253,7 @@ static int manager_setup_time_change(Manager *m) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
r = sd_event_add_io(m->event, m->time_change_fd, EPOLLIN, manager_dispatch_time_change_fd, m, &m->time_change_event_source);
|
||||
r = sd_event_add_io(m->event, &m->time_change_event_source, m->time_change_fd, EPOLLIN, manager_dispatch_time_change_fd, m);
|
||||
if (r < 0) {
|
||||
log_error("Failed to create time change event source: %s", strerror(-r));
|
||||
return r;
|
||||
@@ -340,7 +340,7 @@ static int manager_setup_signals(Manager *m) {
|
||||
if (m->signal_fd < 0)
|
||||
return -errno;
|
||||
|
||||
r = sd_event_add_io(m->event, m->signal_fd, EPOLLIN, manager_dispatch_signal_fd, m, &m->signal_event_source);
|
||||
r = sd_event_add_io(m->event, &m->signal_event_source, m->signal_fd, EPOLLIN, manager_dispatch_signal_fd, m);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
@@ -455,7 +455,7 @@ int manager_new(SystemdRunningAs running_as, Manager **_m) {
|
||||
if (r < 0)
|
||||
goto fail;
|
||||
|
||||
r = sd_event_add_defer(m->event, manager_dispatch_run_queue, m, &m->run_queue_event_source);
|
||||
r = sd_event_add_defer(m->event, &m->run_queue_event_source, manager_dispatch_run_queue, m);
|
||||
if (r < 0)
|
||||
goto fail;
|
||||
|
||||
@@ -552,7 +552,7 @@ static int manager_setup_notify(Manager *m) {
|
||||
}
|
||||
|
||||
if (!m->notify_event_source) {
|
||||
r = sd_event_add_io(m->event, m->notify_fd, EPOLLIN, manager_dispatch_notify_fd, m, &m->notify_event_source);
|
||||
r = sd_event_add_io(m->event, &m->notify_event_source, m->notify_fd, EPOLLIN, manager_dispatch_notify_fd, m);
|
||||
if (r < 0) {
|
||||
log_error("Failed to allocate notify event source: %s", strerror(-r));
|
||||
return -errno;
|
||||
|
||||
+2
-2
@@ -181,7 +181,7 @@ static int mount_arm_timer(Mount *m) {
|
||||
return sd_event_source_set_enabled(m->timer_event_source, SD_EVENT_ONESHOT);
|
||||
}
|
||||
|
||||
return sd_event_add_monotonic(UNIT(m)->manager->event, now(CLOCK_MONOTONIC) + m->timeout_usec, 0, mount_dispatch_timer, m, &m->timer_event_source);
|
||||
return sd_event_add_monotonic(UNIT(m)->manager->event, &m->timer_event_source, now(CLOCK_MONOTONIC) + m->timeout_usec, 0, mount_dispatch_timer, m);
|
||||
}
|
||||
|
||||
static void mount_unwatch_control_pid(Mount *m) {
|
||||
@@ -1612,7 +1612,7 @@ static int mount_enumerate(Manager *m) {
|
||||
if (!m->proc_self_mountinfo)
|
||||
return -errno;
|
||||
|
||||
r = sd_event_add_io(m->event, fileno(m->proc_self_mountinfo), EPOLLPRI, mount_dispatch_io, m, &m->mount_event_source);
|
||||
r = sd_event_add_io(m->event, &m->mount_event_source, fileno(m->proc_self_mountinfo), EPOLLPRI, mount_dispatch_io, m);
|
||||
if (r < 0)
|
||||
goto fail;
|
||||
|
||||
|
||||
+1
-1
@@ -71,7 +71,7 @@ int path_spec_watch(PathSpec *s, sd_event_io_handler_t handler) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
r = sd_event_add_io(s->unit->manager->event, s->inotify_fd, EPOLLIN, handler, s, &s->event_source);
|
||||
r = sd_event_add_io(s->unit->manager->event, &s->event_source, s->inotify_fd, EPOLLIN, handler, s);
|
||||
if (r < 0)
|
||||
goto fail;
|
||||
|
||||
|
||||
+1
-1
@@ -88,7 +88,7 @@ static int scope_arm_timer(Scope *s) {
|
||||
return sd_event_source_set_enabled(s->timer_event_source, SD_EVENT_ONESHOT);
|
||||
}
|
||||
|
||||
return sd_event_add_monotonic(UNIT(s)->manager->event, now(CLOCK_MONOTONIC) + s->timeout_stop_usec, 0, scope_dispatch_timer, s, &s->timer_event_source);
|
||||
return sd_event_add_monotonic(UNIT(s)->manager->event, &s->timer_event_source, now(CLOCK_MONOTONIC) + s->timeout_stop_usec, 0, scope_dispatch_timer, s);
|
||||
}
|
||||
|
||||
static void scope_set_state(Scope *s, ScopeState state) {
|
||||
|
||||
+2
-2
@@ -264,7 +264,7 @@ static void service_start_watchdog(Service *s) {
|
||||
|
||||
r = sd_event_source_set_enabled(s->watchdog_event_source, SD_EVENT_ONESHOT);
|
||||
} else {
|
||||
r = sd_event_add_monotonic(UNIT(s)->manager->event, s->watchdog_timestamp.monotonic + s->watchdog_usec, 0, service_dispatch_watchdog, s, &s->watchdog_event_source);
|
||||
r = sd_event_add_monotonic(UNIT(s)->manager->event, &s->watchdog_event_source, s->watchdog_timestamp.monotonic + s->watchdog_usec, 0, service_dispatch_watchdog, s);
|
||||
if (r < 0) {
|
||||
log_warning_unit(UNIT(s)->id, "%s failed to add watchdog timer: %s", UNIT(s)->id, strerror(-r));
|
||||
return;
|
||||
@@ -354,7 +354,7 @@ static int service_arm_timer(Service *s, usec_t usec) {
|
||||
return sd_event_source_set_enabled(s->timer_event_source, SD_EVENT_ONESHOT);
|
||||
}
|
||||
|
||||
return sd_event_add_monotonic(UNIT(s)->manager->event, now(CLOCK_MONOTONIC) + usec, 0, service_dispatch_timer, s, &s->timer_event_source);
|
||||
return sd_event_add_monotonic(UNIT(s)->manager->event, &s->timer_event_source, now(CLOCK_MONOTONIC) + usec, 0, service_dispatch_timer, s);
|
||||
}
|
||||
|
||||
#ifdef HAVE_SYSV_COMPAT
|
||||
|
||||
+2
-2
@@ -175,7 +175,7 @@ static int socket_arm_timer(Socket *s) {
|
||||
return sd_event_source_set_enabled(s->timer_event_source, SD_EVENT_ONESHOT);
|
||||
}
|
||||
|
||||
return sd_event_add_monotonic(UNIT(s)->manager->event, now(CLOCK_MONOTONIC) + s->timeout_usec, 0, socket_dispatch_timer, s, &s->timer_event_source);
|
||||
return sd_event_add_monotonic(UNIT(s)->manager->event, &s->timer_event_source, now(CLOCK_MONOTONIC) + s->timeout_usec, 0, socket_dispatch_timer, s);
|
||||
}
|
||||
|
||||
static int socket_instantiate_service(Socket *s) {
|
||||
@@ -1112,7 +1112,7 @@ static int socket_watch_fds(Socket *s) {
|
||||
if (p->event_source)
|
||||
r = sd_event_source_set_enabled(p->event_source, SD_EVENT_ON);
|
||||
else
|
||||
r = sd_event_add_io(UNIT(s)->manager->event, p->fd, EPOLLIN, socket_dispatch_io, p, &p->event_source);
|
||||
r = sd_event_add_io(UNIT(s)->manager->event, &p->event_source, p->fd, EPOLLIN, socket_dispatch_io, p);
|
||||
|
||||
if (r < 0) {
|
||||
log_warning_unit(UNIT(s)->id, "Failed to watch listening fds: %s", strerror(-r));
|
||||
|
||||
+2
-2
@@ -184,7 +184,7 @@ static int swap_arm_timer(Swap *s) {
|
||||
return sd_event_source_set_enabled(s->timer_event_source, SD_EVENT_ONESHOT);
|
||||
}
|
||||
|
||||
return sd_event_add_monotonic(UNIT(s)->manager->event, now(CLOCK_MONOTONIC) + s->timeout_usec, 0, swap_dispatch_timer, s, &s->timer_event_source);
|
||||
return sd_event_add_monotonic(UNIT(s)->manager->event, &s->timer_event_source, now(CLOCK_MONOTONIC) + s->timeout_usec, 0, swap_dispatch_timer, s);
|
||||
}
|
||||
|
||||
static int swap_add_device_links(Swap *s) {
|
||||
@@ -1270,7 +1270,7 @@ static int swap_enumerate(Manager *m) {
|
||||
if (!m->proc_swaps)
|
||||
return errno == ENOENT ? 0 : -errno;
|
||||
|
||||
r = sd_event_add_io(m->event, fileno(m->proc_swaps), EPOLLPRI, swap_dispatch_io, m, &m->swap_event_source);
|
||||
r = sd_event_add_io(m->event, &m->swap_event_source, fileno(m->proc_swaps), EPOLLPRI, swap_dispatch_io, m);
|
||||
if (r < 0)
|
||||
goto fail;
|
||||
|
||||
|
||||
+2
-2
@@ -350,7 +350,7 @@ static void timer_enter_waiting(Timer *t, bool initial) {
|
||||
|
||||
r = sd_event_source_set_enabled(t->monotonic_event_source, SD_EVENT_ONESHOT);
|
||||
} else
|
||||
r = sd_event_add_monotonic(UNIT(t)->manager->event, t->next_elapse_monotonic, t->accuracy_usec, timer_dispatch, t, &t->monotonic_event_source);
|
||||
r = sd_event_add_monotonic(UNIT(t)->manager->event, &t->monotonic_event_source, t->next_elapse_monotonic, t->accuracy_usec, timer_dispatch, t);
|
||||
|
||||
if (r < 0)
|
||||
goto fail;
|
||||
@@ -376,7 +376,7 @@ static void timer_enter_waiting(Timer *t, bool initial) {
|
||||
|
||||
r = sd_event_source_set_enabled(t->realtime_event_source, SD_EVENT_ONESHOT);
|
||||
} else
|
||||
r = sd_event_add_realtime(UNIT(t)->manager->event, t->next_elapse_realtime, t->accuracy_usec, timer_dispatch, t, &t->realtime_event_source);
|
||||
r = sd_event_add_realtime(UNIT(t)->manager->event, &t->realtime_event_source, t->next_elapse_realtime, t->accuracy_usec, timer_dispatch, t);
|
||||
|
||||
if (r < 0)
|
||||
goto fail;
|
||||
|
||||
Reference in New Issue
Block a user