blob: 7cc7c712bf5d9768bdd50fabae4767620c1318f0 (
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
61
62
63
64
65
66
|
#include <errno.h>
#include <poll.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/stat.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 = {0};
if (server_init(&server) == -1) {
log_errorf("server_create failed: %s", strerror(errno));
return 1;
}
char *path = getenv("SEATD_SOCK");
if (path == NULL) {
path = "/run/seatd.sock";
struct stat st;
if (stat(path, &st) == 0) {
log_info("removing leftover seatd socket");
unlink(path);
}
}
if (server_listen(&server, path) == -1) {
log_errorf("server_listen failed: %s", strerror(errno));
server_finish(&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_finish(&server);
unlink(path);
return 0;
}
|