On Wednesday, 22 March 2017 17:31:41 CET Richard W.M. Jones wrote:
On Wed, Mar 22, 2017 at 05:16:34PM +0100, Pino Toscano wrote:
> Check for a "product.id" file in an architecture-specific subdirectory
> of the main partition, and use its data to improve the data on the
> media.
>
> Only Mageia as distribution name is recognized there, since most
> probably this file will not be available on other distros.
> ---
> lib/inspect-fs-cd.c | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 76 insertions(+)
>
> diff --git a/lib/inspect-fs-cd.c b/lib/inspect-fs-cd.c
> index 278386e..9c809b4 100644
> --- a/lib/inspect-fs-cd.c
> +++ b/lib/inspect-fs-cd.c
> @@ -21,6 +21,8 @@
> #include <stdio.h>
> #include <stdlib.h>
> #include <string.h>
> +#include <libintl.h>
> +#include <inttypes.h>
>
> #ifdef HAVE_ENDIAN_H
> #include <endian.h>
> @@ -432,10 +434,72 @@ check_w2k3_installer_root (guestfs_h *g, struct inspect_fs
*fs,
> return 0;
> }
>
> +/* Read the data from a product.id-like file.
> + *
> + * This is an old file, mostly used in Mandriva-based systems (still including
> + * Mageia). A very minimal documentation for it is:
> + * -
https://wiki.mageia.org/en/Product_id
> + * -
http://wiki.mandriva.com/en/Product_id (old URL, defunct)
> + */
> +static int
> +check_product_id_installer_root (guestfs_h *g, struct inspect_fs *fs,
> + const char *filename)
> +{
> + int64_t size;
> + CLEANUP_FREE_STRING_LIST char **lines = NULL;
> + const char *elem;
> + char *saveptr;
> +
> + fs->type = OS_TYPE_LINUX;
> +
> + /* Don't trust guestfs_head_n not to break with very large files.
> + * Check the file size is something reasonable first.
> + */
> + size = guestfs_filesize (g, filename);
> + if (size == -1)
> + /* guestfs_filesize failed and has already set error in handle */
> + return -1;
> + if (size > MAX_SMALL_FILE_SIZE) {
> + error (g, _("size of %s is unreasonably large (%" PRIi64 "
bytes)"),
> + filename, size);
> + return -1;
> + }
> +
> + lines = guestfs_head_n (g, 1, filename);
> + if (lines == NULL)
> + return -1;
Could the above code be replaced by a call to
guestfs_int_first_line_of_file ?
Indeed, good catch -- thanks!
> + elem = strtok_r (lines[0], ",", &saveptr);
You can probably use strtok here [I think?] if it's simpler.
I'd maybe if this was in the daemon, which runs single-threaded.
OTOH, using a non-reentrant strtok in the library might cause conflicts
with multithreaded applications using libguestfs.
Thanks,
--
Pino Toscano