Changes in uspace/srv/taskmon/taskmon.c [dbae3b6:4c6fd56] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/taskmon/taskmon.c
rdbae3b6 r4c6fd56 1 1 /* 2 * Copyright (c) 202 4Jiri Svoboda2 * Copyright (c) 2023 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 35 35 */ 36 36 37 #include <stdio.h> 37 38 #include <async.h> 38 #include <errno.h>39 #include <macros.h>40 39 #include <ipc/services.h> 40 #include <task.h> 41 41 #include <ipc/corecfg.h> 42 42 #include <loc.h> 43 #include <sif.h> 44 #include <stdio.h> 45 #include <str.h> 43 #include <macros.h> 44 #include <errno.h> 46 45 #include <str_error.h> 47 #include <task.h>48 46 49 47 #define NAME "taskmon" 50 48 51 static const char *taskmon_cfg_path = "/w/cfg/taskmon.sif";52 53 49 static bool write_core_files; 54 50 55 static errno_t taskmon_load_cfg(const char *);56 static errno_t taskmon_save_cfg(const char *);57 51 static void corecfg_client_conn(ipc_call_t *, void *); 58 52 … … 109 103 write_core_files = ipc_get_arg1(icall); 110 104 async_answer_0(icall, EOK); 111 (void) taskmon_save_cfg(taskmon_cfg_path);112 105 } 113 106 … … 141 134 } 142 135 143 /** Load task monitor configuration from SIF file.144 *145 * @param cfgpath Configuration file path146 *147 * @return EOK on success or an error code148 */149 static errno_t taskmon_load_cfg(const char *cfgpath)150 {151 sif_doc_t *doc = NULL;152 sif_node_t *rnode;153 sif_node_t *ncorefiles;154 const char *ntype;155 const char *swrite;156 errno_t rc;157 158 rc = sif_load(cfgpath, &doc);159 if (rc != EOK)160 goto error;161 162 rnode = sif_get_root(doc);163 ncorefiles = sif_node_first_child(rnode);164 ntype = sif_node_get_type(ncorefiles);165 if (str_cmp(ntype, "corefiles") != 0) {166 rc = EIO;167 goto error;168 }169 170 swrite = sif_node_get_attr(ncorefiles, "write");171 if (swrite == NULL) {172 rc = EIO;173 goto error;174 }175 176 if (str_cmp(swrite, "y") == 0) {177 write_core_files = true;178 } else if (str_cmp(swrite, "n") == 0) {179 write_core_files = false;180 } else {181 rc = EIO;182 goto error;183 }184 185 sif_delete(doc);186 return EOK;187 error:188 if (doc != NULL)189 sif_delete(doc);190 return rc;191 }192 193 /** Save task monitor configuration to SIF file.194 *195 * @param cfgpath Configuration file path196 *197 * @return EOK on success or an error code198 */199 static errno_t taskmon_save_cfg(const char *cfgpath)200 {201 sif_doc_t *doc = NULL;202 sif_node_t *rnode;203 sif_node_t *ncorefiles;204 errno_t rc;205 206 rc = sif_new(&doc);207 if (rc != EOK)208 goto error;209 210 rnode = sif_get_root(doc);211 rc = sif_node_append_child(rnode, "corefiles", &ncorefiles);212 if (rc != EOK)213 goto error;214 215 rc = sif_node_set_attr(ncorefiles, "write",216 write_core_files ? "y" : "n");217 if (rc != EOK)218 goto error;219 220 rc = sif_save(doc, cfgpath);221 if (rc != EOK)222 goto error;223 224 sif_delete(doc);225 return EOK;226 error:227 if (doc != NULL)228 sif_delete(doc);229 return rc;230 }231 232 136 int main(int argc, char *argv[]) 233 137 { … … 241 145 write_core_files = false; 242 146 #endif 243 (void) taskmon_load_cfg(taskmon_cfg_path);244 245 147 if (async_event_subscribe(EVENT_FAULT, fault_event, NULL) != EOK) { 246 148 printf("%s: Error registering fault notifications.\n", NAME);
Note:
See TracChangeset
for help on using the changeset viewer.