Spawning processes with display output from Linux kernel module
Linux - KernelThis forum is for all discussion relating to the Linux kernel.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Spawning processes with display output from Linux kernel module
I am trying to spawn a process from a kernel module, that has visual output - for now, I'm just trying to spawn xeyes. I am trying to do this using call_usermodehelper. I am getting a return value of 256.
I am specifying these environmental variables in envp:
HOME=/
DISPLAY=:0 (this is what I get when I echo $DISPLAY in any of my terminals)
PATH=/sbin:/bin:/usr/sbin:/usr/bin
Here is my module code:
Code:
#include <linux/module.h>
#include <linux/init.h>
#include <linux/kernel.h>
int spawnProcess(void) {
char *argv[] = { "/usr/bin/xeyes", NULL };
static char *envp[] = { "HOME=/","DISPLAY=:0", "PATH=/sbin:/bin:/usr/sbin:/usr/bin", NULL };
printk(KERN_DEBUG "Inside spawnProcess\n");
return call_usermodehelper( argv[0], argv, envp, UMH_WAIT_PROC );
}
static int __init moduleLoader(void) {
int i;
printk(KERN_INFO "My module is loading...\n");
i = spawnProcess();
printk(KERN_DEBUG "return value %d\n",i);
printk(KERN_INFO "My module is done loading.\n");
return 0;
}
static void __exit moduleUnloader(void) {
printk(KERN_INFO "My module was unloaded.\n");
return;
}
module_init(moduleLoader);
module_exit(moduleUnloader);
MODULE_AUTHOR("Yaron Shragai");
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("Lorem ipsum dolor sit amet");
Here is the output in the system log:
Mar 29 17:38:16 yaron-VirtualBox kernel: [84070.533179] My module is loading...
Mar 29 17:38:16 yaron-VirtualBox kernel: [84070.533180] Inside spawnProcess
Mar 29 17:38:16 yaron-VirtualBox kernel: [84070.534297] return value 256
Mar 29 17:38:16 yaron-VirtualBox kernel: [84070.534299] My module is done loading.
I am running 64-bit Ubuntu 16.04 LTS on a VirtualBox VM.
Output from uname -a:
Linux yaron-VirtualBox 4.4.0-57-generic #78-Ubuntu SMP Fri Dec 9 23:50:32 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
You might want to have a look at Xvfb (X virtual frame buffer) to see how it does its thing. It may give you ideas on what to do in your module.
Xvfb is something that allows one to start X-GUI items in the background. We've used it for years because many Oracle products spawn GUIs even when started in background.
Thank you @MensaWater, I'll take a look.
By the way, a bit of added detail: When I try to spawn x programs (e.g., xterm, xeyes), I get a failure of 256, as shown in the OP. When I try to spawn a program that has stdoutput (e.g., the ls command, or, a program that just has one printf), I get a failure of -2. (If the spawned program has no screen output - e.g., just accesses files - it works.)
I guess only: root has no right to use that X server. You may try to open a root shell and try xeyes or similar first (with the same DISPLAY settings).
by the way I think HOME is /root, not / usually.
so if you can execute a binary, construct a new one which will start xterm and catch all the stdout and stderr and probably you will see some usable info about it
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.