source: mainline/uspace/lib/sysman/src/ctl.c@ 241f1985

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

Correcting failure from previous merge

The commits from Michal Koutný from the branch system-daemon
where built on a old version of Helenos. Because of this
many types and API functions have changed. This commit
upgrades the merge code

  • Property mode set to 100644
File size: 5.3 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 <async.h>
30#include <errno.h>
31#include <stdlib.h>
32#include <str.h>
33#include <sysman/ctl.h>
34#include <sysman/sysman.h>
35
36errno_t sysman_unit_handle(const char *unit_name, unit_handle_t *handle_ptr)
37{
38 async_exch_t *exch = sysman_exchange_begin(SYSMAN_PORT_CTL);
39
40 ipc_call_t call;
41 aid_t req = async_send_0(exch, SYSMAN_CTL_UNIT_HANDLE, &call);
42 errno_t rc = async_data_write_start(exch, unit_name, str_size(unit_name));
43 sysman_exchange_end(exch);
44
45 if (rc != EOK) {
46 async_forget(req);
47 return rc;
48 }
49
50 async_wait_for(req, &rc);
51 if (rc == EOK) {
52 *handle_ptr = ipc_get_arg1(&call);
53 }
54 return rc;
55}
56
57/*
58 * TODO
59 * Non-blocking favor of this API is effectively incomplete as it doesn't
60 * provide means how to obtain result of the start operation.
61 * Probably devise individual API for brokers that could exploit the fact that
62 * broker knows when appropriate exposee is created and the request succeeded.
63 * Still though, it's necessary to centralize timeout into sysman.
64 * TODO convert to name->handle API
65 */
66errno_t sysman_unit_start_by_name(const char *unit_name, int flags)
67{
68 async_exch_t *exch = sysman_exchange_begin(SYSMAN_PORT_CTL);
69
70 aid_t req = async_send_1(exch, SYSMAN_CTL_UNIT_START_BY_NAME, flags, NULL);
71 errno_t rc = async_data_write_start(exch, unit_name, str_size(unit_name));
72 sysman_exchange_end(exch);
73
74 if (rc != EOK) {
75 async_forget(req);
76 return rc;
77 }
78
79 async_wait_for(req, &rc);
80 return rc;
81}
82
83errno_t sysman_unit_start(unit_handle_t handle, int flags)
84{
85 async_exch_t *exch = sysman_exchange_begin(SYSMAN_PORT_CTL);
86
87 errno_t rc = async_req_2_0(exch, SYSMAN_CTL_UNIT_START, handle, flags);
88 sysman_exchange_end(exch);
89
90 return rc;
91}
92
93errno_t sysman_unit_stop(unit_handle_t handle, int flags)
94{
95 async_exch_t *exch = sysman_exchange_begin(SYSMAN_PORT_CTL);
96
97 errno_t rc = async_req_2_0(exch, SYSMAN_CTL_UNIT_STOP, handle, flags);
98 sysman_exchange_end(exch);
99
100 return rc;
101}
102
103static errno_t sysman_get_units_once(sysarg_t *buf, size_t buf_size,
104 size_t *act_size)
105{
106 async_exch_t *exch = sysman_exchange_begin(SYSMAN_PORT_CTL);
107
108 ipc_call_t answer;
109 aid_t req = async_send_0(exch, SYSMAN_CTL_GET_UNITS, &answer);
110 errno_t rc = async_data_read_start(exch, buf, buf_size);
111
112 sysman_exchange_end(exch);
113
114 if (rc != EOK) {
115 async_forget(req);
116 return rc;
117 }
118
119 errno_t retval;
120 async_wait_for(req, &retval);
121
122 if (retval != EOK) {
123 return retval;
124 }
125
126 *act_size = ipc_get_arg1(&answer);
127 return EOK;
128}
129
130errno_t sysman_get_units(unit_handle_t **units_ptr, size_t *cnt_ptr)
131{
132 *units_ptr = NULL;
133 *cnt_ptr = 0;
134
135 unit_handle_t *units = NULL;
136 size_t alloc_size = 0;
137 size_t act_size = 0;
138
139 while (true) {
140 errno_t rc = sysman_get_units_once(units, alloc_size, &act_size);
141 if (rc != EOK) {
142 return rc;
143 }
144
145 if (act_size <= alloc_size) {
146 break;
147 }
148
149 alloc_size = act_size;
150 units = realloc(units, alloc_size);
151 if (units == NULL) {
152 return ENOMEM;
153 }
154 }
155
156 *units_ptr = units;
157 *cnt_ptr = act_size / sizeof(unit_handle_t);
158 return EOK;
159}
160
161errno_t sysman_unit_get_name(unit_handle_t handle, char *buf, size_t buf_size)
162{
163 async_exch_t *exch = sysman_exchange_begin(SYSMAN_PORT_CTL);
164
165 ipc_call_t answer;
166 aid_t req = async_send_1(exch, SYSMAN_CTL_UNIT_GET_NAME, handle, &answer);
167 errno_t rc = async_data_read_start(exch, buf, buf_size);
168
169 sysman_exchange_end(exch);
170
171 if (rc != EOK) {
172 async_forget(req);
173 return rc;
174 }
175
176 errno_t retval;
177 async_wait_for(req, &retval);
178
179 if (retval != EOK) {
180 return retval;
181 }
182
183 return EOK;
184}
185
186errno_t sysman_unit_get_state(unit_handle_t handle, unit_state_t *state)
187{
188 async_exch_t *exch = sysman_exchange_begin(SYSMAN_PORT_CTL);
189 errno_t rc = async_req_1_1(exch, SYSMAN_CTL_UNIT_GET_STATE, handle, (sysarg_t *)state);
190 sysman_exchange_end(exch);
191
192 return rc;
193}
194
195errno_t sysman_shutdown(void)
196{
197 async_exch_t *exch = sysman_exchange_begin(SYSMAN_PORT_CTL);
198 errno_t rc = async_req_0_0(exch, SYSMAN_CTL_SHUTDOWN);
199 sysman_exchange_end(exch);
200
201 return rc;
202}
Note: See TracBrowser for help on using the repository browser.