still testing, as on i watched reusing fd 0

This commit is contained in:
ftasnetamot authored and Yves Rutschle committed 2024-09-08 16:56:50 +02:00
1 parent 109052fdc7
commit 4def95865c
1 file changed
+1 -3
+1 -3
View File
@@ -288,14 +288,12 @@ int main(int argc, char *argv[], char* envp[])
if (!cfg.foreground) {
if (fork() > 0) exit(0); /* Detach */
// close stdin, stderr, stdout
// closing stdin frees a filehandle, and 0 will not be reused, so no problem
// with control-jobs, trying to catch fd/0
close(fileno(stdin));
int newfd;
// duplicating a handle connected to /dev/null to stdout and stderr
// so we don't run in any problems, when a control-job wor whats-o-ever will
// grab stdout and stderr
if ((newfd = open("/dev/null", O_RDWR))) {
dup2 (newfd, STDIN_FILENO);
dup2 (newfd, STDOUT_FILENO);
dup2 (newfd, STDERR_FILENO);
// close the helper handle, as this is now unnecessary