mirror of
https://passt.top/passt
synced 2025-06-17 12:45:34 +02:00
passt, util: Move opening of PID file to its own function
We won't call it from main() any longer: move it. Signed-off-by: Stefano Brivio <sbrivio@redhat.com> Reviewed-by: Richard W.M. Jones <rjones@redhat.com>
This commit is contained in:
parent
57d8aa8ffe
commit
ba23b05545
3 changed files with 25 additions and 9 deletions
22
util.c
22
util.c
|
@ -402,6 +402,28 @@ void pidfile_write(int fd, pid_t pid)
|
|||
close(fd);
|
||||
}
|
||||
|
||||
/**
|
||||
* pidfile_open() - Open PID file if needed
|
||||
* @path: Path for PID file, empty string if no PID file is requested
|
||||
*
|
||||
* Return: descriptor for PID file, -1 if path is NULL, won't return on failure
|
||||
*/
|
||||
int pidfile_open(const char *path)
|
||||
{
|
||||
int fd;
|
||||
|
||||
if (!*path)
|
||||
return -1;
|
||||
|
||||
if ((fd = open(path, O_CREAT | O_TRUNC | O_WRONLY | O_CLOEXEC,
|
||||
S_IRUSR | S_IWUSR)) < 0) {
|
||||
perror("PID file open");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
return fd;
|
||||
}
|
||||
|
||||
/**
|
||||
* __daemon() - daemon()-like function writing PID file before parent exits
|
||||
* @pidfile_fd: Open PID file descriptor
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue