Page MenuHomeFreeBSD

D57231.diff
No OneTemporary

D57231.diff

diff --git a/usr.sbin/watchdogd/watchdogd.8 b/usr.sbin/watchdogd/watchdogd.8
--- a/usr.sbin/watchdogd/watchdogd.8
+++ b/usr.sbin/watchdogd/watchdogd.8
@@ -41,6 +41,7 @@
.Op Fl -pretimeout-action Ar action
.Op Fl e Ar cmd
.Op Fl I Ar file
+.Op Fl k Ar kenv
.Op Fl s Ar sleep
.Op Fl t Ar timeout
.Op Fl T Ar script_timeout
@@ -130,6 +131,10 @@
Write the process ID of the
.Nm
utility in the specified file.
+.It Fl k Ar kenv
+Write the process ID of the
+.Nm
+utility in the specified kernel environment variable.
.It Fl d Fl -debug
Do not fork.
When this option is specified,
diff --git a/usr.sbin/watchdogd/watchdogd.c b/usr.sbin/watchdogd/watchdogd.c
--- a/usr.sbin/watchdogd/watchdogd.c
+++ b/usr.sbin/watchdogd/watchdogd.c
@@ -34,6 +34,7 @@
*/
#include <sys/types.h>
+#include <sys/cdefs.h>
#include <sys/mman.h>
#include <sys/param.h>
#include <sys/rtprio.h>
@@ -45,6 +46,7 @@
#include <err.h>
#include <errno.h>
#include <fcntl.h>
+#include <kenv.h>
#include <libutil.h>
#include <math.h>
#include <paths.h>
@@ -74,6 +76,7 @@
static int debugging = 0;
static int end_program = 0;
static const char *pidfile = _PATH_VARRUN "watchdogd.pid";
+static const char *kenv_name = NULL;
static sbintime_t timeout = 128 * SBT_1S;
static u_int exit_timeout = WD_TO_NEVER;
static u_int pretimeout = 0;
@@ -117,9 +120,11 @@
int
main(int argc, char *argv[])
{
+ char spid[sizeof(__XSTRING(PID_MAX))];
struct rtprio rtp;
struct pidfh *pfh;
- pid_t otherpid;
+ pid_t pid, otherpid;
+ int ret;
if (getuid() != 0)
errx(EX_SOFTWARE, "not super user");
@@ -162,6 +167,17 @@
signal(SIGINT, sighandler);
signal(SIGTERM, sighandler);
+ if (kenv_name != NULL) {
+ pid = getpid();
+ ret = snprintf(spid, sizeof(spid), "%d", pid);
+ if (ret == -1 || ret >= (int)sizeof(spid)) {
+ warn("Cannot convert pid to string");
+ } else if (kenv(KENV_SET, kenv_name, spid,
+ sizeof(spid)) == -1) {
+ warn("Cannot set pid in kenv");
+ }
+ }
+
pidfile_write(pfh);
if (madvise(0, 0, MADV_PROTECT) != 0)
warn("madvise failed");
@@ -461,8 +477,8 @@
{
if (is_daemon)
fprintf(stderr, "usage:\n"
-" watchdogd [-dnSw] [-e cmd] [-I pidfile] [-s sleep] [-t timeout]\n"
-" [-T script_timeout] [-x exit_timeout]\n"
+" watchdogd [-dnSw] [-e cmd] [-I pidfile] [-k kenv_name] [-s sleep]\n"
+" [-t timeout] [-T script_timeout] [-x exit_timeout]\n"
" [--debug]\n"
" [--pretimeout seconds] [-pretimeout-action action]\n"
" [--softtimeout] [-softtimeout-action action]\n"
@@ -653,7 +669,7 @@
is_daemon = 1;
if (is_daemon)
- getopt_shortopts = "I:de:ns:t:ST:wx:?";
+ getopt_shortopts = "I:de:k:ns:t:ST:wx:?";
else
getopt_shortopts = "dt:?";
@@ -669,6 +685,9 @@
case 'e':
test_cmd = strdup(optarg);
break;
+ case 'k':
+ kenv_name = optarg;
+ break;
case 'n':
is_dry_run = 1;
break;

File Metadata

Mime Type
text/plain
Expires
Fri, May 29, 10:28 PM (6 m, 41 s)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
33610354
Default Alt Text
D57231.diff (2 KB)

Event Timeline