From owner-svn-src-head@freebsd.org Wed Dec 6 04:30:11 2017 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id DBFF3E8F629; Wed, 6 Dec 2017 04:30:11 +0000 (UTC) (envelope-from cy.schubert@komquats.com) Received: from smtp-out-so.shaw.ca (smtp-out-so.shaw.ca [64.59.136.138]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "Client", Issuer "CA" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 8EF6427EA; Wed, 6 Dec 2017 04:30:11 +0000 (UTC) (envelope-from cy.schubert@komquats.com) Received: from spqr.komquats.com ([96.50.22.10]) by shaw.ca with SMTP id MRLUeZWoZGvLHMRLVemPO6; Tue, 05 Dec 2017 21:30:10 -0700 X-Authority-Analysis: v=2.2 cv=a9pAzQaF c=1 sm=1 tr=0 a=jvE2nwUzI0ECrNeyr98KWA==:117 a=jvE2nwUzI0ECrNeyr98KWA==:17 a=kj9zAlcOel0A:10 a=ocR9PWop10UA:10 a=6I5d2MoRAAAA:8 a=YxBL1-UpAAAA:8 a=rEqYXyXTbiSD_AIRaIoA:9 a=CjuIK1q_8ugA:10 a=IjZwj45LgO3ly-622nXo:22 a=Ia-lj3WSrqcvXOmTRaiG:22 Received: from slippy.cwsent.com (slippy8 [10.2.2.6]) by spqr.komquats.com (Postfix) with ESMTPS id 48E562C8; Tue, 5 Dec 2017 20:30:08 -0800 (PST) Received: from slippy.cwsent.com (localhost [127.0.0.1]) by slippy.cwsent.com (8.15.2/8.15.2) with ESMTP id vB64U7GT068873; Tue, 5 Dec 2017 20:30:07 -0800 (PST) (envelope-from Cy.Schubert@cschubert.com) Received: from slippy (cy@localhost) by slippy.cwsent.com (8.15.2/8.15.2/Submit) with ESMTP id vB64U74f068870; Tue, 5 Dec 2017 20:30:07 -0800 (PST) (envelope-from Cy.Schubert@cschubert.com) Message-Id: <201712060430.vB64U74f068870@slippy.cwsent.com> X-Authentication-Warning: slippy.cwsent.com: cy owned process doing -bs X-Mailer: exmh version 2.8.0 04/21/2012 with nmh-1.7 Reply-to: Cy Schubert From: Cy Schubert X-os: FreeBSD X-Sender: cy@cwsent.com X-URL: http://www.cschubert.com/ To: Gleb Smirnoff cc: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: Re: svn commit: r326574 - head/usr.bin/logger In-Reply-To: Message from Gleb Smirnoff of "Tue, 05 Dec 2017 19:55:53 +0000." <201712051955.vB5Jtrwp079953@repo.freebsd.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Tue, 05 Dec 2017 20:30:07 -0800 X-CMAE-Envelope: MS4wfB8jkpawOHoOTQyjms6JmDRA2F/+QtDMOSfZJua7RohfLhABehrB73xCxTjQsBu3Qb+EMVErouwNIccnFzWn4mvR47vv6peT985lNAfkGpHyJEJRvUko ZMEZDWNaLISgAaCk1rdhWO/MsAHFW3abXtBl1E7ec9ymc5EBvOplhesKwkEJ4Tv8kRs0kWl3R8IJPDqjHr3IYbH7r0uYGdoJ4z5gOoB3uWlKWWHVmqRp/dGV VHEK1VN2GQhID0qQ0mVtMqx/qGaFnTiwPUzHOYvdRPIZisCNnaT0pEMgutkgvPA8 X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 06 Dec 2017 04:30:12 -0000 In message <201712051955.vB5Jtrwp079953@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 > __FBSDID("$FreeBSD$"); > > -#include > +#include > #include > #include > > @@ -54,6 +54,7 @@ __FBSDID("$FreeBSD$"); > #include > #include > #include > +#include > #include > > #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=, argv=) at /opt/src/svn-current/usr.bin/logger/logger.c:186 186 *strchr(hostname, '.') = '\0'; (gdb) bt #0 0x0000000000402152 in main (argc=, argv=) 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 FreeBSD UNIX: Web: http://www.FreeBSD.org The need of the many outweighs the greed of the few.