Dolda2000 GitWeb
/
ashd.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
44f924b
)
htparser: Added a simple PID-file state monitoring protocol.
author
Fredrik Tolf
<fredrik@dolda2000.com>
Fri, 14 May 2021 14:05:07 +0000
(16:05 +0200)
committer
Fredrik Tolf
<fredrik@dolda2000.com>
Fri, 14 May 2021 14:05:07 +0000
(16:05 +0200)
src/htparser.c
patch
|
blob
|
blame
|
history
diff --git
a/src/htparser.c
b/src/htparser.c
index
d10121c
..
348a940
100644
(file)
--- a/
src/htparser.c
+++ b/
src/htparser.c
@@
-40,7
+40,6
@@
#include "htparser.h"
static int plex;
#include "htparser.h"
static int plex;
-static char *pidfile = NULL;
static int daemonize, usesyslog;
struct mtbuf listeners;
static int daemonize, usesyslog;
struct mtbuf listeners;
@@
-603,7
+602,7
@@
int main(int argc, char **argv)
{
int c, d;
int i, s1;
{
int c, d;
int i, s1;
- char *root;
+ char *root
, *pidfile, *pidtmp
;
FILE *pidout;
struct passwd *pwent;
FILE *pidout;
struct passwd *pwent;
@@
-656,8
+655,14
@@
int main(int argc, char **argv)
bufadd(listeners, mustart(plexwatch, plex));
pidout = NULL;
if(pidfile != NULL) {
bufadd(listeners, mustart(plexwatch, plex));
pidout = NULL;
if(pidfile != NULL) {
- if((pidout = fopen(pidfile, "w")) == NULL) {
- flog(LOG_ERR, "could not open %s for writing: %s", pidfile, strerror(errno));
+ pidtmp = sprintf3("%s.new", pidfile);
+ if((pidout = fopen(pidtmp, "w")) == NULL) {
+ flog(LOG_ERR, "could not open %s for writing: %s", pidtmp, strerror(errno));
+ return(1);
+ }
+ if(rename(pidtmp, pidfile)) {
+ flog(LOG_ERR, "could not overwrite %s: %s", pidfile, strerror(errno));
+ unlink(pidtmp);
return(1);
}
}
return(1);
}
}
@@
-688,7
+693,7
@@
int main(int argc, char **argv)
}
if(pidout != NULL) {
fprintf(pidout, "%i\n", getpid());
}
if(pidout != NULL) {
fprintf(pidout, "%i\n", getpid());
- f
close
(pidout);
+ f
flush
(pidout);
}
d = 0;
while(!d) {
}
d = 0;
while(!d) {
@@
-701,11
+706,17
@@
int main(int argc, char **argv)
while(listeners.d > 0)
resume(listeners.b[0], 0);
flog(LOG_INFO, "no longer listening");
while(listeners.d > 0)
resume(listeners.b[0], 0);
flog(LOG_INFO, "no longer listening");
+ if(pidout != NULL) {
+ putc('\n', pidout);
+ fflush(pidout);
+ }
} else {
d = 1;
}
break;
}
}
} else {
d = 1;
}
break;
}
}
+ if(pidout != NULL)
+ ftruncate(fileno(pidout), 0);
return(0);
}
return(0);
}