Package: rootstrap Version: 0.3.24-1 Severity: wishlist Tags: patch The following enables debugging as well as logging with the -o switch or by redirecting the output to a file, while avoiding the case where the UML stdin is taken from the console and its stdout is directed to a file. I believe that preventing debugging when a log file is being used makes debugging more difficult. It also enables running rootstrap in the background. There is also a somewhat more obvious prompt for the UML terminal and a usage of UML exitcode.
--- builder.orig 2006-12-02 13:06:04.000000000 +0200 +++ builder.new 2006-12-02 13:16:54.000000000 +0200 @@ -42,35 +42,59 @@ script = scriptpat % module if os.path.exists(script): - # try to ease module debugging - # - # debug_exit == 0 --> exit and raise exception - # 1 --> re-eval script that failed - # 2 --> go on with next script - # X --> exit and raise exception while 1: print "Using rootstrap module %s from:\n\t%s" % (module,script) status = os.spawnle(os.P_WAIT, script, script, vars) if status != 0: - if "debug" in vars and vars["debug"] == "true": - print "Module %s failed with status %d: %s" % \ - (module,status,os.strerror(status)) - print "The exit value from the shell will be evaluated:" - print " 0 --> exit and raise exception" - print " 1 --> re-eval script that failed" - print " 2 --> go on with next script" - print " N --> exit and raise exception" - debug_exit = os.spawnle(os.P_WAIT, "/bin/sh", "/bin/sh", vars) - if debug_exit == 1: - continue - elif debug_exit == 2: - return - raise "rootstrap: Module '%s' failed, status %d: %s" % \ - (module,status,os.strerror(status)) + print "Module %s failed with status %d" % \ + (module,status) + + if 'debug' in vars and vars['debug'] == 'true': + if 'Redirected' not in \ + os.environ['backgroundRedirection'] and \ + 'Background' not in \ + os.environ['backgroundRedirection']: + if 'PS1' not in vars: + vars['PS1']='UML:\s-\\v\$ ' + # + # try to ease module debugging by spawning + # a shell and evaluatig its exit value + # + print "The exit value of this shell will be " \ + "evaluated as follows:\n" \ + "\t0 --> raise exception and exit UML\n"\ + "\t1 --> re-eval script that failed\n" \ + "\t2 --> go on with next script\n" \ + "\tX --> raise exception and exit\n" \ + "If you don't understand what this is " \ + "all about, type\n" \ + "\t\texit 0\n" \ + # debug_exit == 0 --> raise exception and exit + # 1 --> re-eval script that failed + # 2 --> go on with next script + # X --> raise exception and exit + debug_exit = os.spawnle(os.P_WAIT, \ + "/bin/sh", "/bin/sh", vars) + del vars['PS1'] + if debug_exit == 1: + continue + elif debug_exit == 2: + return + + else: + print "\n" \ + "\tRunning rootstrap interactively " \ + "with `debug=true' would have\n" \ + "\ttry to ease module debugging " \ + "by dropping into a UML terminal\n" + + raise "rootstrap: Module '%s' failed, status: %d" \ + % (module,status) return + print "rootstrap: unknown module: %s\n" % module raise "rootstrap: unknown module: %s\n" % module config = ConfigParser.ConfigParser() @@ -89,8 +113,14 @@ if config.has_section(module): for var in config.options(module): modulevars[var] = config.get(module,var) - - dispatch(module, modulevars) + + try: + dispatch(module, modulevars) + except: + exitcode = open('/proc/exitcode','w') + exitcode.write('1\n') + exitcode.close() + break os.system("mount -o remount,ro hostfs /") os.system("/sbin/halt -d -f") --- rootstrap.orig 2006-12-02 13:02:06.000000000 +0200 +++ rootstrap.new 2006-12-02 13:23:41.000000000 +0200 @@ -59,12 +59,8 @@ if opt in ('-s', '--image-size'): imagesize = long(arg) elif opt in ('-o',): - if not config.has_option('global', 'debug') or \ - config.get('global', 'debug') != 'true': - log = open(arg,"w") - os.dup2(log.fileno(), sys.stdout.fileno()) - else: - print "Ignoring -o because the debug option is set" + log = open(arg,"w") + os.dup2(log.fileno(), sys.stdout.fileno()) elif opt in ('-c', '--config'): umlargs_extra.append('rsconfig=%s' % os.path.abspath(os.path.expanduser(arg))) elif opt in ('-u', '--umlarg'): @@ -117,6 +113,27 @@ image.truncate(imagesize * 1048576L) image.close() +backgroundRedirection = '' +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()) + backgroundRedirection += 'Background' +if sys.stdout.isatty() and \ + os.tcgetpgrp(sys.stdout.fileno()) != os.getpgrp(): + sink = open('/dev/null','w') + os.dup2(sink.fileno(), sys.stdout.fileno()) + if 'Background' not in backgroundRedirection: + backgroundRedirection += 'Background' +if sys.stderr.isatty() and \ + os.tcgetpgrp(sys.stderr.fileno()) != os.getpgrp() and \ + 'Background' not in backgroundRedirection: + backgroundRedirection += 'Background' +if not ( sys.stdin.isatty() and sys.stdout.isatty() and \ + sys.stderr.isatty() ): + backgroundRedirection += 'Redirected' +umlargs.append('backgroundRedirection=%s' % backgroundRedirection) + if os.spawnvpe(os.P_WAIT,umlargs[0], umlargs, os.environ) != 0: sys.stderr.write("UML exited with non-zero status, aborting\n") sys.exit(1) As an aside, those issues are also related to using pseudo terminals. Perhaps rootstrap should have used python's pty module. -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]