source: mainline/uspace/srv/sysman/dep.c@ af92309

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

sysman: Naive autostart instrumentation of locsrv

  • Add IPC_FLAG_AUTOSTART flag.
  • libsysman: sysman's broker and control API.
  • Simple implementation of service unit, exposee verification is missing.
  • Simple mapping of exposee to unit name in locsrv.
  • Temporary debug prints in locsrv.

Conflicts:

boot/Makefile.common
boot/arch/amd64/Makefile.inc
uspace/lib/c/include/ipc/services.h
uspace/srv/locsrv/locsrv.c

  • Property mode set to 100644
File size: 3.7 KB
Line 
1/*
2 * Copyright (c) 2015 Michal Koutny
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#include <assert.h>
30#include <errno.h>
31#include <stdlib.h>
32#include <str.h>
33
34#include "dep.h"
35
36static void dep_dependency_init(unit_dependency_t *dep)
37{
38 memset(dep, 0, sizeof(*dep));
39 link_initialize(&dep->dependants);
40 link_initialize(&dep->dependencies);
41
42 dep->state = DEP_EMBRYO;
43}
44
45unit_dependency_t *dep_dependency_create(void)
46{
47 unit_dependency_t *dep = malloc(sizeof(unit_dependency_t));
48 if (dep) {
49 dep_dependency_init(dep);
50 }
51 return dep;
52}
53
54void dep_dependency_destroy(unit_dependency_t **dep_ptr)
55{
56 unit_dependency_t *dep = *dep_ptr;
57 if (dep == NULL) {
58 return;
59 }
60
61 list_remove(&dep->dependencies);
62 list_remove(&dep->dependants);
63
64 free(dep->dependency_name);
65 free(dep);
66
67 *dep_ptr = NULL;
68}
69
70int dep_sprout_dependency(unit_t *dependant, const char *dependency_name)
71{
72 unit_dependency_t *dep = dep_dependency_create();
73 int rc;
74
75 if (dep == NULL) {
76 rc = ENOMEM;
77 goto finish;
78 }
79
80 dep->dependency_name = str_dup(dependency_name);
81 if (dep->dependency_name == NULL) {
82 rc = ENOMEM;
83 goto finish;
84 }
85
86 list_append(&dep->dependencies, &dependant->dependencies);
87 dep->dependant = dependant;
88
89 rc = EOK;
90
91finish:
92 if (rc != EOK) {
93 dep_dependency_destroy(&dep);
94 }
95 return rc;
96}
97
98void dep_resolve_dependency(unit_dependency_t *dep, unit_t *unit)
99{
100 assert(dep->dependency == NULL);
101 assert(dep->dependency_name != NULL);
102
103 // TODO add to other side dependants list
104 dep->dependency = unit;
105 free(dep->dependency_name);
106 dep->dependency_name = NULL;
107}
108
109
110/**
111 * @return EOK on success
112 * @return ENOMEM
113 */
114int dep_add_dependency(unit_t *dependant, unit_t *dependency)
115{
116 unit_dependency_t *dep = dep_dependency_create();
117 if (dep == NULL) {
118 return ENOMEM;
119 }
120
121 // TODO check existence of the dep
122 // TODO locking
123 // TODO check types and states of connected units
124 list_append(&dep->dependants, &dependency->dependants);
125 list_append(&dep->dependencies, &dependant->dependencies);
126
127 dep->dependant = dependant;
128 dep->dependency = dependency;
129 return EOK;
130}
131
132/** Remove dependency from dependency graph
133 *
134 * Given dependency is removed from graph and unallocated.
135 */
136void dep_remove_dependency(unit_dependency_t **dep_ptr)
137{
138 // TODO here should be some checks, othewise replace this wrapper with
139 // direct destroy
140 dep_dependency_destroy(dep_ptr);
141}
Note: See TracBrowser for help on using the repository browser.