mirror of
https://git.proxmox.com/git/mirror_frr
synced 2026-01-01 06:43:31 +00:00
lib: Use gotos in filter control functions
Use gotos to reduce return paths in the log filter add/del/dump functions. Signed-off-by: Stephen Worley <sworley@cumulusnetworks.com>
This commit is contained in:
parent
4aaea8fb49
commit
ec1d97751e
38
lib/log.c
38
lib/log.c
@ -92,30 +92,33 @@ int zlog_filter_add(const char *filter)
|
||||
{
|
||||
pthread_mutex_lock(&loglock);
|
||||
|
||||
int ret = 0;
|
||||
|
||||
if (zlog_filter_count >= ZLOG_FILTERS_MAX) {
|
||||
pthread_mutex_unlock(&loglock);
|
||||
return 1;
|
||||
ret = 1;
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (zlog_filter_lookup(filter) != -1) {
|
||||
/* Filter already present */
|
||||
pthread_mutex_unlock(&loglock);
|
||||
return -1;
|
||||
ret = -1;
|
||||
goto done;
|
||||
}
|
||||
|
||||
strlcpy(zlog_filters[zlog_filter_count], filter,
|
||||
sizeof(zlog_filters[0]));
|
||||
|
||||
if (zlog_filters[zlog_filter_count] == NULL
|
||||
|| zlog_filters[zlog_filter_count][0] == '\0') {
|
||||
pthread_mutex_unlock(&loglock);
|
||||
return -1;
|
||||
if (zlog_filters[zlog_filter_count][0] == '\0') {
|
||||
/* Filter was either empty or didn't get copied correctly */
|
||||
ret = -1;
|
||||
goto done;
|
||||
}
|
||||
|
||||
zlog_filter_count++;
|
||||
|
||||
done:
|
||||
pthread_mutex_unlock(&loglock);
|
||||
return 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
int zlog_filter_del(const char *filter)
|
||||
@ -124,11 +127,12 @@ int zlog_filter_del(const char *filter)
|
||||
|
||||
int found_idx = zlog_filter_lookup(filter);
|
||||
int last_idx = zlog_filter_count - 1;
|
||||
int ret = 0;
|
||||
|
||||
if (found_idx == -1) {
|
||||
/* Didn't find the filter to delete */
|
||||
pthread_mutex_unlock(&loglock);
|
||||
return -1;
|
||||
ret = -1;
|
||||
goto done;
|
||||
}
|
||||
|
||||
/* Adjust the filter array */
|
||||
@ -137,8 +141,9 @@ int zlog_filter_del(const char *filter)
|
||||
|
||||
zlog_filter_count--;
|
||||
|
||||
done:
|
||||
pthread_mutex_unlock(&loglock);
|
||||
return 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Dump all filters to buffer, delimited by new line */
|
||||
@ -154,13 +159,13 @@ int zlog_filter_dump(char *buf, size_t max_size)
|
||||
zlog_filters[i]);
|
||||
len += ret;
|
||||
if ((ret < 0) || ((size_t)len >= max_size)) {
|
||||
pthread_mutex_unlock(&loglock);
|
||||
return -1;
|
||||
len = -1;
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
||||
done:
|
||||
pthread_mutex_unlock(&loglock);
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
@ -342,7 +347,7 @@ static int vzlog_filter(struct zlog *zl, struct timestamp_control *tsctl,
|
||||
|
||||
len += ret;
|
||||
if ((ret < 0) || ((size_t)len >= sizeof(buf)))
|
||||
return search_buf(buf);
|
||||
goto search;
|
||||
|
||||
if (zl && zl->record_priority)
|
||||
snprintf(buf + len, sizeof(buf) - len, "%s: %s: %s",
|
||||
@ -351,6 +356,7 @@ static int vzlog_filter(struct zlog *zl, struct timestamp_control *tsctl,
|
||||
snprintf(buf + len, sizeof(buf) - len, "%s: %s", proto_str,
|
||||
msg);
|
||||
|
||||
search:
|
||||
return search_buf(buf);
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user