Alan Jenkins | 29 Sep 16:58

[PATCH] replace strerror() usage with threadsafe "%m" format string

strerror() is not threadsafe.  It uses a buffer to build messages of the form
"Unknown error 387689".

syslog() provides a %m format which is equivalent to strerror(errno).
As a GNU extension, this is also accepted by printf and friends.
At least in the current implementation, it is correctly threadsafe.

Signed-off-by: Alan Jenkins <alan-jenkins <at> tuffmail.co.uk>

diff --git a/udev/lib/libudev-ctrl.c b/udev/lib/libudev-ctrl.c
index 7d37074..268ce2d 100644
--- a/udev/lib/libudev-ctrl.c
+++ b/udev/lib/libudev-ctrl.c
@@ -79,7 +79,7 @@ struct udev_ctrl *udev_ctrl_new_from_socket(struct udev *udev, const char *socke

 	uctrl->sock = socket(AF_LOCAL, SOCK_DGRAM, 0);
 	if (uctrl->sock < 0) {
-		err(udev, "error getting socket: %s\n", strerror(errno));
+		err(udev, "error getting socket: %m\n");
 		udev_ctrl_unref(uctrl);
 		return NULL;
 	}
@@ -101,7 +101,7 @@ int udev_ctrl_enable_receiving(struct udev_ctrl *uctrl)

 	err= bind(uctrl->sock, (struct sockaddr *)&uctrl->saddr, uctrl->addrlen);
 	if (err < 0) {
-		err(uctrl->udev, "bind failed: %s\n", strerror(errno));
+		err(uctrl->udev, "bind failed: %m\n");
 		return err;
 	}
(Continue reading)

Kay Sievers | 29 Sep 17:08
Gravatar

Re: [PATCH] replace strerror() usage with threadsafe "%m" format string

On Mon, 2008-09-29 at 16:01 +0100, Alan Jenkins wrote:
> strerror() is not threadsafe.  It uses a buffer to build messages of the form
> "Unknown error 387689".
> 
> syslog() provides a %m format which is equivalent to strerror(errno).
> As a GNU extension, this is also accepted by printf and friends.
> At least in the current implementation, it is correctly threadsafe.

Great! Applied. Thanks,
Kay

--
To unsubscribe from this list: send the line "unsubscribe linux-hotplug" in
the body of a message to majordomo <at> vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Gmane