syslog_r writes to /dev/null
- From: "Tom Einertson" <tome@xxxxxxxxxxxxxxxx>
- Date: Wed, 1 Apr 2009 23:19:38 -0500
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
.
- Follow-Ups:
- Re: syslog_r writes to /dev/null
- From: Heinrich Mislik
- Re: syslog_r writes to /dev/null
- From: Thomas Braunbeck
- Re: syslog_r writes to /dev/null
- Prev by Date: Re: How to identify whether the hard disk is from SAN ?
- Next by Date: Bag: coach, miumiu, dior, chanel, juicy, lv, Gucci. Etc.
- Previous by thread: Re: How to identify whether the hard disk is from SAN ?
- Next by thread: Re: syslog_r writes to /dev/null
- Index(es):
Relevant Pages
|
Loading