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#include <assert.h> // for assert
29#include <errno.h> // for errno
30#include <stdint.h> // for uintmax_t
31#include <stdio.h> // for fprintf, stderr
32#include <string.h> // for strerror
33#include <inttypes.h>
34
35#ifdef _WIN32
36#include "win/rlimit.h"
37#else
38#include <sys/resource.h> // for rlimit, RLIMIT_STACK, getrlimit, setrlimit
39#endif //_WIN32
40
42{
43 // make sure that stack/frame limits are good (musl)
44
45 int ret;
46
47 struct rlimit rlim = { 0 };
48
49 ret = getrlimit(RLIMIT_STACK, &rlim);
50
51 if(ret != 0)
52 {
53 const int errsv = errno;
54 fprintf(stderr, "[dt_set_rlimits_stack] error: getrlimit(RLIMIT_STACK) returned %i: %i (%s)\n", ret, errsv,
55 strerror(errsv));
56 }
57
58 assert((ret == 0 && (WANTED_STACK_SIZE <= rlim.rlim_max || RLIM_INFINITY == rlim.rlim_max)) || (ret != 0));
59
60 if(ret != 0 || (rlim.rlim_cur < WANTED_STACK_SIZE && rlim.rlim_cur != RLIM_INFINITY) /*|| 1*/)
61 {
62 // looks like we need to bump/set it...
63
64 fprintf(stderr, "[dt_set_rlimits_stack] info: bumping RLIMIT_STACK rlim_cur from %"PRIuMAX" to %"PRIuMAX"\n",
65 (uintmax_t)rlim.rlim_cur, (uintmax_t)WANTED_STACK_SIZE);
66
68
69 ret = setrlimit(RLIMIT_STACK, &rlim);
70 if(ret != 0)
71 {
72 int errsv = errno;
73 fprintf(stderr, "[dt_set_rlimits_stack] error: setrlimit(RLIMIT_STACK) returned %i: %i (%s)\n", ret, errsv,
74 strerror(errsv));
75 }
76 }
77}
78
83
84
85// clang-format off
86// modelines: These editor modelines have been set for all relevant files by tools/update_modelines.py
87// vim: shiftwidth=2 expandtab tabstop=2 cindent
88// kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;
89// clang-format on
90
#define WANTED_STACK_SIZE
static void dt_set_rlimits_stack()
void dt_set_rlimits()
int getrlimit(int resource, struct rlimit *rlp)
Definition rlimit.c:79
int setrlimit(int resource, const struct rlimit *rlp)
Definition rlimit.c:109
#define RLIM_INFINITY
Definition rlimit.h:34
#define RLIMIT_STACK
Definition rlimit.h:28
__int64 rlim_cur
Definition rlimit.h:44
__int64 rlim_max
Definition rlimit.h:45