|
发表于 2006-4-18 17:20:30
|
显示全部楼层
/*************---printk.c-----**********/
/*
**desp:将提示信息输出到当前用户的终端tty,使用telnet or ssh连接的用户将会看到
*在当前终端输出的提示信息
*/
#include <linux/kernel.h>
#include <linux/module.h>
#ifdef CONFIG_MODULEVERSIONS
#define MODULEVERSIONS
#include <linux/moduleversions>
#endif
MODULE_LICENSE("GPL");
MODULE_AUTHOR("duanjigang");
#include <linux/sched.h>/*For current*/
#include <linux/tty.h> /*For tty declarations*/
void print_string(char *str)
{
struct tty_struct * my_tty;
/*获得当前进程的tty,写到标准输出*/
my_tty = current->tty;
if(my_tty != NULL)
{
(*(my_tty->driver).write)(my_tty, 0 ,str, strlen(str));
(*(my_tty->driver).write)(my_tty, 0 ,"\015\012", 2);
}
}
int init_module()
{
print_string("module inserted!");
return 0;
}
void cleanup_module()
{
print_string("module cleaned!");
}
Makefile
#Author: duanjigang <duanjigang1983@126.com> <duanjigang@hotmail.com>
#Date: 2006-3-19
CC=cc
CFLAG := -Wall -DMODULE -D__KERNEL__ -DLINUX
printk.o:printk.c /usr/include/linux/version.h
$(CC) $(CFLAG) -c printk.c -I /usr/src/linux-2.4.20-8/include
install:
insmod printk.o
clean:
rm -f *.o |
|