#include "bus-error.h"
#include "bus-util.h"
#include "dbus-automount.h"
+#include "dbus-unit.h"
#include "fd-util.h"
#include "format-util.h"
#include "io-util.h"
#include "mkdir.h"
#include "mount-util.h"
#include "mount.h"
+#include "mountpoint-util.h"
#include "parse-util.h"
#include "path-util.h"
#include "process-util.h"
int ioctl_fd;
};
-static inline void expire_data_free(struct expire_data *data) {
+static void expire_data_free(struct expire_data *data) {
if (!data)
return;
int r;
assert(a);
-
- if (UNIT(a)->load_state != UNIT_LOADED)
- return 0;
+ assert(UNIT(a)->load_state == UNIT_LOADED);
if (path_equal(a->where, "/")) {
log_unit_error(UNIT(a), "Cannot have an automount unit for the root directory. Refusing.");
return 1;
}
+static int automount_add_extras(Automount *a) {
+ int r;
+
+ r = automount_set_where(a);
+ if (r < 0)
+ return r;
+
+ r = automount_add_trigger_dependencies(a);
+ if (r < 0)
+ return r;
+
+ r = automount_add_mount_dependencies(a);
+ if (r < 0)
+ return r;
+
+ return automount_add_default_dependencies(a);
+}
+
static int automount_load(Unit *u) {
Automount *a = AUTOMOUNT(u);
int r;
assert(u->load_state == UNIT_STUB);
/* Load a .automount file */
- r = unit_load_fragment_and_dropin(u);
+ r = unit_load_fragment_and_dropin(u, true);
if (r < 0)
return r;
- if (u->load_state == UNIT_LOADED) {
- r = automount_set_where(a);
- if (r < 0)
- return r;
-
- r = automount_add_trigger_dependencies(a);
- if (r < 0)
- return r;
-
- r = automount_add_mount_dependencies(a);
- if (r < 0)
- return r;
+ if (u->load_state != UNIT_LOADED)
+ return 0;
- r = automount_add_default_dependencies(a);
- if (r < 0)
- return r;
- }
+ r = automount_add_extras(a);
+ if (r < 0)
+ return r;
return automount_verify(a);
}
AutomountState old_state;
assert(a);
+ if (a->state != state)
+ bus_unit_send_pending_change_signal(UNIT(a), false);
+
old_state = a->state;
a->state = state;
if (a->result == AUTOMOUNT_SUCCESS)
a->result = f;
- if (a->result == AUTOMOUNT_SUCCESS)
- unit_log_success(UNIT(a));
- else
- unit_log_failure(UNIT(a), automount_result_to_string(a->result));
-
+ unit_log_result(UNIT(a), a->result == AUTOMOUNT_SUCCESS, automount_result_to_string(a->result));
automount_set_state(a, a->result != AUTOMOUNT_SUCCESS ? AUTOMOUNT_FAILED : AUTOMOUNT_DEAD);
}
if (r < 0)
goto fail;
- (void) mkdir_p_label(a->where, 0555);
+ (void) mkdir_p_label(a->where, a->directory_mode);
unit_warn_if_dir_nonempty(UNIT(a), a->where);
goto fail;
}
- if (pipe2(p, O_NONBLOCK|O_CLOEXEC) < 0) {
+ if (pipe2(p, O_CLOEXEC) < 0) {
r = -errno;
goto fail;
}
+ r = fd_nonblock(p[0], true);
+ if (r < 0)
+ goto fail;
xsprintf(options, "fd=%i,pgrp="PID_FMT",minproto=5,maxproto=5,direct", p[1], getpgrp());
xsprintf(name, "systemd-"PID_FMT, getpid_cached());
return;
}
- mkdir_p_label(a->where, a->directory_mode);
+ (void) mkdir_p_label(a->where, a->directory_mode);
/* Before we do anything, let's see if somebody is playing games with us? */
if (lstat(a->where, &st) < 0) {
goto fail;
}
- r = manager_add_job(UNIT(a)->manager, JOB_START, trigger, JOB_REPLACE, &error, NULL);
+ r = manager_add_job(UNIT(a)->manager, JOB_START, trigger, JOB_REPLACE, NULL, &error, NULL);
if (r < 0) {
log_unit_warning(UNIT(a), "Failed to queue mount startup job: %s", bus_error_message(&error, r));
goto fail;
static int automount_start(Unit *u) {
Automount *a = AUTOMOUNT(u);
- Unit *trigger;
int r;
assert(a);
return -EEXIST;
}
- trigger = UNIT_TRIGGER(u);
- if (!trigger || trigger->load_state != UNIT_LOADED) {
- log_unit_error(u, "Refusing to start, unit to trigger not loaded.");
- return -ENOENT;
- }
+ r = unit_test_trigger_loaded(u);
+ if (r < 0)
+ return r;
- r = unit_start_limit_test(u);
+ r = unit_test_start_limit(u);
if (r < 0) {
automount_enter_dead(a, AUTOMOUNT_FAILURE_START_LIMIT_HIT);
return r;
goto fail;
}
- r = manager_add_job(UNIT(a)->manager, JOB_STOP, trigger, JOB_REPLACE, &error, NULL);
+ r = manager_add_job(UNIT(a)->manager, JOB_STOP, trigger, JOB_REPLACE, NULL, &error, NULL);
if (r < 0) {
log_unit_warning(UNIT(a), "Failed to queue umount startup job: %s", bus_error_message(&error, r));
goto fail;