[PATCH] Fix console= persistence, remove serial (#928269)

Will Woods wwoods at redhat.com
Tue Apr 9 21:20:56 UTC 2013


The 'serial' option was supposed to have been removed, but it got left
behind in a few places. Somehow it mutated into an argument to keep the
user-set "console=XXX" argument in the installed system?

This patch should straighten things out to match the intended behavior:
* "serial" is deprecated and ignored; try "console=ttyS0" instead.
* If you use "console=XXX" it will be preserved in the installed system.
* If multiple "console=XXX" args are used, the *last* one is preserved.

It might be kind of useful to be able to override this but I really
can't think of a use case for that right now, so I'm leaving it out.
You can always just remove it with a sed oneliner¹ or something.

Here's what the patch actually changes:
- Adds iutil.get_active_console()
- Uses that to fix iutil.isConsoleOnVirtualTerminal()²
- Sets BootLoader.console whenever 'console=XXX' is present, instead of
  only when flags.serial is set
- Uses iutil.isConsoleOnVirtualTerminal() instead of flags.serial to
  determine when it's OK to use GRUB splash
- Removes flags.serial, since it's now completely unused.

¹ e.g. `sed 's/console=\S*\s*//' /etc/grub*.cfg`
² Note the "XXX PJFIX", which means pjones owes me a beer.
---
 anaconda                 |  4 ----
 pyanaconda/bootloader.py | 14 +++++++-------
 pyanaconda/flags.py      |  1 -
 pyanaconda/iutil.py      | 17 +++++++++++------
 4 files changed, 18 insertions(+), 18 deletions(-)

diff --git a/anaconda b/anaconda
index a982214..b553de3 100755
--- a/anaconda
+++ b/anaconda
@@ -245,7 +245,6 @@ def parseOptions(argv=None, cmdline=None):
     op.add_option("--headless", dest="isHeadless", action="store_true", default=False)
     op.add_option("--nofb")
     op.add_option("--resolution", dest="runres", default=None)
-    op.add_option("--serial", action="store_true", default=False)
     op.add_option("--usefbx", dest="xdriver", action="store_const", const="fbdev")
     op.add_option("--vnc", action="store_true", default=False)
     op.add_option("--vncconnect")
@@ -441,9 +440,6 @@ def setupDisplay(anaconda, opts, addon_paths=None):
                 if len(cargs[1]) > 0:
                     vncS.vncconnectport = cargs[1]
 
-    if opts.serial:
-        flags.serial = True
-
     if opts.xdriver:
         anaconda.xdriver = opts.xdriver
         anaconda.writeXdriver(root="/")
diff --git a/pyanaconda/bootloader.py b/pyanaconda/bootloader.py
index 0d45d38..f5bda35 100644
--- a/pyanaconda/bootloader.py
+++ b/pyanaconda/bootloader.py
@@ -97,7 +97,9 @@ def parse_serial_opt(arg):
                 bits, and "f" is flow control ("r" for RTS or
                 omit it).  Default is "9600n8".
     but note that everything after the baud rate is optional, so these are
-    all valid: 9600, 19200n, 38400n8, 9600e7r"""
+    all valid: 9600, 19200n, 38400n8, 9600e7r.
+    Also note that the kernel assumes 1 stop bit; this can't be changed.
+    """
     opts = serial_opts()
     m = re.match('\d+', arg)
     if m is None:
@@ -877,11 +879,9 @@ class BootLoader(object):
 
     def _set_console(self):
         """ Set console options based on boot arguments. """
-        if flags.serial:
-            console = flags.cmdline.get("console", "ttyS0").split(",", 1)
-            self.console = console[0]
-            if len(console) > 1:
-                self.console_options = console[1]
+        console = flags.cmdline.get("console", "")
+        console = os.path.basename(console)
+        self.console, x, self.console_options = console.partition(",")
 
     def write_config_console(self, config):
         """Write console-related configuration lines."""
@@ -1129,7 +1129,7 @@ class GRUB(BootLoader):
 
         self.write_config_console(config)
 
-        if not flags.serial:
+        if iutil.isConsoleOnVirtualTerminal(self.console):
             splash = "splash.xpm.gz"
             splash_path = os.path.normpath("%s/boot/%s/%s" % (ROOT_PATH,
                                                         self.splash_dir,
diff --git a/pyanaconda/flags.py b/pyanaconda/flags.py
index f3aa78b..5ba291c 100644
--- a/pyanaconda/flags.py
+++ b/pyanaconda/flags.py
@@ -49,7 +49,6 @@ class Flags(object):
         self.dlabel = 0
         self.ibft = 1
         self.iscsi = 0
-        self.serial = 0
         self.usevnc = 0
         self.vncquestion = True
         self.mpath = 1
diff --git a/pyanaconda/iutil.py b/pyanaconda/iutil.py
index 51e9853..eecaf36 100644
--- a/pyanaconda/iutil.py
+++ b/pyanaconda/iutil.py
@@ -257,12 +257,17 @@ def mkdirChain(dir):
 
         log.error("could not create directory %s: %s" % (dir, e.strerror))
 
-def isConsoleOnVirtualTerminal():
-    # XXX PJFIX is there some way to ask the kernel this instead?
-    # XXX we don't want to have to import storage from here
-    if os.uname()[4].startswith("s390"):
-        return False
-    return not flags.serial
+def get_active_console(dev="console"):
+    while True:
+        try:
+            dev = open("/sys/class/tty/%s/active" % dev).read().split()[-1]
+        except (IOError, IndexError):
+            break
+    return dev
+
+def isConsoleOnVirtualTerminal(dev="console"):
+    console = get_active_console(dev)
+    return console.rstrip('01243456789') == 'tty'
 
 def strip_markup(text):
     if text.find("<") == -1:
-- 
1.8.1.4



More information about the anaconda-patches mailing list