Add --socket argument to all clients

Makes it not needed to kill daemon for testing, but disables implicit
`powerline-config shell command` testing.
This commit is contained in:
ZyX 2014-08-23 14:55:59 +04:00
parent 77a7a26782
commit 0232d3215b
6 changed files with 68 additions and 28 deletions

View File

@ -60,20 +60,28 @@ int main(int argc, char *argv[]) {
int i;
ptrdiff_t read_size;
struct sockaddr_un server;
char address[ADDRESS_SIZE];
char address_buf[ADDRESS_SIZE];
const char eof[2] = "\0\0";
char num_args[NUM_ARGS_SIZE];
char buf[BUF_SIZE];
char *newargv[NEW_ARGV_SIZE];
char *wd = NULL;
char **envp;
const char *address;
if (argc < 2) {
printf("Must provide at least one argument.\n");
return EXIT_FAILURE;
}
snprintf(address, ADDRESS_SIZE, ADDRESS_TEMPLATE, getuid());
if (argc > 3 && strcmp(argv[1], "--socket") == 0) {
address = argv[2];
argv += 2;
argc -= 2;
} else {
snprintf(address_buf, ADDRESS_SIZE, ADDRESS_TEMPLATE, getuid());
address = &(address_buf[0]);
}
sd = socket(AF_UNIX, SOCK_STREAM, 0);
if (sd == -1)

View File

@ -15,10 +15,15 @@ if len(sys.argv) < 2:
platform = sys.platform.lower()
use_filesystem = 'darwin' in platform
# use_filesystem = True
del platform
address = ('/tmp/powerline-ipc-%d' if use_filesystem else '\0powerline-ipc-%d') % os.getuid()
if sys.argv[1] == '--socket':
address = sys.argv[2]
if not use_filesystem:
address = '\0' + address
del sys.argv[1:3]
else:
address = ('/tmp/powerline-ipc-%d' if use_filesystem else '\0powerline-ipc-%d') % os.getuid()
sock = socket.socket(family=socket.AF_UNIX)

View File

@ -1,6 +1,12 @@
#!/bin/sh
ADDRESS="powerline-ipc-${UID:-`id -u`}"
if test "$1" = "--socket" ; then
shift
ADDRESS="$1"
shift
else
ADDRESS="powerline-ipc-${UID:-`id -u`}"
fi
# Warning: env -0 does not work in busybox. Consider switching to parsing
# `set` output in this case

View File

@ -66,6 +66,7 @@ def get_argparser(parser=None, *args, **kwargs):
p.add_argument('-t', '--theme_option', metavar='THEME.KEY.KEY=VALUE', action='append', help='Like above, but theme-specific. THEME should point to an existing and used theme to have any effect, but it is fine to use any theme here.')
p.add_argument('-R', '--renderer_arg', metavar='KEY=VAL', action='append', help='Like above, but provides argument for renderer. Is supposed to be used only by shell bindings to provide various data like last_exit_code or last_pipe_status (they are not using --renderer_arg for historical resons: renderer_arg was added later).')
p.add_argument('-p', '--config_path', action='append', metavar='PATH', help='Path to configuration directory. If it is present then configuration files will only be seeked in the provided path. May be provided multiple times to search in a list of directories.')
p.add_argument('--socket', metavar='ADDRESS', type=str, help='Socket address to use in daemon clients. Is always UNIX domain socket on linux and file socket on Mac OS X. Not used here, present only for compatibility with other powerline clients. This argument must always be the first one and be in a form `--socket ADDRESS\': no `=\' or short form allowed (in other powerline clients, not here).')
return p

View File

@ -17,20 +17,13 @@ from io import StringIO
from powerline.shell import get_argparser, finish_args, ShellPowerline, write_output
from powerline.lib.monotonic import monotonic
is_daemon = False
platform = sys.platform.lower()
use_filesystem = 'darwin' in platform
# use_filesystem = True
del platform
if use_filesystem:
address = '/tmp/powerline-ipc-%d'
pidfile = address + '.pid'
else:
# Use the abstract namespace for sockets rather than the filesystem
# (Available only in linux)
address = '\0powerline-ipc-%d'
address = address % os.getuid()
address = None
pidfile = None
class NonInteractiveArgParser(ArgumentParser):
@ -334,8 +327,11 @@ def lockpidfile():
import fcntl
import atexit
import stat
fd = os.open(pidfile, os.O_WRONLY | os.O_CREAT,
stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IROTH)
fd = os.open(
pidfile,
os.O_WRONLY | os.O_CREAT,
stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IROTH
)
try:
fcntl.lockf(fd, fcntl.LOCK_EX | fcntl.LOCK_NB)
except EnvironmentError:
@ -352,15 +348,34 @@ def lockpidfile():
def main():
p = ArgumentParser(description=
'Daemon to improve the performance of powerline')
global address
global pidfile
p = ArgumentParser(description='Daemon to improve the performance of powerline')
p.add_argument('--quiet', '-q', action='store_true', help='Without other options: do not complain about already running powerline-daemon instance. Will still exit with 1. With `--kill\' and `--replace\': do not show any messages. With `--foreground\': ignored. Does not silence exceptions in any case.')
p.add_argument('--socket', '-s', help='Specify socket which will be used for connecting to daemon.')
a = p.add_mutually_exclusive_group().add_argument
a('--kill', '-k', action='store_true', help='Kill an already running instance')
a('--foreground', '-f', action='store_true', help='Run in the foreground (dont daemonize)')
a('--replace', '-r', action='store_true', help='Replace an already running instance')
args = p.parse_args()
if args.socket:
address = args.socket
if not use_filesystem:
address = '\0' + address
else:
if use_filesystem:
address = '/tmp/powerline-ipc-%d'
else:
# Use the abstract namespace for sockets rather than the filesystem
# (Available only in linux)
address = '\0powerline-ipc-%d'
address = address % os.getuid()
if use_filesystem:
pidfile = address + '.pid'
if args.kill:
if kill_daemon():
if not args.quiet:

View File

@ -16,6 +16,7 @@ ONLY_SHELL: execute only tests for given shell
ONLY_TEST_TYPE: execute only "daemon" or "nodaemon" tests
COMMAND_PATTERN: use only commands that match given pattern for testing
EOF
exit 0
fi
check_screen_log() {
@ -213,21 +214,25 @@ done
unset ENV
if test -z "${ONLY_SHELL}" || test "x${ONLY_SHELL%sh}" != "x${ONLY_SHELL}" || test "x${ONLY_SHELL}" = xbusybox ; then
powerline-daemon -k || true
sleep 1s
export ADDRESS="powerline-ipc-test-$RANDOM"
export PYTHON
echo "Powerline address: $ADDRESS"
if test -z "${ONLY_SHELL}" || test "x${ONLY_SHELL%sh}" != "x${ONLY_SHELL}" || test "x${ONLY_SHELL}" = xbusybox ; then
scripts/powerline-config shell command
for TEST_TYPE in "daemon" "nodaemon" ; do
if test $TEST_TYPE = daemon ; then
sh -c 'echo $$ > tests/shell/daemon_pid; $PYTHON ./scripts/powerline-daemon -f &>tests/shell/daemon_log' &
sh -c '
echo $$ > tests/shell/daemon_pid
$PYTHON ./scripts/powerline-daemon -s$ADDRESS -f &>tests/shell/daemon_log
' &
fi
if test "x$ONLY_TEST_TYPE" != "x" && test "x$ONLY_TEST_TYPE" != "x$TEST_TYPE" ; then
continue
fi
echo "> Testing $TEST_TYPE"
for POWERLINE_COMMAND in "" \
for POWERLINE_COMMAND in \
$PWD/scripts/powerline \
$PWD/scripts/powerline-render \
"$PYTHON $PWD/client/powerline.py" \
@ -238,7 +243,6 @@ if test -z "${ONLY_SHELL}" || test "x${ONLY_SHELL%sh}" != "x${ONLY_SHELL}" || te
*powerline-render) TEST_CLIENT=render ;;
*powerline.py) TEST_CLIENT=python ;;
*powerline.sh) TEST_CLIENT=shell ;;
"") TEST_CLIENT=auto ;;
esac
if test "$TEST_CLIENT" = "C" && ! test -x scripts/powerline ; then
if which powerline >/dev/null ; then
@ -258,6 +262,7 @@ if test -z "${ONLY_SHELL}" || test "x${ONLY_SHELL%sh}" != "x${ONLY_SHELL}" || te
then
continue
fi
POWERLINE_COMMAND="$POWERLINE_COMMAND --socket $ADDRESS"
export POWERLINE_COMMAND
echo ">> powerline command is ${POWERLINE_COMMAND:-empty}"
for TEST_COMMAND in \
@ -286,7 +291,7 @@ if test -z "${ONLY_SHELL}" || test "x${ONLY_SHELL%sh}" != "x${ONLY_SHELL}" || te
done
done
if test $TEST_TYPE = daemon ; then
$PYTHON ./scripts/powerline-daemon -k
$PYTHON ./scripts/powerline-daemon -s$ADDRESS -k
wait $(cat tests/shell/daemon_pid)
if ! test -z "$(cat tests/shell/daemon_log)" ; then
echo '____________________________________________________________'
@ -299,12 +304,12 @@ if test -z "${ONLY_SHELL}" || test "x${ONLY_SHELL%sh}" != "x${ONLY_SHELL}" || te
done
fi
if ! $PYTHON scripts/powerline-daemon &> tests/shell/daemon_log_2 ; then
if ! $PYTHON scripts/powerline-daemon -s$ADDRESS &> tests/shell/daemon_log_2 ; then
echo "Daemon exited with status $?"
FAILED=1
else
sleep 1
$PYTHON scripts/powerline-daemon -k
$PYTHON scripts/powerline-daemon -s$ADDRESS -k
fi
if ! test -z "$(cat tests/shell/daemon_log_2)" ; then