2011 OSDC Day 1 筆記

Update: 補上 OSDC 紀錄影片 2011.06.26 今年很高興可以北上參加 OSDC 2011 (Open Source Developers Conference),由於之前都在南部唸書及工作,沒有機會北上參加聚會,現在人在新竹,終於有機會可以參加了,雖然早上六點就要起床趕電車了,不過到現場聽課感覺就是不同,也可以認識很多新朋友,底下來紀錄上課筆記 微軟與 jQuery 社群的親密接觸 講者: Eric Shangkuan (Microsoft) Slide: 微軟與 jQuery 社群的親密接觸 這是 OSDC 第一場演講,早上九點就開始了,雖然人不多,但是蠻多人還是為了講者而來,首先介紹什麼是 jQuery,以及 jQuery 一些基本用法,像是 CSS selector,如何在 Windows Visual Studio 上面開發 jQuery 及撰寫 plugin 整合進去 ASP.Net,最後介紹三個不錯用的 jQuery Plugin: Templeate, Datalink, Globalzation。 Templeate: 這搭配 Facebook api 可以直接做個人頁面,請參考這裡 Globalzation: 前端多國語系實做 Datalink: 可以快速處理 form,利用 object 跟 jQuery 搭配 如果要研究上述三個 jQuery Plugin 可以參考底下: jQuery Datalink: https://github.com/jquery/jquery-datalink jQuery Templeate: https://github.com/jquery/jquery-tmpl jQuery Globalzation: https://github. [Read More]

Ubuntu (Debian) 架設 apache mpm worker mod_fcgid 筆記

最近想架設 RedmineUbuntu 伺服器上面,架設之前要先搞定 apache 搭配 mpm worker 及 mod_fcgi module,安裝步驟其實不難,就搭配懶人指令 apt 就可以了。

安裝 apache mpm worker 由於怕安裝過程會叫你把 apache2-mpm-worker 移除,改裝 apache2-mpm-prefork,所以安裝順序上面有些變化,請參考底下:

# 先安裝
$ apt-get install apache2.2-bin apache2.2-common apache2-mpm-worker libapache2-mod-fcgid php5-cli php5-cgi php5-common
#後安裝
$ apt-get install apache2 php5 php5-gd php5-curl
至於 PHP 5 套件就看你需要什麼就裝什麼吧,搜尋一下 php5-* 看看,apache 裝好預設看不到 PHP 網頁,也就是認不得 php type,請在 apache config 檔案加入底下 [Read More]

[Linux Kernel] 讀取 /proc 底下資料最佳方法: seq_file interface

前言 最近在整合公司內部

Atheros(被高通買下) 晶片的 Router,從原本 2.6.15 升級到 2.6.34.7,升級過程遇到很多困難,其中一項升級 Wireless Driver 部份,發現在 Kernel Socket 與 User Space 溝通之間出了問題,利用 Ioctl 來取得目前在 AP 上面所有 Client 資料(包含 mac address, 處於 N or G mode…等),在 User Space 上會掉資料,後來利用 /proc 底下檔案來跟 User 之間溝通,才沒有發生任何問題,由於輸出的檔案比較多,就偏向用 2.6 Kernel 提供的 seq_file 介面( interface )建立虛擬檔案 (virtual file) 與 User Space 溝通(此方法為 Alexander Viro 所設計),此功能其實在 2.4.15 已經實做了,只是在 2.6 版本才被大量使用。 程式設計師可以透過引入 <linux/seq_file.h> 來實做 seq_file interface,seq_file 最大優勢就是讀取完全沒有4k boundry 的限制,也就是不用管會不會超出 output buffer。

The iterator interface 為了能夠讓 iterator 正常運作,我們必須實做 4 個 function (start, next, stop, show),跑得過程為 start -> show -> next -> show -> next -> stop,為了方便講解,參考

Linux Kernel(4)- seq_file 裡面範例如下:

#include 
#include 
#include  /* Necessary because we use proc fs */
#include  /* for seq_file */
#include 

MODULE_LICENSE("GPL");

#define MAX_LINE 1000
static uint32_t *lines;

/**
 * seq_start() takes a position as an argument and returns an iterator which
 * will start reading at that position.
 */
static void* seq_start(struct seq_file *s, loff_t *pos)
{
    uint32_t *lines;

    if (*pos >= MAX_LINE) {
        return NULL; // no more data to read
    }

    lines = kzalloc(sizeof(uint32_t), GFP_KERNEL);
    if (!lines) {
        return NULL;
    }

    *lines = *pos + 1;

    return lines;
}

/**
 * move the iterator forward to the next position in the sequence
 */
static void* seq_next(struct seq_file *s, void *v, loff_t *pos)
{
    uint32_t *lines = v;
    *pos = ++(*lines);
    if (*pos >= MAX_LINE) {
        return NULL; // no more data to read
    }
    return lines;
}

/**
 * stop() is called when iteration is complete (clean up)
 */
static void seq_stop(struct seq_file *s, void *v)
{
    kfree(v);
}

/**
 * success return 0, otherwise return error code
 */
static int seq_show(struct seq_file *s, void *v)
{
    seq_printf(s, "Line #%d: This is Brook's demo\n", *((uint32_t*)v));
    return 0;
}

static struct seq_operations seq_ops = {
    .start = seq_start,
    .next  = seq_next,
    .stop  = seq_stop,
    .show  = seq_show
};

static int proc_open(struct inode *inode, struct file *file)
{
    return seq_open(file, &seq_ops);
}

static struct file_operations proc_ops = {
    .owner   = THIS_MODULE, // system
    .open    = proc_open,
    .read    = seq_read,    // system
    .llseek  = seq_lseek,   // system
    .release = seq_release  // system
};

static int __init init_modules(void)
{
    struct proc_dir_entry *ent;

    ent = create_proc_entry("brook", 0, NULL);
    if (ent) {
        ent->proc_fops = &proc_ops;
    }
    return 0;
}

static void __exit exit_modules(void)
{
    if (lines) {
        kfree(lines);
    }
    remove_proc_entry("brook", NULL);
}

module_init(init_modules);
module_exit(exit_modules);
[Read More]

[Linux] 將 iperf 導入嵌入式系統 Router

iperf 是一套測試網路效能工具,對於網通廠各工程師們不可或缺的啦,分享如何將 iperf 裝到嵌入式板子,其實在 Porting 每一個工具到板子上的方式差不多,步驟大概是利用 configure file 產生 Makefile,修改 gcc tool chain 路徑,將編譯好的程式放到 root file system,基本上就是如此,目前 iperf 到 2.0.5 版,大家快去下載吧。 直接修改 user space 的 Makefile: cd ./user/apps/iperf-2.0.5; \ ./configure --host=mips-linux CC=$(TOOLPREFIX)gcc CXX=$(TOOLPREFIX)g++ --disable-ipv6 \ --prefix=$(shell (pwd -P))/user/apps/iperf-2.0.5/romfs;\ $(MAKE) && $(MAKE) install ;\ --host, CC, CXX 請換上 Tool Chain 對應路徑,大致上就可以了,更多設定可以參考 ./configure --help 編譯過程如果出現底下錯誤 undefined reference to malloc 就將 config.h.in 這檔案,底下整段 mark 起來,就可以編譯過了 /* Define to rpl_malloc if the replacement function should be used. [Read More]

[Linux] 釋放虛擬記憶體 (cache)

Linux Kernel 2.6.16 之後加入了 drop caches 的機制,可以讓系統清出多餘的記憶體,這對於搞嵌入式系統相當重要阿,Memory 不夠就不能 upgrade firmware,我們只要利用讀寫 proc 檔案就可以清除 cache 記憶體檔案,底下是操作步驟:

釋放 pagecache:捨棄一般沒使用的 cache

echo 1 > /proc/sys/vm/drop_caches

釋放 dentries and inodes

echo 2 > /proc/sys/vm/drop_caches

釋放 pagecache, dentries and inodes

echo 3 > /proc/sys/vm/drop_caches

Reference: Drop Caches 觀察 Linux 的虛擬記憶體

[Linux] 嵌入式系統不可或缺的工具 – busybox 分析 ifconfig command

Busybox

玩過嵌入式系統的使用者,一定都會知道 Busybox,它提供一些小型 Linux command,方便在 console 端使用,以及一些 C 語言或者是 shell script 裡面,大家都知道 ifconfig 這指令,為了從 Kernel 2.6.15 轉換到 2.6.34.7 版本,原本的 Busybox 版本只有 1.0.1,現在已經到 1.18.1,轉換過程改了 Kernel netfilter 部份,以及 user space 部份 iptables extension。ifconfig 是 Busybox 其中一個指令用來查看目前有多少網路介面(network interface),來看看他是如何得到這些 interface 資訊,包含介面名稱、type、IP Adress、IP network mask、HW address 等….。

要讀取 interface 相關資訊可以透過兩種方式,一種是讀取 (IPv6 是 /proc/net/if_inet6),另一種透過 Socket 連接SOCK_DGRAM,最後用 iotcl 方式讀取 interface 相關資料,busybox 會先偵測檔案 /proc/net/dev 是否存在,如果 Kernel 有支援,就會讀取此檔案,如果不存在,則利用 socket 讀取資料。

if_readlist_proc 函式裡面:

1
2
3
4
fh = fopen_or_warn(_PATH_PROCNET_DEV, "r");
if (!fh) {
    return if_readconf();
}

看一下 /proc/net/dev 內容

1
2
3
4
Inter-|   Receive                                                |  Transmit
 face |bytes    packets errs drop fifo frame compressed multicast|bytes    packets errs drop fifo colls carrier compressed
    lo:     104       1    0    0    0     0          0         0      104       1    0    0    0     0       0          0
  eth0:21798505   51360    0    0    0     0          0         0  7693686   46844    0    0    0     0       0          0
[Read More]

[虛擬主機] VPS Linode 贈送 $100,000 美元給新註冊會員

昨天在下班前看到 Linode VPS 送出這個訊息: Linode $100,000 Giveaway!,只要在美國時間2010年12月17日早上九點開放名額1000名購買 VPS Linode 任何一種,就可以獨享 100 元美金的優惠,原本我已經有買一台 Linode 512 方案,我現在又加購一台,省下不少錢呢,到月底就不續約,然後再用新帳號繼續使用 Linode 512 服務,沒圖沒證據,底下附上我購買相關圖片 另外 VPS Linode 也提供了香港主機的服務,以及新的 Ubuntu OS 也上線了 Arch Linux 2010.05 (i386 and x86_64) CentOS 5.5 (i386 and x86_64) Debian 5.0 (i386 and x86_64) Fedora 14 (i386 and x86_64) Slackware 13.1 (i386 and x86_64) Ubuntu 10.04 LTS (i386 and x86_64) Ubuntu 10.10 (i386 and x86_64) OpenSUSE 11.0 Gentoo 2008.0 (i386 and x86_64) 參考主機放在哪裡比較適合: Datacenter Availability,您可以測試一下每個區域的連線速度 download speed test,我利用學網測試了國外的速度,發現速度比較如下: 單檔都是 100 MB: [Read More]

[網站] 好站連結 (七) Android, javascript, Css, PHP, Perl, FreeBSD, Linux

Windows C# C# 比較字串 MSDN 比較字串 Request.Form Collection Request Query String / Form Parametrs ASP.NET QueryString Usage Using include files with ASP.NET html [將所有 的內容包到一個 中][7] apache Fixing mod_rewrite and .htaccess on GoDaddy Hosting javascript jQuery Week Calendar Javascript: reference the parent window from a popup How to get and set form element values with jQuery How to check and uncheck a checkbox with jQuery Loop through parameters passed to a Javascript function perl-completion. [Read More]

[Linux Kernel] 簡單 hello world: License and Module 介紹(part 3)

在 Kernel 2.4 或以上版本,在編譯模組完成,要進行 load module 之前,你會發現底下訊息: # insmod hello-3.o Warning: loading hello-3.o will taint the kernel: no license See http://www.tux.org/lkml/#export-tainted for information about tainted modules 很顯然這訊息是要您在 kernel module 裡面加上版權宣告,例如:"GPL","GPL v2"…等來宣告您的 module 並非 open source,利用 MODULE_LICENSE() 巨集來宣告程式 License,同樣的,可以用 MODULE_DESCRIPTION() 來描述此模組或者是 Driver 的功用跟簡介,以及用 MODULE_AUTHOR() 來定義此模組作者,這些巨集都可以在 linux/module.h 裡找到,但是這些並非用於 Kernel 本身,如果大家想看範例程式,可以到 drivers/ 資料夾底下觀看每一個 Driver 程式,底下是簡單 hello world 範例: #include /* pr_info所需 include 檔案*/ #include #include /* 所有 module 巨集需要檔案*/ #include static int __init hello_init(void) { pr_info(" [Read More]

ProFTPD UseEncoding 繁體中文亂碼解決 Localization

Proftpd ProFTPD 一直都是我最喜歡使用的 FTP 伺服器,設定方式簡單淺顯易懂,最近在用 PSPad 寫程式,發現使用內建 FTP 功能時候,連不上 FreeBSD 架設的 ProFTPD,連線過程出現許多亂碼,所以造成 PSPad 斷線出現錯誤,解決方式就是利用 mod_lang 模組,設定 UseEncoding 讓系統可以顯示 Big5 中文編碼,FreeBSD Ports 請勾選

[X] NLSUOTA Use nls (builds mod_lang)
自行編譯請按照底下步驟
./configure --enable-nls
make
make install 

UseEncoding 設定

Syntax: UseEncoding on|off|local-charset client-charset
Default: None
Context: "server config", , 
Module: mod_lang
Compatibility: 1.3.2rc1
在 1.3.2rc1 版本之後才有支援,請複製底下設定,貼到 proftpd.conf
# 简体中文環境
UseEncoding UTF-8 GBK
# 繁体中文環境
UseEncoding UTF-8 Big5
Reference:

ProFTPD module mod_lang centos上解決proftp中文亂碼問題