Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/taskmon/taskmon.c

    rdbae3b6 r4c6fd56  
    11/*
    2  * Copyright (c) 2024 Jiri Svoboda
     2 * Copyright (c) 2023 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    3535 */
    3636
     37#include <stdio.h>
    3738#include <async.h>
    38 #include <errno.h>
    39 #include <macros.h>
    4039#include <ipc/services.h>
     40#include <task.h>
    4141#include <ipc/corecfg.h>
    4242#include <loc.h>
    43 #include <sif.h>
    44 #include <stdio.h>
    45 #include <str.h>
     43#include <macros.h>
     44#include <errno.h>
    4645#include <str_error.h>
    47 #include <task.h>
    4846
    4947#define NAME  "taskmon"
    5048
    51 static const char *taskmon_cfg_path = "/w/cfg/taskmon.sif";
    52 
    5349static bool write_core_files;
    5450
    55 static errno_t taskmon_load_cfg(const char *);
    56 static errno_t taskmon_save_cfg(const char *);
    5751static void corecfg_client_conn(ipc_call_t *, void *);
    5852
     
    109103        write_core_files = ipc_get_arg1(icall);
    110104        async_answer_0(icall, EOK);
    111         (void) taskmon_save_cfg(taskmon_cfg_path);
    112105}
    113106
     
    141134}
    142135
    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 
    232136int main(int argc, char *argv[])
    233137{
     
    241145        write_core_files = false;
    242146#endif
    243         (void) taskmon_load_cfg(taskmon_cfg_path);
    244 
    245147        if (async_event_subscribe(EVENT_FAULT, fault_event, NULL) != EOK) {
    246148                printf("%s: Error registering fault notifications.\n", NAME);
Note: See TracChangeset for help on using the changeset viewer.