diff --git a/src/smartdns.c b/src/smartdns.c index 9d3f8f9..f57062b 100644 --- a/src/smartdns.c +++ b/src/smartdns.c @@ -51,6 +51,7 @@ void help(void) "Start smartdns server.\n" " -f run forground.\n" " -c [conf] config file.\n" + " -p [pid] pid file path\n" " -h show this help message.\n" "\n"; /* clang-format on */ @@ -251,10 +252,12 @@ int main(int argc, char *argv[]) int is_forground = 0; int opt; char config_file[MAX_LINE_LEN]; + char pid_file[MAX_LINE_LEN]; strncpy(config_file, SMARTDNS_CONF_FILE, MAX_LINE_LEN); + strncpy(pid_file, SMARTDNS_PID_FILE, MAX_LINE_LEN); - while ((opt = getopt(argc, argv, "fhc:")) != -1) { + while ((opt = getopt(argc, argv, "fhc:p:")) != -1) { switch (opt) { case 'f': is_forground = 1; @@ -262,6 +265,9 @@ int main(int argc, char *argv[]) case 'c': snprintf(config_file, sizeof(config_file), optarg); break; + case 'p': + snprintf(pid_file, sizeof(pid_file), optarg); + break; case 'h': help(); return 1; @@ -280,7 +286,7 @@ int main(int argc, char *argv[]) if (load_conf(config_file) != 0) { } - if (create_pid_file(SMARTDNS_PID_FILE) != 0) { + if (create_pid_file(pid_file) != 0) { fprintf(stderr, "create pid file failed, %s\n", strerror(errno)); goto errout; } diff --git a/systemd/smartdns.service b/systemd/smartdns.service index 91846c6..6b2d686 100644 --- a/systemd/smartdns.service +++ b/systemd/smartdns.service @@ -4,7 +4,7 @@ After=network.target [Service] PIDFile=/var/run/smartdns.pid -EnvironmentFile=-/etc/default/smartdns +EnvironmentFile=/etc/default/smartdns ExecStart=/usr/sbin/smartdns $SMART_DNS_OPTS KillMode=process Restart=always