00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00037 #include <stdio.h>
00038 #include <async.h>
00039 #include <ipc/services.h>
00040 #include <sys/typefmt.h>
00041 #include <task.h>
00042 #include <event.h>
00043 #include <macros.h>
00044 #include <errno.h>
00045 #include <str_error.h>
00046
00047 #define NAME "taskmon"
00048
00049 static void fault_event(ipc_callid_t callid, ipc_call_t *call)
00050 {
00051 const char *fname;
00052 char *s_taskid;
00053 int rc;
00054
00055 task_id_t taskid;
00056 uintptr_t thread;
00057
00058 taskid = MERGE_LOUP32(IPC_GET_ARG1(*call), IPC_GET_ARG2(*call));
00059 thread = IPC_GET_ARG3(*call);
00060
00061 if (asprintf(&s_taskid, "%" PRIu64, taskid) < 0) {
00062 printf("Memory allocation failed.\n");
00063 return;
00064 }
00065
00066 printf(NAME ": Task %" PRIu64 " fault in thread %p.\n", taskid,
00067 (void *) thread);
00068
00069 fname = "/app/taskdump";
00070
00071 #ifdef CONFIG_WRITE_CORE_FILES
00072 char *dump_fname;
00073
00074 if (asprintf(&dump_fname, "/data/core%" PRIu64, taskid) < 0) {
00075 printf("Memory allocation failed.\n");
00076 return;
00077 }
00078
00079 printf(NAME ": Executing %s -c %s -t %s\n", fname, dump_fname, s_taskid);
00080 rc = task_spawnl(NULL, fname, fname, "-c", dump_fname, "-t", s_taskid,
00081 NULL);
00082 #else
00083 printf(NAME ": Executing %s -t %s\n", fname, s_taskid);
00084 rc = task_spawnl(NULL, fname, fname, "-t", s_taskid, NULL);
00085 #endif
00086 if (rc != EOK) {
00087 printf("%s: Error spawning %s (%s).\n", NAME, fname,
00088 str_error(rc));
00089 }
00090 }
00091
00092 int main(int argc, char *argv[])
00093 {
00094 printf(NAME ": Task Monitoring Service\n");
00095
00096 if (event_subscribe(EVENT_FAULT, 0) != EOK) {
00097 printf(NAME ": Error registering fault notifications.\n");
00098 return -1;
00099 }
00100
00101 async_set_interrupt_received(fault_event);
00102 async_manager();
00103
00104 return 0;
00105 }
00106