[Xfce4-commits] [apps/xfce4-volumed-pulse] 47/62: Simplify daemonization (stolen from xfsettingsd)
noreply at xfce.org
noreply at xfce.org
Thu Sep 8 10:33:09 CEST 2016
This is an automated email from the git hooks/post-receive script.
ochosi pushed a commit to branch master
in repository apps/xfce4-volumed-pulse.
commit 4272f431ec385af9909de6c68124c4f3ee4f4027
Author: Lionel Le Folgoc <lionel at lefolgoc.net>
Date: Fri May 25 18:02:54 2012 +0200
Simplify daemonization (stolen from xfsettingsd)
---
src/main.c | 52 ++++++++++++++++++++++------------------------------
1 file changed, 22 insertions(+), 30 deletions(-)
diff --git a/src/main.c b/src/main.c
index 9152757..6b1a73a 100644
--- a/src/main.c
+++ b/src/main.c
@@ -31,40 +31,28 @@
XvdInstance *Inst = NULL;
-static void
+static gint
xvd_daemonize()
{
- gint pid;
- FILE *checkout = NULL;
-
- pid = fork ();
-
- if (-1 == pid) {
- g_warning ("Failed to fork the daemon. Continuing in non-daemon mode.\n");
- } else if (pid > 0) {
- exit (EXIT_SUCCESS);
- }
-
- pid = setsid ();
- if (pid < 0) {
- exit (EXIT_FAILURE);
- }
+#ifdef HAVE_DAEMON
+ return daemon (1, 1);
+#else
+ pid_t pid;
- if ((chdir ("/")) < 0) {
- exit (EXIT_FAILURE);
- }
+ pid = fork ();
+ if (pid < 0)
+ return -1;
- checkout = freopen ("/dev/null", "r", stdin);
- if (NULL == checkout)
- g_warning("Error when redirecting stdin to /dev/null\n");
+ if (pid > 0)
+ _exit (EXIT_SUCCESS);
- checkout = freopen ("/dev/null", "w", stdout);
- if (NULL == checkout)
- g_warning("Error when redirecting stdout to /dev/null\n");
+#ifdef HAVE_SETSID
+ if (setsid () < 0)
+ return -1;
+#endif
- checkout = freopen ("/dev/null", "w", stderr);
- if (NULL == checkout)
- g_warning("Error when redirecting stderr to /dev/null\n");
+ return 0;
+#endif
}
static void
@@ -103,8 +91,12 @@ main(gint argc, gchar **argv)
Inst = g_malloc (sizeof (XvdInstance));
xvd_instance_init (Inst);
/* Daemon mode */
- #ifdef NDEBUG
- xvd_daemonize();
+ #ifndef DEBUG
+ if (xvd_daemonize () == -1)
+ {
+ /* show message and continue in normal mode */
+ g_warning ("Failed to fork the process: %s. Continuing in non-daemon mode.", g_strerror (errno));
+ }
#endif
gtk_init(&argc, &argv);
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the Xfce4-commits
mailing list