[systemd-commits] 2 commits - src/core src/fsck src/journal src/libsystemd src/machine src/nspawn src/shared src/socket-proxy src/systemctl src/test
Lennart Poettering
lennart at kemper.freedesktop.org
Sun Mar 23 19:51:19 PDT 2014
src/core/automount.c | 2
src/core/dbus-timer.c | 2
src/core/execute.c | 4 -
src/core/manager.c | 4 -
src/fsck/fsck.c | 2
src/journal/journal-remote.c | 6 --
src/libsystemd/sd-bus/bus-container.c | 2
src/libsystemd/sd-bus/bus-socket.c | 2
src/libsystemd/sd-bus/test-bus-chat.c | 2
src/libsystemd/sd-event/test-event.c | 8 +--
src/libsystemd/sd-login/test-login.c | 2
src/machine/machinectl.c | 2
src/nspawn/nspawn.c | 2
src/shared/logs-show.c | 2
src/shared/pager.c | 6 +-
src/shared/util.c | 20 +++------
src/shared/util.h | 8 +--
src/socket-proxy/socket-proxyd.c | 4 -
src/systemctl/systemctl.c | 74 ++++++++++++++++++++++++++++------
src/test/test-namespace.c | 2
20 files changed, 102 insertions(+), 54 deletions(-)
New commits:
commit d784e2dbac20d7aa6c2da82d6267173b58c55df8
Author: Lennart Poettering <lennart at poettering.net>
Date: Mon Mar 24 03:42:17 2014 +0100
systemctl: show last trigger time in "systemctl list-timers"
diff --git a/src/core/dbus-timer.c b/src/core/dbus-timer.c
index f7af699..c9b80a0 100644
--- a/src/core/dbus-timer.c
+++ b/src/core/dbus-timer.c
@@ -142,6 +142,8 @@ const sd_bus_vtable bus_timer_vtable[] = {
SD_BUS_PROPERTY("TimersCalendar", "a(sst)", property_get_calendar_timers, 0, SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION),
SD_BUS_PROPERTY("NextElapseUSecRealtime", "t", bus_property_get_usec, offsetof(Timer, next_elapse_realtime), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
SD_BUS_PROPERTY("NextElapseUSecMonotonic", "t", bus_property_get_usec, offsetof(Timer, next_elapse_monotonic), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
+ SD_BUS_PROPERTY("LastTriggerUSecRealtime", "t", bus_property_get_usec, offsetof(Timer, last_trigger.realtime), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
+ SD_BUS_PROPERTY("LastTriggerUSecMonotonic", "t", bus_property_get_usec, offsetof(Timer, last_trigger.monotonic), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
SD_BUS_PROPERTY("Result", "s", property_get_result, offsetof(Timer, result), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
SD_BUS_PROPERTY("AccuracyUSec", "t", bus_property_get_usec, offsetof(Timer, accuracy_usec), SD_BUS_VTABLE_PROPERTY_CONST),
SD_BUS_PROPERTY("Persistent", "b", bus_property_get_bool, offsetof(Timer, persistent), SD_BUS_VTABLE_PROPERTY_CONST),
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index 5a5681b..cceb2b6 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -947,9 +947,39 @@ static int get_next_elapse(
return 0;
}
+static int get_last_trigger(
+ sd_bus *bus,
+ const char *path,
+ usec_t *last) {
+
+ _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
+ int r;
+
+ assert(bus);
+ assert(path);
+ assert(last);
+
+ r = sd_bus_get_property_trivial(
+ bus,
+ "org.freedesktop.systemd1",
+ path,
+ "org.freedesktop.systemd1.Timer",
+ "LastTriggerUSecRealtime",
+ &error,
+ 't',
+ last);
+ if (r < 0) {
+ log_error("Failed to get last trigger time: %s", bus_error_message(&error, r));
+ return r;
+ }
+
+ return 0;
+}
+
struct timer_info {
const char* id;
usec_t next_elapse;
+ usec_t last_trigger;
char** triggered;
};
@@ -970,6 +1000,8 @@ static int output_timers_list(struct timer_info *timer_infos, unsigned n) {
unsigned
nextlen = strlen("NEXT"),
leftlen = strlen("LEFT"),
+ lastlen = strlen("LAST"),
+ passedlen = strlen("PASSED"),
unitlen = strlen("UNIT"),
activatelen = strlen("ACTIVATES");
@@ -991,30 +1023,47 @@ static int output_timers_list(struct timer_info *timer_infos, unsigned n) {
leftlen = MAX(leftlen, strlen(trel));
}
+ if (t->last_trigger > 0) {
+ char tstamp[FORMAT_TIMESTAMP_MAX] = "", trel[FORMAT_TIMESTAMP_RELATIVE_MAX] = "";
+
+ format_timestamp(tstamp, sizeof(tstamp), t->last_trigger);
+ lastlen = MAX(lastlen, strlen(tstamp) + 1);
+
+ format_timestamp_relative(trel, sizeof(trel), t->last_trigger);
+ passedlen = MAX(passedlen, strlen(trel));
+ }
+
unitlen = MAX(unitlen, strlen(t->id));
STRV_FOREACH(a, t->triggered)
ul += strlen(*a) + 2*(a != t->triggered);
+
activatelen = MAX(activatelen, ul);
}
if (n > 0) {
if (!arg_no_legend)
- printf("%-*s %-*s %-*s %s\n",
- nextlen, "NEXT",
- leftlen, "LEFT",
- unitlen, "UNIT",
- "ACTIVATES");
+ printf("%-*s %-*s %-*s %-*s %-*s %s\n",
+ nextlen, "NEXT",
+ leftlen, "LEFT",
+ lastlen, "LAST",
+ passedlen, "PASSED",
+ unitlen, "UNIT",
+ "ACTIVATES");
for (t = timer_infos; t < timer_infos + n; t++) {
- char tstamp[FORMAT_TIMESTAMP_MAX] = "n/a", trel[FORMAT_TIMESTAMP_RELATIVE_MAX] = "n/a";
+ char tstamp1[FORMAT_TIMESTAMP_MAX] = "n/a", trel1[FORMAT_TIMESTAMP_RELATIVE_MAX] = "n/a";
+ char tstamp2[FORMAT_TIMESTAMP_MAX] = "n/a", trel2[FORMAT_TIMESTAMP_RELATIVE_MAX] = "n/a";
char **a;
- format_timestamp(tstamp, sizeof(tstamp), t->next_elapse);
- format_timestamp_relative(trel, sizeof(trel), t->next_elapse);
+ format_timestamp(tstamp1, sizeof(tstamp1), t->next_elapse);
+ format_timestamp_relative(trel1, sizeof(trel1), t->next_elapse);
- printf("%-*s %-*s %-*s",
- nextlen, tstamp, leftlen, trel, unitlen, t->id);
+ format_timestamp(tstamp2, sizeof(tstamp2), t->last_trigger);
+ format_timestamp_relative(trel2, sizeof(trel2), t->last_trigger);
+
+ printf("%-*s %-*s %-*s %-*s %-*s",
+ nextlen, tstamp1, leftlen, trel1, lastlen, tstamp2, passedlen, trel2, unitlen, t->id);
STRV_FOREACH(a, t->triggered)
printf("%s %s",
@@ -1088,7 +1137,7 @@ static int list_timers(sd_bus *bus, char **args) {
for (u = unit_infos; u < unit_infos + n; u++) {
_cleanup_strv_free_ char **triggered = NULL;
dual_timestamp next = {};
- usec_t m;
+ usec_t m, last = 0;
if (!endswith(u->id, ".timer"))
continue;
@@ -1101,6 +1150,8 @@ static int list_timers(sd_bus *bus, char **args) {
if (r < 0)
goto cleanup;
+ get_last_trigger(bus, u->unit_path, &last);
+
if (!GREEDY_REALLOC(timer_infos, size, c+1)) {
r = log_oom();
goto cleanup;
@@ -1111,6 +1162,7 @@ static int list_timers(sd_bus *bus, char **args) {
timer_infos[c++] = (struct timer_info) {
.id = u->id,
.next_elapse = m,
+ .last_trigger = last,
.triggered = triggered,
};
commit 3d94f76c99da13e5603831d0b278f8c8c21bcb02
Author: Lennart Poettering <lennart at poettering.net>
Date: Mon Mar 24 03:22:44 2014 +0100
util: replace close_pipe() with new safe_close_pair()
safe_close_pair() is more like safe_close(), except that it handles
pairs of fds, and doesn't make and misleading allusion, as it works
similarly well for socketpairs() as for pipe()s...
diff --git a/src/core/automount.c b/src/core/automount.c
index 77d80b2..65e6d6f 100644
--- a/src/core/automount.c
+++ b/src/core/automount.c
@@ -532,7 +532,7 @@ static void automount_enter_waiting(Automount *a) {
return;
fail:
- close_pipe(p);
+ safe_close_pair(p);
if (mounted)
repeat_unmount(a->where);
diff --git a/src/core/execute.c b/src/core/execute.c
index a46f25d..353f2d1 100644
--- a/src/core/execute.c
+++ b/src/core/execute.c
@@ -2629,7 +2629,7 @@ ExecRuntime *exec_runtime_unref(ExecRuntime *r) {
if (r->n_ref <= 0) {
free(r->tmp_dir);
free(r->var_tmp_dir);
- close_pipe(r->netns_storage_socket);
+ safe_close_pair(r->netns_storage_socket);
free(r);
}
@@ -2781,7 +2781,7 @@ void exec_runtime_destroy(ExecRuntime *rt) {
rt->var_tmp_dir = NULL;
}
- close_pipe(rt->netns_storage_socket);
+ safe_close_pair(rt->netns_storage_socket);
}
static const char* const exec_input_table[_EXEC_INPUT_MAX] = {
diff --git a/src/core/manager.c b/src/core/manager.c
index 360a65a..a3ff85c 100644
--- a/src/core/manager.c
+++ b/src/core/manager.c
@@ -225,8 +225,8 @@ static int manager_watch_idle_pipe(Manager *m) {
static void manager_close_idle_pipe(Manager *m) {
assert(m);
- close_pipe(m->idle_pipe);
- close_pipe(m->idle_pipe + 2);
+ safe_close_pair(m->idle_pipe);
+ safe_close_pair(m->idle_pipe + 2);
}
static int manager_setup_time_change(Manager *m) {
diff --git a/src/fsck/fsck.c b/src/fsck/fsck.c
index f60cc1d..18f2aca 100644
--- a/src/fsck/fsck.c
+++ b/src/fsck/fsck.c
@@ -374,7 +374,7 @@ int main(int argc, char *argv[]) {
touch("/run/systemd/quotacheck");
finish:
- close_pipe(progress_pipe);
+ safe_close_pair(progress_pipe);
return r;
}
diff --git a/src/journal/journal-remote.c b/src/journal/journal-remote.c
index 4697356..4ece14e 100644
--- a/src/journal/journal-remote.c
+++ b/src/journal/journal-remote.c
@@ -89,7 +89,7 @@ static int spawn_child(const char* child, char** argv) {
if (child_pid < 0) {
r = -errno;
log_error("Failed to fork: %m");
- close_pipe(fd);
+ safe_close_pair(fd);
return r;
}
@@ -101,9 +101,7 @@ static int spawn_child(const char* child, char** argv) {
_exit(EXIT_FAILURE);
}
- r = close_pipe(fd);
- if (r < 0)
- log_warning("Failed to close pipe fds: %m");
+ safe_close_pair(fd);
/* Make sure the child goes away when the parent dies */
if (prctl(PR_SET_PDEATHSIG, SIGTERM) < 0)
diff --git a/src/libsystemd/sd-bus/bus-container.c b/src/libsystemd/sd-bus/bus-container.c
index 2cd0e1f..6bd7ad6 100644
--- a/src/libsystemd/sd-bus/bus-container.c
+++ b/src/libsystemd/sd-bus/bus-container.c
@@ -116,7 +116,7 @@ int bus_container_connect_socket(sd_bus *b) {
}
int bus_container_connect_kernel(sd_bus *b) {
- _cleanup_close_pipe_ int pair[2] = { -1, -1 };
+ _cleanup_close_pair_ int pair[2] = { -1, -1 };
_cleanup_close_ int pidnsfd = -1, mntnsfd = -1, rootfd = -1;
union {
struct cmsghdr cmsghdr;
diff --git a/src/libsystemd/sd-bus/bus-socket.c b/src/libsystemd/sd-bus/bus-socket.c
index bccf501..2e8f008 100644
--- a/src/libsystemd/sd-bus/bus-socket.c
+++ b/src/libsystemd/sd-bus/bus-socket.c
@@ -736,7 +736,7 @@ int bus_socket_exec(sd_bus *b) {
pid = fork();
if (pid < 0) {
- close_pipe(s);
+ safe_close_pair(s);
return -errno;
}
if (pid == 0) {
diff --git a/src/libsystemd/sd-bus/test-bus-chat.c b/src/libsystemd/sd-bus/test-bus-chat.c
index 1b9d98f..c0abc7a 100644
--- a/src/libsystemd/sd-bus/test-bus-chat.c
+++ b/src/libsystemd/sd-bus/test-bus-chat.c
@@ -356,7 +356,7 @@ finish:
sd_bus_error_free(&error);
- close_pipe(pp);
+ safe_close_pair(pp);
return INT_TO_PTR(r);
}
diff --git a/src/libsystemd/sd-event/test-event.c b/src/libsystemd/sd-event/test-event.c
index 68bb2b0..3342ec6 100644
--- a/src/libsystemd/sd-event/test-event.c
+++ b/src/libsystemd/sd-event/test-event.c
@@ -239,10 +239,10 @@ int main(int argc, char *argv[]) {
sd_event_unref(e);
- close_pipe(a);
- close_pipe(b);
- close_pipe(d);
- close_pipe(k);
+ safe_close_pair(a);
+ safe_close_pair(b);
+ safe_close_pair(d);
+ safe_close_pair(k);
return 0;
}
diff --git a/src/libsystemd/sd-login/test-login.c b/src/libsystemd/sd-login/test-login.c
index 2ab083b..9e326de 100644
--- a/src/libsystemd/sd-login/test-login.c
+++ b/src/libsystemd/sd-login/test-login.c
@@ -28,7 +28,7 @@
#include "strv.h"
static void test_login(void) {
- _cleanup_close_pipe_ int pair[2] = { -1, -1 };
+ _cleanup_close_pair_ int pair[2] = { -1, -1 };
_cleanup_free_ char *pp = NULL, *qq = NULL;
int r, k;
uid_t u, u2;
diff --git a/src/machine/machinectl.c b/src/machine/machinectl.c
index d812ef2..6337aa2 100644
--- a/src/machine/machinectl.c
+++ b/src/machine/machinectl.c
@@ -412,7 +412,7 @@ static int terminate_machine(sd_bus *bus, char **args, unsigned n) {
}
static int openpt_in_namespace(pid_t pid, int flags) {
- _cleanup_close_pipe_ int pair[2] = { -1, -1 };
+ _cleanup_close_pair_ int pair[2] = { -1, -1 };
_cleanup_close_ int pidnsfd = -1, mntnsfd = -1, rootfd = -1;
union {
struct cmsghdr cmsghdr;
diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c
index 2d627db..9a9ed9d 100644
--- a/src/nspawn/nspawn.c
+++ b/src/nspawn/nspawn.c
@@ -2582,7 +2582,7 @@ int main(int argc, char *argv[]) {
_cleanup_free_ char *kdbus_domain = NULL, *device_path = NULL, *root_device = NULL, *home_device = NULL, *srv_device = NULL;
bool root_device_rw = true, home_device_rw = true, srv_device_rw = true;
_cleanup_close_ int master = -1, kdbus_fd = -1, image_fd = -1;
- _cleanup_close_pipe_ int kmsg_socket_pair[2] = { -1, -1 };
+ _cleanup_close_pair_ int kmsg_socket_pair[2] = { -1, -1 };
_cleanup_fdset_free_ FDSet *fds = NULL;
int r = EXIT_FAILURE, k, n_fd_passed, loop_nr = -1;
const char *console = NULL;
diff --git a/src/shared/logs-show.c b/src/shared/logs-show.c
index df49375..9d14933 100644
--- a/src/shared/logs-show.c
+++ b/src/shared/logs-show.c
@@ -1139,7 +1139,7 @@ int add_matches_for_user_unit(sd_journal *j, const char *unit, uid_t uid) {
}
static int get_boot_id_for_machine(const char *machine, sd_id128_t *boot_id) {
- _cleanup_close_pipe_ int pair[2] = { -1, -1 };
+ _cleanup_close_pair_ int pair[2] = { -1, -1 };
_cleanup_close_ int pidnsfd = -1, mntnsfd = -1, rootfd = -1;
pid_t pid, child;
siginfo_t si;
diff --git a/src/shared/pager.c b/src/shared/pager.c
index 55b13d6..002e3aa 100644
--- a/src/shared/pager.c
+++ b/src/shared/pager.c
@@ -78,7 +78,7 @@ int pager_open(bool jump_to_end) {
if (pager_pid < 0) {
r = -errno;
log_error("Failed to fork pager: %m");
- close_pipe(fd);
+ safe_close_pair(fd);
return r;
}
@@ -87,7 +87,7 @@ int pager_open(bool jump_to_end) {
const char* less_opts;
dup2(fd[0], STDIN_FILENO);
- close_pipe(fd);
+ safe_close_pair(fd);
less_opts = getenv("SYSTEMD_LESS");
if (!less_opts)
@@ -131,7 +131,7 @@ int pager_open(bool jump_to_end) {
return -errno;
}
- close_pipe(fd);
+ safe_close_pair(fd);
return 1;
}
diff --git a/src/shared/util.c b/src/shared/util.c
index a8c4523..dd67c22 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -2037,22 +2037,18 @@ int default_signals(int sig, ...) {
return r;
}
-int close_pipe(int p[]) {
- int a = 0, b = 0;
-
+void safe_close_pair(int p[]) {
assert(p);
- if (p[0] >= 0) {
- a = close_nointr(p[0]);
- p[0] = -1;
- }
-
- if (p[1] >= 0) {
- b = close_nointr(p[1]);
- p[1] = -1;
+ if (p[0] == p[1]) {
+ /* Special case pairs which use the same fd in both
+ * directions... */
+ p[0] = p[1] = safe_close(p[0]);
+ return;
}
- return a < 0 ? a : b;
+ p[0] = safe_close(p[0]);
+ p[1] = safe_close(p[1]);
}
ssize_t loop_read(int fd, void *buf, size_t nbytes, bool do_poll) {
diff --git a/src/shared/util.h b/src/shared/util.h
index 70c20fd..90464c9 100644
--- a/src/shared/util.h
+++ b/src/shared/util.h
@@ -150,6 +150,7 @@ bool first_word(const char *s, const char *word) _pure_;
int close_nointr(int fd);
int safe_close(int fd);
+void safe_close_pair(int p[]);
void close_many(const int fds[], unsigned n_fd);
@@ -378,7 +379,6 @@ int ignore_signals(int sig, ...);
int default_signals(int sig, ...);
int sigaction_many(const struct sigaction *sa, ...);
-int close_pipe(int p[]);
int fopen_temporary(const char *path, FILE **_f, char **_temp_path);
ssize_t loop_read(int fd, void *buf, size_t nbytes, bool do_poll);
@@ -628,8 +628,8 @@ static inline void umaskp(mode_t *u) {
umask(*u);
}
-static inline void close_pipep(int (*p)[2]) {
- close_pipe(*p);
+static inline void close_pairp(int (*p)[2]) {
+ safe_close_pair(*p);
}
DEFINE_TRIVIAL_CLEANUP_FUNC(FILE*, fclose);
@@ -645,7 +645,7 @@ DEFINE_TRIVIAL_CLEANUP_FUNC(FILE*, endmntent);
#define _cleanup_pclose_ _cleanup_(pclosep)
#define _cleanup_closedir_ _cleanup_(closedirp)
#define _cleanup_endmntent_ _cleanup_(endmntentp)
-#define _cleanup_close_pipe_ _cleanup_(close_pipep)
+#define _cleanup_close_pair_ _cleanup_(close_pairp)
_malloc_ _alloc_(1, 2) static inline void *malloc_multiply(size_t a, size_t b) {
if (_unlikely_(b == 0 || a > ((size_t) -1) / b))
diff --git a/src/socket-proxy/socket-proxyd.c b/src/socket-proxy/socket-proxyd.c
index c172beb..ac47c85 100644
--- a/src/socket-proxy/socket-proxyd.c
+++ b/src/socket-proxy/socket-proxyd.c
@@ -79,8 +79,8 @@ static void connection_free(Connection *c) {
safe_close(c->server_fd);
safe_close(c->client_fd);
- close_pipe(c->server_to_client_buffer);
- close_pipe(c->client_to_server_buffer);
+ safe_close_pair(c->server_to_client_buffer);
+ safe_close_pair(c->client_to_server_buffer);
free(c);
}
diff --git a/src/test/test-namespace.c b/src/test/test-namespace.c
index 5b76b9e..e74fd0c 100644
--- a/src/test/test-namespace.c
+++ b/src/test/test-namespace.c
@@ -63,7 +63,7 @@ static void test_tmpdir(const char *id, const char *A, const char *B) {
}
static void test_netns(void) {
- _cleanup_close_pipe_ int s[2] = { -1, -1 };
+ _cleanup_close_pair_ int s[2] = { -1, -1 };
pid_t pid1, pid2, pid3;
int r, n = 0;
siginfo_t si;
More information about the systemd-commits
mailing list