Hej. Mam taki problem - chciałbym wysyłać do procesu sygnał SIGUSR1 i za pierwszym razem chciałbym przechwycić go za pomoca new_action a po jego otrzymaniu tak przepiąć hendlera, żeby już zawsze był obsługiwany przez old_action. Chodzi o prezentację zastosowania mechanizmu z old_action. Czy może ktoś mi z tym pomóc, bo nie mam już pomysłów :(
Kod:
/* Example of using sigaction() to setup a signal handler with 3 arguments
* including siginfo_t.
*/
#include <stdio.h>
#include <unistd.h>
#include <signal.h>
#include <string.h>
static void hdl (int sig, siginfo_t *siginfo, void *context)
{
printf ("New Action: Sending PID: %ld, UID: %ld\n",
(long)siginfo->si_pid, (long)siginfo->si_uid);
}
static void oldhdl (int sig, siginfo_t *siginfo, void *context)
{
printf ("Old Action: Sending PID: %ld, UID: %ld\n",
(long)siginfo->si_pid, (long)siginfo->si_uid);
}
int main (int argc, char *argv[])
{
struct sigaction act;
struct sigaction oldact;
memset (&act, '\0', sizeof(act));
memset (&oldact, '\0', sizeof(oldact));
/* Use the sa_sigaction field because the handles has two additional parameters */
act.sa_sigaction = &hdl;
oldact.sa_sigaction = &oldhdl;
/* The SA_SIGINFO flag tells sigaction() to use the sa_sigaction field, not sa_handler. */
act.sa_flags = SA_SIGINFO;
oldact.sa_flags = SA_SIGINFO;
if (sigaction(SIGUSR1, &act, &oldact) < 0) {
perror ("sigaction");
return 1;
}
while (1)
sleep (10);
return 0;
}