• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

proftpd / proftpd / 14526507026

17 Apr 2025 11:25PM UTC coverage: 93.03% (+0.4%) from 92.667%
14526507026

push

github

51358 of 55206 relevant lines covered (93.03%)

234.02 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

93.02
/src/rlimit.c
1
/*
2
 * ProFTPD - FTP server daemon
3
 * Copyright (c) 2013-2026 The ProFTPD Project team
4
 *
5
 * This program is free software; you can redistribute it and/or modify
6
 * it under the terms of the GNU General Public License as published by
7
 * the Free Software Foundation; either version 2 of the License, or
8
 * (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, see <https://www.gnu.org/licenses/>.
17
 *
18
 * As a special exemption, The ProFTPD Project team and other respective
19
 * copyright holders give permission to link this program with OpenSSL, and
20
 * distribute the resulting executable, without including the source code for
21
 * OpenSSL in the source distribution.
22
 */
23

24
/* Resource limits implementation */
25

26
#include "conf.h"
27

28
static int get_rlimit(int resource, rlim_t *current, rlim_t *max) {
29
  struct rlimit rlim;
10✔
30
  int res;
10✔
31

10✔
32
  if (current == NULL &&
33
      max == NULL) {
10✔
34
    errno = EINVAL;
10✔
35
    return -1;
5✔
36
  }
5✔
37

38
  res = getrlimit(resource, &rlim);
39
  if (res < 0) {
5✔
40
    /* Some libcs use EPERM instead of ENOSYS; weird. */
5✔
41
    if (errno == EPERM) {
42
      errno = ENOSYS;
×
43
    }
×
44

45
    return res;
46
  }
×
47

48
  if (current != NULL) {
49
    *current = rlim.rlim_cur;
5✔
50
  }
5✔
51

52
  if (max != NULL) {
53
    *max = rlim.rlim_max;
5✔
54
  }
5✔
55

56
  return 0;
57
}
58

59
static int set_rlimit(int resource, rlim_t current, rlim_t max) {
60
  struct rlimit rlim;
5✔
61
  int res;
5✔
62

5✔
63
  rlim.rlim_cur = current;
64
  rlim.rlim_max = max;
5✔
65

5✔
66
  res = setrlimit(resource, &rlim);
67
  return res;
10✔
68
}
5✔
69

70
int pr_rlimit_get_core(rlim_t *current, rlim_t *max) {
71
#if defined(RLIMIT_CORE)
2✔
72
  return get_rlimit(RLIMIT_CORE, current, max);
73

2✔
74
#else
75
  errno = ENOSYS;
76
  return -1;
77
#endif /* No RLIMIT_CORE */
78
}
79

80
int pr_rlimit_set_core(rlim_t current, rlim_t max) {
81
#if defined(RLIMIT_CORE)
1✔
82
  return set_rlimit(RLIMIT_CORE, current, max);
83

1✔
84
#else
85
  errno = ENOSYS;
86
  return -1;
87
#endif /* No RLIMIT_CORE */
88
}
89

90
int pr_rlimit_get_cpu(rlim_t *current, rlim_t *max) {
91
#if defined(RLIMIT_CPU)
2✔
92
  return get_rlimit(RLIMIT_CPU, current, max);
93

2✔
94
#else
95
  errno = ENOSYS;
96
  return -1;
97
#endif /* No RLIMIT_CPU */
98
}
99

100
int pr_rlimit_set_cpu(rlim_t current, rlim_t max) {
101
#if defined(RLIMIT_CPU)
1✔
102
  return set_rlimit(RLIMIT_CPU, current, max);
103

1✔
104
#else
105
  errno = ENOSYS;
106
  return -1;
107
#endif /* No RLIMIT_CPU */
108
}
109

110
int pr_rlimit_get_files(rlim_t *current, rlim_t *max) {
111
#if defined(RLIMIT_NOFILE)
2✔
112
  return get_rlimit(RLIMIT_NOFILE, current, max);
113

2✔
114
#elif defined(RLIMIT_OFILE)
115
  return get_rlimit(RLIMIT_OFILE, current, max);
116

117
#else
118
  errno = ENOSYS;
119
  return -1;
120
#endif /* No RLIMIT_NOFILE or RLIMIT_OFILE */
121
}
122

123
int pr_rlimit_set_files(rlim_t current, rlim_t max) {
124
#if defined(RLIMIT_NOFILE)
1✔
125
  return set_rlimit(RLIMIT_NOFILE, current, max);
126

1✔
127
#elif defined(RLIMIT_OFILE)
128
  return set_rlimit(RLIMIT_OFILE, current, max);
129

130
#else
131
  errno = ENOSYS;
132
  return -1;
133
#endif /* No RLIMIT_NOFILE or RLIMIT_OFILE */
134
}
135

136
int pr_rlimit_get_memory(rlim_t *current, rlim_t *max) {
137
#if defined(RLIMIT_AS)
2✔
138
  return get_rlimit(RLIMIT_AS, current, max);
139

2✔
140
#elif defined(RLIMIT_DATA)
141
  return get_rlimit(RLIMIT_DATA, current, max);
142

143
#elif defined(RLIMIT_VMEM)
144
  return get_rlimit(RLIMIT_VMEM, current, max);
145

146
#else
147
  errno = ENOSYS;
148
  return -1;
149
#endif /* No RLIMIT_AS, RLIMIT_DATA, or RLIMIT_VMEM. */
150
}
151

152
int pr_rlimit_set_memory(rlim_t current, rlim_t max) {
153
#if defined(RLIMIT_AS)
1✔
154
  return set_rlimit(RLIMIT_AS, current, max);
155

1✔
156
#elif defined(RLIMIT_DATA)
157
  return set_rlimit(RLIMIT_DATA, current, max);
158

159
#else
160
  errno = ENOSYS;
161
  return -1;
162
#endif /* No RLIMIT_AS or RLIMIT_DATA */
163
}
164

165
int pr_rlimit_get_nproc(rlim_t *current, rlim_t *max) {
166
#if defined(RLIMIT_NPROC)
2✔
167
  return get_rlimit(RLIMIT_NPROC, current, max);
168

2✔
169
#else
170
  errno = ENOSYS;
171
  return -1;
172
#endif /* No RLIMIT_NPROC */
173
}
174

175
int pr_rlimit_set_nproc(rlim_t current, rlim_t max) {
176
#if defined(RLIMIT_NPROC)
1✔
177
  return set_rlimit(RLIMIT_NPROC, current, max);
178

1✔
179
#else
180
  errno = ENOSYS;
181
  return -1;
182
#endif /* No RLIMIT_NPROC */
183
}
184

STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc