source: mainline/uspace/srv/sysman/main.c@ 694253c

Last change on this file since 694253c was 694253c, checked in by Matthieu Riolo <matthieu.riolo@…>, 6 years ago

Skeleton for sysman (unit) jobs control

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