Changes in uspace/srv/taskmon/taskmon.c [9d58539:b688fd8] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/taskmon/taskmon.c
r9d58539 rb688fd8 1 1 /* 2 * Copyright (c) 201 0Jiri Svoboda2 * Copyright (c) 2013 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 40 40 #include <sys/typefmt.h> 41 41 #include <task.h> 42 #include <event.h> 42 #include <ipc/corecfg.h> 43 #include <loc.h> 43 44 #include <macros.h> 44 45 #include <errno.h> … … 47 48 #define NAME "taskmon" 48 49 49 static void fault_event(ipc_callid_t callid, ipc_call_t *call) 50 static bool write_core_files; 51 52 static void corecfg_client_conn(ipc_callid_t , ipc_call_t *, void *); 53 54 static void fault_event(ipc_callid_t callid, ipc_call_t *call, void *arg) 50 55 { 51 56 const char *fname; 52 57 char *s_taskid; 58 char *dump_fname; 53 59 int rc; 54 60 … … 69 75 fname = "/app/taskdump"; 70 76 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 } 73 82 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); 77 89 } 78 90 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 #else83 printf(NAME ": Executing %s -t %s\n", fname, s_taskid);84 rc = task_spawnl(NULL, fname, fname, "-t", s_taskid, NULL);85 #endif86 91 if (rc != EOK) { 87 92 printf("%s: Error spawning %s (%s).\n", NAME, fname, 88 93 str_error(rc)); 94 } 95 } 96 97 static 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 102 static 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 108 static 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 } 89 132 } 90 133 } … … 94 137 printf("%s: Task Monitoring Service\n", NAME); 95 138 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) { 97 145 printf("%s: Error registering fault notifications.\n", NAME); 98 146 return -1; 99 147 } 100 148 101 async_set_interrupt_received(fault_event); 149 async_set_fallback_port_handler(corecfg_client_conn, NULL); 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 102 166 task_retval(0); 103 167 async_manager();
Note:
See TracChangeset
for help on using the changeset viewer.