From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS22989 209.51.188.0/24 X-Spam-Status: No, score=-3.7 required=3.0 tests=AWL,BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id 477711F63E for ; Mon, 30 Jan 2023 11:48:42 +0000 (UTC) Authentication-Results: dcvr.yhbt.net; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=clisp.org header.i=@clisp.org header.a=rsa-sha256 header.s=strato-dkim-0002 header.b=WpYJP0Qj; dkim-atps=neutral Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pMSe4-0005Vl-0T; Mon, 30 Jan 2023 06:48:20 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pMSe2-0005TJ-He for bug-gnulib@gnu.org; Mon, 30 Jan 2023 06:48:18 -0500 Received: from mo4-p00-ob.smtp.rzone.de ([85.215.255.25]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pMSdz-00045T-SD for bug-gnulib@gnu.org; Mon, 30 Jan 2023 06:48:18 -0500 ARC-Seal: i=1; a=rsa-sha256; t=1675079290; cv=none; d=strato.com; s=strato-dkim-0002; b=YKhUSyKjjaymvdUmQp+a6kCGUD/whAR36Ys/hEONprgB9MZdYkCJjEOvpGZdGTrIVc rWxotnxObDilSwfL9LtYwlROp5k2RgrADPWwRB2UKtZy6+Ia/kqwKmmrmtp9t2OdAsej ZE+EgmkCSo7vp8q+8O6CVxjmv0D9iA+UCWsNasGyoGg2fmCpH6Xwq2Zm8mLsn7gflKy2 FNg0bmITNkd/YqCM3EGu87/Jc3Qkw2Rhuz8/5leeBdbs+PdtOP+JKHBvDnyQCjWT7SLw u1qboULbTvFT/DQhufcp4d2gOrHueDjjSVmgchkmTNnCE/rW9Z50uaYzTLYqpJcxGs67 P9UQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; t=1675079290; s=strato-dkim-0002; d=strato.com; h=References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=TQoq4nz2MBoHKOIEKoaa4sHKi2v+o6STx6efzsLroJY=; b=EA/HzhBjMbkRa993m0caHKSJHwzk3Gy2RCSnAl2d19iRrlQ/87GwZRMXc/isCy7U6t xluh5+LbvS6BSMES+F9G5AV4xxCzl8LUciDjoKuNDJJigndMLOgD6UznX2xSycplCdu6 8yyexmI66qjG6wnjbZdB4/5XJOPmq86iB6/IUyvO92EkpHT9gBRNCaxSZZ/AUFGVekKn TvuvSeapDy6wueykfEvwsstNNNkkVlHExNkkdNW/UdJzkDboFYHupf6/uQECPK5esUMK LMhfCfJjnjqQlqtrSIY36j3Ihrsn9cT6tKt35q0/6JGbxJvE8CjQmKVh1sAOOh5pPzgX qP0Q== ARC-Authentication-Results: i=1; strato.com; arc=none; dkim=none X-RZG-CLASS-ID: mo00 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1675079290; s=strato-dkim-0002; d=clisp.org; h=References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=TQoq4nz2MBoHKOIEKoaa4sHKi2v+o6STx6efzsLroJY=; b=WpYJP0QjlBPyBjdPiS+RVl5Id7+/TrsgALGwMaF1mGqO9JypOgMRhMDu7RT20PF2RU E7vJcpKljLyr914kO+QmcwKkq6hfC3XXiwsweuhSpnBLFxLYzhxIMlfS8LalXn5jILZ3 0EI29Vr97b8kVQMKwkBbRjmdMq9VeI+aDo/FS53dkTZp7dTtqUew8nLtnHWI702NcOf0 IhK89x0ngwR3/2DEPgJUVWtknVyz96C04emrSMM3kE6SorsuhOomijT4XDbfPXrinlJL kPtRRfL9JIrna+tS2B8Ln3qFuUzjOB4PYV19rzK3HikODQx5MSCqbNjvUY94tn6SnYot SeLA== X-RZG-AUTH: ":Ln4Re0+Ic/6oZXR1YgKryK8brlshOcZlIWs+iCP5vnk6shH0WWb0LN8XZoH94zq68+3cfpPF3KZI9ilgtRRA2BFjBWDjzg8H" Received: from nimes.localnet by smtp.strato.de (RZmta 49.2.2 AUTH) with ESMTPSA id 098542z0UBmAT7d (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Mon, 30 Jan 2023 12:48:10 +0100 (CET) From: Bruno Haible To: bug-gnulib@gnu.org, Igor Todorovski Cc: Mike Fulton Subject: Re: Z/OS Enhancement to gnu lib Date: Mon, 30 Jan 2023 12:48:09 +0100 Message-ID: <2103887.quN3GAMpyv@nimes> In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="UTF-8" Received-SPF: none client-ip=85.215.255.25; envelope-from=bruno@clisp.org; helo=mo4-p00-ob.smtp.rzone.de X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: bug-gnulib@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gnulib discussion list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnulib-bounces+normalperson=yhbt.net@gnu.org Sender: bug-gnulib-bounces+normalperson=yhbt.net@gnu.org Hi, > I was wondering if the following changes I made to findutils (to get it t= o function on z/OS) can be merged into gnulib. >=20 > The first change (fdopendir.c) guards the close call. Otherwise we get a = bad file descriptor on z/OS. What's the problem with that "bad file descriptor" error? On POSIX system, EBADF is the natural error code in this situation. If close() on z/OS does not support this situation gracefully, we'll need to override the close() function, like we did on native Windows, see . > I am not sure if this has any other consequences, but so far I haven=E2= =80=99t seen any issues with findutils. If fd is not invalid, it would lead to a file descriptor leak, no? > The second change (openat-proc.c) adds a way to get the pathname when giv= en a file descriptor as an input. Thanks. This looks reasonable. > diff --git a/gl/lib/openat-proc.c b/gl/lib/openat-proc.c > index 3bacf7d..bb788fd 100644 > --- a/gl/lib/openat-proc.c > +++ b/gl/lib/openat-proc.c > @@ -28,6 +28,7 @@ > #include > #include > #include > +#include > #include > #ifdef __KLIBC__ > @@ -53,7 +54,27 @@ openat_proc_name (char buf[OPENAT_BUFFER_SIZE], int fd= , char const *file) > return buf; > } > -#ifndef __KLIBC__ > +#ifdef __MVS__ > + { > + char dir[_XOPEN_PATH_MAX]; > + int rc =3D w_ioctl(fd, _IOCC_GPN, _XOPEN_PATH_MAX, dir); > + if (rc =3D=3D 0) { > + __e2a_l(dir, _XOPEN_PATH_MAX); > + } > + size_t bufsize; > + dirlen =3D strlen (dir); > + bufsize =3D dirlen + 1 + strlen (file) + 1; /* 1 for '/', 1 for null= */ > + if (OPENAT_BUFFER_SIZE < bufsize) > + { > + result =3D malloc (bufsize); > + if (! result) > + return NULL; > + } > + > + strcpy (result, dir); > + result[dirlen++] =3D '/'; > + } > +#elif !defined( __KLIBC__) > # define PROC_SELF_FD_FORMAT "/proc/self/fd/%d/" > { > enum { >=20 There are a number of things that can be improved from this patch: - The include should only be done on platforms that need it, since not all platforms have . - GNU coding style: placement of braces, space between function name and argument list. - Put special cases for special operating systems after the generic/Linux case. Simply as a convenience, so that the reader does not turn away before getting to the main code. - Avoid code duplication of 12 lines of code, if it can easily be avoided. - Use 'sizeof dir' instead of '_XOPEN_PATH_MAX', so that the dimension of that array needs to be stated only once. Useful for future maintenan= ce. I did these improvements. What I then take from your patch is only 3 lines of code. This does not require a copyright assigment from you to the FSF (cf. = ). Therefore I am incorporating this code directly. Btw, do you have reference documentation available for _IOCC_GPN and __e2a_= l? It generally is more advisable to use documented facilities than undocument= ed ones. 2023-01-30 Bruno Haible at-internal: Add support for z/OS. Reported and draft patch by Igor Todorovski . * lib/openat-proc.c [z/OS]: Include . (openat_proc_name): For z/OS, use an approach similar to kLIBC, with 3 lines of z/OS specific code by Igor Todorovski . diff --git a/lib/openat-proc.c b/lib/openat-proc.c index 2a6a85f069..6419a8cf5f 100644 =2D-- a/lib/openat-proc.c +++ b/lib/openat-proc.c @@ -30,9 +30,12 @@ #include #include =20 =2D#ifdef __KLIBC__ +#ifdef __KLIBC__ /* OS/2 */ # include #endif +#ifdef __MVS__ /* z/OS */ +# include +#endif =20 #include "intprops.h" =20 @@ -53,7 +56,8 @@ openat_proc_name (char buf[OPENAT_BUFFER_SIZE], int fd, c= har const *file) return buf; } =20 =2D#ifndef __KLIBC__ +#if !(defined __KLIBC__ || defined __MVS__) + /* Generic code for Linux, Solaris, and similar platforms. */ # define PROC_SELF_FD_FORMAT "/proc/self/fd/%d/" { enum { @@ -107,14 +111,21 @@ openat_proc_name (char buf[OPENAT_BUFFER_SIZE], int f= d, char const *file) dirlen =3D sprintf (result, PROC_SELF_FD_FORMAT, fd); } } =2D#else +#else /* (defined __KLIBC__ || defined __MVS__), i.e. OS/2 or z/OS */ /* OS/2 kLIBC provides a function to retrieve a path from a fd. */ { =2D char dir[_MAX_PATH]; size_t bufsize; =20 +# ifdef __KLIBC__ + char dir[_MAX_PATH]; if (__libc_Back_ioFHToPath (fd, dir, sizeof dir)) return NULL; +# endif +# ifdef __MVS__ + char dir[_XOPEN_PATH_MAX]; + if (w_ioctl (fd, _IOCC_GPN, sizeof dir, dir) =3D=3D 0) + __e2a_l (dir, sizeof dir); +# endif =20 dirlen =3D strlen (dir); bufsize =3D dirlen + 1 + strlen (file) + 1; /* 1 for '/', 1 for null */