Ansel 0.0
A darktable fork - bloat + design vision
Loading...
Searching...
No Matches
resource_limits.c
Go to the documentation of this file.
1/*
2 This file is part of darktable,
3 Copyright (C) 2016-2017 Peter Budai.
4 Copyright (C) 2016 Roman Lebedev.
5 Copyright (C) 2019 Heiko Bauke.
6 Copyright (C) 2020 Pascal Obry.
7 Copyright (C) 2022 Martin Baƙinka.
8
9 darktable is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13
14 darktable is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with darktable. If not, see <http://www.gnu.org/licenses/>.
21*/
22
23#ifdef HAVE_CONFIG_H
24#include "config.h"
25#endif
26
28
29#ifndef _WIN32
30#include <assert.h> // for assert
31#include <errno.h> // for errno
32#include <stdint.h> // for uintmax_t
33#include <stdio.h> // for fprintf, stderr
34#include <string.h> // for strerror
35#include <inttypes.h>
36#include <sys/resource.h> // for rlimit, RLIMIT_STACK, getrlimit, setrlimit
37
38static void dt_set_rlimits_stack()
39{
40 // make sure that stack/frame limits are good (musl)
41
42 int ret;
43
44 struct rlimit rlim = { 0 };
45
46 ret = getrlimit(RLIMIT_STACK, &rlim);
47
48 if(ret != 0)
49 {
50 const int errsv = errno;
51 fprintf(stderr, "[dt_set_rlimits_stack] error: getrlimit(RLIMIT_STACK) returned %i: %i (%s)\n", ret, errsv,
52 strerror(errsv));
53 }
54
55 assert((ret == 0 && (WANTED_STACK_SIZE <= rlim.rlim_max || RLIM_INFINITY == rlim.rlim_max)) || (ret != 0));
56
57 if(ret != 0 || (rlim.rlim_cur < WANTED_STACK_SIZE && rlim.rlim_cur != RLIM_INFINITY) /*|| 1*/)
58 {
59 // looks like we need to bump/set it...
60
61 fprintf(stderr, "[dt_set_rlimits_stack] info: bumping RLIMIT_STACK rlim_cur from %"PRIuMAX" to %"PRIuMAX"\n",
62 (uintmax_t)rlim.rlim_cur, (uintmax_t)WANTED_STACK_SIZE);
63
64 rlim.rlim_cur = WANTED_STACK_SIZE;
65
66 ret = setrlimit(RLIMIT_STACK, &rlim);
67 if(ret != 0)
68 {
69 int errsv = errno;
70 fprintf(stderr, "[dt_set_rlimits_stack] error: setrlimit(RLIMIT_STACK) returned %i: %i (%s)\n", ret, errsv,
71 strerror(errsv));
72 }
73 }
74}
75#endif // !_WIN32
76
85{
86#ifndef _WIN32
87 dt_set_rlimits_stack();
88#endif
89}
90
91
92// clang-format off
93// modelines: These editor modelines have been set for all relevant files by tools/update_modelines.py
94// vim: shiftwidth=2 expandtab tabstop=2 cindent
95// kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;
96// clang-format on
97
#define WANTED_STACK_SIZE
void dt_set_rlimits()
Raise the process limits Ansel needs, where the system lets a running process do it.