[f21/master] Only allow one anaconda instance (#1146735)

Brian C. Lane bcl at redhat.com
Tue Oct 7 00:38:29 UTC 2014


On Mon, Oct 06, 2014 at 02:18:17PM -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")

I'd extend this a bit to see if the PID in the file is actually running.
Or to be even more strict, see if it is actually anaconda.

We may be running in an environment where a crash leaves the pid behind
(eg. anaconda --image from a normal system).

-- 
Brian C. Lane | Anaconda Team | IRC: bcl #anaconda | Port Orchard, WA (PST8PDT)


More information about the anaconda-patches mailing list