From 9f19ab832505ffd721cd466eba1a479ad4ff7cd4 Mon Sep 17 00:00:00 2001 From: Brendan Taylor Date: Tue, 13 Sep 2011 09:17:28 +0000 Subject: make init_fifo and init_socket be less surprising. --- src/io.c | 21 +++++++++------------ src/io.h | 6 ++---- src/variables.c | 10 ++++++++-- 3 files changed, 19 insertions(+), 18 deletions(-) (limited to 'src') diff --git a/src/io.c b/src/io.c index edeca68..5600c79 100644 --- a/src/io.c +++ b/src/io.c @@ -72,8 +72,8 @@ attach_fifo(gchar *path) { } -/*@null@*/ gchar* -init_fifo(gchar *dir) { /* return dir or, on error, free dir and return NULL */ +gboolean +init_fifo(const gchar *dir) { if (uzbl.comm.fifo_path) { /* we're changing the fifo path, get rid of the old fifo if one exists */ if (unlink(uzbl.comm.fifo_path) == -1) @@ -90,15 +90,14 @@ init_fifo(gchar *dir) { /* return dir or, on error, free dir and return NULL */ if (mkfifo (path, 0666) == 0) { if(attach_fifo(path)) - return dir; + return TRUE; else g_warning("init_fifo: can't attach to %s: %s\n", path, strerror(errno)); } else g_warning ("init_fifo: can't create %s: %s\n", path, strerror(errno)); /* if we got this far, there was an error; clean up */ - g_free(dir); g_free(path); - return NULL; + return FALSE; } @@ -286,8 +285,8 @@ attach_socket(gchar *path, struct sockaddr_un *local) { } -/*@null@*/ gchar* -init_socket(gchar *dir) { /* return dir or, on error, free dir and return NULL */ +gboolean +init_socket(const gchar *dir) { if (uzbl.comm.socket_path) { /* remove an existing socket should one exist */ if (unlink(uzbl.comm.socket_path) == -1) g_warning ("init_socket: couldn't unlink socket at %s\n", uzbl.comm.socket_path); @@ -296,8 +295,7 @@ init_socket(gchar *dir) { /* return dir or, on error, free dir and return NULL * } if (*dir == ' ') { - g_free(dir); - return NULL; + return FALSE; } gchar *path = build_stream_name(SOCKET, dir); @@ -311,11 +309,10 @@ init_socket(gchar *dir) { /* return dir or, on error, free dir and return NULL * strcpy (local.sun_path, path); if(attach_socket(path, &local)) { - return dir; + return TRUE; } else g_warning("init_socket: can't attach to %s: %s\n", path, strerror(errno)); /* if we got this far, there was an error; cleanup */ g_free(path); - g_free(dir); - return NULL; + return FALSE; } diff --git a/src/io.h b/src/io.h index a6ea0a1..82b31e6 100644 --- a/src/io.h +++ b/src/io.h @@ -8,14 +8,12 @@ build_stream_name(int type, const gchar *dir); gboolean control_fifo(GIOChannel *gio, GIOCondition condition); -/*@null@*/ gchar* -init_fifo(gchar *dir); +gboolean init_fifo(const gchar *dir); gboolean control_stdin(GIOChannel *gio, GIOCondition condition); void create_stdin(); -/*@null@*/ gchar* -init_socket(gchar *dir); +gboolean init_socket(const gchar *dir); gboolean control_socket(GIOChannel *chan); gboolean control_client_socket(GIOChannel *chan); diff --git a/src/variables.c b/src/variables.c index a1063a0..5d770e6 100644 --- a/src/variables.c +++ b/src/variables.c @@ -465,12 +465,18 @@ set_current_encoding() { void cmd_fifo_dir() { - uzbl.behave.fifo_dir = init_fifo(uzbl.behave.fifo_dir); + if(!init_fifo(uzbl.behave.fifo_dir)) { + g_free(uzbl.behave.fifo_dir); + uzbl.behave.fifo_dir = NULL; + } } void cmd_socket_dir() { - uzbl.behave.socket_dir = init_socket(uzbl.behave.socket_dir); + if(!init_socket(uzbl.behave.socket_dir)) { + g_free(uzbl.behave.socket_dir); + uzbl.behave.socket_dir = NULL; + } } void -- cgit v1.2.3