summaryrefslogtreecommitdiff
path: root/urlopen.c
diff options
context:
space:
mode:
authorDaniel Jones <admin@danieljon.es>2019-03-08 21:49:48 +1030
committerDaniel Jones <admin@danieljon.es>2019-03-08 21:49:48 +1030
commit74d7e5b4ee0a533707a8a2dc21d222f4bdbcf8c7 (patch)
tree8fd1f5377284b68c263a9f0ed7412cfdd59a7db1 /urlopen.c
parenta03877efec27e3a9f712d4fc052810a90c6f4e33 (diff)
downloadurlopener-74d7e5b4ee0a533707a8a2dc21d222f4bdbcf8c7.tar.gz
urlopener-74d7e5b4ee0a533707a8a2dc21d222f4bdbcf8c7.zip
reopen std{out,err} as /dev/null instead of closing them
Diffstat (limited to 'urlopen.c')
-rw-r--r--urlopen.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/urlopen.c b/urlopen.c
index 173dac5..f2c1e3c 100644
--- a/urlopen.c
+++ b/urlopen.c
@@ -38,7 +38,8 @@ char *programs[][2] =
};
char *forceddomains[][2] =
-{ /* if the domain is listed here, the index into programs[x][]
+{
+ /* if the domain is listed here, the index into programs[x][]
* will be the number, don't add the protocol identifier
* the www subdomain is considered a different domain
*/
@@ -195,9 +196,13 @@ main(int argc, char *argv[])
{
// child process, we don't want to ignore signals
signal(SIGCHLD, SIG_DFL);
- // close std{out,err}
- fclose(stdout);
- fclose(stderr);
+ /*
+ * we don't want std{out,err} to be associated with the terminal,
+ * but we also don't want to close it to avoid the file descriptors
+ * being re-used potentially leading to problems, so reopen then to /dev/null
+ */
+ freopen("/dev/null", "w", stdout);
+ freopen("/dev/null", "w", stderr);
char *args[20];
char *buff = malloc(BUFFSIZE);
if (buff == NULL)
@@ -226,7 +231,7 @@ main(int argc, char *argv[])
}
else if (pid == -1)
{
- perror("fork error");
+ perror("fork");
}
}
}