]> git.ipfire.org Git - people/ms/rstp.git/blobdiff - main.c
fixes for 4.3.3 GCC warnings/errors
[people/ms/rstp.git] / main.c
diff --git a/main.c b/main.c
index c89455bc9f709deb9cfbd5fa3481c9358de35b36..a8c21aca05e43828de4790b2eb5e1d8a6c28cca5 100644 (file)
--- a/main.c
+++ b/main.c
@@ -34,6 +34,7 @@
 #include <unistd.h>
 #include <getopt.h>
 #include <syslog.h>
+#include <errno.h>
 
 static int become_daemon = 1;
 static int is_daemon = 0;
@@ -41,7 +42,7 @@ int log_level = LOG_LEVEL_DEFAULT;
 
 int main(int argc, char *argv[])
 {
-       int c;
+       int c,ret;
        while ((c = getopt(argc, argv, "dv:")) != -1) {
                switch (c) {
                case 'd':
@@ -71,9 +72,20 @@ int main(int argc, char *argv[])
        TST(netsock_init() == 0, -1);
        TST(init_bridge_ops() == 0, -1);
        if (become_daemon) {
+               FILE *f = fopen("/var/run/rstpd.pid", "w");
+               if (!f) {
+                       ERROR("can't open /var/run/rstp.pid");
+                       return -1;
+               }
                openlog("rstpd", 0, LOG_DAEMON);
-               daemon(0, 0);
+               ret = daemon(0, 0);
+               if (ret) {
+                       ERROR("daemon() failed");
+                       return -1;                  
+               }
                is_daemon = 1;
+               fprintf(f, "%d", getpid());
+               fclose(f);
        }
        return epoll_main_loop();
 }