This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [patch] compile: rm -rf -> ftw()+rmdir()+unlink() [Re: [patch] compile: Fix MinGW build]
- From: Sergio Durigan Junior <sergiodj at redhat dot com>
- To: Jan Kratochvil <jan dot kratochvil at redhat dot com>
- Cc: Kai Tietz <ktietz at redhat dot com>, Steve Ellcey <sellcey at imgtec dot com>, Eli Zaretskii <eliz at gnu dot org>, brobecker at adacore dot com, yao at codesourcery dot com, gdb-patches at sourceware dot org
- Date: Thu, 18 Dec 2014 15:56:26 -0500
- Subject: Re: [patch] compile: rm -rf -> ftw()+rmdir()+unlink() [Re: [patch] compile: Fix MinGW build]
- Authentication-results: sourceware.org; auth=none
- References: <20141217210144 dot GA26674 at host2 dot jankratochvil dot net>
On Wednesday, December 17 2014, Jan Kratochvil wrote:
> On Wed, 17 Dec 2014 18:29:51 +0100, Steve Ellcey wrote:
>> /scratch/sellcey/repos/nightly2/src/binutils-gdb/gdb/compile/compile.c:175:10: error: ignoring return value of 'system', declared with attribute warn_unused_result [-Werror=unused-result]
>> cc1: all warnings being treated as errors
>> make[1]: *** [compile.o] Error 1
>
> It should get fixed by this patch.
https://sourceware.org/bugzilla/show_bug.cgi?id=17718 has been fixed
about this as well, FYI.
> I have briefly tested (on Linux; on MinGW I have only tested the build) it
> really does delete the directory and its files.
>
> OK for check-in?
>
>
> Thanks,
> Jan
> gdb/ChangeLog
> 2014-12-17 Jan Kratochvil <jan.kratochvil@redhat.com>
>
> * compile/compile.c: Include ftw.h.
> (do_rmdir_fn): New function.
> (do_rmdir): Call nftw with it.
>
> diff --git a/gdb/compile/compile.c b/gdb/compile/compile.c
> index 414fc35..7dbc819 100644
> --- a/gdb/compile/compile.c
> +++ b/gdb/compile/compile.c
> @@ -37,6 +37,7 @@
> #include "filestuff.h"
> #include "target.h"
> #include "osabi.h"
> +#include <ftw.h>
>
>
>
> @@ -162,17 +163,42 @@ compile_code_command (char *arg, int from_tty)
> do_cleanups (cleanup);
> }
>
> +/* Helper for do_rmdir. */
> +
> +static int
> +do_rmdir_fn (const char *fpath, const struct stat *sb, int typeflag,
> + struct FTW *ftwbuf)
> +{
> + switch (typeflag)
> + {
> + case FTW_DP:
> + if (rmdir (fpath) != 0)
> + warning (_("Cannot remove 'compile' command directory \"%s\": %s"),
> + fpath, safe_strerror (errno));
> + break;
> + case FTW_F:
> + if (unlink (fpath) != 0)
> + warning (_("Cannot remove 'compile' command file \"%s\": %s"),
> + fpath, safe_strerror (errno));
> + break;
> + default:
> + warning (_("Unknown 'typeflag' %d for 'compile' command file \"%s\"."),
> + typeflag, fpath);
> + }
> +
> + /* Continue the walk. */
> + return 0;
> +}
> +
> /* A cleanup function to remove a directory and all its contents. */
>
> static void
> do_rmdir (void *arg)
> {
> const char *dir = arg;
> - char *zap;
> -
> +
> gdb_assert (strncmp (dir, TMP_PREFIX, strlen (TMP_PREFIX)) == 0);
> - zap = concat ("rm -rf ", dir, (char *) NULL);
> - system (zap);
> + nftw (dir, do_rmdir_fn, 10, FTW_DEPTH | FTW_MOUNT | FTW_PHYS);
> }
>
> /* Return the name of the temporary directory to use for .o files, and
--
Sergio
GPG key ID: 0x65FC5E36
Please send encrypted e-mail if possible
http://sergiodj.net/