mirror of
https://github.com/labwc/labwc.git
synced 2026-03-15 05:33:53 -04:00
Merge pull request #454 from Joshua-Ashton/bump-fd-limit
main: Increase FD limit
This commit is contained in:
commit
06cc21664f
5 changed files with 54 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',
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <wlr/util/log.h>
|
#include <wlr/util/log.h>
|
||||||
#include "common/spawn.h"
|
#include "common/spawn.h"
|
||||||
|
#include "common/fd_util.h"
|
||||||
|
|
||||||
void
|
void
|
||||||
spawn_async_no_shell(char const *command)
|
spawn_async_no_shell(char const *command)
|
||||||
|
|
@ -39,6 +40,8 @@ spawn_async_no_shell(char const *command)
|
||||||
wlr_log(WLR_ERROR, "unable to fork()");
|
wlr_log(WLR_ERROR, "unable to fork()");
|
||||||
goto out;
|
goto out;
|
||||||
case 0:
|
case 0:
|
||||||
|
restore_nofile_limit();
|
||||||
|
|
||||||
setsid();
|
setsid();
|
||||||
sigset_t set;
|
sigset_t set;
|
||||||
sigemptyset(&set);
|
sigemptyset(&set);
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@
|
||||||
#include "theme.h"
|
#include "theme.h"
|
||||||
#include "xbm/xbm.h"
|
#include "xbm/xbm.h"
|
||||||
#include "menu/menu.h"
|
#include "menu/menu.h"
|
||||||
|
#include "common/fd_util.h"
|
||||||
|
|
||||||
struct rcxml rc = { 0 };
|
struct rcxml rc = { 0 };
|
||||||
|
|
||||||
|
|
@ -85,6 +86,8 @@ main(int argc, char *argv[])
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
increase_nofile_limit();
|
||||||
|
|
||||||
struct server server = { 0 };
|
struct server server = { 0 };
|
||||||
server_init(&server);
|
server_init(&server);
|
||||||
server_start(&server);
|
server_start(&server);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue