Ignore:
File:
1 edited

Legend:

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

    r9d58539 r1c635d6  
    11/*
    2  * Copyright (c) 2010 Jiri Svoboda
     2 * Copyright (c) 2013 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    4040#include <sys/typefmt.h>
    4141#include <task.h>
    42 #include <event.h>
     42#include <ipc/corecfg.h>
     43#include <loc.h>
    4344#include <macros.h>
    4445#include <errno.h>
     
    4748#define NAME  "taskmon"
    4849
    49 static void fault_event(ipc_callid_t callid, ipc_call_t *call)
     50static bool write_core_files;
     51
     52static void corecfg_client_conn(ipc_callid_t , ipc_call_t *, void *);
     53
     54static void fault_event(ipc_callid_t callid, ipc_call_t *call, void *arg)
    5055{
    5156        const char *fname;
    5257        char *s_taskid;
     58        char *dump_fname;
    5359        int rc;
    5460
     
    6975        fname = "/app/taskdump";
    7076
    71 #ifdef CONFIG_WRITE_CORE_FILES
    72         char *dump_fname;
     77        if (write_core_files) {
     78                if (asprintf(&dump_fname, "/data/core%" PRIu64, taskid) < 0) {
     79                        printf("Memory allocation failed.\n");
     80                        return;
     81                }
    7382
    74         if (asprintf(&dump_fname, "/data/core%" PRIu64, taskid) < 0) {
    75                 printf("Memory allocation failed.\n");
    76                 return;
     83                printf(NAME ": Executing %s -c %s -t %s\n", fname, dump_fname, s_taskid);
     84                rc = task_spawnl(NULL, NULL, fname, fname, "-c", dump_fname, "-t", s_taskid,
     85                    NULL);
     86        } else {
     87                printf(NAME ": Executing %s -t %s\n", fname, s_taskid);
     88                rc = task_spawnl(NULL, NULL, fname, fname, "-t", s_taskid, NULL);
    7789        }
    7890
    79         printf(NAME ": Executing %s -c %s -t %s\n", fname, dump_fname, s_taskid);
    80         rc = task_spawnl(NULL, fname, fname, "-c", dump_fname, "-t", s_taskid,
    81             NULL);
    82 #else
    83         printf(NAME ": Executing %s -t %s\n", fname, s_taskid);
    84         rc = task_spawnl(NULL, fname, fname, "-t", s_taskid, NULL);
    85 #endif
    8691        if (rc != EOK) {
    8792                printf("%s: Error spawning %s (%s).\n", NAME, fname,
    8893                    str_error(rc));
     94        }
     95}
     96
     97static void corecfg_get_enable_srv(ipc_callid_t iid, ipc_call_t *icall)
     98{
     99        async_answer_1(iid, EOK, write_core_files);
     100}
     101
     102static void corecfg_set_enable_srv(ipc_callid_t iid, ipc_call_t *icall)
     103{
     104        write_core_files = IPC_GET_ARG1(*icall);
     105        async_answer_0(iid, EOK);
     106}
     107
     108static void corecfg_client_conn(ipc_callid_t iid, ipc_call_t *icall, void *arg)
     109{
     110        /* Accept the connection */
     111        async_answer_0(iid, EOK);
     112
     113        while (true) {
     114                ipc_call_t call;
     115                ipc_callid_t callid = async_get_call(&call);
     116                sysarg_t method = IPC_GET_IMETHOD(call);
     117
     118                if (!method) {
     119                        /* The other side has hung up */
     120                        async_answer_0(callid, EOK);
     121                        return;
     122                }
     123
     124                switch (method) {
     125                case CORECFG_GET_ENABLE:
     126                        corecfg_get_enable_srv(callid, &call);
     127                        break;
     128                case CORECFG_SET_ENABLE:
     129                        corecfg_set_enable_srv(callid, &call);
     130                        break;
     131                }
    89132        }
    90133}
     
    94137        printf("%s: Task Monitoring Service\n", NAME);
    95138       
    96         if (event_subscribe(EVENT_FAULT, 0) != EOK) {
     139#ifdef CONFIG_WRITE_CORE_FILES
     140        write_core_files = true;
     141#else
     142        write_core_files = false;
     143#endif
     144        if (async_event_subscribe(EVENT_FAULT, fault_event, NULL) != EOK) {
    97145                printf("%s: Error registering fault notifications.\n", NAME);
    98146                return -1;
    99147        }
    100148       
    101         async_set_interrupt_received(fault_event);
     149        async_set_client_connection(corecfg_client_conn);
     150       
     151        int rc = loc_server_register(NAME);
     152        if (rc != EOK) {
     153                printf("%s: Failed registering server (%d).\n",
     154                    NAME, rc);
     155                return -1;
     156        }
     157       
     158        service_id_t sid;
     159        rc = loc_service_register(SERVICE_NAME_CORECFG, &sid);
     160        if (rc != EOK) {
     161                printf("%s: Failed registering service (%d).\n",
     162                    NAME, rc);
     163                return -1;
     164        }
     165       
    102166        task_retval(0);
    103167        async_manager();
Note: See TracChangeset for help on using the changeset viewer.