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"
2018-10-04 01:22:50 +02:00
#include "../../core/client.h"
2017-01-19 22:07:52 +01:00
#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
2018-10-04 00:30:47 +02:00
struct ipc_service srv;
2017-01-19 22:07:52 +01:00
struct channels chans;
void handle_signal (int signalnumber)
{
// the application will shut down, and remove the service named pipe
2018-10-04 00:18:08 +02:00
if (ipc_server_close (&srv) < 0) {
handle_error("ipc_server_close < 0");
2017-01-19 22:07:52 +01:00
}
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
{
2018-10-04 00:30:47 +02:00
memset (&srv, 0, sizeof (struct ipc_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
2018-10-04 00:18:08 +02:00
if (ipc_server_init (argc, argv, env, &srv, PUBSUBD_SERVICE_NAME) < 0) {
handle_error("ipc_server_init < 0");
2017-01-19 22:07:52 +01:00
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
2018-10-04 00:18:08 +02:00
if (ipc_server_close (&srv) < 0) {
handle_error("ipc_server_close < 0");
2017-01-19 22:07:52 +01:00
}
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
}