From cb0c2aabc202b0842f890dd09f6066008f64c66a Mon Sep 17 00:00:00 2001 From: Kevin Easton Date: Mon, 30 Apr 2012 08:05:04 +0000 Subject: [PATCH] Improve error handling in /detach - will now soft-fail the detach instead of killing the whole client. git-svn-id: svn://svn.code.sf.net/p/bitchx/code/trunk@163 13b04d17-f746-0410-82c6-800466cd88b0 --- source/commands2.c | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/source/commands2.c b/source/commands2.c index 050dfe8..97933c8 100644 --- a/source/commands2.c +++ b/source/commands2.c @@ -2587,7 +2587,7 @@ static int create_ipc_socket(void) if ((s = connect_by_number(NULL, &port, SERVICE_SERVER, PROTOCOL_TCP, 0)) < 0) { - fprintf(stderr, "error creating socket (%d: %s)\r\n", s, strerror(errno)); + bitchsay("Error creating IPC socket: [%d] %s", s, strerror(errno)); return 1; } @@ -2663,8 +2663,7 @@ BUILT_IN_COMMAND(detachcmd) { #if !defined(__EMX__) && !defined(WINNT) && !defined (GUI) && defined(WANT_DETACH) #ifndef PUBLIC_ACCESS -pid_t pid = getpid(); -pid_t sid; +pid_t pid; /* * this is written so that a running bx client will attempt to * detach and then later a screen type program can be used to re-attach @@ -2681,29 +2680,26 @@ pid_t sid; /* * create a server socket with the above name. */ + if (create_ipc_socket()) + return; + switch(pid = fork()) { case -1: - put_it("error in fork"); + bitchsay("fork() failed: %s", strerror(errno)); return; default: - { do_detach(pid, args); + /* Not reached */ return; - } case 0: break; } - if ((sid = setpgid(0, 0)) == -1) - return; + + setpgid(0, 0); already_detached = 1; use_input = 0; - if (create_ipc_socket()) - { - yell("Error creating IPC socket."); - _exit(0); - } close_detach_fd(); kill_attached_if_needed(1); disable_stop();