Skip to content
Snippets Groups Projects
Commit 3665c81f authored by Marek Vavrusa's avatar Marek Vavrusa
Browse files

Improved signal handling - custom signals.

parent d8971f9f
Branches
Tags
No related merge requests found
#ifndef COMMON
#define COMMON
#include <signal.h>
/* Common types and constants.
*/
......@@ -23,4 +24,8 @@ typedef unsigned int uint;
/* Eliminate compiler warning with unused parameters. */
#define UNUSED(param) (param) = (param)
/* Signal definitions. */
#define SIGCLOSE SIGALRM
#define SIGREADY SIGUSR1
#endif // COMMON
#include <stdio.h>
#include <signal.h>
#include "common.h"
#include "server.h"
......@@ -14,7 +13,7 @@ static cute_server* s_server = NULL;
// SIGINT signal handler
void interrupt_handle(int s)
{
// Invalid input
// Omit other signals
if(s != SIGINT || s_server == NULL) {
return;
}
......@@ -54,7 +53,8 @@ int main( int argc, char **argv )
sigemptyset(&sa.sa_mask);
sa.sa_flags = 0;
sigaction(SIGINT, &sa, NULL);
sigaction(SIGALRM, &sa, NULL); // Notification/Interrupt
sigaction(SIGCLOSE, &sa, NULL); // Interrupt
sigaction(SIGREADY, &sa, NULL); // Notification - server is ready
// Run server
if ((res = cute_start(s_server, argv + 1, argc - 1)) != 0) {
......
......@@ -108,6 +108,9 @@ int cute_start( cute_server *server, char **filenames, uint zones )
if(ret < 0)
return ret;
// Server is ready
raise(SIGREADY);
// Wait for dispatchers to finish
ret = sm_wait(server->manager[TCP]);
......
......@@ -30,12 +30,15 @@ static inline void udp_handler(sm_event *ev)
// Error and interrupt handling
//fprintf(stderr, "recvfrom(): thread %p ret %d errno %s.\n", (void*)pthread_self(), n, strerror(errno));
if(n <= 0 || !ev->manager->is_running) {
if(n <= 0) {
if(errno != EINTR && errno != 0) {
log_error("udp: reading data from the socket failed: %d - %s\n", errno, strerror(errno));
}
return;
if(!ev->manager->is_running)
return;
else
continue;
}
debug_sm("udp: received %d bytes.\n", n);
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment