root/kernel/printk.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. sys_syslog
  2. printk

   1 /*
   2  *  linux/kernel/printk.c
   3  *
   4  *  Copyright (C) 1991, 1992  Linus Torvalds
   5  */
   6 
   7 #include <stdarg.h>
   8 
   9 #include <asm/segment.h>
  10 #include <asm/system.h>
  11 
  12 #include <linux/errno.h>
  13 #include <linux/sched.h>
  14 #include <linux/kernel.h>
  15 
  16 static char buf[1024];
  17 
  18 extern int vsprintf(char * buf, const char * fmt, va_list args);
  19 extern void console_print(const char *);
  20 
  21 static unsigned long log_page = 0;
  22 static unsigned long log_start = 0;
  23 static unsigned long log_size = 0;
  24 static struct wait_queue * log_wait = NULL;
  25 
  26 int sys_syslog(int type, char * buf, int len)
     /* [previous][next][first][last][top][bottom][index][help] */
  27 {
  28         unsigned long i;
  29         char c;
  30 
  31         if (!suser())
  32                 return -EPERM;
  33         switch (type) {
  34                 case 0:
  35                         i = log_page;
  36                         log_page = 0;
  37                         free_page(i);
  38                         wake_up(&log_wait);
  39                         return 0;
  40                 case 1:
  41                         i = get_free_page(GFP_KERNEL);
  42                         if (log_page) {
  43                                 free_page(i);
  44                                 return 0;
  45                         } else if (log_page = i) {
  46                                 log_start = log_size = 0;
  47                                 return 0;
  48                         }
  49                         return -ENOMEM;
  50                 case 2:
  51                         if (!buf || len < 0)
  52                                 return -EINVAL;
  53                         if (!len)
  54                                 return 0;
  55                         verify_area(buf,len);
  56                         while (!log_size) {
  57                                 if (!log_page)
  58                                         return -EIO;
  59                                 if (current->signal & ~current->blocked)
  60                                         return -ERESTARTSYS;
  61                                 cli();
  62                                 if (!log_size)
  63                                         interruptible_sleep_on(&log_wait);
  64                                 sti();
  65                         }
  66                         i = 0;
  67                         while (log_size && len) {
  68                                 c = *((char *) log_page+log_start);
  69                                 log_start++;
  70                                 log_size--;
  71                                 log_start &= 4095;
  72                                 put_fs_byte(c,buf);
  73                                 buf++;
  74                                 i++;
  75                         }
  76                         return i;
  77         }
  78         return -EINVAL;
  79 }
  80                         
  81 
  82 int printk(const char *fmt, ...)
     /* [previous][next][first][last][top][bottom][index][help] */
  83 {
  84         va_list args;
  85         int i,j;
  86         char * p;
  87 
  88         va_start(args, fmt);
  89         i=vsprintf(buf,fmt,args);
  90         va_end(args);
  91         for (j = 0; j < i && log_page ; j++) {
  92                 p = (char *) log_page + (4095 & (log_start+log_size));
  93                 *p = buf[j];
  94                 if (log_size < 4096)
  95                         log_size++;
  96                 else
  97                         log_start++;
  98         }
  99         if (log_page)
 100                 wake_up(&log_wait);
 101         console_print(buf);
 102         return i;
 103 }

/* [previous][next][first][last][top][bottom][index][help] */