Changeset 8d74fdd in mainline
- Timestamp:
- 2019-08-17T13:57:05Z (5 years ago)
- Children:
- f92b315
- Parents:
- be07995
- git-author:
- Michal Koutný <xm.koutny+hos@…> (2016-01-27 00:01:13)
- git-committer:
- Matthieu Riolo <matthieu.riolo@…> (2019-08-17 13:57:05)
- Location:
- uspace
- Files:
-
- 3 added
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/sysctl/main.c
rbe07995 r8d74fdd 39 39 #include <str_error.h> 40 40 #include <sysman/ctl.h> 41 #include <unistd.h> 41 42 42 43 #define NAME "sysctl" … … 141 142 } 142 143 144 static int shutdown(int argc, char *argv[]) 145 { 146 const int delay = 3; 147 printf("Will shutdown in %i seconds...\n", delay); 148 sleep(delay); 149 printf("Shutdown now.\n"); 150 151 int rc = sysman_shutdown(); 152 if (rc != EOK) { 153 printf("Shutdown request failed: %s.\n", str_error(rc)); 154 } 155 return rc; 156 } 157 143 158 command_t commands[] = { 144 159 { "list-units", 0, &list_units }, 145 160 { "start", 1, &start }, 146 161 { "stop", 1, &stop }, 162 { "shutdown", 0, &shutdown }, 147 163 { 0 } 148 164 }; -
uspace/lib/c/include/ipc/sysman.h
rbe07995 r8d74fdd 50 50 SYSMAN_CTL_GET_UNITS, 51 51 SYSMAN_CTL_UNIT_GET_NAME, 52 SYSMAN_CTL_UNIT_GET_STATE 52 SYSMAN_CTL_UNIT_GET_STATE, 53 SYSMAN_CTL_SHUTDOWN 53 54 } sysman_ipc_method_t; 54 55 -
uspace/lib/sysman/include/sysman/ctl.h
rbe07995 r8d74fdd 43 43 int sysman_unit_get_name(unit_handle_t, char *, size_t); 44 44 int sysman_unit_get_state(unit_handle_t, unit_state_t *); 45 46 int sysman_shutdown(void); 45 47 #endif -
uspace/lib/sysman/src/ctl.c
rbe07995 r8d74fdd 192 192 return rc; 193 193 } 194 195 int sysman_shutdown(void) 196 { 197 async_exch_t *exch = sysman_exchange_begin(SYSMAN_PORT_CTL); 198 int rc = async_req_0_0(exch, SYSMAN_CTL_SHUTDOWN); 199 sysman_exchange_end(exch); 200 201 return rc; 202 } -
uspace/srv/sysman/Makefile
rbe07995 r8d74fdd 46 46 log.c \ 47 47 repo.c \ 48 shutdown.c \ 48 49 sm_task.c \ 49 50 sysman.c \ -
uspace/srv/sysman/connection_ctl.c
rbe07995 r8d74fdd 36 36 #include "connection_ctl.h" 37 37 #include "job.h" 38 #include "job_closure.h" 38 39 #include "log.h" 40 #include "shutdown.h" 39 41 #include "sysman.h" 40 42 … … 114 116 115 117 if (!(flags & IPC_FLAG_BLOCKING)) { 116 retval = sysman_run_job(unit, STATE_STARTED, NULL, NULL);118 retval = sysman_run_job(unit, STATE_STARTED, 0, NULL, NULL); 117 119 goto answer; 118 120 } … … 123 125 goto answer; 124 126 } 125 retval = sysman_run_job(unit, STATE_STARTED, &answer_callback,127 retval = sysman_run_job(unit, STATE_STARTED, 0, &answer_callback, 126 128 iid_ptr); 127 129 if (retval != EOK) { … … 154 156 155 157 if (!(flags & IPC_FLAG_BLOCKING)) { 156 retval = sysman_run_job(unit, state, NULL, NULL);158 retval = sysman_run_job(unit, state, 0, NULL, NULL); 157 159 goto answer; 158 160 } … … 163 165 goto answer; 164 166 } 165 retval = sysman_run_job(unit, state, &answer_callback,167 retval = sysman_run_job(unit, state, 0, &answer_callback, 166 168 iid_ptr); 167 169 if (retval != EOK) { … … 278 280 } 279 281 282 static void sysman_shutdown(ipc_callid_t iid, ipc_call_t *icall) 283 { 284 int retval; 285 unit_t *u = repo_find_unit_by_name(TARGET_SHUTDOWN); 286 if (u == NULL) { 287 retval = ENOENT; 288 goto finish; 289 } 290 291 retval = sysman_run_job(u, STATE_STARTED, CLOSURE_ISOLATE, 292 shutdown_cb, NULL); 293 294 finish: 295 async_answer_0(iid, retval); 296 } 297 280 298 void sysman_connection_ctl(ipc_callid_t iid, ipc_call_t *icall) 281 299 { … … 315 333 sysman_unit_get_state(callid, &call); 316 334 break; 335 case SYSMAN_CTL_SHUTDOWN: 336 sysman_shutdown(callid, &call); 337 break; 317 338 default: 318 339 async_answer_0(callid, ENOENT); -
uspace/srv/sysman/job_closure.c
rbe07995 r8d74fdd 295 295 /** Creates job closure for given basic job 296 296 * 297 * @note It is caller's responsibility to clean job_closure (even ton error).297 * @note It is caller's responsibility to clean job_closure (even on error). 298 298 * 299 299 * @return EOK on success otherwise propagated error -
uspace/srv/sysman/main.c
rbe07995 r8d74fdd 38 38 #include <taskman.h> 39 39 40 #include "repo.h"41 40 #include "connection_broker.h" 42 41 #include "connection_ctl.h" … … 44 43 #include "job_queue.h" 45 44 #include "log.h" 45 #include "repo.h" 46 #include "sm_task.h" 46 47 #include "sysman.h" 47 #include "sm_task.h"48 48 #include "unit.h" 49 49 50 50 #define NAME "sysman" 51 52 #define INITRD_DEVICE "bd/initrd"53 #define INITRD_MOUNT_POINT "/"54 #define INITRD_CFG_PATH "/cfg/sysman"55 56 #define TARGET_INIT "initrd.tgt"57 #define TARGET_ROOTFS "rootfs.tgt"58 #define TARGET_DEFAULT "default.tgt"59 60 #define UNIT_MNT_INITRD "initrd.mnt"61 #define UNIT_CFG_INITRD "init.cfg"62 63 51 64 52 static const char *target_sequence[] = { … … 195 183 } 196 184 197 int rc = sysman_run_job(tgt, STATE_STARTED, &sequence_job_handler,185 int rc = sysman_run_job(tgt, STATE_STARTED, 0, &sequence_job_handler, 198 186 target_name_ptr); 199 187 -
uspace/srv/sysman/sm_task.c
rbe07995 r8d74fdd 106 106 * name */ 107 107 108 /* 109 * Temporary workaround to avoid killing ourselves during shutdown, 110 * eventually should be captured by dependencies. 111 */ 112 if (tid == task_get_id() || tid == 2 /*taskman*/) { 113 CAST_SVC(u_svc)->critical = true; 114 } 115 108 116 repo_begin_update(); 109 117 in_repo_update = true; -
uspace/srv/sysman/sysman.c
rbe07995 r8d74fdd 65 65 typedef struct { 66 66 job_t *job; 67 int flags; 67 68 callback_handler_t callback; 68 69 void *callback_arg; … … 205 206 * If unit already has the same job assigned callback is moved to it. 206 207 * 207 * @param[in] callback (optional) callback must explicitly delete reference 208 * to job, void callback(void *job, void *callback_arg) 209 * 210 * return EBUSY unit already has a job assigned of different type 211 */ 212 int sysman_run_job(unit_t *unit, unit_state_t target_state, 208 * @param[in] flags additional flags for job 209 * @param[in] callback (optional) callback must explicitly delete reference 210 * to job, void callback(void *job, void *callback_arg) 211 * @param[in] callback_arg 212 * 213 * @return EOK on successfully queued job 214 */ 215 int sysman_run_job(unit_t *unit, unit_state_t target_state, int flags, 213 216 callback_handler_t callback, void *callback_arg) 214 217 { … … 226 229 /* Pass reference to job_args */ 227 230 job_args->job = job; 231 job_args->flags = flags; 228 232 job_args->callback = callback; 229 233 job_args->callback_arg = callback_arg; … … 364 368 job_args_t *job_args = data; 365 369 job_t *job = job_args->job; 370 int flags = job_args->flags; 366 371 dyn_array_t job_closure; 367 372 dyn_array_initialize(&job_closure, job_t *); … … 373 378 free(job_args); 374 379 375 int rc = job_create_closure(job, &job_closure, 0);380 int rc = job_create_closure(job, &job_closure, flags); 376 381 if (rc != EOK) { 377 382 sysman_log(LVL_ERROR, "Cannot create closure for job %p (%i)", -
uspace/srv/sysman/sysman.h
rbe07995 r8d74fdd 30 30 #define SYSMAN_SYSMAN_H 31 31 32 #define INITRD_DEVICE "bd/initrd" 33 #define INITRD_MOUNT_POINT "/" 34 #define INITRD_CFG_PATH "/cfg/sysman" 35 36 // TODO configurable 37 #define TARGET_INIT "initrd.tgt" 38 #define TARGET_ROOTFS "rootfs.tgt" 39 #define TARGET_DEFAULT "default.tgt" 40 #define TARGET_SHUTDOWN "shutdown.tgt" 41 42 #define UNIT_MNT_INITRD "initrd.mnt" 43 #define UNIT_CFG_INITRD "init.cfg" 44 32 45 #include "job.h" 33 46 #include "unit.h" … … 38 51 extern void sysman_events_init(void); 39 52 extern int sysman_events_loop(void *); 40 extern int sysman_run_job(unit_t *, unit_state_t, callback_handler_t, void *);53 extern int sysman_run_job(unit_t *, unit_state_t, int, callback_handler_t, void *); 41 54 42 55 -
uspace/srv/sysman/test/job_queue.c
rbe07995 r8d74fdd 83 83 job_t *job = NULL; 84 84 85 int rc = sysman_run_job(u, STATE_STARTED, &job_finished_cb,85 int rc = sysman_run_job(u, STATE_STARTED, 0, &job_finished_cb, 86 86 &job); 87 87 PCUT_ASSERT_INT_EQUALS(EOK, rc); … … 102 102 job_t *job = NULL; 103 103 104 int rc = sysman_run_job(u, STATE_STARTED, &job_finished_cb, &job);104 int rc = sysman_run_job(u, STATE_STARTED, 0, &job_finished_cb, &job); 105 105 PCUT_ASSERT_INT_EQUALS(EOK, rc); 106 106 … … 142 142 /* Run test */ 143 143 job_t *job = NULL; 144 int rc = sysman_run_job(s1, STATE_STARTED, &job_finished_cb, &job);144 int rc = sysman_run_job(s1, STATE_STARTED, 0, &job_finished_cb, &job); 145 145 PCUT_ASSERT_INT_EQUALS(EOK, rc); 146 146 … … 163 163 /* Create and start first job */ 164 164 job_t *j0 = NULL; 165 int rc = sysman_run_job(s0, STATE_STARTED, &job_finished_cb, &j0);165 int rc = sysman_run_job(s0, STATE_STARTED, 0, &job_finished_cb, &j0); 166 166 PCUT_ASSERT_INT_EQUALS(EOK, rc); 167 167 … … 176 176 */ 177 177 job_t *j1 = NULL; 178 rc = sysman_run_job(s0, STATE_STARTED, &job_finished_cb, &j1);178 rc = sysman_run_job(s0, STATE_STARTED, 0, &job_finished_cb, &j1); 179 179 PCUT_ASSERT_INT_EQUALS(EOK, rc); 180 180 -
uspace/srv/sysman/units/unit_svc.c
rbe07995 r8d74fdd 120 120 assert(unit->state == STATE_STARTED); 121 121 122 /* 123 * Ugly trick -- critical service is running despite being stopped 124 * circumvent killing ourselves during shutdown (TODO dependencies). 125 */ 126 if (u_svc->critical) { 127 unit->state = STATE_STOPPED; 128 return EOK; 129 } 130 122 131 int rc = task_kill(u_svc->main_task_id); 123 132 -
uspace/srv/sysman/units/unit_svc.h
rbe07995 r8d74fdd 43 43 44 44 bool anonymous; 45 46 /** Service can't be stopped, temporary workaround for shutdown */ 47 bool critical; 45 48 } unit_svc_t; 46 49
Note:
See TracChangeset
for help on using the changeset viewer.