tools: terminate the example server correctly on SIGINT

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
Peter Hutterer 2020-07-29 11:55:02 +10:00
parent 802dfd4ca6
commit 31581eb110

View file

@ -35,6 +35,12 @@
#include "src/util-mem.h"
#include "src/util-strings.h"
static bool stop = false;
static void sighandler(int signal) {
stop = true;
}
int main(int argc, char **argv)
{
const char SOCKETNAME[] = "eis.socket";
@ -49,6 +55,7 @@ int main(int argc, char **argv)
/* This should be handled by libeis */
signal(SIGPIPE, SIG_IGN);
signal(SIGINT, sighandler);
int rc = eis_socket_init(eis, SOCKETNAME);
if (rc != 0) {
@ -64,7 +71,7 @@ int main(int argc, char **argv)
.revents = 0,
};
while (poll(&fds, 1, -1) > -1) {
while (!stop && poll(&fds, 1, -1) > -1) {
eis_dispatch(eis);
while (true) {
@ -121,5 +128,7 @@ int main(int argc, char **argv)
}
}
eis_unref(eis);
return 0;
}