Skip to content

Commit

Permalink
#3099 clean all when no argument is specified
Browse files Browse the repository at this point in the history
also bail out if the server pid is still alive,
but don't bail out if we are killing the xvfb pid
  • Loading branch information
totaam committed Dec 16, 2021
1 parent 05ae985 commit e5d719a
Showing 1 changed file with 39 additions and 13 deletions.
52 changes: 39 additions & 13 deletions xpra/scripts/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
)
from xpra.os_util import (
get_util_logger, getuid, getgid, get_username_for_uid,
bytestostr, use_tty,
bytestostr, use_tty, osexpand,
set_proc_title,
is_systemd_pid1,
WIN32, OSX, POSIX, SIGNAMES, is_Ubuntu,
Expand Down Expand Up @@ -2789,18 +2789,38 @@ def mdns_add(interface, _protocol, name, _stype, domain, host, address, port, te

def run_clean(opts, args):
no_gtk()
if args:
clean = args
kill_displays = True
else:
#TODO: find the sessions to clean:
clean = []
kill_displays = False
from xpra.scripts.server import get_session_dir
try:
uid = int(opts.uid)
except (ValueError, TypeError):
uid = getuid()
from xpra.scripts.server import get_session_dir
clean = {}
if args:
for display in args:
session_dir = get_session_dir(None, opts.sessions_dir, display, uid)
if not os.path.exists(session_dir) or not os.path.isdir(session_dir):
print("session %s not found" % (display,))
else:
clean[display] = session_dir
#the user specified the sessions to clean,
#so we can also kill the display:
kill_displays = True
else:
session_dir = osexpand(opts.sessions_dir)
if not os.path.exists(session_dir):
raise ValueError("cannot find sessions directory %r" % opts.sessions_dir)
#try to find all the session directories:
for x in os.listdir(session_dir):
d = os.path.join(session_dir, x)
if not os.path.isdir(d):
continue
try:
display = int(x)
except ValueError:
continue
else:
clean["%s" % x] = d
kill_displays = False
def kill_pid(pid):
if pid:
try:
Expand All @@ -2821,8 +2841,7 @@ def load_pid(session_dir, pid_filename):

#also clean client sockets?
dotxpra = DotXpra(opts.socket_dir, opts.socket_dirs)
for display in clean:
session_dir = get_session_dir(None, opts.sessions_dir, display, uid)
for display, session_dir in clean.items():
if not os.path.exists(session_dir):
print("session %s not found" % (display,))
continue
Expand All @@ -2831,7 +2850,14 @@ def load_pid(session_dir, pid_filename):
if state in (dotxpra.LIVE, dotxpra.INACCESSIBLE):
#this session is still active
#do not try to clean it!
print("session %s is %s" % (display, state))
if args:
print("session %s is %s" % (display, state))
print(" the session directory %r has not been removed" % session_dir)
continue
server_pid = load_pid(session_dir, "server.pid")
if server_pid and POSIX and not OSX and os.path.exists("/proc/%i" % server_pid):
print("server process for session %s is still running with pid %i" % (display, server_pid))
print(" the session directory %r has not been removed" % session_dir)
continue
try:
dno = int(display.lstrip(":"))
Expand All @@ -2851,7 +2877,7 @@ def load_pid(session_dir, pid_filename):
print(" run clean-displays to terminate it")
else:
print(" cowardly refusing to clean the session")
continue
continue
#print("session_dir: %s : %s" % (session_dir, state))
for pid_filename in ("dbus.pid", "pulseaudio.pid", ):
pid = load_pid(session_dir, pid_filename) #ie: "/run/user/1000/xpra/7/dbus.pid"
Expand Down

0 comments on commit e5d719a

Please sign in to comment.