Message ID | 20170928110910.29088-1-christian.storm@siemens.com |
---|---|
State | Accepted |
Headers | show |
Series | core: unlink temp directories on normal termination | expand |
On 28/09/2017 13:09, Christian Storm wrote: > Remove the temporary directories > $TMPDIR/SCRIPTS_DIR_SUFFIX and > $TMPDIR/DATADST_DIR_SUFFIX > on normal program termination. > > Signed-off-by: Christian Storm <christian.storm@siemens.com> > --- > core/swupdate.c | 29 +++++++++++++++++++++++++++++ > 1 file changed, 29 insertions(+) > > diff --git a/core/swupdate.c b/core/swupdate.c > index 52e0a3f..b490871 100644 > --- a/core/swupdate.c > +++ b/core/swupdate.c > @@ -35,6 +35,7 @@ > #include <pthread.h> > #include <signal.h> > #include <sys/wait.h> > +#include <ftw.h> > > #include "bsdqueue.h" > #include "cpiohdr.h" > @@ -406,6 +407,30 @@ static void create_directory(const char* path) { > mkdir(dpath, 0777); > } > > +static int _remove_directory_cb(const char *fpath, const struct stat *sb, > + int typeflag, struct FTW *ftwbuf) > +{ > + (void)sb; > + (void)typeflag; > + (void)ftwbuf; > + return remove(fpath); > +} > + > +static int remove_directory(const char* path) > +{ > + char* dpath = alloca(strlen(get_tmpdir())+strlen(path)+1); > + sprintf(dpath, "%s%s", get_tmpdir(), path); > + return nftw(dpath, _remove_directory_cb, 64, FTW_DEPTH | FTW_PHYS); > +} > + > +static void swupdate_cleanup(void) > +{ > +#ifndef CONFIG_NOCLEANUP > + remove_directory(SCRIPTS_DIR_SUFFIX); > + remove_directory(DATADST_DIR_SUFFIX); > +#endif > +} > + > static void swupdate_init(struct swupdate_cfg *sw) > { > /* Initialize internal tree to store configuration */ > @@ -422,6 +447,10 @@ static void swupdate_init(struct swupdate_cfg *sw) > create_directory(SCRIPTS_DIR_SUFFIX); > create_directory(DATADST_DIR_SUFFIX); > > + if (atexit(swupdate_cleanup) != 0) { > + TRACE("Cannot setup SWUpdate cleanup on exit"); > + } > + > #ifdef CONFIG_MTD > mtd_init(); > ubi_init(); > Applied to -master, thanks ! Best regards, Stefano Babic
diff --git a/core/swupdate.c b/core/swupdate.c index 52e0a3f..b490871 100644 --- a/core/swupdate.c +++ b/core/swupdate.c @@ -35,6 +35,7 @@ #include <pthread.h> #include <signal.h> #include <sys/wait.h> +#include <ftw.h> #include "bsdqueue.h" #include "cpiohdr.h" @@ -406,6 +407,30 @@ static void create_directory(const char* path) { mkdir(dpath, 0777); } +static int _remove_directory_cb(const char *fpath, const struct stat *sb, + int typeflag, struct FTW *ftwbuf) +{ + (void)sb; + (void)typeflag; + (void)ftwbuf; + return remove(fpath); +} + +static int remove_directory(const char* path) +{ + char* dpath = alloca(strlen(get_tmpdir())+strlen(path)+1); + sprintf(dpath, "%s%s", get_tmpdir(), path); + return nftw(dpath, _remove_directory_cb, 64, FTW_DEPTH | FTW_PHYS); +} + +static void swupdate_cleanup(void) +{ +#ifndef CONFIG_NOCLEANUP + remove_directory(SCRIPTS_DIR_SUFFIX); + remove_directory(DATADST_DIR_SUFFIX); +#endif +} + static void swupdate_init(struct swupdate_cfg *sw) { /* Initialize internal tree to store configuration */ @@ -422,6 +447,10 @@ static void swupdate_init(struct swupdate_cfg *sw) create_directory(SCRIPTS_DIR_SUFFIX); create_directory(DATADST_DIR_SUFFIX); + if (atexit(swupdate_cleanup) != 0) { + TRACE("Cannot setup SWUpdate cleanup on exit"); + } + #ifdef CONFIG_MTD mtd_init(); ubi_init();
Remove the temporary directories $TMPDIR/SCRIPTS_DIR_SUFFIX and $TMPDIR/DATADST_DIR_SUFFIX on normal program termination. Signed-off-by: Christian Storm <christian.storm@siemens.com> --- core/swupdate.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+)