[2019-11-02 20:03] Clint Adams <cl...@debian.org>
> > FTBFS on macOS systems, because of undefined O_TMPFILE,
> > which was introduced in 4.9 release.
> > 
> > Attempt to build was made here: 
> > https://github.com/Homebrew/homebrew-core/pull/46107
>
> Dmitry, any thoughts?  Maybe disabling --stdin on systems without O_TMPFILE?

Maybe it would better to provide emulation? This patch illustrates my
idea, but is /not/ tested:

+#ifdef O_TMPFILE
+static int open_tmpfile_rw(void)
+{
+       const char *tmpdir;
+
+       tmpdir = getenv("TMPDIR");
+       if (!tmpdir) {
+               tmpdir = "/tmp";
+       }
+
+       return open(tmpdir, O_TMPFILE|O_RDWR|O_EXCL, S_IRUSR | S_IWUSR);
+}
+#else
+static char tmpfile_path[] = "/tmp/run-parts.stdin.XXXXXX";
+static int cleanup_tmpfile(void)
+{
+       unlink(tmpfile_path);
+}
+
+static int open_tmpfile_rw(void)
+{
+       int fd;
+
+       fd = mkstemp(tmpfile_path);
+       if (fd != -1) {
+               atexit(&cleanup_tmpfile);
+       }
+       return fd;
+}
+#endif
+
+
 /*
  * Copy stdin into temporary read-write file, and return file descriptor to it.
  */
@@ -396,15 +429,7 @@ static int copy_stdin(void)
   char buffer[4096];
   ssize_t bytes;
 
-  tmpdir = getenv("TMPDIR");
-  if (!tmpdir) {
-    tmpdir = "/tmp";
-  };
-
-  fd = open(tmpdir, O_TMPFILE|O_RDWR|O_EXCL, S_IRUSR | S_IWUSR);
-  if (fd < 0) {
-    return -1;
-  };
+  fd = open_tmpfile_rw();
 
   do {
     ssize_t rest;
-- 
Note, that I send and fetch email in batch, once in a few days.
Please, mention in body of your reply when you add or remove recepients.

Reply via email to