[Pkg-uml-devel] Patch: enables to run rootstrap in the background
Mattia Dongili
malattia at linux.it
Sat Nov 18 20:54:48 CET 2006
On Sat, Nov 18, 2006 at 05:51:06PM +0200, shaulka at 012.net.il wrote:
> Some words of explanation follow.
>
> --- rootstrap.orig 2006-11-18 03:53:54.000000000 +0200
> +++ rootstrap 2006-11-18 15:10:00.000000000 +0200
> @@ -92,11 +92,22 @@
>
> umlargs.extend(umlargs_extra)
>
> +if sys.stdin.isatty() \
> + and \
> + os.tcgetpgrp(sys.stdin.fileno()) != os.getpgrp():
> + (block_on_read,not_to_be_written_to) = os.pipe()
> + os.dup2(block_on_read, sys.stdin.fileno())
> +if sys.stdout.isatty() \
> + and \
> + os.tcgetpgrp(sys.stdout.fileno()) != os.getpgrp():
> + sink = open('/dev/null','w')
> + os.dup2(sink.fileno(), sys.stdout.fileno())
> +
> umlargs.extend(['con0=fd:0,fd:1',
> 'con=pts',
> - 'root=/dev/root',
> - 'rootflags=/',
> - 'rootfstype=hostfs',
> + 'root=/dev/root',
> + 'rootflags=/',
> + 'rootfstype=hostfs',
> 'ubd1=' + imagefile,
> 'init=/usr/lib/rootstrap/builder',
> 'devfs=nomount',
>
> Explanation:
> =========
>
> Note that rootstrap already duplicats the log file to stdout
> when the -o command line switch is invoked.
>
> if sys.std{in,out}.isatty()
>
> insures us that std{in,out} uses the terminal, which is the opposite of
> being redirected (to a file or a pipe).
>
> os.tcgetpgrp(sys.std{in,out}.fileno()) != os.getpgrp()
>
> tell us that rootstrap is running in the background.
>
> Those two idioms are my python equivalent of the C lines
> shown at http://www.ugcs.caltech.edu/manuals/libs/glibc-2.3.2/libc_581.html
>
> (block_on_read,not_to_be_written_to) = os.pipe()
>
> will make the file descriptor block_on_read blocks on read
> while the descriptor not_to_be_written_to will not be closed and
> not be written to.
> block_on_read + sink from the stdout duplication are assumed to
> be compatible with
>
> # Nothing - device=null
>
> This allows the device to be opened, in contrast to 'none', but reads
> will block, and writes will succeed and the data will be thrown out.
>
> from http://user-mode-linux.sourceforge.net/input.html.
hmmm, I was sure I tried something similar when I answered to your other
mail. Thanks for the suggestions.
Anyway, since uml already has some way of avoiding the tty usage why not
simply use "con=null con0=null" when rootstrap is not controlling the
terminal?
--
mattia
:wq!
More information about the Pkg-uml-devel
mailing list