unpackers: check errors from close() too
authorDenys Vlasenko <vda.linux@googlemail.com>
Mon, 5 Oct 2009 01:03:07 +0000 (03:03 +0200)
committerDenys Vlasenko <vda.linux@googlemail.com>
Mon, 5 Oct 2009 01:03:07 +0000 (03:03 +0200)
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
archival/bbunzip.c
include/libbb.h
libbb/xfuncs_printf.c

index d25f5093947dcf307b90a38420005fd90c80a2ba..d6625e476e9bf99800577340ffb56a141d0669c6 100644 (file)
@@ -98,6 +98,7 @@ int FAST_FUNC bbunpack(char **argv,
                status = unpacker(&info);
                if (status < 0)
                        exitcode = 1;
+               xclose(STDOUT_FILENO); /* with error check! */
 
                if (filename) {
                        char *del = new_name;
@@ -108,12 +109,11 @@ int FAST_FUNC bbunpack(char **argv,
 
                                        times.actime = info.mtime;
                                        times.modtime = info.mtime;
-                                       /* Close first.
+                                       /* Note: we closed it first.
                                         * On some systems calling utime
-                                        * then closing resets the mtime. */
-                                       close(STDOUT_FILENO);
-                                       /* Ignoring errors */
-                                       utime(new_name, &times);
+                                        * then closing resets the mtime
+                                        * back to current time. */
+                                       utime(new_name, &times); /* ignoring errors */
                                }
 
                                /* Delete _compressed_ file */
index a02355cc5854f9d2d9eca9321c1c96814d1fa82b..dca14b40d556d627f3aac6261e912147b2a9fa2a 100644 (file)
@@ -631,6 +631,9 @@ extern void xwrite(int fd, const void *buf, size_t count) FAST_FUNC;
 extern void xwrite_str(int fd, const char *str) FAST_FUNC;
 extern void xopen_xwrite_close(const char* file, const char *str) FAST_FUNC;
 
+/* Close fd, but check for failures (some types of write errors) */
+extern void xclose(int fd) FAST_FUNC;
+
 /* Reads and prints to stdout till eof, then closes FILE. Exits on error: */
 extern void xprint_and_close_file(FILE *file) FAST_FUNC;
 
index 5f56b36de54cb1e6d87d1a1b93b7987f674b0561..aaf9989a0aa073cb4379ee7412c30c06a4d90bc0 100644 (file)
@@ -213,6 +213,12 @@ void FAST_FUNC xwrite_str(int fd, const char *str)
        xwrite(fd, str, strlen(str));
 }
 
+void FAST_FUNC xclose(int fd)
+{
+       if (close(fd))
+               bb_perror_msg_and_die("close failed");
+}
+
 // Die with an error message if we can't lseek to the right spot.
 off_t FAST_FUNC xlseek(int fd, off_t offset, int whence)
 {