History log of /freebsd-current/lib/libutil/pidfile.c
Revision Date Author Comments
# a2f733ab 24-Nov-2023 Warner Losh <imp@FreeBSD.org>

lib: Automated cleanup of cdefs and other formatting

Apply the following automated changes to try to eliminate
no-longer-needed sys/cdefs.h includes as well as now-empty
blank lines in a row.

Remove /^#if.*\n#endif.*\n#include\s+<sys/cdefs.h>.*\n/
Remove /\n+#include\s+<sys/cdefs.h>.*\n+#if.*\n#endif.*\n+/
Remove /\n+#if.*\n#endif.*\n+/
Remove /^#if.*\n#endif.*\n/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/types.h>/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/param.h>/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/capsicum.h>/

Sponsored by: Netflix


# 1d386b48 16-Aug-2023 Warner Losh <imp@FreeBSD.org>

Remove $FreeBSD$: one-line .c pattern

Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/


# 4d846d26 10-May-2023 Warner Losh <imp@FreeBSD.org>

spdx: The BSD-2-Clause-FreeBSD identifier is obsolete, drop -FreeBSD

The SPDX folks have obsoleted the BSD-2-Clause-FreeBSD identifier. Catch
up to that fact and revert to their recommended match of BSD-2-Clause.

Discussed with: pfg
MFC After: 3 days
Sponsored by: Netflix


# 287451fd 11-Mar-2022 Mateusz Guzik <mjg@FreeBSD.org>

pidfile: add pidfile_signal

Differential Revision: https://reviews.freebsd.org/D34681


# 9b934d43 25-Jun-2020 David Bright <dab@FreeBSD.org>

Add CAP_EVENT to pidfiles.

CAP_EVENT was omitted on pidfiles (in
pidfile_open()). There seems no reason why a process that creates
and writes a pidfile cannot monitor events on that file. This mod adds
the capability.

Reviewed by: cem@
MFC after: 2 weeks
Sponsored by: Dell EMC Isilon
Differential Revision: https://reviews.freebsd.org/D25363


# 8a9e93bb 06-Apr-2019 Mariusz Zaborski <oshogbo@FreeBSD.org>

Use funlinkat in pidfile to ensure we are removing the right file.


# a273e09c 27-Mar-2019 Mark Johnston <markj@FreeBSD.org>

Fix pidfile_open(3) to handle relative paths with multiple components.

r322369's use of basename(3) was incorrect and worked by accident so
long as the pidfile path was absolute or consisted of a single
component. Fix the basename() usage and add a regression test.

Reported by: 0mp
Reviewed by: cem
MFC after: 3 days
Differential Revision: https://reviews.freebsd.org/D19728


# 5e53a4f9 25-Nov-2017 Pedro F. Giffuni <pfg@FreeBSD.org>

lib: further adoption of SPDX licensing ID tags.

Mainly focus on files that use BSD 2-Clause license, however the tool I
was using mis-identified many licenses so this was mostly a manual - error
prone - task.

The Software Package Data Exchange (SPDX) group provides a specification
to make it easier for automated tools to detect and summarize well known
opensource licenses. We are gradually adopting the specification, noting
that the tags are considered only advisory and do not, in any way,
superceed or replace the license texts.


# 1a32b205 10-Aug-2017 Mariusz Zaborski <oshogbo@FreeBSD.org>

Limit descriptors stored in the pidfh structure.

Reviewed by: markj, cem
Differential Revision: https://reviews.freebsd.org/D11741


# 4f9612a3 10-Aug-2017 Mariusz Zaborski <oshogbo@FreeBSD.org>

Store directory descriptor in the pidfh structure and use unlinkat(2)
function instead of unlink(2).

Now when pidfile_remove() uses unlinkat(2) to remove the pidfile
it is safe to use this function in capability mode.

Style fix: sort headers.

PR: 220524
Reviewed by: markj
Differential Revision: https://reviews.freebsd.org/D11692


# 872a3a62 18-May-2016 Pedro F. Giffuni <pfg@FreeBSD.org>

libutil: minor spelling fixes.


# d1d4d952 28-Aug-2013 Jilles Tjoelker <jilles@FreeBSD.org>

libutil: Use O_CLOEXEC for internal file descriptors from open().


# 36a00a3f 14-Mar-2013 Pawel Jakub Dawidek <pjd@FreeBSD.org>

When pidptr was passed as NULL to pidfile_open(3), we were returning
EAGAIN/EWOULDBLOCK when another daemon was running and had the pidfile open.
We should return EEXIST in that case, fix it.

Reported by: Dirk Engling <erdgeist@erdgeist.org>
Reviewed by: jhb, Dirk Engling <erdgeist@erdgeist.org>
MFC after: 1 week


# fde44397 20-Feb-2012 Guy Helmer <ghelmer@FreeBSD.org>

Set the O_CLOEXEC flag when opening the pidfile to avoid leaking the
file descriptor via exec(3).

Now that daemon(8) has been fixed to resolve the issue noted by trociny,
the consensus is that this change should be OK.


# 000d6ce2 06-Feb-2012 Guy Helmer <ghelmer@FreeBSD.org>

Using the O_CLOEXEC flag on open(2) caused the pidfile lock to be lost
when the child process execs daemon's target program thanks to flock(2)
semantics. So, we apparently have to leak the open pidfile's file
descriptor to keep the lock for the pidfile(3) functions to work properly.

Test case demonstrated by trociny:

ref8-amd64:/home/trociny% uname -r
8.2-STABLE
ref8-amd64:/home/trociny% daemon -p /tmp/sleep.pid sleep 10
ref8-amd64:/home/trociny% daemon -p /tmp/sleep.pid sleep 10
daemon: process already running, pid: 19799

kopusha:~% uname -r
10.0-CURRENT
kopusha:~% daemon -p /tmp/sleep.pid sleep 10
kopusha:~% daemon -p /tmp/sleep.pid sleep 10
kopusha:~%


# 47b3924b 12-Jan-2012 Guy Helmer <ghelmer@FreeBSD.org>

Move struct pidfh definition into pidfile.c, and leave a forward declaration
for pidfh in libutil.h in its place.
This allows us to hide the contents of the pidfh structure, and also
allowed removal of the "#ifdef _SYS_PARAM_H" guard from around the
pidfile_* function prototypes.

Suggested by pjd.


# 656b6da7 11-Jan-2012 Guy Helmer <ghelmer@FreeBSD.org>

jilles pointed out that O_CLOEXEC could be used in the open(2) flags
rather than using fcntl(2) later, and in addition to saving a system
call, removes a possible race with fork/exec from threads or signal
handlers.


# 9de091f2 10-Jan-2012 Pawel Jakub Dawidek <pjd@FreeBSD.org>

Constify arguments.


# 4a25aa06 10-Jan-2012 Guy Helmer <ghelmer@FreeBSD.org>

Style fixes courtesy of pjd.


# f295618d 10-Jan-2012 Guy Helmer <ghelmer@FreeBSD.org>

Add pidfile_fileno() to obtain the file descriptor for an open
pidfile.


# 0dc6d4d1 10-Jan-2012 Guy Helmer <ghelmer@FreeBSD.org>

Set the FD_CLOEXEC flag on the open pidfile file descriptor.

Discussed with: pjd, des


# e8cc80c0 16-Oct-2011 Pawel Jakub Dawidek <pjd@FreeBSD.org>

In pidfile_open(), if the pidfile is locked, but empty (PID is not stored yet)
and the caller requested other process' PID by passing non-NULL pidptr
argument, we will wait at most 100ms for the PID to show up in the file and if
it won't, we will store -1 in *pidptr.

From now on, pidfile_open() function never sets errno to EAGAIN on failure.

In collaboration with: des
MFC after: 1 week


# a7d5f7eb 19-Oct-2010 Jamie Gritton <jamie@FreeBSD.org>

A new jail(8) with a configuration file, to replace the work currently done
by /etc/rc.d/jail.


# fe0506d7 09-Mar-2010 Marcel Moolenaar <marcel@FreeBSD.org>

Create the altix project branch. The altix project will add support
for the SGI Altix 350 to FreeBSD/ia64. The hardware used for porting
is a two-module system, consisting of a base compute module and a
CPU expansion module. SGI's NUMAFlex architecture can be an excellent
platform to test CPU affinity and NUMA-aware features in FreeBSD.


# 51e75198 20-Oct-2008 Dag-Erling Smørgrav <des@FreeBSD.org>

There is no point in releasing a lock on a file which we've unlinked and
are about to close, so don't. As a bonus, pidfile_remove(3) will now
work with an fcntl(2)-based flopen(3).


# d7f03759 19-Oct-2008 Ulf Lilleengen <lulf@FreeBSD.org>

- Import the HEAD csup code which is the basis for the cvsmode work.


# fefc6803 12-Oct-2007 Konstantin Belousov <kib@FreeBSD.org>

When pidfile is already locked and has zero length, do not return
success and zero pid from pidfile_read(). Return EAGAIN instead. Sleep
up to three times for 5 ms while waiting for pidfile to be written.

mount(8) does the kill(mountpid, SIGHUP). If mountd pidfile is truncated,
that would result in the SIGHUP delivered to the mount' process group
instead of the mountd.

Found and analyzed by: Peter Holm
Tested by: Peter Holm, kris
Reviewed by: pjd
MFC after: 1 week


# 062044eb 03-Aug-2007 Dag-Erling Smørgrav <des@FreeBSD.org>

Back out previous commit until I figure out why my regression test fails.

Approved by: re (kensmith)


# 7eb198c6 03-Aug-2007 Dag-Erling Smørgrav <des@FreeBSD.org>

Use fcntl(2)-style locks instead of less-portable flock(2)-style locks.

Approved by: re (kensmith)


# b31d5b56 11-May-2007 Dag-Erling Smørgrav <des@FreeBSD.org>

strlcpy() may be faster than snprintf(), but it is less portable, and this
is not performance critical code anyway. Also, avoid using strlen() to
obtain information which we already have.

MFC after: 3 weeks


# 3884dc67 10-May-2007 Dag-Erling Smørgrav <des@FreeBSD.org>

Use flopen(3).

MFC after: 3 weeks


# 25b5a928 22-Jun-2006 Brian Somers <brian@FreeBSD.org>

Remove some unused variables


# 4d5e876b 11-Apr-2006 John-Mark Gurney <jmg@FreeBSD.org>

use pwrite to always write at the begining of the file.. If multiple calls
to pidfile_write happen, the pidfile will have nul characters prepended
due to the cached file descriptor offset...

Reviewed by: scottl
MFC after: 3 days


# 412fa8f1 24-Aug-2005 Pawel Jakub Dawidek <pjd@FreeBSD.org>

Add a family of functions for reliable pidfiles handling.

Idea from: jmg
Discussed on: arch@