Guard prof related mallctl with opt_prof.

The prof initialization is done only when opt_prof is true.  This change makes
sure the prof_* mallctls only have limited read access (i.e. no access to prof
internals) when opt_prof is false.

In addition, initialize the global prof mutexes even if opt_prof is false.  This
makes sure the mutex stats are set properly.
This commit is contained in:
Qi Wang 2021-09-08 10:58:04 -07:00 committed by Qi Wang
parent 6e848a005e
commit 523cfa55c5
3 changed files with 79 additions and 67 deletions

View file

@ -2337,7 +2337,7 @@ thread_prof_name_ctl(tsd_t *tsd, const size_t *mib,
size_t newlen) {
int ret;
if (!config_prof) {
if (!config_prof || !opt_prof) {
return ENOENT;
}
@ -2374,8 +2374,12 @@ thread_prof_active_ctl(tsd_t *tsd, const size_t *mib,
return ENOENT;
}
oldval = prof_thread_active_get(tsd);
oldval = opt_prof ? prof_thread_active_get(tsd) : false;
if (newp != NULL) {
if (!opt_prof) {
ret = ENOENT;
goto label_return;
}
if (newlen != sizeof(bool)) {
ret = EINVAL;
goto label_return;
@ -3128,6 +3132,10 @@ prof_thread_active_init_ctl(tsd_t *tsd, const size_t *mib,
}
if (newp != NULL) {
if (!opt_prof) {
ret = ENOENT;
goto label_return;
}
if (newlen != sizeof(bool)) {
ret = EINVAL;
goto label_return;
@ -3135,7 +3143,8 @@ prof_thread_active_init_ctl(tsd_t *tsd, const size_t *mib,
oldval = prof_thread_active_init_set(tsd_tsdn(tsd),
*(bool *)newp);
} else {
oldval = prof_thread_active_init_get(tsd_tsdn(tsd));
oldval = opt_prof ? prof_thread_active_init_get(tsd_tsdn(tsd)) :
false;
}
READ(oldval, bool);
@ -3161,13 +3170,19 @@ prof_active_ctl(tsd_t *tsd, const size_t *mib, size_t miblen,
goto label_return;
}
bool val = *(bool *)newp;
if (!opt_prof && val) {
ret = ENOENT;
goto label_return;
if (!opt_prof) {
if (val) {
ret = ENOENT;
goto label_return;
} else {
/* No change needed (already off). */
oldval = false;
}
} else {
oldval = prof_active_set(tsd_tsdn(tsd), val);
}
oldval = prof_active_set(tsd_tsdn(tsd), val);
} else {
oldval = prof_active_get(tsd_tsdn(tsd));
oldval = opt_prof ? prof_active_get(tsd_tsdn(tsd)) : false;
}
READ(oldval, bool);
@ -3182,7 +3197,7 @@ prof_dump_ctl(tsd_t *tsd, const size_t *mib, size_t miblen,
int ret;
const char *filename = NULL;
if (!config_prof) {
if (!config_prof || !opt_prof) {
return ENOENT;
}
@ -3210,13 +3225,17 @@ prof_gdump_ctl(tsd_t *tsd, const size_t *mib, size_t miblen,
}
if (newp != NULL) {
if (!opt_prof) {
ret = ENOENT;
goto label_return;
}
if (newlen != sizeof(bool)) {
ret = EINVAL;
goto label_return;
}
oldval = prof_gdump_set(tsd_tsdn(tsd), *(bool *)newp);
} else {
oldval = prof_gdump_get(tsd_tsdn(tsd));
oldval = opt_prof ? prof_gdump_get(tsd_tsdn(tsd)) : false;
}
READ(oldval, bool);
@ -3231,7 +3250,7 @@ prof_prefix_ctl(tsd_t *tsd, const size_t *mib, size_t miblen,
int ret;
const char *prefix = NULL;
if (!config_prof) {
if (!config_prof || !opt_prof) {
return ENOENT;
}
@ -3251,7 +3270,7 @@ prof_reset_ctl(tsd_t *tsd, const size_t *mib, size_t miblen,
int ret;
size_t lg_sample = lg_prof_sample;
if (!config_prof) {
if (!config_prof || !opt_prof) {
return ENOENT;
}
@ -3278,7 +3297,7 @@ prof_log_start_ctl(tsd_t *tsd, const size_t *mib, size_t miblen, void *oldp,
const char *filename = NULL;
if (!config_prof) {
if (!config_prof || !opt_prof) {
return ENOENT;
}
@ -3298,7 +3317,7 @@ label_return:
static int
prof_log_stop_ctl(tsd_t *tsd, const size_t *mib, size_t miblen, void *oldp,
size_t *oldlenp, void *newp, size_t newlen) {
if (!config_prof) {
if (!config_prof || !opt_prof) {
return ENOENT;
}