syslog_r writes to /dev/null



I was debugging a problem with a program recently which appeared to
be writing data to the wrong file descriptor, so I was watching file
I/O very carefully. When I ran it under truss I noticed that every
time my program called syslog_r, truss reported that it was opening and
writing my syslog messages to /dev/null as well as to the syslog
daemon. I'm trying to figure out why that might be and I'm hoping
someone on this group might know why.

I wrote a simple test program to investigate this some. Except for a
couple of printfs for debugging, this program just calls openlog_r and
then syslog_r. Here's the whole thing.

#include <errno.h>
#include <stdio.h>
#include <stdlib.h>

#include <sys/syslog.h>

struct syslog_data internal_data = SYSLOG_DATA_INIT;

main ()
{

printf ("log_file = %d after initialization\n", internal_data.log_file);

printf ("\nCalling openlog_r\n");
openlog_r ("a.out", LOG_NDELAY | LOG_NOWAIT, LOG_USER, &internal_data);
printf ("log_file = %d after openlog_r\n", internal_data.log_file);

printf ("\nCalling syslog_r\n");
syslog_r (LOG_INFO, &internal_data, "Testing syslog");

}

I compile it using xlC_r (xlC_r -g simple.cpp -o simple). Here is the
output.

ca03dev:tome$ simple
log_file = -1 after initialization

Calling openlog_r
log_file = 3 after openlog_r

Calling syslog_r
ca03dev:tome$

As expected, the call to openlog_r created a connection to syslog as
indicated by the fact that field log_file in the syslog_data structure
changes from -1 to 3.

When I run it under truss, though, I see function syslog_r opening
/dev/null and writing my test message to it.

log_file = -1 after initialization
kwrite(1, 0xF0392A18, 35) = 35

Calling openlog_r
kwrite(1, 0xF0392A18, 19) = 19
socket(1, 2, 0) = 3
kfcntl(3, F_SETFD, 0x00000001) = 0
connext(3, 0x20000734, 16) = 0
log_file = 3 after openlog_r
kwrite(1, 0xF0392A18, 29) = 29

Calling syslog_r
kwrite(1, 0xF0392A18, 18) = 18
open(0xF034E27C, O_WRONLY|O_CREAT|O_TRUNC) = 4
kioctl(4, 22528, 0x00000000, 0x00000000) Err#19 ENODEV
kioctl(4, 22528, 0x00000000, 0x00000000) Err#19 ENODEV
kwrite(4, " T e s t i n g s y s l".., 15) = 15
close(4) = 0
send(3, 0x2FF1ED54, 42, 0) = 42
kfcntl(1, F_GETFL, 0x10013B3B) = 67110914
kfcntl(2, F_GETFL, 0x10013B3B) = 67110914
_exit(0)

Running it in dbx shows that the file name passed to open at 0xF034E27C
is /dev/null. Notice that it writes the test message to /dev/null (the
kwrite call to fd 4). After that it does send the message to syslog
(the send call to fd 3), so the program works. It just seems odd (and
wasteful) that it opens /dev/null and sends a copy of the message to it
every time.

Does anyone have any idea why it is doing this? I'm running this on
AIX 5.3 in case that matters any.

--
Tom Einertson E-mail: tome@xxxxxxxxxxxxxxxx
SIEMENS Power Transmission & Distribution Phone: (952) 607-2244
Energy Management & Automation Division Fax: (952) 607-2018
10900 Wayzata Boulevard, Suite 400
Minnetonka, MN, 55305


.



Relevant Pages

  • Re: Want function or class that uses reflection to iterate over properties in custom object
    ... use a "real" IDE with debugging support. ... > Why don't you use the debugger instead of writing debug code. ... I build and extend a lot of custom objects, ... I've learned that you can do this using reflection. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: segmentation fault - code attached
    ... It is used in VLSI for debugging and waveform dump in ... I was writing a library for the format. ... > `struct Var'. ... Artie Gold -- Austin, Texas ...
    (comp.lang.c)
  • Re: segmentation fault - code attached
    ... > segmentation fault when executing calloc. ... It is used in VLSI for debugging and waveform dump in ... I was writing a library for the format. ... allocated enough space for a pointer to `struct Var' not an instance of ...
    (comp.lang.c)
  • Re: Gallery Pagination Result Problem
    ... I use Altova XML Spy Home Edition when writing simple XML scripts, and it has the added benefit of validating the XML and pointing out errors against the DTD. ... Is there such a free program for writing PHP that has a good debugging mode or validation? ... And if I'm not using a debugger, I've found strategically placed echo statements do wonders for debugging. ...
    (comp.lang.php)
  • Re: ANSI C compliance
    ... > Writing a significant chunk of embedded code. ... > workstation and debugging it there because there were far better tools ... I used some stubs for platform specific functionality. ... C++ Faq: http://www.parashift.com/c++-faq-lite ...
    (comp.lang.c)

Loading