mirror of
https://github.com/troglobit/finit.git
synced 2026-11-06 15:51:03 +00:00
test: touch pidfile on SIGHUP, the default Finit notify mechanism
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
1 parent
3b19734f63
commit
996d3960e1
1 file changed
+28
-12
+28
-12
@@ -6,6 +6,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <err.h>
|
#include <err.h>
|
||||||
|
#include <fcntl.h>
|
||||||
#include <paths.h>
|
#include <paths.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@@ -13,12 +14,14 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <sysexits.h>
|
#include <sysexits.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
|
||||||
#define PROGNM "serv"
|
#define PROGNM "serv"
|
||||||
#define log warnx
|
#define log warnx
|
||||||
|
|
||||||
volatile sig_atomic_t reloading = 1;
|
volatile sig_atomic_t reloading = 1;
|
||||||
volatile sig_atomic_t running = 1;
|
volatile sig_atomic_t running = 1;
|
||||||
|
static char fn[80];
|
||||||
|
|
||||||
static void verify_env(char *arg)
|
static void verify_env(char *arg)
|
||||||
{
|
{
|
||||||
@@ -74,6 +77,11 @@ static void inc_restarts(void)
|
|||||||
fclose(fp);
|
fclose(fp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void cleanup(void)
|
||||||
|
{
|
||||||
|
remove(fn);
|
||||||
|
}
|
||||||
|
|
||||||
static void sig(int signo)
|
static void sig(int signo)
|
||||||
{
|
{
|
||||||
log("Got signal %d ...", signo);
|
log("Got signal %d ...", signo);
|
||||||
@@ -91,22 +99,28 @@ static void sig(int signo)
|
|||||||
|
|
||||||
static void pidfile(char *pidfn)
|
static void pidfile(char *pidfn)
|
||||||
{
|
{
|
||||||
char fn[80];
|
if (!pidfn && fn[0] == 0) {
|
||||||
pid_t pid;
|
|
||||||
FILE *fp;
|
|
||||||
|
|
||||||
if (!pidfn) {
|
|
||||||
snprintf(fn, sizeof(fn), "%s%s.pid", _PATH_VARRUN, PROGNM);
|
snprintf(fn, sizeof(fn), "%s%s.pid", _PATH_VARRUN, PROGNM);
|
||||||
pidfn = fn;
|
pidfn = fn;
|
||||||
}
|
}
|
||||||
pid = getpid();
|
|
||||||
log("Creating PID file %s with %d", pidfn, pid);
|
|
||||||
|
|
||||||
fp = fopen(pidfn, "w");
|
if (access(fn, R_OK)) {
|
||||||
if (!fp)
|
pid_t pid;
|
||||||
exit(1);
|
FILE *fp;
|
||||||
fprintf(fp, "%d\n", pid);
|
|
||||||
fclose(fp);
|
pid = getpid();
|
||||||
|
log("Creating PID file %s with %d", pidfn, pid);
|
||||||
|
|
||||||
|
fp = fopen(pidfn, "w");
|
||||||
|
if (!fp)
|
||||||
|
exit(1);
|
||||||
|
fprintf(fp, "%d\n", pid);
|
||||||
|
fclose(fp);
|
||||||
|
atexit(cleanup);
|
||||||
|
} else {
|
||||||
|
log("Touching PID file %s", pidfn);
|
||||||
|
utimensat(0, fn, NULL, 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int usage(int rc)
|
static int usage(int rc)
|
||||||
@@ -226,6 +240,8 @@ int main(int argc, char *argv[])
|
|||||||
do_notify = 0;
|
do_notify = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (do_pidfile)
|
||||||
|
pidfile(NULL);
|
||||||
reloading = 0;
|
reloading = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user