tools/demo-server: add --force to remove a leftover socket path

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
Peter Hutterer 2020-10-02 09:39:45 +10:00
parent 9b6257bb9d
commit faff1ed597

View file

@ -258,13 +258,14 @@ static void
usage(FILE *fp, const char *argv0)
{
fprintf(fp,
"Usage: %s [--verbose] [--uinput] [--socketpath=/path/to/socket]\n"
"Usage: %s [--verbose] [--uinput] [--socketpath=/path/to/socket] [--force]\n"
"\n"
"Start an EIS demo server. The server accepts all client connections\n"
"and devices and prints any events from the client to stdout.\n"
"\n"
"Options:\n"
" --socketpath Use the given socket path. Default: $XDG_RUNTIME/eis-0\n"
" --force Remove the socket if it already exists\n"
" --layout Use the given XKB layout (requires libxkbcommon). Default:\n"
" use the client-supplied keymap, if any\n"
" --uinput Set up each device as uinput device (this requires root)\n"
@ -277,6 +278,7 @@ int main(int argc, char **argv)
{
bool verbose = false;
bool uinput = false;
bool force = false;
const char *layout = NULL;
_cleanup_unlink_free_ char *socketpath = NULL;
@ -289,12 +291,14 @@ int main(int argc, char **argv)
OPT_VERBOSE,
OPT_LAYOUT,
OPT_SOCKETPATH,
OPT_FORCE,
OPT_UINPUT,
};
static struct option long_opts[] = {
{"socketpath", required_argument, 0, OPT_SOCKETPATH},
{"layout", required_argument, 0, OPT_LAYOUT},
{"uinput", no_argument, 0, OPT_UINPUT},
{"force", no_argument, 0, OPT_FORCE},
{"verbose", no_argument,0, OPT_VERBOSE},
{"help", no_argument,0, 'h'},
{NULL},
@ -319,6 +323,9 @@ int main(int argc, char **argv)
case OPT_UINPUT:
uinput = true;
break;
case OPT_FORCE:
force = true;
break;
case OPT_VERBOSE:
verbose = true;
break;
@ -358,6 +365,9 @@ int main(int argc, char **argv)
signal(SIGINT, sighandler);
if (force)
unlink(socketpath);
int rc = eis_setup_backend_socket(eis, socketpath);
if (rc != 0) {
fprintf(stderr, "init failed: %s\n", strerror(errno));