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

proftpd / proftpd / 26127302613

19 May 2026 09:51PM UTC coverage: 93.024% (+0.4%) from 92.635%
26127302613

push

github

51329 of 55178 relevant lines covered (93.02%)

215.14 hits per line

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

87.5
/src/pidfile.c
1
/*
2
 * ProFTPD - FTP server daemon
3
 * Copyright (c) 2007-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
/* Pidfile management */
25

26
#include "conf.h"
27
#include "privs.h"
28

29
static const char *pidfile_path = PR_PID_FILE_PATH;
30

31
const char *pr_pidfile_get(void) {
32
  return pidfile_path;
1✔
33
}
1✔
34

35
int pr_pidfile_set(const char *path) {
36
  if (path == NULL) {
4✔
37
    errno = EINVAL;
4✔
38
    return -1;
1✔
39
  }
1✔
40

41
  /* Do not allow relative paths. */
42
  if (*path != '/') {
43
    errno = EINVAL;
3✔
44
    return -1;
1✔
45
  }
1✔
46

47
  pidfile_path = pstrdup(permanent_pool, path);
48
  return 0;
2✔
49
}
2✔
50

51
int pr_pidfile_write(void) {
52
  int fd, res, xerrno;
1✔
53
  mode_t mode = 0644;
1✔
54

1✔
55
  PRIVS_ROOT
56
  fd = open(pidfile_path, O_WRONLY|O_CREAT|O_TRUNC, mode);
1✔
57
  xerrno = errno;
1✔
58
  PRIVS_RELINQUISH
1✔
59

1✔
60
  if (fd < 0) {
61
    errno = xerrno;
1✔
62
    return -1;
×
63
  }
×
64

65
  /* Ensure that our permissions are as desired, regardless of umask. */
66
  PRIVS_ROOT
67
  res = fchmod(fd, mode);
1✔
68
  xerrno = errno;
1✔
69
  PRIVS_RELINQUISH
1✔
70

1✔
71
  if (res < 0) {
72
    fprintf(stderr, "error setting permissions for PidFile '%s': %s\n",
1✔
73
      pidfile_path, strerror(xerrno));
×
74
  }
75

76
  dprintf(fd, "%lu\n", (unsigned long) getpid());
77
  if (close(fd) < 0) {
1✔
78
    fprintf(stderr, "error writing PidFile '%s': %s\n", pidfile_path,
1✔
79
      strerror(errno));
×
80
  }
81

82
  return 0;
83
}
84

85
int pr_pidfile_remove(void) {
86
  return unlink(pidfile_path);
3✔
87
}
3✔
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