* Fork and Exec a process within the kernel
@ 2004-08-09 21:03 Eric Masson
2004-08-09 23:10 ` Paul Jackson
0 siblings, 1 reply; 13+ messages in thread
From: Eric Masson @ 2004-08-09 21:03 UTC (permalink / raw)
To: linux-kernel
Hi all,
I know it's not the best approach to the problem I'm attempting to
solve, but I'm attempting to fork a thread and exec a process from
inside the kernel. I tried creating a kernel thread and attempted to
exec from there. I actually make it into my child thread, but the exec
doesn't appear to do anything. Any ideas how to do this.
Eric
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Fork and Exec a process within the kernel
2004-08-09 21:03 Fork and Exec a process within the kernel Eric Masson
@ 2004-08-09 23:10 ` Paul Jackson
2004-08-10 15:22 ` Eric Masson
0 siblings, 1 reply; 13+ messages in thread
From: Paul Jackson @ 2004-08-09 23:10 UTC (permalink / raw)
To: Eric Masson; +Cc: linux-kernel
Try grep'ing for call_usermodehelper()
--
I won't rest till it's the best ...
Programmer, Linux Scalability
Paul Jackson <pj@sgi.com> 1.650.933.1373
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Fork and Exec a process within the kernel
2004-08-09 23:10 ` Paul Jackson
@ 2004-08-10 15:22 ` Eric Masson
2004-08-10 16:21 ` Paul Jackson
2004-08-10 16:33 ` Jan-Benedict Glaw
0 siblings, 2 replies; 13+ messages in thread
From: Eric Masson @ 2004-08-10 15:22 UTC (permalink / raw)
To: Paul Jackson; +Cc: linux-kernel
Thanks for the pointer! My user mode program is running. Any idea how to
control which console it shows up on?
Eric
Paul Jackson wrote:
>Try grep'ing for call_usermodehelper()
>
>
>
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Fork and Exec a process within the kernel
2004-08-10 15:22 ` Eric Masson
@ 2004-08-10 16:21 ` Paul Jackson
2004-08-10 18:20 ` Lee Revell
2004-08-10 19:03 ` Richard B. Johnson
2004-08-10 16:33 ` Jan-Benedict Glaw
1 sibling, 2 replies; 13+ messages in thread
From: Paul Jackson @ 2004-08-10 16:21 UTC (permalink / raw)
To: Eric Masson; +Cc: linux-kernel
> My user mode program is running.
Good.
> Any idea how to control which console it shows up on?
No clue.
--
I won't rest till it's the best ...
Programmer, Linux Scalability
Paul Jackson <pj@sgi.com> 1.650.933.1373
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Fork and Exec a process within the kernel
2004-08-10 15:22 ` Eric Masson
2004-08-10 16:21 ` Paul Jackson
@ 2004-08-10 16:33 ` Jan-Benedict Glaw
1 sibling, 0 replies; 13+ messages in thread
From: Jan-Benedict Glaw @ 2004-08-10 16:33 UTC (permalink / raw)
To: Eric Masson; +Cc: Paul Jackson, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 764 bytes --]
On Tue, 2004-08-10 11:22:10 -0400, Eric Masson <cool_kid@future-ericsoft.com>
wrote in message <4118E822.3000303@future-ericsoft.com>:
> Thanks for the pointer! My user mode program is running. Any idea how to
> control which console it shows up on?
The best idea for a usermode helper is to first close
stdin/stdout/stderr and re-open it with /dev/null...
If you need to communicate, write into some logfile.
MfG, JBG
--
Jan-Benedict Glaw jbglaw@lug-owl.de . +49-172-7608481 _ O _
"Eine Freie Meinung in einem Freien Kopf | Gegen Zensur | Gegen Krieg _ _ O
fuer einen Freien Staat voll Freier Bürger" | im Internet! | im Irak! O O O
ret = do_actions((curr | FREE_SPEECH) & ~(NEW_COPYRIGHT_LAW | DRM | TCPA));
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 189 bytes --]
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Fork and Exec a process within the kernel
2004-08-10 16:21 ` Paul Jackson
@ 2004-08-10 18:20 ` Lee Revell
2004-08-10 19:03 ` Richard B. Johnson
1 sibling, 0 replies; 13+ messages in thread
From: Lee Revell @ 2004-08-10 18:20 UTC (permalink / raw)
To: Paul Jackson; +Cc: Eric Masson, linux-kernel
On Tue, 2004-08-10 at 12:21, Paul Jackson wrote:
> > My user mode program is running.
>
> Good.
>
> > Any idea how to control which console it shows up on?
>
> No clue.
OK, ignore the peanut gallery, this is the real answer:
./foo > /dev/tty1
See /etc/syslog.conf on Debian for another example. Anywhere you could
write to a file you can write to /dev/tty$FOO and it will do the right
thing.
UNIX is full of stuff like this. Pretty cool, huh?
Lee
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Fork and Exec a process within the kernel
2004-08-10 16:21 ` Paul Jackson
2004-08-10 18:20 ` Lee Revell
@ 2004-08-10 19:03 ` Richard B. Johnson
2004-08-11 9:51 ` Erik Mouw
1 sibling, 1 reply; 13+ messages in thread
From: Richard B. Johnson @ 2004-08-10 19:03 UTC (permalink / raw)
To: Paul Jackson; +Cc: Eric Masson, linux-kernel
On Tue, 10 Aug 2004, Paul Jackson wrote:
> > My user mode program is running.
>
> Good.
>
> > Any idea how to control which console it shows up on?
>
> No clue.
>
> --
/dev/console is a symlink to /dev/tty0.
Alt-F1 = /dev/tty0
Alt-F2 = /dev/tty1
Alt-F3 = /dev/tty2
... etc.
struct termios term;
tcgetattr(0, &term); // Get old terminal characteristics
(void)close(0); // Close old terminal(s)
(void)close(1);
(void)close(2);
fd = open("/dev/console", O_RDWR);
tcsetattr(fd, &term); // Restore characteristics
dup2(fd, 0);
dup2(fd, 1);
dup2(fd, 2);
Cheers,
Dick Johnson
Penguin : Linux version 2.4.26 on an i686 machine (5570.56 BogoMips).
Note 96.31% of all statistics are fiction.
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Fork and Exec a process within the kernel
2004-08-10 19:03 ` Richard B. Johnson
@ 2004-08-11 9:51 ` Erik Mouw
2004-08-11 11:24 ` Richard B. Johnson
0 siblings, 1 reply; 13+ messages in thread
From: Erik Mouw @ 2004-08-11 9:51 UTC (permalink / raw)
To: Richard B. Johnson; +Cc: Paul Jackson, Eric Masson, linux-kernel
On Tue, Aug 10, 2004 at 03:03:08PM -0400, Richard B. Johnson wrote:
> /dev/console is a symlink to /dev/tty0.
Please don't mislead newbies, Richard. /dev/console is NOT a link to
/dev/tty0, it's a completely different device:
erik@abra2:~ >ls -l /dev/console
crw------- 1 root tty 5, 1 Apr 7 09:13 /dev/console
erik@abra2:~ >ls -l /dev/tty0
crw------- 1 root tty 4, 0 Feb 10 2000 /dev/tty0
On x86 desktop systems console output usually comes on the virtual
terminals, but you can also use serial console. My embedded StrongARM
board only has serial console.
> struct termios term;
>
> tcgetattr(0, &term); // Get old terminal characteristics
> (void)close(0); // Close old terminal(s)
> (void)close(1);
> (void)close(2);
> fd = open("/dev/console", O_RDWR);
And what happens when you have console on a device that's not a serial
port like a line printer?
Erik
--
+-- Erik Mouw -- www.harddisk-recovery.com -- +31 70 370 12 90 --
| Lab address: Delftechpark 26, 2628 XH, Delft, The Netherlands
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Fork and Exec a process within the kernel
2004-08-11 9:51 ` Erik Mouw
@ 2004-08-11 11:24 ` Richard B. Johnson
2004-08-11 11:41 ` Erik Mouw
0 siblings, 1 reply; 13+ messages in thread
From: Richard B. Johnson @ 2004-08-11 11:24 UTC (permalink / raw)
To: Erik Mouw; +Cc: Paul Jackson, Eric Masson, linux-kernel
On Wed, 11 Aug 2004, Erik Mouw wrote:
> On Tue, Aug 10, 2004 at 03:03:08PM -0400, Richard B. Johnson wrote:
> > /dev/console is a symlink to /dev/tty0.
>
> Please don't mislead newbies, Richard. /dev/console is NOT a link to
> /dev/tty0, it's a completely different device:
>
> erik@abra2:~ >ls -l /dev/console
> crw------- 1 root tty 5, 1 Apr 7 09:13 /dev/console
> erik@abra2:~ >ls -l /dev/tty0
> crw------- 1 root tty 4, 0 Feb 10 2000 /dev/tty0
>
Bullshit. I know how to use `file`.
Script started on Wed Aug 11 07:21:39 2004
# file /dev/console
/dev/console: symbolic link to /dev/tty0
# exit
Script done on Wed Aug 11 07:21:51 2004
> On x86 desktop systems console output usually comes on the virtual
> terminals, but you can also use serial console. My embedded StrongARM
> board only has serial console.
>
Then that's your problem.
> > struct termios term;
> >
> > tcgetattr(0, &term); // Get old terminal characteristics
> > (void)close(0); // Close old terminal(s)
> > (void)close(1);
> > (void)close(2);
> > fd = open("/dev/console", O_RDWR);
>
> And what happens when you have console on a device that's not a serial
> port like a line printer?
>
>
> Erik
>
It will still work but there is no input and it can't be turned
into a "controlling terminal".
Cheers,
Dick Johnson
Penguin : Linux version 2.4.26 on an i686 machine (5570.56 BogoMips).
Note 96.31% of all statistics are fiction.
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Fork and Exec a process within the kernel
2004-08-11 11:24 ` Richard B. Johnson
@ 2004-08-11 11:41 ` Erik Mouw
2004-08-11 11:55 ` Richard B. Johnson
0 siblings, 1 reply; 13+ messages in thread
From: Erik Mouw @ 2004-08-11 11:41 UTC (permalink / raw)
To: Richard B. Johnson; +Cc: Paul Jackson, Eric Masson, linux-kernel
On Wed, Aug 11, 2004 at 07:24:42AM -0400, Richard B. Johnson wrote:
> On Wed, 11 Aug 2004, Erik Mouw wrote:
> > Please don't mislead newbies, Richard. /dev/console is NOT a link to
> > /dev/tty0, it's a completely different device:
> >
> > erik@abra2:~ >ls -l /dev/console
> > crw------- 1 root tty 5, 1 Apr 7 09:13 /dev/console
> > erik@abra2:~ >ls -l /dev/tty0
> > crw------- 1 root tty 4, 0 Feb 10 2000 /dev/tty0
> >
>
> Bullshit. I know how to use `file`.
>
> Script started on Wed Aug 11 07:21:39 2004
> # file /dev/console
> /dev/console: symbolic link to /dev/tty0
It might be a symlink on your machine, but that doesn't mean it's the
right way. For almost 7 years, /dev/console is a separate device, not a
symlink. Here's the relevant section from Documentation/devices.txt:
The console device, /dev/console, is the device to which system
messages should be sent, and on which logins should be permitted in
single-user mode. Starting with Linux 2.1.71, /dev/console is managed
by the kernel; for previous versions it should be a symbolic link to
either /dev/tty0, a specific virtual console such as /dev/tty1, or to
a serial port primary (tty*, not cu*) device, depending on the
configuration of the system.
Linux-2.1.71 was released on December 4, 1997. In your signature you
claim to run linux-2.4.26. Please update your system.
Erik
--
+-- Erik Mouw -- www.harddisk-recovery.com -- +31 70 370 12 90 --
| Lab address: Delftechpark 26, 2628 XH, Delft, The Netherlands
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Fork and Exec a process within the kernel
2004-08-11 11:41 ` Erik Mouw
@ 2004-08-11 11:55 ` Richard B. Johnson
2004-08-11 12:51 ` Erik Mouw
2004-08-11 15:24 ` Alan Cox
0 siblings, 2 replies; 13+ messages in thread
From: Richard B. Johnson @ 2004-08-11 11:55 UTC (permalink / raw)
To: Erik Mouw; +Cc: Paul Jackson, Eric Masson, linux-kernel
On Wed, 11 Aug 2004, Erik Mouw wrote:
> On Wed, Aug 11, 2004 at 07:24:42AM -0400, Richard B. Johnson wrote:
> > On Wed, 11 Aug 2004, Erik Mouw wrote:
> > > Please don't mislead newbies, Richard. /dev/console is NOT a link to
> > > /dev/tty0, it's a completely different device:
> > >
> > > erik@abra2:~ >ls -l /dev/console
> > > crw------- 1 root tty 5, 1 Apr 7 09:13 /dev/console
> > > erik@abra2:~ >ls -l /dev/tty0
> > > crw------- 1 root tty 4, 0 Feb 10 2000 /dev/tty0
> > >
> >
> > Bullshit. I know how to use `file`.
> >
> > Script started on Wed Aug 11 07:21:39 2004
> > # file /dev/console
> > /dev/console: symbolic link to /dev/tty0
>
> It might be a symlink on your machine, but that doesn't mean it's the
> right way. For almost 7 years, /dev/console is a separate device, not a
> symlink. Here's the relevant section from Documentation/devices.txt:
>
> The console device, /dev/console, is the device to which system
> messages should be sent, and on which logins should be permitted in
> single-user mode. Starting with Linux 2.1.71, /dev/console is managed
> by the kernel; for previous versions it should be a symbolic link to
> either /dev/tty0, a specific virtual console such as /dev/tty1, or to
> a serial port primary (tty*, not cu*) device, depending on the
> configuration of the system.
>
> Linux-2.1.71 was released on December 4, 1997. In your signature you
> claim to run linux-2.4.26. Please update your system.
>
>
> Erik
RedHat is NOT Linux. The MAJOR-MINOR 5.1 used in RedHat for the
console has a very serious problem for anybody doing development
work. If there are any kernel messages, they go to __all__ open
terminals. This means that the only "quiet" terminals that may be
available to kill off a runaway process are available iff you can
log in over the network.
Most everybody I know, who does serious development work, and
certainly those who want to control where the %*)&$#!@ kernel
messages go, will make sure they go to the "ALT-F1" as I have
shown. The original query was about how to make kernel messages
go to where, i.e., what VT do they come from. I have shown
how you can control where they go.
Now, if you look at the kernel source, you will note that
just prior to attempting to exec /sbin/init, /dev/console
is opened. This means that you can properly use whatever
you want if you continue to use a sym-link.
Cheers,
Dick Johnson
Penguin : Linux version 2.4.26 on an i686 machine (5570.56 BogoMips).
Note 96.31% of all statistics are fiction.
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Fork and Exec a process within the kernel
2004-08-11 11:55 ` Richard B. Johnson
@ 2004-08-11 12:51 ` Erik Mouw
2004-08-11 15:24 ` Alan Cox
1 sibling, 0 replies; 13+ messages in thread
From: Erik Mouw @ 2004-08-11 12:51 UTC (permalink / raw)
To: Richard B. Johnson; +Cc: Paul Jackson, Eric Masson, linux-kernel
On Wed, Aug 11, 2004 at 07:55:52AM -0400, Richard B. Johnson wrote:
> RedHat is NOT Linux. The MAJOR-MINOR 5.1 used in RedHat for the
> console has a very serious problem for anybody doing development
> work. If there are any kernel messages, they go to __all__ open
> terminals. This means that the only "quiet" terminals that may be
> available to kill off a runaway process are available iff you can
> log in over the network.
If you don't want console messages, you just disable console at all, or
you use a serial console (using the "console=" on the kernel command
line), or you adjust the kernel console log level. Please have a look
at the "dmesg" manual page, especially the "-n" parameter. In emergency
situations, Alt-Sysrq-[0-8] will allow you to do the same (on VGA
consoles for PCs, that is. for serial consoles use Break-[0-8]).
> Most everybody I know, who does serious development work, and
> certainly those who want to control where the %*)&$#!@ kernel
> messages go, will make sure they go to the "ALT-F1" as I have
> shown.
Not all the world is a PC, there is a lot of linux beyond x86. Looks to
me like you haven't done development on embedded systems that don't
have any VGA terminal at all.
Getting kernel messages on a certain pseudo tty is just a matter of
supplying the correct "console=" paramater to the kernel. For example:
"console=tty1" will get your console output on pseudo tty 1.
Alternatively, you can configure syslog to write all kernel messages to
a pseudo tty.
> The original query was about how to make kernel messages
> go to where, i.e., what VT do they come from. I have shown
> how you can control where they go.
Here is the original question:
Thanks for the pointer! My user mode program is running. Any idea how to
control which console it shows up on?
No reference on how to get kernel messages somewhere.
> Now, if you look at the kernel source, you will note that
> just prior to attempting to exec /sbin/init, /dev/console
> is opened. This means that you can properly use whatever
> you want if you continue to use a sym-link.
That was true for linux < 2.1.71, which was released almost 7 years
ago. Things have changed. Newer kernels use the "console=" kernel
command line to select the console. With multiple the "console="
parameter, you can even have mutiple consoles.
Erik
--
+-- Erik Mouw -- www.harddisk-recovery.com -- +31 70 370 12 90 --
| Lab address: Delftechpark 26, 2628 XH, Delft, The Netherlands
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Fork and Exec a process within the kernel
2004-08-11 11:55 ` Richard B. Johnson
2004-08-11 12:51 ` Erik Mouw
@ 2004-08-11 15:24 ` Alan Cox
1 sibling, 0 replies; 13+ messages in thread
From: Alan Cox @ 2004-08-11 15:24 UTC (permalink / raw)
To: root; +Cc: Erik Mouw, Paul Jackson, Eric Masson, Linux Kernel Mailing List
On Mer, 2004-08-11 at 12:55, Richard B. Johnson wrote:
> RedHat is NOT Linux. The MAJOR-MINOR 5.1 used in RedHat for the
> console has a very serious problem for anybody doing development
Actually you might want to
a) man sysklogd
b) check devices.txt distributed with the kernel.
The former will explain why you are wrong and how to channel log
messages, the latter will explain how you are further wrong.
^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2004-08-11 16:26 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-08-09 21:03 Fork and Exec a process within the kernel Eric Masson
2004-08-09 23:10 ` Paul Jackson
2004-08-10 15:22 ` Eric Masson
2004-08-10 16:21 ` Paul Jackson
2004-08-10 18:20 ` Lee Revell
2004-08-10 19:03 ` Richard B. Johnson
2004-08-11 9:51 ` Erik Mouw
2004-08-11 11:24 ` Richard B. Johnson
2004-08-11 11:41 ` Erik Mouw
2004-08-11 11:55 ` Richard B. Johnson
2004-08-11 12:51 ` Erik Mouw
2004-08-11 15:24 ` Alan Cox
2004-08-10 16:33 ` Jan-Benedict Glaw
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox