Obsolete
/
libipc-old
Archived
3
0
Fork 0
This repository has been archived on 2024-06-18. You can view files and clone it, but cannot push or open issues/pull-requests.
libipc-old/pubsub/app/pubsubd.c

61 lines
1.5 KiB
C
Raw Normal View History

2017-01-19 22:07:52 +01:00
#include "../../core/communication.h"
#include "../../core/process.h"
#include "../../core/error.h"
2016-06-05 20:48:13 +02:00
#include "../lib/pubsubd.h"
2016-05-28 19:34:23 +02:00
#include <stdlib.h>
2017-01-19 22:07:52 +01:00
#include <sys/socket.h>
#include <sys/un.h>
#include <unistd.h>
#include <signal.h>
2016-09-11 14:37:41 +02:00
2017-01-19 22:07:52 +01:00
// to quit them properly if a signal occurs
struct service srv;
struct channels chans;
void handle_signal (int signalnumber)
{
// the application will shut down, and remove the service named pipe
if (srv_close (&srv) < 0) {
handle_error("srv_close < 0");
}
pubsubd_channels_del_all (&chans);
fprintf (stderr, "received a signal %d\n", signalnumber);
exit (EXIT_SUCCESS);
2016-05-28 19:34:23 +02:00
}
2016-09-08 13:23:07 +02:00
int
2016-06-12 14:41:25 +02:00
main(int argc, char **argv, char **env)
2016-06-04 20:33:44 +02:00
{
memset (&srv, 0, sizeof (struct service));
2017-01-19 22:07:52 +01:00
srv.index = 0;
srv.version = 0;
2016-05-28 19:34:23 +02:00
2017-01-19 22:07:52 +01:00
signal(SIGHUP, handle_signal);
signal(SIGINT, handle_signal);
signal(SIGQUIT, handle_signal);
2016-05-28 19:34:23 +02:00
memset (&chans, 0, sizeof (struct channels));
2016-06-04 20:33:44 +02:00
pubsubd_channels_init (&chans);
2016-05-28 19:34:23 +02:00
2017-01-19 22:07:52 +01:00
if (srv_init (argc, argv, env, &srv, PUBSUBD_SERVICE_NAME) < 0) {
handle_error("srv_init < 0");
return EXIT_FAILURE;
2016-06-04 20:33:44 +02:00
}
2017-01-19 22:07:52 +01:00
printf ("Listening on %s.\n", srv.spath);
2016-05-28 19:34:23 +02:00
2017-01-19 22:07:52 +01:00
printf("MAIN: server created\n" );
2017-01-19 22:07:52 +01:00
// the service will loop until the end of time, a specific message, a signal
pubsubd_main_loop (&srv, &chans);
2016-09-11 14:37:41 +02:00
2016-06-04 20:33:44 +02:00
// the application will shut down, and remove the service named pipe
2017-01-19 22:07:52 +01:00
if (srv_close (&srv) < 0) {
handle_error("srv_close < 0");
}
2016-05-28 19:34:23 +02:00
2016-06-04 20:33:44 +02:00
return EXIT_SUCCESS;
2016-05-28 19:34:23 +02:00
}