aboutsummaryrefslogtreecommitdiff
path: root/coreutils/fsync.c
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2019-04-02 14:39:56 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2019-04-02 14:39:56 +0200
commit4f74bb6059b54df31b9a6cdaf844112a7003b0ff (patch)
treeeb4ed2d1463644e60fd8cc77704ff8546f951c25 /coreutils/fsync.c
parente48559eae3ba10e4b4f4c2ce726c31fd038a37ba (diff)
downloadbusybox-w32-4f74bb6059b54df31b9a6cdaf844112a7003b0ff.tar.gz
busybox-w32-4f74bb6059b54df31b9a6cdaf844112a7003b0ff.tar.bz2
busybox-w32-4f74bb6059b54df31b9a6cdaf844112a7003b0ff.zip
fsync,sync: make them similar
sync: add O_NOCTTY fsync: drop O_NOATIME, add O_NONBLOCK, set exitcode to 1 if fsync() fails, update --help message to be similar to sync. both: reformat code to minimize "diff -u sync.c fsync.c": in particular, they use same open() flags now function old new delta fsync_main 126 130 +4 packed_usage 33316 33317 +1 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/0 up/down: 5/0) Total: 5 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'coreutils/fsync.c')
-rw-r--r--coreutils/fsync.c30
1 files changed, 16 insertions, 14 deletions
diff --git a/coreutils/fsync.c b/coreutils/fsync.c
index c7cba9f61..216cbcf41 100644
--- a/coreutils/fsync.c
+++ b/coreutils/fsync.c
@@ -12,6 +12,7 @@
12//config: help 12//config: help
13//config: fsync is used to flush file-related cached blocks to disk. 13//config: fsync is used to flush file-related cached blocks to disk.
14 14
15// APPLET_NOFORK:name main location suid_type help
15//applet:IF_FSYNC(APPLET_NOFORK(fsync, fsync, BB_DIR_BIN, BB_SUID_DROP, fsync)) 16//applet:IF_FSYNC(APPLET_NOFORK(fsync, fsync, BB_DIR_BIN, BB_SUID_DROP, fsync))
16 17
17//kbuild:lib-$(CONFIG_FSYNC) += fsync.o 18//kbuild:lib-$(CONFIG_FSYNC) += fsync.o
@@ -19,20 +20,17 @@
19//usage:#define fsync_trivial_usage 20//usage:#define fsync_trivial_usage
20//usage: "[-d] FILE..." 21//usage: "[-d] FILE..."
21//usage:#define fsync_full_usage "\n\n" 22//usage:#define fsync_full_usage "\n\n"
22//usage: "Write files' buffered blocks to disk\n" 23//usage: "Write all buffered blocks in FILEs to disk\n"
23//usage: "\n -d Avoid syncing metadata" 24//usage: "\n -d Avoid syncing metadata"
24 25
25#include "libbb.h" 26#include "libbb.h"
26#ifndef O_NOATIME
27# define O_NOATIME 0
28#endif
29 27
30/* This is a NOFORK applet. Be very careful! */ 28/* This is a NOFORK applet. Be very careful! */
31 29
32int fsync_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 30int fsync_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
33int fsync_main(int argc UNUSED_PARAM, char **argv) 31int fsync_main(int argc UNUSED_PARAM, char **argv)
34{ 32{
35 int status; 33 int ret;
36 int opts; 34 int opts;
37 35
38 opts = getopt32(argv, "d"); /* fdatasync */ 36 opts = getopt32(argv, "d"); /* fdatasync */
@@ -41,20 +39,24 @@ int fsync_main(int argc UNUSED_PARAM, char **argv)
41 bb_show_usage(); 39 bb_show_usage();
42 } 40 }
43 41
44 status = EXIT_SUCCESS; 42 ret = EXIT_SUCCESS;
45 do { 43 do {
46 int fd = open_or_warn(*argv, O_NOATIME | O_NOCTTY | O_RDONLY); 44 /* GNU "sync FILE" uses O_NONBLOCK open */
45 int fd = open_or_warn(*argv, /*O_NOATIME |*/ O_NOCTTY | O_RDONLY | O_NONBLOCK);
46 /* open(NOATIME) can only be used by owner or root, don't use NOATIME here */
47 47
48 if (fd == -1) { 48 if (fd < 0) {
49 status = EXIT_FAILURE; 49 ret = EXIT_FAILURE;
50 continue; 50 goto next;
51 } 51 }
52 if ((opts ? fdatasync(fd) : fsync(fd))) { 52 if ((opts ? fdatasync(fd) : fsync(fd)) != 0) {
53 //status = EXIT_FAILURE; - do we want this?
54 bb_simple_perror_msg(*argv); 53 bb_simple_perror_msg(*argv);
54 ret = EXIT_FAILURE;
55 } 55 }
56 close(fd); 56 close(fd);
57 } while (*++argv); 57 next:
58 argv++;
59 } while (*argv);
58 60
59 return status; 61 return ret;
60} 62}