add option pid
This commit is contained in:
@@ -51,6 +51,7 @@ void help(void)
|
|||||||
"Start smartdns server.\n"
|
"Start smartdns server.\n"
|
||||||
" -f run forground.\n"
|
" -f run forground.\n"
|
||||||
" -c [conf] config file.\n"
|
" -c [conf] config file.\n"
|
||||||
|
" -p [pid] pid file path\n"
|
||||||
" -h show this help message.\n"
|
" -h show this help message.\n"
|
||||||
"\n";
|
"\n";
|
||||||
/* clang-format on */
|
/* clang-format on */
|
||||||
@@ -251,10 +252,12 @@ int main(int argc, char *argv[])
|
|||||||
int is_forground = 0;
|
int is_forground = 0;
|
||||||
int opt;
|
int opt;
|
||||||
char config_file[MAX_LINE_LEN];
|
char config_file[MAX_LINE_LEN];
|
||||||
|
char pid_file[MAX_LINE_LEN];
|
||||||
|
|
||||||
strncpy(config_file, SMARTDNS_CONF_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) {
|
switch (opt) {
|
||||||
case 'f':
|
case 'f':
|
||||||
is_forground = 1;
|
is_forground = 1;
|
||||||
@@ -262,6 +265,9 @@ int main(int argc, char *argv[])
|
|||||||
case 'c':
|
case 'c':
|
||||||
snprintf(config_file, sizeof(config_file), optarg);
|
snprintf(config_file, sizeof(config_file), optarg);
|
||||||
break;
|
break;
|
||||||
|
case 'p':
|
||||||
|
snprintf(pid_file, sizeof(pid_file), optarg);
|
||||||
|
break;
|
||||||
case 'h':
|
case 'h':
|
||||||
help();
|
help();
|
||||||
return 1;
|
return 1;
|
||||||
@@ -280,7 +286,7 @@ int main(int argc, char *argv[])
|
|||||||
if (load_conf(config_file) != 0) {
|
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));
|
fprintf(stderr, "create pid file failed, %s\n", strerror(errno));
|
||||||
goto errout;
|
goto errout;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ After=network.target
|
|||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
PIDFile=/var/run/smartdns.pid
|
PIDFile=/var/run/smartdns.pid
|
||||||
EnvironmentFile=-/etc/default/smartdns
|
EnvironmentFile=/etc/default/smartdns
|
||||||
ExecStart=/usr/sbin/smartdns $SMART_DNS_OPTS
|
ExecStart=/usr/sbin/smartdns $SMART_DNS_OPTS
|
||||||
KillMode=process
|
KillMode=process
|
||||||
Restart=always
|
Restart=always
|
||||||
|
|||||||
Reference in New Issue
Block a user