install-dir:
install -d $(DESTDIR)$(prefix)/sbin
install -d $(DESTDIR)/etc/pfixtools
+ install example/postlicyd.conf $(DESTDIR)/etc/pfixtools/postlicyd.example.conf
.PHONY: clean distclean install install-dir $(SUBDIRS) $(CLEAN_TARGETS) \
$(DISTCLEAN_TARGETS) $(INSTALL_TARGETS)
sig_atomic_t sigint = false;
sig_atomic_t sighup = false;
+bool daemon_process = true;
+
static FILE *pidfile = NULL;
void common_sighandler(int sig)
open("/dev/null", O_RDWR);
pid = fork();
- if (pid < 0)
+ if (pid < 0) {
return -1;
- if (pid)
+ }
+ if (pid) {
+ daemon_process = false;
exit(0);
+ }
setsid();
return 0;
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;
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;
}
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])();
}
return EXIT_FAILURE;
}
+ if (drop_privileges(RUNAS_USER, RUNAS_GROUP) < 0) {
+ syslog(LOG_CRIT, "unable to drop privileges");
+ return EXIT_FAILURE;
+ }
+
config_t *config = config_read(argv[optind]);
if (config == NULL) {
return EXIT_FAILURE;
config->port = port;
}
- if (common_setup(pidfile, false, RUNAS_USER, RUNAS_GROUP,
- daemonize) != EXIT_SUCCESS
+ if (common_setup(pidfile, true, NULL, NULL, daemonize) != EXIT_SUCCESS
|| start_listener(config->port) < 0) {
config_delete(&config);
return EXIT_FAILURE;
- }
- {
+ } else {
int res = server_loop(query_starter, (delete_client_t)query_delete,
policy_run, config_refresh, config);
config_delete(&config);