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

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