Created
January 12, 2022 20:02
-
-
Save kernigh/d1de78fa1febc230af978781387a60c8 to your computer and use it in GitHub Desktop.
hupme.c: look at siginfo_t from SIGHUP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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