add support for custom log filename using "-l" parameter
This commit is contained in:
parent
d638b14ae9
commit
ac47bdf2e0
2
TODO.md
2
TODO.md
@ -1,4 +1,4 @@
|
|||||||
* ~~Add support for IPv6 (autodetect)~~
|
* ~~Add support for IPv6 (autodetect)~~
|
||||||
* ~~Add optional syslog support~~
|
* ~~Add optional syslog support~~
|
||||||
* Add custom log filename support
|
* ~~Add custom log filename support~~
|
||||||
* Add command line options for IPv4/IPv6, port number, logging method, etc
|
* Add command line options for IPv4/IPv6, port number, logging method, etc
|
||||||
|
16
fsipd.c
16
fsipd.c
@ -66,6 +66,7 @@
|
|||||||
log_t *lfh;
|
log_t *lfh;
|
||||||
struct pidfh *pfh;
|
struct pidfh *pfh;
|
||||||
bool use_syslog = false;
|
bool use_syslog = false;
|
||||||
|
char *logfilename = NULL;
|
||||||
int syslog_pri = -1;
|
int syslog_pri = -1;
|
||||||
|
|
||||||
struct sockaddr_in t_sa, u_sa;
|
struct sockaddr_in t_sa, u_sa;
|
||||||
@ -396,9 +397,10 @@ init_logger()
|
|||||||
syslog_pri = LOG_USER | LOG_NOTICE | LOG_PID;
|
syslog_pri = LOG_USER | LOG_NOTICE | LOG_PID;
|
||||||
} else {
|
} else {
|
||||||
/* open a log file in current directory */
|
/* open a log file in current directory */
|
||||||
/* todo: filename should be configurable from command line */
|
if (logfilename == NULL)
|
||||||
if ((lfh = log_open("fsipd.log", 0644)) == NULL)
|
logfilename = strdup("fsipd.log");
|
||||||
err(EXIT_FAILURE, "Cannot open log file");
|
if ((lfh = log_open(logfilename, 0644)) == NULL)
|
||||||
|
err(EXIT_FAILURE, "Cannot open log file \"%s\"", logfilename);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -503,10 +505,11 @@ daemon_start()
|
|||||||
void
|
void
|
||||||
usage()
|
usage()
|
||||||
{
|
{
|
||||||
printf("usage: fsipd [-h] [-s] [-p priority] \n");
|
printf("usage: fsipd [-h] [-l logfile] [-s] [-p priority] \n");
|
||||||
printf("\t-h: this message\n");
|
printf("\t-h: this message\n");
|
||||||
printf("\t-s: use syslog instead of local log file\n");
|
printf("\t-s: use syslog instead of local log file\n");
|
||||||
printf("\t-p: syslog priotiry (default: user.notice)\n");
|
printf("\t-p: syslog priotiry (default: user.notice)\n");
|
||||||
|
printf("\t-l: specify output log filename (default: fsipd.log)\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@ -552,7 +555,7 @@ main(int argc, char *argv[])
|
|||||||
{
|
{
|
||||||
int opt;
|
int opt;
|
||||||
|
|
||||||
while ((opt = getopt(argc, argv, "hsp:")) != -1) {
|
while ((opt = getopt(argc, argv, "hl:sp:")) != -1) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case 's':
|
case 's':
|
||||||
use_syslog = true;
|
use_syslog = true;
|
||||||
@ -564,6 +567,9 @@ main(int argc, char *argv[])
|
|||||||
errx(EX_USAGE, "you need to specify \"-s\".");
|
errx(EX_USAGE, "you need to specify \"-s\".");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case 'l':
|
||||||
|
logfilename = strdup(optarg);
|
||||||
|
break;
|
||||||
case 'h':
|
case 'h':
|
||||||
usage();
|
usage();
|
||||||
exit(0);
|
exit(0);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user