Minor cleanup, use the glibc function.  This does everything that was
done previously, plus closes stdin, stdout and stderr when running as a
daemon and using syslog for output.

Signed-off-by: Chris Leech <[email protected]>
---

 fcoemon.c |   21 +++------------------
 1 files changed, 3 insertions(+), 18 deletions(-)

diff --git a/fcoemon.c b/fcoemon.c
index 196a4de..78cccda 100644
--- a/fcoemon.c
+++ b/fcoemon.c
@@ -2565,28 +2565,13 @@ int main(int argc, char **argv)
        if (argc != optind)
                fcm_usage();
 
-       if (!fcm_fg) {
-               pid_t pid, sid;
-
-               pid = fork();
-               if (pid < 0) {
-                       FCM_LOG("Starting daemon failed");
-                       exit(EXIT_FAILURE);
-               } else if (pid)
-                       exit(EXIT_SUCCESS);
-
-               /* Create a new SID for the child process */
-               sid = setsid();
-               if (sid < 0)
-                       exit(EXIT_FAILURE);
+       if (!fcm_fg && daemon(0, fcoe_config.use_syslog)) {
+               FCM_LOG("Starting daemon failed");
+               exit(EXIT_FAILURE);
        }
 
        umask(0);
 
-       /* Change the current working directory */
-       if ((chdir("/")) < 0)
-               exit(EXIT_FAILURE);
-
        /*
         * Set up for signals.
         */

_______________________________________________
devel mailing list
[email protected]
http://www.open-fcoe.org/mailman/listinfo/devel

Reply via email to