bs11_config: makes sure we disconnect properly before exiting

diff --git a/src/bs11_config.c b/src/bs11_config.c
index bb15391..1e980c9 100644
--- a/src/bs11_config.c
+++ b/src/bs11_config.c
@@ -421,7 +421,7 @@
 	case BS11_STATE_MAINTENANCE:
 		if (command) {
 			if (!strcmp(command, "disconnect"))
-				exit(0);
+				abis_nm_bs11_factory_logon(g_bts, 0);
 			else if (!strcmp(command, "reconnect"))
 				rc = abis_nm_bs11_bsc_disconnect(g_bts, 1);
 			else if (!strcmp(command, "software")
@@ -438,9 +438,13 @@
 			} else if (!strcmp(command, "delete-trx1")) {
 				abis_nm_bs11_delete_object(g_bts, BS11_OBJ_BBSIG, 1);
 				abis_nm_bs11_delete_object(g_bts, BS11_OBJ_PA, 1);
+				sleep(5);
+				abis_nm_bs11_factory_logon(g_bts, 0);
 				command = NULL;
 			} else if (!strcmp(command, "create-trx1")) {
 				create_trx1(g_bts);
+				sleep(5);
+				abis_nm_bs11_factory_logon(g_bts, 0);
 				command = NULL;
 			} else if (!strcmp(command, "restart")) {
 				abis_nm_bs11_restart(g_bts);
@@ -451,7 +455,7 @@
 	case BS11_STATE_NORMAL:
 		if (command) {
 			if (!strcmp(command, "reconnect"))
-				exit(0);
+				abis_nm_bs11_factory_logon(g_bts, 0);
 			else if (!strcmp(command, "disconnect"))
 				abis_nm_bs11_bsc_disconnect(g_bts, 0);
 			else if (!strcmp(command, "query")) {
@@ -460,6 +464,8 @@
 				abis_nm_bs11_get_oml_tei_ts(g_bts);
 				abis_nm_bs11_get_trx_power(&g_bts->trx[0]);
 				abis_nm_bs11_get_trx_power(&g_bts->trx[1]);
+				sleep(5);
+				abis_nm_bs11_factory_logon(g_bts, 0);
 				command = NULL;
 			}
 		} else if (param_disconnect) {
diff --git a/src/rs232.c b/src/rs232.c
index 90e8818..92e2e9b 100644
--- a/src/rs232.c
+++ b/src/rs232.c
@@ -50,6 +50,8 @@
 
 #define LAPD_HDR_LEN	10
 
+static int handle_ser_write(struct bsc_fd *bfd);
+
 /* callback from abis_nm */
 int _abis_nm_sendmsg(struct msgb *msg)
 {
@@ -78,6 +80,9 @@
 	msgb_enqueue(&sh->tx_queue, msg);
 	sh->fd.when |= BSC_FD_WRITE;
 
+	/* we try to immediately send */
+	handle_ser_write(&sh->fd);
+
 	return 0;
 }