jitterbug/main.c

50 lines
1.1 KiB
C
Raw Normal View History

#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
2022-12-26 20:28:56 +02:00
#include <string.h>
#include <errno.h>
2023-01-03 17:20:02 +02:00
#include <signal.h>
2022-12-29 20:10:36 +02:00
#include "match.h"
#include "server.h"
const char *arg_shift(int *argc, char ***argv) {
if (*argc < 1)
return NULL;
const char *result = *argv[0];
*argc -= 1;
*argv += 1;
return result;
}
int main(int argc, char *argv[])
{
arg_shift(&argc, &argv);
const char *socket_path = arg_shift(&argc, &argv);
socket_path = socket_path == NULL ? "/tmp/jitterbug-unix0" : socket_path;
2023-01-03 17:20:02 +02:00
/* we handle send() errors directly in the code */
signal(SIGPIPE, SIG_IGN);
2023-01-19 02:46:49 +02:00
Bus *srv = bus_create(socket_path);
if (srv == NULL) {
fprintf(stderr, "server_create failed\n");
return EXIT_FAILURE;
}
printf("Listening on %s\n", socket_path);
while (1) {
2023-01-10 13:08:49 +02:00
if (bus_turn(srv) < 0) {
2022-12-26 20:28:56 +02:00
fprintf(stderr, "server_turn failed (errno=%d, strerror=%s)\n", errno, strerror(errno));
2023-01-10 13:08:49 +02:00
bus_free(srv);
return EXIT_FAILURE;
}
}
2023-01-10 13:08:49 +02:00
bus_free(srv);
return EXIT_SUCCESS;
}