logread: cleanup pid file handling
authorJohn Crispin <john@phrozen.org>
Wed, 14 Feb 2018 07:40:13 +0000 (08:40 +0100)
committerJohn Crispin <john@phrozen.org>
Wed, 14 Feb 2018 08:00:08 +0000 (09:00 +0100)
Signed-off-by: John Crispin <john@phrozen.org>
log/logread.c

index d85e03cc3a21ab34b88466c25fef574add2654a7..c4ab4290c4830ef33abb380914bd468e8ec4ec7a 100644 (file)
@@ -322,6 +322,14 @@ int main(int argc, char **argv)
        }
        ubus_add_uloop(ctx);
 
+       if (log_follow && pid_file) {
+               FILE *fp = fopen(pid_file, "w+");
+               if (fp) {
+                       fprintf(fp, "%d", getpid());
+                       fclose(fp);
+               }
+       }
+
        /* ugly ugly ugly ... we need a real reconnect logic */
        do {
                ret = ubus_lookup_id(ctx, "log", &id);
@@ -338,15 +346,6 @@ int main(int argc, char **argv)
                        blobmsg_add_u32(&b, "lines", lines);
                else if (log_follow)
                        blobmsg_add_u32(&b, "lines", 0);
-               if (log_follow) {
-                       if (pid_file) {
-                               FILE *fp = fopen(pid_file, "w+");
-                               if (fp) {
-                                       fprintf(fp, "%d", getpid());
-                                       fclose(fp);
-                               }
-                       }
-               }
 
                if (log_ip && log_port) {
                        openlog("logread", LOG_PID, LOG_DAEMON);
@@ -375,5 +374,8 @@ int main(int argc, char **argv)
 
        } while (ret && tries--);
 
+       if (log_follow && pid_file)
+               unlink(pid_file);
+
        return ret;
 }