关于LDD3 setconsole.c Alesssandro Rubini 的邮件回复
http://blog.csdn.net/cinmyheart/article/details/38960967
关于 "setconsole.c" Alesssandro Rubini 的邮件回复
抱着试一试的心态给偶像写了一封求助e-mail,回复了!!!我的小心脏啊~
呵呵~Rubini是谁不解释了...
我的HELP原文主要的关于setconsole.c的问题,这个是LDD3的一个小程序
setconsole.c
- /*
- * setconsole.c -- choose a console to receive kernel messages
- *
- * Copyright (C) 1998,2000,2001 Alessandro Rubini
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
- */
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <errno.h>
- #include <unistd.h>
- #include <sys/ioctl.h>
- int main(int argc, char **argv)
- {
- char bytes[2] = {11,0}; /* 11 is the TIOCLINUX cmd number */
- if (argc==2) bytes[1] = atoi(argv[1]); /* the chosen console */
- else {
- fprintf(stderr, "%s: need a single arg\n",argv[0]); exit(1);
- }
- if (ioctl(STDIN_FILENO, TIOCLINUX, bytes)<0) { /* use stdin */
- fprintf(stderr,"%s: ioctl(stdin, TIOCLINUX): %s\n",
- argv[0], strerror(errno));
- exit(1);
- }
- exit(0);
- }
但是在虚拟控制台之间测试一直不成功,很纠结~
下面是Rubini 对我的回复:
首先指出了我的误区
1. ioctl(TIOCLINUX) 影响的并不是printf,而是printk!
2.tty 或者 terminal 不是console! 通过ctrl + alt + F* (1~6 )达到的都是控制台,F7是图形环境,不是console!
Allan Cruse 在2007年对setconsole做了一点改进
- //----------------------------------------------------------------
- // setconsole.cpp
- //
- // This utility allows a user possessing root privilege
- // to redirect 'printk' output to a designated console.
- //
- // compile using:
- // root# gcc -o setconsole setconsole.cpp
- // root# chmod a+s setconsole
- //
- // execute using:
- // user$ setconsole 4
- //
- // Code used here is from an example by Alesandro Rubini,
- // "Linux Device Drivers (2nd Edition)," pages 99-100.
- //
- // programmer: ALLAN CRUSE
- // written on: 24 NOV 2002
- // revised on: 24 JUN 2007 -- to use "/dev/console" device
- //----------------------------------------------------------------
- #include <fcntl.h> // for open() <--- added
- #include <stdio.h> // for fprintf()
- #include <errno.h> // for errno
- #include <stdlib.h> // for exit()
- #include <unistd.h> // for STDIN_FILENO
- #include <string.h> // for strerror()
- #include <sys/ioctl.h> // for ioctl()
- #include <asm/ioctls.h> // for TIOCLINUX
- int main( int argc, char **argv )
- {
- char bytes[ 2 ] = { 11, 0 }; // 11 is the TIOCLINUX command-number
- if ( argc == 2 ) bytes[1] = atoi( argv[1] ); // console id-number
- else {
- fprintf( stderr, "%s: need a single argument\n", argv[0] );
- exit(1);
- }
- int fd = open( "/dev/console", O_RDWR ); // <--- added
- if ( fd < 0 ) { perror( "/dev/console" ); exit(1); } // <--- added
- if ( ioctl( fd, TIOCLINUX, bytes ) < 0 ) // <--- changed
- {
- fprintf( stderr, "%s: ioctl( fd, TIOCLINUX ): %s\n", // <---
- argv[0], strerror( errno ) );
- exit(1);
- }
- exit(0);
- }
是可以在console之间重定向IO的!!
这幅图看到的是tty4,我把控制台的IO重定向到了console 3,也就是/dev/tty3
切换到tty2,我们插入hello.ko 模块,调用printk,打印hello world
我故意执行了tty这个shell程序,提示读者当前我们在tty2,进行insmod操作
明明是有hello world的为什么不打印呢?去哪儿了?console 3!
我们ctrl + alt + F3 切换到console 3看看
终于搞定了!利用ioctl实现了对于不同console之间的IO重定向!
最后谢谢偶像~ Alesssandro Rubini & Allan Cruse
关于LDD3 setconsole.c Alesssandro Rubini 的邮件回复相关推荐
- 解密:Gmail移动客户端自动邮件回复技术
雷锋网(公众号:雷锋网)按:本文作者NLP日月星辰,北京航空航天大学在读博士生,研究方向为 自然语言处理,深度学习. 深度学习已经在许多工业产品中取得应用.例如Jeff Dean(谷歌大脑负责人)在去 ...
- 工作中邮件回复10大注意事项
背景: 工作中经常需要回复邮件,但邮件回复的一些细节却没人注意,尤其初入职场的小白,简单整理了一下,感觉不管是什么岗位都能用得着: 1.邮件内容最好不要超出一屏: (这样是为了容易看,一眼就能看完所有 ...
- Valine - 自定义邮件回复提示
前言 前面一篇文章主要写了: Valine - 一款快速.简洁且高效的无后端评论系统 在Hexo(sakura)主题中引入valine评论系统以及魔改diy样式! 插曲:根据cndrew的提醒,这里修 ...
- WordPress知更鸟(Begin)主题评论邮件回复失效的解决办法
小任还不容易搞定了腾讯云这个坑人的安全组,实现了smtp的方式发邮件,具体文章:WordPress腾讯云服务器SMTP不能发邮件的解决办法,但是经过了测试发现,这个对于评论邮件回复居然没有用,但是有新 ...
- 外企邮件回复模板_电子邮件回复模板
外企邮件回复模板 If you frequently type the same responses to email questions, you can use an email response ...
- 关于《强化狼群等级制度的灰狼优化算法》的问题邮件回复
声明: 自己当初在看到该文章的时候就抱着试试的态度,给作者发了 邮件,不过 会回复的那么快,而且每个问题都做说明,很是惊喜,还开心,之前就一直收藏在邮箱里,这两天重新翻阅,越发觉得应该贴出来.再次谢谢 ...
- 关于MetaAPI问题CSDN给的邮件回复
在设置office发送博文功能时,发现csdn的MetaAPI功能不能用了. 随手给csdn的服务邮箱发一封邮件,没想到csdn给回复了态度还很诚恳,赞一个! -------------------- ...
- 微软 Exchange 服务器被滥用于内部邮件回复链攻击
聚焦源代码安全,网罗国内外最新资讯! 编译:代码卫士 摘要 威胁行动者正在利用 ProxyShell 和 ProxyLogon exploit 分发恶意软件并利用被盗的内部回复链邮件绕过检测. 分发 ...
- php邮件回复功能,用PHP回复邮件(Laravel Mailgun)
我有一个使用电子邮件创建记录的应用程序 . 用户向某个地址发送电子邮件(例如:create@example.com),Mailgun获取邮件,解析邮件并向我的应用程序中的某个脚本发送POST请求(PO ...
最新文章
- React 万能的函数表达式
- Express中间件工作原理介绍
- [silverlight]WCF和Web Service(ASMX)的soap header传输方法
- 支持向量机器—SMO算法
- windows2003 apache php mysql_Windows 2003搭建Apache PHP MySQL环境经验分享
- 阿里P8成长路线!我的头条面试经历分享,吊打面试官系列!
- (JAVA)Map集合
- html5硬件接口,HTML5通用接口详解
- python获取某天的属于第几周等时间问题
- 惊 腾讯云、阿里云服务器无需备案配置域名访问方法
- Spring复习——B站
- python 操作word教程_Python 使用 win32com 模块对word文件进行操作
- JavaSE——IO流
- 传统民俗闹新春 浙江千年古村飘“非遗年味”
- 如何找大量微信群?有没有找微信群的小程序?
- 量子逻辑电路的初步探索
- 计算机怎么让两个用户独立,两个显示屏如何用同一个电脑_一台主机两个显示器独立工作-win7之家...
- Ubuntu 20.04修改ip地址(Netplan)
- emd_visu函数_visu
- 社区项目分享 | 用 Jina 搭建一个电影推荐系统
热门文章
- 皮一皮:这才是书法的最高境界...
- 皮一皮:这是。。。养了个白眼狼???
- 每日一皮:这就是成都马拉松???...
- Mybatis 强大的结果映射器ResultMap
- 找条朋友圈手都刷断了,原来是没有掌握正确的使用姿势...
- 死磕Java并发:J.U.C之重入锁:ReentrantLock
- 一文让你秒懂AQS,附带源码剖析!
- 注册界面翻译_B站UP主自制的开源OCR翻译器走红Github,用一次就粉了
- 【SpringCloud】Feigin-实例
- module ‘open3d‘ has no attribute ‘PointCloud‘