1 | #include <async.h>
|
---|
2 | #include <errno.h>
|
---|
3 | #include <fibril.h>
|
---|
4 | #include <stddef.h>
|
---|
5 | #include <stdio.h>
|
---|
6 |
|
---|
7 | #include "configuration.h"
|
---|
8 | #include "dep.h"
|
---|
9 | #include "sysman.h"
|
---|
10 | #include "unit.h"
|
---|
11 |
|
---|
12 | #define NAME "sysman"
|
---|
13 |
|
---|
14 | static void sysman_connection(ipc_callid_t callid, ipc_call_t *call, void *arg)
|
---|
15 | {
|
---|
16 | /* TODO handle client connections */
|
---|
17 | }
|
---|
18 |
|
---|
19 | static int sysman_entry_point(void *arg) {
|
---|
20 | /*
|
---|
21 | * Build hard coded configuration.
|
---|
22 | */
|
---|
23 | int result = EOK;
|
---|
24 | unit_t *mnt_initrd = NULL;
|
---|
25 | unit_t *cfg_init = NULL;
|
---|
26 | unit_t *tgt_default = NULL;
|
---|
27 |
|
---|
28 | mnt_initrd = unit_create(UNIT_MOUNT);
|
---|
29 | if (mnt_initrd == NULL) {
|
---|
30 | result = ENOMEM;
|
---|
31 | goto fail;
|
---|
32 | }
|
---|
33 | // TODO Use RDFMT
|
---|
34 | mnt_initrd->data.mnt.type = "ext4fs";
|
---|
35 | mnt_initrd->data.mnt.mountpoint = "/";
|
---|
36 | mnt_initrd->data.mnt.device = "bd/initrd";
|
---|
37 |
|
---|
38 | cfg_init = unit_create(UNIT_CONFIGURATION);
|
---|
39 | if (cfg_init == NULL) {
|
---|
40 | result = ENOMEM;
|
---|
41 | goto fail;
|
---|
42 | }
|
---|
43 | cfg_init->data.cfg.path = "/cfg/";
|
---|
44 |
|
---|
45 | tgt_default = unit_create(UNIT_TARGET);
|
---|
46 | if (tgt_default == NULL) {
|
---|
47 | result = ENOMEM;
|
---|
48 | goto fail;
|
---|
49 | }
|
---|
50 |
|
---|
51 |
|
---|
52 | /*
|
---|
53 | * Add units to configuration and start the default target.
|
---|
54 | */
|
---|
55 | configuration_add_unit(mnt_initrd);
|
---|
56 | configuration_add_unit(cfg_init);
|
---|
57 | configuration_add_unit(tgt_default);
|
---|
58 |
|
---|
59 | result = dep_add_dependency(tgt_default, cfg_init);
|
---|
60 | if (result != EOK) {
|
---|
61 | goto fail;
|
---|
62 | }
|
---|
63 |
|
---|
64 | result = dep_add_dependency(cfg_init, mnt_initrd);
|
---|
65 | if (result != EOK) {
|
---|
66 | goto fail;
|
---|
67 | }
|
---|
68 |
|
---|
69 | configuration_commit();
|
---|
70 |
|
---|
71 | result = sysman_unit_start(tgt_default);
|
---|
72 |
|
---|
73 | return result;
|
---|
74 |
|
---|
75 | fail:
|
---|
76 | unit_destroy(&tgt_default);
|
---|
77 | unit_destroy(&cfg_init);
|
---|
78 | unit_destroy(&mnt_initrd);
|
---|
79 | return result;
|
---|
80 | }
|
---|
81 |
|
---|
82 | int main(int argc, char *argv[])
|
---|
83 | {
|
---|
84 | printf(NAME ": HelenOS system daemon\n");
|
---|
85 |
|
---|
86 | configuration_init();
|
---|
87 |
|
---|
88 | /*
|
---|
89 | * Create and start initial configuration asynchronously
|
---|
90 | * so that we can start server's fibril that may be used
|
---|
91 | * when executing the start.
|
---|
92 | */
|
---|
93 | fid_t entry_fibril = fibril_create(sysman_entry_point, NULL);
|
---|
94 | fibril_add_ready(entry_fibril);
|
---|
95 |
|
---|
96 | /* Prepare and start sysman server */
|
---|
97 | async_set_client_connection(sysman_connection);
|
---|
98 |
|
---|
99 | printf(NAME ": Accepting connections\n");
|
---|
100 | async_manager();
|
---|
101 |
|
---|
102 | return 0;
|
---|
103 | }
|
---|