" limit; available suffixes: G, M and K; default\n"
" suffix: G)\n"
" -o, --set-option=K=V set configuration option K to V\n"
+" -p, --print-config print current configuration options\n"
" -s, --show-stats show statistics summary\n"
" -z, --zero-stats zero statistics counters\n"
"\n"
failed();
}
+static void
+conf_printer(const char *s, void *context)
+{
+ if (context == NULL) {
+ cc_log("%s\n", s);
+ } else {
+ fprintf(context, "%s\n", s);
+ }
+}
+
/* the main program when not doing a compile */
static int
ccache_main_options(int argc, char *argv[])
{"max-files", required_argument, 0, 'F'},
{"max-size", required_argument, 0, 'M'},
{"set-option", required_argument, 0, 'o'},
+ {"print-config", no_argument, 0, 'p'},
{"show-stats", no_argument, 0, 's'},
{"version", no_argument, 0, 'V'},
{"zero-stats", no_argument, 0, 'z'},
{0, 0, 0, 0}
};
- while ((c = getopt_long(argc, argv, "cChF:M:o:sVz", options, NULL)) != -1) {
+ while ((c = getopt_long(argc, argv, "cChF:M:o:psVz", options, NULL)) != -1) {
switch (c) {
case DUMP_MANIFEST:
manifest_dump(optarg, stdout);
}
break;
+ case 'p': /* --print-config */
+ initialize();
+ conf_print_items(conf, conf_printer, stdout);
+ break;
+
case 's': /* --show-stats */
initialize();
stats_summary(conf);
return *value;
}
-static bool
-parse_octal(const char *str, void *result, char **errmsg)
-{
- unsigned *value = (unsigned *)result;
- char *endptr;
- errno = 0;
- *value = strtoul(str, &endptr, 8);
- if (errno == 0 && *str != '\0' && *endptr == '\0') {
- return true;
- } else {
- *errmsg = format("not an octal integer: \"%s\"", str);
- return false;
- }
-}
-
static bool
parse_size(const char *str, void *result, char **errmsg)
{
return true;
}
+static bool
+parse_umask(const char *str, void *result, char **errmsg)
+{
+ unsigned *value = (unsigned *)result;
+ char *endptr;
+ if (str_eq(str, "")) {
+ *value = UINT_MAX;
+ return true;
+ }
+ errno = 0;
+ *value = strtoul(str, &endptr, 8);
+ if (errno == 0 && *str != '\0' && *endptr == '\0') {
+ return true;
+ } else {
+ *errmsg = format("not an octal integer: \"%s\"", str);
+ return false;
+ }
+}
+
static bool
parse_unsigned(const char *str, void *result, char **errmsg)
{
ITEM(sloppiness, sloppiness),
ITEM(stats, bool),
ITEM(temporary_dir, env_string),
- ITEM(umask, octal),
+ ITEM(umask, umask),
ITEM(unify, bool)
};
reformat(&s, "temporary_dir = %s", conf->temporary_dir);
printer(s, context);
- reformat(&s, "umask = %03o", conf->umask);
- printer(s, context);
+ if (conf->umask == UINT_MAX) {
+ printer("umask = ", context);
+ } else {
+ reformat(&s, "umask = %03o", conf->umask);
+ printer(s, context);
+ }
reformat(&s, "unify = %s", conf->unify ? "true" : "false");
printer(s, context);
conf_free(conf);
}
-TEST(conf_read_invalid_octal)
+TEST(conf_read_empty_umask)
{
struct conf *conf = conf_create();
char *errmsg;
- create_file("ccache.conf", "umask = 890x");
- CHECK(!conf_read(conf, "ccache.conf", &errmsg));
- CHECK_STR_EQ_FREE2("ccache.conf:1: not an octal integer: \"890x\"",
- errmsg);
+ create_file("ccache.conf", "umask = ");
+ CHECK(conf_read(conf, "ccache.conf", &errmsg));
+ CHECK_INT_EQ(conf->umask, UINT_MAX);
conf_free(conf);
}