星期日, 11月 29, 2009

簡單介紹Cygwin

Cygwin可以讓習慣使用unix command line & utility的人在其他的作業環下方便作業。

以在windows下為例

先抓到安裝檔

http://www.cygwin.com/setup.exe

然後點兩下安裝,可以自行選擇要加上哪些套件,如果沒有特別選的話,

裝好後一開始就沒有太多工具。

最後要說和windows檔案結合的部份是在/cygdrive/x

x是磁區,C:\\就是/cygdrive/c,D:\\就是/cygdrive/d依此類推。

星期六, 11月 28, 2009

Ubuntu中加入System call

首先在/usr/src/linux/kernel/sys.c中加入想要的syscall如下

/* adding helloworld system call */
#include

asmlinkage int sys_helloworld() {
printk(KERN_EMERG "Hello World!\n");
return 0;
}

當然也可以自行新增.c檔案,但是要記得#include
說明一下,asmlinkage表示我們的程式碼是用c寫的,而非c++
printk會把string放到/var/log/syslog中,
KERN_EMERG表示此log等級是緊急了(當然是在此亂打的)
然後還有3個檔案要修改的分別是

/usr/src/linux/arch/x86/include/asm/unistd_32.h中加上
#define __NR_helloworld 337
後面的號碼要記得看最後一個syscall號碼在加上1,
此號碼用來定義syscall的唯一編號

/usr/src/linux/arch/x86/include/asm/syscalls.h
在這些註解後面
/* X86_32 only */
/* kernel/sys.c */
加上
asmlinkage int sys_helloworld();
用來註冊system call

/usr/src/linux/arch/x86/kernel/syscall_table_32.S
加上
.long sys_helloworld

然後重新編譯核心
就可以來測試囉!

#include
#include
#include

#define __NR_helloworld 337 /* or whatever you set it in unistd.h */

int helloworld() {
return (int) syscall(__NR_helloworld);
};

main () {
printf("The return code from the helloworld system call is %d\n", helloworld());
}


此文章參考自:http://macboypro.wordpress.com/2009/05/15/adding-a-custom-system-call-to-the-linux-os/

星期日, 11月 22, 2009

htmlParser malformed start tag errors

今天寫的時候遇到了這樣的問題

Traceback (most recent call last):
File "/home/cacaegg/programs/script/spider.py", line 22, in
par.feed(htmlSource)
File "/usr/lib/python2.6/HTMLParser.py", line 108, in feed
self.goahead(0)
File "/usr/lib/python2.6/HTMLParser.py", line 148, in goahead
k = self.parse_starttag(i)
File "/usr/lib/python2.6/HTMLParser.py", line 226, in parse_starttag
endpos = self.check_for_whole_start_tag(i)
File "/usr/lib/python2.6/HTMLParser.py", line 301, in check_for_whole_start_tag
self.error("malformed start tag")
File "/usr/lib/python2.6/HTMLParser.py", line 115, in error
raise HTMLParseError(message, self.getpos())
HTMLParseError: malformed start tag, at line 46, column 3275

所以參考了http://bugs.python.org/issue736428來解決
主要就是做兩件事
1.override the class's error function

def error(self, message):
print message


2.add a line after line 301 in HTMLParser.py

self.updatepos(i, j)
self.error("malformed start tag")
return j # ADDED THIS LINE


暫時就先這樣解決吧!

星期六, 11月 21, 2009

Build up a kernel in Ubuntu

花了不少時間總算裝好kernel,

簡述一下步驟。

首先先抓個kernel

wget -c http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.31.4.tar.bz2


接著解壓縮在某個資料夾

tar -xvf linux-2.6.31.4.tar.bz2


在那資料夾


% sudo make menuconfig
% sudo make clean
% sudo make
% sudo make install
% sudo make modules
% sudo make modules_install
% sudo update-initramfs -c -k 2.6.31.4
% sudo update-initramfs -c -k 2.6.31.4-custom
% sudo vim /boot/grub/menu.lst

make menuconfig:在此設定有關kernel的設定,以及各種模組
make clean:清除之前make的檔案
make:編譯kernel
make install:把kernel安裝到系統中 /boot目錄之下
到此為止,可能有些機器可行,有些不行,
會在開機時會遇到kernel panic - not syncing: VFS : unable to mount root fs on unknown block(0,0)
則表示kernel沒有此driver去把disk mount,
Linux下有個特別的方法--initramfs,
讓grub先把此image load好,此image中會有一些必須的driver,就可以解決了
所以在menu.list中再用此設定

title Ubuntu 9.10, kernel 2.6.31.4-custom (recovery mode)
root (hd0,0)
kernel /boot/vmlinuz-2.6.31.4-custom root=UUID=b3d28e09-397a-4a8c-8c76-04b1845ab6b8 ro single
initrd /boot/initrd.img-2.6.31.4-custom

下次開機時就會有此選單了。