freebsd-dev/libexec/rc
Mariusz Zaborski 6ba108e52d rc.subr: use _pidcmd to determine pid for protect
This is a more reliable method that accounts for existing pidfiles,
procname and interpreter settings.

Current method of obtaining the pid for oomprotect="YES"|"ALL" processes
in certain cases fails to find a unique pid.

One such case are rc.d scripts defining command as:
command="daemon"

which results in all processes started via daemon being selected and
passed to protect(1) which fails and prints usage:

$ /etc/rc.d/exampled restart
Stopping exampled.
Starting exampled.
usage: protect [-i] command
   protect [-cdi] -g pgrp | -p pid

Running the same with -x reveals what happens:

+ pid='3051 4268 4390 4421 4427 4470 4588 4733 4740 4870 4949 4954 4979
5835 5866 55487 55583 56525 57643 57789 57882 58072 58167 99419'
+ /usr/bin/protect -p 3051 4268 4390 4421 4427 4470 4588 4733 4740 4870
4949 4954 4979 5835 5866 55487 55583 56525 57643 57789 57882 58072 58167
99419
usage: protect [-i] command
   protect [-cdi] -g pgrp | -p pid

We have a more reliable way of obtaining pid already defined in rc.subr
and available when protect(1) needs it. We can simply `eval $_pidcmd`
which also invokes `check_process` but properly accounts for existing
pidfile, procname and interpreter settings.

With the change the pidfile is properly obtained.

Submitted by:	Adam Wolk <a.wolk at fudosecurity.com>
Sponsored by:	Fudo Security
Differential Revision:	https://reviews.freebsd.org/D30367
2021-06-24 20:14:31 +02:00
..
rc.d devmatch: improve naming of devmatch config variable 2021-06-18 13:17:30 +01:00
Makefile Revert r359294 per manu's request 2020-03-25 08:35:55 +00:00
netstart
network.subr IPv6: set ifdisabled in the kernel rather than in rc 2020-11-25 20:58:01 +00:00
pccard_ether
rc Revert "rc: implement parallel boot" 2021-03-09 14:26:07 +01:00
rc.bsdextended pkgbase: Really move rc.bsdextended 2019-05-22 07:39:59 +00:00
rc.conf devmatch: improve naming of devmatch config variable 2021-06-18 13:17:30 +01:00
rc.firewall rc.firewall: Merge two identical conditions into one. 2020-07-23 15:03:28 +00:00
rc.initdiskless Make mdmfs verbose if diskless boot is verbose. 2019-04-26 14:44:50 +00:00
rc.resume rcorder(8): add support for /etc/rc.resume, so it calls "rcorder -k resume" 2018-10-27 17:21:13 +00:00
rc.sendmail pkgbase: Really move rc.sendmail 2019-05-22 07:40:39 +00:00
rc.shutdown rc.shutdown: kill shutdown process after logging message 2019-12-07 00:33:08 +00:00
rc.subr rc.subr: use _pidcmd to determine pid for protect 2021-06-24 20:14:31 +02:00
rc.suspend