jcs's openbsd hax
openbsd
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Do not leak a file descriptor when opening nohup.out. Make sure that stdout and stderr are not closed. from Nan Xiao

bluhm 3b521a6e 965127f8

+6 -3
+6 -3
usr.bin/nohup/nohup.c
··· 1 - /* $OpenBSD: nohup.c,v 1.17 2018/04/26 12:42:51 guenther Exp $ */ 1 + /* $OpenBSD: nohup.c,v 1.18 2018/09/14 18:17:46 bluhm Exp $ */ 2 2 /* $NetBSD: nohup.c,v 1.6 1995/08/31 23:35:25 jtc Exp $ */ 3 3 4 4 /* ··· 78 78 if (argc < 2) 79 79 usage(); 80 80 81 - if (isatty(STDOUT_FILENO)) 81 + if (isatty(STDOUT_FILENO) || errno == EBADF) 82 82 dofile(); 83 83 84 84 if (pledge("stdio exec", NULL) == -1) 85 85 err(1, "pledge"); 86 86 87 - if (isatty(STDERR_FILENO) && dup2(STDOUT_FILENO, STDERR_FILENO) == -1) { 87 + if ((isatty(STDERR_FILENO) || errno == EBADF) && 88 + dup2(STDOUT_FILENO, STDERR_FILENO) == -1) { 88 89 /* may have just closed stderr */ 89 90 (void)fprintf(stdin, "nohup: %s\n", strerror(errno)); 90 91 exit(EXIT_MISC); ··· 125 126 (void)lseek(fd, (off_t)0, SEEK_END); 126 127 if (dup2(fd, STDOUT_FILENO) == -1) 127 128 err(EXIT_MISC, NULL); 129 + if (fd > STDERR_FILENO) 130 + (void)close(fd); 128 131 (void)fprintf(stderr, "sending output to %s\n", p); 129 132 } 130 133