• 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-2016 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, write to the Free Software
17
 * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
18
 *
19
 * As a special exemption, The ProFTPD Project team and other respective
20
 * copyright holders give permission to link this program with OpenSSL, and
21
 * distribute the resulting executable, without including the source code for
22
 * OpenSSL in the source distribution.
23
 */
24

25
/* Resource limits implementation */
26

27
#include "conf.h"
28

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

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

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

46
    return res;
×
47
  }
48

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

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

57
  return 0;
58
}
59

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

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

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

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

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

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

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

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

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

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

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

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

115
#elif defined(RLIMIT_OFILE)
116
  return get_rlimit(RLIMIT_OFILE, current, max);
117

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

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

128
#elif defined(RLIMIT_OFILE)
129
  return set_rlimit(RLIMIT_OFILE, current, max);
130

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

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

141
#elif defined(RLIMIT_DATA)
142
  return get_rlimit(RLIMIT_DATA, current, max);
143

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

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

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

157
#elif defined(RLIMIT_DATA)
158
  return set_rlimit(RLIMIT_DATA, current, max);
159

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

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

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

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

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

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