diff options
author | Tom Gundersen <teg@jklm.no> | 2014-02-28 02:07:29 +0100 |
---|---|---|
committer | Tom Gundersen <teg@jklm.no> | 2014-02-28 02:08:08 +0100 |
commit | cb6fa44cb5411ed574f14109ee862ff663ab0a36 (patch) | |
tree | ec1e33cf95961e3f61de47caf6a6e8afa2558387 /src/network/sd-network.c | |
parent | 82bdf8ce36ccfe1b6ff389a9c9c7e2b2d049a43d (diff) |
sd-network: turn states 'unknown' and 'unmanaged' into errnos
Diffstat (limited to 'src/network/sd-network.c')
-rw-r--r-- | src/network/sd-network.c | 23 |
1 files changed, 10 insertions, 13 deletions
diff --git a/src/network/sd-network.c b/src/network/sd-network.c index 7469873664..23af940903 100644 --- a/src/network/sd-network.c +++ b/src/network/sd-network.c @@ -34,7 +34,7 @@ #include "dhcp-lease-internal.h" _public_ int sd_network_get_link_state(unsigned index, char **state) { - char *p, *s = NULL; + _cleanup_free_ char *s = NULL, *p = NULL; int r; assert_return(index, -EINVAL); @@ -44,23 +44,20 @@ _public_ int sd_network_get_link_state(unsigned index, char **state) { return -ENOMEM; r = parse_env_file(p, NEWLINE, "STATE", &s, NULL); - free(p); - - if (r == -ENOENT) { - free(s); - s = strdup("unknown"); - if (!s) - return -ENOMEM; - *state = s; - return 0; - } else if (r < 0) { - free(s); + if (r == -ENOENT) + return -ENODATA; + else if (r < 0) return r; - } else if (!s) + else if (!s) return -EIO; + if (streq(s, "unmanaged")) + return -EUNATCH; + *state = s; + s = NULL; + return 0; } |