This conditional chain short-circuits if futimens(2) fails, leaving the
file descriptor open. We need to evaluate each system call in the chain
separately to ensure we attempt to close(2) the descriptor.
With input from guenther@ and millert@.
Thread: https://marc.info/?l=openbsd-tech&m=
164332809900558&w=2
ok millert@, probably ok guenther@
-/* $OpenBSD: touch.c,v 1.26 2019/03/10 15:11:52 schwarze Exp $ */
+/* $OpenBSD: touch.c,v 1.27 2022/01/29 00:06:26 cheloha Exp $ */
/* $NetBSD: touch.c,v 1.11 1995/08/31 22:10:06 jtc Exp $ */
/*
/* 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("%s", *argv);
+ rval = 1;
+ }
+ if (close(fd) == -1) {
+ warn("%s", *argv);
+ rval = 1;
}
}
return rval;