From nobody Sun Feb 27 01:47:08 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 CAB3F19EDBD9; Sun, 27 Feb 2022 01:47:08 +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 4K5mbJ4b1Qz3pCB; Sun, 27 Feb 2022 01:47:08 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1645926428; 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=VfIQlm46xU532tv/dU9nOQTK8T2sdims5Kc6OV/IwM8=; b=MPlH29TG/mcx5Q+V0znhGkum3yIifWwCkbWcc2R8In5TCTdh4e9HI/IlwuiLDsARlkQ8R/ 1Q3fvdDCtnH+J+Mj1+brH3GiHh55HbMttg1Lkt69NyGzCPsi68r8ZNvCjwEFJcwVktwQGN N62ZA+Ka90KiZBFDlZaBP3kA7EfWIxEExCiCQ0cExOYdss5n0aOYkxc8CaCE5MOXCP0m5p T7YV5SEEKsrLZVJFraEULnAoYVQUkF3KVD7IyE1yaImuVu13bN0qBk9prnc19IGYOJIOhj KOU15oDa1GyPPbIsBLS2XuOHbLPqIWfME+/GxGS9iu4u4mIGQsPTrBolonvIrQ== 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 7DF711E6E1; Sun, 27 Feb 2022 01:47:08 +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 21R1l8nT031179; Sun, 27 Feb 2022 01:47:08 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 21R1l8Rk031178; Sun, 27 Feb 2022 01:47:08 GMT (envelope-from git) Date: Sun, 27 Feb 2022 01:47:08 GMT Message-Id: <202202270147.21R1l8Rk031178@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Jamie Gritton Subject: git: be7cf3f4b8c2 - main - posixshm: Add a -j option to posixshmcontrol ls, to specify a jail PR: 257556 Reported by: grembo@ 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: jamie X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: be7cf3f4b8c2818155f5a4a83c64c9ef6a60a320 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1645926428; 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=VfIQlm46xU532tv/dU9nOQTK8T2sdims5Kc6OV/IwM8=; b=iX/8eTybzH3CzI5bR+FnS80ZiiMGdx6shH0JXyN1WjIaIi1wmlkTz6GWnvaWABruTRGZnX G8sb+wGLpKiROcUay2r70Jrf+W2VHWaBfH1rfiwV8Lof1y3OuRjXJ8tJrfvW1zvx5NHSEg ZDa5jcHN2Kahkd8NJuFHVU1sBpr4ed7JJ/TSreII12+0nzkSpq8CXIMfFsfQO/MT0frGxi NaPD92yDlzzms+xoxcgdrG32XHuLPtEZNUtuoURABGFrowyEL7nNF1kMyCfur2OBSBxZQh P1PCE3oOTgAjPwoHp3jpqn5M0PvkT95Ay4Jd+UkRLUtspXTVEG6j96oJqxl8ZA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1645926428; a=rsa-sha256; cv=none; b=dTiT6yX2EJdBjsa9wk0bPZCQWiaBI9slyiqGLnsF5AG7RXgVFInuR1/XtsvsjN3S+gw5rS +ituEa5sk/wulAsPXmDaLX+ll0E9zehpTjzlQo95/hMl2HJGAakf1vpKEQ7Ecvw3o0bFnH VdlnMWopGiJxhCdiP2SC5U1l5EPWTQk7FYLo1QSPX1tS0ZUH/nPATgsh3lTeCu2xpsCkvP bAZeXl55Q8xpmcaQ5sy9vvK44JaSPAQd9ozF0ZD0Rgo3V+D7HQuV6mzMv3PP88iJyjZtJC dHEM6yIrvF+PrcpSXhx+Y8fou8YFPLtfYY3RUgYDxL3Bmgy3nTVRuqqw984hhQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by jamie: URL: https://cgit.FreeBSD.org/src/commit/?id=be7cf3f4b8c2818155f5a4a83c64c9ef6a60a320 commit be7cf3f4b8c2818155f5a4a83c64c9ef6a60a320 Author: Jamie Gritton AuthorDate: 2022-02-27 01:45:28 +0000 Commit: Jamie Gritton CommitDate: 2022-02-27 01:45:28 +0000 posixshm: Add a -j option to posixshmcontrol ls, to specify a jail PR: 257556 Reported by: grembo@ --- usr.bin/posixshmcontrol/Makefile | 2 +- usr.bin/posixshmcontrol/posixshmcontrol.1 | 8 ++++++- usr.bin/posixshmcontrol/posixshmcontrol.c | 39 ++++++++++++++++++++++++++----- 3 files changed, 41 insertions(+), 8 deletions(-) diff --git a/usr.bin/posixshmcontrol/Makefile b/usr.bin/posixshmcontrol/Makefile index c6f847e18478..e5e9588df7bb 100644 --- a/usr.bin/posixshmcontrol/Makefile +++ b/usr.bin/posixshmcontrol/Makefile @@ -1,6 +1,6 @@ # $FreeBSD$ PROG= posixshmcontrol -LIBADD= util +LIBADD= jail util .include diff --git a/usr.bin/posixshmcontrol/posixshmcontrol.1 b/usr.bin/posixshmcontrol/posixshmcontrol.1 index f6743b070b50..1d8c3438b165 100644 --- a/usr.bin/posixshmcontrol/posixshmcontrol.1 +++ b/usr.bin/posixshmcontrol/posixshmcontrol.1 @@ -27,7 +27,7 @@ .\" .\" $FreeBSD$ .\" -.Dd March 18, 2020 +.Dd February 26, 2022 .Dt POSIXSHMCONTROL 1 .Os .Sh NAME @@ -45,6 +45,7 @@ .Ar ls .Op Fl h .Op Fl n +.Op Fl j Ar jail .Nm .Ar dump .Op Pa path \&... @@ -87,6 +88,11 @@ Unlink the paths specified. .It Ic ls List all linked named shared memory segments visible to the caller. For each segment, the user and group owner, size, and path are displayed. +The +.Fl j +option limits the output to segments within the specified +.Ar jail +name or id. .It Ic dump Output raw bytes values from the segment to standard output. .It Ic stat diff --git a/usr.bin/posixshmcontrol/posixshmcontrol.c b/usr.bin/posixshmcontrol/posixshmcontrol.c index 47a19b78a9d2..f64fcd3dd663 100644 --- a/usr.bin/posixshmcontrol/posixshmcontrol.c +++ b/usr.bin/posixshmcontrol/posixshmcontrol.c @@ -39,6 +39,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -54,7 +55,7 @@ usage(void) fprintf(stderr, "Usage:\n" "posixshmcontrol create [-m ] [-l ] ...\n" "posixshmcontrol rm ...\n" - "posixshmcontrol ls [-h] [-n]\n" + "posixshmcontrol ls [-h] [-n] [-j jail]\n" "posixshmcontrol dump ...\n" "posixshmcontrol stat [-h] [-n] ...\n" "posixshmcontrol truncate [-s ] ...\n"); @@ -221,17 +222,19 @@ shm_decode_mode(mode_t m, char *str) static int list_shm(int argc, char **argv) { - char *buf, *bp, sizebuf[8], str[10]; + char *buf, *bp, *ep, jailpath[MAXPATHLEN], sizebuf[8], str[10]; + const char *jailparam; const struct kinfo_file *kif; struct stat st; - int c, error, fd, mib[3], ret; - size_t len, miblen; - bool hsize, uname; + int c, error, fd, jid, mib[3], ret; + size_t len, jailpathlen, miblen; + bool hsize, jailed, uname; hsize = false; + jailed = false; uname = true; - while ((c = getopt(argc, argv, "hn")) != -1) { + while ((c = getopt(argc, argv, "hj:n")) != -1) { switch (c) { case 'h': hsize = true; @@ -239,6 +242,28 @@ list_shm(int argc, char **argv) case 'n': uname = false; break; + case 'j': + jid = strtoul(optarg, &ep, 10); + if (ep > optarg && !*ep) { + jailparam = "jid"; + jailed = jid > 0; + } else { + jailparam = "name"; + jailed = true; + } + if (jailed) { + if (jail_getv(0, jailparam, optarg, "path", + jailpath, NULL) < 0) { + if (errno == ENOENT) + warnx("no such jail: %s", optarg); + else + warnx("%s", jail_errmsg); + return (1); + } + jailpathlen = strlen(jailpath); + jailpath[jailpathlen] = '/'; + } + break; default: usage(); return (2); @@ -279,6 +304,8 @@ list_shm(int argc, char **argv) kif = (const struct kinfo_file *)(void *)bp; if (kif->kf_structsize == 0) break; + if (jailed && strncmp(kif->kf_path, jailpath, jailpathlen + 1)) + continue; fd = shm_open(kif->kf_path, O_RDONLY, 0); if (fd == -1) { warn("open %s", kif->kf_path);