Enable -Wwrite-strings

Also, fix leak from ztest_global_vars_to_zdb_args()

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz>
Closes #13348
This commit is contained in:
наб
2022-04-19 20:38:30 +02:00
committed by Brian Behlendorf
parent e7d90362e5
commit a926aab902
99 changed files with 633 additions and 717 deletions
+29 -36
View File
@@ -90,7 +90,7 @@ char metric_data_type = 'u';
uint64_t metric_value_mask = UINT64_MAX;
uint64_t timestamp = 0;
int complained_about_sync = 0;
char *tags = "";
const char *tags = "";
typedef int (*stat_printer_f)(nvlist_t *, const char *, const char *);
@@ -131,7 +131,7 @@ escape_string(const char *s)
* print key=value where value is a uint64_t
*/
static void
print_kv(char *key, uint64_t value)
print_kv(const char *key, uint64_t value)
{
printf("%s=%llu%c", key,
(u_longlong_t)value & metric_value_mask, metric_data_type);
@@ -152,9 +152,9 @@ print_scan_status(nvlist_t *nvroot, const char *pool_name)
uint64_t remaining_time;
pool_scan_stat_t *ps = NULL;
double pct_done;
char *state[DSS_NUM_STATES] = {
const char *const state[DSS_NUM_STATES] = {
"none", "scanning", "finished", "canceled"};
char *func;
const char *func;
(void) nvlist_lookup_uint64_array(nvroot,
ZPOOL_CONFIG_SCAN_STATS,
@@ -262,17 +262,15 @@ static char *
get_vdev_name(nvlist_t *nvroot, const char *parent_name)
{
static char vdev_name[256];
char *vdev_type = NULL;
uint64_t vdev_id = 0;
if (nvlist_lookup_string(nvroot, ZPOOL_CONFIG_TYPE,
&vdev_type) != 0) {
vdev_type = "unknown";
}
char *vdev_type = (char *)"unknown";
nvlist_lookup_string(nvroot, ZPOOL_CONFIG_TYPE, &vdev_type);
if (nvlist_lookup_uint64(
nvroot, ZPOOL_CONFIG_ID, &vdev_id) != 0) {
nvroot, ZPOOL_CONFIG_ID, &vdev_id) != 0)
vdev_id = UINT64_MAX;
}
if (parent_name == NULL) {
(void) snprintf(vdev_name, sizeof (vdev_name), "%s",
vdev_type);
@@ -298,22 +296,15 @@ static char *
get_vdev_desc(nvlist_t *nvroot, const char *parent_name)
{
static char vdev_desc[2 * MAXPATHLEN];
char *vdev_type = NULL;
uint64_t vdev_id = 0;
char vdev_value[MAXPATHLEN];
char *vdev_path = NULL;
char *s, *t;
if (nvlist_lookup_string(nvroot, ZPOOL_CONFIG_TYPE, &vdev_type) != 0) {
vdev_type = "unknown";
}
if (nvlist_lookup_uint64(nvroot, ZPOOL_CONFIG_ID, &vdev_id) != 0) {
vdev_id = UINT64_MAX;
}
if (nvlist_lookup_string(
nvroot, ZPOOL_CONFIG_PATH, &vdev_path) != 0) {
vdev_path = NULL;
}
char *vdev_type = (char *)"unknown";
uint64_t vdev_id = UINT64_MAX;
char *vdev_path = NULL;
nvlist_lookup_string(nvroot, ZPOOL_CONFIG_TYPE, &vdev_type);
nvlist_lookup_uint64(nvroot, ZPOOL_CONFIG_ID, &vdev_id);
nvlist_lookup_string(nvroot, ZPOOL_CONFIG_PATH, &vdev_path);
if (parent_name == NULL) {
s = escape_string(vdev_type);
@@ -393,8 +384,8 @@ print_vdev_latency_stats(nvlist_t *nvroot, const char *pool_name,
/* short_names become part of the metric name and are influxdb-ready */
struct lat_lookup {
char *name;
char *short_name;
const char *name;
const char *short_name;
uint64_t sum;
uint64_t *array;
};
@@ -487,8 +478,8 @@ print_vdev_size_stats(nvlist_t *nvroot, const char *pool_name,
/* short_names become the field name */
struct size_lookup {
char *name;
char *short_name;
const char *name;
const char *short_name;
uint64_t sum;
uint64_t *array;
};
@@ -579,8 +570,8 @@ print_queue_stats(nvlist_t *nvroot, const char *pool_name,
/* short_names are used for the field name */
struct queue_lookup {
char *name;
char *short_name;
const char *name;
const char *short_name;
};
struct queue_lookup queue_type[] = {
{ZPOOL_CONFIG_VDEV_SYNC_R_ACTIVE_QUEUE, "sync_r_active"},
@@ -632,8 +623,8 @@ print_top_level_vdev_stats(nvlist_t *nvroot, const char *pool_name)
/* short_names become part of the metric name */
struct queue_lookup {
char *name;
char *short_name;
const char *name;
const char *short_name;
};
struct queue_lookup queue_type[] = {
{ZPOOL_CONFIG_VDEV_SYNC_R_ACTIVE_QUEUE, "sync_r_active_queue"},
@@ -789,7 +780,7 @@ main(int argc, char *argv[])
{
int opt;
int ret = 8;
char *line = NULL;
char *line = NULL, *ttags = NULL;
size_t len, tagslen = 0;
struct option long_options[] = {
{"execd", no_argument, NULL, 'e'},
@@ -817,15 +808,17 @@ main(int argc, char *argv[])
sum_histogram_buckets = 1;
break;
case 't':
free(ttags);
tagslen = strlen(optarg) + 2;
tags = calloc(1, tagslen);
if (tags == NULL) {
ttags = calloc(1, tagslen);
if (ttags == NULL) {
fprintf(stderr,
"error: cannot allocate memory "
"for tags\n");
exit(1);
}
(void) snprintf(tags, tagslen, ",%s", optarg);
(void) snprintf(ttags, tagslen, ",%s", optarg);
tags = ttags;
break;
default:
usage(argv[0]);