博客首页
注册
建议与交流
排行榜
加入友情链接
推荐
投诉
搜索:
帮助
超越无限的博客
做好你想做的--其它的都不重要。。。
lidaibin.cublog.cn
管理博客
发表文章
留言
收藏夹
· 朋友
博客圈
音乐
相册
· 屏幕截图
文章
· linux
}
· gentoo
· asm
· c/c++
· python
· 生活随笔
首页
关于作者
姓名:李代斌 职业:程序员 年龄:27 位置:陕西西安 个性介绍:心比天高
||
<<
>>
||
我的分类
最新照片
上一张
下一张
幻灯片
停止播放
最新文章
·
gedit自动识别文件编码
·
linux下安装ie6sp1和QQ
·
gentoo下lxr的配置
·
linux下安装msoffice的几..
·
关于swing程序无法使用GT..
·
在Gentoo上构建windows交..
·
汇编学习之系统调用
·
iptables端口映射
·
关于inotify
·
rs422在linux下跟我开了个..
最新留言
·
hardnature
问题已解决,thank you al..
·
hardnature
我WINE出来的QQ为什么没有..
·
本站网友
忘了联系方式:280220297
·
本站网友
我也是西安的欢迎交流
·
7dehao
今天才看见李兄的留言,不..
最新评论
·
李总~ 给点儿详细的呗,..
·
你好,我也刚用inotify + ..
·
这个方法很正确,因为有的..
·
谢谢,我也刚好遇到这个问..
·
我WINE出来的QQ为什么没有..
最新收藏
·
我的主页
·
我的blogger
·
我的LiveJournal
·
hellwolf的blog
·
zhllg的blog
·
小锁的blog
统计信息
·
总访问量:80642
·
文章个数:37
·
评论条数:11
·
留言条数:7
·
网友推荐:
【置顶】搜索我的博客
<!-- Google CSE Search Box Begins  --> <form id="searchbox_000830355677282745957:3xzoiezzul4" action="http://www.google.com/search"> <input name="cx" value="000830355677282745957:3xzoiezzul4" type="hidden"> <input name="cof" value="FORID:0" type="hidden"> 搜索我的博客:<input name="q" size="40" type="text"> <input name="sa" value="搜索" type="submit"> </form> <script type="text/javascript" src="http://www.google.com/coop/cse/brand?form=searchbox_000830355677282745957%3A3xzoiezzul4"></script><!-- Google CSE Search Box Ends -->
查看全文
发表于:2007-03-25 ┆
阅读(1020)
┆
评论(0)
gedit自动识别文件编码
gedit默认只能UTF-8编码的文件,通过gconf可以设置其编码检测的编码列表,以达到自动识别编码的效果。<br><br>gconftool-2 --set --type=list --list-type=string /apps/gedit-2/preferences/encodings/auto_detected "[UTF-8,CURRENT,GBK,BIG5-HKSCS,UTF-16]"<br>
查看全文
发表于:2008-06-02 ┆
阅读(636)
┆
评论(1)
linux下安装ie6sp1和QQ
1、利用ies4linux安装ie6sp1,将${HOME}/.ies4linux/ie6放到${HOME}下并改为.wine,ies4linux安装ie并设置wine模拟的默认windows版本是98,由于QQ需要windows 2000以上的版本,因此最好将默认windows版本设置为xp,安装完QQ之后再改回98。<br><br>2、设置字体,运行regedit,将HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows NT\\CurrentVersion\\FontSubstitutes中的所有键值都改为SimSun,另外再增加FixedSys、System、Tahoma,值均为SimSun。或者将下面内容保存成zh.reg,regedit zh.reg导入即可。<br>REGEDIT4<br><br>[HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\FontSubstitutes]<br>"Arial"="SimSun"<br>"Arial CE,238"="SimSun"<br>"Arial CYR,204"="SimSun"<br>"Arial Greek,161"="SimSun"<br>"Arial TUR,162"="SimSun"<br>"Courier New"="SimSun"<br>"Courier New CE,238"="SimSun"<br>"Courier New CYR,204"="SimSun"<br>"Courier New Greek,161"="SimSun"<br>"Courier New TUR,162"="SimSun"<br>"FixedSys"="SimSun"<br>"Helv"="SimSun"<br>"Helvetica"="SimSun"<br>"MS Sans Serif"="SimSun"<br>"MS Shell Dlg"="SimSun"<br>"MS Shell Dlg 2"="SimSun"<br>"System"="SimSun"<br>"Tahoma"="SimSun"<br>"Times"="SimSun"<br>"Times New Roman CE,238"="SimSun"<br>"Times New Roman CYR,204"="SimSun"<br>"Times New Roman Greek,161"="SimSun"<br>"Times New Roman TUR,162"="SimSun"<br>"Tms Rmn"="SimSun"<br><br>3、安装腾迅官方QQ 2005 English Version,不要安装中文版,中文版乱七八糟的东西太多wine模拟起来不稳定。安装完之后删除QQ目录里的TIMPlatform.exe,这个文件据说是会检查键盘加密控件的。另外可选地可以删除QQexternal.exe、Dat/ad.gif、Dat/default_av_chatroom.gif、Dat/infoad.gif、Dat/vqqad.gif,这些是与广告相关的文件,可以删除!<br><br>4、运行winecfg,添加QQ.exe应用程序,将windows版本设置为windows xp,Libraries中设置riched20和riched32为(native, builtin),另外就是rpcrt4(builtin, native)和msxml3(builtin, native),前面的两个库是为了解决QQ聊天窗口输入乱码的现象,后面两个库是为了解决qzone浏览的问题。<br><br>5、如果需要使用招商银行大众版,可以到其网站上下载ActiveX控件安装包safeeditinstall.exe,暂时将默认windows版本改为98安装完之后再改回来就可以用了。<br><br>6、有时候中文无论你如何设置某些软件界面上总有地方并不是你想要的字体,经常会默认为“华文彩云”或者其它字体,你可以给windows/fonts目录下做一个符号链接,将你喜欢的字体链接为cour.ttf,或者cp过去都行。<br><br>基本上就这几个步骤就搞定了,下面是我的两张截图,可以看看效果^_^。<br><br><br><a href="http://lidaibin.googlepages.com/screenshot-qq.png"><img src="http://lidaibin.googlepages.com/screenshot-qq.png" height="200" width="320"></a> <a href="http://lidaibin.googlepages.com/screenshot-cmbchina.png"><img src="http://lidaibin.googlepages.com/screenshot-cmbchina.png" height="200" width="320"></a>
查看全文
发表于:2008-05-09 ┆
阅读(1293)
┆
评论(1)
gentoo下lxr的配置
lxr是一个基于web的源代码交叉索引工具,用来阅读源代码非常方便,但lxr的配置确实很痛苦,今天在gentoo下配置lxr费了点周折,不过总算是成功了,现记录一下配置过程,以防下次配置再走弯路!以pidgin-2.4.1为例。<br><br><span style="font-weight: bold;">1、安装</span><br>gentoo下安装lxr很简单,直接emerge即可,不过要注意的是lxr是采用perl语言写的,要求perl和libperl安装的时候加上ithreads这个USE Flag,另外需要emerge apache mod_perl mysql,索引工具采用glimpse则emerge glimpse,如果要采用swish-e就USE=freetext emerge lxr即可。<br><br style="font-weight: bold;"><span style="font-weight: bold;">2、准备源码目录</span><br>在我机器上,/data/codes/other是用来存放第三方我需要阅读的项目,配置lxr先在/data/codes/other目录下创建了pidgin并将pidgin解压至pidgin目录改名为2.4.1,在/data/codes/others/pidgin目录下创建versions文件,写入2.4.1。<br><br style="font-weight: bold;"><span style="font-weight: bold;">3、准备数据库</span><br>执行mysql -u root < /usr/share/webapps/lxr/0.9.5/sqlscripts/mysql/0.9.5_create.sql创建一个lxr库,然后将/var/lib/mysql/lxr库名改为pidgin。如果要添加别的项目再做类似的工作即可。<br><br><span style="font-weight: bold;">4、配置lxr</span><br>首先配置你的apache,生成默认的web目录,emerge --config =www-servers/apache-x.x.x,然后修改/etc/conf.d/apache,给APACHE2_OPTS加上"-D PERL"选项,重启apache即可。然后执行cp -pr /usr/share/webapps/lxr/0.9.5/htdocs /var/www/localhost/htdocs/pidgin,如果要添加另一个项目重复此cp操作,重要的就是配置lxr.conf,上传了一个<a href="http://lidaibin.googlepages.com/lxr.conf" target="_blank">pidgin的lxr.conf</a>可以参考。<br><br><span style="font-weight: bold;">5、生成索引</span><br>进入/var/www/localhost/htdocs/pidgin,ln -snf /data/codes/other/pidgin/lxr.conf然后执行./genxref --url=http://localhost/pidgin即可生成索引,(对了,到这儿你会发现操作mysql数据库时会报错,是因为lxr建的lxr_releases表里的release字段与mysql的关键字冲突,需要修改一下/usr/lib/perl5/vendor_perl/5.8.8/LXR/Index/Mysql.pm文件,将其中的sql语句中的release字段都加上``变成`release`)现在基本上可以访问了。<br>
查看全文
发表于:2008-04-11 ┆
阅读(563)
┆
评论(0)
linux下安装msoffice的几个注意事项
首先,我是一个铁杆的linux迷,也非常支持开源产品,但是我还是在我日常工作的笔记本装上了msoffice,原因很简单,OOo或者goffice系列均无法让我很高效地完成文档写作需求。工作的内容主要是程序开发,一般开发文档采用docbook或者gtk-doc之类的方式,但还有一部分工作是经常需要给客户编写需求文档、解决方案以及或者其它类似文档,经常需要在文档里提供网络结构图以及流程图等等,dia无疑是linux下gnome桌面环境的首选产品,当然dia也完全可以胜任这样的工作,但是与visio相比dia缺乏炫丽的图形元素,总是难以达到理想的效果。另外就是字处理工具无法做到与msoffice完全兼容,虽然可以存取word文档,但无法做到版面级兼容。无奈之下退而求其次,利用crossover-office-pro-bin工具安装了msoffice。<br><br> 言归正传,crossover office是基于wine的一款商业产品,为linux下安装ms软件提供了简洁的方法,基本上不需要配置就能达到较好的效果,其实用wine安装msoffice也是非常方便的,只不过多少会比较麻烦一些,而且采用crossover office安装完msoffice之后自动生成mime数据,这是感觉比较贴心的功能。<br><br> 我的linux发行版是<a href="http://www.gentoo.org/" target="_blank">Gentoo Linux</a>, 安装crossover office professional非常方便,将所需文件放到你的${DISTFILES}目录直接emerge即可,我的locale环境是英文环境,LC_CTYPE是zh_CN.UTF-8,因此我所遇到的问题及解决办法不一定适用环境不同于我的朋友。用crossover office安装完msoffice 2003之后有几个问题需要注意,总结如下:<br><br>1、运行msoffice最好使用中文环境,将LANG设置为zh_CN.UTF-8(或者zh_CN.GBK等),如果你不希望改变系统的默认语言,也可以直接修改${HOME}/.cxoffice/win2000/desktopdata目录下cxassoc和cxmenu目录相应的脚本,在运行msoffice之前加上export LANG=zh_CN.UTF-8,也可以直接执行以下shell指令:for f in `find . -type f`; do grep "wine" $f 2>&1 >/dev/null && sed -i '2i\export LANG="zh_CN.UTF-8"' $f; done。<br><br>2、运行msoffice的时候你会发现你的菜单字体可能并不是你所期望的宋体,这个你可以通过修改${HOME}/.cxoffice/win2000/drive_c/windows/win.ini解决,给win.ini中加入以下两行即可:<br>[Desktop]<br>IconTitleFaceName=SimSun<br><br>3、如果你是UTF-8环境的话你可能发现msoffice运行起来非常慢,而且CPU占用率奇高,别着急,这是wine在从X核心字体中找GB2312字体造成的,你可以到你的中文字体目录中通过mkfontscale和mkfontdir生成fonts.scale和fonts.dir,不过这两个工具目前的版本似乎都不会生成GB2312和GBK的字体,你需要手工编辑fonts.dir和fonts.scale,手工加上GB2312和GBK的字体(不要害怕,你打开文件就知道怎么改了,复制一行改一下即可,假设你复制了GB18030.2000-0的字体,你可以将后面的GB18030.2000-0改成GB2312.1980-0和gbk-0),然后将该字体目录添加到xorg.conf的Files段即可,如我的xorg.conf文件中加入了FontPath "/usr/share/fonts/ms-fonts"。<br><br> 基本上到现在为止你的msoffice用起来应该会非常爽了,我这有几张截图可以先看看效果:<br><a href="http://lidaibin.googlepages.com/screenshot-word.png"><img src="http://lidaibin.googlepages.com/screenshot-word.png" height="200" width="320"></a> <a href="http://lidaibin.googlepages.com/screenshot-excel.png"><img src="http://lidaibin.googlepages.com/screenshot-excel.png" height="200" width="320"></a><br><br><a href="http://lidaibin.googlepages.com/screenshot-powerpoint.png"><img src="http://lidaibin.googlepages.com/screenshot-powerpoint.png" height="200" width="320"></a> <a href="http://lidaibin.googlepages.com/screenshot-visio.png"><img src="http://lidaibin.googlepages.com/screenshot-visio.png" height="200" width="320"></a><br><br><a href="http://lidaibin.googlepages.com/screenshot-cs.jpg"><img src="http://lidaibin.googlepages.com/screenshot-cs.jpg" height="400" width="640"></a><br>
查看全文
发表于:2008-03-06 ┆
阅读(804)
┆
评论(0)
关于swing程序无法使用GTK+外观样式的问题
在linux下使用swing(jre 1.6)程序的时候经常无法使用gtk+外观,无法享受gtk+原生的样式及字体渲染效果未免太可惜,而且jre的字体配置也够变态的,运行错误如下:<br><br>Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException<br> at com.sun.java.swing.plaf.gtk.GTKLookAndFeel.initSystemColorDefaults(GTKLookAndFeel.java:1267)<br> at com.sun.java.swing.plaf.gtk.GTKLookAndFeel.loadStyles(GTKLookAndFeel.java:1509)<br> at com.sun.java.swing.plaf.gtk.GTKLookAndFeel.access$000(GTKLookAndFeel.java:37)<br> at com.sun.java.swing.plaf.gtk.GTKLookAndFeel$WeakPCL$1.run(GTKLookAndFeel.java:1449)<br> at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)<br> at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)<br> at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)<br> at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)<br> at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)<br> at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)<br> at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)<br> at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)<br>Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException<br> at com.sun.java.swing.plaf.gtk.GTKLookAndFeel.initSystemColorDefaults(GTKLookAndFeel.java:1267)<br> at com.sun.java.swing.plaf.gtk.GTKLookAndFeel.loadStyles(GTKLookAndFeel.java:1509)<br> at com.sun.java.swing.plaf.gtk.GTKLookAndFeel.access$000(GTKLookAndFeel.java:37)<br> at com.sun.java.swing.plaf.gtk.GTKLookAndFeel$WeakPCL$1.run(GTKLookAndFeel.java:1449)<br> at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)<br> at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)<br> at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)<br> at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)<br> at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)<br> at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)<br> at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)<br> at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)<br>internal error: cannot create application: java.lang.NullPointerException:<br>javax.swing.MultiUIDefaults.getUIError(MultiUIDefaults.java:117)<br>javax.swing.UIDefaults.getUI(UIDefaults.java:741)<br>javax.swing.UIManager.getUI(UIManager.java:1012)<br>javax.swing.JPanel.updateUI(JPanel.java:109)<br>javax.swing.JPanel.<init>(JPanel.java:69)<br>javax.swing.JPanel.<init>(JPanel.java:92)<br>javax.swing.JPanel.<init>(JPanel.java:100)<br>javax.swing.JRootPane.createGlassPane(JRootPane.java:527)<br>javax.swing.JRootPane.<init>(JRootPane.java:347)<br>javax.swing.JFrame.createRootPane(JFrame.java:260)<br><br>原来这是与系统locale环境有关,将LC_CTYPE改为en_US.UTF-8就好了,用zh_CN.UTF-8就总是会报上面的错误!<br>
查看全文
发表于:2008-02-28 ┆
阅读(995)
┆
评论(1)
在Gentoo上构建windows交叉编译环境
最近公司开发一款跨平台的产品,主要支持的平台包括linux和windows,由于我的日常工作操作系统是linux,因此要调试windows部分代码极其不方便,要么在linux下安装一个虚拟机跑windows,要么双系统重启机器进入windows,总之是比较费时且麻烦。于是不安份的情绪让我折腾了一上午时间,终于成功地在我的Gentoo Linux上构建好了windows交叉编译环境。<br><br>其实在Gentoo Linux上构建交叉编译环境非常方便,crossdev一行命令就搞定一切,关于crossdev的用法很简单,可以参考Gentoo官方网站或者Gentoo-Wiki网站上的相关文档。构建windows交叉编译环境直接执行crossdev i686-mingw32即可。<br><br>构建好交叉编译环境之后可以写个hello world程序尝试一下,i686-mingw32-gcc -o test.exe test.c,然后file test.exe即可看到文件类型为“MS-DOS executable PE for MS Windows (console) Intel 80386 32-bit”,你也可以用wine test.exe执行一下看看结果。<br><br>似乎到此就圆满结束了?为了更方便地进行交叉编译,继续往下看吧。。。<br><br>开源软件大多数采用autotools来完成项目的自动构造,我们能不能利用autotools来方便地进行管理规模稍大的项目呢?答案是肯定的,今天上午为了测试交叉编译写了一个简单的win32 service,可以通过以下链接下载:<a href="http://lidaibin.googlepages.com/SMQService-1.0.2.tar.bz2" target="_blank">SMQService</a>,方便懒人们快速尝试交叉编译,不过你可能马上就会遇到挫折,来看看结果吧。<br><br>debianl@ldb /data/codes/test/win32service $ ./configure --target=i686-mingw32 --host=i686-mingw32 --build=i686-mingw32 --prefix=/usr/i686-mingw32/usr<br>checking for a BSD-compatible install... /usr/bin/install -c<br>checking whether build environment is sane... yes<br>checking for a thread-safe mkdir -p... /usr/bin/mkdir -p<br>checking for gawk... gawk<br>checking whether make sets $(MAKE)... yes<br>checking for i686-mingw32-gcc... i686-mingw32-gcc<br>checking for C compiler default output file name... a.exe<br>checking whether the C compiler works... configure: error: cannot run C compiled programs.<br>If you meant to cross compile, use `--host'.<br>See `config.log' for more details.<br><br>仔细看一下config.log即可看出configure会采用编译器编译一个测试程序并执行,在这儿会产生一个a.exe并直接执行,在linux直接执行exe文件如果不做点工作是不行的,直接执行a.exe报错configure也就停下了,告诉你"cannot run C compiled programs",其实compiler工作得好好的,那么我们现在只要解决直接在linux下运行exe文件就可以让autotools顺利地工作了。<br><br>其实要实现这个功能很简单,编译内核时注意选上Executable file formats->Kernel support for MISC binaries,如果编译成模块modprobe binfmt_misc即可加载,然后给你的/etc/fstab里加上一行“none /proc/sys/fs/binfmt_misc binfmt_misc defaults 0 0”,在系统引导完成之后执行"echo ':DOSWin:M::MZ::/usr/bin/wine:' > /proc/sys/fs/binfmt_misc/register",在Gentoo下可以将这行指令写到/etc/conf.d/local.start文件,现在再试应该就好了。<br><br>以下是我的编译日志:<br>debianl@ldb /data/codes/test/win32service $ ./configure --target=i686-mingw32 --host=i686-mingw32 --build=i686-mingw32 --prefix=/usr/i686-mingw32/usr<br>checking for a BSD-compatible install... /usr/bin/install -c<br>checking whether build environment is sane... yes<br>checking for a thread-safe mkdir -p... /usr/bin/mkdir -p<br>checking for gawk... gawk<br>checking whether make sets $(MAKE)... yes<br>checking for style of include used by make... GNU<br>checking for i686-mingw32-gcc... i686-mingw32-gcc<br>checking for C compiler default output file name... a.exe<br>checking whether the C compiler works... yes<br>checking whether we are cross compiling... no<br>checking for suffix of executables... .exe<br>checking for suffix of object files... o<br>checking whether we are using the GNU C compiler... yes<br>checking whether i686-mingw32-gcc accepts -g... yes<br>checking for i686-mingw32-gcc option to accept ISO C89... none needed<br>checking dependency style of i686-mingw32-gcc... gcc3<br>checking how to run the C preprocessor... i686-mingw32-gcc -E<br>checking for grep that handles long lines and -e... /bin/grep<br>checking for egrep... /bin/grep -E<br>checking for ANSI C header files... yes<br>checking for sys/types.h... yes<br>checking for sys/stat.h... yes<br>checking for stdlib.h... yes<br>checking for string.h... yes<br>checking for memory.h... yes<br>checking for strings.h... yes<br>checking for inttypes.h... yes<br>checking for stdint.h... yes<br>checking for unistd.h... yes<br>checking for stdlib.h... (cached) yes<br>checking for string.h... (cached) yes<br>checking stdio.h usability... yes<br>checking stdio.h presence... yes<br>checking for stdio.h... yes<br>checking windows.h usability... yes<br>checking windows.h presence... yes<br>checking for windows.h... yes<br>checking for an ANSI C-conforming const... yes<br>checking for inline... inline<br>checking for size_t... yes<br>checking for stdlib.h... (cached) yes<br>checking for GNU libc compatible malloc... yes<br>checking for stdlib.h... (cached) yes<br>checking for GNU libc compatible realloc... yes<br>configure: creating ./config.status<br>config.status: creating Makefile<br>config.status: creating src/Makefile<br>config.status: creating src/config.h<br>config.status: executing depfiles commands<br><br>debianl@ldb /data/codes/test/win32service $ make<br>Making all in src<br>make[1]: Entering directory `/data/codes/test/win32service/src'<br>make all-am<br>make[2]: Entering directory `/data/codes/test/win32service/src'<br>i686-mingw32-gcc -DHAVE_CONFIG_H -I. -g -O2 -MT main.o -MD -MP -MF .deps/main.Tpo -c -o main.o main.c<br>mv -f .deps/main.Tpo .deps/main.Po<br>i686-mingw32-gcc -g -O2 -o SMQService.exe main.o <br>make[2]: Leaving directory `/data/codes/test/win32service/src'<br>make[1]: Leaving directory `/data/codes/test/win32service/src'<br>make[1]: Entering directory `/data/codes/test/win32service'<br>make[1]: Nothing to be done for `all-am'.<br>make[1]: Leaving directory `/data/codes/test/win32service'<br><br>debianl@ldb /data/codes/test/win32service $ file src/SMQService.exe <br>src/SMQService.exe: MS-DOS executable PE for MS Windows (console) Intel 80386 32-bit<br><br>
查看全文
发表于:2007-12-26 ┆
阅读(1429)
┆
评论(2)
汇编学习之系统调用
<p>最近工作比较闲散,因此抽空看了看汇编,基本上从头开始,看了前面几章不知不觉也学会了“Hello world”,刚好看的这本书基本上都是以GNU的开发工具为开发环境的,这比较适合我的兴趣。其实看的这几章也就只有一章(这一章还没看完^_^)才是 汇编语言的基础,刚学会了点AT&T的汇编语法,知道了跟Intel的汇编语法的区别,另外这一章用不同的方式实现了cpuid的调用,学会了如 何调用系统调用以及如何调用C函数库中的函数。<br><br>先看看下面通过系统调用实现的hello world代码:<br></p><pre style="color: rgb(245, 222, 179); background-color: rgb(47, 79, 79);"><br><font color="#fa8072">.section</font> .data<br><font color="#7fffd4"><b>msg</b></font>:<br> <font color="#fa8072">.ascii</font> <font color="#ffa07a">"Hello world!\n"</font><br><br><font color="#fa8072">.section</font> .text<br><br><font color="#fa8072">.globl</font> _start<br><br><font color="#7fffd4"><b>_start</b></font>:<br> <font color="#fa8072">movl</font> $4, <font color="#7fffd4"><b>%eax</b></font><br> <font color="#fa8072">movl</font> $1, <font color="#7fffd4"><b>%ebx</b></font><br> <font color="#fa8072">movl</font> $msg, <font color="#7fffd4"><b>%ecx</b></font><br> <font color="#fa8072">movl</font> $13, <font color="#7fffd4"><b>%edx</b></font><br> <font color="#fa8072">int</font> $0x80<br> <font color="#fa8072">movl</font> $1, <font color="#7fffd4"><b>%eax</b></font><br> <font color="#fa8072">movl</font> $0, <font color="#7fffd4"><b>%ebx</b></font><br> <font color="#fa8072">int</font> $0x80<br> </pre><br>系 统调用是通过int 0x80来实现的,eax寄存器中为调用的功能号,ebx、ecx、edx、esi等等寄存器则依次为参数,从 /usr/include/asm/unistd.h中可以看到exit的功能号_NR_exit为1,write(_NR_write)功能号为4,因 此第一个int $0x80调用之前eax寄存器值为4,ebx为文件描述符,stdout的文件描述符为1,ecx则为buffer的内存地址,edx为buffer长 度。第二个int $0x80之前eax为1表示调用exit,ebx为0表示返回0。编译链接步骤如下所示:<br>as -o helloworld.o helloworld.s<br>ld -o helloworld helloworld.o<br><br>再看看调用C函数的代码:<br><pre style="color: rgb(245, 222, 179); background-color: rgb(47, 79, 79);"><br><font color="#fa8072">.section</font> .data<br><font color="#7fffd4"><b>output</b></font>:<br> <font color="#fa8072">.asciz</font> <font color="#ffa07a">"Hello world!\n"</font><br><br><font color="#fa8072">.section</font> .text<br><br><font color="#fa8072">.globl</font> _start<br><br><font color="#7fffd4"><b>_start</b></font>:<br> <font color="#fa8072">pushl</font> $output<br> <font color="#fa8072">call</font> printf<br> <font color="#fa8072">addl</font> $8, <font color="#7fffd4"><b>%esp</b></font><br> <font color="#fa8072">pushl</font> $0<br> <font color="#fa8072">call</font> exit<br> </pre><br>这 个例子相对来说看起来简单得多,将参数压入堆栈调用相应的函数即可,不过要注意的是:1、C函数需要调用的字符串参数必须以asciz声明,而不是 ascii,这样才会给字符串后面加'\0'。2、压栈顺序刚好与C函数顺序相反,最后的参数应最先入栈。3、链接的时候需要链接libc.so库并指定 动态链接库加载器/lib/ld-linux.so.2,步骤如下:<br>as -o helloworld2.o helloworld2.s<br>ld -dynamic-linker /lib/ld-linux.so.2 -lc -o helloworld2 helloworld2.o
查看全文
发表于:2007-07-26 ┆
阅读(909)
┆
评论(0)
iptables端口映射
一个简单的应用:我的机器IP是192.168.1.240,期望访问另一个局域网的web服务器其IP为192.168.0.109,中间有台双网卡的服务器用来做透明代理,该服务器eth0为192.168.1.2,eth1为192.168.0.2。<br><br>首先需要将到达192.168.1.2:80的包顺利转给192.168.0.109,因此有了下面的DNAT:<br>iptables -t nat -A PREROUTING -s 192.168.1.0/24 -d 192.168.1.2 -p tcp --dport 80 -j DNAT --to 192.168.0.109:80<br><br>乍一看这应该没什么问题了,可是接下来问题是发现我的包是到0.109了,可是我的机器与0.109仍然无法正常通信,原来是到达0.109的源地址仍然是1.240,0.109回包的时候当然无法直接给1.240了,接下来就是SNAT的事了:<br>iptables -t nat -A POSTROUTING -d 192.168.0.109 --dport 80 -o eth1 -j SNAT --to 192.168.0.2<br><br>当然别忘了echo 1 > /proc/sys/net/ipv4/ip_forward,最好连/etc/sysctl.conf里的net.ipv4.ip_forward=1一并加上。。。<br>
查看全文
发表于:2007-07-11 ┆
阅读(1477)
┆
评论(0)
关于inotify
<p>inotify是什么?用它能干些什么?这个问题我们还是首先从内核的文档开始吧-- Documentation/filesystems/inotify.txt(说点题外话,内核文档虽然是没有任何格式的txt文档,给人的感觉却非常 好,而且作者总是以最精炼的语言清楚地描述了相关的内容): a powerful yet simple file change notification system,通俗点说它是一个内核用于通知用户空间客户程序文件系统变化的系统,并且它是powerful yet simple的。<br><br>inotify的用户接口原型主要有以下3个:<br>初始化:int inotify_init(void);<br>添加监视对象:int inotify_add_watch(int fd, const char *path, uint32_t mask);<br>删除监视对象:int inotify_rm_watch(int fd, uint32_t wd);<br><br>内核文档里对于inotify_rm_watch的用户接口原型描述似乎有点问题,第2个参数写成了mask,实际上它应该是inotify_add_watch返回的watch descriptor。<br><br>根据文档描述可以看出,inotify使用大概分为以下几个步骤:<br>1、int fd = inotify_init(); 初始化inotify实例。<br>2、 int wd = inotify_add_watch(fd, path, mask); 添加监视对象,这里的mask是一个或多个事件的位标记集合,具体的事件定义可参考(linux/inotify.h)或者 (sys/inotify.h),前者为linux内核头文件,后者为glibc提供的头文件。<br>3、size_t len = read(fd, buf, BUF_LEN); 读取事件数据,buf应是一个指向inotify_event结构数组的指针。不过要注意的是inotify_event的name成员长度是可变的,这个问题后面再解释。<br>4、已经存在的监视对象可通过int ret = inotify_rm_watch(fd, wd);来删除。<br><br>下面我们来看一个示例:<br></p><pre style="font-size: 12px; color: rgb(245, 222, 179); background-color: rgb(47, 79, 79);"><br><font color="#fa8072">#include</font> <font color="#ffa07a"><stdio.h></font><br><font color="#fa8072">#include</font> <font color="#ffa07a"><unistd.h></font><br><font color="#fa8072">#include</font> <font color="#ffa07a"><sys/select.h></font><br><font color="#fa8072">#include</font> <font color="#ffa07a"><errno.h></font><br><font color="#fa8072">#include</font> <font color="#ffa07a"><sys/inotify.h></font><br><br><font color="#fa8072">static</font> <font color="#9acd32"><b>void</b></font><br><font color="#7fffd4"><b>_inotify_event_handler</b></font>(<font color="#fa8072">struct</font> <font color="#9acd32"><b>inotify_event</b></font> *<font color="#7fffd4"><b>event</b></font>)<br>{<br> printf(<font color="#ffa07a">"event->mask: 0x%08x\n"</font>, event->mask);<br> printf(<font color="#ffa07a">"event->name: %s\n"</font>, event->name);<br>}<br><br><font color="#9acd32"><b>int</b></font><br><font color="#7fffd4"><b>main</b></font>(<font color="#9acd32"><b>int</b></font> <font color="#7fffd4"><b>argc</b></font>, <font color="#9acd32"><b>char</b></font> **<font color="#7fffd4"><b>argv</b></font>)<br>{<br> <font color="#fa8072">if</font> (argc != 2) {<br> printf(<font color="#ffa07a">"Usage: %s <file/dir>\n"</font>, argv[0]);<br> <font color="#fa8072">return</font> -1;<br> }<br><br> <font color="#9acd32"><b>unsigned</b></font> <font color="#9acd32"><b>char</b></font> <font color="#7fffd4"><b>buf</b></font>[1024] = {0};<br> <font color="#fa8072">struct</font> <font color="#9acd32"><b>inotify_event</b></font> *<font color="#7fffd4"><b>event</b></font> = {0};<br> <font color="#9acd32"><b>int</b></font> <font color="#7fffd4"><b>fd</b></font> = inotify_init();<br> <font color="#9acd32"><b>int</b></font> <font color="#7fffd4"><b>wd</b></font> = inotify_add_watch(fd, argv[1], IN_ALL_EVENTS);<br><br> <font color="#fa8072">for</font> (;;) {<br> <font color="#9acd32"><b>fd_set</b></font> <font color="#7fffd4"><b>fds</b></font>;<br> FD_ZERO(&fds);<br> FD_SET(fd, &fds);<br> <font color="#fa8072">if</font> (select(fd + 1, &fds, <font color="#7fffd4">NULL</font>, <font color="#7fffd4">NULL</font>, <font color="#7fffd4">NULL</font>) > 0) {<br> <font color="#9acd32"><b>int</b></font> <font color="#7fffd4"><b>len</b></font>, <font color="#7fffd4"><b>index</b></font> = 0;<br> <font color="#fa8072">while</font> (((len = read(fd, &buf, <font color="#fa8072">sizeof</font>(buf))) < 0) && (errno == EINTR));<br> <font color="#fa8072">while</font> (index < len) {<br> event = (<font color="#fa8072">struct</font> <font color="#9acd32"><b>inotify_event</b></font> *)(buf + index);<br> _inotify_event_handler(event);<br> index += <font color="#fa8072">sizeof</font>(<font color="#fa8072">struct</font> <font color="#9acd32"><b>inotify_event</b></font>) + event->len;<br> }<br> }<br> }<br><br> inotify_rm_watch(fd, wd);<br><br> <font color="#fa8072">return</font> 0;<br>}<br></pre><br><br>由 以上代码可以看出inotify_init返回的file descriptor是可以用select或者poll进行I/O复用的。由于inotify_event长度是可变的,因此在读取 inotify_event数组内容的时候需要动态计算下一个事件数据的偏移量(index += sizeof(struct inotify_event) + event->len),len成员即name成员的长度。<br><br>在实际测试过程中,通过运行以上的 测试程序监视一个文件,还遇到过两个奇怪的现象:用vim编辑那个被监视的文件,修改并保存,触发的是IN_DELETE_SELF和 IN_MOVE_SELF事件而不是我们所期望的IN_MODIFY事件;再次修改并保存的时候不再有任何事件发生。希望能给看官一个教训,其实这是由于 vim的工作机制引起的,vim会先将源文件复制为另一个文件,然后在另一文件基础上编辑(一般后缀名为swp),保存的时候再将这个文件覆盖源文件,因 此会出现上述的第一个现象,第二个现象是因为原来的文件已经被后来的新文件代替,因此监视对象所监视的文件已经不存在了,所以自然不会产生任何事件。<br><br>另外,内核文档第四部分介绍了inotify的背景以及设计思路,不可不看:<br><br>Q: What is the design decision behind not tying the watch to the open fd of<br> the watched object?<br><br>A: Watches are associated with an open inotify device, not an open file.<br> This solves the primary problem with dnotify: keeping the file open pins<br> the file and thus, worse, pins the mount. Dnotify is therefore infeasible<br> for use on a desktop system with removable media as the media cannot be<br> unmounted. Watching a file should not require that it be open.<br><br>Q: What is the design decision behind using an-fd-per-instance as opposed to<br> an fd-per-watch?<br><br>A: An fd-per-watch quickly consumes more file descriptors than are allowed,<br> more fd's than are feasible to manage, and more fd's than are optimally<br> select()-able. Yes, root can bump the per-process fd limit and yes, users<br> can use epoll, but requiring both is a silly and extraneous requirement.<br> A watch consumes less memory than an open file, separating the number<br> spaces is thus sensible. The current design is what user-space developers<br> want: Users initialize inotify, once, and add n watches, requiring but one<br> fd and no twiddling with fd limits. Initializing an inotify instance two<br> thousand times is silly. If we can implement user-space's preferences <br> cleanly--and we can, the idr layer makes stuff like this trivial--then we <br> should.<br><br> There are other good arguments. With a single fd, there is a single<br> item to block on, which is mapped to a single queue of events. The single<br> fd returns all watch events and also any potential out-of-band data. If<br> every fd was a separate watch,<br><br> - There would be no way to get event ordering. Events on file foo and<br> file bar would pop poll() on both fd's, but there would be no way to tell<br> which happened first. A single queue trivially gives you ordering. Such<br> ordering is crucial to existing applications such as Beagle. Imagine<br> "mv a b ; mv b a" events without ordering.<br><br> - We'd have to maintain n fd's and n internal queues with state,<br> versus just one. It is a lot messier in the kernel. A single, linear<br> queue is the data structure that makes sense.<br><br> - User-space developers prefer the current API. The Beagle guys, for<br> example, love it. Trust me, I asked. It is not a surprise: Who'd want<br> to manage and block on 1000 fd's via select?<br><br> - No way to get out of band data.<br><br> - 1024 is still too low. ;-)<br><br> When you talk about designing a file change notification system that<br> scales to 1000s of directories, juggling 1000s of fd's just does not seem<br> the right interface. It is too heavy.<br><br> Additionally, it _is_ possible to more than one instance and<br> juggle more than one queue and thus more than one associated fd. There<br> need not be a one-fd-per-process mapping; it is one-fd-per-queue and a<br> process can easily want more than one queue.<br><br>Q: Why the system call approach?<br><br>A: The poor user-space interface is the second biggest problem with dnotify.<br> Signals are a terrible, terrible interface for file notification. Or for<br> anything, for that matter. The ideal solution, from all perspectives, is a<br> file descriptor-based one that allows basic file I/O and poll/select.<br> Obtaining the fd and managing the watches could have been done either via a<br> device file or a family of new system calls. We decided to implement a<br> family of system calls because that is the preferred approach for new kernel<br> interfaces. The only real difference was whether we wanted to use open(2)<br> and ioctl(2) or a couple of new system calls. System calls beat ioctls.
查看全文
发表于:2007-06-21 ┆
阅读(1599)
┆
评论(1)