Changeset 46c20c8 in mainline for uspace/app/klog/klog.c


Ignore:
Timestamp:
2010-11-26T20:08:10Z (15 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
45df59a
Parents:
fb150d78 (diff), ffdd2b9 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge mainline changes.

File:
1 edited

Legend:

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

    rfb150d78 r46c20c8  
    4343#include <event.h>
    4444#include <errno.h>
     45#include <str_error.h>
    4546#include <io/klog.h>
    4647
    47 #define NAME  "klog"
     48#define NAME       "klog"
     49#define LOG_FNAME  "/log/klog"
    4850
    4951/* Pointer to klog area */
    5052static wchar_t *klog;
    5153static size_t klog_length;
     54
     55static FILE *log;
    5256
    5357static void interrupt_received(ipc_callid_t callid, ipc_call_t *call)
     
    5862        size_t i;
    5963       
    60         for (i = klog_len - klog_stored; i < klog_len; i++)
    61                 putchar(klog[(klog_start + i) % klog_length]);
     64        for (i = klog_len - klog_stored; i < klog_len; i++) {
     65                wchar_t ch = klog[(klog_start + i) % klog_length];
     66               
     67                putchar(ch);
     68               
     69                if (log != NULL)
     70                        fputc(ch, log);
     71        }
     72       
     73        if (log != NULL) {
     74                fflush(log);
     75                fsync(fileno(log));
     76        }
    6277}
    6378
    6479int main(int argc, char *argv[])
    6580{
    66         size_t klog_pages = sysinfo_value("klog.pages");
     81        size_t klog_pages;
     82        if (sysinfo_get_value("klog.pages", &klog_pages) != EOK) {
     83                printf("%s: Error getting klog address\n", NAME);
     84                return -1;
     85        }
     86       
    6787        size_t klog_size = klog_pages * PAGE_SIZE;
    6888        klog_length = klog_size / sizeof(wchar_t);
     
    7090        klog = (wchar_t *) as_get_mappable_page(klog_size);
    7191        if (klog == NULL) {
    72                 printf(NAME ": Error allocating memory area\n");
     92                printf("%s: Error allocating memory area\n", NAME);
    7393                return -1;
    7494        }
     
    7797            klog_size, SERVICE_MEM_KLOG);
    7898        if (res != EOK) {
    79                 printf(NAME ": Error initializing memory area\n");
     99                printf("%s: Error initializing memory area\n", NAME);
    80100                return -1;
    81101        }
    82102       
    83103        if (event_subscribe(EVENT_KLOG, 0) != EOK) {
    84                 printf(NAME ": Error registering klog notifications\n");
     104                printf("%s: Error registering klog notifications\n", NAME);
    85105                return -1;
    86106        }
     107       
     108        /*
     109         * Mode "a" would be definitively much better here, but it is
     110         * not well supported by the FAT driver.
     111         *
     112         */
     113        log = fopen(LOG_FNAME, "w");
     114        if (log == NULL)
     115                printf("%s: Unable to create log file %s (%s)\n", NAME, LOG_FNAME,
     116                    str_error(errno));
    87117       
    88118        async_set_interrupt_received(interrupt_received);
Note: See TracChangeset for help on using the changeset viewer.