Changes in uspace/app/klog/klog.c [6119f24:1ea99cc] in mainline


Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/klog/klog.c

    r6119f24 r1ea99cc  
    3636
    3737#include <stdio.h>
     38#include <ipc/ipc.h>
    3839#include <async.h>
     40#include <ipc/services.h>
    3941#include <as.h>
    40 #include <ddi.h>
     42#include <sysinfo.h>
    4143#include <event.h>
    4244#include <errno.h>
    43 #include <str_error.h>
    4445#include <io/klog.h>
    45 #include <sysinfo.h>
    4646
    47 #define NAME       "klog"
    48 #define LOG_FNAME  "/log/klog"
     47#define NAME  "klog"
    4948
    5049/* Pointer to klog area */
    5150static wchar_t *klog;
    5251static size_t klog_length;
    53 
    54 static FILE *log;
    5552
    5653static void interrupt_received(ipc_callid_t callid, ipc_call_t *call)
     
    6158        size_t i;
    6259       
    63         for (i = klog_len - klog_stored; i < klog_len; i++) {
    64                 wchar_t ch = klog[(klog_start + i) % klog_length];
    65                
    66                 putchar(ch);
    67                
    68                 if (log != NULL)
    69                         fputc(ch, log);
    70         }
    71        
    72         if (log != NULL) {
    73                 fflush(log);
    74                 fsync(fileno(log));
    75         }
     60        for (i = klog_len - klog_stored; i < klog_len; i++)
     61                putchar(klog[(klog_start + i) % klog_length]);
    7662}
    7763
    7864int main(int argc, char *argv[])
    7965{
    80         size_t pages;
    81         int rc = sysinfo_get_value("klog.pages", &pages);
    82         if (rc != EOK) {
    83                 fprintf(stderr, "%s: Unable to get number of klog pages\n",
    84                     NAME);
    85                 return rc;
     66        size_t klog_pages = sysinfo_value("klog.pages");
     67        size_t klog_size = klog_pages * PAGE_SIZE;
     68        klog_length = klog_size / sizeof(wchar_t);
     69       
     70        klog = (wchar_t *) as_get_mappable_page(klog_size);
     71        if (klog == NULL) {
     72                printf(NAME ": Error allocating memory area\n");
     73                return -1;
     74        }
     75
     76        printf("got area at 0x%08lx, length %lx byes\n", klog, klog_size);
     77       
     78        int res = ipc_share_in_start_1_0(PHONE_NS, (void *) klog,
     79            klog_size, SERVICE_MEM_KLOG);
     80        if (res != EOK) {
     81                printf(NAME ": Error initializing memory area\n");
     82                return -1;
    8683        }
    8784       
    88         uintptr_t faddr;
    89         rc = sysinfo_get_value("klog.faddr", &faddr);
    90         if (rc != EOK) {
    91                 fprintf(stderr, "%s: Unable to get klog physical address\n",
    92                     NAME);
    93                 return rc;
     85        if (event_subscribe(EVENT_KLOG, 0) != EOK) {
     86                printf(NAME ": Error registering klog notifications\n");
     87                return -1;
    9488        }
    95        
    96         size_t size = pages * PAGE_SIZE;
    97         klog_length = size / sizeof(wchar_t);
    98        
    99         klog = (wchar_t *) as_get_mappable_page(size);
    100         if (klog == NULL) {
    101                 fprintf(stderr, "%s: Unable to allocate virtual memory area\n",
    102                     NAME);
    103                 return ENOMEM;
    104         }
    105        
    106         rc = physmem_map((void *) faddr, (void *) klog, pages,
    107             AS_AREA_READ | AS_AREA_CACHEABLE);
    108         if (rc != EOK) {
    109                 fprintf(stderr, "%s: Unable to map klog\n", NAME);
    110                 return rc;
    111         }
    112        
    113         rc = event_subscribe(EVENT_KLOG, 0);
    114         if (rc != EOK) {
    115                 fprintf(stderr, "%s: Unable to register klog notifications\n",
    116                     NAME);
    117                 return rc;
    118         }
    119        
    120         /*
    121          * Mode "a" would be definitively much better here, but it is
    122          * not well supported by the FAT driver.
    123          */
    124         log = fopen(LOG_FNAME, "w");
    125         if (log == NULL)
    126                 printf("%s: Unable to create log file %s (%s)\n", NAME, LOG_FNAME,
    127                     str_error(errno));
    12889       
    12990        async_set_interrupt_received(interrupt_received);
Note: See TracChangeset for help on using the changeset viewer.