From nobody Wed Dec 13 20:06:22 2023 X-Original-To: dev-commits-src-branches@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 4Sr61p55GZz54FLn; Wed, 13 Dec 2023 20:06:22 +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 4Sr61p3kF9z4YpN; Wed, 13 Dec 2023 20:06:22 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1702497982; 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=WTLJ8xajZGxoC49L4nntC/e3IpvEmVhog92bnc2wBpg=; b=M3kaQ55+gntyZ95AlPywa55usbST0AYI+Km6aXdB22yHCaWOOdBhIZgnHSFncGlnqXDXp3 8V8WIF8u6PQ1Y7zJWJzMPSqYXYszQGS9qgbb4G1udNbHDLXjIajhbALOgjFY2g4Om/uKoh A5RuEmJsZxdZh9U0Vtw4G9aWXjaqXxE5xBdtS9mz+O1tq0KNShPZIYG6+QU7P4HFI6Ezqx JOdNDADJSsIh7JZJUoOewNKEw3/jLQpK5CcOUZbb3zsRLQlxQhBcSPNEgjMkQ06LO/A7vJ tINlwaraqAkbZTsNMKsNlxfl2W8yR7Q2dioyeTxa+q7u+MlckXjXQ4bvEhKuZA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1702497982; a=rsa-sha256; cv=none; b=xIilenwQ1I6wvJ0RTMyx8Xkrs2ucqQ/S1Ri05VKDJMRWnHSWRUcXxTQeBYqFMVw/7LcFxv WkHk5jzcG76TSBkAk3v5y5bVNXwFyqW44qTVwx48FK6wDKyh1msLYpZ6phM0Ib5BEUcI1o bRYu5BBId+BtDPUWyeGViyQRioHuObzb53EQVjGGHBOeAFtllhCdgUC175wFgwtdyM7TFd QzcfirBPhBy5vWDIfgFEu72Dqmk1kFPewnAi5c4NYdusMQFEYpU9n96dTxByUbmNdcSpTK 9MyMveYh7WbUJSHZVPtiIefxUqD9ZgyIZ1ELyW3wdJQAE4PZ7rmMMFoNMU0wCQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1702497982; 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=WTLJ8xajZGxoC49L4nntC/e3IpvEmVhog92bnc2wBpg=; b=PqYN0IUV55rnqqEP6NAO0cIKVXq85sd5xfHKR/dhlAg2iP8NVm5hy67QKt8N0qOjhloUBd +vdimyCDRzLzm6zhoAyulPbCXcQW+EFr2fXT81q2FHG3aFq8dNVHtnY36rvBMak4JhhdUN HPsYCoB+UFf66Af3XWvIP2rdR9i2geH2RnR5COYnrkr+/7QpyYXBfH56SqlvrsZWWhpAlj yeJzFSjE7J/vA4B9rsRBd3iBCHdRIaZb5phZUQe+v12dputRA89dP1HwBXIaOUWEnTXRnK 9z74n5XmFcoGKXl+ycfwq5o/TvZuSsAdMOilNxMUXNpgCRNIY3jdPz+yoJrI3g== 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 4Sr61p2knwz1C3F; Wed, 13 Dec 2023 20:06:22 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 3BDK6MSW087063; Wed, 13 Dec 2023 20:06:22 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 3BDK6MQm087060; Wed, 13 Dec 2023 20:06:22 GMT (envelope-from git) Date: Wed, 13 Dec 2023 20:06:22 GMT Message-Id: <202312132006.3BDK6MQm087060@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Dag-Erling =?utf-8?Q?Sm=C3=B8rgrav?= Subject: git: 06c9bece28c3 - stable/13 - growfs: make exit codes more consistent List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: des X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 06c9bece28c397111f10f14d9ab22208cf61f5c4 Auto-Submitted: auto-generated The branch stable/13 has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=06c9bece28c397111f10f14d9ab22208cf61f5c4 commit 06c9bece28c397111f10f14d9ab22208cf61f5c4 Author: Mina Galić AuthorDate: 2023-10-05 18:24:53 +0000 Commit: Dag-Erling Smørgrav CommitDate: 2023-12-13 16:19:56 +0000 growfs: make exit codes more consistent We have overused err(1), so it's hard to distinguish when an error is very, very serious, and when it's just a user-error, or even harmless. This patch changes the current behaviour to distinguish between the following three: 1 for usage errors 2 for recoverable errors 3 or higher for unrecoverable errors Reviewed by: jilles, pauamma_gundo.com, des Differential Revision: https://reviews.freebsd.org/D27161 (cherry picked from commit 70a0fb43f91cfe3d08db7cb443d9690f8bff065e) --- sbin/growfs/growfs.8 | 6 +++++- sbin/growfs/growfs.c | 42 +++++++++++++++++++++--------------------- 2 files changed, 26 insertions(+), 22 deletions(-) diff --git a/sbin/growfs/growfs.8 b/sbin/growfs/growfs.8 index ec606f8caf8f..171cd5592c32 100644 --- a/sbin/growfs/growfs.8 +++ b/sbin/growfs/growfs.8 @@ -36,7 +36,7 @@ .\" .\" $TSHeader: src/sbin/growfs/growfs.8,v 1.3 2000/12/12 19:31:00 tomsoft Exp $ .\" -.Dd December 13, 2017 +.Dd October 3, 2023 .Dt GROWFS 8 .Os .Sh NAME @@ -88,6 +88,10 @@ This value defaults to the size of the raw partition specified in .Nm will enlarge the file system to the size of the entire partition). .El +.Sh EXIT STATUS +Exit status is 0 on success, and >= 1 on errors. +Errors recoverable by user action are indicated by 2. +OS errors, which are usually not recoverable, are indicated by 3 or greater. .Sh EXAMPLES Expand root file system to fill up available space: .Dl growfs / diff --git a/sbin/growfs/growfs.c b/sbin/growfs/growfs.c index 423ecbeed722..22d4f895ed26 100644 --- a/sbin/growfs/growfs.c +++ b/sbin/growfs/growfs.c @@ -147,7 +147,7 @@ growfs(int fsi, int fso, unsigned int Nflag) */ fscs = (struct csum *)calloc((size_t)1, (size_t)sblock.fs_cssize); if (fscs == NULL) - errx(1, "calloc failed"); + errx(3, "calloc failed"); memcpy(fscs, osblock.fs_csp, osblock.fs_cssize); free(osblock.fs_csp); osblock.fs_csp = NULL; @@ -259,7 +259,7 @@ growfs(int fsi, int fso, unsigned int Nflag) * and all the alternates back to disk. */ if (!Nflag && sbput(fso, &sblock, sblock.fs_ncg) != 0) - errc(2, EIO, "could not write updated superblock"); + errc(3, EIO, "could not write updated superblock"); DBG_PRINT0("fscs written\n"); #ifdef FS_DEBUG @@ -1339,7 +1339,7 @@ main(int argc, char **argv) size <<= 30; size <<= 10; } else - errx(1, "unknown suffix on -s argument"); + errx(2, "unknown suffix on -s argument"); break; case 'v': /* for compatibility to newfs */ break; @@ -1364,23 +1364,23 @@ main(int argc, char **argv) statfsp = getmntpoint(*argv); device = getdev(*argv, statfsp); if (device == NULL) - errx(1, "cannot find special device for %s", *argv); + errx(2, "cannot find special device for %s", *argv); fsi = open(device, O_RDONLY); if (fsi < 0) - err(1, "%s", device); + err(3, "%s", device); /* * Try to guess the slice size if not specified. */ if (ioctl(fsi, DIOCGMEDIASIZE, &mediasize) == -1) - err(1,"DIOCGMEDIASIZE"); + err(3,"DIOCGMEDIASIZE"); /* * Check if that partition is suitable for growing a file system. */ if (mediasize < 1) - errx(1, "partition is unavailable"); + errx(2, "partition is unavailable"); /* * Read the current superblock, and take a backup. @@ -1388,16 +1388,16 @@ main(int argc, char **argv) if ((ret = sbget(fsi, &fs, STDSB)) != 0) { switch (ret) { case ENOENT: - errx(1, "superblock not recognized"); + errx(2, "superblock not recognized"); default: - errc(1, ret, "unable to read superblock"); + errc(3, ret, "unable to read superblock"); } } /* * Check for filesystem that was unclean at mount time. */ if ((fs->fs_flags & (FS_UNCLEAN | FS_NEEDSFSCK)) != 0) - errx(1, "%s is not clean - run fsck.\n", *argv); + errx(2, "%s is not clean - run fsck.\n", *argv); memcpy(&osblock, fs, fs->fs_sbsize); free(fs); memcpy((void *)&fsun1, (void *)&fsun2, osblock.fs_sbsize); @@ -1418,7 +1418,7 @@ main(int argc, char **argv) mediasize, "B", HN_AUTOSCALE, HN_B | HN_NOSPACE | HN_DECIMAL); - errx(1, "requested size %s is larger " + errx(2, "requested size %s is larger " "than the available %s", oldsizebuf, newsizebuf); } } @@ -1439,7 +1439,7 @@ main(int argc, char **argv) if (size == (uint64_t)(osblock.fs_size * osblock.fs_fsize)) errx(0, "requested size %s is equal to the current " "filesystem size %s", newsizebuf, oldsizebuf); - errx(1, "requested size %s is smaller than the current " + errx(2, "requested size %s is smaller than the current " "filesystem size %s", newsizebuf, oldsizebuf); } @@ -1451,7 +1451,7 @@ main(int argc, char **argv) * Are we really growing? */ if (osblock.fs_size >= sblock.fs_size) { - errx(1, "we are not growing (%jd->%jd)", + errx(3, "we are not growing (%jd->%jd)", (intmax_t)osblock.fs_size, (intmax_t)sblock.fs_size); } @@ -1461,7 +1461,7 @@ main(int argc, char **argv) if (yflag == 0) { for (j = 0; j < FSMAXSNAP; j++) { if (sblock.fs_snapinum[j]) { - errx(1, "active snapshot found in file system; " + errx(2, "active snapshot found in file system; " "please remove all snapshots before " "using growfs"); } @@ -1506,14 +1506,14 @@ main(int argc, char **argv) if (statfsp != NULL && (statfsp->f_flags & MNT_RDONLY) == 0) { fso = open(_PATH_UFSSUSPEND, O_RDWR); if (fso == -1) - err(1, "unable to open %s", _PATH_UFSSUSPEND); + err(3, "unable to open %s", _PATH_UFSSUSPEND); error = ioctl(fso, UFSSUSPEND, &statfsp->f_fsid); if (error != 0) - err(1, "UFSSUSPEND"); + err(3, "UFSSUSPEND"); } else { fso = open(device, O_WRONLY); if (fso < 0) - err(1, "%s", device); + err(3, "%s", device); } } @@ -1522,7 +1522,7 @@ main(int argc, char **argv) */ testbuf = malloc(sblock.fs_fsize); if (testbuf == NULL) - err(1, "malloc"); + err(3, "malloc"); rdfs((ufs2_daddr_t)((size - sblock.fs_fsize) / DEV_BSIZE), sblock.fs_fsize, testbuf, fsi); wtfs((ufs2_daddr_t)((size - sblock.fs_fsize) / DEV_BSIZE), @@ -1577,7 +1577,7 @@ main(int argc, char **argv) fragroundup(&sblock, sblock.fs_ncg * sizeof(struct csum)); if (osblock.fs_size >= sblock.fs_size) - errx(1, "not enough new space"); + errx(3, "not enough new space"); DBG_PRINT0("sblock calculated\n"); @@ -1591,11 +1591,11 @@ main(int argc, char **argv) if (statfsp != NULL && (statfsp->f_flags & MNT_RDONLY) == 0) { error = ioctl(fso, UFSRESUME); if (error != 0) - err(1, "UFSRESUME"); + err(3, "UFSRESUME"); } error = close(fso); if (error != 0) - err(1, "close"); + err(3, "close"); if (statfsp != NULL && (statfsp->f_flags & MNT_RDONLY) != 0 && chkdoreload(statfsp, warn) != 0) exit(9);