Changeset dda2602 in mainline
- Timestamp:
- 2019-08-03T09:41:07Z (5 years ago)
- Children:
- dd5c623
- Parents:
- c0e4fc50
- git-author:
- Michal Koutný <xm.koutny+hos@…> (2015-05-08 11:10:06)
- git-committer:
- Matthieu Riolo <matthieu.riolo@…> (2019-08-03 09:41:07)
- Location:
- uspace
- Files:
-
- 9 added
- 17 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/cfg/sysman/logger.svc
rc0e4fc50 rdda2602 1 1 [Service] 2 ExecStart = /srv/logger 2 ExecStart = /srv/logger warn 3 3 -
uspace/cfg/sysman/rootfs.tgt
rc0e4fc50 rdda2602 1 1 [Unit] 2 ; should there be this dependency? 3 ; then the target could be used instead of mount in other dependencies 2 4 After = rootfs.mnt 5 After = rootfs.cfg -
uspace/srv/hid/compositor/compositor.c
rc0e4fc50 rdda2602 2183 2183 async_sess_t *sess; 2184 2184 service_id_t dsid; 2185 2186 errno_t rc = loc_service_get_id(svc, &dsid, 0); 2185 unsigned int flags = IPC_FLAG_AUTOSTART; 2186 2187 errno_t rc = loc_service_get_id(svc, &dsid, flags); 2187 2188 if (rc != EOK) { 2188 2189 printf("%s: Input service %s not found\n", NAME, svc); … … 2190 2191 } 2191 2192 2192 sess = loc_service_connect(dsid, INTERFACE_INPUT, 0);2193 sess = loc_service_connect(dsid, INTERFACE_INPUT, flags); 2193 2194 if (sess == NULL) { 2194 2195 printf("%s: Unable to connect to input service %s\n", NAME, -
uspace/srv/locsrv/locsrv.c
rc0e4fc50 rdda2602 359 359 } 360 360 361 printf("%s(%s) before\n", __func__, unit_name);361 //printf("%s(%s) before\n", __func__, unit_name);//DEBUG 362 362 int rc = sysman_unit_start(unit_name, IPC_FLAG_BLOCKING); 363 printf("%s(%s) after %i\n", __func__, unit_name, rc);363 //printf("%s(%s) after %i\n", __func__, unit_name, rc);//DEBUG 364 364 free(unit_name); 365 365 free(service_name); … … 566 566 list_append(&service->server_services, &service->server->services); 567 567 568 printf("%s: broadcast new service '%s/%s'\n", NAME, namespace->name,569 service->name);570 571 568 fibril_mutex_unlock(&service->server->services_mutex); 572 569 fibril_condvar_broadcast(&services_list_cv); … … 801 798 const loc_service_t *svc; 802 799 int flags = ipc_get_arg1(*icall); 800 bool start_requested = false; 803 801 804 802 recheck: … … 813 811 */ 814 812 if (svc == NULL) { 815 printf("%s: service '%s/%s' not found\n", NAME, ns_name, name);813 //printf("%s: service '%s/%s' not found\n", NAME, ns_name, name);//DEBUG 816 814 if (flags & (IPC_FLAG_AUTOSTART | IPC_FLAG_BLOCKING)) { 817 815 /* TODO: … … 821 819 * for ID might be someone else than those connecting) 822 820 */ 823 if ( flags & IPC_FLAG_AUTOSTART) {821 if (!start_requested && (flags & IPC_FLAG_AUTOSTART)) { 824 822 rc = loc_service_request_start(ns_name, name); 825 823 if (rc != EOK) { 826 824 goto finish; 827 825 } 826 start_requested = true; 828 827 } 829 828 … … 834 833 rc = ENOENT; 835 834 } else { 836 printf("%s: service '%s/%s' FOUND\n", NAME, ns_name, name);835 //printf("%s: service '%s/%s' FOUND\n", NAME, ns_name, name);//DEBUG 837 836 rc = EOK; 838 837 } -
uspace/srv/sysman/configuration.c
rc0e4fc50 rdda2602 38 38 #include "log.h" 39 39 40 static hash_table_t units; 40 LIST_INITIALIZE(units); 41 42 static hash_table_t units_by_name; 41 43 42 44 /* Hash table functions */ 43 static size_t units_ ht_hash(const ht_link_t *item)45 static size_t units_by_name_ht_hash(const ht_link_t *item) 44 46 { 45 47 unit_t *unit = 46 hash_table_get_inst(item, unit_t, units );48 hash_table_get_inst(item, unit_t, units_by_name); 47 49 return hash_string(unit->name); 48 50 } 49 51 50 static size_t units_ ht_key_hash(void *key)52 static size_t units_by_name_ht_key_hash(void *key) 51 53 { 52 54 return hash_string((const char *)key); 53 55 } 54 56 55 static bool units_ ht_equal(const ht_link_t *item1, const ht_link_t *item2)57 static bool units_by_name_ht_equal(const ht_link_t *item1, const ht_link_t *item2) 56 58 { 57 59 return str_cmp( 58 hash_table_get_inst(item1, unit_t, units )->name,59 hash_table_get_inst(item2, unit_t, units )->name) == 0;60 } 61 62 static bool units_ ht_key_equal(void *key, const ht_link_t *item)60 hash_table_get_inst(item1, unit_t, units_by_name)->name, 61 hash_table_get_inst(item2, unit_t, units_by_name)->name) == 0; 62 } 63 64 static bool units_by_name_ht_key_equal(void *key, const ht_link_t *item) 63 65 { 64 66 return str_cmp((const char *)key, 65 hash_table_get_inst(item, unit_t, units )->name) == 0;66 } 67 68 69 static hash_table_ops_t units_ ht_ops = {70 .hash = &units_ ht_hash,71 .key_hash = &units_ ht_key_hash,72 .equal = &units_ ht_equal,73 .key_equal = &units_ ht_key_equal,67 hash_table_get_inst(item, unit_t, units_by_name)->name) == 0; 68 } 69 70 71 static hash_table_ops_t units_by_name_ht_ops = { 72 .hash = &units_by_name_ht_hash, 73 .key_hash = &units_by_name_ht_key_hash, 74 .equal = &units_by_name_ht_equal, 75 .key_equal = &units_by_name_ht_key_equal, 74 76 .remove_callback = NULL // TODO realy unneeded? 75 77 }; … … 79 81 void configuration_init(void) 80 82 { 81 hash_table_create(&units , 0, 0, &units_ht_ops);83 hash_table_create(&units_by_name, 0, 0, &units_by_name_ht_ops); 82 84 } 83 85 … … 89 91 sysman_log(LVL_DEBUG2, "%s('%s')", __func__, unit_name(unit)); 90 92 91 if (hash_table_insert_unique(&units, &unit->units)) { 93 if (hash_table_insert_unique(&units_by_name, &unit->units_by_name)) { 94 list_append(&unit->units, &units); 92 95 return EOK; 93 96 } else { … … 102 105 static bool configuration_commit_unit(ht_link_t *ht_link, void *arg) 103 106 { 104 unit_t *unit = hash_table_get_inst(ht_link, unit_t, units );107 unit_t *unit = hash_table_get_inst(ht_link, unit_t, units_by_name); 105 108 // TODO state locking? 106 109 if (unit->state == STATE_EMBRYO) { … … 116 119 } 117 120 118 /** Marks newly added units as usable (via state change) */121 /** Marks newly added units_by_name as usable (via state change) */ 119 122 void configuration_commit(void) 120 123 { … … 122 125 123 126 /* 124 * Apply commit to all units , each commited unit commits its outgoing127 * Apply commit to all units_by_name, each commited unit commits its outgoing 125 128 * deps, thus eventually commiting all embryo deps as well. 126 129 */ 127 hash_table_apply(&units , &configuration_commit_unit, NULL);130 hash_table_apply(&units_by_name, &configuration_commit_unit, NULL); 128 131 } 129 132 130 133 static bool configuration_rollback_unit(ht_link_t *ht_link, void *arg) 131 134 { 132 unit_t *unit = hash_table_get_inst(ht_link, unit_t, units );135 unit_t *unit = hash_table_get_inst(ht_link, unit_t, units_by_name); 133 136 134 137 list_foreach_safe(unit->dependencies, cur_link, next_link) { … … 141 144 142 145 if (unit->state == STATE_EMBRYO) { 143 hash_table_remove_item(&units, ht_link); 146 hash_table_remove_item(&units_by_name, ht_link); 147 list_remove(&unit->units); 144 148 unit_destroy(&unit); 145 149 } … … 148 152 } 149 153 150 /** Remove all uncommited units and edges from configuratio154 /** Remove all uncommited units_by_name and edges from configuratio 151 155 * 152 156 * Memory used by removed object is released. … … 156 160 sysman_log(LVL_DEBUG2, "%s", __func__); 157 161 158 hash_table_apply(&units , &configuration_rollback_unit, NULL);162 hash_table_apply(&units_by_name, &configuration_rollback_unit, NULL); 159 163 } 160 164 … … 162 166 { 163 167 bool *has_error_ptr = arg; 164 unit_t *unit = hash_table_get_inst(ht_link, unit_t, units );168 unit_t *unit = hash_table_get_inst(ht_link, unit_t, units_by_name); 165 169 166 170 list_foreach(unit->dependencies, dependencies, unit_dependency_t, dep) { … … 187 191 } 188 192 189 /** Resolve unresolved dependencies between any pair of units 193 /** Resolve unresolved dependencies between any pair of units_by_name 190 194 * 191 195 * @return EOK on success … … 197 201 198 202 bool has_error = false; 199 hash_table_apply(&units , &configuration_resolve_unit, &has_error);203 hash_table_apply(&units_by_name, &configuration_resolve_unit, &has_error); 200 204 201 205 return has_error ? ENOENT : EOK; … … 204 208 unit_t *configuration_find_unit_by_name(const char *name) 205 209 { 206 ht_link_t *ht_link = hash_table_find(&units , (void *)name);210 ht_link_t *ht_link = hash_table_find(&units_by_name, (void *)name); 207 211 if (ht_link != NULL) { 208 return hash_table_get_inst(ht_link, unit_t, units );212 return hash_table_get_inst(ht_link, unit_t, units_by_name); 209 213 } else { 210 214 return NULL; -
uspace/srv/sysman/configuration.h
rc0e4fc50 rdda2602 30 30 #define SYSMAN_CONFIGURATION_H 31 31 32 #include <adt/list.h> 33 32 34 #include "unit.h" 35 36 extern list_t units; 33 37 34 38 extern void configuration_init(void); -
uspace/srv/sysman/connection_ctl.c
rc0e4fc50 rdda2602 78 78 unit_t *unit = configuration_find_unit_by_name(unit_name); 79 79 if (unit == NULL) { 80 sysman_log(LVL_NOTE, "Unit '%s' not found.", unit_name); 80 81 retval = ENOENT; 81 82 goto answer; -
uspace/srv/sysman/job.c
rc0e4fc50 rdda2602 27 27 */ 28 28 29 #include <adt/ fifo.h>29 #include <adt/list.h> 30 30 #include <assert.h> 31 31 #include <errno.h> 32 32 #include <stdlib.h> 33 34 #include "configuration.h" 33 35 #include "dep.h" 34 36 #include "job.h" … … 42 44 */ 43 45 44 static int job_add_blocked_job(job_t *job, job_t *blocked_job) 45 { 46 int rc = dyn_array_append(&job->blocked_jobs, job_ptr_t, blocked_job); 46 static int job_add_blocked_job(job_t *blocking_job, job_t *blocked_job) 47 { 48 int rc = dyn_array_append(&blocking_job->blocked_jobs, job_ptr_t, 49 blocked_job); 47 50 if (rc != EOK) { 48 51 return ENOMEM; … … 73 76 assert(job); 74 77 assert(u); 78 assert(u->job == NULL); 75 79 memset(job, 0, sizeof(*job)); 76 80 … … 82 86 job->unit = u; 83 87 84 dyn_array_initialize(&job->blocked_jobs, job_ptr_t, 0); 88 u->job = job; 89 job_add_ref(job); 90 91 (void)dyn_array_initialize(&job->blocked_jobs, job_ptr_t, 0); 85 92 job->blocking_jobs = 0; 86 93 job->blocking_job_failed = false; … … 225 232 int job_create_closure(job_t *main_job, dyn_array_t *job_closure) 226 233 { 227 // TODO replace hard-coded FIFO size with resizable FIFO228 FIFO_INITIALIZE_DYNAMIC(jobs_fifo, job_ptr_t, 10);229 void *fifo_data = fifo_create(jobs_fifo);230 234 int rc; 231 if (fifo_data == NULL) { 232 rc = ENOMEM; 233 goto finish; 234 } 235 236 /* 237 * Traverse dependency graph in BFS fashion and create jobs for every 238 * necessary unit. 239 * Closure keeps reference to each job. We've to add reference to the 240 * main job, other newly created jobs are pased to the closure. 241 */ 242 fifo_push(jobs_fifo, main_job); 243 job_add_ref(main_job); 244 while (jobs_fifo.head != jobs_fifo.tail) { 245 job_t *job = fifo_pop(jobs_fifo); 235 list_t units_fifo; 236 list_initialize(&units_fifo); 237 238 /* Zero BFS tags before use */ 239 list_foreach(units, units, unit_t, u) { 240 u->bfs_tag = false; 241 } 246 242 243 unit_t *unit = main_job->unit; 244 list_append(&unit->bfs_link, &units_fifo); 245 unit->bfs_tag = true; 246 247 while (!list_empty(&units_fifo)) { 248 unit = list_get_instance(list_first(&units_fifo), unit_t, 249 bfs_link); 250 assert(unit->job); 251 list_remove(&unit->bfs_link); 252 job_t *job = unit->job; 253 254 247 255 // TODO more sophisticated check? (unit that is in transitional 248 256 // state cannot have currently multiple jobs queued) 249 if (job->target_state == job->unit->state) {257 if (job->target_state == unit->state) { 250 258 /* 251 259 * Job would do nothing, finish it on spot. … … 254 262 job->retval = JOB_OK; 255 263 job_finish(job); 256 job_del_ref(&job);257 264 continue; 258 } else {259 /* No refcount increase, pass it to the closure */260 dyn_array_append(job_closure, job_ptr_t, job);261 265 } 262 266 263 /* Traverse dependencies edges */ 264 unit_t *u = job->unit; 265 list_foreach(u->dependencies, dependencies, unit_dependency_t, dep) { 266 // TODO prepare for reverse edge direction and 267 // non-identity state mapping 268 job_t *new_job = 269 job_create(dep->dependency, job->target_state); 270 if (new_job == NULL) { 271 rc = ENOMEM; 272 goto finish; 267 job_add_ref(job); 268 dyn_array_append(job_closure, job_ptr_t, job); 269 270 /* 271 * Traverse dependencies edges 272 * Depending on dependency type and edge direction create 273 * appropriate jobs. 274 */ 275 list_foreach(unit->dependencies, dependencies, unit_dependency_t, dep) { 276 unit_t *u = dep->dependency; 277 job_t *blocking_job; 278 if (u->bfs_tag) { 279 assert(u->job); 280 blocking_job = u->job; 281 } else { 282 u->bfs_tag = true; 283 blocking_job = job_create(u, job->target_state); 284 if (blocking_job == NULL) { 285 rc = ENOMEM; 286 goto finish; 287 } 288 /* Reference to job is kept in unit */ 289 job_del_ref(&blocking_job); 290 list_append(&u->bfs_link, &units_fifo); 273 291 } 274 job_add_blocked_job(new_job, job);275 fifo_push(jobs_fifo, new_job);292 293 job_add_blocked_job(blocking_job, job); 276 294 } 277 295 } 296 sysman_log(LVL_DEBUG2, "%s(%s):", __func__, unit_name(main_job->unit)); 297 dyn_array_foreach(*job_closure, job_ptr_t, job_it) { 298 sysman_log(LVL_DEBUG2, "%s\t%s", __func__, unit_name((*job_it)->unit)); 299 } 278 300 rc = EOK; 279 301 280 302 finish: 281 free(fifo_data); 282 /* 283 * Newly created jobs are already passed to the closure, thus not 284 * deleting reference to them here. 285 */ 303 /* Any unprocessed jobs may be referenced by units */ 304 list_foreach(units_fifo, bfs_link, unit_t, u) { 305 job_del_ref(&u->job); 306 } 286 307 return rc; 287 308 } 288 309 310 /** Create job assigned to the unit 311 * 312 * @param[in] unit unit to be modified, its job must be empty 313 * @param[in] target_state 314 * 315 * @return NULL or newly created job 316 * There are two references to the job, one set in the unit and second 317 * is the return value. 318 */ 289 319 job_t *job_create(unit_t *u, unit_state_t target_state) 290 320 { … … 293 323 job_init(job, u, target_state); 294 324 295 /* Start withone reference for the creator */325 /* Add one reference for the creator */ 296 326 job_add_ref(job); 297 327 } … … 354 384 } 355 385 if (rc != EOK) { 386 sysman_log(LVL_DEBUG, "%s(%p), %s -> %i, error: %i", 387 __func__, job, unit_name(u), job->target_state, rc); 356 388 goto fail; 357 389 } … … 378 410 assert(job->state != JOB_FINISHED); 379 411 assert(job->retval != JOB_UNDEFINED_); 412 assert(job->unit->job == job); 380 413 381 414 sysman_log(LVL_DEBUG2, "%s(%p) %s -> %i", … … 390 423 dyn_array_clear(&job->blocked_jobs); 391 424 392 /* Add reference for the event */ 393 job_add_ref(job); 425 /* 426 * Remove job from unit and pass the reference from the unit to the 427 * event. 428 */ 429 job->unit->job = NULL; 394 430 sysman_raise_event(&sysman_event_job_finished, job); 395 431 } -
uspace/srv/sysman/job.h
rc0e4fc50 rdda2602 54 54 } job_retval_t; 55 55 56 typedef struct{56 struct job { 57 57 link_t job_queue; 58 58 atomic_t refcnt; … … 72 72 /** See job_retval_t */ 73 73 job_retval_t retval; 74 } job_t;74 }; 75 75 76 typedef struct job job_t; 76 77 typedef job_t *job_ptr_t; 77 78 -
uspace/srv/sysman/sysman.c
rc0e4fc50 rdda2602 151 151 152 152 /* Process event */ 153 sysman_log(LVL_DEBUG2, "process_event(%p, %p)",154 event->handler, event->data);153 //sysman_log(LVL_DEBUG2, "process_event(%p, %p)", 154 // event->handler, event->data); 155 155 event->handler(event->data); 156 156 free(event); … … 182 182 void sysman_raise_event(event_handler_t handler, void *data) 183 183 { 184 sysman_log(LVL_DEBUG2, "%s(%p, %p)", __func__, handler, data);184 //sysman_log(LVL_DEBUG2, "%s(%p, %p)", __func__, handler, data); 185 185 event_t *event = malloc(sizeof(event_t)); 186 186 if (event == NULL) { -
uspace/srv/sysman/unit.c
rc0e4fc50 rdda2602 70 70 unit->state = STATE_EMBRYO; 71 71 72 link_initialize(&unit->units); 73 link_initialize(&unit->bfs_link); 72 74 list_initialize(&unit->dependants); 73 75 list_initialize(&unit->dependencies); … … 181 183 } 182 184 183 bool unit_parse_unit_list(const char * value, void *dst, text_parse_t *parse,185 bool unit_parse_unit_list(const char *string, void *dst, text_parse_t *parse, 184 186 size_t lineno) 185 187 { 186 188 unit_t *unit = dst; 187 189 bool result; 188 char *my_ value = str_dup(value);189 190 if (!my_ value) {190 char *my_string = str_dup(string); 191 192 if (!my_string) { 191 193 result = false; 192 194 goto finish; 193 195 } 194 196 195 char *to_split = my_ value;197 char *to_split = my_string; 196 198 char *cur_tok; 197 199 … … 206 208 207 209 finish: 208 free(my_ value);210 free(my_string); 209 211 return result; 210 212 } -
uspace/srv/sysman/unit.h
rc0e4fc50 rdda2602 42 42 typedef enum { 43 43 UNIT_TYPE_INVALID = -1, 44 UNIT_ TARGET= 0,44 UNIT_CONFIGURATION = 0, 45 45 UNIT_MOUNT, 46 UNIT_ CONFIGURATION,47 UNIT_ SERVICE46 UNIT_SERVICE, 47 UNIT_TARGET 48 48 } unit_type_t; 49 49 … … 56 56 } unit_state_t; 57 57 58 /* Forward declarations */ 59 typedef struct unit_vmt unit_vmt_t; 60 struct unit_vmt; 61 62 typedef struct job job_t; 63 struct job; 64 58 65 typedef struct { 59 ht_link_t units; 66 /** Link to name-to-unit hash table */ 67 ht_link_t units_by_name; 68 69 /** Link to list of all units */ 70 link_t units; 71 72 /** Link to queue, when BFS traversing units */ 73 link_t bfs_link; 74 75 /** Seen tag for BFS traverse, must be reset before each BFS */ 76 bool bfs_tag; 77 78 job_t *job; 60 79 61 80 unit_type_t type; … … 67 86 list_t dependants; 68 87 } unit_t; 69 70 typedef struct unit_vmt unit_vmt_t;71 struct unit_vmt;72 88 73 89 #include "unit_cfg.h" -
uspace/srv/sysman/units/unit_cfg.c
rc0e4fc50 rdda2602 101 101 assert(u->type == unit_type); 102 102 103 fn = compose_path(dirname, filename);103 fn = util_compose_path(dirname, filename); 104 104 if (fn == NULL) { 105 105 rc = ENOMEM; -
uspace/srv/sysman/units/unit_svc.c
rc0e4fc50 rdda2602 39 39 40 40 static config_item_t unit_configuration[] = { 41 {"ExecStart", & config_parse_string, offsetof(unit_svc_t, exec_start), NULL},41 {"ExecStart", &util_parse_command, offsetof(unit_svc_t, exec_start), NULL}, 42 42 CONFIGURATION_ITEM_SENTINEL 43 43 }; … … 47 47 unit_svc_t *u_svc = CAST_SVC(unit); 48 48 assert(u_svc); 49 util_command_init(&u_svc->exec_start); 49 50 } 50 51 … … 54 55 unit_svc_t *u_svc = CAST_SVC(unit); 55 56 56 free(u_svc->exec_start);57 util_command_deinit(&u_svc->exec_start); 57 58 } 58 59 … … 84 85 assert(unit->state == STATE_STOPPED); 85 86 86 // TODO extend the simple implementation87 const char *args[] = {"warn", NULL};88 int rc = task_spawnv(NULL, NULL, u_svc->exec_start, args);87 int rc = task_spawnv(NULL, NULL, u_svc->exec_start.path, 88 u_svc->exec_start.argv); 89 sysman_log(LVL_DEBUG2, "task_spawn(%s, %s)", u_svc->exec_start.path, u_svc->exec_start.argv[0]); 89 90 if (rc != EOK) { 90 91 unit->state = STATE_FAILED; … … 101 102 unit->state = STATE_STARTED; 102 103 104 /* 105 * Workaround to see log output even after devman starts (and overrides 106 * kernel's frame buffer. It's here since devman is started as a 107 * service (however not all services are devman...). 108 */ 103 109 if (console_kcon()) { 104 110 sysman_log(LVL_DEBUG2, "%s: Kconsole grabbed.", __func__); -
uspace/srv/sysman/units/unit_svc.h
rc0e4fc50 rdda2602 31 31 32 32 #include "unit.h" 33 #include "util.h" 33 34 34 35 typedef struct { 35 36 unit_t unit; 36 37 37 char *exec_start; 38 38 command_t exec_start; 39 39 } unit_svc_t; 40 40 -
uspace/srv/sysman/util.c
rc0e4fc50 rdda2602 38 38 * @return NULL on error 39 39 */ 40 char * compose_path(const char *dirname, const char *filename)40 char *util_compose_path(const char *dirname, const char *filename) 41 41 { 42 42 size_t size = str_size(dirname) + str_size(filename) + 2; … … 51 51 return result; 52 52 } 53 54 /** Parse command line 55 * 56 * @param[out] dst pointer to command_t 57 * path and zeroth argument are the equal 58 * 59 * @return true on success 60 * @return false on (low memory) error 61 */ 62 bool util_parse_command(const char *string, void *dst, text_parse_t *parse, 63 size_t lineno) 64 { 65 command_t *command = dst; 66 util_command_deinit(command); 67 68 command->buffer = str_dup(string); 69 if (!command->buffer) { 70 return false; 71 } 72 73 command->argc = 0; 74 char *to_split = command->buffer; 75 char *cur_tok; 76 bool has_path = false; 77 78 while ((cur_tok = str_tok(to_split, " ", &to_split)) && 79 command->argc < MAX_COMMAND_ARGS) { 80 if (!has_path) { 81 command->path = cur_tok; 82 has_path = true; 83 } 84 command->argv[command->argc++] = cur_tok; 85 } 86 command->argv[command->argc] = NULL; 87 88 89 if (command->argc > MAX_COMMAND_ARGS) { 90 text_parse_raise_error(parse, lineno, 91 CONFIGURATION_ELIMIT); 92 return false; 93 } else { 94 return true; 95 } 96 } 97 98 99 void util_command_init(command_t *command) 100 { 101 memset(command, 0, sizeof(*command)); 102 } 103 104 void util_command_deinit(command_t *command) 105 { 106 free(command->buffer); 107 memset(command, 0, sizeof(*command)); 108 } -
uspace/srv/sysman/util.h
rc0e4fc50 rdda2602 30 30 #define SYSMAN_UTIL_H 31 31 32 extern char *compose_path(const char *, const char *); 32 #include <conf/configuration.h> 33 34 #define MAX_COMMAND_ARGS 256 35 36 /** Represent stuctured execute command */ 37 typedef struct { 38 /** Path to executable */ 39 const char *path; 40 /** No. of command line arguments */ 41 size_t argc; 42 /** NULL-terminated vector of command line arguments */ 43 const char *argv[MAX_COMMAND_ARGS + 1]; 44 /** (internal) Buffer holding raw string data */ 45 char *buffer; 46 } command_t; 47 48 extern char *util_compose_path(const char *, const char *); 49 50 extern bool util_parse_command(const char *, void *, text_parse_t *, size_t); 51 52 extern void util_command_init(command_t *); 53 extern void util_command_deinit(command_t *); 33 54 34 55 #endif
Note:
See TracChangeset
for help on using the changeset viewer.