1
0
mirror of https://github.com/systemd/systemd.git synced 2024-12-22 17:35:35 +03:00

networkd-state-file: use ASSERT_PTR where appropriate

This commit is contained in:
Mike Yuan 2024-09-07 19:49:11 +02:00
parent 8b29949a41
commit 4c8dc66438
No known key found for this signature in database
GPG Key ID: 417471C0A40F58B3

View File

@ -277,10 +277,6 @@ int manager_save(Manager *m) {
address_state = LINK_ADDRESS_STATE_OFF; address_state = LINK_ADDRESS_STATE_OFF;
LinkOnlineState online_state; LinkOnlineState online_state;
size_t links_offline = 0, links_online = 0; size_t links_offline = 0, links_online = 0;
_cleanup_(unlink_and_freep) char *temp_path = NULL;
_cleanup_strv_free_ char **p = NULL;
_cleanup_fclose_ FILE *f = NULL;
Link *link;
int r; int r;
assert(m); assert(m);
@ -288,6 +284,7 @@ int manager_save(Manager *m) {
if (isempty(m->state_file)) if (isempty(m->state_file))
return 0; /* Do not update state file when running in test mode. */ return 0; /* Do not update state file when running in test mode. */
Link *link;
HASHMAP_FOREACH(link, m->links_by_index) { HASHMAP_FOREACH(link, m->links_by_index) {
if (link->flags & IFF_LOOPBACK) if (link->flags & IFF_LOOPBACK)
continue; continue;
@ -336,20 +333,14 @@ int manager_save(Manager *m) {
(links_offline > 0 ? LINK_ONLINE_STATE_PARTIAL : LINK_ONLINE_STATE_ONLINE) : (links_offline > 0 ? LINK_ONLINE_STATE_PARTIAL : LINK_ONLINE_STATE_ONLINE) :
(links_offline > 0 ? LINK_ONLINE_STATE_OFFLINE : _LINK_ONLINE_STATE_INVALID); (links_offline > 0 ? LINK_ONLINE_STATE_OFFLINE : _LINK_ONLINE_STATE_INVALID);
operstate_str = link_operstate_to_string(operstate); operstate_str = ASSERT_PTR(link_operstate_to_string(operstate));
assert(operstate_str); carrier_state_str = ASSERT_PTR(link_carrier_state_to_string(carrier_state));
address_state_str = ASSERT_PTR(link_address_state_to_string(address_state));
ipv4_address_state_str = ASSERT_PTR(link_address_state_to_string(ipv4_address_state));
ipv6_address_state_str = ASSERT_PTR(link_address_state_to_string(ipv6_address_state));
carrier_state_str = link_carrier_state_to_string(carrier_state); _cleanup_(unlink_and_freep) char *temp_path = NULL;
assert(carrier_state_str); _cleanup_fclose_ FILE *f = NULL;
address_state_str = link_address_state_to_string(address_state);
assert(address_state_str);
ipv4_address_state_str = link_address_state_to_string(ipv4_address_state);
assert(ipv4_address_state_str);
ipv6_address_state_str = link_address_state_to_string(ipv6_address_state);
assert(ipv6_address_state_str);
r = fopen_temporary(m->state_file, &f, &temp_path); r = fopen_temporary(m->state_file, &f, &temp_path);
if (r < 0) if (r < 0)
@ -386,6 +377,8 @@ int manager_save(Manager *m) {
temp_path = mfree(temp_path); temp_path = mfree(temp_path);
_cleanup_strv_free_ char **p = NULL;
if (m->operational_state != operstate) { if (m->operational_state != operstate) {
m->operational_state = operstate; m->operational_state = operstate;
if (strv_extend(&p, "OperationalState") < 0) if (strv_extend(&p, "OperationalState") < 0)
@ -569,8 +562,7 @@ static void link_save_domains(Link *link, FILE *f, OrderedSet *static_domains, U
} }
static int link_save(Link *link) { static int link_save(Link *link) {
const char *admin_state, *oper_state, *carrier_state, *address_state, *ipv4_address_state, *ipv6_address_state, const char *admin_state, *oper_state, *carrier_state, *address_state, *ipv4_address_state, *ipv6_address_state;
*captive_portal;
_cleanup_(unlink_and_freep) char *temp_path = NULL; _cleanup_(unlink_and_freep) char *temp_path = NULL;
_cleanup_fclose_ FILE *f = NULL; _cleanup_fclose_ FILE *f = NULL;
int r; int r;
@ -584,23 +576,12 @@ static int link_save(Link *link) {
if (link->state == LINK_STATE_LINGER) if (link->state == LINK_STATE_LINGER)
return 0; return 0;
admin_state = link_state_to_string(link->state); admin_state = ASSERT_PTR(link_state_to_string(link->state));
assert(admin_state); oper_state = ASSERT_PTR(link_operstate_to_string(link->operstate));
carrier_state = ASSERT_PTR(link_carrier_state_to_string(link->carrier_state));
oper_state = link_operstate_to_string(link->operstate); address_state = ASSERT_PTR(link_address_state_to_string(link->address_state));
assert(oper_state); ipv4_address_state = ASSERT_PTR(link_address_state_to_string(link->ipv4_address_state));
ipv6_address_state = ASSERT_PTR(link_address_state_to_string(link->ipv6_address_state));
carrier_state = link_carrier_state_to_string(link->carrier_state);
assert(carrier_state);
address_state = link_address_state_to_string(link->address_state);
assert(address_state);
ipv4_address_state = link_address_state_to_string(link->ipv4_address_state);
assert(ipv4_address_state);
ipv6_address_state = link_address_state_to_string(link->ipv6_address_state);
assert(ipv6_address_state);
r = fopen_temporary(link->state_file, &f, &temp_path); r = fopen_temporary(link->state_file, &f, &temp_path);
if (r < 0) if (r < 0)
@ -619,7 +600,7 @@ static int link_save(Link *link) {
admin_state, oper_state, carrier_state, address_state, ipv4_address_state, ipv6_address_state); admin_state, oper_state, carrier_state, address_state, ipv4_address_state, ipv6_address_state);
if (link->network) { if (link->network) {
const char *online_state; const char *online_state, *captive_portal;
bool space = false; bool space = false;
online_state = link_online_state_to_string(link->online_state); online_state = link_online_state_to_string(link->online_state);