From b81bea73b627e1f9cf75f1556634856280a2a89b Mon Sep 17 00:00:00 2001 From: John Crispin Date: Wed, 14 Feb 2018 08:40:13 +0100 Subject: [PATCH] logread: cleanup pid file handling Signed-off-by: John Crispin --- log/logread.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/log/logread.c b/log/logread.c index d85e03c..c4ab429 100644 --- a/log/logread.c +++ b/log/logread.c @@ -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; } -- 2.25.1