免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
楼主: linuxer_lhw
打印 上一主题 下一主题

如何在伪终端(通过ssh远程登录)显示内核打印信息 [复制链接]

论坛徽章:
0
21 [报告]
发表于 2010-07-14 15:48 |只看该作者
回复 20# Godbach


    那是应该的。

本来我是直接调用系统调用的,但不知为何加载时链接不到sys_open符号,所以用filp_open等方法了,用USE_SYS_CALL来区分两种方法。

论坛徽章:
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
22 [报告]
发表于 2010-07-14 15:53 |只看该作者
用filp_open挺好的。

论坛徽章:
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
23 [报告]
发表于 2010-07-14 15:54 |只看该作者
改过后的这块代码为:
  1. static void write_msg(struct console *con, const char *msg, unsigned int len)
  2. {
  3. #if USE_SYS_CALL
  4.         unsigned long flags;
  5.         mm_segment_t old_fs;
  6.                
  7. //        local_irq_save(flags);
  8.         old_fs = get_fs();
  9.         set_fs(KERNEL_DS);
  10.         sys_write(np.pty_fd, msg, len);
  11.         set_fs(old_fs);
  12.        
  13. //        local_irq_restore(flags);       
  14. #else
  15.         unsigned long flags;
  16.         ssize_t ret = -EBADF;
  17.         mm_segment_t old_fs;
  18.                
  19.         if (np.pty_file) {
  20.                 local_irq_save(flags);
  21.                
  22.                 old_fs = get_fs();
  23.                 set_fs(KERNEL_DS);
  24.                        
  25.                 loff_t pos = np.pty_file->f_pos;
  26.                 ret = vfs_write(np.pty_file, msg, len, &pos);
  27.                 np.pty_file->f_pos = pos;
  28.                
  29.                 set_fs(old_fs);
  30.                
  31. //                local_irq_restore(flags);
  32.         }
  33. #endif
  34. }
复制代码
加载模块情况为
[root@localhost ~]# ptyfile:/dev/pts/2
np.pty_file:d59e3780
open file: 0
BUG: sleeping function called from invalid context at include/asm/uaccess_32.h:512
in_atomic():0, irqs_disabled():1
Pid: 6590, comm: insmod Not tainted 2.6.24.4 #2
[<c01259f8>] __might_sleep+0xa4/0xa9
[<c01ec615>] copy_from_user+0x2d/0x60
[<c02284a7>] tty_write+0x132/0x1c7
[<c022c585>] write_chan+0x0/0x1b3
[<c017389a>] vfs_write+0xac/0x12c
[<e0a0a04a>] write_msg+0x4a/0x6f [ptyconsole]
[<e0a0a000>] write_msg+0x0/0x6f [ptyconsole]
[<c01289ba>] __call_console_drivers+0x51/0x5b
[<c0128ad7>] call_console_drivers+0xb2/0xd4
[<c01290f4>] release_console_sem+0x70/0xb0
[<e0a0a126>] init_ptyconsole+0x40/0x54 [ptyconsole]
[<c01461df>] sys_init_module+0x91/0x11b
[<c0104dc6>] sysenter_past_esp+0x5f/0x85
=======================
ptyconsole: network logging started

论坛徽章:
0
24 [报告]
发表于 2010-07-14 15:56 |只看该作者
本帖最后由 lmarsin 于 2010-07-14 15:57 编辑

回复 23# Godbach


    好像你还漏改了一个地方,你贴代码的20行

论坛徽章:
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
25 [报告]
发表于 2010-07-14 16:01 |只看该作者
回复 24# lmarsin
惭愧,这个关键的地方漏掉了。

论坛徽章:
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
26 [报告]
发表于 2010-07-14 16:03 |只看该作者
改了之后,好像还和前面的信息一样:
[root@localhost ~]# ptyfile:/dev/pts/2
np.pty_file:c6d48b40
open file: 0
BUG: sleeping function called from invalid context at include/asm/uaccess_32.h:512
in_atomic():0, irqs_disabled():1
Pid: 7481, comm: insmod Not tainted 2.6.24.4 #2
[<c01259f8>] __might_sleep+0xa4/0xa9
[<c01ec615>] copy_from_user+0x2d/0x60
[<c02284a7>] tty_write+0x132/0x1c7
[<c022c585>] write_chan+0x0/0x1b3
[<c017389a>] vfs_write+0xac/0x12c
[<e0a2a041>] write_msg+0x41/0x66 [ptyconsole]
[<e0a2a000>] write_msg+0x0/0x66 [ptyconsole]
[<c01289ba>] __call_console_drivers+0x51/0x5b
[<c0128ad7>] call_console_drivers+0xb2/0xd4
[<c01290f4>] release_console_sem+0x70/0xb0
[<e0a2a11d>] init_ptyconsole+0x40/0x54 [ptyconsole]
[<c01461df>] sys_init_module+0x91/0x11b
[<c0104dc6>] sysenter_past_esp+0x5f/0x85
=======================
ptyconsole: network logging started

论坛徽章:
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
27 [报告]
发表于 2010-07-14 16:04 |只看该作者
我这里设置USE_SYS_CALL为1的,编译时也提示sys_open和sys_write的问题

论坛徽章:
0
28 [报告]
发表于 2010-07-14 16:06 |只看该作者
我这边只提示sys_open

论坛徽章:
0
29 [报告]
发表于 2010-07-14 18:02 |只看该作者
回复 26# Godbach


    系统会挂掉吗?

论坛徽章:
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
30 [报告]
发表于 2010-07-14 18:39 |只看该作者
系统不会挂掉。就是报错的信息还是一样的。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP