예제 #1
0
 def test_still_running():
     with timer(5):
         # Run something forever so we can kill it
         proc = util.startProgram(["/bin/sh", "-c", "while true; do sleep 1; done"])
         WatchProcesses.watch_process(proc, "test1")
         proc.kill()
         # Wait for the SIGCHLD
         signal.pause()
예제 #2
0
 def test_still_running():
     with timer(5):
         # Run something forever so we can kill it
         proc = util.startProgram(["/bin/sh", "-c", "while true; do sleep 1; done"])
         WatchProcesses.watch_process(proc, "test1")
         proc.kill()
         # Wait for the SIGCHLD
         signal.pause()
예제 #3
0
def exitHandler(rebootData, storage):
    # Clear the list of watched PIDs.
    from pyanaconda.core.process_watchers import WatchProcesses
    WatchProcesses.unwatch_all_processes()

    if flags.usevnc:
        vnc.shutdownServer()

    if "nokill" in kernel_arguments:
        util.vtActivate(1)
        print("anaconda halting due to nokill flag.")
        print("The system will be rebooted when you press Ctrl-Alt-Delete.")
        while True:
            time.sleep(10000)

    if anaconda.dbus_inhibit_id:
        from pyanaconda.screensaver import uninhibit_screensaver
        uninhibit_screensaver(anaconda.dbus_session_connection,
                              anaconda.dbus_inhibit_id)
        anaconda.dbus_inhibit_id = None

    # Unsetup the payload, which most usefully unmounts live images
    if anaconda.payload:
        anaconda.payload.unsetup()

    # Unmount the filesystems.
    if not conf.target.is_hardware:
        anaconda.storage.umount_filesystems(swapoff=False)

    # Tear down disk images.
    if conf.target.is_image:
        anaconda.storage.devicetree.teardown_disk_images()

    # Clean up the PID file
    if pidfile:
        pidfile.close()

    anaconda.dbus_launcher.stop()

    if conf.system.can_reboot:
        from pykickstart.constants import KS_SHUTDOWN, KS_WAIT

        if flags.eject or rebootData.eject:
            for cdrom in (d for d in storage.devices if d.type == "cdrom"):
                if util.get_mount_paths(cdrom.path):
                    util.dracut_eject(cdrom.path)

        if flags.kexec:
            util.execWithRedirect("systemctl", ["--no-wall", "kexec"])
            while True:
                time.sleep(10000)
        elif rebootData.action == KS_SHUTDOWN:
            util.execWithRedirect("systemctl", ["--no-wall", "poweroff"])
        elif rebootData.action == KS_WAIT:
            util.execWithRedirect("systemctl", ["--no-wall", "halt"])
        else:  # reboot action is KS_REBOOT or None
            util.execWithRedirect("systemctl", ["--no-wall", "reboot"])
예제 #4
0
def startX(argv, output_redirect=None, timeout=X_TIMEOUT):
    """ Start X and return once X is ready to accept connections.

        X11, if SIGUSR1 is set to SIG_IGN, will send SIGUSR1 to the parent
        process once it is ready to accept client connections. This method
        sets that up and waits for the signal or bombs out if nothing happens
        for a minute. The process will also be added to the list of watched
        processes.

        :param argv: The command line to run, as a list
        :param output_redirect: file or file descriptor to redirect stdout and stderr to
        :param timeout: Number of seconds to timing out.
    """
    # Use a list so the value can be modified from the handler function
    x11_started = [False]

    def sigusr1_handler(num, frame):
        log.debug("X server has signalled a successful start.")
        x11_started[0] = True

    # Fail after, let's say a minute, in case something weird happens
    # and we don't receive SIGUSR1
    def sigalrm_handler(num, frame):
        # Check that it didn't make it under the wire
        if x11_started[0]:
            return
        log.error("Timeout trying to start %s", argv[0])
        raise ExitError("Timeout trying to start %s" % argv[0])

    # preexec_fn to add the SIGUSR1 handler in the child
    def sigusr1_preexec():
        signal.signal(signal.SIGUSR1, signal.SIG_IGN)

    try:
        old_sigusr1_handler = signal.signal(signal.SIGUSR1, sigusr1_handler)
        old_sigalrm_handler = signal.signal(signal.SIGALRM, sigalrm_handler)

        # Start the timer
        log.debug("Setting timeout %s seconds for starting X.", timeout)
        signal.alarm(timeout)

        childproc = startProgram(argv, stdout=output_redirect, stderr=output_redirect,
                                 preexec_fn=sigusr1_preexec)
        WatchProcesses.watch_process(childproc, argv[0])

        # Wait for SIGUSR1
        while not x11_started[0]:
            signal.pause()

    finally:
        # Put everything back where it was
        signal.alarm(0)
        signal.signal(signal.SIGUSR1, old_sigusr1_handler)
        signal.signal(signal.SIGALRM, old_sigalrm_handler)
예제 #5
0
def start_user_systemd():
    """Start the user instance of systemd.

    The service org.a11y.Bus runs the dbus-broker-launch in
    the user scope that requires the user instance of systemd.
    """
    if not conf.system.can_start_user_systemd:
        log.debug("Don't start the user instance of systemd.")
        return

    childproc = util.startProgram(["/usr/lib/systemd/systemd", "--user"])
    WatchProcesses.watch_process(childproc, "systemd")
예제 #6
0
def do_startup_x11_actions():
    """Start the window manager.

    When metacity actually connects to the X server is unknowable, but
    fortunately it doesn't matter. metacity does not need to be the first
    connection to Xorg, and if anaconda starts up before metacity, metacity
    will just take over and maximize the window and make everything right,
    fingers crossed.
    Add XDG_DATA_DIRS to the environment to pull in our overridden schema
    files.
    """
    datadir = os.environ.get('ANACONDA_DATADIR', '/usr/share/anaconda')
    if 'XDG_DATA_DIRS' in os.environ:
        xdg_data_dirs = datadir + '/window-manager:' + os.environ['XDG_DATA_DIRS']
    else:
        xdg_data_dirs = datadir + '/window-manager:/usr/share'

    childproc = util.startProgram(["metacity", "--display", ":1", "--sm-disable"],
                                  env_add={'XDG_DATA_DIRS': xdg_data_dirs})
    WatchProcesses.watch_process(childproc, "metacity")
예제 #7
0
def do_startup_x11_actions():
    """Start the window manager.

    When metacity actually connects to the X server is unknowable, but
    fortunately it doesn't matter. metacity does not need to be the first
    connection to Xorg, and if anaconda starts up before metacity, metacity
    will just take over and maximize the window and make everything right,
    fingers crossed.
    Add XDG_DATA_DIRS to the environment to pull in our overridden schema
    files.
    """
    datadir = os.environ.get('ANACONDA_DATADIR', '/usr/share/anaconda')
    if 'XDG_DATA_DIRS' in os.environ:
        xdg_data_dirs = datadir + '/window-manager:' + os.environ['XDG_DATA_DIRS']
    else:
        xdg_data_dirs = datadir + '/window-manager:/usr/share'

    childproc = util.startProgram(["metacity", "--display", ":1", "--sm-disable"],
                                  env_add={'XDG_DATA_DIRS': xdg_data_dirs})
    WatchProcesses.watch_process(childproc, "metacity")
예제 #8
0
    def test_watch_process(self):
        """Test watchProcess"""
        def test_still_running():
            with timer(5):
                # Run something forever so we can kill it
                proc = util.startProgram(
                    ["/bin/sh", "-c", "while true; do sleep 1; done"])
                WatchProcesses.watch_process(proc, "test1")
                proc.kill()
                # Wait for the SIGCHLD
                signal.pause()

        with pytest.raises(ExitError):
            test_still_running()

        # Make sure watchProcess checks that the process has not already exited
        with timer(5):
            proc = util.startProgram(["true"])
            proc.communicate()
        with pytest.raises(ExitError):
            WatchProcesses.watch_process(proc, "test2")
예제 #9
0
def exitHandler(rebootData):
    # Clear the list of watched PIDs.
    from pyanaconda.core.process_watchers import WatchProcesses
    WatchProcesses.unwatch_all_processes()

    if flags.usevnc:
        vnc.shutdownServer()

    if "nokill" in kernel_arguments:
        util.vtActivate(1)
        print("anaconda halting due to nokill flag.")
        print("The system will be rebooted when you press Ctrl-Alt-Delete.")
        while True:
            time.sleep(10000)

    if anaconda.dbus_inhibit_id:
        from pyanaconda.screensaver import uninhibit_screensaver
        uninhibit_screensaver(anaconda.dbus_session_connection, anaconda.dbus_inhibit_id)
        anaconda.dbus_inhibit_id = None

    # Unsetup the payload, which most usefully unmounts live images
    if anaconda.payload:
        anaconda.payload.unsetup()

    # Collect all optical media.
    from pyanaconda.modules.common.constants.objects import DEVICE_TREE
    from pyanaconda.modules.common.structures.storage import DeviceData
    device_tree = STORAGE.get_proxy(DEVICE_TREE)
    optical_media = []

    for device_name in device_tree.FindOpticalMedia():
        device_data = DeviceData.from_structure(
            device_tree.GetDeviceData(device_name)
        )
        optical_media.append(device_data.path)

    # Tear down the storage module.
    storage_proxy = STORAGE.get_proxy()

    for task_path in storage_proxy.TeardownWithTasks():
        task_proxy = STORAGE.get_proxy(task_path)
        sync_run_task(task_proxy)

    # Stop the DBus session.
    anaconda.dbus_launcher.stop()

    # Clean up the PID file
    if pidfile:
        pidfile.close()

    # Reboot the system.
    if conf.system.can_reboot:
        from pykickstart.constants import KS_SHUTDOWN, KS_WAIT

        if flags.eject or rebootData.eject:
            for device_path in optical_media:
                if util.get_mount_paths(device_path):
                    util.dracut_eject(device_path)

        if flags.kexec:
            util.execWithRedirect("systemctl", ["--no-wall", "kexec"])
            while True:
                time.sleep(10000)
        elif rebootData.action == KS_SHUTDOWN:
            util.execWithRedirect("systemctl", ["--no-wall", "poweroff"])
        elif rebootData.action == KS_WAIT:
            util.execWithRedirect("systemctl", ["--no-wall", "halt"])
        else:  # reboot action is KS_REBOOT or None
            util.execWithRedirect("systemctl", ["--no-wall", "reboot"])
예제 #10
0
def exitHandler(rebootData, storage):
    # Clear the list of watched PIDs.
    from pyanaconda.core.process_watchers import WatchProcesses
    WatchProcesses.unwatch_all_processes()

    # stop and save coverage here b/c later the file system may be unavailable
    if coverage is not None:
        cov.stop()
        if os.path.isdir('/mnt/sysimage/root'):
            cov.save()

    if flags.usevnc:
        vnc.shutdownServer()

    if "nokill" in flags.cmdline:
        util.vtActivate(1)
        print("anaconda halting due to nokill flag.")
        print("The system will be rebooted when you press Ctrl-Alt-Delete.")
        while True:
            time.sleep(10000)

    if anaconda.dbus_inhibit_id:
        from pyanaconda.screensaver import uninhibit_screensaver
        uninhibit_screensaver(anaconda.dbus_session_connection,
                              anaconda.dbus_inhibit_id)
        anaconda.dbus_inhibit_id = None

    # Unsetup the payload, which most usefully unmounts live images
    if anaconda.payload:
        anaconda.payload.unsetup()

    if not conf.target.is_hardware:
        anaconda.storage.umount_filesystems(swapoff=False)
        devicetree = anaconda.storage.devicetree
        devicetree.teardown_all()
        for imageName in devicetree.disk_images:
            dev = devicetree.get_device_by_name(imageName)
            for loop in dev.parents:
                loop.controllable = True
            dev.deactivate(recursive=True)

    # Clean up the PID file
    if pidfile:
        pidfile.close()

    anaconda.dbus_launcher.stop()

    if conf.system.can_reboot:
        from pykickstart.constants import KS_SHUTDOWN, KS_WAIT

        if flags.eject or rebootData.eject:
            for cdrom in (d for d in storage.devices if d.type == "cdrom"):
                if util.get_mount_paths(cdrom.path):
                    util.dracut_eject(cdrom.path)

        if flags.kexec:
            util.execWithRedirect("systemctl", ["--no-wall", "kexec"])
            while True:
                time.sleep(10000)
        elif rebootData.action == KS_SHUTDOWN:
            util.execWithRedirect("systemctl", ["--no-wall", "poweroff"])
        elif rebootData.action == KS_WAIT:
            util.execWithRedirect("systemctl", ["--no-wall", "halt"])
        else:  # reboot action is KS_REBOOT or None
            util.execWithRedirect("systemctl", ["--no-wall", "reboot"])
예제 #11
0
def startX(argv, output_redirect=None, timeout=X_TIMEOUT):
    """ Start X and return once X is ready to accept connections.

        X11, if SIGUSR1 is set to SIG_IGN, will send SIGUSR1 to the parent
        process once it is ready to accept client connections. This method
        sets that up and waits for the signal or bombs out if nothing happens
        for a minute. The process will also be added to the list of watched
        processes.

        :param argv: The command line to run, as a list
        :param output_redirect: file or file descriptor to redirect stdout and stderr to
        :param timeout: Number of seconds to timing out.
    """
    x11_status = X11Status()

    # Handle successful start before timeout
    def sigusr1_success_handler(num, frame):
        log.debug("X server has signalled a successful start.")
        x11_status.started = True

    # Fail after, let's say a minute, in case something weird happens
    # and we don't receive SIGUSR1
    def sigalrm_handler(num, frame):
        # Check that it didn't make it under the wire
        if x11_status.started:
            return
        x11_status.timed_out = True
        log.error("Timeout trying to start %s", argv[0])

    # Handle delayed start after timeout
    def sigusr1_too_late_handler(num, frame):
        if x11_status.timed_out:
            log.debug(
                "SIGUSR1 received after X server timeout. Switching back to tty1. "
                "SIGUSR1 now again initiates test of exception reporting.")
            signal.signal(signal.SIGUSR1, old_sigusr1_handler)

    # preexec_fn to add the SIGUSR1 handler in the child we are starting
    # see man page XServer(1), section "signals"
    def sigusr1_preexec():
        signal.signal(signal.SIGUSR1, signal.SIG_IGN)

    try:
        old_sigusr1_handler = signal.signal(signal.SIGUSR1,
                                            sigusr1_success_handler)
        old_sigalrm_handler = signal.signal(signal.SIGALRM, sigalrm_handler)

        # Start the timer
        log.debug("Setting timeout %s seconds for starting X.", timeout)
        signal.alarm(timeout)

        childproc = startProgram(argv,
                                 stdout=output_redirect,
                                 stderr=output_redirect,
                                 preexec_fn=sigusr1_preexec)
        WatchProcesses.watch_process(childproc, argv[0])

        # Wait for SIGUSR1 or SIGALRM
        while x11_status.needs_waiting():
            signal.pause()

    finally:
        # Stop the timer
        signal.alarm(0)
        signal.signal(signal.SIGALRM, old_sigalrm_handler)

        # Handle outcome of X start attempt
        if x11_status.started:
            signal.signal(signal.SIGUSR1, old_sigusr1_handler)
        elif x11_status.timed_out:
            signal.signal(signal.SIGUSR1, sigusr1_too_late_handler)
            # Kill Xorg because from now on we will not use it. It will exit only after sending
            # the signal, but at least we don't have to track that.
            WatchProcesses.unwatch_process(childproc)
            childproc.terminate()
            log.debug(
                "Exception handler test suspended to prevent accidental activation by "
                "delayed Xorg start. Next SIGUSR1 will be handled as delayed Xorg start."
            )
            # Raise an exception to notify the caller that things went wrong. This affects
            # particularly pyanaconda.display.do_startup_x11_actions(), where the window manager
            # is started immediately after this. The WM would just wait forever.
            raise TimeoutError("Timeout trying to start %s" % argv[0])
예제 #12
0
def exitHandler(rebootData, storage):
    # Clear the list of watched PIDs.
    from pyanaconda.core.process_watchers import WatchProcesses
    WatchProcesses.unwatch_all_processes()

    # stop and save coverage here b/c later the file system may be unavailable
    if coverage is not None:
        cov.stop()
        if os.path.isdir('/mnt/sysimage/root'):
            cov.save()

    if flags.usevnc:
        vnc.shutdownServer()

    if "nokill" in flags.cmdline:
        util.vtActivate(1)
        print("anaconda halting due to nokill flag.")
        print("The system will be rebooted when you press Ctrl-Alt-Delete.")
        while True:
            time.sleep(10000)

    if anaconda.dbus_inhibit_id:
        from pyanaconda.screensaver import uninhibit_screensaver
        uninhibit_screensaver(anaconda.dbus_session_connection, anaconda.dbus_inhibit_id)
        anaconda.dbus_inhibit_id = None

    # Unsetup the payload, which most usefully unmounts live images
    if anaconda.payload:
        anaconda.payload.unsetup()

    if not conf.target.is_hardware:
        anaconda.storage.umount_filesystems(swapoff=False)
        devicetree = anaconda.storage.devicetree
        devicetree.teardown_all()
        for imageName in devicetree.disk_images:
            dev = devicetree.get_device_by_name(imageName)
            for loop in dev.parents:
                loop.controllable = True
            dev.deactivate(recursive=True)

    # Clean up the PID file
    if pidfile:
        pidfile.close()

    anaconda.dbus_launcher.stop()

    if conf.system.can_reboot:
        from pykickstart.constants import KS_SHUTDOWN, KS_WAIT

        if flags.eject or rebootData.eject:
            for cdrom in (d for d in storage.devices if d.type == "cdrom"):
                if util.get_mount_paths(cdrom.path):
                    util.dracut_eject(cdrom.path)

        if flags.kexec:
            util.execWithRedirect("systemctl", ["--no-wall", "kexec"])
            while True:
                time.sleep(10000)
        elif rebootData.action == KS_SHUTDOWN:
            util.execWithRedirect("systemctl", ["--no-wall", "poweroff"])
        elif rebootData.action == KS_WAIT:
            util.execWithRedirect("systemctl", ["--no-wall", "halt"])
        else:  # reboot action is KS_REBOOT or None
            util.execWithRedirect("systemctl", ["--no-wall", "reboot"])