Public bug reported:

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

The following program and associated output illustrates the problem.

#include <err.h>
#include <stdio.h>
#include <stdlib.h>

#include <bsd/libutil.h>

show_pfh( const char func[], struct pidfh * pfh ) {
  printf( "%s: fh = %d, name = %s\n", func, pfh->pf_fd, pfh->pf_path );

main(int argc, char *argv[])
  pid_t pid;
  struct pidfh * pfh = pidfile_open("/tmp/", 0644, &pid);

  if( !pfh ) {
    err(EXIT_FAILURE, "pidfile_open");
  show_pfh("open", pfh);
  if( -1 == pidfile_write(pfh) ) {
    err(EXIT_FAILURE, "pidfile_write");
  show_pfh("write", pfh);

  if( -1 == pidfile_close(pfh) ) {
    err(EXIT_FAILURE, "pidfile_close");
  show_pfh("close", pfh);

  if( -1 == pidfile_remove(pfh) ) {
    err(EXIT_FAILURE, "pidfile_remove");
  show_pfh("remove", pfh);

  return 0;
$ ./pid
open: fh = 3, name = /tmp/
write: fh = 3, name = /tmp/
close: fh = 0, name = 
pid: pidfile_remove: Invalid argument

$ grep -iE 'name|version' /etc/os-release 
VERSION="16.04 LTS (Xenial Xerus)"
PRETTY_NAME="Ubuntu 16.04 LTS"

$ gcc --version | grep ^gcc
gcc (Ubuntu 5.4.0-6ubuntu1~16.04.11) 5.4.0 20160609

$ ldd pid =>  (0x00007fffc79b6000) => /lib/x86_64-linux-gnu/ (0x00007f72ee343000) => /lib/x86_64-linux-gnu/ (0x00007f72edf79000)
        /lib64/ (0x00007f72ee558000)

** Affects: libbsd (Ubuntu)
     Importance: Undecided
         Status: New

You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.

  pidfile_close prevents pidfile_remove from working

To manage notifications about this bug go to:

ubuntu-bugs mailing list

Reply via email to