/* SPDX-License-Identifier: LGPL-2.1+ */
-/***
- This file is part of systemd.
-
- Copyright 2010 Lennart Poettering
-***/
#include <errno.h>
#include <sys/epoll.h>
if (!unit_has_name(UNIT(s), e)) {
log_unit_error(UNIT(s), "Value of What= and unit name do not match, not loading.");
- return -EINVAL;
+ return -ENOEXEC;
}
if (s->exec_context.pam_name && s->kill_context.kill_mode != KILL_CONTROL_GROUP) {
log_unit_error(UNIT(s), "Unit has PAM enabled. Kill mode must be set to 'control-group'. Refusing to load.");
- return -EINVAL;
+ return -ENOEXEC;
}
return 0;
_cleanup_(udev_device_unrefp) struct udev_device *d = NULL;
struct stat st;
const char *p;
+ int r;
assert(s);
if (stat(s->what, &st) < 0 || !S_ISBLK(st.st_mode))
return 0;
- d = udev_device_new_from_devnum(UNIT(s)->manager->udev, 'b', st.st_rdev);
- if (!d)
+ r = udev_device_new_from_stat_rdev(UNIT(s)->manager->udev, &st, &d);
+ if (r < 0) {
+ log_unit_full(UNIT(s), r == -ENOENT ? LOG_DEBUG : LOG_WARNING, r,
+ "Failed to allocate udev device for swap %s: %m", s->what);
return 0;
+ }
p = udev_device_get_devnode(d);
if (!p)
return -ENOMEM;
}
- path_kill_slashes(s->what);
+ path_simplify(s->what, false);
if (!UNIT(s)->description) {
r = unit_set_description(u, s->what);
if (stat(device, &st) < 0 || !S_ISBLK(st.st_mode))
return 0;
- d = udev_device_new_from_devnum(m->udev, 'b', st.st_rdev);
- if (!d)
+ r = udev_device_new_from_stat_rdev(m->udev, &st, &d);
+ if (r < 0) {
+ log_full_errno(r == -ENOENT ? LOG_DEBUG : LOG_WARNING, r,
+ "Failed to allocate udev device for swap %s: %m", device);
return 0;
+ }
/* Add the main device node */
dn = udev_device_get_devnode(d);
if (state != old_state)
log_unit_debug(UNIT(s), "Changed %s -> %s", swap_state_to_string(old_state), swap_state_to_string(state));
- unit_notify(UNIT(s), state_translation_table[old_state], state_translation_table[state], true);
+ unit_notify(UNIT(s), state_translation_table[old_state], state_translation_table[state], 0);
/* If there other units for the same device node have a job
queued it might be worth checking again if it is runnable
.stdin_fd = -1,
.stdout_fd = -1,
.stderr_fd = -1,
+ .exec_fd = -1,
};
pid_t pid;
int r;
return r;
s->result = SWAP_SUCCESS;
+ exec_command_reset_status_array(s->exec_command, _SWAP_EXEC_COMMAND_MAX);
u->reset_accounting = true;
if (cunescape(dev, UNESCAPE_RELAX, &d) < 0)
return log_oom();
- device_found_node(m, d, true, DEVICE_FOUND_SWAP, set_flags);
+ device_found_node(m, d, DEVICE_FOUND_SWAP, DEVICE_FOUND_SWAP);
k = swap_process_new(m, d, prio, set_flags);
if (k < 0)
}
if (swap->what)
- device_found_node(m, swap->what, false, DEVICE_FOUND_SWAP, true);
+ device_found_node(m, swap->what, 0, DEVICE_FOUND_SWAP);
} else if (swap->just_activated) {
assert(m);
m->swap_event_source = sd_event_source_unref(m->swap_event_source);
-
m->proc_swaps = safe_fclose(m->proc_swaps);
-
m->swaps_by_devnode = hashmap_free(m->swaps_by_devnode);
}
m->proc_swaps = fopen("/proc/swaps", "re");
if (!m->proc_swaps) {
if (errno == ENOENT)
- log_debug("Not swap enabled, skipping enumeration");
+ log_debug_errno(errno, "Not swap enabled, skipping enumeration.");
else
- log_error_errno(errno, "Failed to open /proc/swaps: %m");
+ log_warning_errno(errno, "Failed to open /proc/swaps, ignoring: %m");
return;
}