Commit be831865 authored by Jeremy White's avatar Jeremy White

Drop the --auto option in favor of having that be the primary parameter.

parent 69b0660a
...@@ -8,7 +8,7 @@ AM_CFLAGS = -Wall $(ALL_XCB_CFLAGS) $(GTK2_CFLAGS) $(SPICE_CFLAGS) $(SPICE_PROTO ...@@ -8,7 +8,7 @@ AM_CFLAGS = -Wall $(ALL_XCB_CFLAGS) $(GTK2_CFLAGS) $(SPICE_CFLAGS) $(SPICE_PROTO
x11spice_LDADD = $(ALL_XCB_LIBS) $(GTK2_LIBS) $(SPICE_LIBS) $(GLIB2_LIBS) $(PIXMAN_LIBS) $(CODE_COVERAGE_LDFLAGS) x11spice_LDADD = $(ALL_XCB_LIBS) $(GTK2_LIBS) $(SPICE_LIBS) $(GLIB2_LIBS) $(PIXMAN_LIBS) $(CODE_COVERAGE_LDFLAGS)
x11spice_SOURCES = \ x11spice_SOURCES = \
agent.c \ agent.c \
auto.c \ listen.c \
display.c \ display.c \
gui.c \ gui.c \
options.c \ options.c \
......
...@@ -19,10 +19,9 @@ ...@@ -19,10 +19,9 @@
*/ */
/*---------------------------------------------------------------------------- /*----------------------------------------------------------------------------
** auto.c ** listen.c
** This file provides functions to implement the '--auto' option ** This file provides functions to listen for the address given.
** for x11spice. This mostly involves trying to find an open port we can use ** This mostly involves trying to find an open port we can use for our server
** for our Xserver
**--------------------------------------------------------------------------*/ **--------------------------------------------------------------------------*/
#include <stdlib.h> #include <stdlib.h>
...@@ -40,12 +39,12 @@ ...@@ -40,12 +39,12 @@
#include <arpa/inet.h> #include <arpa/inet.h>
#include <errno.h> #include <errno.h>
#include "auto.h" #include "listen.h"
#include "x11spice.h" #include "x11spice.h"
#define SPICE_URI_PREFIX "spice://" #define SPICE_URI_PREFIX "spice://"
int auto_parse(const char *auto_spec, char **addr, int *port_start, int *port_end) int listen_parse(const char *listen_spec, char **addr, int *port_start, int *port_end)
{ {
int leading = 0; int leading = 0;
int trailing = 0; int trailing = 0;
...@@ -57,13 +56,13 @@ int auto_parse(const char *auto_spec, char **addr, int *port_start, int *port_en ...@@ -57,13 +56,13 @@ int auto_parse(const char *auto_spec, char **addr, int *port_start, int *port_en
*addr = NULL; *addr = NULL;
/* Allow form of spice:// */ /* Allow form of spice:// */
if (strlen(auto_spec) > strlen(SPICE_URI_PREFIX)) if (strlen(listen_spec) > strlen(SPICE_URI_PREFIX))
if (memcmp(auto_spec, SPICE_URI_PREFIX, strlen(SPICE_URI_PREFIX)) == 0) if (memcmp(listen_spec, SPICE_URI_PREFIX, strlen(SPICE_URI_PREFIX)) == 0)
auto_spec += strlen(SPICE_URI_PREFIX); listen_spec += strlen(SPICE_URI_PREFIX);
p = auto_spec + strlen(auto_spec) - 1; p = listen_spec + strlen(listen_spec) - 1;
/* Look for a form of NNNN-NNNN at the end of the line */ /* Look for a form of NNNN-NNNN at the end of the line */
for (; p >= auto_spec && *p; p--) { for (; p >= listen_spec && *p; p--) {
/* Skip trailing white space */ /* Skip trailing white space */
if (isspace(*p) && !hyphen && !trailing) if (isspace(*p) && !hyphen && !trailing)
continue; continue;
...@@ -100,16 +99,16 @@ int auto_parse(const char *auto_spec, char **addr, int *port_start, int *port_en ...@@ -100,16 +99,16 @@ int auto_parse(const char *auto_spec, char **addr, int *port_start, int *port_en
/* If we got a port range, make sure we had either no address provided, /* If we got a port range, make sure we had either no address provided,
or a clear addr:NNNN-NNNN specficiation */ or a clear addr:NNNN-NNNN specficiation */
if (leading || trailing) if (leading || trailing)
if (p > auto_spec && *p != ':') if (p > listen_spec && *p != ':')
return X11SPICE_ERR_PARSE; return X11SPICE_ERR_PARSE;
if (p > auto_spec && *p == ':') if (p > listen_spec && *p == ':')
p--; p--;
len = p - auto_spec + 1; len = p - listen_spec + 1;
if (len > 0) { if (len > 0) {
*addr = calloc(1, len + 1); *addr = calloc(1, len + 1);
memcpy(*addr, auto_spec, len); memcpy(*addr, listen_spec, len);
} }
return 0; return 0;
...@@ -179,7 +178,7 @@ listen: ...@@ -179,7 +178,7 @@ listen:
return sock; return sock;
} }
int auto_listen_port_fd(const char *addr, int start, int end, int *port) int listen_find_open_port(const char *addr, int start, int end, int *port)
{ {
int i; int i;
int rc; int rc;
...@@ -200,19 +199,3 @@ int auto_listen_port_fd(const char *addr, int start, int end, int *port) ...@@ -200,19 +199,3 @@ int auto_listen_port_fd(const char *addr, int start, int end, int *port)
return -1; return -1;
} }
int auto_listen(char *auto_spec, char **addr, int *port)
{
int start;
int end;
int rc;
if (auto_parse(auto_spec, addr, &start, &end))
return -1;
rc = auto_listen_port_fd(*addr, start, end, port);
fflush(stdout);
return rc;
}
...@@ -18,13 +18,14 @@ ...@@ -18,13 +18,14 @@
along with x11spice. If not, see <http://www.gnu.org/licenses/>. along with x11spice. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef AUTO_H_ #ifndef LISTEN_H_
#define AUTO_H_ #define LISTEN_H_
/*---------------------------------------------------------------------------- /*----------------------------------------------------------------------------
** Prototypes ** Prototypes
**--------------------------------------------------------------------------*/ **--------------------------------------------------------------------------*/
int auto_listen(char *auto_spec, char **addr, int *port); int listen_parse(const char *listen_spec, char **addr, int *port_start, int *port_end);
int listen_find_open_port(const char *addr, int start, int end, int *port);
#endif #endif
...@@ -53,9 +53,6 @@ void options_free(options_t *options) ...@@ -53,9 +53,6 @@ void options_free(options_t *options)
options->display = NULL; options->display = NULL;
} }
g_free(options->spice_addr);
options->spice_addr = NULL;
g_free(options->spice_password); g_free(options->spice_password);
options->spice_password = NULL; options->spice_password = NULL;
...@@ -64,9 +61,9 @@ void options_free(options_t *options) ...@@ -64,9 +61,9 @@ void options_free(options_t *options)
g_free(options->uinput_path); g_free(options->uinput_path);
options->uinput_path = NULL; options->uinput_path = NULL;
if (options->autouri) if (options->listen)
free(options->autouri); free(options->listen);
options->autouri = NULL; options->listen = NULL;
g_free(options->user_config_file); g_free(options->user_config_file);
options->user_config_file = NULL; options->user_config_file = NULL;
...@@ -123,14 +120,29 @@ static gboolean bool_option(GKeyFile *u, GKeyFile *s, const gchar *section, cons ...@@ -123,14 +120,29 @@ static gboolean bool_option(GKeyFile *u, GKeyFile *s, const gchar *section, cons
static void usage(options_t *options, char *argv0) static void usage(options_t *options, char *argv0)
{ {
int len = strlen(argv0); char indent[256];
printf("%s: [--viewonly ] [--timeout=seconds] [--display=DISPLAY]\n", argv0);
printf("%*.*s [--password=<password>] [--password-file={-|<password-file>}]\n", len, len, ""); snprintf(indent, sizeof(indent), "%*.*s ", (int) strlen(argv0), (int) strlen(argv0), "");
printf("%*.*s [--auto=<listen-spec>] [--generate-password[=len]]\n", len, len, ""); printf("%s: [OPTIONS] [<listen-specification>]\n", argv0);
printf("%*.*s [--hide] [--minimize]\n", len, len, ""); printf("\n");
printf("Command line parameters override settings in %s\n", options->user_config_file); printf("Starts a Spice server and connects it to an X11 display.\n");
printf("which overrides settings in %s\n", printf("\n");
options->system_config_file ? options->system_config_file : "the system config file"); printf("The <listen-specification> is of the form:\n");
printf(" [[host]:[port][-end-port]\n");
printf("where host specifies the address to listen on. Defaults to localhost\n");
printf(" port specifies the port to listen to. Defaults to 5900.\n");
printf(" end-port, if given, will cause x11spice to scan from port to end-port\n");
printf(" checking for an open port, and using the first one available.\n");
printf("\n");
printf("Options:\n");
printf("%s [--viewonly]\n", indent);
printf("%s [--timeout=<seconds>]\n", indent);
printf("%s [--display=<DISPLAY>]\n", indent);
printf("%s [--generate-password[=<len>]\n", indent);
printf("%s [--password=<password>]\n", indent);
printf("%s [--password-file={-|<password-file}]\n", indent);
printf("%s [--hide]\n", indent);
printf("%s [--minimize]\n", indent);
} }
int options_parse_arguments(int argc, char *argv[], options_t *options) int options_parse_arguments(int argc, char *argv[], options_t *options)
...@@ -175,10 +187,6 @@ int options_parse_arguments(int argc, char *argv[], options_t *options) ...@@ -175,10 +187,6 @@ int options_parse_arguments(int argc, char *argv[], options_t *options)
options->timeout = atol(optarg); options->timeout = atol(optarg);
break; break;
case OPTION_AUTO:
options->autouri = strdup(optarg);
break;
case OPTION_HIDE: case OPTION_HIDE:
options->hide = 1; options->hide = 1;
break; break;
...@@ -224,6 +232,19 @@ int options_parse_arguments(int argc, char *argv[], options_t *options) ...@@ -224,6 +232,19 @@ int options_parse_arguments(int argc, char *argv[], options_t *options)
} }
} }
/* Grab the listen spec, if given */
if (rc == 0) {
if (optind >= argc) {
/* Default */
options->listen = strdup("5900");
} else if (optind < (argc - 1)) {
fprintf(stderr, "Error: too many arguments\n");
rc = X11SPICE_ERR_BADARGS;
} else {
options->listen = strdup(argv[optind]);
}
}
return rc; return rc;
} }
...@@ -252,12 +273,10 @@ void options_from_config(options_t *options) ...@@ -252,12 +273,10 @@ void options_from_config(options_t *options)
options->generate_password = int_option(userkey, systemkey, "spice", "generate-password"); options->generate_password = int_option(userkey, systemkey, "spice", "generate-password");
options->hide = int_option(userkey, systemkey, "spice", "hide"); options->hide = int_option(userkey, systemkey, "spice", "hide");
options->display = string_option(userkey, systemkey, "spice", "display"); options->display = string_option(userkey, systemkey, "spice", "display");
options->autouri = string_option(userkey, systemkey, "spice", "auto");
options->spice_addr = string_option(userkey, systemkey, "spice", "addr"); options->listen = string_option(userkey, systemkey, "spice", "listen");
options->spice_password = string_option(userkey, systemkey, "spice", "password"); options->spice_password = string_option(userkey, systemkey, "spice", "password");
options->password_file = string_option(userkey, systemkey, "spice", "password-file"); options->password_file = string_option(userkey, systemkey, "spice", "password-file");
options->spice_port = int_option(userkey, systemkey, "spice", "port");
options->disable_ticketing = bool_option(userkey, systemkey, "spice", "disable-ticketing"); options->disable_ticketing = bool_option(userkey, systemkey, "spice", "disable-ticketing");
options->exit_on_disconnect = bool_option(userkey, systemkey, "spice", "exit-on-disconnect"); options->exit_on_disconnect = bool_option(userkey, systemkey, "spice", "exit-on-disconnect");
options->virtio_path = string_option(userkey, systemkey, "spice", "virtio-path"); options->virtio_path = string_option(userkey, systemkey, "spice", "virtio-path");
...@@ -268,8 +287,8 @@ void options_from_config(options_t *options) ...@@ -268,8 +287,8 @@ void options_from_config(options_t *options)
if (userkey) if (userkey)
g_key_file_free(userkey); g_key_file_free(userkey);
g_debug("options addr '%s', disable_ticketing %d, port %d", options->spice_addr, g_debug("options listen '%s', disable_ticketing %d", options->listen,
options->disable_ticketing, options->spice_port); options->disable_ticketing);
} }
static int process_password_file(options_t *options) static int process_password_file(options_t *options)
......
...@@ -37,11 +37,9 @@ typedef struct { ...@@ -37,11 +37,9 @@ typedef struct {
int generate_password; int generate_password;
int hide; int hide;
char *display; char *display;
char *autouri; char *listen;
/* config only */ /* config only */
char *spice_addr;
int spice_port;
char *spice_password; char *spice_password;
char *password_file; char *password_file;
int disable_ticketing; int disable_ticketing;
......
...@@ -36,7 +36,7 @@ ...@@ -36,7 +36,7 @@
#include "x11spice.h" #include "x11spice.h"
#include "display.h" #include "display.h"
#include "session.h" #include "session.h"
#include "auto.h" #include "listen.h"
struct SpiceTimer { struct SpiceTimer {
SpiceTimerFunc func; SpiceTimerFunc func;
...@@ -579,12 +579,6 @@ static void set_options(spice_t *s, options_t *options) ...@@ -579,12 +579,6 @@ static void set_options(spice_t *s, options_t *options)
if (options->disable_ticketing) if (options->disable_ticketing)
spice_server_set_noauth(s->server); spice_server_set_noauth(s->server);
if (!options->autouri) {
spice_server_set_addr(s->server, options->spice_addr ? options->spice_addr : "", 0);
if (options->spice_port)
spice_server_set_port(s->server, options->spice_port);
}
if (options->spice_password) if (options->spice_password)
spice_server_set_ticket(s->server, options->spice_password, 0, 0, 0); spice_server_set_ticket(s->server, options->spice_password, 0, 0, 0);
...@@ -592,17 +586,31 @@ static void set_options(spice_t *s, options_t *options) ...@@ -592,17 +586,31 @@ static void set_options(spice_t *s, options_t *options)
} }
static int try_auto(spice_t *s, options_t *options) static int try_listen(spice_t *s, options_t *options)
{ {
int fd; int fd;
int port; int port;
char *addr = NULL; char *addr = NULL;
int start;
int end;
int rc;
fd = auto_listen(options->autouri, &addr, &port); rc = listen_parse(options->listen, &addr, &start, &end);
if (fd < 0) if (rc)
return X11SPICE_ERR_AUTO_FAILED; return rc;
close(fd); fd = listen_find_open_port(addr, start, end, &port);
fflush(stdout);
if (fd >= 0)
close(fd);
else {
if (start != -1)
return X11SPICE_ERR_AUTO_FAILED;
else
return X11SPICE_ERR_LISTEN;
}
if (addr) { if (addr) {
spice_server_set_addr(s->server, addr, 0); spice_server_set_addr(s->server, addr, 0);
...@@ -627,10 +635,13 @@ int spice_start(spice_t *s, options_t *options, shm_image_t *fullscreen) ...@@ -627,10 +635,13 @@ int spice_start(spice_t *s, options_t *options, shm_image_t *fullscreen)
set_options(s, options); set_options(s, options);
if (options->autouri) { rc = try_listen(s, options);
int rc = try_auto(s, options); if (rc) {
if (rc) if (rc == X11SPICE_ERR_AUTO_FAILED)
return rc; fprintf(stderr, "Error: unable to open any port in range '%s'.\n", options->listen);
else
fprintf(stderr, "Error: unable to listen on '%s'.\n", options->listen);
return rc;
} }
if (spice_server_init(s->server, s->core) < 0) { if (spice_server_init(s->server, s->core) < 0) {
......
...@@ -41,10 +41,10 @@ static int exec_x11spice(x11spice_server_t *server, gchar *display) ...@@ -41,10 +41,10 @@ static int exec_x11spice(x11spice_server_t *server, gchar *display)
dup2(server->pipe, fileno(stderr)); dup2(server->pipe, fileno(stderr));
if (valgrind) if (valgrind)
snprintf(buf, sizeof(buf), "%s ../x11spice --display :%s --auto localhost:5900-5999 --hide", snprintf(buf, sizeof(buf), "%s ../x11spice --display :%s localhost:5900-5999 --hide",
valgrind, display); valgrind, display);
else else
snprintf(buf, sizeof(buf), "../x11spice --display :%s --auto localhost:5900-5999 --hide", snprintf(buf, sizeof(buf), "../x11spice --display :%s localhost:5900-5999 --hide",
display); display);
return execl("/bin/sh", "sh", "-c", buf, NULL); return execl("/bin/sh", "sh", "-c", buf, NULL);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment