From nobody Sat Jan 04 08:53:31 2025 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4YQDkM4J8tz5jyxx; Sat, 04 Jan 2025 08:53:31 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4YQDkM3cMsz3xFX; Sat, 4 Jan 2025 08:53:31 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1735980811; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=4U+c6fj+ErL4TK77hXdrK6L00mfsYtUT+0fl3dh6hIs=; b=d+o2SISXDpLY4EaSMY8mMXW7vJ7tHUwCQxqZrxkOdal01MiiAB4uQO/6hracL0n1Txfwlg RCxOT9Ylbh7XsWYOX38skTr977eZML8h4TFbyVTPIHvKZc6fLgOhEE22Oj+S3X0sPpBh4g dGLNe3a4Vqi/mBQ+tYEszav+DBdGaCInNkQd9ZzgFOxDkMrYCaR4o8G68pQ3Jgb55V1kA0 Z71emsfuBsIbDpdFM8orS0UV+ZRRNz8ffjlqX0F84RaEoeXd9i990huGEYXAfWF2Jd539l h0TZbyoX0Fhkq2CgZwUIAcFnJl/0r8RSzT8V44n2h9dExEajhDH8AW3TYHePwg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1735980811; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=4U+c6fj+ErL4TK77hXdrK6L00mfsYtUT+0fl3dh6hIs=; b=DrWt4yfeH4+dA670qAvQN+VRdySQuWY1dAR7ISGba+GGVsrgjgLIiEOEoDFsRXd9VTiBHo 83ztK96ZWUWgdG9f0iC8EN+Bu5ok3l13JZNr8hqhZBNQv0rnBgO1zCic95VGbicrvypln7 RM8LOn2hw89J0Mgpp0RxcP9QmTvsewZHY7Xe1r3ijbLNzTrGIsf7r6hD34U8uRZ7vXFHne +reHJt/dD9YsYNKdPVIa0s21hIEXEj+2pRZPlcMDPWn3Qaw22iTplTQ+I2D053OqCrfXep SDbybTFN7X7Vffkv78j/BA3HB4WEKh0hHUVi7Xl+6oWucONVfp+C5Oyzvi+7kw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1735980811; a=rsa-sha256; cv=none; b=E2H15O6YJq2lDIU0TZn2iYouJ1ie4TjDY3SehEN2vEXFS0QbG83yGi1SIXL9y5pkVPQQ5R dVQN5klwCubOLR0xgJwkBHZ2LXAt/UaUq7Pbgen+vrbOgj2n7k6qCMU0DmWJc3MMjkSGPW r7ooMsSQUhlEo6KwZ92E40Lm/kLu5WYgVEVyfYkGOG17WV8m3eEnCoxY38ToagWabdZ9d9 YJ/FD/qyiC/DO2Q8PFH4kyDJIcMtT//ukOYTJwtsLzYm9BN26YxhC6bp0KNnfRM5JBZjgn UqoXTN9+5ttTAXf0V50AoMonaWLYLTaV8tvsr2lJtmThS183Ok3ccewWC4qQOw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4YQDkM3BbSzlkf; Sat, 04 Jan 2025 08:53:31 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 5048rVSA087731; Sat, 4 Jan 2025 08:53:31 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 5048rVCw087728; Sat, 4 Jan 2025 08:53:31 GMT (envelope-from git) Date: Sat, 4 Jan 2025 08:53:31 GMT Message-Id: <202501040853.5048rVCw087728@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Gordon Bergling Subject: git: d633a7d12105 - main - timeout(1): Add -v/--verbose option to show diagnosis info List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: gbe X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: d633a7d12105a54551622882f4eee80a13a1445a Auto-Submitted: auto-generated The branch main has been updated by gbe: URL: https://cgit.FreeBSD.org/src/commit/?id=d633a7d12105a54551622882f4eee80a13a1445a commit d633a7d12105a54551622882f4eee80a13a1445a Author: Gordon Bergling AuthorDate: 2025-01-04 08:52:56 +0000 Commit: Gordon Bergling CommitDate: 2025-01-04 08:52:56 +0000 timeout(1): Add -v/--verbose option to show diagnosis info The -v/--verbose option enables this utility to show diagnosis info to stderr about any signal sent on timeout. This implementation refers to GNU coreutils's timeout(1). Reviewed by: bapt, Alexander Ziaee (manpages) Approved by: bapt (src) Obtained from: DragonFlyBSD MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D48225 --- bin/timeout/timeout.1 | 6 ++++-- bin/timeout/timeout.c | 28 +++++++++++++++++++++++----- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/bin/timeout/timeout.1 b/bin/timeout/timeout.1 index b8ec3030b271..1a5fd95a6256 100644 --- a/bin/timeout/timeout.1 +++ b/bin/timeout/timeout.1 @@ -24,7 +24,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd December 28, 2024 +.Dd January 4, 2025 .Dt TIMEOUT 1 .Os .Sh NAME @@ -34,7 +34,7 @@ .Nm .Op Fl k Ar time | Fl -kill-after Ar time .Op Fl s Ar sig | Fl -signal Ar sig -.Op Fl -kill-after Ar time | Fl k Ar time +.Op Fl v | Fl -verbose .Op Fl -foreground .Op Fl -preserve-status .Ar duration @@ -76,6 +76,8 @@ Specify the signal to send on timeout. By default, .Dv SIGTERM is sent. +.It Fl v , Fl -verbose +Show information to stderr about any signal sent on timeout. .It Fl -foreground Do not propagate timeout to the children of .Ar command . diff --git a/bin/timeout/timeout.c b/bin/timeout/timeout.c index 76e51eaa965e..429ca64349e3 100644 --- a/bin/timeout/timeout.c +++ b/bin/timeout/timeout.c @@ -49,14 +49,17 @@ static sig_atomic_t sig_chld = 0; static sig_atomic_t sig_term = 0; static sig_atomic_t sig_alrm = 0; static sig_atomic_t sig_ign = 0; +static const char *command = NULL; +static bool verbose = false; static void usage(void) { fprintf(stderr, "Usage: %s [-k time | --kill-after time]" - " [-s sig | --signal sig] [--foreground] [--preserve-status]" - " \n", getprogname()); + " [-s sig | --signal sig] [-v | --verbose] [--foreground]" + " [--preserve-status] \n", + getprogname()); exit(EXIT_FAILURE); } @@ -146,6 +149,16 @@ sig_handler(int signo) } } +static void +send_sig(pid_t pid, int signo) +{ + if (verbose) { + warnx("sending signal %s(%d) to command '%s'", + sys_signame[signo], signo, command); + } + kill(pid, signo); +} + static void set_interval(double iv) { @@ -196,10 +209,11 @@ main(int argc, char **argv) { "kill-after", required_argument, NULL, 'k'}, { "signal", required_argument, NULL, 's'}, { "help", no_argument, NULL, 'h'}, + { "verbose", no_argument, NULL, 'v'}, { NULL, 0, NULL, 0 } }; - while ((ch = getopt_long(argc, argv, "+k:s:h", longopts, NULL)) != -1) { + while ((ch = getopt_long(argc, argv, "+k:s:vh", longopts, NULL)) != -1) { switch (ch) { case 'k': do_second_kill = true; @@ -208,6 +222,9 @@ main(int argc, char **argv) case 's': killsig = parse_signal(optarg); break; + case 'v': + verbose = true; + break; case 0: break; case 'h': @@ -225,6 +242,7 @@ main(int argc, char **argv) first_kill = parse_duration(argv[0]); argc--; argv++; + command = argv[0]; if (!foreground) { /* Acquire a reaper */ @@ -315,7 +333,7 @@ main(int argc, char **argv) procctl(P_PID, getpid(), PROC_REAP_KILL, &killemall); } else - kill(pid, killsig); + send_sig(pid, killsig); if (do_second_kill) { set_interval(second_kill); @@ -332,7 +350,7 @@ main(int argc, char **argv) procctl(P_PID, getpid(), PROC_REAP_KILL, &killemall); } else - kill(pid, sig_term); + send_sig(pid, sig_term); if (do_second_kill) { set_interval(second_kill);