From: Francois Marier Date: Sun, 1 Nov 2009 18:39:58 +0000 (+0100) Subject: Detect and report permission failure for "ccache -F/-M" X-Git-Tag: v3.0pre0~183 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9786fdf1d22a17e4c1cc314759ec8e840aecc3b2;p=thirdparty%2Fccache.git Detect and report permission failure for "ccache -F/-M" Debian patch 12_cachesize_permissions.diff. See . --- diff --git a/ccache.c b/ccache.c index 2bafb9731..e2552163f 100644 --- a/ccache.c +++ b/ccache.c @@ -1051,15 +1051,23 @@ static int ccache_main(int argc, char *argv[]) case 'F': check_cache_dir(); v = atoi(optarg); - stats_set_limits(v, -1); - printf("Set cache file limit to %u\n", (unsigned)v); + if (stats_set_limits(v, -1) == 0) { + printf("Set cache file limit to %u\n", (unsigned)v); + } else { + printf("Could not set cache file limit.\n"); + exit(1); + } break; case 'M': check_cache_dir(); v = value_units(optarg); - stats_set_limits(-1, v); - printf("Set cache size limit to %uk\n", (unsigned)v); + if (stats_set_limits(-1, v) == 0) { + printf("Set cache size limit to %uk\n", (unsigned)v); + } else { + printf("Could not set cache size limit.\n"); + exit(1); + } break; default: diff --git a/ccache.h b/ccache.h index 2ce9cb3a6..9e6f2213b 100644 --- a/ccache.h +++ b/ccache.h @@ -118,7 +118,7 @@ void stats_zero(void); void stats_summary(void); void stats_tocache(size_t size); void stats_read(const char *stats_file, unsigned counters[STATS_END]); -void stats_set_limits(long maxfiles, long maxsize); +int stats_set_limits(long maxfiles, long maxsize); size_t value_units(const char *s); void display_size(unsigned v); void stats_set_sizes(const char *dir, size_t num_files, size_t total_size); diff --git a/stats.c b/stats.c index e5662fb26..ddaf768db 100644 --- a/stats.c +++ b/stats.c @@ -286,7 +286,7 @@ void stats_zero(void) /* set the per directory limits */ -void stats_set_limits(long maxfiles, long maxsize) +int stats_set_limits(long maxfiles, long maxsize) { int dir; unsigned counters[STATS_END]; @@ -298,7 +298,9 @@ void stats_set_limits(long maxfiles, long maxsize) maxsize /= 16; } - create_dir(cache_dir); + if (create_dir(cache_dir) != 0) { + return 1; + } /* set the limits in each directory */ for (dir=0;dir<=0xF;dir++) { @@ -306,7 +308,9 @@ void stats_set_limits(long maxfiles, long maxsize) int fd; x_asprintf(&cdir, "%s/%1x", cache_dir, dir); - create_dir(cdir); + if (create_dir(cdir) != 0) { + return 1; + } x_asprintf(&fname, "%s/stats", cdir); free(cdir); @@ -326,6 +330,8 @@ void stats_set_limits(long maxfiles, long maxsize) } free(fname); } + + return 0; } /* set the per directory sizes */