source: mainline/uspace/app/klog/klog.c@ 007e6efa

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 007e6efa was 007e6efa, checked in by Martin Decky <martin@…>, 15 years ago
  • libc routines for registering services and connecting to services via NS
  • async_connect_to_me()
  • Property mode set to 100644
File size: 3.0 KB
Line 
1/*
2 * Copyright (c) 2006 Ondrej Palkovsky
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 klog KLog
30 * @brief HelenOS KLog
31 * @{
32 */
33/**
34 * @file
35 */
36
37#include <stdio.h>
38#include <ipc/ipc.h>
39#include <ipc/ns.h>
40#include <async.h>
41#include <ipc/services.h>
42#include <as.h>
43#include <sysinfo.h>
44#include <event.h>
45#include <errno.h>
46#include <str_error.h>
47#include <io/klog.h>
48
49#define NAME "klog"
50#define LOG_FNAME "/log/klog"
51
52/* Pointer to klog area */
53static wchar_t *klog;
54static size_t klog_length;
55
56static FILE *log;
57
58static void interrupt_received(ipc_callid_t callid, ipc_call_t *call)
59{
60 size_t klog_start = (size_t) IPC_GET_ARG1(*call);
61 size_t klog_len = (size_t) IPC_GET_ARG2(*call);
62 size_t klog_stored = (size_t) IPC_GET_ARG3(*call);
63 size_t i;
64
65 for (i = klog_len - klog_stored; i < klog_len; i++) {
66 wchar_t ch = klog[(klog_start + i) % klog_length];
67
68 putchar(ch);
69
70 if (log != NULL)
71 fputc(ch, log);
72 }
73
74 if (log != NULL) {
75 fflush(log);
76 fsync(fileno(log));
77 }
78}
79
80int main(int argc, char *argv[])
81{
82 klog = service_klog_share_in(&klog_length);
83 if (klog == NULL) {
84 printf("%s: Error accessing to klog\n", NAME);
85 return -1;
86 }
87
88 if (event_subscribe(EVENT_KLOG, 0) != EOK) {
89 printf("%s: Error registering klog notifications\n", NAME);
90 return -1;
91 }
92
93 /*
94 * Mode "a" would be definitively much better here, but it is
95 * not well supported by the FAT driver.
96 */
97 log = fopen(LOG_FNAME, "w");
98 if (log == NULL)
99 printf("%s: Unable to create log file %s (%s)\n", NAME, LOG_FNAME,
100 str_error(errno));
101
102 async_set_interrupt_received(interrupt_received);
103 klog_update();
104 async_manager();
105
106 return 0;
107}
108
109/** @}
110 */
Note: See TracBrowser for help on using the repository browser.