My understanding of sigaction is that my signal handler function should get a siginfo_t
argument with the pid and uid of the process sending the signal.
#include <stdatomic.h>
#include <signal.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
static atomic_int gTermParentPid = -1;
static void SigTermHandler(int signalValue, siginfo_t *info, void *uap) {
gTermParentPid = info->si_pid;
}
int main(int argc, const char * argv[]) {
struct sigaction handlerAction;
handlerAction.sa_sigaction = SigTermHandler;
handlerAction.sa_flags = SA_SIGINFO;
sigemptyset(&handlerAction.sa_mask);
if (sigaction(SIGTERM, &handlerAction, NULL) != 0) {
perror(NULL);
abort();
}
printf("pid: %d\n", getpid());
while (gTermParentPid == -1) {
sleep(1);
}
printf("ParentPid: %d\n", gTermParentPid);
}
so when I run the above program and then send it a kill
from another shell I would expect it to log the pid of the shell I sent the kill
from. In all cases though I am getting a pid and uid of 0. Is this expected? This seems to work fine on linux.
I tested this with a variety of other signals (SIGALRM
, SIGINT
) with the same results.
Not sure if Exception Handling
was the right tag, but it was the closest I could find.
Filed as FB11850436 as well.