From owner-svn-src-all@freebsd.org Mon Jun 29 22:12:24 2020 Return-Path: Delivered-To: svn-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 1104C356F61; Mon, 29 Jun 2020 22:12:24 +0000 (UTC) (envelope-from asomers@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 "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 49whYg6fPVz4WKJ; Mon, 29 Jun 2020 22:12:23 +0000 (UTC) (envelope-from asomers@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id C862CE802; Mon, 29 Jun 2020 22:12:23 +0000 (UTC) (envelope-from asomers@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 05TMCNU8058761; Mon, 29 Jun 2020 22:12:23 GMT (envelope-from asomers@FreeBSD.org) Received: (from asomers@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 05TMCNYx058759; Mon, 29 Jun 2020 22:12:23 GMT (envelope-from asomers@FreeBSD.org) Message-Id: <202006292212.05TMCNYx058759@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: asomers set sender to asomers@FreeBSD.org using -f From: Alan Somers Date: Mon, 29 Jun 2020 22:12:23 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r362790 - in head: sbin/savecore share/man/man5 X-SVN-Group: head X-SVN-Commit-Author: asomers X-SVN-Commit-Paths: in head: sbin/savecore share/man/man5 X-SVN-Commit-Revision: 362790 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 29 Jun 2020 22:12:24 -0000 Author: asomers Date: Mon Jun 29 22:12:23 2020 New Revision: 362790 URL: https://svnweb.freebsd.org/changeset/base/362790 Log: savecore: accept device names without the /dev/ prefix dumpon has accepted device names without the prefix ever since r291207. Since dumpon and savecore are always paired, they ought to accept the same arguments. Prior to this change, specifying 'dumpdev="da3"' in /etc/rc.conf, for example, would result in dumpon working just fine but savecore complaining that "Dump device does not exist". PR: 247618 Reviewed by: cem, bcr MFC after: 2 weeks Sponsored by: Axcient Differential Revision: https://reviews.freebsd.org/D25500 Modified: head/sbin/savecore/savecore.c head/share/man/man5/rc.conf.5 Modified: head/sbin/savecore/savecore.c ============================================================================== --- head/sbin/savecore/savecore.c Mon Jun 29 21:35:50 2020 (r362789) +++ head/sbin/savecore/savecore.c Mon Jun 29 22:12:23 2020 (r362790) @@ -973,7 +973,45 @@ closefd: close(fddev); } +/* Prepend "/dev/" to any arguments that don't already have it */ static char ** +devify(int argc, char **argv) +{ + char **devs; + int i, l; + + devs = malloc(argc * sizeof(*argv)); + if (devs == NULL) { + logmsg(LOG_ERR, "malloc(): %m"); + exit(1); + } + for (i = 0; i < argc; i++) { + if (strncmp(argv[i], _PATH_DEV, sizeof(_PATH_DEV) - 1) == 0) + devs[i] = strdup(argv[i]); + else { + char *fullpath; + + fullpath = malloc(PATH_MAX); + if (fullpath == NULL) { + logmsg(LOG_ERR, "malloc(): %m"); + exit(1); + } + l = snprintf(fullpath, PATH_MAX, "%s%s", _PATH_DEV, + argv[i]); + if (l < 0) { + logmsg(LOG_ERR, "snprintf(): %m"); + exit(1); + } else if (l >= PATH_MAX) { + logmsg(LOG_ERR, "device name too long"); + exit(1); + } + devs[i] = fullpath; + } + } + return (devs); +} + +static char ** enum_dumpdevs(int *argcp) { struct fstab *fsp; @@ -1069,6 +1107,7 @@ main(int argc, char **argv) { cap_rights_t rights; const char *savedir; + char **devs; int i, ch, error, savedirfd; checkfor = compress = clear = force = keep = verbose = 0; @@ -1132,7 +1171,9 @@ main(int argc, char **argv) argv++; } if (argc == 0) - argv = enum_dumpdevs(&argc); + devs = enum_dumpdevs(&argc); + else + devs = devify(argc, argv); savedirfd = open(savedir, O_RDONLY | O_DIRECTORY); if (savedirfd < 0) { @@ -1148,10 +1189,10 @@ main(int argc, char **argv) } /* Enter capability mode. */ - init_caps(argc, argv); + init_caps(argc, devs); for (i = 0; i < argc; i++) - DoFile(savedir, savedirfd, argv[i]); + DoFile(savedir, savedirfd, devs[i]); /* Emit minimal output. */ if (nfound == 0) { Modified: head/share/man/man5/rc.conf.5 ============================================================================== --- head/share/man/man5/rc.conf.5 Mon Jun 29 21:35:50 2020 (r362789) +++ head/share/man/man5/rc.conf.5 Mon Jun 29 22:12:23 2020 (r362790) @@ -24,7 +24,7 @@ .\" .\" $FreeBSD$ .\" -.Dd June 23, 2020 +.Dd June 28, 2020 .Dt RC.CONF 5 .Os .Sh NAME @@ -3469,7 +3469,9 @@ the first suitable swap device listed in .Pa /etc/fstab will be used as dump device. Otherwise, the value of this variable is passed as the argument to -.Xr dumpon 8 . +.Xr dumpon 8 +and +.Xr savecore 8 . To disable crash dumps, set this variable to .Dq Li NO . .It Va dumpon_flags