[email protected] (Jeremie Courreges-Anglas) writes:
> Simple idiom: always initialize the pre-opened fd to -1, and within
> rdaemon() test whether the passed fd is valid.
>
> ok?
Updated diff after Theo suggested avoiding the fcntl call if possible.
Index: usr.sbin/rtadvd/rtadvd.c
===================================================================
RCS file: /cvs/src/usr.sbin/rtadvd/rtadvd.c,v
retrieving revision 1.81
diff -u -p -r1.81 rtadvd.c
--- usr.sbin/rtadvd/rtadvd.c 21 Sep 2016 18:54:24 -0000 1.81
+++ usr.sbin/rtadvd/rtadvd.c 24 Sep 2016 17:56:55 -0000
@@ -1320,6 +1320,12 @@ ra_timer_update(struct rainfo *rai)
int
rdaemon(int devnull)
{
+ if (devnull == -1) {
+ errno = EBADF;
+ return (-1);
+ }
+ if (fcntl(devnull, F_GETFL) == -1)
+ return (-1);
switch (fork()) {
case -1:
Index: usr.sbin/dhcrelay/dhcrelay.c
===================================================================
RCS file: /cvs/src/usr.sbin/dhcrelay/dhcrelay.c,v
retrieving revision 1.42
diff -u -p -r1.42 dhcrelay.c
--- usr.sbin/dhcrelay/dhcrelay.c 15 Sep 2016 16:16:03 -0000 1.42
+++ usr.sbin/dhcrelay/dhcrelay.c 24 Sep 2016 17:22:20 -0000
@@ -368,6 +368,12 @@ usage(void)
int
rdaemon(int devnull)
{
+ if (devnull == -1) {
+ errno = EBADF;
+ return (-1);
+ }
+ if (fcntl(devnull, F_GETFL) == -1)
+ return (-1);
switch (fork()) {
case -1:
Index: usr.sbin/ftp-proxy/ftp-proxy.c
===================================================================
RCS file: /cvs/src/usr.sbin/ftp-proxy/ftp-proxy.c,v
retrieving revision 1.35
diff -u -p -r1.35 ftp-proxy.c
--- usr.sbin/ftp-proxy/ftp-proxy.c 15 Sep 2016 16:16:03 -0000 1.35
+++ usr.sbin/ftp-proxy/ftp-proxy.c 24 Sep 2016 17:55:37 -0000
@@ -633,6 +633,7 @@ main(int argc, char *argv[])
verbose = 0;
/* Other initialization. */
+ devnull = -1;
id_count = 1;
session_count = 0;
@@ -1142,6 +1143,12 @@ usage(void)
int
rdaemon(int devnull)
{
+ if (devnull == -1) {
+ errno = EBADF;
+ return (-1);
+ }
+ if (fcntl(devnull, F_GETFL) == -1)
+ return (-1);
switch (fork()) {
case -1:
Index: usr.sbin/tftpd/tftpd.c
===================================================================
RCS file: /cvs/src/usr.sbin/tftpd/tftpd.c,v
retrieving revision 1.37
diff -u -p -r1.37 tftpd.c
--- usr.sbin/tftpd/tftpd.c 4 Sep 2016 14:41:49 -0000 1.37
+++ usr.sbin/tftpd/tftpd.c 24 Sep 2016 17:55:58 -0000
@@ -1584,6 +1584,12 @@ getip(void *s)
int
rdaemon(int devnull)
{
+ if (devnull == -1) {
+ errno = EBADF;
+ return (-1);
+ }
+ if (fcntl(devnull, F_GETFL) == -1)
+ return (-1);
switch (fork()) {
case -1:
--
jca | PGP : 0x1524E7EE / 5135 92C1 AD36 5293 2BDF DDCC 0DFA 74AE 1524 E7EE