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
x11spice_LDADD = $(ALL_XCB_LIBS) $(GTK2_LIBS) $(SPICE_LIBS) $(GLIB2_LIBS) $(PIXMAN_LIBS) $(CODE_COVERAGE_LDFLAGS)
x11spice_SOURCES = \
agent.c \
auto.c \
listen.c \
display.c \
gui.c \
options.c \
......
......@@ -19,10 +19,9 @@
*/
/*----------------------------------------------------------------------------
** auto.c
** This file provides functions to implement the '--auto' option
** for x11spice. This mostly involves trying to find an open port we can use
** for our Xserver
** listen.c
** This file provides functions to listen for the address given.
** This mostly involves trying to find an open port we can use for our server
**--------------------------------------------------------------------------*/
#include <stdlib.h>
......@@ -40,12 +39,12 @@
#include <arpa/inet.h>
#include <errno.h>
#include "auto.h"
#include "listen.h"
#include "x11spice.h"
#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 trailing = 0;
......@@ -57,13 +56,13 @@ int auto_parse(const char *auto_spec, char **addr, int *port_start, int *port_en
*addr = NULL;
/* Allow form of spice:// */
if (strlen(auto_spec) > strlen(SPICE_URI_PREFIX))
if (memcmp(auto_spec, SPICE_URI_PREFIX, strlen(SPICE_URI_PREFIX)) == 0)
auto_spec += strlen(SPICE_URI_PREFIX);
if (strlen(listen_spec) > strlen(SPICE_URI_PREFIX))
if (memcmp(listen_spec, SPICE_URI_PREFIX, strlen(SPICE_URI_PREFIX)) == 0)
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 */
for (; p >= auto_spec && *p; p--) {
for (; p >= listen_spec && *p; p--) {
/* Skip trailing white space */
if (isspace(*p) && !hyphen && !trailing)
continue;
......@@ -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,
or a clear addr:NNNN-NNNN specficiation */
if (leading || trailing)
if (p > auto_spec && *p != ':')
if (p > listen_spec && *p != ':')
return X11SPICE_ERR_PARSE;
if (p > auto_spec && *p == ':')
if (p > listen_spec && *p == ':')
p--;
len = p - auto_spec + 1;
len = p - listen_spec + 1;
if (len > 0) {
*addr = calloc(1, len + 1);
memcpy(*addr, auto_spec, len);
memcpy(*addr, listen_spec, len);
}
return 0;
......@@ -179,7 +178,7 @@ listen:
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 rc;
......@@ -200,19 +199,3 @@ int auto_listen_port_fd(const char *addr, int start, int end, int *port)
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 @@
along with x11spice. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef AUTO_H_
#define AUTO_H_
#ifndef LISTEN_H_
#define LISTEN_H_
/*----------------------------------------------------------------------------
** 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
......@@ -53,9 +53,6 @@ void options_free(options_t *options)
options->display = NULL;
}
g_free(options->spice_addr);
options->spice_addr = NULL;
g_free(options->spice_password);
options->spice_password = NULL;
......@@ -64,9 +61,9 @@ void options_free(options_t *options)
g_free(options->uinput_path);
options->uinput_path = NULL;
if (options->autouri)
free(options->autouri);
options->autouri = NULL;
if (options->listen)
free(options->listen);
options->listen = NULL;
g_free(options->user_config_file);
options->user_config_file = NULL;
......@@ -123,14 +120,29 @@ static gboolean bool_option(GKeyFile *u, GKeyFile *s, const gchar *section, cons
static void usage(options_t *options, char *argv0)
{
int len = strlen(argv0);
printf("%s: [--viewonly ] [--timeout=seconds] [--display=DISPLAY]\n", argv0);
printf("%*.*s [--password=<password>] [--password-file={-|<password-file>}]\n", len, len, "");
printf("%*.*s [--auto=<listen-spec>] [--generate-password[=len]]\n", len, len, "");
printf("%*.*s [--hide] [--minimize]\n", len, len, "");
printf("Command line parameters override settings in %s\n", options->user_config_file);
printf("which overrides settings in %s\n",
options->system_config_file ? options->system_config_file : "the system config file");
char indent[256];
snprintf(indent, sizeof(indent), "%*.*s ", (int) strlen(argv0), (int) strlen(argv0), "");
printf("%s: [OPTIONS] [<listen-specification>]\n", argv0);
printf("\n");
printf("Starts a Spice server and connects it to an X11 display.\n");
printf("\n");
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)
......@@ -175,10 +187,6 @@ int options_parse_arguments(int argc, char *argv[], options_t *options)
options->timeout = atol(optarg);
break;
case OPTION_AUTO:
options->autouri = strdup(optarg);
break;
case OPTION_HIDE:
options->hide = 1;
break;
......@@ -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;
}
......@@ -252,12 +273,10 @@ void options_from_config(options_t *options)
options->generate_password = int_option(userkey, systemkey, "spice", "generate-password");
options->hide = int_option(userkey, systemkey, "spice", "hide");
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->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->exit_on_disconnect = bool_option(userkey, systemkey, "spice", "exit-on-disconnect");
options->virtio_path = string_option(userkey, systemkey, "spice", "virtio-path");
......@@ -268,8 +287,8 @@ void options_from_config(options_t *options)
if (userkey)
g_key_file_free(userkey);
g_debug("options addr '%s', disable_ticketing %d, port %d", options->spice_addr,
options->disable_ticketing, options->spice_port);
g_debug("options listen '%s', disable_ticketing %d", options->listen,
options->disable_ticketing);
}
static int process_password_file(options_t *options)
......
......@@ -37,11 +37,9 @@ typedef struct {
int generate_password;
int hide;
char *display;
char *autouri;
char *listen;
/* config only */
char *spice_addr;
int spice_port;
char *spice_password;
char *password_file;
int disable_ticketing;
......
......@@ -36,7 +36,7 @@
#include "x11spice.h"
#include "display.h"
#include "session.h"
#include "auto.h"
#include "listen.h"
struct SpiceTimer {
SpiceTimerFunc func;
......@@ -579,12 +579,6 @@ static void set_options(spice_t *s, options_t *options)
if (options->disable_ticketing)
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)
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)
}
static int try_auto(spice_t *s, options_t *options)
static int try_listen(spice_t *s, options_t *options)
{
int fd;
int port;
char *addr = NULL;
int start;
int end;
int rc;
fd = auto_listen(options->autouri, &addr, &port);
if (fd < 0)
return X11SPICE_ERR_AUTO_FAILED;
rc = listen_parse(options->listen, &addr, &start, &end);
if (rc)
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) {
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)
set_options(s, options);
if (options->autouri) {
int rc = try_auto(s, options);
if (rc)
return rc;
rc = try_listen(s, options);
if (rc) {
if (rc == X11SPICE_ERR_AUTO_FAILED)
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) {
......
......@@ -41,10 +41,10 @@ static int exec_x11spice(x11spice_server_t *server, gchar *display)
dup2(server->pipe, fileno(stderr));
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);
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);
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