473,408 Members | 1,845 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

fork + syslog blocking

Hello,

I'm having what seems to be a deadlock in syslog with the code (wich
comes from a project I'm working on, but I've reduced the test case to
its minimum) I put at the end of this messsage.

It must be compiled with -lpthread. (so the fork could be also a
possible cause of what I'm mentionning).
The "bug" does not occur every times. So you should maybe launch the
prog a few times before the block occurs.

Is there someone knowing the true about this fact :
Is it from my code ? or is it a bug within syslog ???
or something else ?
And are they any technics (or patch for syslog ?) wich could resolve the
problem ??

Ho, btw, I'm using Linux 2.4.21, and it's a Mandrake 9.1.

Thanks for your responses.

Greg.

Here is the code :

################################################## ################################

#include <sys/types.h>
#include <signal.h>
#include <syslog.h>
#include <stdio.h>
#include <errno.h>

void handler_sigchild (int signal_value);

void
set_father_signals (void)
{
struct sigaction
sigchild;
sigset_t
sigsblocked;

sigchild.sa_handler = handler_sigchild;
sigchild.sa_flags = 0;

if (sigfillset (&sigchild.sa_mask) == -1)
{
printf ("set_father_signals: a sigfillset() failed. err = %s
!\n", strerror (errno));
}

if ((sigfillset (&sigsblocked) == -1) /* and we respond
only to those */
|| (sigdelset (&sigsblocked, SIGCHLD) == -1))
{
printf ("set_father_signals: could not fill blocked signals.
err = %s !\n", strerror (errno));
}

if (sigprocmask (SIG_SETMASK, &sigsblocked, NULL) == -1)
{
printf ("set_father_signals: could not set blocked signals. err
= %s !\n", strerror (errno));
}

if (sigaction (SIGCHLD, &sigchild, NULL) == -1)
{
printf ("kern_set_father_signals: a sigaction() failed. err =
%s !\n", strerror (errno));
}
}

int main ( int argc, char * argv [] )
{
pid_t pid;

openlog ("testbug3", LOG_PID | LOG_CONS, LOG_DAEMON);

set_father_signals ();

switch (pid = fork ())
{
case -1:
printf ("Error while forking : %s\n", strerror (errno));
break;
case 0 : /* in child */
exit (0); /* just return immediately */
default : /* in father */
printf ("father: after fork, before syslog\n");
fflush (stdout);
syslog (LOG_INFO, "TRACE: child's pid = %lu", pid);
printf ("father: after fork, after syslog\n");
fflush (stdout);
}

closelog ();
wait (NULL); /* wait for the child */
printf ("exiting\n");
fflush (stdout);
}

void handler_sigchild (int sig)
{
printf ("In sighandle, before syslog\n");
fflush (stdout);
syslog (LOG_INFO, "received a SIGCHLD");
printf ("In sighandle, after syslog\n");
fflush (stdout);
}

################################################## #######################

Nov 13 '05 #1
1 3690
Gregory Starck <gr************@skybel.net> wrote:
I'm having what seems to be a deadlock in syslog with the code (wich
comes from a project I'm working on, but I've reduced the test case to
its minimum) I put at the end of this messsage. It must be compiled with -lpthread. (so the fork could be also a
possible cause of what I'm mentionning).
The "bug" does not occur every times. So you should maybe launch the
prog a few times before the block occurs.


Sorry, but you really should post this e.g. on comp.unix.programmer
because everything your asking about is off-topic here in clc. The
topic of this group is programming in standard C and there's no
fork(), syslog() etc. in standard C - these are UNIX (or POSIX)
extensions. If you post in compunix.programmer you probably also
should explain in more detail what you mean by "deadlock" (and
did you notice that you may call closelog() before the SIGCHLD
has arrived?).
Regards, Jens
--
_ _____ _____
| ||_ _||_ _| Je***********@physik.fu-berlin.de
_ | | | | | |
| |_| | | | | | http://www.physik.fu-berlin.de/~toerring
\___/ens|_|homs|_|oerring
Nov 13 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Erich Trowbridge | last post by:
Has anybody seen this tool? It is awesome. check out http://vw.vermeer.org/ . It's a php front end for large-scale syslog deployments. It makes managing syslog in large networks a snap. The idea...
5
by: Micha³ Wo¼niak | last post by:
Hi again The Question of Logs, part II. :) What are the advantages/disadvantages of using syslog() to do the logging rather than writing the logs with fopen(), fwrite() and fclose()? What...
0
by: Stephen Touset | last post by:
--=-vqiBeaRpc7WKjfgJmDzK Content-Type: text/plain Content-Transfer-Encoding: quoted-printable Is there now a way within MySQL to log to syslog? I was reading an archived email conversation...
8
by: Guy Noir | last post by:
Hello. I am needing some advice. I need to build a syslog server that writes to a sql backend. I am concerned about the server not being able to handle multiple requests. For example on an...
27
by: steve | last post by:
I was given the following code, and asked what the possible outputs could be. We're learning about processes and forking. int value; int main(){ int pid, number = 1; value = 2; pid = fork();...
2
by: greg | last post by:
Hi All, Could anyone tell me how I could syslog to a specific log (e.g. /var/ log/daemon.log, /var/log/syslog.log...)? Thanks very much in advance! -Greg
3
by: Troels Arvin | last post by:
Hello, On a server with DB2 v. 8.2, db2diag.log ran full, it seems (i.e. reached a size of 2GB). And it seems that in this case, DB2 started using syslog instead. I would actually like DB2 to...
1
by: anjaliraman2 | last post by:
Hi All, I am facing a problem of writing into and reading from syslog in Linux Enviornment using C++. The CPU utilization is extremely high of about 55% and is creating problems for other...
1
by: Lincoln Yeoh | last post by:
Hi, I've just started to learn python (I've been using perl for some years). How do I redirect ALL stderr stuff to syslog, even stderr from external programs that don't explicitly change their...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.