diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2017-01-24 04:20:05 +0100 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2017-02-07 12:21:22 +0100 |
commit | 3606898d231c7766e8271981e9d3d52310a6a43f (patch) | |
tree | 425103712d05bf9f0b0f6492b93924f5336dfa45 /src/config.c | |
parent | wg: setconf should remove existing psk (diff) | |
download | wireguard-tools-3606898d231c7766e8271981e9d3d52310a6a43f.tar.xz wireguard-tools-3606898d231c7766e8271981e9d3d52310a6a43f.zip |
wg: remove key for any empty file
Rather than just using /dev/null to mean key removal, match on any empty
file, so that this interface is cross platform.
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'src/config.c')
-rw-r--r-- | src/config.c | 14 |
1 files changed, 3 insertions, 11 deletions
diff --git a/src/config.c b/src/config.c index e6db6ad..da19cc3 100644 --- a/src/config.c +++ b/src/config.c @@ -390,7 +390,6 @@ static int read_line(char **dst, const char *path) { FILE *f; size_t n = 0; - struct stat stat; *dst = NULL; @@ -399,22 +398,15 @@ static int read_line(char **dst, const char *path) perror("fopen"); return -1; } - if (fstat(fileno(f), &stat) < 0) { - perror("fstat"); - fclose(f); - return -1; - } - if (S_ISCHR(stat.st_mode) && stat.st_rdev == makedev(1, 3)) { - fclose(f); - return 1; - } - if (getline(dst, &n, f) < 0) { + if (getline(dst, &n, f) < 0 && errno) { perror("getline"); fclose(f); return -1; } fclose(f); n = strlen(*dst); + if (!n) + return 1; while (--n) { if (isspace((*dst)[n])) (*dst)[n] = '\0'; |