What can cause syslog() print to a opened user file? - Unix

This is a discussion on What can cause syslog() print to a opened user file? - Unix ; Hi, My program ( cpp on arm/linux ) use syslog(3) to output debug information to log files. But today when I use the program, I suddenly found (I may made some changes on the code this week, but I can ...

+ Reply to Thread
Results 1 to 4 of 4

Thread: What can cause syslog() print to a opened user file?

  1. What can cause syslog() print to a opened user file?

    Hi,

    My program ( cpp on arm/linux ) use syslog(3) to output debug
    information to log files. But today when I use the program, I suddenly
    found (I may made some changes on the code this week, but I can not
    remember anything relevant) the log file is empty, and all log
    messages were printed to another file /var/tmp/myprg.pid. The
    myprg.pid file is opened by my program and keep it open in all the
    program's lifetime. Actually, you may see that my program is a daemon,
    which closes all file descriptors after it starts up, then open the
    mentioned myprg.pid file which is filled with its pid number.

    Before I going to debug, it will be great if I can hear some of you
    advice for the potential causes from your experience. Thank you.

    -
    narke

  2. Re: What can cause syslog() print to a opened user file?

    In article
    ,
    Steven Woody wrote:

    > Hi,
    >
    > My program ( cpp on arm/linux ) use syslog(3) to output debug
    > information to log files. But today when I use the program, I suddenly
    > found (I may made some changes on the code this week, but I can not
    > remember anything relevant) the log file is empty, and all log
    > messages were printed to another file /var/tmp/myprg.pid. The
    > myprg.pid file is opened by my program and keep it open in all the
    > program's lifetime. Actually, you may see that my program is a daemon,
    > which closes all file descriptors after it starts up, then open the
    > mentioned myprg.pid file which is filled with its pid number.
    >
    > Before I going to debug, it will be great if I can hear some of you
    > advice for the potential causes from your experience. Thank you.


    Is your first call to syslog() or openlog() before you close all
    descriptors? It sounds to me like openlog() is opening the log file,
    and you're closing it. But it continues to use that fd, which is the
    same fd that was returned when you opened myprg.pid.

    If you're going to close all descriptors, you have to do it very early
    in the program, before calling anything that might open its own
    descriptors that it expects to keep open for the process lifetime.

    --
    Barry Margolin, barmar@alum.mit.edu
    Arlington, MA
    *** PLEASE post questions in newsgroups, not directly to me ***
    *** PLEASE don't copy me on replies, I'll read them in the group ***

  3. Re: What can cause syslog() print to a opened user file?

    On Sep 26, 3:29*am, Barry Margolin wrote:
    > In article
    > ,
    > *Steven Woody wrote:
    >
    > > Hi,

    >
    > > My program ( cpp on arm/linux ) use syslog(3) to output debug
    > > information to log files. But today when I use the program, I suddenly
    > > found (I may made some changes on the code this week, but I can not
    > > remember anything relevant) the log file is empty, and all log
    > > messages were printed to another file /var/tmp/myprg.pid. * The
    > > myprg.pid file is opened by my program and keep it open in all the
    > > program's lifetime. Actually, you may see that my program is a daemon,
    > > which closes all file descriptors after it starts up, then open the
    > > mentioned myprg.pid file which is filled with its pid number.

    >
    > > Before I going to debug, *it will be great if I can hear some of you
    > > advice for the potential causes from your experience. *Thank you.

    >
    > Is your first call to syslog() or openlog() before you close all
    > descriptors? *It sounds to me like openlog() is opening the log file,
    > and you're closing it. *But it continues to use that fd, which is the
    > same fd that was returned when you opened myprg.pid.


    Yes, the openlog() is almost my first statement in the program. I did
    think this might be the cause as you. But, my program is always
    written in this way, why I did not met problem before? And, I had ever
    watched the /proc/pid/fd directory, it seems openlog() will not open
    any descriptor. But, maybe I am wrong, so I will take this into
    account in my debug. Thank you!!

    >
    > If you're going to close all descriptors, you have to do it very early
    > in the program, before calling anything that might open its own
    > descriptors that it expects to keep open for the process lifetime.
    >
    > --
    > Barry Margolin, bar...@alum.mit.edu
    > Arlington, MA
    > *** PLEASE post questions in newsgroups, not directly to me ***
    > *** PLEASE don't copy me on replies, I'll read them in the group ***



  4. Re: What can cause syslog() print to a opened user file?

    In article
    ,
    Steven Woody wrote:

    > On Sep 26, 3:29*am, Barry Margolin wrote:
    > > In article
    > > ,
    > > *Steven Woody wrote:
    > >
    > > > Hi,

    > >
    > > > My program ( cpp on arm/linux ) use syslog(3) to output debug
    > > > information to log files. But today when I use the program, I suddenly
    > > > found (I may made some changes on the code this week, but I can not
    > > > remember anything relevant) the log file is empty, and all log
    > > > messages were printed to another file /var/tmp/myprg.pid. * The
    > > > myprg.pid file is opened by my program and keep it open in all the
    > > > program's lifetime. Actually, you may see that my program is a daemon,
    > > > which closes all file descriptors after it starts up, then open the
    > > > mentioned myprg.pid file which is filled with its pid number.

    > >
    > > > Before I going to debug, *it will be great if I can hear some of you
    > > > advice for the potential causes from your experience. *Thank you.

    > >
    > > Is your first call to syslog() or openlog() before you close all
    > > descriptors? *It sounds to me like openlog() is opening the log file,
    > > and you're closing it. *But it continues to use that fd, which is the
    > > same fd that was returned when you opened myprg.pid.

    >
    > Yes, the openlog() is almost my first statement in the program. I did
    > think this might be the cause as you. But, my program is always
    > written in this way, why I did not met problem before? And, I had ever
    > watched the /proc/pid/fd directory, it seems openlog() will not open
    > any descriptor. But, maybe I am wrong, so I will take this into
    > account in my debug. Thank you!!


    Do you call syslog() before closing descriptors? I don't think
    openlog() opens any descriptors, it just sets things up, but the first
    call to syslog() will.

    Why don't you trace the system calls, you should see all the file opens
    and closes.

    --
    Barry Margolin, barmar@alum.mit.edu
    Arlington, MA
    *** PLEASE post questions in newsgroups, not directly to me ***
    *** PLEASE don't copy me on replies, I'll read them in the group ***

+ Reply to Thread