Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for daemonisation in config file #2

Merged
merged 1 commit into from Mar 15, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 8 additions & 1 deletion smf-spf.c
Expand Up @@ -54,6 +54,7 @@
#define TAG_SUBJECT 1
#define ADD_HEADER 1
#define QUARANTINE 0
#define DAEMONIZE 1

#define MAXLINE 128
#define HASH_POWER 16
Expand Down Expand Up @@ -132,6 +133,7 @@ typedef struct config {
int add_header;
int quarantine;
int syslog_facility;
int daemonize;
unsigned long spf_ttl;
} config;

Expand Down Expand Up @@ -366,6 +368,7 @@ static int load_config(void) {
conf.add_header = ADD_HEADER;
conf.quarantine = QUARANTINE;
conf.spf_ttl = SPF_TTL;
conf.daemonize = DAEMONIZE;
if (!(fp = fopen(config_file, "r"))) return 0;
while (fgets(buf, sizeof(buf) - 1, fp)) {
char key[MAXLINE];
Expand Down Expand Up @@ -468,6 +471,10 @@ static int load_config(void) {
conf.quarantine = 1;
continue;
}
if (!strcasecmp(key, "daemonize") && !strcasecmp(val, "off")) {
conf.daemonize = 0;
continue;
}
if (!strcasecmp(key, "quarantinebox")) {
SAFE_FREE(conf.quarantine_box);
conf.quarantine_box = strdup(val);
Expand Down Expand Up @@ -953,7 +960,7 @@ int main(int argc, char **argv) {
fprintf(stderr, "smfi_register failed\n");
goto done;
}
if (daemon(0, 0)) {
if (conf.daemonize && daemon(0, 0)) {
fprintf(stderr, "daemonize failed: %s\n", strerror(errno));
goto done;
}
Expand Down
9 changes: 9 additions & 0 deletions smf-spf.conf
Expand Up @@ -102,3 +102,12 @@ WhitelistIP 192.168.0.0/16
# Default: mail
#
#Syslog mail # (daemon|mail|local0...local7)

# Run as a daemon process in the background
#
# When disabled, the process will stay in the foreground.
# This is preferred by some init systems, f.i. systemd
#
# Default: on
#
#Daemonize on # (on|off)