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