LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Other *NIX Forums > *BSD
User Name
Password
*BSD This forum is for the discussion of all BSD variants.
FreeBSD, OpenBSD, NetBSD, etc.

Notices


Reply
  Search this Thread
Old 11-19-2008, 09:49 AM   #1
Curtor
Member
 
Registered: Feb 2008
Posts: 65

Rep: Reputation: 16
siginfo_t not set on BSD


Alright, so, I have created a simple signal experiment program.

-Program sets up child signals
-Forks, and prints PID of child
-Child exits
-Parent gets exit signal from child and prints info on the signal

This worked fine and dandy on Ubuntu, and upon porting it over to BSD I am not getting the same results. Any idea how I can get this working?

Ubuntu Code Output:
Code:
PID: 4121
Entering signal handler!
Handling signal 17 at 0x3e800001019
PID: 4121	 
Signal code: 1
BSD Code Output:
Code:
PID: 11747
Entering signal handler!
Handling signal 20 at 0x0
PID: 0   
Signal code: 0
Code:
Code:
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
#include <cstring>
#include <errno.h>


void signalChild(
    int signal, siginfo_t* info, void* notUsed
){
    printf("Entering signal handler!\n");
    if ( info == NULL ) 
    {
        printf("siginfo is NULL...aborting!\n");
        exit(1);
    }
    printf("Handling signal %d at %p\n", signal, info->si_addr);
    printf("PID: %d\t \n", info->si_pid);
    printf("Signal code: %d\n", info->si_code );
}


int main()
{
    struct sigaction child;
    sigemptyset ( &child.sa_mask );
    child.sa_sigaction = &signalChild;
    child.sa_flags = 0;
    child.sa_flags = SA_SIGINFO;

    if ( sigaction( SIGCHLD, &child, NULL ) == -1 )
    {
        fprintf( stderr, "Error with signal setup.  Errno: %i\n", errno );
        exit( 1 );
    }

    int pid = fork();

    if ( pid == 0 )
    {
        fprintf( stderr, "PID: %i\n", getpid() );
        exit(0);
    }

    sleep( 1 );
    exit(0);
}
 
Old 11-25-2008, 05:19 AM   #2
taylor_venable
Member
 
Registered: Jun 2005
Location: Indiana, USA
Distribution: OpenBSD, Ubuntu
Posts: 892

Rep: Reputation: 43
If you search around, it seems like there's some contention on whether this is a bug or not.

So it's either a bug, or intentional, or a kludge that nobody uses. I think you'd be best mailing some technical hacker lists for whatever particular BSD you're trying to port it to. For the record, I get exactly the same result as you on OpenBSD 4.4; though on my system at least I don't think that si_addr and si_pid can be set at the same time - they're in separate entries of a union.

If you figure something out, kindly post back here; my curiosity has been piqued.
 
Old 11-26-2008, 02:25 PM   #3
Curtor
Member
 
Registered: Feb 2008
Posts: 65

Original Poster
Rep: Reputation: 16
Well, for those that are curious, I did do a little digging. I got a response back from the league, or rather, the BSD mailing list. In short...

Quote:
It doesn't work because no one has has taught the kernel to generate
one SIGCHLD per zombie child, with siginfo value extracted from the
zombie's information. I.e., this is a known defect. It'll get fixed
when it gets to the top of someone's priority heap.

(If someone else is interested in taking a stab at this, I could
review and perhaps shepherd it, but I don't have the time right now to
do it myself.)


"Philip Guenther" <guenther@gmail.com>
Furthermore...

Quote:
> ...
> I found the following post from Otto that seems to say that what I'm
> trying to do may not work on OpenBSD.
>
> http://www.archivum.info/fa.openbsd..../msg00124.html
> ...

This is probably a bug, as I said in the post you mentioned. Just use
wait(2), there are plenty of examples in the tree that use wait in a
SIGCHLD handler.

Otto Moerbeek <otto@drijf.net>
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Video For BSD --- New project to develop V4L compatible drivers for BSD Fritz_Katz *BSD 5 07-19-2008 11:53 PM
LXer: Set Up PC-BSD v1.4 beta LXer Syndicated Linux News 0 09-02-2007 10:20 AM
LXer: PC-BSD : A user friendly BSD flavor geared for the desktop LXer Syndicated Linux News 0 02-04-2006 03:01 PM
How set x-manager on BSD machine sarajevo *BSD 2 11-20-2005 11:34 PM

LinuxQuestions.org > Forums > Other *NIX Forums > *BSD

All times are GMT -5. The time now is 05:25 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration