Patchwork [v2,6/6] support: Add support_create_temp_fifo

login
register
mail settings
Submitter Adhemerval Zanella Netto
Date Dec. 28, 2018, 1:02 a.m.
Message ID <20181228010255.21406-7-adhemerval.zanella@linaro.org>
Download mbox | patch
Permalink /patch/30876/
State New
Headers show

Comments

Adhemerval Zanella Netto - Dec. 28, 2018, 1:02 a.m.
Checked on x86_64-linux-gnu.

	* support/temp_file.c (support_create_temp_fifo): New function.
	* support/temp_file.h (support_create_temp_fifo): New prototype.
---
 ChangeLog           |  3 +++
 support/temp_file.c | 23 +++++++++++++++++++++++
 support/temp_file.h |  6 ++++++
 3 files changed, 32 insertions(+)
Siddhesh Poyarekar - Dec. 29, 2018, 2:24 a.m.
On 28/12/18 6:32 AM, Adhemerval Zanella wrote:
> Checked on x86_64-linux-gnu.

Please describe why you need this.

Thanks,
Siddhesh
Andreas Schwab - Dec. 29, 2018, 8:55 a.m.
On Dez 27 2018, Adhemerval Zanella <adhemerval.zanella@linaro.org> wrote:

> +/* Create a temporary fifo.  Return the opened file descriptor on
> +   success, or -1 on failure.  Write the file name to *FILENAME if
> +   FILENAME is not NULL.  In this case, the caller is expected to free
> +   *FILENAME.  */
> +int support_create_temp_fifo (const char *name, char **fifoname);

s/FILENAME/FIFONAME/

Andreas.
Florian Weimer - Dec. 29, 2018, 9:41 a.m.
* Adhemerval Zanella:

> +int
> +support_create_temp_fifo (const char *base, char **fifoname)
> +{
> +  char *fname = xasprintf ("%s/%sXXXXXX", test_dir, base);
> +  mktemp (fname);
> +
> +  int fd = mkfifo (fname, 0600);
> +  if (fd == -1)
> +    {
> +      printf ("cannot open temporary fifo '%s': %m\n", fname);
> +      free (fname);
> +      return -1;
> +    }

Ideally, this needs an error check for mktemp and a retry loop,
similar to what mkstemp does internally.
Adhemerval Zanella Netto - Jan. 3, 2019, 5:37 p.m.
On 29/12/2018 00:24, Siddhesh Poyarekar wrote:
> On 28/12/18 6:32 AM, Adhemerval Zanella wrote:
>> Checked on x86_64-linux-gnu.
> 
> Please describe why you need this.
> 
> Thanks,
> Siddhesh

The intention it to use on a new testcase for BZ#12683, and I
think it would be better to actually include it along with 
BZ#12683 fix. It will also allow to rework with changes
proposed by Florian to retry the mkfifo and fix the comment
noted by Andreas.
Siddhesh Poyarekar - Jan. 4, 2019, 4:02 a.m.
On 03/01/19 11:07 PM, Adhemerval Zanella wrote:
> 
> 
> On 29/12/2018 00:24, Siddhesh Poyarekar wrote:
>> On 28/12/18 6:32 AM, Adhemerval Zanella wrote:
>>> Checked on x86_64-linux-gnu.
>>
>> Please describe why you need this.
>>
>> Thanks,
>> Siddhesh
> 
> The intention it to use on a new testcase for BZ#12683, and I
> think it would be better to actually include it along with
> BZ#12683 fix. It will also allow to rework with changes
> proposed by Florian to retry the mkfifo and fix the comment
> noted by Andreas.

Sorry I wasn't clear.  I meant to say that you need to describe it in 
the git commit so that one would know why this change was made.

Siddhesh
Adhemerval Zanella Netto - Jan. 4, 2019, 11:04 a.m.
On 04/01/2019 02:02, Siddhesh Poyarekar wrote:
> On 03/01/19 11:07 PM, Adhemerval Zanella wrote:
>>
>>
>> On 29/12/2018 00:24, Siddhesh Poyarekar wrote:
>>> On 28/12/18 6:32 AM, Adhemerval Zanella wrote:
>>>> Checked on x86_64-linux-gnu.
>>>
>>> Please describe why you need this.
>>>
>>> Thanks,
>>> Siddhesh
>>
>> The intention it to use on a new testcase for BZ#12683, and I
>> think it would be better to actually include it along with
>> BZ#12683 fix. It will also allow to rework with changes
>> proposed by Florian to retry the mkfifo and fix the comment
>> noted by Andreas.
> 
> Sorry I wasn't clear.  I meant to say that you need to describe it in the git commit so that one would know why this change was made.
> 
> Siddhesh
> 

I get than and I think for this specific part I think it is
better to postpone to when I resend BZ#12683 fix itself.
Siddhesh Poyarekar - Jan. 4, 2019, 11:20 a.m.
On 04/01/19 4:34 PM, Adhemerval Zanella wrote:
> I get than and I think for this specific part I think it is
> better to postpone to when I resend BZ#12683 fix itself.

Great, that sounds like a good plan.

Thanks,
Siddhesh

Patch

diff --git a/support/temp_file.c b/support/temp_file.c
index 0bbc7f9972..362ef171cc 100644
--- a/support/temp_file.c
+++ b/support/temp_file.c
@@ -86,6 +86,29 @@  create_temp_file (const char *base, char **filename)
   return fd;
 }
 
+int
+support_create_temp_fifo (const char *base, char **fifoname)
+{
+  char *fname = xasprintf ("%s/%sXXXXXX", test_dir, base);
+  mktemp (fname);
+
+  int fd = mkfifo (fname, 0600);
+  if (fd == -1)
+    {
+      printf ("cannot open temporary fifo '%s': %m\n", fname);
+      free (fname);
+      return -1;
+    }
+
+  add_temp_file (fname);
+  if (fifoname != NULL)
+    *fifoname = fname;
+  else
+    free (fname);
+
+  return fd;
+}
+
 char *
 support_create_temp_directory (const char *base)
 {
diff --git a/support/temp_file.h b/support/temp_file.h
index c7795cc577..081b241b68 100644
--- a/support/temp_file.h
+++ b/support/temp_file.h
@@ -32,6 +32,12 @@  void add_temp_file (const char *name);
    *FILENAME.  */
 int create_temp_file (const char *base, char **filename);
 
+/* Create a temporary fifo.  Return the opened file descriptor on
+   success, or -1 on failure.  Write the file name to *FILENAME if
+   FILENAME is not NULL.  In this case, the caller is expected to free
+   *FILENAME.  */
+int support_create_temp_fifo (const char *name, char **fifoname);
+
 /* Create a temporary directory and schedule it for deletion.  BASE is
    used as a prefix for the unique directory name, which the function
    returns.  The caller should free this string.  */