04 21 |
usermode helper-來自kernel的呼喚作者: Joey 日期: 2009-04-21 16:19 |
博客來最近都在促銷Orielly的書,只要買足3本,就可享75折的優惠,所以我這次一口氣買了三本雖然之前看過但很想收藏的書,自從出社會後,幾乎每個月都會買個幾本技術相關的書籍典藏,雖然網路上都抓得到,但總覺的缺了一份質感,沒有翻書的感覺,就好像沒在看書
這次要介紹東西很簡單,但這種技巧很常見,不論是hotplug會是kernel init,都會發現這個函式的蹤影,當安裝plug&play裝置時,kernel會呼叫hotplug執行device setup script,而從kernel呼叫user space的API,就是user modehelper,簡單的程式我列如下
程式的重點在於envp和argv的設定,envp是環境設定的變數,而argv是user application的執行參數
- static int __init testmodule_init(void)
- {
- int ret;
- char *envp[] = {
- "HOME=/",
- "TERM=linux",
- "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
- NULL,
- };
- char *argv[] = {
- "/bin/ash",
- "-c",
- "echo 1 > /mnt/jffs2/aa.conf",
- NULL
- };
- if ((ret =call_usermodehelper(argv[0], argv, envp, /*UMH_WAIT_PROC*/1)) != 0) {
- printk(KERN_ERR "user mode helper failed to run\n”);
- return 0;
- }
- static void __exit testmodule_exit(void)
- {
- }
評論: 0 |
引用: 0 |
閱讀: 4233
發表評論
Regular expression-跟brainfuck差不多的東西 (2009-11-13 15:37)
Reading file in kernel-簡單但實用 (2009-10-13 15:18)
Linux file system for dummies-只花你45分鐘 (2009-08-19 15:40)
OPENSSL-TCP SSL初心者之路 (2009-07-16 15:16)
NAPI與pure interrupt driver的效能比較 (2009-04-29 19:06)
kernel module memory detector-抓出有害的kernel module (2009-03-31 13:50)
kernel space coding-如履薄冰 (2009-03-26 09:52)
readahead與posix_advise-預讀取是萬能靈丹? (2009-03-06 15:54)
Who call me – kernel版 (2009-02-19 10:53)