automount_send_ready(a, -EHOSTDOWN);
a->pipe_event_source = sd_event_source_unref(a->pipe_event_source);
-
- close_nointr_nofail(a->pipe_fd);
- a->pipe_fd = -1;
+ a->pipe_fd = safe_close(a->pipe_fd);
/* If we reload/reexecute things we keep the mount point
* around */
static int automount_verify(Automount *a) {
bool b;
- char *e;
+ _cleanup_free_ char *e = NULL;
assert(a);
if (UNIT(a)->load_state != UNIT_LOADED)
return -ENOMEM;
b = unit_has_name(UNIT(a), e);
- free(e);
if (!b) {
log_error_unit(UNIT(a)->id, "%s's Where setting doesn't match unit name. Refusing.", UNIT(a)->id);
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;
}
init_autofs_dev_ioctl(¶m);
if (ioctl(m->dev_autofs_fd, AUTOFS_DEV_IOCTL_VERSION, ¶m) < 0) {
- close_nointr_nofail(m->dev_autofs_fd);
- m->dev_autofs_fd = -1;
+ m->dev_autofs_fd = safe_close(m->dev_autofs_fd);
return -errno;
}
}
int automount_send_ready(Automount *a, int status) {
- int ioctl_fd, r;
+ _cleanup_close_ int ioctl_fd = -1;
unsigned token;
+ int r;
assert(a);
assert(status <= 0);
return 0;
ioctl_fd = open_ioctl_fd(UNIT(a)->manager->dev_autofs_fd, a->where, a->dev_id);
- if (ioctl_fd < 0) {
- r = ioctl_fd;
- goto fail;
- }
+ if (ioctl_fd < 0)
+ return ioctl_fd;
if (status)
log_debug_unit(UNIT(a)->id, "Sending failure: %s", strerror(-status));
r = k;
}
-fail:
- if (ioctl_fd >= 0)
- close_nointr_nofail(ioctl_fd);
-
return r;
}
static void automount_enter_waiting(Automount *a) {
+ _cleanup_close_ int ioctl_fd = -1;
int p[2] = { -1, -1 };
char name[32], options[128];
bool mounted = false;
- int r, ioctl_fd = -1, dev_autofs_fd;
+ int r, dev_autofs_fd;
struct stat st;
assert(a);
mounted = true;
- close_nointr_nofail(p[1]);
- p[1] = -1;
+ p[1] = safe_close(p[1]);
if (stat(a->where, &st) < 0) {
r = -errno;
* the direct mount will not receive events from the
* kernel. */
- 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;
return;
fail:
- assert_se(close_pipe(p) == 0);
-
- if (ioctl_fd >= 0)
- close_nointr_nofail(ioctl_fd);
+ safe_close_pair(p);
if (mounted)
repeat_unmount(a->where);
if (safe_atoi(value, &fd) < 0 || fd < 0 || !fdset_contains(fds, fd))
log_debug_unit(u->id, "Failed to parse pipe-fd value %s", value);
else {
- if (a->pipe_fd >= 0)
- close_nointr_nofail(a->pipe_fd);
-
+ safe_close(a->pipe_fd);
a->pipe_fd = fdset_remove(fds, fd);
}
} else
get_process_comm(packet.v5_packet.pid, &p);
log_info_unit(UNIT(a)->id,
- "Got automount request for %s, triggered by %lu (%s)",
- a->where, (unsigned long) packet.v5_packet.pid, strna(p));
+ "Got automount request for %s, triggered by "PID_FMT" (%s)",
+ a->where, packet.v5_packet.pid, strna(p));
} else
log_debug_unit(UNIT(a)->id, "Got direct mount request on %s", a->where);
static void automount_shutdown(Manager *m) {
assert(m);
- if (m->dev_autofs_fd >= 0)
- close_nointr_nofail(m->dev_autofs_fd);
+ m->dev_autofs_fd = safe_close(m->dev_autofs_fd);
}
static void automount_reset_failed(Unit *u) {