[v2,6/6] support: Add support_create_temp_fifo
Commit Message
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(+)
Comments
On 28/12/18 6:32 AM, Adhemerval Zanella wrote:
> Checked on x86_64-linux-gnu.
Please describe why you need this.
Thanks,
Siddhesh
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.
* 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.
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.
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
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.
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
@@ -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)
{
@@ -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. */