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,37 +2577,38 @@ 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));
sprintf(buf, socket_path, port); return 1;
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\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;
} }