summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonathon Jongsma <jjongsma@redhat.com>2015-02-12 10:55:46 -0600
committerFabiano FidĂȘncio <fidencio@redhat.com>2015-02-23 23:00:46 +0100
commita763d0f76cc4ebede88334578574dab2bebf56ff (patch)
treeab211575ea8893299822a5faa4f78964fa3eaa8d
parentcd9845478328c00254919e73da7cb0141c96b4fc (diff)
downloadspice-a763d0f76cc4ebede88334578574dab2bebf56ff.tar.gz
spice-a763d0f76cc4ebede88334578574dab2bebf56ff.tar.xz
spice-a763d0f76cc4ebede88334578574dab2bebf56ff.zip
Remove last usage of global 'reds' variable
This should be the final piece of removing the global reds variable. We still need a global variable to clean up during the atexit() function, but we use a GList of servers (even though we technically don't support multiple servers in the same process yet).
-rw-r--r--server/reds.c78
-rw-r--r--server/reds.h1
2 files changed, 26 insertions, 53 deletions
diff --git a/server/reds.c b/server/reds.c
index b9252cfa..24562eef 100644
--- a/server/reds.c
+++ b/server/reds.c
@@ -90,7 +90,9 @@
static pthread_mutex_t *lock_cs;
static long *lock_count;
-RedsState *reds = NULL;
+/* While we can technically create more than one server in a process, the
+ * intended use is to support a single server per process */
+GList *servers = NULL;
typedef struct RedLinkInfo {
RedsState *reds;
@@ -819,7 +821,6 @@ static int reds_get_n_clients(RedsState *reds)
SPICE_GNUC_VISIBLE int spice_server_get_num_clients(SpiceServer *s)
{
- spice_assert(reds == s);
return reds_get_n_clients(s);
}
@@ -2311,7 +2312,6 @@ SPICE_GNUC_VISIBLE int spice_server_add_client(SpiceServer *s, int socket, int s
{
RedLinkInfo *link;
- spice_assert(reds == s);
if (!(link = reds_init_client_connection(s, socket))) {
spice_warning("accept failed");
return -1;
@@ -2328,7 +2328,6 @@ SPICE_GNUC_VISIBLE int spice_server_add_ssl_client(SpiceServer *s, int socket, i
{
RedLinkInfo *link;
- spice_assert(reds == s);
if (!(link = reds_init_client_ssl_connection(s, socket))) {
return -1;
}
@@ -2634,8 +2633,9 @@ static int reds_init_ssl(RedsState *reds)
return 0;
}
-static void reds_exit(void)
+static void reds_destroy_internal(RedsState *reds)
{
+ g_array_unref(reds->renderers);
if (reds->main_channel) {
main_channel_close(reds->main_channel);
}
@@ -2645,6 +2645,16 @@ static void reds_exit(void)
#endif
}
+static void reds_exit(void)
+{
+ GList *l;
+
+ for (l = servers; l != NULL; l = l->next) {
+ RedsState *reds = l->data;
+ reds_destroy_internal(reds);
+ }
+}
+
static inline void on_activating_ticketing(RedsState *reds)
{
if (!reds->ticketing_enabled && reds_main_channel_connected(reds)) {
@@ -2986,8 +2996,6 @@ static int spice_server_char_device_add_interface(SpiceServer *s,
SPICE_CONTAINEROF(sin, SpiceCharDeviceInstance, base);
SpiceCharDeviceState *dev_state = NULL;
- spice_assert(s == reds);
-
spice_info("CHAR_DEVICE %s", char_device->subtype);
if (strcmp(char_device->subtype, SUBTYPE_VDAGENT) == 0) {
if (s->vdagent) {
@@ -3060,8 +3068,6 @@ SPICE_GNUC_VISIBLE int spice_server_add_interface(SpiceServer *s,
{
const SpiceBaseInterface *interface = sin->sif;
- spice_assert(reds == s);
-
if (strcmp(interface->type, SPICE_INTERFACE_KEYBOARD) == 0) {
spice_info("SPICE_INTERFACE_KEYBOARD");
if (interface->major_version != SPICE_INTERFACE_KEYBOARD_MAJOR ||
@@ -3225,6 +3231,7 @@ const char *version_string = VERSION;
static int do_spice_init(RedsState *reds, SpiceCoreInterface *core_interface)
{
+ static gboolean first = TRUE;
spice_info("starting %s", version_string);
if (core_interface->base.major_version != SPICE_INTERFACE_CORE_MAJOR) {
@@ -3303,7 +3310,11 @@ static int do_spice_init(RedsState *reds, SpiceCoreInterface *core_interface)
if (reds->allow_multiple_clients) {
spice_warning("spice: allowing multiple client connections");
}
- atexit(reds_exit);
+ if (first) {
+ atexit(reds_exit);
+ first = FALSE;
+ }
+ servers = g_list_prepend(servers, reds);
return 0;
err:
@@ -3313,10 +3324,7 @@ err:
/* new interface */
SPICE_GNUC_VISIBLE SpiceServer *spice_server_new(void)
{
- /* we can't handle multiple instances (yet) */
- spice_assert(reds == NULL);
-
- reds = spice_new0(RedsState, 1);
+ RedsState *reds = spice_new0(RedsState, 1);
reds->default_channel_security =
SPICE_CHANNEL_SECURITY_NONE | SPICE_CHANNEL_SECURITY_SSL;
reds->default_renderer = "sw";
@@ -3380,7 +3388,6 @@ SPICE_GNUC_VISIBLE int spice_server_init(SpiceServer *s, SpiceCoreInterface *cor
{
int ret;
- spice_assert(reds == s);
ret = do_spice_init(s, core);
if (s->default_renderer) {
reds_add_renderer(s, s->default_renderer);
@@ -3390,9 +3397,10 @@ SPICE_GNUC_VISIBLE int spice_server_init(SpiceServer *s, SpiceCoreInterface *cor
SPICE_GNUC_VISIBLE void spice_server_destroy(SpiceServer *s)
{
- spice_assert(reds == s);
- g_array_unref(s->renderers);
- reds_exit();
+ reds_destroy_internal(s);
+ /* remove the server from the list of servers so that we don't attempt to
+ * free it again at exit */
+ servers = g_list_remove(servers, s);
}
SPICE_GNUC_VISIBLE spice_compat_version_t spice_get_current_compat_version(void)
@@ -3417,7 +3425,6 @@ SPICE_GNUC_VISIBLE int spice_server_set_compat_version(SpiceServer *s,
SPICE_GNUC_VISIBLE int spice_server_set_port(SpiceServer *s, int port)
{
- spice_assert(reds == s);
if (port < 0 || port > 0xffff) {
return -1;
}
@@ -3427,7 +3434,6 @@ SPICE_GNUC_VISIBLE int spice_server_set_port(SpiceServer *s, int port)
SPICE_GNUC_VISIBLE void spice_server_set_addr(SpiceServer *s, const char *addr, int flags)
{
- spice_assert(reds == s);
g_strlcpy(s->spice_addr, addr, sizeof(s->spice_addr));
if (flags & SPICE_ADDR_FLAG_IPV4_ONLY) {
s->spice_family = PF_INET;
@@ -3439,21 +3445,18 @@ SPICE_GNUC_VISIBLE void spice_server_set_addr(SpiceServer *s, const char *addr,
SPICE_GNUC_VISIBLE int spice_server_set_listen_socket_fd(SpiceServer *s, int listen_fd)
{
- spice_assert(reds == s);
s->spice_listen_socket_fd = listen_fd;
return 0;
}
SPICE_GNUC_VISIBLE int spice_server_set_exit_on_disconnect(SpiceServer *s, int flag)
{
- spice_assert(reds == s);
s->exit_on_disconnect = !!flag;
return 0;
}
SPICE_GNUC_VISIBLE int spice_server_set_noauth(SpiceServer *s)
{
- spice_assert(reds == s);
memset(s->taTicket.password, 0, sizeof(s->taTicket.password));
s->ticketing_enabled = 0;
return 0;
@@ -3461,7 +3464,6 @@ SPICE_GNUC_VISIBLE int spice_server_set_noauth(SpiceServer *s)
SPICE_GNUC_VISIBLE int spice_server_set_sasl(SpiceServer *s, int enabled)
{
- spice_assert(reds == s);
#if HAVE_SASL
s->sasl_enabled = enabled;
return 0;
@@ -3472,7 +3474,6 @@ SPICE_GNUC_VISIBLE int spice_server_set_sasl(SpiceServer *s, int enabled)
SPICE_GNUC_VISIBLE int spice_server_set_sasl_appname(SpiceServer *s, const char *appname)
{
- spice_assert(reds == s);
#if HAVE_SASL
free(s->sasl_appname);
s->sasl_appname = spice_strdup(appname);
@@ -3499,8 +3500,6 @@ SPICE_GNUC_VISIBLE int spice_server_set_ticket(SpiceServer *s,
int fail_if_connected,
int disconnect_if_connected)
{
- spice_assert(reds == s);
-
if (reds_main_channel_connected(s)) {
if (fail_if_connected) {
return -1;
@@ -3532,7 +3531,6 @@ SPICE_GNUC_VISIBLE int spice_server_set_tls(SpiceServer *s, int port,
const char *private_key_file, const char *key_passwd,
const char *dh_key_file, const char *ciphersuite)
{
- spice_assert(reds == s);
if (port == 0 || ca_cert_file == NULL || certs_file == NULL ||
private_key_file == NULL) {
return -1;
@@ -3568,20 +3566,17 @@ SPICE_GNUC_VISIBLE int spice_server_set_tls(SpiceServer *s, int port,
SPICE_GNUC_VISIBLE int spice_server_set_image_compression(SpiceServer *s,
spice_image_compression_t comp)
{
- spice_assert(reds == s);
reds_set_image_compression(s, comp);
return 0;
}
SPICE_GNUC_VISIBLE spice_image_compression_t spice_server_get_image_compression(SpiceServer *s)
{
- spice_assert(reds == s);
return s->image_compression;
}
SPICE_GNUC_VISIBLE int spice_server_set_jpeg_compression(SpiceServer *s, spice_wan_compression_t comp)
{
- spice_assert(reds == s);
if (comp == SPICE_WAN_COMPRESSION_INVALID) {
spice_error("invalid jpeg state");
return -1;
@@ -3593,7 +3588,6 @@ SPICE_GNUC_VISIBLE int spice_server_set_jpeg_compression(SpiceServer *s, spice_w
SPICE_GNUC_VISIBLE int spice_server_set_zlib_glz_compression(SpiceServer *s, spice_wan_compression_t comp)
{
- spice_assert(reds == s);
if (comp == SPICE_WAN_COMPRESSION_INVALID) {
spice_error("invalid zlib_glz state");
return -1;
@@ -3620,8 +3614,6 @@ SPICE_GNUC_VISIBLE int spice_server_set_channel_security(SpiceServer *s, const c
};
int i;
- spice_assert(reds == s);
-
if (channel == NULL) {
s->default_channel_security = security;
return 0;
@@ -3637,7 +3629,6 @@ SPICE_GNUC_VISIBLE int spice_server_set_channel_security(SpiceServer *s, const c
SPICE_GNUC_VISIBLE int spice_server_get_sock_info(SpiceServer *s, struct sockaddr *sa, socklen_t *salen)
{
- spice_assert(reds == s);
if (main_channel_getsockname(s->main_channel, sa, salen) < 0) {
return -1;
}
@@ -3646,7 +3637,6 @@ SPICE_GNUC_VISIBLE int spice_server_get_sock_info(SpiceServer *s, struct sockadd
SPICE_GNUC_VISIBLE int spice_server_get_peer_info(SpiceServer *s, struct sockaddr *sa, socklen_t *salen)
{
- spice_assert(reds == s);
if (main_channel_getpeername(s->main_channel, sa, salen) < 0) {
return -1;
}
@@ -3655,13 +3645,11 @@ SPICE_GNUC_VISIBLE int spice_server_get_peer_info(SpiceServer *s, struct sockadd
SPICE_GNUC_VISIBLE int spice_server_is_server_mouse(SpiceServer *s)
{
- spice_assert(reds == s);
return s->mouse_mode == SPICE_MOUSE_MODE_SERVER;
}
SPICE_GNUC_VISIBLE int spice_server_add_renderer(SpiceServer *s, const char *name)
{
- spice_assert(reds == s);
if (!reds_add_renderer(s, name)) {
return -1;
}
@@ -3678,7 +3666,6 @@ SPICE_GNUC_VISIBLE int spice_server_kbd_leds(SpiceKbdInstance *sin, int leds)
SPICE_GNUC_VISIBLE int spice_server_set_streaming_video(SpiceServer *s, int value)
{
- spice_assert(reds == s);
if (value != SPICE_STREAM_VIDEO_OFF &&
value != SPICE_STREAM_VIDEO_ALL &&
value != SPICE_STREAM_VIDEO_FILTER)
@@ -3695,14 +3682,12 @@ uint32_t reds_get_streaming_video(RedsState *reds)
SPICE_GNUC_VISIBLE int spice_server_set_playback_compression(SpiceServer *s, int enable)
{
- spice_assert(reds == s);
snd_set_playback_compression(enable);
return 0;
}
SPICE_GNUC_VISIBLE int spice_server_set_agent_mouse(SpiceServer *s, int enable)
{
- spice_assert(reds == s);
s->agent_mouse = enable;
reds_update_mouse_mode(s);
return 0;
@@ -3710,7 +3695,6 @@ SPICE_GNUC_VISIBLE int spice_server_set_agent_mouse(SpiceServer *s, int enable)
SPICE_GNUC_VISIBLE int spice_server_set_agent_copypaste(SpiceServer *s, int enable)
{
- spice_assert(reds == s);
s->agent_copypaste = enable;
s->agent_state.write_filter.copy_paste_enabled = s->agent_copypaste;
s->agent_state.read_filter.copy_paste_enabled = s->agent_copypaste;
@@ -3719,7 +3703,6 @@ SPICE_GNUC_VISIBLE int spice_server_set_agent_copypaste(SpiceServer *s, int enab
SPICE_GNUC_VISIBLE int spice_server_set_agent_file_xfer(SpiceServer *s, int enable)
{
- spice_assert(reds == s);
s->agent_file_xfer = enable;
s->agent_state.write_filter.file_xfer_enabled = s->agent_file_xfer;
s->agent_state.read_filter.file_xfer_enabled = s->agent_file_xfer;
@@ -3762,7 +3745,6 @@ SPICE_GNUC_VISIBLE int spice_server_migrate_connect(SpiceServer *s, const char*
spice_info(NULL);
spice_assert(s->migration_interface);
- spice_assert(reds == s);
if (s->expect_migrate) {
spice_info("consecutive calls without migration. Canceling previous call");
@@ -3819,7 +3801,6 @@ SPICE_GNUC_VISIBLE int spice_server_migrate_info(SpiceServer *s, const char* des
SPICE_GNUC_VISIBLE int spice_server_migrate_start(SpiceServer *s)
{
- spice_assert(reds == s);
spice_info(NULL);
if (!s->mig_spice) {
return -1;
@@ -3829,8 +3810,6 @@ SPICE_GNUC_VISIBLE int spice_server_migrate_start(SpiceServer *s)
SPICE_GNUC_VISIBLE int spice_server_migrate_client_state(SpiceServer *s)
{
- spice_assert(reds == s);
-
if (!reds_main_channel_connected(s)) {
return SPICE_MIGRATE_CLIENT_NONE;
} else if (s->mig_wait_connect) {
@@ -3849,7 +3828,6 @@ SPICE_GNUC_VISIBLE int spice_server_migrate_end(SpiceServer *s, int completed)
spice_info(NULL);
spice_assert(s->migration_interface);
- spice_assert(reds == s);
sif = SPICE_CONTAINEROF(s->migration_interface->base.sif, SpiceMigrateInterface, base);
if (completed && !s->expect_migrate && s->num_clients) {
@@ -3876,7 +3854,6 @@ complete:
/* interface for switch-host migration */
SPICE_GNUC_VISIBLE int spice_server_migrate_switch(SpiceServer *s)
{
- spice_assert(reds == s);
spice_info(NULL);
if (!s->num_clients) {
return 0;
@@ -3890,7 +3867,6 @@ SPICE_GNUC_VISIBLE void spice_server_vm_start(SpiceServer *s)
{
RingItem *item;
- spice_assert(s == reds);
s->vm_running = TRUE;
RING_FOREACH(item, &s->char_devs_states) {
SpiceCharDeviceStateItem *st_item;
@@ -3905,7 +3881,6 @@ SPICE_GNUC_VISIBLE void spice_server_vm_stop(SpiceServer *s)
{
RingItem *item;
- spice_assert(s == reds);
s->vm_running = FALSE;
RING_FOREACH(item, &s->char_devs_states) {
SpiceCharDeviceStateItem *st_item;
@@ -3918,7 +3893,6 @@ SPICE_GNUC_VISIBLE void spice_server_vm_stop(SpiceServer *s)
SPICE_GNUC_VISIBLE void spice_server_set_seamless_migration(SpiceServer *s, int enable)
{
- spice_assert(s == reds);
/* seamless migration is not supported with multiple clients */
s->seamless_migration_enabled = enable && !s->allow_multiple_clients;
spice_debug("seamless migration enabled=%d", enable);
diff --git a/server/reds.h b/server/reds.h
index c72562ed..ca2d5b7d 100644
--- a/server/reds.h
+++ b/server/reds.h
@@ -34,7 +34,6 @@
#define SPICE_GNUC_VISIBLE __attribute__ ((visibility ("default")))
typedef struct RedsState RedsState;
-extern RedsState *reds;
struct QXLState {
QXLInterface *qif;