SUMMARY: syslog(3) - Problem

From: Michael Mehl (mehl@dfki.uni-sb.de)
Date: Thu Apr 16 1992 - 14:57:14 CDT


> After a chroot(2)-call syslog(3) doesn't work any more. The trace of the
> program shows the following output:

> sendto(3, "<31>Apr 15 18:11:59 myprog[8941]: ".., 42, 0, AF_UNIX(/dev/log), 16)
> = -1 (No such file or directory)

> So the error seems to be that the AF_UNIX socket "/dev/log" is no longer
> accessible after the chroot-call.

I received the following replies: (Thanks folks)

------------

From: Neil W Rickert <rickert@cs.niu.edu>
From: pete@cs.UMD.EDU (Pete Cottrell)
From: Matt Crawford <matt@oddjob.uchicago.edu>
From: jimw@PE-Nelson.COM (Jim Watt)
From: trinkle@cs.purdue.edu
From: doug@perry.berkeley.edu (Doug Neuhauser)
From: Jim Guyton <guyton%condor@rand.org>
From: Barry Margolin <barmar@Think.COM>

------------

Solutions:

11111111111111111111111111111111111111111111111111111111111111111111111111111111

> This behavior is true on the Suns, but not on many other vendors'
> version of syslog(); I encountered the problem when I was trying to
> determine why my ftp logging disappeared I got an anonymous connection.
> Since I have source, my solution was to figure out why Sun's syslog()
> was different, and to change it. You might be able to get a free version
> of the syslog code from the BSD Network II distribution and use that.
> Here's my RCS comments, and my diffs:

revision 1.2
date: 92/03/24 18:31:17; author: pete; state: Exp; lines added/del: 3/1
change sendto() to connect() and write(), so that SyslogAddr is bound once
and for all. If we don't, then the chroot() done with anonymous FTPs will
make us lose the syslog() socket in /dev/log.

rcsdiff -c -r1.1 syslog.c
RCS file: RCS/syslog.c,v
retrieving revision 1.1
diff -c -r1.1 syslog.c
*** /tmp/,RCSt1a22223 Wed Apr 15 17:07:47 1992
--- syslog.c Tue Mar 24 18:33:45 1992
***************
*** 166,172 ****
                c = MAXLINE;

        /* output the message to the local logger */
! if (sendto(LogFile, outline, c, 0, &SyslogAddr, sizeof SyslogAddr) >= 0)
                return;
        if (!(LogStat & LOG_CONS))
                return;
--- 166,173 ----
                c = MAXLINE;

        /* output the message to the local logger */
! /*if (sendto(LogFile, outline, c, 0, &SyslogAddr, sizeof SyslogAddr) >=
0)*/
! if (write(LogFile, outline, c) >= 0)
                return;
        if (!(LogStat & LOG_CONS))
                return;
***************
*** 216,221 ****
        if (LogStat & LOG_NDELAY) {
                LogFile = socket(AF_UNIX, SOCK_DGRAM, 0);
                (void)fcntl(LogFile, F_SETFD, 1);
+ (void) connect(LogFile, &SyslogAddr, sizeof SyslogAddr);
        }
  }

22222222222222222222222222222222222222222222222222222222222222222222222222222222

> I made that discovery while working on ftpd logging. The only answer I
> found was to use "localhost" for the log. Here's the code, from syslog.c:

/*
 * OPENLOG -- open system log
 */

openlog(ident, logstat, logfac)
        char *ident;
        int logstat, logfac;
{
        if (ident != NULL)
                LogTag = ident;
        LogStat = logstat;
        if (logfac != 0 && (logfac &~ LOG_FACMASK) == 0)
                LogFacility = logfac;
        if (LogFile == -1) {
                SyslogAddr.sin_family = AF_INET;
                SyslogAddr.sin_port = htons(514);
                SyslogAddr.sin_addr.s_addr = inet_addr("127.0.0.1");
                if (LogStat & LOG_NDELAY) {
                        LogFile = socket(AF_INET, SOCK_DGRAM, 0);
                        fcntl(LogFile, F_SETFD, 1);
                }
        }
        if (LogFile != -1 && !connected /*&&
            connect(LogFile, &SyslogAddr, sizeof(SyslogAddr)) != -1*/)
                connected = 1;
}

33333333333333333333333333333333333333333333333333333333333333333333333333333333

make /dev/log a symlink to the real /dev/log which is in within the anonymous
ftp subtree.

4444444444444444444444444444444444444444444444444444444444444444444444444444444

Well, one fix is to use the internet version of syslog(3) instead
of the unix port. That's what I did to make our additional syslog
msgs in anonymous ftp work properly. See bsd source sites for pd
versions of syslog.

------------
Michael Mehl, DFKI, Stuhlsatzenhausweg 3, D-W-6600 Saarbruecken 11, Germany
Tel: +49 681 302-5308; Fax: +49 681 302-5341; Net: mehl@dfki.uni-sb.de



This archive was generated by hypermail 2.1.2 : Fri Sep 28 2001 - 23:06:41 CDT