9front - general discussion about 9front
 help / color / mirror / Atom feed
* [9front] ape/mkstemp: Fix flags
@ 2022-01-04 19:45 Benjamin Riefenstahl
  2022-01-06 16:13 ` ori
  0 siblings, 1 reply; 3+ messages in thread
From: Benjamin Riefenstahl @ 2022-01-04 19:45 UTC (permalink / raw)
  To: 9front

[-- 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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [9front] ape/mkstemp: Fix flags
  2022-01-04 19:45 [9front] ape/mkstemp: Fix flags Benjamin Riefenstahl
@ 2022-01-06 16:13 ` ori
  2022-01-06 16:44   ` Benjamin Riefenstahl
  0 siblings, 1 reply; 3+ messages in thread
From: ori @ 2022-01-06 16:13 UTC (permalink / raw)
  To: 9front

Quoth Benjamin Riefenstahl <b.riefenstahl@turtle-trading.net>:
> 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.

that looks good to me: applied.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [9front] ape/mkstemp: Fix flags
  2022-01-06 16:13 ` ori
@ 2022-01-06 16:44   ` Benjamin Riefenstahl
  0 siblings, 0 replies; 3+ messages in thread
From: Benjamin Riefenstahl @ 2022-01-06 16:44 UTC (permalink / raw)
  To: ori; +Cc: 9front

Hi ori,

ori writes:
> that looks good to me: applied.

Thank you, benny

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-01-06 16:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-04 19:45 [9front] ape/mkstemp: Fix flags Benjamin Riefenstahl
2022-01-06 16:13 ` ori
2022-01-06 16:44   ` Benjamin Riefenstahl

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).