2022-12-21 00:38:10 +02:00
|
|
|
#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"
|
2022-12-21 00:38:10 +02:00
|
|
|
#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-10 13:08:49 +02:00
|
|
|
bus_t *srv = bus_create(socket_path);
|
2022-12-21 00:38:10 +02:00
|
|
|
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);
|
2022-12-21 00:38:10 +02:00
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-10 13:08:49 +02:00
|
|
|
bus_free(srv);
|
2022-12-21 00:38:10 +02:00
|
|
|
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|