From 5cf8ed2c792fe99a48abf6b1a30a9cbc302d3574 Mon Sep 17 00:00:00 2001 From: Kevin Easton Date: Wed, 1 Feb 2012 13:21:47 +0000 Subject: [PATCH] Cleanup create_ipc_socket() and ensure it detects all errors in connect_by_number(). Make function static since it is only used in one source file. git-svn-id: svn://svn.code.sf.net/p/bitchx/code/trunk@145 13b04d17-f746-0410-82c6-800466cd88b0 --- include/irc.h | 1 - source/commands2.c | 51 +++++++++++++++++++++++----------------------- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/include/irc.h b/include/irc.h index 4464ef6..2863ff0 100644 --- a/include/irc.h +++ b/include/irc.h @@ -330,7 +330,6 @@ extern short ospeed; #endif void reattach_tty(char *, char *); -int create_ipc_socket(void); void init_socketpath(void); void kill_attached_if_needed(int); void setup_pid(); diff --git a/source/commands2.c b/source/commands2.c index 6417b32..c7a30e2 100644 --- a/source/commands2.c +++ b/source/commands2.c @@ -2577,37 +2577,38 @@ int i, j; } } -int create_ipc_socket(void) +static int create_ipc_socket(void) { -int s = -1, - u = -1; -unsigned short port = 0; + int s = -1, u = -1; + unsigned short port = 0; + char buf[BIG_BUFFER_SIZE+1]; init_socketpath(); - if ((s = connect_by_number(NULL, &port, SERVICE_SERVER, PROTOCOL_TCP, 0)) != -1) + if ((s = connect_by_number(NULL, &port, SERVICE_SERVER, PROTOCOL_TCP, 0)) < 0) { - char buf[BIG_BUFFER_SIZE+1]; - sprintf(buf, socket_path, port); - if ((u = open(buf, O_CREAT|O_WRONLY, 0600)) != -1) - { - chmod(buf, SOCKMODE); - chown(buf, getuid(), getgid()); - make_cookie(); - write(u, connect_cookie, strlen(connect_cookie)); - write(u, "\n", 1); - close(u); - } -#ifdef F_SETOWN - fcntl(s, F_SETOWN, getpid()); -#endif /* F_SETOWN */ - set_non_blocking(s); - add_socketread(s, port, 0, socket_path, handle_reconnect, NULL); - save_ipc = s; - return 0; + fprintf(stderr, "error creating socket (%d: %s)\r\n", s, strerror(errno)); + return 1; } - fprintf(stderr, "error creating socket\r\n"); - return 1; + + sprintf(buf, socket_path, port); + if ((u = open(buf, O_CREAT|O_WRONLY, 0600)) != -1) + { + chmod(buf, SOCKMODE); + chown(buf, getuid(), getgid()); + make_cookie(); + write(u, connect_cookie, strlen(connect_cookie)); + write(u, "\n", 1); + close(u); + } +#ifdef F_SETOWN + fcntl(s, F_SETOWN, getpid()); +#endif /* F_SETOWN */ + set_non_blocking(s); + add_socketread(s, port, 0, socket_path, handle_reconnect, NULL); + save_ipc = s; + + return 0; }