aboutsummaryrefslogtreecommitdiffstats
path: root/FICS
diff options
context:
space:
mode:
authorMarkus Uhlin <markus@nifty-networks.net>2024-08-04 02:09:56 +0200
committerMarkus Uhlin <markus@nifty-networks.net>2024-08-04 02:09:56 +0200
commitea36b3dfcccdc0f620603c3abb797d178ff4b50a (patch)
treea98ad79bf264660e2db5ac225a8b92f5e58c6776 /FICS
parenta285a990436511d506bc80553807ed848bdbeff2 (diff)
Changed daemonize()
Diffstat (limited to 'FICS')
-rw-r--r--FICS/ficsmain.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/FICS/ficsmain.c b/FICS/ficsmain.c
index f1bdf6d..d9ba3d1 100644
--- a/FICS/ficsmain.c
+++ b/FICS/ficsmain.c
@@ -87,25 +87,25 @@ daemonize(void)
__func__,
DAEMON_LOCKFILE);
} else if ((fd[0] = open(DAEMON_LOCKFILE, (O_CREAT | O_RDWR),
- mode[0])) == -1)
+ mode[0])) == -1) {
err(1, "%s: open(%s, ...)", __func__, DAEMON_LOCKFILE);
-
- dprintf(fd[0], "%jd\n", (intmax_t)getpid());
- close(fd[0]);
-
- if ((fd[1] = open(DAEMON_LOGFILE, (O_APPEND | O_CREAT | O_RDWR),
- mode[1])) == -1)
+ } else if ((fd[1] = open(DAEMON_LOGFILE, (O_APPEND | O_CREAT | O_RDWR),
+ mode[1])) == -1) {
err(1, "%s: open(%s, ...)", __func__, DAEMON_LOGFILE);
- else if (daemon(1, 1) == -1) {
+ } else if (daemon(1, 1) == -1) {
int i;
i = errno;
+ close(fd[0]);
close(fd[1]);
errno = i;
err(1, "%s: failed to run in the background", __func__);
}
+ dprintf(fd[0], "%jd\n", (intmax_t)getpid());
+ close(fd[0]);
+
(void) dup2(fd[1], STDIN_FILENO);
(void) dup2(fd[1], STDOUT_FILENO);
(void) dup2(fd[1], STDERR_FILENO);