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
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_open("/tmp/foo.pid", 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/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_CODENAME=xenial

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

$ ldd pid
        linux-vdso.so.1 =>  (0x00007fffc79b6000)
        libbsd.so.0 => /lib/x86_64-linux-gnu/libbsd.so.0 (0x00007f72ee343000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f72edf79000)
        /lib64/ld-linux-x86-64.so.2 (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.
https://bugs.launchpad.net/bugs/1836219

Title:
  pidfile_close prevents pidfile_remove from working

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/libbsd/+bug/1836219/+subscriptions

-- 
ubuntu-bugs mailing list
ubuntu-bugs@lists.ubuntu.com
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs

Reply via email to