diff --git a/man/logger.1 b/man/logger.1 index 91d364f..b747349 100644 --- a/man/logger.1 +++ b/man/logger.1 @@ -37,6 +37,7 @@ .Op Fl d Ar SD .Op Fl f Ar FILE .Op Fl h Ar HOST +.Op Fl H Ar HOSTNAME .Op Fl m Ar MSGID .Op Fl p Ar PRIO .Op Fl P Ar PORT @@ -95,6 +96,11 @@ accepts .Fl f- as an alias for .Ar stdout . +.It Fl H Ar hostname +Set the hostname in the header of the message to specified value. +If not specified, host part of +.Xr gethostname 3 +will be used. .It Fl h Ar host Send the message to the remote system .Ar host diff --git a/src/logger.c b/src/logger.c index 8dc1382..534e160 100644 --- a/src/logger.c +++ b/src/logger.c @@ -236,6 +236,7 @@ static int usage(int code) " -d SD Log SD as RFC5424 style 'structured data' in message\n" " -f FILE Log file to write messages to, instead of syslog daemon\n" " -h HOST Send (UDP) message to this remote syslog server (IP or DNS name)\n" + " -H NAME Use NAME instead of system hostname in message header\n" " -i Log process ID of the logger process with each line (LOG_PID)\n" #ifdef __linux__ " -k Log to kernel /dev/kmsg if /dev/log doesn't exist yet\n" @@ -277,7 +278,7 @@ int main(int argc, char *argv[]) int c, num = 5; int rotate = 0; - while ((c = getopt(argc, argv, "46?bcd:f:h:ikm:np:P:r:st:u:v")) != EOF) { + while ((c = getopt(argc, argv, "46?bcd:f:h:H:ikm:np:P:r:st:u:v")) != EOF) { switch (c) { case '4': family = AF_INET; @@ -307,6 +308,10 @@ int main(int argc, char *argv[]) host = optarg; break; + case 'H': + strlcpy(log.log_hostname, optarg, sizeof(log.log_hostname)); + break; + case 'i': log_opts |= LOG_PID; break;