summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2014-01-12 15:55:10 -0500
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2014-02-08 13:07:39 -0500
commit2ba110900aca729f7d511c185b62149c4a28a293 (patch)
treef390dcbeb0f646aaa46e8e7f7906d514dff9bfb8
parent550a40eceb7d1917152fc9317bf2696708d52bc2 (diff)
core: use automatic cleanup in two functions
-rw-r--r--src/core/manager.c48
1 files changed, 13 insertions, 35 deletions
diff --git a/src/core/manager.c b/src/core/manager.c
index b58b98c137..dbe08f930f 100644
--- a/src/core/manager.c
+++ b/src/core/manager.c
@@ -1916,7 +1916,7 @@ int manager_get_job_from_dbus_path(Manager *m, const char *s, Job **_j) {
void manager_send_unit_audit(Manager *m, Unit *u, int type, bool success) {
#ifdef HAVE_AUDIT
- char *p;
+ _cleanup_free_ char *p = NULL;
int audit_fd;
audit_fd = get_audit_fd();
@@ -1949,17 +1949,19 @@ void manager_send_unit_audit(Manager *m, Unit *u, int type, bool success) {
} else
log_warning("Failed to send audit message: %m");
}
-
- free(p);
#endif
}
void manager_send_unit_plymouth(Manager *m, Unit *u) {
- int fd = -1;
- union sockaddr_union sa;
+ union sockaddr_union sa = {
+ .sa.sa_family = AF_UNIX,
+ .un.sun_path = "\0/org/freedesktop/plymouthd",
+ };
+
int n = 0;
- char *message = NULL;
+ _cleanup_free_ char *message = NULL;
+ _cleanup_close_ int fd = -1;
/* Don't generate plymouth events if the service was already
* started and we're just deserializing */
@@ -1985,46 +1987,22 @@ void manager_send_unit_plymouth(Manager *m, Unit *u) {
return;
}
- zero(sa);
- sa.sa.sa_family = AF_UNIX;
- strncpy(sa.un.sun_path+1, "/org/freedesktop/plymouthd", sizeof(sa.un.sun_path)-1);
if (connect(fd, &sa.sa, offsetof(struct sockaddr_un, sun_path) + 1 + strlen(sa.un.sun_path+1)) < 0) {
- if (errno != EPIPE &&
- errno != EAGAIN &&
- errno != ENOENT &&
- errno != ECONNREFUSED &&
- errno != ECONNRESET &&
- errno != ECONNABORTED)
+ if (!IN_SET(errno, EPIPE, EAGAIN, ENOENT, ECONNREFUSED, ECONNRESET, ECONNABORTED))
log_error("connect() failed: %m");
-
- goto finish;
+ return;
}
if (asprintf(&message, "U\002%c%s%n", (int) (strlen(u->id) + 1), u->id, &n) < 0) {
log_oom();
- goto finish;
+ return;
}
errno = 0;
- if (write(fd, message, n + 1) != n + 1) {
-
- if (errno != EPIPE &&
- errno != EAGAIN &&
- errno != ENOENT &&
- errno != ECONNREFUSED &&
- errno != ECONNRESET &&
- errno != ECONNABORTED)
+ if (write(fd, message, n + 1) != n + 1)
+ if (!IN_SET(errno, EPIPE, EAGAIN, ENOENT, ECONNREFUSED, ECONNRESET, ECONNABORTED))
log_error("Failed to write Plymouth message: %m");
-
- goto finish;
- }
-
-finish:
- if (fd >= 0)
- close_nointr_nofail(fd);
-
- free(message);
}
void manager_dispatch_bus_name_owner_changed(