diff mbox series

[v2,6/6] support: Add support_create_temp_fifo

Message ID 20181228010255.21406-7-adhemerval.zanella@linaro.org
State New
Headers show
Series General fixes and refactor for BZ#12683 | expand

Commit Message

Adhemerval Zanella Dec. 28, 2018, 1:02 a.m. UTC
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(+)

-- 
2.17.1

Comments

Siddhesh Poyarekar Dec. 29, 2018, 2:24 a.m. UTC | #1
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. UTC | #2
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.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."
Florian Weimer Dec. 29, 2018, 9:41 a.m. UTC | #3
* 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 Jan. 3, 2019, 5:37 p.m. UTC | #4
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. UTC | #5
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 Jan. 4, 2019, 11:04 a.m. UTC | #6
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. UTC | #7
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
diff mbox series

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.  */