genode/repos/ports/src/test/noux_signals/main.cc
Norman Feske ca971bbfd8 Move repositories to 'repos/' subdirectory
This patch changes the top-level directory layout as a preparatory
step for improving the tools for managing 3rd-party source codes.
The rationale is described in the issue referenced below.

Issue #1082
2014-05-14 16:08:00 +02:00

57 lines
1018 B
C++

/*
* \brief Noux SIGINT handler test
* \author Christian Prochaska
* \date 2013-10-17
*/
/*
* Copyright (C) 2013 Genode Labs GmbH
*
* This file is part of the Genode OS framework, which is distributed
* under the terms of the GNU General Public License version 2.
*/
#include <errno.h>
#include <signal.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/wait.h>
void signal_handler(int signal)
{
printf("%d: signal handler for signal %d called\n",
getpid(), signal);
}
int main(int argc, char *argv[])
{
char c;
struct sigaction sa;
memset (&sa, '\0', sizeof(sa));
sa.sa_handler = signal_handler;
sigaction(SIGINT, &sa, 0);
int pid = fork();
if (pid == 0)
printf("test ready\n");
if ((read(0, &c, 1) == -1) && (errno = EINTR))
printf("%d: 'read()' returned with error EINTR\n", getpid());
else
printf("%d: 'read()' returned character 0x = %x\n", getpid(), c);
if (pid > 0) {
waitpid(pid, 0, 0);
printf("test finished\n");
}
return 0;
}