mirror of
				https://github.com/isar/libmdbx.git
				synced 2025-10-31 15:38:57 +08:00 
			
		
		
		
	mdbx: backport - mdb_env_copyfd2(): Don't abort on SIGPIPE (ITS#8504).
Return EPIPE instead. Never clear mc_error, we could lose a failure in the other thread. Change-Id: Ief08803ed56293309f07be116e69123c10907e77
This commit is contained in:
		
							
								
								
									
										17
									
								
								mdb.c
									
									
									
									
									
								
							
							
						
						
									
										17
									
								
								mdb.c
									
									
									
									
									
								
							| @@ -9072,6 +9072,14 @@ mdb_env_copythr(void *arg) | |||||||
| 	int toggle = 0, wsize, rc = 0; | 	int toggle = 0, wsize, rc = 0; | ||||||
| 	int len; | 	int len; | ||||||
|  |  | ||||||
|  | #ifdef SIGPIPE | ||||||
|  | 	sigset_t set; | ||||||
|  | 	sigemptyset(&set); | ||||||
|  | 	sigaddset(&set, SIGPIPE); | ||||||
|  | 	if ((rc = pthread_sigmask(SIG_BLOCK, &set, NULL)) != 0) | ||||||
|  | 		my->mc_error = rc; | ||||||
|  | #endif | ||||||
|  |  | ||||||
| 	pthread_mutex_lock(&my->mc_mutex); | 	pthread_mutex_lock(&my->mc_mutex); | ||||||
| 	for(;;) { | 	for(;;) { | ||||||
| 		while (!my->mc_new) | 		while (!my->mc_new) | ||||||
| @@ -9086,6 +9094,15 @@ again: | |||||||
| 			len = write(my->mc_fd, ptr, wsize); | 			len = write(my->mc_fd, ptr, wsize); | ||||||
| 			if (len < 0) { | 			if (len < 0) { | ||||||
| 				rc = errno; | 				rc = errno; | ||||||
|  | #ifdef SIGPIPE | ||||||
|  | 				if (rc == EPIPE) { | ||||||
|  | 					/* Collect the pending SIGPIPE, otherwise at least OS X | ||||||
|  | 					 * gives it to the process on thread-exit (ITS#8504). | ||||||
|  | 					 */ | ||||||
|  | 					int tmp; | ||||||
|  | 					sigwait(&set, &tmp); | ||||||
|  | 				} | ||||||
|  | #endif | ||||||
| 				break; | 				break; | ||||||
| 			} else if (len > 0) { | 			} else if (len > 0) { | ||||||
| 				rc = MDB_SUCCESS; | 				rc = MDB_SUCCESS; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user