/* Copyright 2006 Varun Marupadi * varun [dot] marupadi [at] gmail [dot] com * Unless mentioned otherwise below, this and * all programs I write are distributed under the * terms of the GNU General Public License version * 2 only */ /* * force_printk: routine to push output directly to * the screen: useful for quick debugging of kernel hacks. * Originally written for use in the CPS196 Systems and * Networks class in the Computer Science Department at Duke * University, Durham, NC in the Spring of 2006. * This file is released by the author into the PUBLIC DOMAIN */ #include #include #include /* * Get as input the same parameters as printk(), write the * formatted output directly to the console of the current * process. String length limited to 1Kbytes. Return -1 on * error. */ int force_printk(char *format, ...) { struct tty_struct *current_tty; va_list args; char out_string[1024]; va_start(args, format); vsnprintf(out_string, sizeof(out_string), format, args); va_end(args); current_tty = current->signal->tty; if (current_tty == NULL) return -1; ((current_tty->driver)->write) (current_tty, out_string, strlen(out_string)); ((current_tty->driver)->write) (current_tty, "\r\n", 2); return 0; }