LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices


Reply
  Search this Thread
Old 03-31-2017, 10:56 AM   #1
yaronshr
LQ Newbie
 
Registered: Mar 2017
Posts: 5

Rep: Reputation: Disabled
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 have been able to successfully spawn a process that does not generate display output (namely, /usr/bin/logger), as per the example here: https://www.ibm.com/developerworks/l...er-space-apps/

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

Thanks for any help!
 
Old 04-05-2017, 07:20 AM   #2
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
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.
 
Old 04-05-2017, 09:21 AM   #3
yaronshr
LQ Newbie
 
Registered: Mar 2017
Posts: 5

Original Poster
Rep: Reputation: Disabled
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.)
 
Old 04-05-2017, 09:27 AM   #4
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,838

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
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.
 
Old 04-05-2017, 09:46 AM   #5
yaronshr
LQ Newbie
 
Registered: Mar 2017
Posts: 5

Original Poster
Rep: Reputation: Disabled
pan64, tested that out as you suggest. A root terminal (at least on my system) can indeed spawn x applications - so that's not the issue.
 
Old 04-06-2017, 01:10 AM   #6
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,838

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
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
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Writing kernel module to renice processes DKSL Linux - Newbie 2 06-02-2012 10:48 PM
Expect: Restrictions on spawning multiple processes on Linux-Fedora rajivk Programming 0 02-05-2012 05:22 PM
Perl script control gateway locking down when spawning too many child processes. systemlordanubis Programming 5 09-08-2011 07:41 AM
Help! imapd is spawning multiple processes, all of a sudden, for no reason! fishsponge Linux - Server 1 02-26-2009 10:55 AM
Memory usage when spawning child processes brianvdc Programming 4 10-24-2003 06:03 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel

All times are GMT -5. The time now is 10:33 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration