X-Git-Url: https://gapil.gnulinux.it/gitweb/?p=gapil.git;a=blobdiff_plain;f=sources%2Frtsigvalsend.c;fp=sources%2Frtsigvalsend.c;h=a9c156d7f15523dde7086384f479680f698310d4;hp=0000000000000000000000000000000000000000;hb=21e461fe379f4875729fcfe1ac1876f5f166e827;hpb=8ef50c43a245c37e5018ecd1c3795cea0849b8cd diff --git a/sources/rtsigvalsend.c b/sources/rtsigvalsend.c new file mode 100644 index 0000000..a9c156d --- /dev/null +++ b/sources/rtsigvalsend.c @@ -0,0 +1,76 @@ +/* test_fopen.c + * + * Copyright (C) 2021 Simone Piccardi + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ +/**************************************************************** + * + * Program rtsigvalsend.c: + * Program to test sigqueue and sigval send + * + * Author: Simone Piccardi + * Aug 2021 + * + * Usage: ./rtsigvalsend + **********************************************************/ +/* + * Include needed headers + */ +#include /* unix standard library */ +#include /* standard I/O library */ +#include /* C standard library */ +#include /* C strings library */ +#include /* signal constants, types and functions */ +#include /* error definitions and routines */ +#include + +#define MAXLINE 256 + +void SigHand(int signum, siginfo_t *info, void *ucontext) { + printf("Signal %d\n", signum); + printf("From pid %d\n", info->si_pid); + printf("From user %d\n", info->si_uid); + printf("Value %d\n", info->si_value.sival_int); +} + +int main(int argc, char *argv[], char *envp[]) +{ + char buffer[MAXLINE+1]; + int nread; + sigval_t value; + int signo = SIGRTMIN+1; + + struct sigaction new_handl, old_handl; + new_handl.sa_sigaction = SigHand; + sigemptyset(&new_handl.sa_mask); + new_handl.sa_flags=SA_SIGINFO; + /* change action for signo signal */ + sigaction(signo, &new_handl, &old_handl); + while (1) { + nread = read(STDIN_FILENO, buffer, MAXLINE); + if (nread < 0) { + printf("Errore in lettura: %s\n", strerror(errno)); + return 0; + } + buffer[nread]=0; + value.sival_int = strtol(buffer, NULL, 10); + if (value.sival_int > 0) { + sigqueue(getpid(), signo, value); + } else { + printf("Ignoring invalid input\n"); + } + } +}