Topic: How do I use sigaction?
Author: kgor@ksg.avl.com
Date: 1995/07/24 Raw View
I get a warning from g++ (2.7.0) and cfront 3.0 on a Unixware machine.
The uname is
UNIX_SV ksg 4.2MP 2.01 i386 x86at.
My question is how do I eliminate the warning/error. I understand the
problem is do the definition of struct sigaction in <sys/signal.h> as
struct sigaction {
int sa_flags;
void (*sa_handler)();
sigset_t sa_mask;
int sa_resv[2];
};
This works in C due to the sa_handler declaration being seen as a K&R
declaration. I want to be able to create signal handling routines to
be able to use the argument(s) passed to it. Is there any way to do
this or do I have to put the signal handling code is separate modules
and compile with a C compiler? The output for g++ and CC is listed
below followed by the source code.
g++ main.cc
main.cc: In function `int main(int, char **)':
main.cc:15: warning: ANSI C++ prohibits conversion from `(int)' to `(...)'
CC main.cc
"main.cc", line 15: error: a value of type "void (*)(int)" cannot be assigned to an entity of type "void (*)()"
new_sig.sa_handler =stop;
#include <signal.h>
static int run;
extern "C" {
static void stop(int signal)
{
run = 0;
return;
}
}
int main( int argc, char *argv[])
{
struct sigaction new_sig, old_sig;
new_sig.sa_handler =stop;
sigemptyset(&new_sig.sa_mask);
new_sig.sa_flags = SA_RESTART;
sigaction(SIGHUP,&new_sig, &old_sig);
sigaction(SIGKILL,&new_sig, &old_sig);
run = 1;
while (run) {
}
}
--
Kent S. Gordon, Pinpoint Communication
email: kgor@avl.com kgor@ksg.com