Xpra: Ticket #1185: UnboundLocalError: local variable 'scriptfile' referenced before assignment

xpra main error:
Traceback (most recent call last):
  File "/usr/lib64/python2.7/site-packages/xpra/scripts/main.py", line 126, in main
    return run_mode(script_file, err, options, args, mode, defaults)
  File "/usr/lib64/python2.7/site-packages/xpra/scripts/main.py", line 1003, in run_mode
    return run_server(error_cb, options, mode, script_file, args, current_display)
  File "/usr/lib64/python2.7/site-packages/xpra/scripts/server.py", line 1038, in run_server
    write_runner_shell_scripts(script)
  File "/usr/lib64/python2.7/site-packages/xpra/scripts/server.py", line 234, in write_runner_shell_scripts
    sys.stderr.write("Error: failed to write script file '%s':\n" % scriptfile)
UnboundLocalError: local variable 'scriptfile' referenced before assignment

Environment variables:

ENV \
        PORT=30000 \
        XPRA_HOME=/home/xpra \
        XDG_RUNTIME_DIR=$XPRA_HOME/.xpra \
        XPRA_USE_RUNTIME_DIR=1 \
        XPRA_LOG_DIR=$XDG_RUNTIME_DIR \
        XPRA_SCRIPT_BIN_DIR=$XDG_RUNTIME_DIR \
        XPRA_SOCKET_DIRS=$XDG_RUNTIME_DIR

Which means XPRA_SCRIPT_BIN_DIR is set, but empty, while XDG_RUNTIME_DIR contains /.xpra.

Command line:

exec xpra start :100 --exit-with-children --daemon=no --mdns=no --pulseaudio=no --webcam=no --tcp-auth=env --tcp-encryption=AES --bind-tcp=0.0.0.0:$PORT --start-child="xterm"

All this can also be found in the Dockerfile and entrypoint.sh: https://github.com/urzds/xpra-docker/tree/fedora



Fri, 22 Apr 2016 15:46:30 GMT - urzds:

This is actually independent of the bad values of XPRA_SCRIPT_BIN_DIR and XDG_RUNTIME_DIR:

sh-4.3$ whoami
xpra
sh-4.3$ echo $XDG_RUNTIME_DIR
/home/xpra/.xpra
sh-4.3$ xpra start :100 --exit-with-children --daemon=no --mdns=no --pulseaudio=no --webcam=no --tcp-auth=env --tcp-encryption=AES --bind-tcp=0.0.0.0:30000 --start-child="xterm"
xpra main error:
Traceback (most recent call last):
  File "/usr/lib64/python2.7/site-packages/xpra/scripts/main.py", line 126, in main
    return run_mode(script_file, err, options, args, mode, defaults)
  File "/usr/lib64/python2.7/site-packages/xpra/scripts/main.py", line 1003, in run_mode
    return run_server(error_cb, options, mode, script_file, args, current_display)
  File "/usr/lib64/python2.7/site-packages/xpra/scripts/server.py", line 1038, in run_server
    write_runner_shell_scripts(script)
  File "/usr/lib64/python2.7/site-packages/xpra/scripts/server.py", line 234, in write_runner_shell_scripts
    sys.stderr.write("Error: failed to write script file '%s':\n" % scriptfile)
UnboundLocalError: local variable 'scriptfile' referenced before assignment

Fri, 22 Apr 2016 15:49:18 GMT - urzds:

It is also independent of XPRA_USE_RUNTIME_DIR:

sh-4.3$ whoami
xpra
sh-4.3$ echo $XPRA_USE_RUNTIME_DIR
sh-4.3$ echo $XDG_RUNTIME_DIR
/home/xpra/.xpra
sh-4.3$ echo $XPRA_SCRIPT_BIN_DIR
/home/xpra/.xpra
sh-4.3$ xpra start :100 --exit-with-children --daemon=no --mdns=no --pulseaudio=no --webcam=no --tcp-auth=env --tcp-encryption=AES --bind-tcp=0.0.0.0:$PORT --start-child="xterm"
xpra main error:
Traceback (most recent call last):
  File "/usr/lib64/python2.7/site-packages/xpra/scripts/main.py", line 126, in main
    return run_mode(script_file, err, options, args, mode, defaults)
  File "/usr/lib64/python2.7/site-packages/xpra/scripts/main.py", line 1003, in run_mode
    return run_server(error_cb, options, mode, script_file, args, current_display)
  File "/usr/lib64/python2.7/site-packages/xpra/scripts/server.py", line 1038, in run_server
    write_runner_shell_scripts(script)
  File "/usr/lib64/python2.7/site-packages/xpra/scripts/server.py", line 234, in write_runner_shell_scripts
    sys.stderr.write("Error: failed to write script file '%s':\n" % scriptfile)
UnboundLocalError: local variable 'scriptfile' referenced before assignment

Fri, 22 Apr 2016 15:57:25 GMT - urzds:

P.S: I'm running r12466 of the 0.17.x tag.


Fri, 22 Apr 2016 16:05:12 GMT - urzds:

This is actually quite simple, when reading the code:

        scriptpath = os.path.join(scriptdir, "run-xpra")
        [...]
        except Exception as e:
            sys.stderr.write("Error: failed to write script file '%s':\n" % scriptfile)
            sys.stderr.write(" %s\n" % (scriptfile, e))

The logging code should print scriptpath instead of scriptfile and then output e instead of (scriptfile, e) in the second line.

Following sed makes it work:

# sed -i '/Error: failed to write script file/s/scriptfile/scriptpath/' /usr/lib64/python2.7/site-packages/xpra/scripts/server.py
# sed -i 's/(scriptfile, e)/e/' /usr/lib64/python2.7/site-packages/xpra/scripts/server.py

Fri, 22 Apr 2016 16:37:55 GMT - urzds: component changed


Sat, 23 Apr 2016 02:35:09 GMT - Antoine Martin: owner changed

Good find! This should be fixed in r12470. (will apply to v0.17.x)


Tue, 09 Aug 2016 15:06:38 GMT - Antoine Martin: status changed; resolution set

Not heard back, closing.


Sat, 23 Jan 2021 05:17:18 GMT - migration script:

this ticket has been moved to: https://github.com/Xpra-org/xpra/issues/1185