Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Signals with accompanying information sent with sigqueue()

Reply
Thread Tools

Signals with accompanying information sent with sigqueue()

 
 
Falcon Kirtaran
Guest
Posts: n/a
 
      03-12-2008
I'm using glibc 2.7-r1 packaged by gentoo and gcc 4.2.2 also packaged by
gentoo. The following code results in the value of the void * component
of the sigval struct sent from the sending program being assigned to the
si_int member of the siginfo_t struct.

Sending process:

sigval sigval_data;
sigval_data.sival_int = 1;
sigval_data.sival_ptr = 5; /*only to test this*/
sigqueue(getppid(), SIGUSR1, sigval_data);
pause(); //wait for the parent to die.
exit(-1); //we should have died by SIGHUP before.

Receiving process's signal handler:

void h_mesg(int signal, siginfo_t * info, void * context) {
printf("DEBUG: h_mesg: int value = %i\n", info->si_int);
};

It prints that the value is 5. Have I done something silly, or is this
a bug in glibc or in something else?

--
--Falcon Kirtaran
 
Reply With Quote
 
 
 
 
ppi
Guest
Posts: n/a
 
      03-12-2008
> sigval sigval_data;
> sigval_data.sival_int = 1;
> sigval_data.sival_ptr = 5; /*only to test this*/
> sigqueue(getppid(), SIGUSR1, sigval_data);


you should ask that kind of stuff in comp.unix.programmer.
Regarding your question, sigval is a union, as such last assignment
wins i.e. .sival_ptr and .sival_int share the same storage location
hence the value 5.

cheers,
-- paulo

 
Reply With Quote
 
 
 
 
Falcon Kirtaran
Guest
Posts: n/a
 
      03-12-2008
ppi wrote:
>> sigval sigval_data;
>> sigval_data.sival_int = 1;
>> sigval_data.sival_ptr = 5; /*only to test this*/
>> sigqueue(getppid(), SIGUSR1, sigval_data);

>
> you should ask that kind of stuff in comp.unix.programmer.
> Regarding your question, sigval is a union, as such last assignment
> wins i.e. .sival_ptr and .sival_int share the same storage location
> hence the value 5.
>
> cheers,
> -- paulo
>


Thank you. So I suppose I should not assign to both, then.
 
Reply With Quote
 
santosh
Guest
Posts: n/a
 
      03-12-2008
Falcon Kirtaran wrote:

> ppi wrote:
>>> sigval sigval_data;
>>> sigval_data.sival_int = 1;
>>> sigval_data.sival_ptr = 5; /*only to test this*/
>>> sigqueue(getppid(), SIGUSR1, sigval_data);

>>
>> you should ask that kind of stuff in comp.unix.programmer.
>> Regarding your question, sigval is a union, as such last assignment
>> wins i.e. .sival_ptr and .sival_int share the same storage location
>> hence the value 5.


> Thank you. So I suppose I should not assign to both, then.


You can, but you can only legally access the object to which the latest
write was done.

Also (n1256 - 6.5.2.3p5):

One special guarantee is made in order to simplify the use of unions: if
a union contains several structures that share a common initial
sequence (see below), and if the union object currently contains one of
these structures, it is permitted to inspect the common initial part of
any of them anywhere that a declaration of the complete type of the
union is visible. Two structures share a common initial sequence if
corresponding members have compatible types (and, for bit-fields, the
same widths) for a sequence of one or more initial members.

A footnote (not normative) also adds:

If the member used to access the contents of a union object is not the
same as the member last used to store a value in the object, the
appropriate part of the object representation of the value is
reinterpreted as an object representation in the new type as described
in 6.2.6 (a process sometimes called "type punning"). This might be a
trap representation.

 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Finding an accompanying java book to Objects first with java SIDSARAN@gmail.com Java 8 01-22-2007 07:14 AM
strange information from asp.net trace / getting performance information using WebRequest and StreamReader z. f. ASP .Net 0 02-03-2005 11:23 AM
Browser information not being sent to the Domain Master Browser Russell Stamper Cisco 1 10-12-2004 08:14 PM
PythonDSS: A suggestion for a book and accompanying software distribution Ajith Prasad Python 0 09-26-2004 12:53 PM
Identifying type of web control that sent some information to servlet Asad Java 3 05-26-2004 04:05 AM



Advertisments