From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from primenet.com.au (ns1.primenet.com.au [203.24.36.2]) by inbox.vuxu.org (OpenSMTPD) with ESMTP id 52f9b7c7 for ; Fri, 29 Mar 2019 15:23:21 +0000 (UTC) Received: (qmail 19619 invoked by alias); 29 Mar 2019 15:23:05 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: List-Unsubscribe: X-Seq: 44197 Received: (qmail 1822 invoked by uid 1010); 29 Mar 2019 15:23:05 -0000 X-Qmail-Scanner-Diagnostics: from heimdall.zentaur.org by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.101.1/25398. spamassassin: 3.4.2. Clear:RC:0(45.56.127.49):SA:0(-2.0/5.0):. Processed in 4.631 secs); 29 Mar 2019 15:23:05 -0000 X-Envelope-From: cdb_zsh@zentaur.org X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: pass (ns1.primenet.com.au: SPF record at zentaur.org designates 45.56.127.49 as permitted sender) DKIM-Filter: OpenDKIM Filter v2.11.0 heimdall.zentaur.org x2TFMEc0026957 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=zentaur.org; s=default; t=1553872940; bh=e+fjqksq+MVc62i74KgGzBUI07yYg4bIC6izFo3b2mo=; h=Subject:To:References:From:Date:In-Reply-To:From; b=mcOG1oeC+IqWc5hrULEaLPY76hWg1wDsLwggcWPbpeJ8/U/D+XJPHgMExGRzQOVu8 FtJc7GJbzjQypr2Jg3NxVBRTkCs7Y8pGXk6LcymmDno5iQLTHex4lzqrVbYKRFJapD n5FV+w7BM04wEDpEhHOMXL8M/6C+thv5XPddY4JU= Subject: Re: [RFC] adding zmktemp command To: Daniel Shahaf , zsh-workers@zsh.org References: <38c2ebfc-f238-4f85-af76-b87c9e7f4531@www.fastmail.com> <45a86a2c-c277-c29e-2c69-06eec33b627a@zentaur.org> <20190328211359.prb6pdpidcgq5xn6@tarpaulin.shahaf.local2> From: Clinton Bunch Message-ID: Date: Fri, 29 Mar 2019 10:20:38 -0500 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: <20190328211359.prb6pdpidcgq5xn6@tarpaulin.shahaf.local2> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US On 3/28/2019 4:13 PM, Daniel Shahaf wrote: > Clinton Bunch wrote on Thu, Mar 28, 2019 at 10:00:24 -0500: >> On 3/28/2019 4:38 AM, Daniel Shahaf wrote: >>> Clinton Bunch wrote on Wed, 27 Mar 2019 21:18 +00:00: >>>> I'm thinking of adding a zmktemp command either in a new module (e.g. >>>> zsh/tempfile) or in the zsh/files module. >>> ... >>>> Thoughts? >>> A few. >>> >>> - I wonder if implementing mktemp in the shell is easier than expecting >>> people to install a third-party mktemp(1) binary with whatever >>> functionality they desire. BSD systems often have both BSD make and >>> GNU make, so it's conceivable that HP-UX systems could have both the >>> native mktemp(1) and a third-party one. >>> (To be clear, I do not object to your RFC; I just wonder if there's a >>> better solution to the underlying problem.) >> That situation is why I proposed this.  On my HP-UX systems I use gnu >> coreutils mktemp, but either I have to order my path so that it's before >> /usr/bin, which can get me non-standard versions of standard commands which >> might affect the script, > You neglected to explain why none of the other possible solutions to > this subproblem is suitable for you. (For starters, there are 'add a > directory to the front of $PATH that contains just GNU mktemp and > nothing else' and 'use the "hash" builtin to specify a different mktemp > than the one in $PATH'.) Didn't think of the hash builtin. > >> or name it something else (which I did, gmktemp). >> Either way this makes for less portable scripts. > So your problem statement is "HP-UX and Linux use incompatible mktemp(1) > binaries". I don't understand why that should be fixed in zsh; > shouldn't that be fixed by getting HP-UX to improve their mktemp? > Compare how there is any number of instances in the FreeBSD man pages of > option flags that have been added for compatibility with coreutils (see > ls(1) and find(1) for example). Fixing the incompatibilities of HP-UX mktemp requires more than adding a few ignored options.  It doesn't make temporary directories and in fact uses -d to specify the directory to create the file.  It doesn't take a template string.  And most importantly doesn't create the temporary file by default (you have to give a -c option to do so).  It also uses the highly predictable HP-UX mktemp(3) to generate the name. > > (By the way: I wonder if mktemp(1) will be added to POSIX?) It should, but who knows if it will. > > As to your proposal itself, I initially thought you were proposing to > implement a drop-in replacement of some mktemp(1) out there (probably > GNU's, though for license reasons it'd be easier to crib BSD's); > however, reading your responses to Peter and Oliver I see that you might > be thinking of adding an *idiomatic* make-temporary-files interface, > e.g., one that returns an fd and/or returns the filename in REPLY to > save a fork. Which is it? Could you sketch the API that will be > provided to script authors? Is it "see GNU coreutils' mktemp(1) man > page, plus the -f option to return an fd"? I'm thinking of something that *could* be used as a drop-in replacement for mktemp (from the online man pages I can find, other than HP-UX, the other *nix with mktemp accept the same short options as GNU), but I want to make it better (that seems to be the zsh way :) The -f var option mentioned elsewhere to return the opened file descriptor. a -i (invisible) that will unlink the file as soon as it's opened.  (Not sure what the use case for this is, but there must be one as both stdio's tempfile and perl's File::Temp (as an option) offer this functionality) a -E to erase the file on exit (if I can figure out how to use the exit hook) a -e to clear the FD_CLOEXEC on the file descriptor so external programs could inherit the open file descriptor (perhaps useful on those systems with /dev/fd or with other specially written programs) > >> That also requires that >> the script writer have access to install packages or the wherewithal to >> build these packages and install them in their home directory themselves. > By this argument, we should ship an rsync implementation in zsh if HP-UX > doesn't happen to ship rsync in part of its (HP-UX's) default installation. I suppose that argument could be made, but opening temp files is a much more common use case than rsync.  To be honest I've used temp files in scripts a lot more often than some of the other builtins in zsh/files like chgrp or chown > >>> - O_EXCL is exposed by zsh/system's 'sysopen' builtin, so a pure zsh >>> implementation should be possible. >> I didn't think about a pure zsh implementation, but modifying the template >> character by character in zsh sounds like at least as much work as it is in >> C, but slower. > Given that there's going to be a syscall at the end anyway [open(O_EXCL)], > I'm not sure if the overhead of zsh over pure C would be noticeable. > > I mentioned a pure zsh implementation because it could be implemented as > an autoloaded function and released as a plugin (rather than a module), > so it would be installable by users who don't or can't compile their own > zsh, and it would even be compatible with existing zsh binaries out > there. That wouldn't allow the -i option or the -e mentioned above. > Cheers, > > Daniel