Commit b76eefbe authored by Jeremy White's avatar Jeremy White

Add the ability to specify an option file on the command line.

Then go on to use this facility in the tests, so the tests work
even if the user has a normal configuration file.
parent 640530ac
......@@ -65,6 +65,7 @@ int main(int argc, char *argv[])
** Parse arguments
**----------------------------------------------------------------------*/
options_init(&session.options);
options_handle_user_config(argc, argv, &session.options);
options_from_config(&session.options);
rc = options_parse_arguments(argc, argv, &session.options);
if (rc)
......
......@@ -141,17 +141,28 @@ static void usage(options_t *options, char *argv0)
printf("%s [--generate-password[=<len>]\n", indent);
printf("%s [--password=<password>]\n", indent);
printf("%s [--password-file={-|<password-file}]\n", indent);
printf("%s [--config=<config-file>]\n", indent);
printf("%s [--hide]\n", indent);
printf("%s [--minimize]\n", indent);
}
void options_handle_user_config(int argc, char *argv[], options_t *options)
{
int i;
for (i = 1; i < argc - 1; i++)
if (strcmp(argv[i], "--config") == 0 || strcmp(argv[i], "-config") == 0) {
options->user_config_file = strdup(argv[i + 1]);
i++;
}
}
int options_parse_arguments(int argc, char *argv[], options_t *options)
{
int rc;
int longindex = 0;
enum option_types { OPTION_VIEWONLY, OPTION_TIMEOUT, OPTION_AUTO, OPTION_HIDE,
OPTION_PASSWORD, OPTION_PASSWORD_FILE,
OPTION_PASSWORD, OPTION_PASSWORD_FILE, OPTION_CONFIG,
OPTION_GENERATE_PASSWORD, OPTION_DISPLAY, OPTION_MINIMIZE,
OPTION_HELP
};
......@@ -164,6 +175,7 @@ int options_parse_arguments(int argc, char *argv[], options_t *options)
{"hide", 0, 0, OPTION_HIDE },
{"password", 1, 0, OPTION_PASSWORD },
{"password-file", 1, 0, OPTION_PASSWORD_FILE },
{"config", 1, 0, OPTION_CONFIG },
{"generate-password", 2, 0, OPTION_GENERATE_PASSWORD },
{"display", 1, 0, OPTION_DISPLAY },
{"minimize", 0, 0, OPTION_MINIMIZE },
......@@ -199,6 +211,10 @@ int options_parse_arguments(int argc, char *argv[], options_t *options)
options->password_file = strdup(optarg);
break;
case OPTION_CONFIG:
/* This was handled previously; we can ignore */
break;
case OPTION_GENERATE_PASSWORD:
options->generate_password = DEFAULT_PASSWORD_LENGTH;
if (optarg)
......@@ -251,22 +267,26 @@ int options_parse_arguments(int argc, char *argv[], options_t *options)
void options_from_config(options_t *options)
{
GKeyFile *userkey = g_key_file_new();
GKeyFile *systemkey = g_key_file_new();
options->user_config_file = g_build_filename(g_get_user_config_dir(), "x11spice/x11spice.conf", NULL);
GKeyFile *systemkey = NULL;
int config_file_given = options->user_config_file ? TRUE : FALSE;
if (!config_file_given) {
options->user_config_file = g_build_filename(g_get_user_config_dir(), "x11spice/x11spice.conf", NULL);
systemkey = g_key_file_new();
if (!g_key_file_load_from_dirs(systemkey, "x11spice/x11spice.conf",
(const char **) g_get_system_config_dirs(),
&options->system_config_file, G_KEY_FILE_NONE, NULL)) {
g_key_file_free(systemkey);
systemkey = NULL;
}
}
if (!g_key_file_load_from_file(userkey, options->user_config_file, G_KEY_FILE_NONE, NULL)) {
g_key_file_free(userkey);
userkey = NULL;
}
if (!g_key_file_load_from_dirs(systemkey, "x11spice/x11spice.conf",
(const char **) g_get_system_config_dirs(),
&options->system_config_file, G_KEY_FILE_NONE, NULL)) {
g_key_file_free(systemkey);
systemkey = NULL;
}
options->timeout = int_option(userkey, systemkey, "spice", "timeout");
options->minimize = bool_option(userkey, systemkey, "spice", "minimize");
options->viewonly = bool_option(userkey, systemkey, "spice", "viewonly");
......
......@@ -57,6 +57,7 @@ typedef struct {
** Prototypes
**--------------------------------------------------------------------------*/
void options_init(options_t *options);
void options_handle_user_config(int argc, char *argv[], options_t *options);
int options_parse_arguments(int argc, char *argv[], options_t *options);
int options_process_io(options_t *options);
void options_free(options_t *options);
......
......@@ -41,11 +41,11 @@ 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 localhost:5900-5999 --hide",
valgrind, display);
snprintf(buf, sizeof(buf), "%s ../x11spice --display :%s localhost:5900-5999 --hide --config %s",
valgrind, display, server->conffile);
else
snprintf(buf, sizeof(buf), "../x11spice --display :%s localhost:5900-5999 --hide",
display);
snprintf(buf, sizeof(buf), "../x11spice --display :%s localhost:5900-5999 --hide --config %s",
display, server->conffile);
return execl("/bin/sh", "sh", "-c", buf, NULL);
......@@ -100,9 +100,25 @@ int x11spice_start(x11spice_server_t *server, test_t *test)
int rc;
int pos = 0;
int flush;
FILE *fp;
server->running = FALSE;
server->conffile = g_test_build_filename(G_TEST_BUILT, "run", test->name, "x11spice.conf", NULL);
if (!server->conffile) {
g_warning("Failed to create conffile");
g_test_fail();
return -1;
}
fp = fopen(server->conffile, "w");
if (fp) {
char *config_data = "[spice]\n"
"disable-ticketing=true\n";
fwrite(config_data, 1, strlen(config_data), fp);
fclose(fp);
}
if (socketpair(PF_LOCAL, SOCK_STREAM, 0, fd))
return -1;
......@@ -122,7 +138,8 @@ int x11spice_start(x11spice_server_t *server, test_t *test)
return -1;
}
server->logfd = open(test->logfile, O_CREAT | O_WRONLY, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
server->logfd = open(test->logfile, O_CREAT | O_WRONLY | O_TRUNC,
S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
if (server->logfd <= 0) {
x11spice_stop(server);
return -1;
......
......@@ -38,6 +38,7 @@ typedef struct {
pthread_t flush_thread;
gboolean running;
gchar *uri;
const gchar *conffile;
} x11spice_server_t;
/*----------------------------------------------------------------------------
......
......@@ -26,13 +26,11 @@ connection status and provide a mechanism to disconnect a remote viewer
or exit the program altogether.
.SH OPTIONS
.TP
\fB\-\-viewonly\fR
This will prevent a remote viewer from being able to inject mouse or keyboard
commands.
.TP
\fB\-\-timeout\fR[=\fISECONDS\fR]
If a timeout is specificed, if no connection is made within the given number of seconds,
x11spice will exit.
\fB\-\-config\fR[=\fIFILENAME\fR]
This will read configuration settings from FILENAME, ignoring all settings
in normal XDG locations. If not provided, x11spice will first read settings
from /etc/xdg/x11spice/x11spice.conf, then overwrite them with any settings read
from ~/.config/x11spice/x11spice.conf.
.TP
\fB\-\-display\fR=\fIDISPLAY\fR
DISPLAY will use an alternate Xorg server. The string should be in the standard
......@@ -43,19 +41,27 @@ When this option is selected, x11spice will generate a password randomly
and use that for the connection; the password will be printed to the standard
output for use. If the optional LEN is given, the password will have that length.
.TP
\fB\-\-password-file\fR={\fI-\fR|\fIPASSWORD\fR}
If specified, x11spice will read the password from the given file, or stdin in the
case of a file named \fI-\fR.
\fB\-\-hide\fR
This will prevent the x11spice user interface from appearing at all.
.TP
\fB\-\-minimize\fR
If given, the x11spice user interface will start minimized.
.TP
\fB\-\-password\fR=\fIPASSWORD\fR
If given, x11spice will directly use PASSWORD as an option. \fBNote: this is not recommended.\fR
This will expose the password in the process list, which is a security concern.
.TP
\fB\-\-hide\fR
This will prevent the x11spice user interface from appearing at all.
\fB\-\-password-file\fR={\fI-\fR|\fIPASSWORD\fR}
If specified, x11spice will read the password from the given file, or stdin in the
case of a file named \fI-\fR.
.TP
\fB\-\-minimize\fR
If given, the x11spice user interface will start minimized.
\fB\-\-timeout\fR[=\fISECONDS\fR]
If a timeout is specificed, if no connection is made within the given number of seconds,
x11spice will exit.
.TP
\fB\-\-viewonly\fR
This will prevent a remote viewer from being able to inject mouse or keyboard
commands.
.SH EXIT STATUS
x11spice will return a status of 0 if it is able to start a Spice session.
......
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