Matteo Cafasso
2016-Mar-29 19:56 UTC
[Libguestfs] [PATCH] renamed daemon/tsk.c to daemon/sleuthkit.c
In order to support the new features I am renaming the file with a better name. The file sleuthkit.c will contain the code depending on the sleuthkit package. The original tsk.c file will contain the logic built using libtsk which is the sleuthkit core library. This patch is ready for review. Code available at: https://github.com/noxdafox/libguestfs/tree/sleuthkit_rename Signed-off-by: Matteo Cafasso <noxdafox@gmail.com> --- daemon/Makefile.am | 2 +- daemon/sleuthkit.c | 114 +++++++++++++++++++++++++++++++++++++++++++++++++++++ daemon/tsk.c | 114 ----------------------------------------------------- 3 files changed, 115 insertions(+), 115 deletions(-) create mode 100644 daemon/sleuthkit.c delete mode 100644 daemon/tsk.c diff --git a/daemon/Makefile.am b/daemon/Makefile.am index 4e2051b..beb7962 100644 --- a/daemon/Makefile.am +++ b/daemon/Makefile.am @@ -171,6 +171,7 @@ guestfsd_SOURCES = \ sfdisk.c \ sh.c \ sleep.c \ + sleuthkit.c \ stat.c \ statvfs.c \ strings.c \ @@ -179,7 +180,6 @@ guestfsd_SOURCES = \ syslinux.c \ tar.c \ truncate.c \ - tsk.c \ umask.c \ upload.c \ utimens.c \ diff --git a/daemon/sleuthkit.c b/daemon/sleuthkit.c new file mode 100644 index 0000000..0fe1250 --- /dev/null +++ b/daemon/sleuthkit.c @@ -0,0 +1,114 @@ +/* libguestfs - the guestfsd daemon + * Copyright (C) 2016 Red Hat Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include <config.h> + +#include <stdio.h> +#include <stdlib.h> +#include <inttypes.h> +#include <string.h> +#include <unistd.h> + +#include "guestfs_protocol.h" +#include "daemon.h" +#include "actions.h" +#include "optgroups.h" + +static int file_out (const char *cmd); + +GUESTFSD_EXT_CMD(str_sleuthkit_probe, icat); + +int +optgroup_sleuthkit_available (void) +{ + return prog_exists (str_sleuthkit_probe); +} + +int +do_icat (const mountable_t *mountable, int64_t inode) +{ + CLEANUP_FREE char *cmd = NULL; + + /* Inode must be greater than 0 */ + if (inode < 0) { + reply_with_error ("inode must be >= 0"); + return -1; + } + + /* Construct the command. */ + if (asprintf (&cmd, "icat -r %s %" PRIi64, mountable->device, inode) == -1) { + reply_with_perror ("asprintf"); + return -1; + } + + return file_out (cmd); +} + +static int +file_out (const char *cmd) +{ + int r; + FILE *fp; + CLEANUP_FREE char *buffer = NULL; + + if (verbose) + fprintf (stderr, "%s\n", cmd); + + buffer = malloc (GUESTFS_MAX_CHUNK_SIZE); + if (buffer == NULL) { + reply_with_perror ("malloc"); + return -1; + } + + fp = popen (cmd, "r"); + if (fp == NULL) { + reply_with_perror ("%s", cmd); + return -1; + } + + /* Now we must send the reply message, before the file contents. After + * this there is no opportunity in the protocol to send any error + * message back. Instead we can only cancel the transfer. + */ + reply (NULL, NULL); + + while ((r = fread (buffer, 1, sizeof buffer, fp)) > 0) { + if (send_file_write (buffer, r) < 0) { + pclose (fp); + return -1; + } + } + + if (ferror (fp)) { + fprintf (stderr, "fread: %m"); + send_file_end (1); /* Cancel. */ + pclose (fp); + return -1; + } + + if (pclose (fp) != 0) { + fprintf (stderr, "pclose: %m"); + send_file_end (1); /* Cancel. */ + return -1; + } + + if (send_file_end (0)) /* Normal end of file. */ + return -1; + + return 0; +} diff --git a/daemon/tsk.c b/daemon/tsk.c deleted file mode 100644 index 0fe1250..0000000 --- a/daemon/tsk.c +++ /dev/null @@ -1,114 +0,0 @@ -/* libguestfs - the guestfsd daemon - * Copyright (C) 2016 Red Hat Inc. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#include <config.h> - -#include <stdio.h> -#include <stdlib.h> -#include <inttypes.h> -#include <string.h> -#include <unistd.h> - -#include "guestfs_protocol.h" -#include "daemon.h" -#include "actions.h" -#include "optgroups.h" - -static int file_out (const char *cmd); - -GUESTFSD_EXT_CMD(str_sleuthkit_probe, icat); - -int -optgroup_sleuthkit_available (void) -{ - return prog_exists (str_sleuthkit_probe); -} - -int -do_icat (const mountable_t *mountable, int64_t inode) -{ - CLEANUP_FREE char *cmd = NULL; - - /* Inode must be greater than 0 */ - if (inode < 0) { - reply_with_error ("inode must be >= 0"); - return -1; - } - - /* Construct the command. */ - if (asprintf (&cmd, "icat -r %s %" PRIi64, mountable->device, inode) == -1) { - reply_with_perror ("asprintf"); - return -1; - } - - return file_out (cmd); -} - -static int -file_out (const char *cmd) -{ - int r; - FILE *fp; - CLEANUP_FREE char *buffer = NULL; - - if (verbose) - fprintf (stderr, "%s\n", cmd); - - buffer = malloc (GUESTFS_MAX_CHUNK_SIZE); - if (buffer == NULL) { - reply_with_perror ("malloc"); - return -1; - } - - fp = popen (cmd, "r"); - if (fp == NULL) { - reply_with_perror ("%s", cmd); - return -1; - } - - /* Now we must send the reply message, before the file contents. After - * this there is no opportunity in the protocol to send any error - * message back. Instead we can only cancel the transfer. - */ - reply (NULL, NULL); - - while ((r = fread (buffer, 1, sizeof buffer, fp)) > 0) { - if (send_file_write (buffer, r) < 0) { - pclose (fp); - return -1; - } - } - - if (ferror (fp)) { - fprintf (stderr, "fread: %m"); - send_file_end (1); /* Cancel. */ - pclose (fp); - return -1; - } - - if (pclose (fp) != 0) { - fprintf (stderr, "pclose: %m"); - send_file_end (1); /* Cancel. */ - return -1; - } - - if (send_file_end (0)) /* Normal end of file. */ - return -1; - - return 0; -} -- 2.8.0.rc3
Pino Toscano
2016-Mar-30 11:05 UTC
Re: [Libguestfs] [PATCH] renamed daemon/tsk.c to daemon/sleuthkit.c
On Tuesday 29 March 2016 22:56:29 Matteo Cafasso wrote:> In order to support the new features I am renaming the file with a better name. > > The file sleuthkit.c will contain the code depending on the sleuthkit package. > > The original tsk.c file will contain the logic built using libtsk > which is the sleuthkit core library.Makes sense, pushed to git with two small changes:> This patch is ready for review. > Code available at: > > https://github.com/noxdafox/libguestfs/tree/sleuthkit_rename(a) this part of the commit message is not needed (b) updated po/POTFILES with the file rename Thanks, -- Pino Toscano
Richard W.M. Jones
2016-Mar-30 15:16 UTC
Re: [Libguestfs] [PATCH] renamed daemon/tsk.c to daemon/sleuthkit.c
On Wed, Mar 30, 2016 at 01:05:50PM +0200, Pino Toscano wrote:> On Tuesday 29 March 2016 22:56:29 Matteo Cafasso wrote: > > In order to support the new features I am renaming the file with a better name. > > > > The file sleuthkit.c will contain the code depending on the sleuthkit package. > > > > The original tsk.c file will contain the logic built using libtsk > > which is the sleuthkit core library. > > Makes sense, pushed to git with two small changes: > > > This patch is ready for review. > > Code available at: > > > > https://github.com/noxdafox/libguestfs/tree/sleuthkit_rename > > (a) this part of the commit message is not neededI asked Matteo to create this repo and link to it, since it makes it a bit easier to keep track of the state of his patches. However as you say it shouldn't appear in the commit message (since commit messages are forever), but instead should be in the cover letter. Thanks for reviewing these. Rich.> (b) updated po/POTFILES with the file rename > > Thanks, > -- > Pino Toscano> _______________________________________________ > Libguestfs mailing list > Libguestfs@redhat.com > https://www.redhat.com/mailman/listinfo/libguestfs-- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com libguestfs lets you edit virtual machines. Supports shell scripting, bindings from many languages. http://libguestfs.org