Check if pid file did not open.
[lcr.git] / main.c
diff --git a/main.c b/main.c
index 0a85f46..51da4a1 100644 (file)
--- a/main.c
+++ b/main.c
@@ -314,6 +314,7 @@ int main(int argc, char *argv[])
        if (!(strcasecmp(argv[1],"fork")))
        {
                pid_t pid;
+               FILE *pidfile;
 
                /* do daemon fork */
                pid = fork();
@@ -344,6 +345,14 @@ int main(int argc, char *argv[])
                        exit(0);
                }
                nooutput = 1;
+
+               /* write pid file */
+               pidfile = fopen("/var/run/lcr.pid","w");
+               if (pidfile)
+               {
+                       fprintf(pidfile, "%d\n", getpid());
+                       fclose(pidfile);
+               }
        } else
        /* if not start */
        if (!!strcasecmp(argv[1],"start"))