Skip to content

Commit

Permalink
#888: use "auto" value for log-dir so we can choose at runtime which …
Browse files Browse the repository at this point in the history
…directory to use for log files (Xorg's and ours)

git-svn-id: https://xpra.org/svn/Xpra/trunk@14071 3bb7dfac-3a0b-4e04-842a-767bc560f471
  • Loading branch information
totaam committed Oct 9, 2016
1 parent 933587d commit 68a2514
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 32 deletions.
1 change: 1 addition & 0 deletions src/etc/xpra/conf.d/60_server.conf.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# Server Options:

# Directory for server log files:
#log-dir = /var/run/user/$UID
#log-dir = ~/.xpra
#log-dir = /tmp
log-dir = %(log_dir)s
Expand Down
9 changes: 6 additions & 3 deletions src/xpra/platform/darwin/paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,16 +98,19 @@ def do_get_user_conf_dirs():
dirs.append("~/.xpra")
return dirs

def do_get_default_log_dir():
def do_get_default_log_dirs():
dirs = []
try:
from Foundation import NSSearchPathForDirectoriesInDomains, NSLibraryDirectory, NSUserDomainMask #@UnresolvedImport
dirs = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, False)
#ie: ~/Library/
library_dir = dirs[0]
return os.path.join(library_dir, "Xpra")
dirs.append(os.path.join(library_dir, "Xpra"))
except:
pass
return "~/Library/Logs"
dirs.append("~/Library/Logs")
dirs.append("/tmp")
return dirs

def do_get_socket_dirs():
return ["/var/tmp/%s-Xpra" % os.getuid(), "~/.xpra"]
Expand Down
12 changes: 6 additions & 6 deletions src/xpra/platform/paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ def get_socket_dirs():
def do_get_socket_dirs():
return ["~/.xpra"]

def get_default_log_dir():
return env_or_delegate("XPRA_LOG_DIR", do_get_default_log_dir)
def do_get_default_log_dir():
return "~/.xpra"
def get_default_log_dirs():
return envaslist_or_delegate("XPRA_LOG_DIRS", do_get_default_log_dirs)
def do_get_default_log_dirs():
return ["~/.xpra"]

def get_download_dir():
return env_or_delegate("XPRA_DOWNLOAD_DIR", do_get_download_dir)
Expand Down Expand Up @@ -256,7 +256,7 @@ def do_get_sound_command():
"do_get_system_conf_dirs",
"do_get_user_conf_dirs",
"do_get_socket_dirs",
"do_get_default_log_dir",
"do_get_default_log_dirs",
"do_get_download_dir",
"do_get_script_bin_dirs")

Expand All @@ -267,7 +267,7 @@ def get_info():
"system_conf" : {"dirs" : get_system_conf_dirs()},
"user_conf" : {"dirs" : get_user_conf_dirs()},
"socket" : {"dirs" : get_socket_dirs()},
"log" : {"dir" : get_default_log_dir()},
"log" : {"dirs" : get_default_log_dirs()},
"download" : {"dir" : get_download_dir()},
"app" : {"dir" : get_app_dir()},
"app" : {"default" : {"dir" : default_get_app_dir()}},
Expand Down
8 changes: 2 additions & 6 deletions src/xpra/platform/xposix/paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

USE_RUNTIME_DIR = envbool("XPRA_USE_RUNTIME_DIR", True)

USE_RUNTIME_LOG_DIR = envbool("XPRA_USE_RUNTIME_LOG_DIR", USE_RUNTIME_DIR)
USE_RUNTIME_BIN_DIR = envbool("XPRA_USE_RUNTIME_BIN_DIR", USE_RUNTIME_DIR)
USE_RUNTIME_SOCKET_DIR = envbool("XPRA_USE_RUNTIME_SOCKET_DIR", USE_RUNTIME_DIR)

Expand Down Expand Up @@ -102,8 +101,5 @@ def do_get_socket_dirs():
SOCKET_DIRS.append("/var/run/xpra")
return SOCKET_DIRS

def do_get_default_log_dir():
runtime_dir = _get_xpra_runtime_dir()
if USE_RUNTIME_LOG_DIR and runtime_dir:
return runtime_dir
return "~/.xpra"
def do_get_default_log_dirs():
return [_get_xpra_runtime_dir(), "~/.xpra", "/tmp"]
12 changes: 5 additions & 7 deletions src/xpra/scripts/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def get_xorg_bin():
return None


def get_Xdummy_command(xorg_cmd="Xorg", log_dir="${HOME}/.xpra", xorg_conf="/etc/xpra/xorg.conf"):
def get_Xdummy_command(xorg_cmd="Xorg", log_dir="${XPRA_LOG_DIR}", xorg_conf="/etc/xpra/xorg.conf"):
cmd = [xorg_cmd] #ie: ["Xorg"] or ["xpra_Xdummy"] or ["./install/bin/xpra_Xdummy"]
if os.path.exists("/etc/debian_version"):
#no patched dummy driver for debian, so force reasonable DPI instead:
Expand Down Expand Up @@ -136,8 +136,6 @@ def Xorg_suid_check():
use_wrapper = True
else:
use_wrapper = False
from xpra.platform.paths import get_default_log_dir
log_dir = get_default_log_dir().replace("~/", "${HOME}/")
xorg_conf = os.path.join(conf_dir, "xorg.conf")
if use_wrapper:
xorg_cmd = "xpra_Xdummy"
Expand All @@ -147,7 +145,7 @@ def Xorg_suid_check():
if bin_dir and os.path.exists(os.path.join(bin_dir, xorg_cmd)):
if bin_dir not in ("/usr/bin", "/bin"):
xorg_cmd = os.path.join(bin_dir, xorg_cmd)
return get_Xdummy_command(xorg_cmd, log_dir=log_dir, xorg_conf=xorg_conf)
return get_Xdummy_command(xorg_cmd, xorg_conf=xorg_conf)

if Xdummy_ENABLED is False:
return get_Xvfb_command()
Expand Down Expand Up @@ -564,7 +562,7 @@ def get_defaults():
return GLOBAL_DEFAULTS
from xpra.platform.features import DEFAULT_SSH_COMMAND, OPEN_COMMAND, DEFAULT_PULSEAUDIO_CONFIGURE_COMMANDS, DEFAULT_PULSEAUDIO_COMMAND, \
DEFAULT_ENV, CAN_DAEMONIZE
from xpra.platform.paths import get_download_dir, get_default_log_dir, get_remote_run_xpra_scripts
from xpra.platform.paths import get_download_dir, get_remote_run_xpra_scripts
try:
from xpra.platform.info import get_username
username = get_username()
Expand Down Expand Up @@ -642,7 +640,7 @@ def addtrailingslash(v):
"systemd-run-args" : "",
"xvfb" : " ".join(xvfb),
"socket-dir" : "",
"log-dir" : get_default_log_dir(),
"log-dir" : "auto",
"log-file" : "$DISPLAY.log",
"border" : "auto,5:off",
"window-close" : "auto",
Expand Down Expand Up @@ -1036,7 +1034,7 @@ def abs_paths(options):
f = k.replace("-", "_")
v = getattr(options, f)
if v and (k!="ssl-ca-certs" or v!="default"):
if os.path.isabs(v):
if os.path.isabs(v) or v=="auto":
continue
if v.startswith("~") or v.startswith("$"):
continue
Expand Down
34 changes: 25 additions & 9 deletions src/xpra/scripts/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -776,12 +776,15 @@ def start_Xvfb(xvfb_str, display_name, cwd):
raise InitException("failed to create the Xorg log directory '%s': %s" % (xorg_log_dir, e))

#apply string substitutions:
subs = {"XAUTHORITY" : xauthority,
subs = {
"XAUTHORITY" : xauthority,
"USER" : os.environ.get("USER", "unknown-user"),
"UID" : os.getuid(),
"GID" : os.getgid(),
"HOME" : os.environ.get("HOME", cwd),
"DISPLAY" : display_name}
"DISPLAY" : display_name,
"XPRA_LOG_DIR" : os.environ.get("XPRA_LOG_DIR"),
}
xvfb_str = shellsub(xvfb_str, subs)

def setsid():
Expand Down Expand Up @@ -1065,13 +1068,26 @@ def run_server(error_cb, opts, mode, xpra_file, extra_args, desktop_display=None
if start_vfb or opts.daemon:
#we will probably need a log dir
#either for the vfb, or for our own log file
log_dir = osexpand(opts.log_dir)
if not os.path.exists(log_dir):
try:
os.mkdir(log_dir, 0o700)
except Exception as e:
sys.stderr.write("%s\n" % e)

log_dir = opts.log_dir or ""
if not log_dir or log_dir.lower()=="auto":
log_dir = ""
from xpra.platform.paths import get_default_log_dirs
for x in get_default_log_dirs():
v = osexpand(x)
if not os.path.exists(v):
try:
os.mkdir(v, 0o700)
except Exception as e:
sys.stderr.write("%s\n" % e)
continue
log_dir = v
break
if not log_dir:
raise InitException("cannot find or create a logging directory")
#expose the log-dir as "XPRA_LOG_DIR",
#this is used by Xdummy for the Xorg log file
if "XPRA_LOG_DIR" not in os.environ:
os.environ["XPRA_LOG_DIR"] = log_dir
stdout = sys.stdout
stderr = sys.stderr
# Daemonize:
Expand Down
2 changes: 1 addition & 1 deletion src/xpra/server/server_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ def init_html_proxy(self, opts):
log.error(" '%s' does not exist", self._www_dir)
self._html = False
if self._html:
log.info("serving html content from '%s'", self._www_dir)
log.info("serving html content from: %s", self._www_dir)
if self._html and self._tcp_proxy:
log.warn("Warning: the built in html server is enabled,")
log.warn(" disabling the tcp-proxy option")
Expand Down

0 comments on commit 68a2514

Please sign in to comment.