Modified datadir_cleanup so that it calls nftw to walk the directory tree and remove files and directories it meets.
This commit is contained in:
@ -37,7 +37,8 @@
|
|||||||
*
|
*
|
||||||
* @endverbatim
|
* @endverbatim
|
||||||
*/
|
*/
|
||||||
|
#define _XOPEN_SOURCE 500
|
||||||
|
#include <ftw.h>
|
||||||
#include <gw.h>
|
#include <gw.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <service.h>
|
#include <service.h>
|
||||||
@ -109,7 +110,7 @@ static void libmysqld_done(void);
|
|||||||
static bool file_write_header(FILE* outfile);
|
static bool file_write_header(FILE* outfile);
|
||||||
static bool file_write_footer(FILE* outfile);
|
static bool file_write_footer(FILE* outfile);
|
||||||
static void write_footer(void);
|
static void write_footer(void);
|
||||||
|
static int ntfw_cb(const char*, const struct stat*, int, struct FTW*);
|
||||||
/**
|
/**
|
||||||
* Handler for SIGHUP signal. Reload the configuration for the
|
* Handler for SIGHUP signal. Reload the configuration for the
|
||||||
* gateway.
|
* gateway.
|
||||||
@ -191,18 +192,41 @@ static int signal_set (int sig, void (*handler)(int)) {
|
|||||||
/**
|
/**
|
||||||
* Cleanup the temporary data directory we created for the gateway
|
* Cleanup the temporary data directory we created for the gateway
|
||||||
*/
|
*/
|
||||||
void
|
int ntfw_cb(
|
||||||
datadir_cleanup()
|
const char* filename,
|
||||||
|
const struct stat* filestat,
|
||||||
|
int fileflags,
|
||||||
|
struct FTW* pfwt)
|
||||||
{
|
{
|
||||||
char buf[1024];
|
int rc = remove(filename);
|
||||||
|
|
||||||
if (datadir[0] && access(datadir, F_OK) == 0)
|
if (rc != 0)
|
||||||
{
|
{
|
||||||
sprintf(buf, "rm -rf %s", datadir);
|
int eno = errno;
|
||||||
system(buf);
|
errno = 0;
|
||||||
|
|
||||||
|
skygw_log_write(
|
||||||
|
LOGFILE_ERROR,
|
||||||
|
"Error : Failed to remove the data directory %s of "
|
||||||
|
"MaxScale due to %d, %s.",
|
||||||
|
datadir,
|
||||||
|
eno,
|
||||||
|
strerror(eno));
|
||||||
}
|
}
|
||||||
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void datadir_cleanup()
|
||||||
|
{
|
||||||
|
int depth = 1;
|
||||||
|
int flags = FTW_CHDIR|FTW_DEPTH|FTW_MOUNT;
|
||||||
|
int rc;
|
||||||
|
|
||||||
|
if (datadir[0] != 0 && access(datadir, F_OK) == 0)
|
||||||
|
{
|
||||||
|
rc = nftw(datadir, ntfw_cb, depth, flags);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void libmysqld_done(void)
|
static void libmysqld_done(void)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user