}
static int process_progress(int fd) {
- FILE *f, *console;
+ _cleanup_fclose_ FILE *console = NULL, *f = NULL;
usec_t last = 0;
bool locked = false;
int clear = 0;
}
console = fopen("/dev/console", "w");
- if (!console) {
- fclose(f);
+ if (!console)
return -ENOMEM;
- }
while (!feof(f)) {
int pass, m;
unsigned long cur, max;
- char *device;
+ _cleanup_free_ char *device = NULL;
double p;
usec_t t;
/* Only show one progress counter at max */
if (!locked) {
- if (flock(fileno(console), LOCK_EX|LOCK_NB) < 0) {
- free(device);
+ if (flock(fileno(console), LOCK_EX|LOCK_NB) < 0)
continue;
- }
locked = true;
}
/* Only update once every 50ms */
t = now(CLOCK_MONOTONIC);
- if (last + 50 * USEC_PER_MSEC > t) {
- free(device);
+ if (last + 50 * USEC_PER_MSEC > t)
continue;
- }
last = t;
fprintf(console, "\r%s: fsck %3.1f%% complete...\r%n", device, p, &m);
fflush(console);
- free(device);
-
if (m > clear)
clear = m;
}
fflush(console);
}
- fclose(f);
- fclose(console);
return 0;
}
if (stat("/", &st) < 0) {
log_error("Failed to stat() the root directory: %m");
- goto finish;
+ return EXIT_FAILURE;
}
/* Virtual root devices don't need an fsck */
if (major(st.st_dev) == 0)
- return 0;
+ return EXIT_SUCCESS;
/* check if we are already writable */
times[0] = st.st_atim;
times[1] = st.st_mtim;
if (utimensat(AT_FDCWD, "/", times, 0) == 0) {
log_info("Root directory is writable, skipping check.");
- return 0;
+ return EXIT_SUCCESS;
}
- if (!(udev = udev_new())) {
+ udev = udev_new();
+ if (!udev) {
log_oom();
- goto finish;
+ return EXIT_FAILURE;
}
- if (!(udev_device = udev_device_new_from_devnum(udev, 'b', st.st_dev))) {
+ udev_device = udev_device_new_from_devnum(udev, 'b', st.st_dev);
+ if (!udev_device) {
log_error("Failed to detect root device.");
- goto finish;
+ return EXIT_FAILURE;
}
- if (!(device = udev_device_get_devnode(udev_device))) {
+ device = udev_device_get_devnode(udev_device);
+ if (!device) {
log_error("Failed to detect device node of root directory.");
- goto finish;
+ return EXIT_FAILURE;
}
root_directory = true;
if (arg_show_progress)
if (pipe(progress_pipe) < 0) {
log_error("pipe(): %m");
- goto finish;
+ return EXIT_FAILURE;
}
cmdline[i++] = "/sbin/fsck";