Thursday, April 30, 2009

"The Linux Kernel" book

"The Linux Kernel" book
http://tldp.org/LDP/tlk/tlk-toc.html

It is old, based on 2.0.33. But some chapter are still useful, such as PCI.

Wednesday, April 29, 2009

ifup configuration not found

Sometimes, if you use "ifup eth0" , but get following error:
/sbin/ifup:configuration for etho not found usage :ifup

Then you need to create a config file like:
/etc/sysconfig/network-scripe/ifcfg-eth0

Here is the sample content for CentOS 5:
DEVICE=eth0
BOOTPROTO=dhcp
HWADDR=XX:XX:XX:XX:XX
ONBOOT=no

Friday, April 24, 2009

Linux kernel module

不错的文章,不过是讲 2.2 kernel的。
http://www.yuanma.org/data/2008/0806/article_3127_1.htm

LINUX KERNEL MODULE PROGRAMMING GUIDE:
http://tldp.org/LDP/lkmpg/2.6/html/index.html

Modify the PATH environment variable for Linux

http://www.troubleshooters.com/linux/prepostpath.htm

Wednesday, April 22, 2009

终于搞定了 998--ERROR_NOACCESS

最近在用WINDOWS 的NAMED PIPE, 被一个问题困扰了好久. 现象是我的PIPE SERVER 不定时的会报错, READFILE 失败, 返回的错误代码是 998!
 
于是查MSDN,用VS的ERROR LOOK UP看, 发现998 的意思是INVALID ACCESS TO MEMROY LOCATION. 不过这个解释太含糊了, 为什么会INVALID呢? 为什么PIPE SERVER 时好时坏呢? 代码一直都没变啊. 没办法, 只好把PIPE CLIENT 那边的信息打印出来, 看看是不是CLIENT的问题. 检查之后发现CLIENT端正常, 是SERVER先 丁咗(死掉)的. 可是SERVER为什么有时又能正常读消息呢? 最讨厌这种时好时坏的BUG了. 如果一直不行, 我也容易查, 容易试. 但是来个段誉六脉神剑式的, 时灵时不灵, 那就头大死了.
 
接下来又把MSDN上PIPE使用的例子看了好几遍,觉得自己的代码也没什么不对的地方. 然后GOOGLE PIPE 998, 也没有找到什么有用的信息. 然后又把以前写的基本PIPE CLIENT SERVER测试的小程序拿出来, 看看是不是因为CLIENT 了先关掉, 所以SERVER读不出来了? 发现也不是.
 
气急败坏之下,有一种用MEMORY MAPPED FILE 重新写通信机制的冲动. 因为我怀疑WINDOWS PIPE是不是本身就有缺陷, 有内部BUG? 只不过一般人不知道呢? 还好脑子还没有完全坏掉, 想想PIPE 不至于这么弱, 而且我只是在本机的2个进程间通信, 没有什么特别复杂的. 如果用MMF 是效率高点,不过也更加容易出错了.
 
无奈之下, 继续GOOGLE, 这次点了下在GOOGLE GROUP了搜寻998 PIPE的连接. 你别说, 还真让我找到了一个挺有用的贴子, 如下:
http://groups.google.com/group/microsoft.public.win32.programmer.kernel/browse_thread/thread/4d4156c7d388f128/bdf7c4615bfaebdb?lnk=st&q=error+998+pipe&rnum=9&hl=en#bdf7c4615bfaebdb
这里起码解释了998的含义到底是什么, 原来是READFILE自己传进去的BUFFER有问题. 而和SECURITY 无关. 其实之前我还真往SECURITY 方向查了半天.
 
现在对998的理解又深入了一步, 那么仔细检查我的代码吧. 不看不知道, 一看吓一跳. 原来我给READFILE 传的参数还真有问题. READFILE里有2个参数,一个是BUFFER指针, 一个是BUFFER大小(有多少BYTE). 我发现, 原来我给READFILE 传了一个实际大小为1024BYTE的BUFFER, 但是告诉他BUFFER的SIZE是2048! -_-|| . 为什么开始没发现这个错误呢? 因为我把PIPE的读消息函数又包了一层, 封到一个类里去了. 所以不看类的实现是看不出来的. 或者说是函数的接口定义的不好, 容易有歧义.
 
问题找到了, 那么改起来就方便了. 2分钟改完, 赶紧测试了一下, 一切顺利, 再也没有该死的998错误了. 

SetWindowsHookEx return error 87

最近要用 SetWindowsHookEx 函数改变下 VMware 的一个功能。于是开始先写一个单独的,简单的测试程序。弄了半天,发现在 HOOK VMware 的时候总是失败,给的错误代码是87,也就是无效参数。但是我已经确认过那4个参数都是对的啊。头疼。

没办法,又自己写个超小的WINDOWS程序来代替VMWARE, 一切正常。可是为啥VMWARE 不行呢?还是想不通,于是又换个程序HOOK. 不过换成CALC.EXE(计算器)之后,出现同样的87错误。可是同样的程序HOOK我自己的小程序就没那个错误。苦恼。

又想了下,那4个传给 SetWindowsHookEx 参数绝对都是对的,因为我都检查过。那么我的小程序和其他CALC.EXE, VMWARE有啥不同呢?GOOLE了N个文章,没答案。又想了半天,忽然想到,我是在CREATEPROCESS之后马上用 SetWindowsHookEx进行HOOK的。我的小程序启动肯定很快,但是另外2个也许比较慢。难道要多等一段时间才能HOOK? 马上在SetWindowsHookEx 之前加个SLEEP 3秒钟。再试,搞定!

我现在觉得,原因在于CREATEPROCESS是异步调用的。虽然它已经返回了,但是新的PROCESS也许还没真正准备好 (创建一个新进程比生个小孩还麻烦)。所以这时马上调用 SetWindowsHookEx 的话,就会出错。不过错误信息太雷人了。

另外 MSDN 上应该好好说明一下。

A few days ago, I tried to use SetWindowsHookEx function to modify the behavior of a program -- VMware. In my program, I first  call CreateProcess to create vmware process then I call SetWindowsHookEx. But SetWindowsHookEx  always return an error -- 87. It means invalid parameter. However, I was sure all the parameters passed to SetWindowsHookEx are correct. So what's wrong? After a lot of googling and thinking, I finally found out that you have to put a Sleep(100) or sth. similar between the CreateProcess and SetWindowsHookEx. I guess the reason is that CreateProcess is an asynchronous function. When it returns, the process may not actually ready and call SetWindowsHookEx immediately may then fail. Unfortunately, the error code is misleading and make it hard to find out the true reason.

Friday, April 17, 2009

Increase screen resolution on CentOS

http://www.linuxforums.org/forum/redhat-fedora-linux-help/52999-cant-increase-screen-resolution-beyond-800x600.html

You have to change the your monitor settings (Desktop>System Settings>Display) .You should find the monitor type directly above the Graphics card type, and i am guessing that it is probably set up as generic monitorIf you want resolutions above 800*600, you will need to Change it from generic monitor, to generic 1024×768 Monitor (or whatever resolution you want), and then you will be able to select higher resolutions from the drop down list.

Thursday, April 16, 2009

Compile linux kernel and vmlinux

compile kernel: http://www.cyberciti.biz/tips/compiling-linux-kernel-26.html In short:

  • make menuconfig

  • make

  • make modules

  • make modules_install

  • make install

Note, to use make menuconfig on CentOS 5, run: yum install ncurses-devel ncurses


To use make xconfig, need to install g++ and qt. On CentOS 5, run: yum install gcc-c++ qt-devel


Debian, or Ubuntu: http://www.linuxdiyf.com/viewarticle.php?id=84895 compile for vmlinux: http://www.gnuradio.org/trac/wiki/InBandProfiling make vmlinux

Install Java on CentOS

Eclipse requires the new JAVA (>1.5). And CentOS 5.3 can only provide java1.4.2. To install new Java, do following:
1) go to java.com and download the package for linux
2) install that package.
3) Modify the "PATH" environment variable to use the new Java
create (or edit) /etc/profile.d/java.sh file, example below;
export JAVA_HOME="/usr/java/jre1.5.0_11/bin"
export JAVA_PATH="$JAVA_HOME"
export PATH="$PATH:$JAVA_HOME"

4) remove the old java:
mv /usr/bin/java /usr/bin/oldjava

5) logoff and login again
Ref: http://www.smithproject.org/forum/posts/list/17.page

Install VNC on CentOS

http://www.7ota.com/blog/2008/09/install-vnc-server-on-centos/
http://wiki.centos.org/HowTos/VNC-Server

Tuesday, April 14, 2009

Create a ISO file on Linux

http://www.granneman.com/techinfo/linux/burningcds/makeanisoimage.htm

 To make an ISO from files on your hard drive, create a directory which holds the files you want. Then use the mkisofs command.

mkisofs -o /tmp/cd.iso /tmp/directory/ 

Monday, April 13, 2009

How to view chm file and open rar file on Linux

For chm file, you can use following package:
gnochm, kchmviewer, xchm. You can use apt-get to install those package. On CentOS, you can use DAG repository: http://dag.wieers.com/rpm/FAQ.php#B1
to install.
For rar file, use unrar package.

Ref:
http://www.cyberciti.biz/faq/open-chm-file-under-linuxfreebsd/
http://linuxondesktop.blogspot.com/2008/02/viewing-chm-files-in-linux-with.html
http://www.mydigitallife.info/2008/07/08/how-to-open-and-view-or-extract-chm-compiled-html-files-in-linux/