From 53ee70fd2e4c59b4e7b6d221e4cc594e2d1c13b4 Mon Sep 17 00:00:00 2001 From: samr7 Date: Fri, 24 Oct 2008 19:49:05 +0000 Subject: Use strerror() to convert errno values to useful descriptions. git-svn-id: http://nohands.svn.sourceforge.net/svnroot/nohands/trunk@13 126591fb-c623-4b62-a76d-97a8e4f34109 --- libhfp/bt.cpp | 31 ++++++++++++----------- libhfp/hfp.cpp | 73 ++++++++++++++++++++++++++++++++++++------------------- libhfp/rfcomm.cpp | 36 +++++++++++++++------------ 3 files changed, 86 insertions(+), 54 deletions(-) diff --git a/libhfp/bt.cpp b/libhfp/bt.cpp index 32179a9..82f0a94 100644 --- a/libhfp/bt.cpp +++ b/libhfp/bt.cpp @@ -359,11 +359,12 @@ SdpShutdown(void) int err, status; err = kill(m_pid, SIGKILL); if (err) - m_ei->LogWarn("Send sig to SDP helper process: %d\n", - errno); + m_ei->LogWarn("Send sig to SDP helper process: %s\n", + strerror(errno)); err = waitpid(m_pid, &status, 0); if (err < 0) - m_ei->LogWarn("Reap SDP helper process: %d\n", errno); + m_ei->LogWarn("Reap SDP helper process: %s\n", + strerror(errno)); m_pid = -1; } @@ -403,7 +404,7 @@ HciDataReadyNot(SocketNotifier *notp, int fh) (errno == ENOBUFS)) return; - m_ei->LogWarn("HCI socket read error: %d\n", errno); + m_ei->LogWarn("HCI socket read error: %s\n", strerror(errno)); m_hub->InvoluntaryStop(); return; } @@ -650,7 +651,7 @@ HciSend(int fh, HciTask *taskp, void *data, size_t len) free(buf); if (ret < 0) { - m_ei->LogError("HCI write failed: %d\n", errno); + m_ei->LogError("HCI write failed: %s\n", strerror(errno)); return -errno; } @@ -768,7 +769,7 @@ HciInit(void) fh = hci_open_dev(did); if (fh < 0) { did = -errno; - m_ei->LogWarn("Could not open HCI: %d\n", errno); + m_ei->LogWarn("Could not open HCI: %s\n", strerror(errno)); return did; } @@ -781,7 +782,8 @@ HciInit(void) if (setsockopt(fh, SOL_HCI, HCI_FILTER, &flt, sizeof(flt)) < 0) { did = -errno; - m_ei->LogWarn("Could not set filter on HCI: %d\n", errno); + m_ei->LogWarn("Could not set filter on HCI: %s\n", + strerror(errno)); close(fh); return did; } @@ -935,14 +937,15 @@ Start(void) res = m_sdp_handler.SdpCreateThread(); if (res) { - m_ei->LogWarn("Could not create SDP task thread: %d\n", - -res); + m_ei->LogWarn("Could not create SDP task thread: %s\n", + strerror(-res)); goto failed; } res = m_hci_handler.HciInit(); if (res) { - m_ei->LogWarn("Could not create HCI raw socket: %d\n", -res); + m_ei->LogWarn("Could not create HCI raw socket: %s\n", + strerror(-res)); goto failed; } @@ -1120,12 +1123,12 @@ HciInquiryResult(HciTask *taskp) if (taskp->m_complete) { if (taskp->m_errno) { if (taskp->m_errno == EIO) - m_ei->LogWarn("Inquiry failed: %d/%d\n", - taskp->m_errno, + m_ei->LogWarn("Inquiry failed: %s (%d)\n", + strerror(taskp->m_errno), taskp->m_hci_status); else - m_ei->LogWarn("Inquiry failed: %d\n", - taskp->m_errno); + m_ei->LogWarn("Inquiry failed: %s\n", + strerror(taskp->m_errno)); } delete taskp; m_inquiry_task = 0; diff --git a/libhfp/hfp.cpp b/libhfp/hfp.cpp index 7a111f5..06ad2e6 100644 --- a/libhfp/hfp.cpp +++ b/libhfp/hfp.cpp @@ -133,7 +133,8 @@ ScoListen(void) sock = socket(PF_BLUETOOTH, SOCK_SEQPACKET, BTPROTO_SCO); if (sock < 0) { - GetDi()->LogWarn("Create SCO socket: %d\n", errno); + GetDi()->LogWarn("Create SCO socket: %s\n", + strerror(errno)); return false; } @@ -142,17 +143,20 @@ ScoListen(void) bacpy(&saddr.sco_bdaddr, BDADDR_ANY); if (bind(sock, (struct sockaddr*)&saddr, sizeof(saddr)) < 0) { - GetDi()->LogWarn("Bind SCO socket: %d\n", errno); + GetDi()->LogWarn("Bind SCO socket: %s\n", + strerror(errno)); goto failed; } if (listen(sock, 1) < 0) { - GetDi()->LogWarn("Set SCO socket to listen: %d\n", errno); + GetDi()->LogWarn("Set SCO socket to listen: %s\n", + strerror(errno)); goto failed; } if (!SetNonBlock(sock, true)) { - GetDi()->LogWarn("Set SCO listener nonblocking: %d\n", errno); + GetDi()->LogWarn("Set SCO listener nonblocking: %s\n", + strerror(errno)); goto failed; } @@ -656,13 +660,15 @@ ScoGetParams(int ssock) size = sizeof(sci); if (getsockopt(ssock, SOL_SCO, SCO_CONNINFO, &sci, &size) < 0) { - GetDi()->LogWarn("Query SCO_CONNINFO: %d\n", errno); + GetDi()->LogWarn("Query SCO_CONNINFO: %s\n", + strerror(errno)); return false; } size = sizeof(sopts); if (getsockopt(ssock, SOL_SCO, SCO_OPTIONS, &sopts, &size) < 0) { - GetDi()->LogWarn("Query SCO_OPTIONS: %d\n", errno); + GetDi()->LogWarn("Query SCO_OPTIONS: %s\n", + strerror(errno)); return false; } @@ -686,7 +692,7 @@ bool HfpSession:: ScoConnect(void) { struct sockaddr_sco src, dest; - int ssock; + int ssock, err; if (!IsConnected()) { return false; @@ -708,26 +714,31 @@ ScoConnect(void) ssock = socket(PF_BLUETOOTH, SOCK_SEQPACKET, BTPROTO_SCO); if (ssock < 0) { - GetDi()->LogWarn("Create SCO socket: %d\n", errno); + GetDi()->LogWarn("Create SCO socket: %s\n", + strerror(errno)); return false; } if (bind(ssock, (struct sockaddr*)&src, sizeof(src)) < 0) { close(ssock); - GetDi()->LogWarn("Bind SCO socket: %d\n", errno); + GetDi()->LogWarn("Bind SCO socket: %s\n", + strerror(errno)); return false; } if (!SetNonBlock(ssock, true)) { close(ssock); - GetDi()->LogWarn("Set SCO socket nonblocking: %d\n", errno); + GetDi()->LogWarn("Set SCO socket nonblocking: %s\n", + strerror(errno)); return false; } if (connect(ssock, (struct sockaddr*)&dest, sizeof(dest)) < 0) { if ((errno != EINPROGRESS) && (errno != EAGAIN)) { + err = errno; close(ssock); - GetDi()->LogWarn("Connect SCO socket: %d\n", errno); + GetDi()->LogWarn("Connect SCO socket: %s\n", + strerror(err)); return false; } } @@ -800,7 +811,8 @@ ScoDataNotify(SocketNotifier *notp, int fh) if (!ioctl(m_sco_sock, TIOCOUTQ, &outq) < 0) { outq /= 2; } else { - GetDi()->LogWarn("SCO TIOCOUTQ: %d\n", errno); + GetDi()->LogWarn("SCO TIOCOUTQ: %s\n", + strerror(errno)); outq = m_hw_outq; } } else { @@ -959,6 +971,7 @@ SndPushInput(bool nonblock) unsigned int nsamples; uint8_t *buf; ssize_t res; + int err; if (!IsConnectedVoice()) { return; } @@ -978,11 +991,13 @@ SndPushInput(bool nonblock) } res = read(m_sco_sock, buf, nsamples * 2); if (res < 0) { - if ((errno != EAGAIN) && - (errno != ECONNRESET)) { - GetDi()->LogWarn("Read SCO data: %d\n", errno); + err = errno; + if ((err != EAGAIN) && + (err != ECONNRESET)) { + GetDi()->LogWarn("Read SCO data: %s\n", + strerror(err)); } - if (ReadErrorFatal(errno)) { + if (ReadErrorFatal(err)) { /* Connection is lost */ res = 0; } else { @@ -1025,6 +1040,7 @@ SndPushOutput(bool nonblock) unsigned int nsamples; uint8_t *buf; ssize_t res; + int err; if (!IsConnectedVoice()) { return; } @@ -1043,11 +1059,12 @@ SndPushOutput(bool nonblock) res = send(m_sco_sock, buf, nsamples * 2, MSG_NOSIGNAL); if (res < 0) { - if (errno != EAGAIN) { - GetDi()->LogWarn("Write SCO data: %d\n", - errno); + err = errno; + if (err != EAGAIN) { + GetDi()->LogWarn("Write SCO data: %s\n", + strerror(err)); } - if (WriteErrorFatal(errno)) { + if (WriteErrorFatal(err)) { /* Connection lost: both cbs asynchronous */ __DisconnectSco(true, true, true); } @@ -1205,6 +1222,7 @@ HfpDataReady(SocketNotifier *notp, int fh) { size_t cons; ssize_t ret; + int err; assert(fh == m_rfcomm_sock); assert(notp == m_rfcomm_not); @@ -1221,14 +1239,16 @@ HfpDataReady(SocketNotifier *notp, int fh) sizeof(m_rsp_buf) - (m_rsp_start + m_rsp_len)); if (ret < 0) { - GetDi()->LogWarn("Read from RFCOMM socket: %d\n", errno); + err = errno; + GetDi()->LogWarn("Read from RFCOMM socket: %s\n", + strerror(err)); /* * Some errors do not indicate loss of connection * Others do not indicate voluntary loss of connection */ - if (ReadErrorFatal(errno)) { - __Disconnect(true, ReadErrorVoluntary(errno)); + if (ReadErrorFatal(err)) { + __Disconnect(true, ReadErrorVoluntary(err)); } return; } @@ -1684,6 +1704,7 @@ StartCommand(void) { AtCommand *cmdp; int cl, rl; + int err; if (!IsRfcommConnected() || m_commands.Empty()) return; @@ -1696,9 +1717,11 @@ StartCommand(void) rl = send(m_rfcomm_sock, cmdp->m_command_text, cl, MSG_NOSIGNAL); if (rl < 0) { + err = errno; /* Problems!! */ - GetDi()->LogDebug("Write to RFCOMM socket: %d\n", errno); - __Disconnect(true, ReadErrorVoluntary(errno)); + GetDi()->LogDebug("Write to RFCOMM socket: %s\n", + strerror(err)); + __Disconnect(true, ReadErrorVoluntary(err)); } else if (rl != cl) { diff --git a/libhfp/rfcomm.cpp b/libhfp/rfcomm.cpp index b8d8762..30c7e76 100644 --- a/libhfp/rfcomm.cpp +++ b/libhfp/rfcomm.cpp @@ -181,8 +181,8 @@ RfcommListen(uint8_t channel) "Channel %d is in use\n", channel); } else { - GetDi()->LogWarn("Bind RFCOMM socket: %d\n", - errno); + GetDi()->LogWarn("Bind RFCOMM socket: %s\n", + strerror(errno)); } goto failed; } @@ -193,8 +193,8 @@ RfcommListen(uint8_t channel) if (bind(rsock, (struct sockaddr*)&raddr, sizeof(raddr)) < 0) { if (errno != EADDRINUSE) { - GetDi()->LogWarn("Bind RFCOMM socket: %d\n", - errno); + GetDi()->LogWarn("Bind RFCOMM socket: %s\n", + strerror(errno)); goto failed; } continue; @@ -204,20 +204,21 @@ RfcommListen(uint8_t channel) if (!SetLinkModeOptions(rsock, m_bt_master, m_secmode)) { GetDi()->LogWarn("Error setting RFCOMM link mode " - "options: %d\n", errno); + "options: %s\n", strerror(errno)); goto failed; } if (listen(rsock, 1) < 0) { - GetDi()->LogWarn("Set RFCOMM socket to listen: %d\n", errno); + GetDi()->LogWarn("Set RFCOMM socket to listen: %s\n", + strerror(errno)); goto failed; } /* Query the assigned channel of the RFCOMM */ al = sizeof(raddr); if (getsockname(rsock, (struct sockaddr*)&raddr, &al) < 0) { - GetDi()->LogWarn("Query RFCOMM listener local address: %d\n", - errno); + GetDi()->LogWarn("Query RFCOMM listener local address: %s\n", + strerror(errno)); goto failed; } @@ -410,8 +411,8 @@ RfcommSdpLookupChannelComplete(SdpTask *taskp) m_rfcomm_inbound = false; if (taskp->m_params.m_errno) { - GetDi()->LogDebug("SDP lookup failure: %d\n", - taskp->m_params.m_errno); + GetDi()->LogDebug("SDP lookup failure: %s\n", + strerror(taskp->m_params.m_errno)); delete taskp; m_rfcomm_sdp_task = 0; __Disconnect(true, false); @@ -460,20 +461,23 @@ RfcommConnect(uint8_t channel) rsock = socket(PF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM); if (rsock < 0) { - GetDi()->LogWarn("Create RFCOMM socket: %d\n", errno); + GetDi()->LogWarn("Create RFCOMM socket: %s\n", + strerror(errno)); goto failure; } memset(&raddr, 0, sizeof(raddr)); raddr.rc_family = AF_BLUETOOTH; if (hci_devba(hciid, &raddr.rc_bdaddr) < 0) { - GetDi()->LogWarn("Get HCI adapter address: %d\n", errno); + GetDi()->LogWarn("Get HCI adapter address: %s\n", + strerror(errno)); goto failure; } raddr.rc_channel = 0; if (bind(rsock, (struct sockaddr*)&raddr, sizeof(raddr)) < 0) { - GetDi()->LogWarn("Bind RFCOMM socket: %d\n", errno); + GetDi()->LogWarn("Bind RFCOMM socket: %s\n", + strerror(errno)); goto failure; } @@ -487,7 +491,8 @@ RfcommConnect(uint8_t channel) m_rfcomm_secmode = GetService()->m_secmode; if (!SetNonBlock(rsock, true)) { - GetDi()->LogWarn("Set socket nonblocking: %d\n", errno); + GetDi()->LogWarn("Set socket nonblocking: %s\n", + strerror(errno)); goto failure; } @@ -497,7 +502,8 @@ RfcommConnect(uint8_t channel) if (connect(rsock, (struct sockaddr*)&raddr, sizeof(raddr)) < 0) { if ((errno != EINPROGRESS) && (errno != EAGAIN)) { - GetDi()->LogWarn("Connect RFCOMM socket: %d\n", errno); + GetDi()->LogWarn("Connect RFCOMM socket: %s\n", + strerror(errno)); goto failure; } -- cgit v1.2.1