summaryrefslogtreecommitdiff
path: root/src/monitor.c
blob: 1df3f2eea3c719e27d1a7be17e466ff5459dc9e9 (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
67
68
69
70
71
72
73
74
75
/**
 * @file
 * @section AUTHORS
 *
 *  Authors:
 *       Eamon Walsh <ewalsh@tycho.nsa.gov>
 *
 * @section LICENSE
 *
 * This file is in the public domain.
 *
 * @section DESCRIPTION
 *
 * This is the main routine for the linpicker-monitor program.
 * Nothing much here except initialization, select loop, and teardown.
 */

#include <sys/types.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <signal.h>
#include <errno.h>

#include "common.h"
#include "fd.h"
#include "xen_backend.h"
#include "sys-queue.h"

extern int xenfb_monitor_init(void);

static int timetodie;

/*
 * Is called in case of process signals.
 */
static void
server_sighandler(int sig)
{
    timetodie = 1;
}

/* 
 * Main
 */
int main (int argc, char *argv[])
{
    struct sigaction sa = { .sa_handler = server_sighandler };

    /* Set up sighandlers */
    sigaction(SIGINT, &sa, NULL);
    sigaction(SIGTERM, &sa, NULL);

    /* Open logfile */
    if (fd_open_logfile(MONITOR_LOG) < 0)
	return 1;

    /* Initialize subsystems */
    if (xen_be_init() < 0)
	return 1;
    if (xenfb_monitor_init() < 0)
	return 2;

    /* Create a daemon */
    daemon(0, 1);

    /* Enter select loop */
    while (!timetodie && fd_run_select() == 0);

    /* Shut down */
    fd_shutdown();
    return 0;
}