chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
7d74558
)
fsck: modernization
author
Zbigniew Jędrzejewski-Szmek
<zbyszek@in.waw.pl>
Tue, 12 Nov 2013 04:32:31 +0000
(23:32 -0500)
committer
Zbigniew Jędrzejewski-Szmek
<zbyszek@in.waw.pl>
Sat, 16 Nov 2013 03:53:14 +0000
(22:53 -0500)
src/fsck/fsck.c
patch
|
blob
|
history
diff --git
a/src/fsck/fsck.c
b/src/fsck/fsck.c
index 9b67ccfc0e278527c47abc64132f881effcb94cf..c2e1c741d571382ba7f593986cd1bb0e57a96161 100644
(file)
--- a/
src/fsck/fsck.c
+++ b/
src/fsck/fsck.c
@@
-144,7
+144,7
@@
static double percent(int pass, unsigned long cur, unsigned long max) {
}
static int process_progress(int fd) {
}
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;
usec_t last = 0;
bool locked = false;
int clear = 0;
@@
-156,15
+156,13
@@
static int process_progress(int fd) {
}
console = fopen("/dev/console", "w");
}
console = fopen("/dev/console", "w");
- if (!console) {
- fclose(f);
+ if (!console)
return -ENOMEM;
return -ENOMEM;
- }
while (!feof(f)) {
int pass, m;
unsigned long cur, max;
while (!feof(f)) {
int pass, m;
unsigned long cur, max;
-
char *device
;
+
_cleanup_free_ char *device = NULL
;
double p;
usec_t t;
double p;
usec_t t;
@@
-173,20
+171,16
@@
static int process_progress(int fd) {
/* Only show one progress counter at max */
if (!locked) {
/* 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;
continue;
- }
locked = true;
}
/* Only update once every 50ms */
t = now(CLOCK_MONOTONIC);
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;
continue;
- }
last = t;
last = t;
@@
-194,8
+188,6
@@
static int process_progress(int fd) {
fprintf(console, "\r%s: fsck %3.1f%% complete...\r%n", device, p, &m);
fflush(console);
fprintf(console, "\r%s: fsck %3.1f%% complete...\r%n", device, p, &m);
fflush(console);
- free(device);
-
if (m > clear)
clear = m;
}
if (m > clear)
clear = m;
}
@@
-210,8
+202,6
@@
static int process_progress(int fd) {
fflush(console);
}
fflush(console);
}
- fclose(f);
- fclose(console);
return 0;
}
return 0;
}
@@
-255,34
+245,37
@@
int main(int argc, char *argv[]) {
if (stat("/", &st) < 0) {
log_error("Failed to stat() the root directory: %m");
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)
}
/* 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.");
/* 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();
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.");
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.");
log_error("Failed to detect device node of root directory.");
-
goto finish
;
+
return EXIT_FAILURE
;
}
root_directory = true;
}
root_directory = true;
@@
-291,7
+284,7
@@
int main(int argc, char *argv[]) {
if (arg_show_progress)
if (pipe(progress_pipe) < 0) {
log_error("pipe(): %m");
if (arg_show_progress)
if (pipe(progress_pipe) < 0) {
log_error("pipe(): %m");
-
goto finish
;
+
return EXIT_FAILURE
;
}
cmdline[i++] = "/sbin/fsck";
}
cmdline[i++] = "/sbin/fsck";