Skip to content

Commit

Permalink
Fixes to zfs_strerror(), use strerror_r() if available.
Browse files Browse the repository at this point in the history
Signed-off-by: Richard Kojedzinszky <[email protected]>
  • Loading branch information
rkojedzinszky committed Jan 3, 2025
1 parent cfb5106 commit 62ade6f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion config/user.m4
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ AC_DEFUN([ZFS_AC_CONFIG_USER], [
ZFS_AC_CONFIG_USER_MAKEDEV_IN_MKDEV
ZFS_AC_CONFIG_USER_ZFSEXEC
AC_CHECK_FUNCS([execvpe issetugid mlockall strlcat strlcpy gettid])
AC_CHECK_FUNCS([execvpe issetugid mlockall strlcat strlcpy strerror_r gettid])
AC_SUBST(RM)
])
16 changes: 10 additions & 6 deletions include/libzutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -276,13 +276,17 @@ _LIBZUTIL_H void update_vdev_config_dev_sysfs_path(nvlist_t *nv,
* Thread-safe strerror() for use in ZFS libraries
*/
static inline char *zfs_strerror(int errnum) {
static __thread char errbuf[2048];
static __thread pthread_mutex_t zfs_strerror_lock =
PTHREAD_MUTEX_INITIALIZER;
static __thread char errbuf[512];

pthread_mutex_lock(&zfs_strerror_lock);
strlcpy(errbuf, strerror(errnum), sizeof(errbuf));
pthread_mutex_unlock(&zfs_strerror_lock);
#if defined(HAVE_STRERROR_R)
(void) strerror_r(errnum, errbuf, sizeof(errbuf));

Check failure on line 282 in include/libzutil.h

View workflow job for this annotation

GitHub Actions / checkstyle

missing space between keyword and paren
#else
static pthread_mutex_t zfs_strerror_lock = PTHREAD_MUTEX_INITIALIZER;

(void) pthread_mutex_lock(&zfs_strerror_lock);
(void) strlcpy(errbuf, strerror(errnum), sizeof(errbuf));

Check failure on line 287 in include/libzutil.h

View workflow job for this annotation

GitHub Actions / checkstyle

missing space between keyword and paren
(void) pthread_mutex_unlock(&zfs_strerror_lock);
#endif

return errbuf;

Check failure on line 291 in include/libzutil.h

View workflow job for this annotation

GitHub Actions / checkstyle

unparenthesized return expression
}
Expand Down

0 comments on commit 62ade6f

Please sign in to comment.