aboutsummaryrefslogtreecommitdiff
path: root/seatd/seatd.c
blob: c1cdccf4e2bc39e9c69d6d6a9022fe6723edb712 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <errno.h>
#include <poll.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/un.h>

#include "client.h"
#include "log.h"
#include "poller.h"
#include "server.h"

int main(int argc, char *argv[]) {
	(void)argc;
	(void)argv;

	char *loglevel = getenv("SEATD_LOGLEVEL");
	enum libseat_log_level level = LIBSEAT_ERROR;
	if (loglevel != NULL) {
		if (strcmp(loglevel, "silent") == 0) {
			level = LIBSEAT_SILENT;
		} else if (strcmp(loglevel, "info") == 0) {
			level = LIBSEAT_INFO;
		} else if (strcmp(loglevel, "debug") == 0) {
			level = LIBSEAT_DEBUG;
		}
	}
	libseat_log_init(level);

	struct server *server = server_create();
	if (server == NULL) {
		log_errorf("server_create failed: %s", strerror(errno));
		return 1;
	}
	char *path = getenv("SEATD_SOCK");
	if (path == NULL) {
		path = "/run/seatd.sock";
	}

	if (server_listen(server, path) == -1) {
		log_errorf("server_listen failed: %s", strerror(errno));
		server_destroy(server);
		return 1;
	}

	log_info("seatd started");

	while (server->running) {
		if (poller_poll(server->poller) == -1) {
			log_errorf("poller failed: %s", strerror(errno));
			return 1;
		}
	}

	server_destroy(server);
	unlink(path);
	return 0;
}