diff options
Diffstat (limited to 'coreutils/sync.c')
-rw-r--r-- | coreutils/sync.c | 22 |
1 files changed, 9 insertions, 13 deletions
diff --git a/coreutils/sync.c b/coreutils/sync.c index b93476aee..e60e553a3 100644 --- a/coreutils/sync.c +++ b/coreutils/sync.c | |||
@@ -20,6 +20,7 @@ | |||
20 | //config: sync -d FILE... executes fdatasync() on each FILE. | 20 | //config: sync -d FILE... executes fdatasync() on each FILE. |
21 | //config: sync -f FILE... executes syncfs() on each FILE. | 21 | //config: sync -f FILE... executes syncfs() on each FILE. |
22 | 22 | ||
23 | // APPLET_NOFORK:name main location suid_type help | ||
23 | //applet:IF_SYNC(APPLET_NOFORK(sync, sync, BB_DIR_BIN, BB_SUID_DROP, sync)) | 24 | //applet:IF_SYNC(APPLET_NOFORK(sync, sync, BB_DIR_BIN, BB_SUID_DROP, sync)) |
24 | 25 | ||
25 | //kbuild:lib-$(CONFIG_SYNC) += sync.o | 26 | //kbuild:lib-$(CONFIG_SYNC) += sync.o |
@@ -52,7 +53,7 @@ int sync_main(int argc UNUSED_PARAM, char **argv IF_NOT_DESKTOP(UNUSED_PARAM)) | |||
52 | return EXIT_SUCCESS; | 53 | return EXIT_SUCCESS; |
53 | #else | 54 | #else |
54 | unsigned opts; | 55 | unsigned opts; |
55 | int ret = EXIT_SUCCESS; | 56 | int ret; |
56 | 57 | ||
57 | enum { | 58 | enum { |
58 | OPT_DATASYNC = (1 << 0), | 59 | OPT_DATASYNC = (1 << 0), |
@@ -66,35 +67,30 @@ int sync_main(int argc UNUSED_PARAM, char **argv IF_NOT_DESKTOP(UNUSED_PARAM)) | |||
66 | if (!argv[0]) | 67 | if (!argv[0]) |
67 | sync(); | 68 | sync(); |
68 | 69 | ||
70 | ret = EXIT_SUCCESS; | ||
69 | while (*argv) { | 71 | while (*argv) { |
70 | int fd = open_or_warn(*argv, O_RDONLY); | 72 | /* GNU "sync FILE" uses O_NONBLOCK open */ |
73 | int fd = open_or_warn(*argv, /*O_NOATIME |*/ O_NOCTTY | O_RDONLY | O_NONBLOCK); | ||
74 | /* open(NOATIME) can only be used by owner or root, don't use NOATIME here */ | ||
71 | 75 | ||
72 | if (fd < 0) { | 76 | if (fd < 0) { |
73 | ret = EXIT_FAILURE; | 77 | ret = EXIT_FAILURE; |
74 | goto next; | 78 | goto next; |
75 | } | 79 | } |
76 | if (opts & OPT_DATASYNC) { | ||
77 | if (fdatasync(fd)) | ||
78 | goto err; | ||
79 | goto do_close; | ||
80 | } | ||
81 | if (opts & OPT_SYNCFS) { | 80 | if (opts & OPT_SYNCFS) { |
82 | /* | 81 | /* |
83 | * syncfs is documented to only fail with EBADF, | 82 | * syncfs is documented to only fail with EBADF, |
84 | * which can't happen here. So, no error checks. | 83 | * which can't happen here. So, no error checks. |
85 | */ | 84 | */ |
86 | syncfs(fd); | 85 | syncfs(fd); |
87 | goto do_close; | 86 | } else |
88 | } | 87 | if (((opts & OPT_DATASYNC) ? fdatasync(fd) : fsync(fd)) != 0) { |
89 | if (fsync(fd)) { | ||
90 | err: | ||
91 | bb_simple_perror_msg(*argv); | 88 | bb_simple_perror_msg(*argv); |
92 | ret = EXIT_FAILURE; | 89 | ret = EXIT_FAILURE; |
93 | } | 90 | } |
94 | do_close: | ||
95 | close(fd); | 91 | close(fd); |
96 | next: | 92 | next: |
97 | ++argv; | 93 | argv++; |
98 | } | 94 | } |
99 | 95 | ||
100 | return ret; | 96 | return ret; |