pidfile_close prevents pidfile_remove from working
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
libbsd (Ubuntu) |
New
|
Undecided
|
Unassigned |
Bug Description
The whole pidfile_xxx suite, besides being unnecessarily complicated compared to 1 function in NetBSD, does not do what it says on the tin.
Complications. 4 functions instead of one. pidfile_open requires pidptr, but doesn't use it. The other functions require an argument that the documentation says isn't needed, but is.
Error. Most important, pidfile_close modifies its argument such that pidfile_remove can't use it: both the file descriptor and the name are destroyed.
The following program and associated output illustrates the problem.
#include <err.h>
#include <stdio.h>
#include <stdlib.h>
#include <bsd/libutil.h>
void
show_pfh( const char func[], struct pidfh * pfh ) {
printf( "%s: fh = %d, name = %s\n", func, pfh->pf_fd, pfh->pf_path );
}
int
main(int argc, char *argv[])
{
pid_t pid;
struct pidfh * pfh = pidfile_
if( !pfh ) {
err(
}
show_pfh("open", pfh);
if( -1 == pidfile_write(pfh) ) {
err(
}
show_pfh("write", pfh);
if( -1 == pidfile_close(pfh) ) {
err(
}
show_pfh("close", pfh);
if( -1 == pidfile_remove(pfh) ) {
err(
}
show_
return 0;
}
$ ./pid
open: fh = 3, name = /tmp/foo.pid
write: fh = 3, name = /tmp/foo.pid
close: fh = 0, name =
pid: pidfile_remove: Invalid argument
$ grep -iE 'name|version' /etc/os-release
NAME="Ubuntu"
VERSION="16.04 LTS (Xenial Xerus)"
PRETTY_NAME="Ubuntu 16.04 LTS"
VERSION_ID="16.04"
UBUNTU_
$ gcc --version | grep ^gcc
gcc (Ubuntu 5.4.0-6ubuntu1~
$ ldd pid
libbsd.so.0 => /lib/x86_
libc.so.6 => /lib/x86_