[BusyBox] close() return value (+ dd patch)
Axel Kittenberger
Axel.Kittenberger at maxxio.at
Fri Dec 7 06:11:54 UTC 2001
Hi guys,
Unfortunally I've discovered that the return value of close() is silently
swallowed on many, many places. However close can fail! (See `man 2 close`),
In example the NFS server may be gone, or data written before
might have failed if an overcommit cache is enabled, or like in my case a
device driver that can possibly fail on close.
(Yes, the linux kernel yet also swallows char device driver release()
values, but I'm after to get a patch applied for that too)
I know it means no good news for binary size, but silenly ignoring close
values is simply false. The busybox cp command seems to do it right, and to
start I've added a patch for dd, since one expects at least such lowlevel
utility to handle it correctly.
How exactly the error message is displayed is just a matter of taste, I|ve
copied the source from busybox cp for the dd patch.
the `orignal' dd seems to write something like this on a failed close: (might
be better)
perror_msg("dd: %s: %m", filename);
--- dd.c 2001/08/28 15:33:14 1.1.1.3
+++ dd.c 2001/12/07 12:52:55
@@ -51,6 +51,7 @@
ssize_t n;
off_t seek = 0, skip = 0;
char *infile = NULL, *outfile = NULL, *buf;
+ int status = EXIT_SUCCESS;
for (i = 1; i < argc; i++) {
if (strncmp("bs=", argv[i], 3) == 0)
@@ -150,5 +151,14 @@
fprintf(stderr, "%ld+%ld records in\n", (long)in_full, (long)in_part);
fprintf(stderr, "%ld+%ld records out\n", (long)out_full,
(long)out_part);
- return EXIT_SUCCESS;
+ if (close (ofd) < 0) {
+ perror_msg("unable to close `%s'", outfile);
+ status = EXIT_FAILURE;
+ }
+ if (close (ifd) < 0) {
+ perror_msg("unable to close `%s'", infile);
+ status = EXIT_FAILURE;
+ }
+
+ return status;
}
More information about the busybox
mailing list