Re: ftp: use closefrom instead of close(pid)
Sure. But always be careful that the fd loop isn't bounded for a reason, for instance some fd at > 20 that it wanted left open. > This variable reuse has a funny smell. > > Index: usr.bin/ftp/cmds.c > === > RCS file: /var/cvs/src/usr.bin/ftp/cmds.c,v > retrieving revision 1.79 > diff -u -p -r1.79 cmds.c > --- usr.bin/ftp/cmds.c21 Jan 2017 08:33:07 - 1.79 > +++ usr.bin/ftp/cmds.c23 Jan 2018 08:40:32 - > @@ -987,8 +987,7 @@ shell(int argc, char *argv[]) > old1 = signal (SIGINT, SIG_IGN); > old2 = signal (SIGQUIT, SIG_IGN); > if ((pid = fork()) == 0) { > - for (pid = 3; pid < 20; pid++) > - (void)close(pid); > + (void)closefrom(3); > (void)signal(SIGINT, SIG_DFL); > (void)signal(SIGQUIT, SIG_DFL); > shellp = getenv("SHELL"); >
Re: ftp: use closefrom instead of close(pid)
On Wed, Jan 24 2018, Theo Buehler wrote: > This variable reuse has a funny smell. ok > Index: usr.bin/ftp/cmds.c > === > RCS file: /var/cvs/src/usr.bin/ftp/cmds.c,v > retrieving revision 1.79 > diff -u -p -r1.79 cmds.c > --- usr.bin/ftp/cmds.c21 Jan 2017 08:33:07 - 1.79 > +++ usr.bin/ftp/cmds.c23 Jan 2018 08:40:32 - > @@ -987,8 +987,7 @@ shell(int argc, char *argv[]) > old1 = signal (SIGINT, SIG_IGN); > old2 = signal (SIGQUIT, SIG_IGN); > if ((pid = fork()) == 0) { > - for (pid = 3; pid < 20; pid++) > - (void)close(pid); > + (void)closefrom(3); > (void)signal(SIGINT, SIG_DFL); > (void)signal(SIGQUIT, SIG_DFL); > shellp = getenv("SHELL"); > -- jca | PGP : 0x1524E7EE / 5135 92C1 AD36 5293 2BDF DDCC 0DFA 74AE 1524 E7EE