source: mainline/uspace/srv/taskmon/taskmon.c@ 850fd32

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 850fd32 was a35b458, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 8 years ago

style: Remove trailing whitespace on _all_ lines, including empty ones, for particular file types.

Command used: tools/srepl '\s\+$' '' -- *.c *.h *.py *.sh *.s *.S *.ag

Currently, whitespace on empty lines is very inconsistent.
There are two basic choices: Either remove the whitespace, or keep empty lines
indented to the level of surrounding code. The former is AFAICT more common,
and also much easier to do automatically.

Alternatively, we could write script for automatic indentation, and use that
instead. However, if such a script exists, it's possible to use the indented
style locally, by having the editor apply relevant conversions on load/save,
without affecting remote repository. IMO, it makes more sense to adopt
the simpler rule.

  • Property mode set to 100644
File size: 4.4 KB
Line 
1/*
2 * Copyright (c) 2013 Jiri Svoboda
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup taskmon
30 * @brief
31 * @{
32 */
33/**
34 * @file
35 */
36
37#include <stdio.h>
38#include <async.h>
39#include <ipc/services.h>
40#include <task.h>
41#include <ipc/corecfg.h>
42#include <loc.h>
43#include <macros.h>
44#include <errno.h>
45#include <str_error.h>
46
47#define NAME "taskmon"
48
49static bool write_core_files;
50
51static void corecfg_client_conn(ipc_callid_t , ipc_call_t *, void *);
52
53static void fault_event(ipc_call_t *call, void *arg)
54{
55 const char *fname;
56 char *s_taskid;
57 char *dump_fname;
58 errno_t rc;
59
60 task_id_t taskid;
61 uintptr_t thread;
62
63 taskid = MERGE_LOUP32(IPC_GET_ARG1(*call), IPC_GET_ARG2(*call));
64 thread = IPC_GET_ARG3(*call);
65
66 if (asprintf(&s_taskid, "%" PRIu64, taskid) < 0) {
67 printf("Memory allocation failed.\n");
68 return;
69 }
70
71 printf(NAME ": Task %" PRIu64 " fault in thread %p.\n", taskid,
72 (void *) thread);
73
74 fname = "/app/taskdump";
75
76 if (write_core_files) {
77 if (asprintf(&dump_fname, "/data/core%" PRIu64, taskid) < 0) {
78 printf("Memory allocation failed.\n");
79 return;
80 }
81
82 printf(NAME ": Executing %s -c %s -t %s\n", fname, dump_fname, s_taskid);
83 rc = task_spawnl(NULL, NULL, fname, fname, "-c", dump_fname, "-t", s_taskid,
84 NULL);
85 } else {
86 printf(NAME ": Executing %s -t %s\n", fname, s_taskid);
87 rc = task_spawnl(NULL, NULL, fname, fname, "-t", s_taskid, NULL);
88 }
89
90 if (rc != EOK) {
91 printf("%s: Error spawning %s (%s).\n", NAME, fname,
92 str_error(rc));
93 }
94}
95
96static void corecfg_get_enable_srv(ipc_callid_t iid, ipc_call_t *icall)
97{
98 async_answer_1(iid, EOK, write_core_files);
99}
100
101static void corecfg_set_enable_srv(ipc_callid_t iid, ipc_call_t *icall)
102{
103 write_core_files = IPC_GET_ARG1(*icall);
104 async_answer_0(iid, EOK);
105}
106
107static void corecfg_client_conn(ipc_callid_t iid, ipc_call_t *icall, void *arg)
108{
109 /* Accept the connection */
110 async_answer_0(iid, EOK);
111
112 while (true) {
113 ipc_call_t call;
114 ipc_callid_t callid = async_get_call(&call);
115 sysarg_t method = IPC_GET_IMETHOD(call);
116
117 if (!method) {
118 /* The other side has hung up */
119 async_answer_0(callid, EOK);
120 return;
121 }
122
123 switch (method) {
124 case CORECFG_GET_ENABLE:
125 corecfg_get_enable_srv(callid, &call);
126 break;
127 case CORECFG_SET_ENABLE:
128 corecfg_set_enable_srv(callid, &call);
129 break;
130 }
131 }
132}
133
134int main(int argc, char *argv[])
135{
136 printf("%s: Task Monitoring Service\n", NAME);
137
138#ifdef CONFIG_WRITE_CORE_FILES
139 write_core_files = true;
140#else
141 write_core_files = false;
142#endif
143 if (async_event_subscribe(EVENT_FAULT, fault_event, NULL) != EOK) {
144 printf("%s: Error registering fault notifications.\n", NAME);
145 return -1;
146 }
147
148 async_set_fallback_port_handler(corecfg_client_conn, NULL);
149
150 errno_t rc = loc_server_register(NAME);
151 if (rc != EOK) {
152 printf("%s: Failed registering server: %s.\n",
153 NAME, str_error(rc));
154 return -1;
155 }
156
157 service_id_t sid;
158 rc = loc_service_register(SERVICE_NAME_CORECFG, &sid);
159 if (rc != EOK) {
160 printf("%s: Failed registering service: %s.\n",
161 NAME, str_error(rc));
162 return -1;
163 }
164
165 task_retval(0);
166 async_manager();
167
168 return 0;
169}
170
171/** @}
172 */
Note: See TracBrowser for help on using the repository browser.