Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lUkCF-0005Yr-He for pgsql-hackers@arkaria.postgresql.org; Fri, 09 Apr 2021 06:00:47 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lUkCC-0007Ni-2N for pgsql-hackers@arkaria.postgresql.org; Fri, 09 Apr 2021 06:00:44 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lUkCB-0007Na-QN for pgsql-hackers@lists.postgresql.org; Fri, 09 Apr 2021 06:00:43 +0000 Received: from wout4-smtp.messagingengine.com ([64.147.123.20]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lUkC9-0005RF-BD for pgsql-hackers@lists.postgresql.org; Fri, 09 Apr 2021 06:00:43 +0000 Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.west.internal (Postfix) with ESMTP id B012415C3; Fri, 9 Apr 2021 02:00:37 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Fri, 09 Apr 2021 02:00:38 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paquier.xyz; h= date:from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=fm1; bh=WxiCiZPWi0wp9r7ZDFsqA4oPhx0 EDNih1VF5TtllqdY=; b=I9pkrkMl7vBQf/dhl2c/nisaQfEQV/PfFUHLS/C1kla WEhxFek9r+cXtivg6BE9PC2LV50qp8i/QzfuKQ/iuzLIBVLGAdVRxil7eD8jNyFz K6FZTuGRnAnLIeYISVN8VwKk5arrGda4/701Jec/UJnEpeoc4nxVHLmtlC5E0vPk bBG9DiFuZUeUupCQyO5bT/dGKG3RecsdLS/He/0k4fGln9oa0Rg1I60db/izAQnr NgFmdk4Fq/iBAmMHvc2qg97vXMqShrBgs8J7jHI8jv5bpY+DPsLc08Xo1GnbK9pU 1pIaqeoPnbt92KQBAed46nwvcgVbGsgGHl26lgZYsGA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; bh=WxiCiZ PWi0wp9r7ZDFsqA4oPhx0EDNih1VF5TtllqdY=; b=pu9bFSIkw1t9ddw02f+XIp d8bi8FWOivpBoZY6IqmBey1GoNQKyv2ZHiIQorh6ZgXbyivOmVlAKpoTOj3ftWmL 9EoI4W6QqY4EQ9sn/uHkCh8c8/QGZwJbypHd6w9Gz5eLZ8K/ycWLH3Ej9aX5izIm 0tGjg0pPw1t4zuEznmWE1We1PrTSQqQYKKUrbl7JD2qgOmc/xtsjE7zWITTjPikb sUCcoxdxOEBpsYnc/frizow+oB1OdS/KVVs5iWYojCdbIsvUEOtPNfnzcIZ2zA4D Vq7fq5dg3rFXO4GJbZyalOEpIOEpjGHhMXNec6/4KHUA7uky4z6PjGnXH8lAVKZA == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrudektddguddtudcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enfghrlhcuvffnffculdejtddmnecujfgurhepfffhvffukfhfgggtuggjsehgtderredt tddvnecuhfhrohhmpefoihgthhgrvghlucfrrghquhhivghruceomhhitghhrggvlhesph grqhhuihgvrhdrgiihiieqnecuggftrfgrthhtvghrnhepvdegudeuhfdtueeltedtveej heehieevueeigeelteegleejleeiueeiheegvefhnecukfhppeduuddurddutddvrdduke dtrddukeehnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhho mhepmhhitghhrggvlhesphgrqhhuihgvrhdrgiihii X-ME-Proxy: Received: from paquier.xyz (ee0822lan1.rev.em-net.ne.jp [111.102.180.185]) by mail.messagingengine.com (Postfix) with ESMTPA id 5C79B24005E; Fri, 9 Apr 2021 02:00:35 -0400 (EDT) Date: Fri, 9 Apr 2021 15:00:31 +0900 From: Michael Paquier To: Noah Misch Cc: Robert Haas , Christoph Berg , PostgreSQL Hackers Subject: Re: pgsql: Move tablespace path re-creation from the makefiles to pg_regres Message-ID: References: <20210325025659.GA4017435@rfd.leadboat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="nbd65AywjMAyoKsx" Content-Disposition: inline In-Reply-To: <20210325025659.GA4017435@rfd.leadboat.com> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --nbd65AywjMAyoKsx Content-Type: multipart/mixed; boundary="CmSGset7HBxds4Zx" Content-Disposition: inline --CmSGset7HBxds4Zx Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Mar 24, 2021 at 07:56:59PM -0700, Noah Misch wrote: > That would entail forbidding various shell metacharacters in @testtablesp= ace@. > One could avoid imposing such a restriction by adding a mkdir() function = to > regress.c and writing it like: >=20 > CREATE FUNCTION mkdir(text) > RETURNS void AS '@libdir@/regress@DLSUFFIX@', 'regress_mkdir' > LANGUAGE C STRICT\; > REVOKE ALL ON FUNCTION mkdir FROM public; > SELECT mkdir('@testtablespace@'); > CREATE TABLESPACE regress_tblspace LOCATION '@testtablespace@'; Sounds simple. >> I doubt that all the Windows environments would be able to get their >> hands on that. >=20 >> And I am not sure either that this would work when it >> comes to the CI case, again on Windows. >=20 > How might a CI provider break that? I am wondering about potential issues when it comes to create the base tablespace path from the Postgres backend, while HEAD does it while relying on a restricted token obtained when starting pg_regress. I have compiled a simple patch that uses a SQL function for the base tablespace directory creation, that I have tested on Linux and MSVC. To get some coverage with the CF bot, I am adding a CF entry with this thread. I am still not sure if people would prefer this approach over what's on HEAD. So if there are any opinions, please feel free. -- Michael --CmSGset7HBxds4Zx Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="regress-mkdir.patch" Content-Transfer-Encoding: quoted-printable diff --git a/src/test/regress/input/tablespace.source b/src/test/regress/in= put/tablespace.source index c133e73499..0c1a9929c2 100644 --- a/src/test/regress/input/tablespace.source +++ b/src/test/regress/input/tablespace.source @@ -1,3 +1,10 @@ +-- Create the tablespace path. +CREATE FUNCTION mkdir(text) + RETURNS void AS '@libdir@/regress@DLSUFFIX@', 'regress_mkdir' + LANGUAGE C STRICT; +SELECT mkdir('@testtablespace@'); +DROP FUNCTION mkdir(text); + -- create a tablespace using WITH clause CREATE TABLESPACE regress_tblspacewith LOCATION '@testtablespace@' WITH (s= ome_nonexistent_parameter =3D true); -- fail CREATE TABLESPACE regress_tblspacewith LOCATION '@testtablespace@' WITH (r= andom_page_cost =3D 3.0); -- ok diff --git a/src/test/regress/output/tablespace.source b/src/test/regress/o= utput/tablespace.source index 1bbe7e0323..ea07211d1a 100644 --- a/src/test/regress/output/tablespace.source +++ b/src/test/regress/output/tablespace.source @@ -1,3 +1,14 @@ +-- Create the tablespace path. +CREATE FUNCTION mkdir(text) + RETURNS void AS '@libdir@/regress@DLSUFFIX@', 'regress_mkdir' + LANGUAGE C STRICT; +SELECT mkdir('@testtablespace@'); + mkdir=20 +------- +=20 +(1 row) + +DROP FUNCTION mkdir(text); -- create a tablespace using WITH clause CREATE TABLESPACE regress_tblspacewith LOCATION '@testtablespace@' WITH (s= ome_nonexistent_parameter =3D true); -- fail ERROR: unrecognized parameter "some_nonexistent_parameter" diff --git a/src/test/regress/pg_regress.c b/src/test/regress/pg_regress.c index b7d80bd9bb..dbb2e8bea7 100644 --- a/src/test/regress/pg_regress.c +++ b/src/test/regress/pg_regress.c @@ -506,23 +506,6 @@ convert_sourcefiles_in(const char *source_subdir, cons= t char *dest_dir, const ch =20 snprintf(testtablespace, MAXPGPATH, "%s/testtablespace", outputdir); =20 - /* - * Clean out the test tablespace dir, or create it if it doesn't exist. On - * Windows, doing this cleanup here makes possible to run the regression - * tests as a Windows administrative user account with the restricted - * token obtained when starting pg_regress. - */ - if (directory_exists(testtablespace)) - { - if (!rmtree(testtablespace, true)) - { - fprintf(stderr, _("\n%s: could not remove test tablespace \"%s\"\n"), - progname, testtablespace); - exit(2); - } - } - make_directory(testtablespace); - /* finally loop on each file and do the replacement */ for (name =3D names; *name; name++) { diff --git a/src/test/regress/regress.c b/src/test/regress/regress.c index 1990cbb6a1..a884b5ed71 100644 --- a/src/test/regress/regress.c +++ b/src/test/regress/regress.c @@ -18,6 +18,7 @@ =20 #include #include +#include =20 #include "access/detoast.h" #include "access/htup_details.h" @@ -80,6 +81,43 @@ static void regress_lseg_construct(LSEG *lseg, Point *pt= 1, Point *pt2); =20 PG_MODULE_MAGIC; =20 +static bool +directory_exists(const char *dir) +{ + struct stat st; + + if (stat(dir, &st) !=3D 0) + return false; + if (S_ISDIR(st.st_mode)) + return true; + return false; +} + +/* + * Create a new directory for the tests, to be used for tablespaces. + * If this directory exists, clean up its contents and create it again + * from scratch. + */ +PG_FUNCTION_INFO_V1(regress_mkdir); + +Datum +regress_mkdir(PG_FUNCTION_ARGS) +{ + char *dir =3D text_to_cstring(PG_GETARG_TEXT_PP(0)); + + if (!superuser()) + elog(ERROR, "must be superuser to create paths"); + + if (directory_exists(dir)) + { + if (!rmtree(dir, true)) + elog(ERROR, "could not remove path \"%s\"\n", dir); + } + if (mkdir(dir, S_IRWXU | S_IRWXG | S_IRWXO) < 0) + elog(ERROR, "could not create directory \"%s\": %m", dir); + + PG_RETURN_VOID(); +} =20 /* return the point where two paths intersect, or NULL if no intersection.= */ PG_FUNCTION_INFO_V1(interpt_pp); --CmSGset7HBxds4Zx-- --nbd65AywjMAyoKsx Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAmBv7X8ACgkQnvQgOdby QH0heBAAl5HKPsLAtzMV08xCPmC5fvQmTmn0zbskhkFJdBg/IdySUENI5CWKUPBw dqZmvlhQCMmbMk/Q4CNb9OTyKM1k/9v3WkeI7ZGiKT2FMZWE6moeUf6Wazza2/iL hpfSca+mtTMF1j/Ty+oincFLR7w2DWBvPdhNkMqthpQHSSnVNjwf89/FNTkn0vY+ w7jIpuM9XqpVL1kB8wd3+JMPNKAKckJIqtu9njS4/1r9EogX59y2Y63wC6+u6wGG M1AHfj4gycYVXOhVebCbG9C+Lz+iZUejhF2zfGqx5TmwVzUC6NDC6Vv5Wtb4vgDO NHqH+zSPYSY0ncZtCWMDt6jWsVlZK/o+X5+o2btXG0QKWiMWbU4OAo1bSUaxiKnB 9/38dMuQj61dw/NSUYtrcp8JFTLbQLnIljOfo9N0trekeJCYItS3+AUMzxc6CC9i /3x/atx7j0yve12riMwdTiXQG9SbSHsucZTXGYDXa2tHpFTZXfg1Uc16rA6MUEfR EPlh/rpV/LwaxepeM8X3UzfDEpsTTFgMLYQAB8pyVtWcDnEEM1vG43AOvcL6Y6Lg x55QrqxdRGCKNsx8k0y2NOm17d76RF3iXOk/wbjPfgecmBTH7Yeb4keINECzXTBX lGXpQaf+47K9WjtvrT8pc9+qVv96rQvpCfKEsK0B19Yzklmqu9M= =qD++ -----END PGP SIGNATURE----- --nbd65AywjMAyoKsx--