From nobody Tue May 24 08:05:11 2022 X-Original-To: dev-commits-src-main@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 BF7291B3ADD1; Tue, 24 May 2022 08:05:11 +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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4L6mvq4xcQz4qFx; Tue, 24 May 2022 08:05:11 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1653379511; 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=+e7hAS0O/dFMqg0WNAWCJS6vuobPiQtcg5/JRQJhSlQ=; b=kHcZeGkh/YV/aGyYiaWPMFEex3y3OfmHhcG59NDCYJiO2YqjD52Fv+yfsVuSt0OtBbeHfq W8m07k8T3af/ZU9nyu0frKFX0nflrnkMxqMm0xgy5qVZW2K/3mEO7JJjZOb+xnIB8d00aP SPcE0Ck4A7W35GqpOQ1kERB1oHzTWLLZZbtVT4WyzoxtvvgRUNFWPfOJ35fSY4ROnsHMAF ikToZjK9FOTSM+kDtb8K0TYzg+fAkd4UOVOptuVz7cdez0T6AWVZo+njX8hhVfxsukdz7/ 73vUaQNqKZvpYkdcHjYTMpcpUIMKV1jk14c5ZYb+NM1VjhhjYpYwF0RQGSvItA== 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 7FC4F20D34; Tue, 24 May 2022 08:05:11 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 24O85Bi0094146; Tue, 24 May 2022 08:05:11 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 24O85B1e094145; Tue, 24 May 2022 08:05:11 GMT (envelope-from git) Date: Tue, 24 May 2022 08:05:11 GMT Message-Id: <202205240805.24O85B1e094145@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: =?utf-8?Q?Stefan E=C3=9Fer?= Subject: git: 34978f7edd15 - main - bin/sleep: add support for units other than seconds List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: se X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 34978f7edd15ef5aa9c14a6eecb18ae5d6fd8842 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1653379511; 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=+e7hAS0O/dFMqg0WNAWCJS6vuobPiQtcg5/JRQJhSlQ=; b=MS6UQs6QDxHFSYz0grYkEG9SNJg1gdOkPoq5tpQBH+J3EjgFGevnraGOd4KaDCddAyokp0 BzuSW/OfCLeJfzjDbs3HJu0s4hmCCwMNtWoKla9mgVG7rLV+RUvLyibI1QvsCnpymVvIPX 3EhNmViZmjpjwTxl+3ZK7q4iBn+MpJXn9uW3uSO90qqBGIVfnzcxUNeCvMyY6qHp6Mkzhi vCPcLD9fYkj2h2lI7jAhpov+WgIYzEdPpkGbsrzOYEkXwyK48L1veMJhghJriPURS61IDu oE+Ns4lWCwttDrJjO1uFnyVrDLhnqcyYMLc5U8tAUbyxps6eDWVCqC4tAM0lrQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1653379511; a=rsa-sha256; cv=none; b=uvBVAtI1dhVN6J6W0GmlyszfpsP2z9kIrNR2tp0Mjcs5MPqEQXirJwEVT17tJmiz9Rq/Nh jKsgYh5RFXc4A2fstxPDdMsHiGh/Hi9ysXFf+H9T5cFZHNq+6Ema3rSFcjTKwIndznYRPr mdQggjDz2+6aZlLyQY+4pu/wNlIKCIYqhFWrgHBzqxA9mNrHD+U4+w0MyNYJ0DKGk14U2V cm70bhj0vTwFbFnhTDYSyghKRKj1/by0HEUFt1G5IKICs15UHj6rlWynpXohbI5OJcH4w8 D4zMZHHDpJdJeUkv5rXIdtFVSRFoH/LrdJhzrdavjT1M/6fJFWf9eQUz6+h1sw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by se: URL: https://cgit.FreeBSD.org/src/commit/?id=34978f7edd15ef5aa9c14a6eecb18ae5d6fd8842 commit 34978f7edd15ef5aa9c14a6eecb18ae5d6fd8842 Author: A. Mallory AuthorDate: 2022-05-24 07:43:38 +0000 Commit: Stefan Eßer CommitDate: 2022-05-24 07:43:38 +0000 bin/sleep: add support for units other than seconds The coreutils version of this command accepts a unit designation of s, m, h, or d (for seconds, minutes, hours, days) immediately following the number of (fractional) units to delay. The submitted patch has been modified in one detail: the test meant to detect the presence of the unit modified was not specific (!= 1) and would have accepted a non-numeric initial element or extra characters following the union. The committed version accepts only the number immediately followed by one of the defined unit designators and no further characters. PR: 264162 MFC after: 1 week --- bin/sleep/sleep.1 | 12 ++++++++++-- bin/sleep/sleep.c | 18 +++++++++++++++--- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/bin/sleep/sleep.1 b/bin/sleep/sleep.1 index 924bc732a0d0..3ce82936a0e7 100644 --- a/bin/sleep/sleep.1 +++ b/bin/sleep/sleep.1 @@ -40,13 +40,21 @@ .Nd suspend execution for an interval of time .Sh SYNOPSIS .Nm -.Ar seconds +.Ar number[unit] .Sh DESCRIPTION The .Nm command suspends execution for a minimum of -.Ar seconds . +.Ar number +seconds (the default, or unit +.Ar s ) , +or minutes (unit +.Ar m ) , +hours (unit +.Ar h ) , +or days (unit +.Ar d ) . .Pp If the .Nm diff --git a/bin/sleep/sleep.c b/bin/sleep/sleep.c index b4b54a336100..8f383e43c479 100644 --- a/bin/sleep/sleep.c +++ b/bin/sleep/sleep.c @@ -66,6 +66,7 @@ main(int argc, char *argv[]) struct timespec time_to_sleep; double d; time_t original; + char unit; char buf[2]; if (caph_limit_stdio() < 0 || caph_enter() < 0) @@ -74,8 +75,17 @@ main(int argc, char *argv[]) if (argc != 2) usage(); - if (sscanf(argv[1], "%lf%1s", &d, buf) != 1) - usage(); + if (sscanf(argv[1], "%lf%c%1s", &d, &unit, buf) == 2) + switch(unit) { + case 'd': d *= 24; + case 'h': d *= 60; + case 'm': d *= 60; + case 's': break; + default: usage(); + } + else + if (sscanf(argv[1], "%lf%1s", &d, buf) != 1) + usage(); if (d > INT_MAX) usage(); if (d <= 0) @@ -106,6 +116,8 @@ static void usage(void) { - fprintf(stderr, "usage: sleep seconds\n"); + fprintf(stderr, "usage: sleep number[unit]\n"); + fprintf(stderr, "Unit can be 's' (seconds, the default), " + "m (minutes), h (hours), or d (days).\n"); exit(1); }