search for: memstream

Displaying 20 results from an estimated 28 matches for "memstream".

2020 Oct 06
2
[PATCH libnbd] info: Write output atomically.
...int64_t size; const char *protocol; int tls_negotiated; + char *output = NULL; + size_t output_len = 0; progname = argv[0]; @@ -207,6 +210,17 @@ main (int argc, char *argv[]) if (map) probe_content = false; + /* Try to write output atomically. We spool output into a + * memstream, pointed to by fp, and write it all at once at the end. + * On error nothing should be printed on stdout. + */ + fp = open_memstream (&output, &output_len); + if (fp == NULL) { + fprintf (stderr, "%s: ", progname); + perror ("open_memstream"); + exit (EXIT...
2020 Oct 06
0
Re: [PATCH libnbd] info: Write output atomically.
...plete output > or the error message. > --- > info/Makefile.am | 1 + > info/info-atomic-output.sh | 32 ++++++ > info/nbdinfo.c | 194 ++++++++++++++++++++++--------------- > 3 files changed, 147 insertions(+), 80 deletions(-) ACK. Mostly mechanical, and memstreams make this nice. > +++ b/info/info-atomic-output.sh > @@ -0,0 +1,32 @@ > +. ../tests/functions.sh > + > +set -e > +set -x > + > +requires nbdkit --version > +requires nbdkit eval --version You could simplify this: if the second line passes, the first line is implied,...
2020 Apr 09
0
[PATCH nbdkit v2 2/3] iso: Implement this plugin using fileops (read-only).
...e); return -1; } @@ -103,7 +105,7 @@ make_iso (void) shell_quote (dirs[i], fp); } /* Redirect output to the temporary file. */ - fprintf (fp, " >&%d", fd); + fprintf (fp, " >&%d", iso_fd); if (fclose (fp) == EOF) { nbdkit_error ("memstream failed: %m"); @@ -128,8 +130,8 @@ iso_unload (void) free (dirs[i]); free (dirs); - if (fd >= 0) - close (fd); + if (iso_fd >= 0) + close (iso_fd); } static int @@ -193,25 +195,43 @@ iso_get_ready (void) static void * iso_open (int readonly) { - return NBDKIT_HAN...
2020 Jul 06
2
Re: [PATCH nbdkit 2/2] tar: Rewrite the tar plugin (again), this time in C.
...exportname=on option) > + > +static int > +tar_get_ready (void) > +{ > + FILE *fp; > + CLEANUP_FREE char *cmd = NULL; > + size_t len = 0; > + bool scanned_ok; > + char s[256]; > + > + /* Construct the tar command to examine the tar file. */ > + fp = open_memstream (&cmd, &len); > + if (fp == NULL) { > + nbdkit_error ("open_memstream: %m"); > + return -1; > + } > + fprintf (fp, "LANG=C tar --no-auto-compress -tRvf "); Use of --no-auto-compress is specific to GNU tar, do we care? Should we allow a 'tar=...
2020 Jul 06
0
Re: [PATCH nbdkit 2/2] tar: Rewrite the tar plugin (again), this time in C.
...tic int > >+tar_get_ready (void) > >+{ > >+ FILE *fp; > >+ CLEANUP_FREE char *cmd = NULL; > >+ size_t len = 0; > >+ bool scanned_ok; > >+ char s[256]; > >+ > >+ /* Construct the tar command to examine the tar file. */ > >+ fp = open_memstream (&cmd, &len); > >+ if (fp == NULL) { > >+ nbdkit_error ("open_memstream: %m"); > >+ return -1; > >+ } > >+ fprintf (fp, "LANG=C tar --no-auto-compress -tRvf "); > > Use of --no-auto-compress is specific to GNU tar, do we care...
2020 Jul 14
3
[PATCH nbdkit RFC 0/2] curl: Implement authorization scripts.
This is an RFC only, at the very least it lacks tests. This implements a rather complex new feature in nbdkit-curl-plugin allowing you to specify an external shell script that can be used to fetch an authorization token for services which requires a token or cookie for access, especially if that token must be renewed periodically. The motivation can be seen in the changes to the docs in patch 2.
2020 Mar 17
0
Re: [PATCH nbdkit v2] New tmpdisk plugin.
...t; + return size; > +} > + > +/* This creates and runs the full "mkfs" (or whatever) command. */ > +static int > +run_command (const char *disk) > +{ > + FILE *fp; > + CLEANUP_FREE char *cmd = NULL; > + size_t len = 0; > + int r; > + > + fp = open_memstream (&cmd, &len); > + if (fp == NULL) { > + nbdkit_error ("open_memstream: %m"); > + return -1; > + } > + > + /* Set the shell variables. */ > + fprintf (fp, "disk="); > + shell_quote (disk, fp); [1]...here you are correctly quoting the de...
2020 Jul 15
0
[PATCH nbdkit v2] curl: Implement header and cookie scripts.
.../* Create a temporary file for the errors so we can redirect them + * into nbdkit_error. + */ + fd = mkstemp (tmpfile); + if (fd == -1) { + nbdkit_error ("mkstemp"); + return -1; + } + close (fd); + + /* Generate the full script with the local $url variable. */ + fp = open_memstream (&cmd, &len); + if (fp == NULL) { + nbdkit_error ("open_memstream: %m"); + return -1; + } + fprintf (fp, "exec </dev/null\n"); /* Avoid stdin leaking (nbdkit -s). */ + fprintf (fp, "exec 2>%s\n", tmpfile); /* Catch errors to a temporary file....
2020 Mar 17
2
[PATCH nbdkit v2] New tmpdisk plugin.
...TIVE; +} + +static int64_t +tmpdisk_get_size (void *handle) +{ + return size; +} + +/* This creates and runs the full "mkfs" (or whatever) command. */ +static int +run_command (const char *disk) +{ + FILE *fp; + CLEANUP_FREE char *cmd = NULL; + size_t len = 0; + int r; + + fp = open_memstream (&cmd, &len); + if (fp == NULL) { + nbdkit_error ("open_memstream: %m"); + return -1; + } + + /* Set the shell variables. */ + fprintf (fp, "disk="); + shell_quote (disk, fp); + putc ('\n', fp); + if (label) { + fprintf (fp, "label="); +...
2020 Jun 28
5
[PATCH nbdkit 0/2] tar: Rewrite the tar plugin (again), this time in C.
For context see these threads: https://lists.gnu.org/archive/html/qemu-discuss/2020-06/threads.html#00053 https://lists.gnu.org/archive/html/qemu-block/2020-06/threads.html#01496 Rich.
2020 Jun 28
2
Re: [PATCH nbdkit 2/2] tar: Rewrite the tar plugin (again), this time in C.
...dhat.com> wrote: ... > + > +static int > +tar_get_ready (void) > +{ > + FILE *fp; > + CLEANUP_FREE char *cmd = NULL; > + size_t len = 0; > + bool scanned_ok; > + char s[256]; > + > + /* Construct the tar command to examine the tar file. */ > + fp = open_memstream (&cmd, &len); > + if (fp == NULL) { > + nbdkit_error ("open_memstream: %m"); > + return -1; > + } > + fprintf (fp, "LANG=C tar --no-auto-compress -tRvf "); Using -R is nice, but is block size documented? Also --block-number would be nicer. >...
2020 Jul 15
2
[PATCH nbdkit v2] curl: Implement header and cookie scripts.
Evolution of this patch series: https://www.redhat.com/archives/libguestfs/2020-July/thread.html#00073 Instead of auth-script, this implements header-script and cookie-script. It can be used for similar purposes but the implementation is somewhat saner. Rich.
2020 Mar 16
1
[PATCH nbdkit] New tmpdisk plugin.
Unfinished (needs tests). This is my attempt to make a "remote tmpfs" plugin as outlined in this prior email: https://www.redhat.com/archives/libguestfs/2020-March/msg00134.html Although it would be possible to construct something a bit like this using existing plugins and filters (perhaps with some new features in those filters) I think it may be nicer to have a dedicated plugin for
2019 Feb 22
0
[PATCH nbdkit v3 4/4] Add linuxdisk plugin.
...ir1 + * 34567 dir2 + * 46912 total + * + * We ignore everything except the first number on the last line. + */ +static int64_t +estimate_size (void) +{ + char *command = NULL, *line = NULL; + size_t len = 0; + FILE *fp; + int64_t ret; + int r; + + /* Create the du command. */ + fp = open_memstream (&command, &len); + if (fp == NULL) { + nbdkit_error ("open_memstream: %m"); + return -1; + } + fprintf (fp, "du -c -k -s "); + shell_quote (dir, fp); + if (fclose (fp) == EOF) { + nbdkit_error ("memstream failed: %m"); + return -1; + } + + /...
2020 Jul 14
0
[PATCH nbdkit RFC 2/2] curl: Implement authorization scripts.
.../* Create a temporary file for the errors so we can redirect them + * into nbdkit_error. + */ + fd = mkstemp (tmpfile); + if (fd == -1) { + nbdkit_error ("mkstemp"); + return -1; + } + close (fd); + + /* Generate the full script with the local $url variable. */ + fp = open_memstream (&cmd, &len); + if (fp == NULL) { + nbdkit_error ("open_memstream: %m"); + return -1; + } + fprintf (fp, "exec </dev/null\n"); /* Avoid stdin leaking (nbdkit -s). */ + fprintf (fp, "exec 2>%s\n", tmpfile); /* Catch errors to a temporary file....
2020 Jun 28
0
[PATCH nbdkit 2/2] tar: Rewrite the tar plugin (again), this time in C.
...;file=<FILENAME> The path inside the tar file to server." + +static int +tar_get_ready (void) +{ + FILE *fp; + CLEANUP_FREE char *cmd = NULL; + size_t len = 0; + bool scanned_ok; + char s[256]; + + /* Construct the tar command to examine the tar file. */ + fp = open_memstream (&cmd, &len); + if (fp == NULL) { + nbdkit_error ("open_memstream: %m"); + return -1; + } + fprintf (fp, "LANG=C tar --no-auto-compress -tRvf "); + shell_quote (tarfile, fp); + fputc (' ', fp); + shell_quote (file, fp); + if (fclose (fp) == EOF) { +...
2020 Jul 07
0
[PATCH nbdkit] New filter: tar.
...false; + + assert (entry); + + /* Temporary file to capture the output from the tar command. */ + fd = mkstemp (output); + if (fd == -1) { + nbdkit_error ("mkstemp: %m"); + return -1; + } + close (fd); + + /* Construct the tar command to examine the tar file. */ + fp = open_memstream (&cmd, &cmdlen); + if (fp == NULL) { + nbdkit_error ("open_memstream: %m"); + return -1; + } + fprintf (fp, "LANG=C tar --no-auto-compress -tRvf - "); + shell_quote (entry, fp); + fprintf (fp, " > "); + shell_quote (output, fp); + if (fclose (fp...
2020 Mar 17
2
[PATCH nbdkit v3] New tmpdisk plugin.
v2 was here: https://www.redhat.com/archives/libguestfs/2020-March/msg00154.html v3: - Micro-optimize tmpdir. - Quote $disk in default command shell fragment. - Don't redirect mkfs output to /dev/null. Instead use exec </dev/null >/dev/null before the shell fragment. We may want to do this in other places where we run external shell scripts, or more generally for all
2020 Jul 07
3
[PATCH nbdkit] tar as a filter.
For review only, this needs some clean up and more tests. My eyes are going cross-eyed looking at the calculate_offset_of_entry function, so time to take a break ... Rich.
2019 Feb 19
0
[PATCH nbdkit 4/4] Add linuxdisk plugin.
...+ * 34567 dir2 + * 46912 total + * + * We ignore everything except the first number on the last line. + */ +static int64_t +estimate_size (void) +{ + char *command = NULL, *line = NULL; + size_t len = 0; + FILE *fp; + size_t i; + int64_t ret; + + /* Create the du command. */ + fp = open_memstream (&command, &len); + if (fp == NULL) { + nbdkit_error ("open_memstream: %m"); + return -1; + } + fprintf (fp, "du -c -k -s"); + for (i = 0; i < nr_dirs; ++i) { + fputc (' ', fp); + shell_quote (dirs[i], fp); + } + if (fclose (fp) == EOF) { +...