chiark / gitweb /
use linux/sched.h instead of sched.h for older glibc
[elogind.git] / main.c
1 /*-*- Mode: C; c-basic-offset: 8 -*-*/
2
3 #include <dbus/dbus.h>
4
5 #include <stdio.h>
6 #include <errno.h>
7 #include <string.h>
8 #include <unistd.h>
9
10 #include "manager.h"
11 #include "log.h"
12
13 int main(int argc, char *argv[]) {
14         Manager *m = NULL;
15         Unit *target = NULL;
16         Job *job = NULL;
17         int r, retval = 1;
18
19         assert_se(set_unit_path("test1") >= 0);
20
21         if (!(m = manager_new())) {
22                 log_error("Failed to allocate manager object: %s", strerror(ENOMEM));
23                 goto finish;
24         }
25
26         if ((r = manager_coldplug(m)) < 0) {
27                 log_error("Failed to retrieve coldplug information: %s", strerror(-r));
28                 goto finish;
29         }
30
31         if ((r = manager_load_unit(m, SPECIAL_DEFAULT_TARGET, &target)) < 0) {
32                 log_error("Failed to load default target: %s", strerror(-r));
33                 goto finish;
34         }
35
36         printf("→ By units:\n");
37         manager_dump_units(m, stdout, "\t");
38
39         if ((r = manager_add_job(m, JOB_START, target, JOB_REPLACE, false, &job)) < 0) {
40                 log_error("Failed to start default target: %s", strerror(-r));
41                 goto finish;
42         }
43
44         printf("→ By jobs:\n");
45         manager_dump_jobs(m, stdout, "\t");
46
47         if ((r = manager_loop(m)) < 0) {
48                 log_error("Failed to run mainloop: %s", strerror(-r));
49                 goto finish;
50         }
51
52         retval = 0;
53
54 finish:
55         if (m)
56                 manager_free(m);
57
58         log_debug("Exit.");
59
60         dbus_shutdown();
61
62         return retval;
63 }