projects
/
apps
/
pfixtools.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Cleanup daemon startup.
[apps/pfixtools.git]
/
common
/
common.c
diff --git
a/common/common.c
b/common/common.c
index
758e869
..
c2abeb4
100644
(file)
--- a/
common/common.c
+++ b/
common/common.c
@@
-44,6
+44,8
@@
sig_atomic_t sigint = false;
sig_atomic_t sighup = false;
sig_atomic_t sigint = false;
sig_atomic_t sighup = false;
+bool daemon_process = true;
+
static FILE *pidfile = NULL;
void common_sighandler(int sig)
static FILE *pidfile = NULL;
void common_sighandler(int sig)
@@
-193,10
+195,13
@@
int daemon_detach(void)
open("/dev/null", O_RDWR);
pid = fork();
open("/dev/null", O_RDWR);
pid = fork();
- if (pid < 0)
+ if (pid < 0)
{
return -1;
return -1;
- if (pid)
+ }
+ if (pid) {
+ daemon_process = false;
exit(0);
exit(0);
+ }
setsid();
return 0;
setsid();
return 0;
@@
-276,11
+281,6
@@
static void pidfile_close(void)
int common_setup(const char* pidfilename, bool unsafe, const char* runas_user,
const char* runas_group, bool daemonize)
{
int common_setup(const char* pidfilename, bool unsafe, const char* runas_user,
const char* runas_group, bool daemonize)
{
- if (pidfile_open(pidfilename) < 0) {
- syslog(LOG_CRIT, "unable to write pidfile %s", pidfilename);
- return EXIT_FAILURE;
- }
-
if (!unsafe && drop_privileges(runas_user, runas_group) < 0) {
syslog(LOG_CRIT, "unable to drop privileges");
return EXIT_FAILURE;
if (!unsafe && drop_privileges(runas_user, runas_group) < 0) {
syslog(LOG_CRIT, "unable to drop privileges");
return EXIT_FAILURE;
@@
-291,6
+291,11
@@
int common_setup(const char* pidfilename, bool unsafe, const char* runas_user,
return EXIT_FAILURE;
}
return EXIT_FAILURE;
}
+ if (pidfile_open(pidfilename) < 0) {
+ syslog(LOG_CRIT, "unable to write pidfile %s", pidfilename);
+ return EXIT_FAILURE;
+ }
+
pidfile_refresh();
return EXIT_SUCCESS;
}
pidfile_refresh();
return EXIT_SUCCESS;
}
@@
-300,9
+305,10
@@
extern exitcall_t __madexit[];
static void common_shutdown(void)
{
static void common_shutdown(void)
{
- syslog(LOG_INFO, "Stopping...");
- pidfile_close();
-
+ if (daemon_process) {
+ syslog(LOG_INFO, "Stopping...");
+ }
+ pidfile_close();
for (int i = -1; __madexit[i]; i--) {
(*__madexit[i])();
}
for (int i = -1; __madexit[i]; i--) {
(*__madexit[i])();
}