If futimens(2) fails here then close(2) is not called and we leak the
descriptor.
I think futimens(2) and close(2) failures are exotic enough to warrant
printing the system call name.
ok?
Index: touch.c
===================================================================
RCS file: /cvs/src/usr.bin/touch/touch.c,v
retrieving revision 1.26
diff -u -p -r1.26 touch.c
--- touch.c 10 Mar 2019 15:11:52 -0000 1.26
+++ touch.c 27 Jan 2022 23:55:50 -0000
@@ -137,9 +137,18 @@ main(int argc, char *argv[])
/* Create the file. */
fd = open(*argv, O_WRONLY | O_CREAT, DEFFILEMODE);
- if (fd == -1 || futimens(fd, ts) || close(fd)) {
+ if (fd == -1) {
rval = 1;
warn("%s", *argv);
+ continue;
+ }
+ if (futimens(fd, ts) == -1) {
+ warn("futimens %s", *argv);
+ rval = 1;
+ }
+ if (close(fd) == -1) {
+ warn("close %s", *argv);
+ rval = 1;
}
}
return rval;