mirror of
				https://git.proxmox.com/git/mirror_zfs.git
				synced 2025-10-26 18:05:04 +03:00 
			
		
		
		
	fix: make zfs_strerror really thread-safe and portable
#15793 wanted to make zfs_strerror threadsafe, unfortunately, it turned out that strerror_l() usage was wrong, and also, some libc implementations dont have strerror_l(). zfs_strerror() now simply calls original strerror() and copies the result to a thread-local buffer, then returns that. Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Reviewed-by: Alexander Motin <mav@FreeBSD.org> Signed-off-by: Richard Kojedzinszky <richard@kojedz.in> Closes #15793 Closes #16640 Closes #16923
This commit is contained in:
		
							parent
							
								
									939e0237c5
								
							
						
					
					
						commit
						dc0324bfa9
					
				| @ -33,7 +33,7 @@ AC_DEFUN([ZFS_AC_CONFIG_USER], [ | |||||||
| 	ZFS_AC_CONFIG_USER_MAKEDEV_IN_MKDEV | 	ZFS_AC_CONFIG_USER_MAKEDEV_IN_MKDEV | ||||||
| 	ZFS_AC_CONFIG_USER_ZFSEXEC | 	ZFS_AC_CONFIG_USER_ZFSEXEC | ||||||
| 
 | 
 | ||||||
| 	AC_CHECK_FUNCS([execvpe issetugid mlockall strerror_l strlcat strlcpy gettid]) | 	AC_CHECK_FUNCS([execvpe issetugid mlockall strlcat strlcpy gettid]) | ||||||
| 
 | 
 | ||||||
| 	AC_SUBST(RM) | 	AC_SUBST(RM) | ||||||
| ]) | ]) | ||||||
|  | |||||||
| @ -27,7 +27,7 @@ | |||||||
| #define	_LIBZUTIL_H extern __attribute__((visibility("default"))) | #define	_LIBZUTIL_H extern __attribute__((visibility("default"))) | ||||||
| 
 | 
 | ||||||
| #include <string.h> | #include <string.h> | ||||||
| #include <locale.h> | #include <pthread.h> | ||||||
| #include <sys/nvpair.h> | #include <sys/nvpair.h> | ||||||
| #include <sys/fs/zfs.h> | #include <sys/fs/zfs.h> | ||||||
| 
 | 
 | ||||||
| @ -276,11 +276,14 @@ _LIBZUTIL_H void update_vdev_config_dev_sysfs_path(nvlist_t *nv, | |||||||
|  * Thread-safe strerror() for use in ZFS libraries |  * Thread-safe strerror() for use in ZFS libraries | ||||||
|  */ |  */ | ||||||
| static inline char *zfs_strerror(int errnum) { | static inline char *zfs_strerror(int errnum) { | ||||||
| #ifdef HAVE_STRERROR_L | 	static __thread char errbuf[512]; | ||||||
| 	return (strerror_l(errnum, uselocale(0))); | 	static pthread_mutex_t zfs_strerror_lock = PTHREAD_MUTEX_INITIALIZER; | ||||||
| #else | 
 | ||||||
| 	return (strerror(errnum)); | 	(void) pthread_mutex_lock(&zfs_strerror_lock); | ||||||
| #endif | 	(void) strlcpy(errbuf, strerror(errnum), sizeof (errbuf)); | ||||||
|  | 	(void) pthread_mutex_unlock(&zfs_strerror_lock); | ||||||
|  | 
 | ||||||
|  | 	return (errbuf); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| #ifdef	__cplusplus | #ifdef	__cplusplus | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 Richard Kojedzinszky
						Richard Kojedzinszky