diff --git a/usr.bin/lockf/lockf.1 b/usr.bin/lockf/lockf.1 --- a/usr.bin/lockf/lockf.1 +++ b/usr.bin/lockf/lockf.1 @@ -30,7 +30,7 @@ .Nd execute a command while holding a file lock .Sh SYNOPSIS .Nm -.Op Fl knpsw +.Op Fl knpsTw .Op Fl t Ar seconds .Ar file .Ar command @@ -136,6 +136,22 @@ to open .Ar file for writing rather than reading. +.It Fl T +Upon receipt of a +.Dv SIGTERM , +forward a +.Dv SIGTERM +along to the +.Ar command +before cleaning up the +.Ar file +and exiting. +By default, +.Nm +effectively orphans the +.Ar command +after cleaning up the +.Ar file . .It Fl t Ar seconds Specifies a timeout for waiting for the lock. By default, diff --git a/usr.bin/lockf/lockf.c b/usr.bin/lockf/lockf.c --- a/usr.bin/lockf/lockf.c +++ b/usr.bin/lockf/lockf.c @@ -35,6 +35,7 @@ #include #include #include +#include #include #include #include @@ -64,6 +65,7 @@ static int keep; static int fdlock; static int status; +static bool termchild; static volatile sig_atomic_t timed_out; /* @@ -109,7 +111,7 @@ silent = keep = writepid = 0; flags = O_CREAT | O_RDONLY; waitsec = -1; /* Infinite. */ - while ((ch = getopt(argc, argv, "knpst:w")) != -1) { + while ((ch = getopt(argc, argv, "knpsTt:w")) != -1) { switch (ch) { case 'k': keep = 1; @@ -120,6 +122,9 @@ case 's': silent = 1; break; + case 'T': + termchild = true; + break; case 't': { const char *errstr; @@ -356,6 +361,8 @@ killed(int sig) { + if (termchild && child >= 0) + kill(child, sig); cleanup(); signal(sig, SIG_DFL); if (kill(getpid(), sig) == -1)