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
This commit is contained in:
Kevin Easton
2012-02-01 13:21:47 +00:00
parent 71cc2bf5f4
commit 5cf8ed2c79
2 changed files with 26 additions and 26 deletions

View File

@@ -330,7 +330,6 @@ extern short ospeed;
#endif #endif
void reattach_tty(char *, char *); void reattach_tty(char *, char *);
int create_ipc_socket(void);
void init_socketpath(void); void init_socketpath(void);
void kill_attached_if_needed(int); void kill_attached_if_needed(int);
void setup_pid(); void setup_pid();

View File

@@ -2577,17 +2577,20 @@ int i, j;
} }
} }
int create_ipc_socket(void) static int create_ipc_socket(void)
{ {
int s = -1, int s = -1, u = -1;
u = -1;
unsigned short port = 0; unsigned short port = 0;
char buf[BIG_BUFFER_SIZE+1];
init_socketpath(); 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]; fprintf(stderr, "error creating socket (%d: %s)\r\n", s, strerror(errno));
return 1;
}
sprintf(buf, socket_path, port); sprintf(buf, socket_path, port);
if ((u = open(buf, O_CREAT|O_WRONLY, 0600)) != -1) if ((u = open(buf, O_CREAT|O_WRONLY, 0600)) != -1)
{ {
@@ -2604,11 +2607,9 @@ unsigned short port = 0;
set_non_blocking(s); set_non_blocking(s);
add_socketread(s, port, 0, socket_path, handle_reconnect, NULL); add_socketread(s, port, 0, socket_path, handle_reconnect, NULL);
save_ipc = s; save_ipc = s;
return 0; return 0;
} }
fprintf(stderr, "error creating socket\r\n");
return 1;
}
void do_detach(int pid, char *args) void do_detach(int pid, char *args)