Skip to content

Commit

Permalink
#1323: try harder not to leave an Xvfb behind if we fail to init the …
Browse files Browse the repository at this point in the history
…server: register close_display earlier so we kill the Xvfb if we start one, but only give it the inherited Xvfb pid once we're sure we will run the clean exit codepath

git-svn-id: https://xpra.org/svn/Xpra/trunk@13860 3bb7dfac-3a0b-4e04-842a-767bc560f471
  • Loading branch information
totaam committed Sep 25, 2016
1 parent e6cba77 commit 875ce71
Showing 1 changed file with 27 additions and 22 deletions.
49 changes: 27 additions & 22 deletions src/xpra/scripts/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -1149,6 +1149,7 @@ def run_server(error_cb, opts, mode, xpra_file, extra_args, desktop_display=None
xvfb_pid = None
xauth_data = None
if start_vfb:
assert not proxying
try:
xvfb, display_name, xauth_data = start_Xvfb(opts.xvfb, display_name, cwd)
except OSError as e:
Expand All @@ -1160,6 +1161,24 @@ def run_server(error_cb, opts, mode, xpra_file, extra_args, desktop_display=None
#always update as we may now have the "real" display name:
os.environ["DISPLAY"] = display_name

close_display = None
if not proxying:
def close_display():
# Close our display(s) first, so the server dying won't kill us.
# (if gtk has been loaded)
gtk_mod = sys.modules.get("gtk")
if gtk_mod:
for d in gtk_mod.gdk.display_manager_get().list_displays():
d.close()
if xvfb_pid:
log.info("killing xvfb with pid %s", xvfb_pid)
try:
os.kill(xvfb_pid, signal.SIGTERM)
except OSError as e:
log.info("failed to kill xvfb process with pid %s:", xvfb_pid)
log.info(" %s", e)
_cleanups.append(close_display)

# if pam is present, try to create a new session:
if os.name=="posix":
try:
Expand Down Expand Up @@ -1241,7 +1260,6 @@ def run_server(error_cb, opts, mode, xpra_file, extra_args, desktop_display=None

if clobber:
#get the saved pids and env
xvfb_pid = get_xvfb_pid()
dbus_pid = get_dbus_pid()
dbus_env = get_dbus_env()
else:
Expand Down Expand Up @@ -1330,24 +1348,6 @@ def kill_dbus():
for mode, listen_on in mdns_recs:
mdns_publish(display_name, mode, listen_on, mdns_info)

#we got this far so the sockets have initialized and
#the server should be able to manage the display
#from now on, if we exit without upgrading we will also kill the Xvfb
def close_display():
# Close our display(s) first, so the server dying won't kill us.
import gtk #@Reimport
for d in gtk.gdk.display_manager_get().list_displays():
d.close()
if xvfb_pid:
log.info("killing xvfb with pid %s", xvfb_pid)
try:
os.kill(xvfb_pid, signal.SIGTERM)
except OSError as e:
log.info("failed to kill xvfb process with pid %s:", xvfb_pid)
log.info(" %s", e)
if not proxying:
_cleanups.append(close_display)

try:
app._ssl_wrap_socket = wrap_socket_fn
app.original_desktop_display = desktop_display
Expand Down Expand Up @@ -1383,6 +1383,11 @@ def close_display():
app.init_when_ready(_when_ready)

try:
#from here on, we own the vfb, even if we inherited one:
if (starting or starting_desktop or upgrading) and clobber:
#and it will be killed if exit cleanly:
xvfb_pid = get_xvfb_pid()

log("running %s", app.run)
e = app.run()
log("%s()=%s", app.run, e)
Expand All @@ -1394,10 +1399,10 @@ def close_display():
e = -128
if e>0:
# Upgrading/exiting, so leave X and dbus servers running
if close_display in _cleanups:
if close_display:
_cleanups.remove(close_display)
if kill_dbus:
_cleanups.remove(kill_dbus)
if kill_dbus:
_cleanups.remove(kill_dbus)
from xpra.server.server_core import ServerCore
if e==ServerCore.EXITING_CODE:
log.info("exiting: not cleaning up Xvfb")
Expand Down

0 comments on commit 875ce71

Please sign in to comment.