[f21/master] Only allow one anaconda instance (#1146735)
Vratislav Podzimek
vpodzime at redhat.com
Mon Oct 6 19:39:30 UTC 2014
On Mon, 2014-10-06 at 14:18 -0400, David Shea wrote:
> Display a graphical error dialog if we're in the sort of environment
> that can display graphical dialogs early on, otherwise just print a
> message and bomb out.
> ---
> anaconda | 42 ++++++++++++++++++++++++++++++++++++++----
> 1 file changed, 38 insertions(+), 4 deletions(-)
>
> diff --git a/anaconda b/anaconda
> index beeaabd..1507bbf 100755
> --- a/anaconda
> +++ b/anaconda
> @@ -44,7 +44,7 @@ if ("debug=1" in proc_cmdline) or ("debug" in proc_cmdline):
> cov.start()
>
>
> -import atexit, sys, os, time, signal
> +import atexit, sys, os, time, signal, stat, errno
>
> def exitHandler(rebootData, storage):
> # Clear the list of watched PIDs.
> @@ -81,6 +81,9 @@ def exitHandler(rebootData, storage):
> uninhibit_screensaver(anaconda.dbus_session_connection, anaconda.dbus_inhibit_id)
> anaconda.dbus_inhibit_id = None
>
> + # Clean up the PID file
> + os.unlink("/var/run/anaconda.pid")
> +
> if not flags.imageInstall and not flags.livecdInstall \
> and not flags.dirInstall:
> from pykickstart.constants import KS_SHUTDOWN, KS_WAIT
> @@ -841,9 +844,40 @@ if __name__ == "__main__":
> # make sure we have /var/log soon, some programs fail to start without it
> iutil.mkdirChain("/var/log")
>
> - pidfile = open("/var/run/anaconda.pid", "w")
> - pidfile.write("%s\n" % (os.getpid(),))
> - del pidfile
> + # Attempt to create the pidfile
> + # Set all of the read/write bits and let umask make it make sense
> + try:
> + pidfile = os.open("/var/run/anaconda.pid", os.O_WRONLY|os.O_CREAT|os.O_EXCL,
> + stat.S_IRUSR|stat.S_IWUSR|stat.S_IRGRP|stat.S_IWGRP|stat.S_IROTH|stat.S_IWOTH)
> + os.write(pidfile, "%s\n" % os.getpid())
> + os.close(pidfile)
> + except OSError as e:
> + # If the failure was anything other than EEXIST during the open call,
> + # just re-raise the exception
> + if e.errno != errno.EEXIST:
> + raise
> +
> + log.error("/var/run/anaconda.pid already exists, exiting")
> +
> + # If we have a $DISPLAY and zenity is available, we may be running in
> + # a live environment and we can display an error dialog. Otherwise
> + # just print an error.
> + if "DISPLAY" in os.environ and os.access("/usr/bin/zenity", os.X_OK):
> + # The module-level _() calls are ok here because the language may
> + # be set from the live environment in this case, and anaconda's
> + # language setup hasn't happened yet.
> + # pylint: disable=found-_-in-module-class
> + iutil.execWithRedirect("zenity",
> + ["--error", "--title", _("Unable to create PID file"), "--text",
> + _("Anaconda is unable to create /var/run/anaconda.pid because the file" +
> + " already exists. Anaconda is already running, or a previous instance" +
> + " of anaconda has crashed.")])
> + else:
> + print("/var/run/anaconda.pid already exists, exiting")
> +
> + iutil.ipmi_report(constants.IPMI_FAILED)
> + sys.exit(1)
> +
> # add our own additional signal handlers
> signal.signal(signal.SIGHUP, startDebugger)
ACK.
--
Vratislav Podzimek
Anaconda Rider | Red Hat, Inc. | Brno - Czech Republic
More information about the anaconda-patches
mailing list