In message <201712051955.vb5jtrwp079...@repo.freebsd.org>, Gleb Smirnoff 
writes
:
> Author: glebius
> Date: Tue Dec  5 19:55:53 2017
> New Revision: 326574
> URL: https://svnweb.freebsd.org/changeset/base/326574
>
> Log:
>   Generate fully RFC3164 compliant messages, with timestamp and hostname.
>   Allow to set hostname to any string with -H.
>   
>   MFC after:  2 months
>
> Modified:
>   head/usr.bin/logger/logger.1
>   head/usr.bin/logger/logger.c
>
> Modified: head/usr.bin/logger/logger.1
> =============================================================================
> =
> --- head/usr.bin/logger/logger.1      Tue Dec  5 19:54:55 2017        (r32657
> 3)
> +++ head/usr.bin/logger/logger.1      Tue Dec  5 19:55:53 2017        (r32657
> 4)
> @@ -28,7 +28,7 @@
>  .\"  @(#)logger.1    8.1 (Berkeley) 6/6/93
>  .\" $FreeBSD$
>  .\"
> -.Dd December 23, 2016
> +.Dd December 5, 2017
>  .Dt LOGGER 1
>  .Os
>  .Sh NAME
> @@ -38,6 +38,7 @@
>  .Nm
>  .Op Fl 46Ais
>  .Op Fl f Ar file
> +.Op Fl H Ar hostname
>  .Op Fl h Ar host
>  .Op Fl P Ar port
>  .Op Fl p Ar pri
> @@ -77,6 +78,11 @@ Log the message to standard error, as well as the syst
>  .It Fl f Ar file
>  Read the contents of the specified file into syslog.
>  This option is ignored when a message is also specified.
> +.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
>
> Modified: head/usr.bin/logger/logger.c
> =============================================================================
> =
> --- head/usr.bin/logger/logger.c      Tue Dec  5 19:54:55 2017        (r32657
> 3)
> +++ head/usr.bin/logger/logger.c      Tue Dec  5 19:55:53 2017        (r32657
> 4)
> @@ -44,7 +44,7 @@ static char sccsid[] = "@(#)logger.c        8.1 (Berkeley) 
> 6/
>  #include <sys/cdefs.h>
>  __FBSDID("$FreeBSD$");
>  
> -#include <sys/types.h>
> +#include <sys/param.h>
>  #include <sys/socket.h>
>  #include <netinet/in.h>
>  
> @@ -54,6 +54,7 @@ __FBSDID("$FreeBSD$");
>  #include <stdio.h>
>  #include <stdlib.h>
>  #include <string.h>
> +#include <time.h>
>  #include <unistd.h>
>  
>  #define      SYSLOG_NAMES
> @@ -71,8 +72,8 @@ static int  decode(char *, const CODE *);
>  static int   pencode(char *);
>  static ssize_t       socksetup(const char *, const char *, const char *,
>                   struct socks **);
> -static void  logmessage(int, const char *, struct socks *, ssize_t,
> -                        const char *);
> +static void  logmessage(int, const char *, const char *, const char *,
> +                 struct socks *, ssize_t, const char *);
>  static void  usage(void);
>  
>  #ifdef INET6
> @@ -93,19 +94,22 @@ main(int argc, char *argv[])
>  {
>       struct socks *socks;
>       ssize_t nsock;
> +     time_t now;
>       int ch, logflags, pri;
> -     char *tag, *host, buf[1024];
> +     char *tag, *host, buf[1024], *timestamp, tbuf[26],
> +         *hostname, hbuf[MAXHOSTNAMELEN];
>       const char *svcname, *src;
>  
>       tag = NULL;
>       host = NULL;
> +     hostname = NULL;
>       svcname = "syslog";
>       src = NULL;
>       socks = NULL;
>       pri = LOG_USER | LOG_NOTICE;
>       logflags = 0;
>       unsetenv("TZ");
> -     while ((ch = getopt(argc, argv, "46Af:h:iP:p:S:st:")) != -1)
> +     while ((ch = getopt(argc, argv, "46Af:H:h:iP:p:S:st:")) != -1)
>               switch((char)ch) {
>               case '4':
>                       family = PF_INET;
> @@ -123,6 +127,9 @@ main(int argc, char *argv[])
>                               err(1, "%s", optarg);
>                       setvbuf(stdin, 0, _IONBF, 0);
>                       break;
> +             case 'H':               /* hostname to set in message header */
> +                     hostname = optarg;
> +                     break;
>               case 'h':               /* hostname to deliver to */
>                       host = optarg;
>                       break;
> @@ -168,6 +175,17 @@ main(int argc, char *argv[])
>               openlog(tag, logflags, 0);
>       (void) fclose(stdout);
>  
> +     (void )time(&now);
> +     (void )ctime_r(&now, tbuf);
> +     tbuf[19] = '\0';
> +     timestamp = tbuf + 4;
> +
> +     if (hostname == NULL) {
> +             hostname = hbuf;
> +             (void )gethostname(hbuf, MAXHOSTNAMELEN);
> +             *strchr(hostname, '.') = '\0';

Hi Gleb,

I'm getting a segfault here.

[New LWP 101396]
Core was generated by `logger -p daemon.notice -t local-dhclient(lagg0):4629
2 dhclient-script for inter'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0  0x0000000000402152 in main (argc=<optimized out>, argv=<optimized out>)
    at /opt/src/svn-current/usr.bin/logger/logger.c:186
186                     *strchr(hostname, '.') = '\0';
(gdb) bt
#0  0x0000000000402152 in main (argc=<optimized out>, argv=<optimized out>)
    at /opt/src/svn-current/usr.bin/logger/logger.c:186
(gdb) 

> +     }
> +
>       /* log input line if appropriate */
>       if (argc > 0) {
>               char *p, *endp;
> @@ -176,11 +194,13 @@ main(int argc, char *argv[])


-- 
Cheers,
Cy Schubert <cy.schub...@cschubert.com>
FreeBSD UNIX:  <c...@freebsd.org>   Web:  http://www.FreeBSD.org

        The need of the many outweighs the greed of the few.


_______________________________________________
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to