mirror of
				https://github.com/labwc/labwc.git
				synced 2025-11-03 09:01:51 -05:00 
			
		
		
		
	common: Add helpers for raising/lowering FD limit
Signed-off-by: Joshua Ashton <joshua@froggi.es>
This commit is contained in:
		
							parent
							
								
									fd7ec0ab95
								
							
						
					
					
						commit
						6c2bbb42ea
					
				
					 3 changed files with 48 additions and 0 deletions
				
			
		
							
								
								
									
										8
									
								
								include/common/fd_util.h
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								include/common/fd_util.h
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,8 @@
 | 
				
			||||||
 | 
					/* SPDX-License-Identifier: GPL-2.0-only */
 | 
				
			||||||
 | 
					#ifndef __LABWC_FD_UTIL_H
 | 
				
			||||||
 | 
					#define __LABWC_FD_UTIL_H
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void increase_nofile_limit(void);
 | 
				
			||||||
 | 
					void restore_nofile_limit(void);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#endif /* __LABWC_FD_UTIL_H */
 | 
				
			||||||
							
								
								
									
										39
									
								
								src/common/fd_util.c
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										39
									
								
								src/common/fd_util.c
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,39 @@
 | 
				
			||||||
 | 
					// SPDX-License-Identifier: GPL-2.0-only
 | 
				
			||||||
 | 
					#define _POSIX_C_SOURCE 200809L
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <sys/resource.h>
 | 
				
			||||||
 | 
					#include <wlr/util/log.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "common/fd_util.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static struct rlimit original_nofile_rlimit = {0};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void
 | 
				
			||||||
 | 
					increase_nofile_limit(void)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						if (getrlimit(RLIMIT_NOFILE, &original_nofile_rlimit) != 0) {
 | 
				
			||||||
 | 
							wlr_log_errno(WLR_ERROR, "Failed to bump max open files limit: getrlimit(NOFILE) failed");
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						struct rlimit new_rlimit = original_nofile_rlimit;
 | 
				
			||||||
 | 
						new_rlimit.rlim_cur = new_rlimit.rlim_max;
 | 
				
			||||||
 | 
						if (setrlimit(RLIMIT_NOFILE, &new_rlimit) != 0) {
 | 
				
			||||||
 | 
							wlr_log_errno(WLR_ERROR, "Failed to bump max open files limit: setrlimit(NOFILE) failed");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							wlr_log(WLR_INFO, "Running with %d max open files",
 | 
				
			||||||
 | 
					            (int)original_nofile_rlimit.rlim_cur);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void
 | 
				
			||||||
 | 
					restore_nofile_limit(void)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						if (original_nofile_rlimit.rlim_cur == 0) {
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (setrlimit(RLIMIT_NOFILE, &original_nofile_rlimit) != 0) {
 | 
				
			||||||
 | 
							wlr_log_errno(WLR_ERROR, "Failed to restore max open files limit: setrlimit(NOFILE) failed");
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -1,6 +1,7 @@
 | 
				
			||||||
labwc_sources += files(
 | 
					labwc_sources += files(
 | 
				
			||||||
  'buf.c',
 | 
					  'buf.c',
 | 
				
			||||||
  'dir.c',
 | 
					  'dir.c',
 | 
				
			||||||
 | 
					  'fd_util.c',
 | 
				
			||||||
  'font.c',
 | 
					  'font.c',
 | 
				
			||||||
  'grab-file.c',
 | 
					  'grab-file.c',
 | 
				
			||||||
  'nodename.c',
 | 
					  'nodename.c',
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue