strerror() is not thread-safe, nor in the glibc implementation,
nor in the POSIX specification. In my experience, it will infrequently
crash when another thread uses locale data in any way, including
string formatting and such...

Since the Huawei driver uses thread, we might as well avoid strerror().
---
 drivers/isimodem/sim.c |    3 ++-
 plugins/hfp.c          |    4 ++--
 plugins/isigen.c       |   13 ++++++++-----
 plugins/n900.c         |   14 +++++++-------
 plugins/nokia-gpio.c   |   29 +++++++++++++++++------------
 5 files changed, 36 insertions(+), 27 deletions(-)

diff --git a/drivers/isimodem/sim.c b/drivers/isimodem/sim.c
index d03a07e..6379af8 100644
--- a/drivers/isimodem/sim.c
+++ b/drivers/isimodem/sim.c
@@ -428,7 +428,8 @@ static void sim_reachable_cb(GIsiClient *client, gboolean 
alive,
        struct ofono_sim *sim = opaque;
 
        if (!alive) {
-               DBG("SIM client: %s", strerror(-g_isi_client_error(client)));
+               errno = -g_isi_client_error(client);
+               DBG("SIM client: %m");
                ofono_sim_remove(sim);
                return;
        }
diff --git a/plugins/hfp.c b/plugins/hfp.c
index 0a19dac..2169d40 100644
--- a/plugins/hfp.c
+++ b/plugins/hfp.c
@@ -324,8 +324,8 @@ static int service_level_connection(struct ofono_modem 
*modem, int fd)
 
        io = g_io_channel_unix_new(fd);
        if (!io) {
-               ofono_error("Service level connection failed: %s (%d)",
-                       strerror(errno), errno);
+               ofono_error("Service level connection failed: %m (%d)",
+                       errno);
                return -EIO;
        }
 
diff --git a/plugins/isigen.c b/plugins/isigen.c
index 3384e9f..5eb2a96 100644
--- a/plugins/isigen.c
+++ b/plugins/isigen.c
@@ -217,7 +217,8 @@ static void reachable_cb(GIsiClient *client, gboolean 
alive, uint16_t object,
        };
 
        if (!alive) {
-               DBG("MTC client: %s", strerror(-g_isi_client_error(client)));
+               errno = -g_isi_client_error(client);
+               DBG("MTC client: %m");
 
                if (isi->linkstate == PN_LINK_UP)
                        g_isi_send(client, msg, sizeof(msg),
@@ -272,25 +273,27 @@ static int isigen_probe(struct ofono_modem *modem)
 
        idx = g_isi_modem_by_name(ifname);
        if (idx == NULL) {
-               DBG("Interface=%s: %s", ifname, strerror(errno));
+               DBG("Interface=%s: %m", ifname);
                return -errno;
        }
 
        if (g_pn_netlink_by_modem(idx)) {
-               DBG("%s: %s", ifname, strerror(EBUSY));
+               errno = EBUSY;
+               DBG("%s: %m", ifname);
                return -EBUSY;
        }
 
        link = g_pn_netlink_start(idx, phonet_status_cb, modem);
        if (!link) {
-               DBG("%s: %s", ifname, strerror(errno));
+               DBG("%s: %m", ifname);
                return -errno;
        }
 
        if (address) {
                int error = g_pn_netlink_set_address(idx, address);
                if (error && error != -EEXIST) {
-                       DBG("g_pn_netlink_set_address: %s", strerror(-error));
+                       errno = -error;
+                       DBG("g_pn_netlink_set_address: %m");
                        g_pn_netlink_stop(link);
                        return -errno;
                }
diff --git a/plugins/n900.c b/plugins/n900.c
index a9e6b59..4e27d20 100644
--- a/plugins/n900.c
+++ b/plugins/n900.c
@@ -218,8 +218,7 @@ static gboolean mtc_startup_synq_cb(GIsiClient *client,
        const unsigned char *msg = data;
 
        if (!msg) {
-               DBG("%s: %s", "MTC_STARTUP_SYNQ",
-                       strerror(-g_isi_client_error(client)));
+               DBG("%s: %m", "MTC_STARTUP_SYNQ");
                return TRUE;
        }
 
@@ -280,7 +279,8 @@ static void mtc_reachable_cb(GIsiClient *client, gboolean 
alive,
        struct isi_data *isi = opaque;
 
        if (!alive) {
-               DBG("MTC client: %s", strerror(-g_isi_client_error(client)));
+               errno = -g_isi_client_error(client);
+               DBG("MTC client: %m");
                /* enable is terminated eventually by timeout */
                return;
        }
@@ -332,8 +332,8 @@ static gboolean mtc_power_off_cb(GIsiClient *client,
        const unsigned char *msg = data;
 
        if (!msg) {
-               DBG("%s: %s", "MTC_POWER_OFF_RESP",
-                       strerror(-g_isi_client_error(client)));
+               errno = -g_isi_client_error(client);
+               DBG("%s: %m", "MTC_POWER_OFF_RESP");
 
                if (isi->power_state == POWER_STATE_OFF_STARTED)
                        mtc_power_off(isi);
@@ -399,12 +399,12 @@ static int n900_probe(struct ofono_modem *modem)
 
        idx = g_isi_modem_by_name(ifname);
        if (!idx) {
-               DBG("Interface=%s: %s", ifname, strerror(errno));
+               DBG("Interface=%s: %m", ifname);
                return -errno;
        }
 
        if (gpio_probe(idx, address, n900_power_cb, modem) != 0) {
-               DBG("gpio for %s: %s", ifname, strerror(errno));
+               DBG("gpio for %s: %m", ifname);
                return -errno;
        }
 
diff --git a/plugins/nokia-gpio.c b/plugins/nokia-gpio.c
index f3b9460..1a08ff9 100644
--- a/plugins/nokia-gpio.c
+++ b/plugins/nokia-gpio.c
@@ -156,7 +156,7 @@ static int file_write(char const *filename, char const 
*output)
 
        f = fopen(filename, "r+");
        if (!f) {
-               DBG("%s: %s (%d)", filename, strerror(errno), errno);
+               DBG("%s: %m (%d)", filename, errno);
                return -1;
        }
 
@@ -647,14 +647,14 @@ static int gpio_probe_links(void)
        if (!dir_exists(cmtdir)) {
 
                if (mkdir(cmtdir, 0755) == -1) {
-                       DBG("%s: %s", cmtdir, strerror(errno));
+                       DBG("%s: %m", cmtdir);
                        return -(errno = ENODEV);
                }
        }
 
        gpio = opendir(gpiodir);
        if (gpio == NULL) {
-               DBG("%s: %s", "gpiodir", strerror(errno));
+               DBG("%s: %m", "gpiodir");
                return -(errno = ENODEV);
        }
 
@@ -670,14 +670,14 @@ static int gpio_probe_links(void)
 
                nf = fopen(nn, "rb");
                if (nf == NULL) {
-                       DBG("%s: %s", nn, strerror(errno));
+                       DBG("%s: %m", nn);
                        continue;
                }
 
                len = fread(name, sizeof name, 1, nf);
 
                if (ferror(nf)) {
-                       DBG("read from %s: %s", nn, strerror(errno));
+                       DBG("read from %s: %m", nn);
                        fclose(nf);
                        continue;
                }
@@ -696,10 +696,10 @@ static int gpio_probe_links(void)
                snprintf(to, sizeof to, "%s/%s", cmtdir, name);
 
                if (symlink(from, to) == -1)
-                       DBG("%s: %s", to, strerror(errno));
+                       DBG("%s: %m", to);
        }
 
-       DBG("%s: %s", "/sys/class/gpio", strerror(errno));
+       DBG("%s: %m", "/sys/class/gpio");
 
        return -(errno = ENODEV);
 }
@@ -715,13 +715,15 @@ int gpio_probe(GIsiModem *idx, unsigned addr, 
gpio_finished_cb_t cb, void *data)
        }
 
        if (self.callback) {
-               DBG("gpio: %s", strerror(EBUSY));
-               return -(errno = EBUSY);
+               errno = EBUSY;
+               DBG("gpio: %m");
+               return -EBUSY;
        }
 
        if (g_pn_netlink_by_modem(idx)) {
-               DBG("Phonet link %p: %s", idx, strerror(EBUSY));
-               return -(errno = EBUSY);
+               errno = EBUSY;
+               DBG("Phonet link %p: %m", idx);
+               return -EBUSY;
        }
 
        self.target = PHONET_LINK_NONE;
@@ -765,7 +767,10 @@ int gpio_probe(GIsiModem *idx, unsigned addr, 
gpio_finished_cb_t cb, void *data)
        if (addr) {
                error = g_pn_netlink_set_address(idx, addr);
                if (error && error != -EEXIST)
-                       DBG("g_pn_netlink_set_address: %s", strerror(-error));
+               {
+                       errno = -error;
+                       DBG("g_pn_netlink_set_address: %m");
+               }
        }
 
        return 0;
-- 
1.7.1

_______________________________________________
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono

Reply via email to