9front - general discussion about 9front
 help / color / mirror / Atom feed
From: Benjamin Riefenstahl <b.riefenstahl@turtle-trading.net>
To: 9front@9front.org
Subject: [9front] ape/mkstemp: Fix flags
Date: Tue, 04 Jan 2022 20:45:25 +0100	[thread overview]
Message-ID: <8735m34756.fsf@turtle-trading.net> (raw)

[-- Attachment #1: Type: text/plain, Size: 323 bytes --]

Tcl tries to use mkstemp() but the current implementation in APE does
not allow reading from the file.  This sets the flags to open() as
documented in various man pages.

Other implementations also check errno==EEXIST after failure, to break
the loop earlier.  But that is probably overkill for that rare error
condition.


[-- Attachment #2.1: Type: text/plain, Size: 296 bytes --]

from postmaster@4ess:
The following attachment had content that we can't
prove to be harmless.  To avoid possible automatic
execution, we changed the content headers.
The original header was:

	Content-Type: text/x-diff
	Content-Disposition: inline; filename=0001-ape-mkstemp-better-options.patch

[-- Attachment #2.2: 0001-ape-mkstemp-better-options.patch.suspect --]
[-- Type: application/octet-stream, Size: 902 bytes --]

From: Benjamin Riefenstahl <b.riefenstahl@turtle-trading.net>
Date: Fri, 10 Dec 2021 20:44:26 +0000
Subject: [PATCH] ape/mkstemp: better options


Use O_EXCL and make the file descriptor writeable.  This is more
usefull and it conforms to Single Unix and other specs.
---
diff 3568e27ec8774a212564c8d2bf6b3d9a19d4d571 9a027a77a0d407d542dbb49be398a474b10deb2b
--- a/sys/src/ape/lib/ap/gen/mkstemp.c	Tue Jan  4 01:19:36 2022
+++ b/sys/src/ape/lib/ap/gen/mkstemp.c	Fri Dec 10 21:44:26 2021
@@ -1,6 +1,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
+#include <fcntl.h>
 
 int
 mkstemp(char *template)
@@ -14,7 +15,7 @@
    for(i=0; i<20; i++){
        strcpy(s, template);
        mktemp(s);
-       if((fd = creat(s, 0666)) >= 0){
+       if((fd = open(s, O_RDWR | O_CREAT | O_EXCL, 0600)) >= 0){
            strcpy(template, s);
            free(s);
            return fd;

-- 
1.0


             reply	other threads:[~2022-01-04 22:31 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-04 19:45 Benjamin Riefenstahl [this message]
2022-01-06 16:13 ` ori
2022-01-06 16:44   ` Benjamin Riefenstahl

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8735m34756.fsf@turtle-trading.net \
    --to=b.riefenstahl@turtle-trading.net \
    --cc=9front@9front.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).