projects
/
apps
/
pfixtools.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Rename to match convention in the tools directory
[apps/pfixtools.git]
/
common
/
common.c
diff --git
a/common/common.c
b/common/common.c
index
af95efa
..
3d2862f
100644
(file)
--- a/
common/common.c
+++ b/
common/common.c
@@
-52,7
+52,7
@@
static FILE *pidfile = NULL;
void common_sighandler(int sig)
{
switch (sig) {
void common_sighandler(int sig)
{
switch (sig) {
-
case SIGTERM:
+ case SIGTERM:
case SIGINT:
sigint = true;
return;
case SIGINT:
sigint = true;
return;
@@
-62,7
+62,7
@@
void common_sighandler(int sig)
return;
default:
return;
default:
-
err("Killed (got signal %d)...", sig);
+ err("Killed (got signal %d)...", sig);
exit(-1);
}
}
exit(-1);
}
}
@@
-199,11
+199,11
@@
int daemon_detach(void)
pid = fork();
if (pid < 0) {
return -1;
pid = fork();
if (pid < 0) {
return -1;
-
}
+ }
if (pid) {
if (pid) {
-
daemon_process = false;
+ daemon_process = false;
exit(0);
exit(0);
-
}
+ }
setsid();
return 0;
setsid();
return 0;
@@
-236,20
+236,11
@@
int drop_privileges(const char *user, const char *group)
int pidfile_open(const char *name)
{
int pidfile_open(const char *name)
{
- struct flock lock;
- p_clear(&lock, 1);
- lock.l_type = F_WRLCK;
if (name) {
pidfile = fopen(name, "w");
if (!pidfile)
return -1;
if (name) {
pidfile = fopen(name, "w");
if (!pidfile)
return -1;
- if (fcntl(fileno(pidfile), F_SETLK, &lock) == -1) {
- crit("program already started");
- fclose(pidfile);
- pidfile = NULL;
- return -1;
- }
- fprintf(pidfile, "%d\n", getpid());
+ fprintf(pidfile, "%d\n", getpid());
return fflush(pidfile);
}
return 0;
return fflush(pidfile);
}
return 0;
@@
-268,14
+259,12
@@
int pidfile_refresh(void)
static void pidfile_close(void)
{
static void pidfile_close(void)
{
- struct flock lock;
- p_clear(&lock, 1);
- lock.l_type = F_UNLCK;
if (pidfile) {
if (pidfile) {
- rewind(pidfile);
- ftruncate(fileno(pidfile), 0);
- fcntl(fileno(pidfile), F_SETLK, &lock);
- fclose(pidfile);
+ if (daemon_process) {
+ rewind(pidfile);
+ ftruncate(fileno(pidfile), 0);
+ }
+ fclose(pidfile);
pidfile = NULL;
}
}
pidfile = NULL;
}
}
@@
-283,6
+272,11
@@
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) {
+ crit("unable to write pidfile %s", pidfilename);
+ return EXIT_FAILURE;
+ }
+
if (!unsafe && drop_privileges(runas_user, runas_group) < 0) {
crit("unable to drop privileges");
return EXIT_FAILURE;
if (!unsafe && drop_privileges(runas_user, runas_group) < 0) {
crit("unable to drop privileges");
return EXIT_FAILURE;
@@
-293,11
+287,6
@@
int common_setup(const char* pidfilename, bool unsafe, const char* runas_user,
return EXIT_FAILURE;
}
return EXIT_FAILURE;
}
- if (pidfile_open(pidfilename) < 0) {
- crit("unable to write pidfile %s", pidfilename);
- return EXIT_FAILURE;
- }
-
pidfile_refresh();
return EXIT_SUCCESS;
}
pidfile_refresh();
return EXIT_SUCCESS;
}
@@
-307,10
+296,10
@@
extern exitcall_t __madexit[];
static void common_shutdown(void)
{
static void common_shutdown(void)
{
-
if (daemon_process) {
-
info("stopping...");
-
}
-
pidfile_close();
+ if (daemon_process) {
+ info("stopping...");
+ }
+ pidfile_close();
for (int i = -1; __madexit[i]; i--) {
(*__madexit[i])();
}
for (int i = -1; __madexit[i]; i--) {
(*__madexit[i])();
}