Skip to content

Instantly share code, notes, and snippets.

@kernigh
Created January 12, 2022 20:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kernigh/d1de78fa1febc230af978781387a60c8 to your computer and use it in GitHub Desktop.
Save kernigh/d1de78fa1febc230af978781387a60c8 to your computer and use it in GitHub Desktop.
hupme.c: look at siginfo_t from SIGHUP
#include <err.h>
#include <signal.h>
#include <stdio.h>
#include <unistd.h>
int signo;
int code;
int sigerrno;
pid_t pid;
uid_t uid;
int value;
void
hup(int sig, siginfo_t *sip, void *ctx)
{
signo = sip->si_signo;
code = sip->si_code;
sigerrno = sip->si_errno;
pid = sip->si_pid;
uid = sip->si_uid;
value = sip->si_value.sival_int;
}
int
main(void)
{
struct sigaction sa = {};
pid_t me = getpid();
sa.sa_sigaction = hup;
sigemptyset(&sa.sa_mask);
sa.sa_flags = SA_SIGINFO;
sigaction(SIGHUP, &sa, NULL);
kill(me, SIGHUP);
printf("signo = %d %s\n", signo, signo == SIGHUP ? "SIGHUP" : "?");
printf("code = %d %s\n", code, code == SI_USER ? "SI_USER" : "?");
printf("errno = %d\n", sigerrno);
printf("pid = %d, I'm %d\n", (int)pid, (int)me);
printf("uid = %d, I'm %d\n", (int)uid, (int)getuid());
printf("value = %d\n", value);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment