Message ID | 20181228010255.21406-7-adhemerval.zanella@linaro.org |
---|---|
State | New |
Headers | show |
Series | General fixes and refactor for BZ#12683 | expand |
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. -- 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."
* 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
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. */