Changeset ebb1489 in mainline for uspace/srv/taskmon/taskmon.c
- Timestamp:
- 2024-10-13T08:23:40Z (2 months ago)
- Children:
- 0472cf17
- Parents:
- 2a0c827c (diff), b3b79981 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - git-author:
- boba-buba <120932204+boba-buba@…> (2024-10-13 08:23:40)
- git-committer:
- GitHub <noreply@…> (2024-10-13 08:23:40)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/taskmon/taskmon.c
r2a0c827c rebb1489 1 1 /* 2 * Copyright (c) 202 3Jiri Svoboda2 * Copyright (c) 2024 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 35 35 */ 36 36 37 #include <stdio.h>38 37 #include <async.h> 38 #include <errno.h> 39 #include <macros.h> 39 40 #include <ipc/services.h> 40 #include <task.h>41 41 #include <ipc/corecfg.h> 42 42 #include <loc.h> 43 #include <macros.h> 44 #include <errno.h> 43 #include <sif.h> 44 #include <stdio.h> 45 #include <str.h> 45 46 #include <str_error.h> 47 #include <task.h> 46 48 47 49 #define NAME "taskmon" 48 50 51 static const char *taskmon_cfg_path = "/w/cfg/taskmon.sif"; 52 49 53 static bool write_core_files; 50 54 55 static errno_t taskmon_load_cfg(const char *); 56 static errno_t taskmon_save_cfg(const char *); 51 57 static void corecfg_client_conn(ipc_call_t *, void *); 52 58 … … 103 109 write_core_files = ipc_get_arg1(icall); 104 110 async_answer_0(icall, EOK); 111 (void) taskmon_save_cfg(taskmon_cfg_path); 105 112 } 106 113 … … 134 141 } 135 142 143 /** Load task monitor configuration from SIF file. 144 * 145 * @param cfgpath Configuration file path 146 * 147 * @return EOK on success or an error code 148 */ 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 path 196 * 197 * @return EOK on success or an error code 198 */ 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 136 232 int main(int argc, char *argv[]) 137 233 { … … 145 241 write_core_files = false; 146 242 #endif 243 (void) taskmon_load_cfg(taskmon_cfg_path); 244 147 245 if (async_event_subscribe(EVENT_FAULT, fault_event, NULL) != EOK) { 148 246 printf("%s: Error registering fault notifications.\n", NAME);
Note:
See TracChangeset
for help on using the changeset viewer.