taskmon.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2010 Jiri Svoboda
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  *
00009  * - Redistributions of source code must retain the above copyright
00010  *   notice, this list of conditions and the following disclaimer.
00011  * - Redistributions in binary form must reproduce the above copyright
00012  *   notice, this list of conditions and the following disclaimer in the
00013  *   documentation and/or other materials provided with the distribution.
00014  * - The name of the author may not be used to endorse or promote products
00015  *   derived from this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
00018  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00019  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
00020  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
00021  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
00022  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00023  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00024  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00025  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00026  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
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 

Generated on Thu Jun 2 07:45:50 2011 for HelenOS/USB by  doxygen 1.4.7