#include "alloc-util.h"
#include "bus-common-errors.h"
#include "bus-error.h"
+#include "bus-locator.h"
#include "bus-util.h"
#include "device-util.h"
#include "fd-util.h"
#include "path-util.h"
#include "proc-cmdline.h"
#include "process-util.h"
-#include "rlimit-util.h"
#include "signal-util.h"
#include "socket-util.h"
#include "special.h"
#include "stdio-util.h"
-#include "util.h"
static bool arg_skip = false;
static bool arg_force = false;
return;
}
- log_info("Running request %s/start/replace", target);
+ log_info("Requesting %s/start/%s", target, mode);
- /* Start these units only if we can replace base.target with it */
- r = sd_bus_call_method(bus,
- "org.freedesktop.systemd1",
- "/org/freedesktop/systemd1",
- "org.freedesktop.systemd1.Manager",
- "StartUnitReplace",
- &error,
- NULL,
- "sss", "basic.target", target, mode);
+ /* Start this unit only if we can replace basic.target with it */
+ r = bus_call_method(bus, bus_systemd_mgr, "StartUnitReplace", &error, NULL, "sss", "basic.target", target, mode);
/* Don't print a warning if we aren't called during startup */
if (r < 0 && !sd_bus_error_has_name(&error, BUS_ERROR_NO_SUCH_JOB))
p = percent(pass, cur, max);
r = fprintf(console, "\r%s: fsck %3.1f%% complete...\r", device, p);
if (r < 0)
- return -EIO; /* No point in continuing if something happend to our output stream */
+ return -EIO; /* No point in continuing if something happened to our output stream */
fflush(console);
clear = MAX(clear, r);
}
static int fsck_progress_socket(void) {
- static const union sockaddr_union sa = {
- .un.sun_family = AF_UNIX,
- .un.sun_path = "/run/systemd/fsck.progress",
- };
-
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
+ int r;
fd = socket(AF_UNIX, SOCK_STREAM, 0);
if (fd < 0)
return log_warning_errno(errno, "socket(): %m");
- if (connect(fd, &sa.sa, SOCKADDR_UN_LEN(sa.un)) < 0)
- return log_full_errno(IN_SET(errno, ECONNREFUSED, ENOENT) ? LOG_DEBUG : LOG_WARNING,
- errno, "Failed to connect to progress socket %s, ignoring: %m", sa.un.sun_path);
+ r = connect_unix_path(fd, AT_FDCWD, "/run/systemd/fsck.progress");
+ if (r < 0)
+ return log_full_errno(IN_SET(r, -ECONNREFUSED, -ENOENT) ? LOG_DEBUG : LOG_WARNING,
+ r, "Failed to connect to progress socket, ignoring: %m");
return TAKE_FD(fd);
}
static int run(int argc, char *argv[]) {
- _cleanup_close_pair_ int progress_pipe[2] = { -1, -1 };
+ _cleanup_close_pair_ int progress_pipe[2] = EBADF_PAIR;
_cleanup_(sd_device_unrefp) sd_device *dev = NULL;
_cleanup_free_ char *dpath = NULL;
_cleanup_fclose_ FILE *console = NULL;
"%s is not a block device.",
device);
- r = sd_device_new_from_devnum(&dev, 'b', st.st_rdev);
+ r = sd_device_new_from_stat_rdev(&dev, &st);
if (r < 0)
return log_error_errno(r, "Failed to detect device %s: %m", device);
}
if (sd_device_get_property_value(dev, "ID_FS_TYPE", &type) >= 0) {
- r = fsck_exists(type);
+ r = fsck_exists_for_fstype(type);
if (r < 0)
log_device_warning_errno(dev, r, "Couldn't detect if fsck.%s may be used, proceeding: %m", type);
else if (r == 0) {
log_device_info(dev, "fsck.%s doesn't exist, not checking file system.", type);
return 0;
}
+ } else {
+ r = fsck_exists();
+ if (r < 0)
+ log_device_warning_errno(dev, r, "Couldn't detect if the fsck command may be used, proceeding: %m");
+ else if (r == 0) {
+ log_device_info(dev, "The fsck command does not exist, not checking file system.");
+ return 0;
+ }
}
console = fopen("/dev/console", "we");
pipe(progress_pipe) < 0)
return log_error_errno(errno, "pipe(): %m");
- r = safe_fork("(fsck)", FORK_RESET_SIGNALS|FORK_DEATHSIG|FORK_LOG, &pid);
+ r = safe_fork("(fsck)", FORK_RESET_SIGNALS|FORK_DEATHSIG_SIGTERM|FORK_LOG|FORK_RLIMIT_NOFILE_SAFE, &pid);
if (r < 0)
return r;
if (r == 0) {
} else
dash_c[0] = 0;
- cmdline[i++] = "/sbin/fsck";
+ cmdline[i++] = "fsck";
cmdline[i++] = arg_repair;
cmdline[i++] = "-T";
cmdline[i++] = device;
cmdline[i++] = NULL;
- (void) rlimit_nofile_safe();
-
- execv(cmdline[0], (char**) cmdline);
+ execvp(cmdline[0], (char**) cmdline);
_exit(FSCK_OPERATIONAL_ERROR);
}
/* System should be rebooted. */
start_target(SPECIAL_REBOOT_TARGET, "replace-irreversibly");
return -EINVAL;
- } else if (exit_status & (FSCK_SYSTEM_SHOULD_REBOOT | FSCK_ERRORS_LEFT_UNCORRECTED))
- /* Some other problem */
- start_target(SPECIAL_EMERGENCY_TARGET, "replace");
- else
+ } else if (!(exit_status & (FSCK_SYSTEM_SHOULD_REBOOT | FSCK_ERRORS_LEFT_UNCORRECTED)))
log_warning("Ignoring error.");
}