0

I am doubtful whether UMH_NO_WAIT option in call_usermodehelper() is working, or I am missing something.

This is with reference to the following thread, 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");

I think because of the call_usermodehelper() call, the system hangs.Because, at the time of call_usermodehelper() function call only the system freezes. So, I have tried with the option UMH_NO_WAIT, so that the kernel code will not wait for the user process to execute.Then also the system hangs.kindly check www.kernel.org/doc/htmldocs/kernel-api/API-call-usermodehelper.html

Community
  • 1
  • 1
BusyTraveller
  • 183
  • 3
  • 14
  • In the referenced question you use `UMH_WAIT_PROC`, not a `UMH_NO_WAIT`. So, what is a problem? – Tsyvarev Feb 19 '16 at 08:49
  • Because of the call_usermodehelper() call, the system hangs. So, I have tried with the option UMH_NO_WAIT, so that the kernel code will not wait for the user process to execute.Then also the system hangs.kindly check https://www.kernel.org/doc/htmldocs/kernel-api/API-call-usermodehelper.html – BusyTraveller Feb 19 '16 at 09:27
  • As you ask about `UMH_NO_WAIT`, make the code explicitely use it. Moreover, you have another question which asks about original code. – Tsyvarev Feb 19 '16 at 09:39
  • Exactly this code (copy-pasted) works for me (Linux kernel 3.11). (There are some compile warnings about too large argument for `ktime_set` and omitting parameters declaration for `timer_init` and `timer_exit`, but they are not critical). BTW, there is not needs to use `hrtimer` for such long delays. `delayed_work` would fits perfectly for this use-case. – Tsyvarev Feb 19 '16 at 18:30
  • I have tested the code in 3.11.The timer is running fine. But the test code (test.sh),that is mentioned in the program , was not executing.But once I changed to UM_WAIT_PROC or UM_WAIT_EXEC, the system is hanging. – BusyTraveller Feb 22 '16 at 11:09
  • `But the test code (test.sh),that is mentioned in the program , was not executing.` - **Are you sure** that your program has not not executed? It may lack console (like any other deamon process), so your output is lost. Try to create file in your test program, so you will definitely know whether it executed or not. As for `UM_WAIT_PROC` I already said, that it doesn't work withing timer handler. Same for `UM_WAIT_EXEC`. – Tsyvarev Feb 22 '16 at 20:22
  • yes.the test code is not getting executed.The test code , writes some text to a file, which is not happening. – BusyTraveller Feb 23 '16 at 09:29

0 Answers0