call_usermodehelper()中的UMH_NO_WAIT是否正常工作?

时间:2016-02-19 08:32:51

标签: c linux-kernel

我怀疑call_usermodehelper()中的UMH_NO_WAIT选项是否正常工作,或者我遗漏了什么。

这是参考以下主题, Kernel module periodically calling user space program

#include <linux/module.h>   /* Needed by all modules */
#include <linux/kernel.h>   /* Needed for KERN_INFO */
#include <linux/init.h>     /* Needed for the macros */
#include <linux/jiffies.h>
#include <linux/time.h>
#include <linux/proc_fs.h>
#include <asm/uaccess.h>
#include <linux/hrtimer.h>
#include <linux/sched.h>
#include <linux/delay.h>

#define TIME_PERIOD 5000000000

static struct hrtimer hr_timer;
static ktime_t ktime_period_ns;

static enum hrtimer_restart timer_callback(struct hrtimer *timer){
char userprog[] = "test.sh";
char *argv[] = {userprog, "2", NULL };
char *envp[] = {"HOME=/", "PATH=/sbin:/usr/sbin:/bin:/usr/bin", NULL };
printk("\n Timer is running");
hrtimer_forward_now(&hr_timer, ktime_period_ns);

printk("callmodule: %s\n", userprog);
call_usermodehelper(userprog, argv, envp, UMH_NO_WAIT);
return HRTIMER_RESTART;
}

static int __init timer_init() {
    ktime_period_ns= ktime_set( 0, TIME_PERIOD);
    hrtimer_init ( &hr_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL );
    hr_timer.function = timer_callback;
    hrtimer_start( &hr_timer, ktime_period_ns, HRTIMER_MODE_REL );
    return 0;
}


static int __exit timer_exit(){

    int cancelled = hrtimer_cancel(&hr_timer);

    if (cancelled)
        printk(KERN_ERR "Timer is still running\n");
    else
        printk(KERN_ERR "Timer is cancelled\n");

}
module_init(timer_init);
module_exit(timer_exit);

MODULE_LICENSE("GPL");

我认为由于call_usermodehelper()调用,系统挂起。因为,在call_usermodehelper()函数调用时,只有系统冻结。所以,我尝试使用选项UMH_NO_WAIT,以便内核代码不会等待用户进程执行。然后系统挂起。请检查www.kernel.org/doc/htmldocs/kernel-api/API-call -usermodehelper.html

0 个答案:

没有答案