freebsd-dev/libexec
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
..
atf pkgbase: Install atf and kyua in the tests package 2021-01-04 16:20:47 +01:00
atrun libexec: adoption of SPDX licensing ID tags. 2017-11-27 15:25:02 +00:00
blacklistd-helper DIRDEPS_BUILD: Connect new directories and update dependencies. 2016-06-03 19:25:30 +00:00
bootpd Restore WARNS?=1 here. I missed that libexec/bootpd/bootpgw existed. 2019-07-19 18:47:13 +00:00
comsat General further adoption of SPDX licensing ID tags. 2017-11-20 19:49:47 +00:00
dma Only set WARNS if not defined 2020-09-11 13:28:37 +00:00
fingerd Update Makefile.depend files 2019-12-11 17:37:53 +00:00
flua stand: lua: enhance lfs.dir() to speed up kernels_autodetect 2021-01-29 12:47:29 -06:00
ftpd ftpd: Add missing braces around a statfd check 2020-09-22 15:54:18 +00:00
getty libexec/getty/ttys.5: document correct "dialup" flag. 2021-06-01 17:05:16 +01:00
hyperv hyperv: Add VF bringup scripts and devd rules. 2017-07-31 07:18:15 +00:00
mail.local DIRDEPS_BUILD: Update dependencies. 2017-10-31 00:07:04 +00:00
makewhatis.local makewhatis: do not try to operate on read-only mounted directories 2018-10-27 17:15:58 +00:00
mknetid General further adoption of SPDX licensing ID tags. 2017-11-20 19:49:47 +00:00
phttpget phttpget: move out of portsnap 2020-09-09 00:39:47 +00:00
pppoed libexec: adoption of SPDX licensing ID tags. 2017-11-27 15:25:02 +00:00
rbootd Fix the following -Werror warning from clang 10.0.0 in rbootd: 2020-01-28 19:19:55 +00:00
rc rc.subr: use _pidcmd to determine pid for protect 2021-06-24 20:14:31 +02:00
revnetgroup General further adoption of SPDX licensing ID tags. 2017-11-20 19:49:47 +00:00
rpc.rquotad pkgbase: Create a FreeBSD-nfs package 2021-06-19 17:49:50 +02:00
rpc.rstatd General further adoption of SPDX licensing ID tags. 2017-11-20 19:49:47 +00:00
rpc.rusersd General further adoption of SPDX licensing ID tags. 2017-11-20 19:49:47 +00:00
rpc.rwalld libexec: adoption of SPDX licensing ID tags. 2017-11-27 15:25:02 +00:00
rpc.sprayd rpc.sprayd: raise WARNS to 6 2018-03-05 16:11:07 +00:00
rtld-elf rtld-elf: Check the return value of obj_enforce_relro() 2021-06-22 09:10:48 +01:00
rtld-elf32 libcompat: Correct rtld MLINKS 2019-11-12 22:31:59 +00:00
save-entropy Reduce disk write load in /usr/libexec/save-entropy. 2019-11-30 20:06:53 +00:00
smrsh DIRDEPS_BUILD: Update dependencies. 2017-10-31 00:07:04 +00:00
talkd Regularize my copyright notice 2019-12-04 16:56:11 +00:00
tcpd DIRDEPS_BUILD: Update dependencies. 2017-10-31 00:07:04 +00:00
telnetd Update Makefile.depend files 2019-12-11 17:37:53 +00:00
tests Merge ^/user/ngie/release-pkg-fix-tests to unbreak how test files are installed 2016-05-04 23:20:53 +00:00
tftp-proxy (t)ftp-proxy: use libpfctl 2021-04-10 11:16:02 +02:00
tftpd When receiving a file having a length, which is a mulitple of the blocksize, 2020-12-15 09:43:18 +00:00
ulog-helper libexec: adoption of SPDX licensing ID tags. 2017-11-27 15:25:02 +00:00
ypxfr yp*: fix -fno-common build 2020-04-06 23:16:05 +00:00
Makefile phttpget: move out of portsnap 2020-09-09 00:39:47 +00:00
Makefile.amd64
Makefile.i386
Makefile.inc Do a sweep and remove most WARNS=6 settings 2020-10-01 01:10:51 +00:00