免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12下一页
最近访问板块 发新帖
查看: 6639 | 回复: 11
打印 上一主题 下一主题

LDD3中的setlevel.c程序的问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-04-24 17:29 |只看该作者 |倒序浏览
在ldd3中的源码包里面,有一个改变console_loglevel的程序,为什么编译通不过呢?

  1. 1
  2. 2 #include <stdio.h>
  3. 3 #include <stdlib.h>
  4. 4 #include <string.h>
  5. 5#include <errno.h>
  6. 6 #define __LIBRARY__ /* _syscall3 and friends are only available through this */
  7. 27 #include <linux/unistd.h>
  8. 28
  9. 29 /* define the system call, to override the library function */
  10. 30 _syscall3(int, syslog, int, type, char *, bufp, int, len);
  11. 31
  12. 32 int main(int argc, char **argv)
  13. 33 {
  14. 34     int level;
  15. 35
  16. 36     if (argc==2) {
  17. 37     level = atoi(argv[1]); /* the chosen console */
  18. 38     } else {
  19. 39         fprintf(stderr, "%s: need a single arg\n",argv[0]); exit(1);
  20. 40     }
  21. 41     if (syslog(8,NULL,level) < 0) {
  22. 42         fprintf(stderr,"%s: syslog(setlevel): %s\n",
  23. 43                 argv[0],strerror(errno));
  24. 44         exit(1);
  25. 45     }
  26. 46     exit(0);
  27. 47 }
复制代码

gcc setlevel.后,错误如下:
setlevel.c:30: error: expected declaration specifiers or ‘...’ before ‘syslog’
setlevel.c:30: error: expected declaration specifiers or ‘...’ before ‘type’
setlevel.c:30: error: expected declaration specifiers or ‘...’ before ‘bufp’
setlevel.c:30: error: expected declaration specifiers or ‘...’ before ‘len’
setlevel.c:30: warning: data definition has no type or storage class

论坛徽章:
3
金牛座
日期:2014-06-14 22:04:062015年辞旧岁徽章
日期:2015-03-03 16:54:152015年迎新春徽章
日期:2015-03-04 09:49:45
2 [报告]
发表于 2009-04-24 17:39 |只看该作者

回复 #1 szjrabbit 的帖子

你这第30行感觉也没有被调用啊

论坛徽章:
3
金牛座
日期:2014-06-14 22:04:062015年辞旧岁徽章
日期:2015-03-03 16:54:152015年迎新春徽章
日期:2015-03-04 09:49:45
3 [报告]
发表于 2009-04-24 17:45 |只看该作者
主要的问题是_syscall3(int, syslog, int, type, char *, bufp, int, len);没有返回值,编译器把他看作是一个函数原型的声明。

论坛徽章:
36
IT运维版块每日发帖之星
日期:2016-04-10 06:20:00IT运维版块每日发帖之星
日期:2016-04-16 06:20:0015-16赛季CBA联赛之广东
日期:2016-04-16 19:59:32IT运维版块每日发帖之星
日期:2016-04-18 06:20:00IT运维版块每日发帖之星
日期:2016-04-19 06:20:00每日论坛发贴之星
日期:2016-04-19 06:20:00IT运维版块每日发帖之星
日期:2016-04-25 06:20:00IT运维版块每日发帖之星
日期:2016-05-06 06:20:00IT运维版块每日发帖之星
日期:2016-05-08 06:20:00IT运维版块每日发帖之星
日期:2016-05-13 06:20:00IT运维版块每日发帖之星
日期:2016-05-28 06:20:00每日论坛发贴之星
日期:2016-05-28 06:20:00
4 [报告]
发表于 2009-04-24 18:01 |只看该作者
应该是你用的内核版本的问题,LZ 的内核版本是多少?

论坛徽章:
0
5 [报告]
发表于 2009-04-24 18:24 |只看该作者

回复 #4 Godbach 的帖子

2.6.24-23-386

论坛徽章:
0
6 [报告]
发表于 2009-04-24 18:26 |只看该作者

回复 #2 dreamice 的帖子

我也不太清楚,ldd中的源代码就是这么写的。我不太清楚_syscall3(int, syslog, int, type, char *, bufp, int, len);
和syslog(8,NULL,level)的关系

论坛徽章:
36
IT运维版块每日发帖之星
日期:2016-04-10 06:20:00IT运维版块每日发帖之星
日期:2016-04-16 06:20:0015-16赛季CBA联赛之广东
日期:2016-04-16 19:59:32IT运维版块每日发帖之星
日期:2016-04-18 06:20:00IT运维版块每日发帖之星
日期:2016-04-19 06:20:00每日论坛发贴之星
日期:2016-04-19 06:20:00IT运维版块每日发帖之星
日期:2016-04-25 06:20:00IT运维版块每日发帖之星
日期:2016-05-06 06:20:00IT运维版块每日发帖之星
日期:2016-05-08 06:20:00IT运维版块每日发帖之星
日期:2016-05-13 06:20:00IT运维版块每日发帖之星
日期:2016-05-28 06:20:00每日论坛发贴之星
日期:2016-05-28 06:20:00
7 [报告]
发表于 2009-04-24 18:57 |只看该作者
原帖由 szjrabbit 于 2009-4-24 18:26 发表
我也不太清楚,ldd中的源代码就是这么写的。我不太清楚_syscall3(int, syslog, int, type, char *, bufp, int, len);
和syslog(8,NULL,level)的关系

LDD3提供的源码是在2.6.10上运行的。2.6版本的子版本之间变化可能比较大,我用2.6.18编译这个程序也报错。LZ 尝试修改一下这个程序,以适应适应你的内核,正好也算练练手。

论坛徽章:
0
8 [报告]
发表于 2009-04-25 15:03 |只看该作者
找到解决方法:

  1. 1
  2. 2 #include <stdio.h>
  3. 3 #include <stdlib.h>
  4. 4 #include <string.h>
  5. 5#include <errno.h>
  6. 6#include <sys/syscall.h>
  7. 27 #include <linux/unistd.h>
  8. 28
  9. 29int syslog(int type,char *bufp,int len)
  10. 30 {
  11. 31     long __res;
  12. 32     __asm__ volatile ("int $0x80":"=a"(__res):"0"(103),"b"((long)(type)),"c"    ((long)(bufp)),"d"((long)(len)));
  13. 33
  14. 34     if ((unsigned long)(__res) >= (unsigned long)(-125)){
  15. 35         errno = -(__res);
  16. 36         __res = -1;
  17. 37     }
  18. 38     return (int)(__res);
  19. 39 }

  20. 40
  21. 41 int main(int argc, char **argv)
  22. 42 {
  23. 43     int level;
  24. 44
  25. 45     if (argc==2) {
  26. 46     level = atoi(argv[1]); /* the chosen console */
  27. 47     } else {
  28. 48        fprintf(stderr, "%s: need a single arg\n",argv[0]); exit(1);
  29. 49     }
  30. 50     if (syslog(8,NULL,level) < 0) {
  31. 52                 argv[0],strerror(errno));
  32. 53        exit(1);
  33. 54     }
  34. 55     exit(0);
  35. 56 }
复制代码

评分

参与人数 1可用积分 +15 收起 理由
dreamice + 15 我很赞同

查看全部评分

论坛徽章:
3
金牛座
日期:2014-06-14 22:04:062015年辞旧岁徽章
日期:2015-03-03 16:54:152015年迎新春徽章
日期:2015-03-04 09:49:45
9 [报告]
发表于 2009-04-25 19:59 |只看该作者
感谢分享解决方法

论坛徽章:
36
IT运维版块每日发帖之星
日期:2016-04-10 06:20:00IT运维版块每日发帖之星
日期:2016-04-16 06:20:0015-16赛季CBA联赛之广东
日期:2016-04-16 19:59:32IT运维版块每日发帖之星
日期:2016-04-18 06:20:00IT运维版块每日发帖之星
日期:2016-04-19 06:20:00每日论坛发贴之星
日期:2016-04-19 06:20:00IT运维版块每日发帖之星
日期:2016-04-25 06:20:00IT运维版块每日发帖之星
日期:2016-05-06 06:20:00IT运维版块每日发帖之星
日期:2016-05-08 06:20:00IT运维版块每日发帖之星
日期:2016-05-13 06:20:00IT运维版块每日发帖之星
日期:2016-05-28 06:20:00每日论坛发贴之星
日期:2016-05-28 06:20:00
10 [报告]
发表于 2009-04-25 23:56 |只看该作者
感谢分享啊。这样学习的收获更大。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP