这个程序是用来修改console_level值的程序。
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <sys/syscall.h> /*需要加上这个头文件,否则编译不能通过*/
#define __syscall_return(type, res) \
do { \
if ((unsigned long)(res) >= (unsigned long)(-125)) { \
errno = -(res); \
res = -1; \
} \
return (type) (res); \
} while (0)
#define _syscall3(type,name,type1,arg1,type2,arg2,type3,arg3) \
type name(type1 arg1,type2 arg2,type3 arg3) \
{ \
long __res; \
__asm__ volatile ("int $0x80" \
: "=a" (__res) \
: "0" (__NR_##name),"b" ((long)(arg1)),"c" ((long)(arg2)), \
"d" ((long)(arg3))); \
__syscall_return(type,__res); \
}
_syscall3(int,syslog, int,type, char *,bufp, int,len);
int main(int argc, char **argv)
{
int level;
if (argc==2) {
level = atoi(argv[1]); /* the chosen console */
} else {
fprintf(stderr, "%s: need a single arg\n",argv[0]); exit(1);
}
if (syslog(8,NULL,level) < 0) {
fprintf(stderr,"%s: syslog(setlevel): %s\n",
argv[0],strerror(errno));
exit(1);
}
exit(0);
}
我这个程序写入后,命名为setlevel.c文件,然后用gcc –o setlevel setlevel.c编译
却得出一下错误:
Setlevel.c: 在函数’syslog’中:
Setlevel.c:27:错误:expected ‘)’ before ‘:’ token
不知什么意思。令我的内核是linux 2.6.20-15-generic。《linux设备驱动程序设计》(第三版)提供的程序不能在这个内核编译成功,故加了段代码。
修改console_level值得程序不成功 高手指点
-
- 帖子: 4
- 注册时间: 2007-05-08 10:10