Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 29 Dec 2002 23:25:14 -0500
From:      John De Boskey <jwd@bsdwins.com>
To:        Current List <freebsd-current@freebsd.org>
Subject:   cron/crontab openlog() cleanup
Message-ID:  <20021230042514.GA10022@BSDWins.Com>

next in thread | raw e-mail | index | archive | help
Hi,

   While debugging a problem recently I had all.log enabled
in syslog.conf. One of the things I noted was the messages
coming from cron where the ident string was the fully qualified
pathname:

Dec 29 21:00:00 xxx4 /usr/sbin/cron[7409]: (root) CMD (newsyslog) 
Dec 29 21:00:00 xxx4 /usr/sbin/cron[7410]: (root) CMD (/usr/libexec/atrun) 

   Any comments on one of the two patch sets below? Either crontab.c
and cron.c need a patch, or the common routine they call.

cvs server: Diffing .
cvs server: Diffing cron
Index: cron/cron.c
===================================================================
RCS file: /home/ncvs/src/usr.sbin/cron/cron/cron.c,v
retrieving revision 1.14
diff -u -r1.14 cron.c
--- cron/cron.c 9 Mar 2001 03:14:09 -0000       1.14
+++ cron/cron.c 30 Dec 2002 03:24:23 -0000
@@ -70,7 +70,10 @@
 {
        cron_db database;
 
-       ProgramName = argv[0];
+       if (ProgramName = strrchr(argv[0],'/')
+               ++ProgramName;
+       else
+               ProgramName = argv[0];
 
 #if defined(BSD)
        setlinebuf(stdout);
cvs server: Diffing crontab
Index: crontab/crontab.c
===================================================================
RCS file: /home/ncvs/src/usr.sbin/cron/crontab/crontab.c,v
retrieving revision 1.19
diff -u -r1.19 crontab.c
--- crontab/crontab.c   1 Oct 2002 22:59:11 -0000       1.19
+++ crontab/crontab.c   30 Dec 2002 03:24:23 -0000
@@ -91,7 +91,10 @@
        int     exitstatus;
 
        Pid = getpid();
-       ProgramName = argv[0];
+       if (ProgramName = strrchr(argv[0],'/')
+               ++ProgramName;
+       else  
+               ProgramName = argv[0];
 
 #if defined(POSIX)
        setlocale(LC_ALL, "");


   Or, the single patch to the common openlog interface:

Index: lib/misc.c
===================================================================
RCS file: /home/ncvs/src/usr.sbin/cron/lib/misc.c,v
retrieving revision 1.11
diff -u -r1.11 misc.c
--- lib/misc.c  4 Aug 2002 04:32:27 -0000       1.11
+++ lib/misc.c  30 Dec 2002 03:24:23 -0000
@@ -508,14 +508,12 @@
 
 #if defined(SYSLOG)
        if (!syslog_open) {
-               /* we don't use LOG_PID since the pid passed to us by
-                * our client may not be our own.  therefore we want to
-                * print the pid ourselves.
-                */
+               char *Name = strrchr(ProgramName,'/');
+               Name = Name ? Name+1 : ProgramName;
 # ifdef LOG_DAEMON
-               openlog(ProgramName, LOG_PID, LOG_CRON);
+               openlog(Name, LOG_PID, LOG_CRON);
 # else
-               openlog(ProgramName, LOG_PID);
+               openlog(Name, LOG_PID);
 # endif
                syslog_open = TRUE;             /* assume openlog success */
        }


   I removed the comment since it's out-of-date. Maybe I should
leave it (to reduce diffs for historical purposes). I tend to
prefer this single patch.

   It's amazing how much this code hasn't changed... I haven't
looked at it since '88/'89 when I ported it to a ps/2 Mod80
running ISC Unix... memories... :-)

Thanks,
John


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-current" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20021230042514.GA10022>