tree-wide: make use of errno_or_else() everywhere
This commit is contained in:
@@ -81,7 +81,7 @@ int cg_read_pid(FILE *f, pid_t *_pid) {
|
||||
if (feof(f))
|
||||
return 0;
|
||||
|
||||
return errno > 0 ? -errno : -EIO;
|
||||
return errno_or_else(EIO);
|
||||
}
|
||||
|
||||
if (ul <= 0)
|
||||
@@ -770,10 +770,8 @@ int cg_trim(const char *controller, const char *path, bool delete_root) {
|
||||
if (nftw(fs, trim_cb, 64, FTW_DEPTH|FTW_MOUNT|FTW_PHYS) != 0) {
|
||||
if (errno == ENOENT)
|
||||
r = 0;
|
||||
else if (errno > 0)
|
||||
r = -errno;
|
||||
else
|
||||
r = -EIO;
|
||||
r = errno_or_else(EIO);
|
||||
}
|
||||
|
||||
if (delete_root) {
|
||||
@@ -2502,8 +2500,8 @@ int cg_kernel_controllers(Set **ret) {
|
||||
if (feof(f))
|
||||
break;
|
||||
|
||||
if (ferror(f) && errno > 0)
|
||||
return -errno;
|
||||
if (ferror(f))
|
||||
return errno_or_else(EIO);
|
||||
|
||||
return -EBADMSG;
|
||||
}
|
||||
|
||||
+4
-4
@@ -298,7 +298,7 @@ int verify_file(const char *fn, const char *blob, bool accept_extra_nl) {
|
||||
errno = 0;
|
||||
k = fread(buf, 1, l + accept_extra_nl + 1, f);
|
||||
if (ferror(f))
|
||||
return errno > 0 ? -errno : -EIO;
|
||||
return errno_or_else(EIO);
|
||||
|
||||
if (k != l && k != l + accept_extra_nl)
|
||||
return 0;
|
||||
@@ -382,7 +382,7 @@ int read_full_stream_full(
|
||||
l += k;
|
||||
|
||||
if (ferror(f)) {
|
||||
r = errno > 0 ? -errno : -EIO;
|
||||
r = errno_or_else(EIO);
|
||||
goto finalize;
|
||||
}
|
||||
|
||||
@@ -661,7 +661,7 @@ int fflush_and_check(FILE *f) {
|
||||
fflush(f);
|
||||
|
||||
if (ferror(f))
|
||||
return errno > 0 ? -errno : -EIO;
|
||||
return errno_or_else(EIO);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -888,7 +888,7 @@ int safe_fgetc(FILE *f, char *ret) {
|
||||
k = fgetc(f);
|
||||
if (k == EOF) {
|
||||
if (ferror(f))
|
||||
return errno > 0 ? -errno : -EIO;
|
||||
return errno_or_else(EIO);
|
||||
|
||||
if (ret)
|
||||
*ret = 0;
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include <unistd.h>
|
||||
|
||||
#include "dirent-util.h"
|
||||
#include "errno-util.h"
|
||||
#include "glob-util.h"
|
||||
#include "macro.h"
|
||||
#include "path-util.h"
|
||||
@@ -36,13 +37,12 @@ int safe_glob(const char *path, int flags, glob_t *pglob) {
|
||||
|
||||
errno = 0;
|
||||
k = glob(path, flags | GLOB_ALTDIRFUNC, NULL, pglob);
|
||||
|
||||
if (k == GLOB_NOMATCH)
|
||||
return -ENOENT;
|
||||
if (k == GLOB_NOSPACE)
|
||||
return -ENOMEM;
|
||||
if (k != 0)
|
||||
return errno > 0 ? -errno : -EIO;
|
||||
return errno_or_else(EIO);
|
||||
if (strv_isempty(pglob->gl_pathv))
|
||||
return -ENOENT;
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "alloc-util.h"
|
||||
#include "errno-util.h"
|
||||
#include "in-addr-util.h"
|
||||
#include "macro.h"
|
||||
#include "parse-util.h"
|
||||
@@ -315,7 +316,7 @@ int in_addr_to_string(int family, const union in_addr_union *u, char **ret) {
|
||||
|
||||
errno = 0;
|
||||
if (!inet_ntop(family, u, x, l))
|
||||
return errno > 0 ? -errno : -EINVAL;
|
||||
return errno_or_else(EINVAL);
|
||||
|
||||
*ret = TAKE_PTR(x);
|
||||
return 0;
|
||||
@@ -345,7 +346,7 @@ int in_addr_prefix_to_string(int family, const union in_addr_union *u, unsigned
|
||||
|
||||
errno = 0;
|
||||
if (!inet_ntop(family, u, x, l))
|
||||
return errno > 0 ? -errno : -EINVAL;
|
||||
return errno_or_else(EINVAL);
|
||||
|
||||
p = x + strlen(x);
|
||||
l -= strlen(x);
|
||||
@@ -384,7 +385,7 @@ int in_addr_ifindex_to_string(int family, const union in_addr_union *u, int ifin
|
||||
|
||||
errno = 0;
|
||||
if (!inet_ntop(family, u, x, l))
|
||||
return errno > 0 ? -errno : -EINVAL;
|
||||
return errno_or_else(EINVAL);
|
||||
|
||||
sprintf(strchr(x, 0), "%%%i", ifindex);
|
||||
|
||||
@@ -404,7 +405,7 @@ int in_addr_from_string(int family, const char *s, union in_addr_union *ret) {
|
||||
|
||||
errno = 0;
|
||||
if (inet_pton(family, s, ret ?: &buffer) <= 0)
|
||||
return errno > 0 ? -errno : -EINVAL;
|
||||
return errno_or_else(EINVAL);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -78,7 +78,7 @@ int socket_address_parse(SocketAddress *a, const char *s) {
|
||||
|
||||
errno = 0;
|
||||
if (inet_pton(AF_INET6, n, &a->sockaddr.in6.sin6_addr) <= 0)
|
||||
return errno > 0 ? -errno : -EINVAL;
|
||||
return errno_or_else(EINVAL);
|
||||
|
||||
e++;
|
||||
if (*e != ':')
|
||||
|
||||
+13
-12
@@ -15,6 +15,7 @@
|
||||
#include <utmp.h>
|
||||
|
||||
#include "alloc-util.h"
|
||||
#include "errno-util.h"
|
||||
#include "fd-util.h"
|
||||
#include "fileio.h"
|
||||
#include "format-util.h"
|
||||
@@ -213,7 +214,7 @@ int get_user_creds(
|
||||
p = getpwnam(*username);
|
||||
}
|
||||
if (!p) {
|
||||
r = errno > 0 ? -errno : -ESRCH;
|
||||
r = errno_or_else(ESRCH);
|
||||
|
||||
/* If the user requested that we only synthesize as fallback, do so now */
|
||||
if (FLAGS_SET(flags, USER_CREDS_PREFER_NSS)) {
|
||||
@@ -307,7 +308,7 @@ int get_group_creds(const char **groupname, gid_t *gid, UserCredsFlags flags) {
|
||||
}
|
||||
|
||||
if (!g)
|
||||
return errno > 0 ? -errno : -ESRCH;
|
||||
return errno_or_else(ESRCH);
|
||||
|
||||
if (gid) {
|
||||
if (!gid_is_valid(g->gr_gid))
|
||||
@@ -492,7 +493,7 @@ int get_home_dir(char **_h) {
|
||||
errno = 0;
|
||||
p = getpwuid(u);
|
||||
if (!p)
|
||||
return errno > 0 ? -errno : -ESRCH;
|
||||
return errno_or_else(ESRCH);
|
||||
|
||||
if (!path_is_valid(p->pw_dir) ||
|
||||
!path_is_absolute(p->pw_dir))
|
||||
@@ -549,7 +550,7 @@ int get_shell(char **_s) {
|
||||
errno = 0;
|
||||
p = getpwuid(u);
|
||||
if (!p)
|
||||
return errno > 0 ? -errno : -ESRCH;
|
||||
return errno_or_else(ESRCH);
|
||||
|
||||
if (!path_is_valid(p->pw_shell) ||
|
||||
!path_is_absolute(p->pw_shell))
|
||||
@@ -770,7 +771,7 @@ int putpwent_sane(const struct passwd *pw, FILE *stream) {
|
||||
|
||||
errno = 0;
|
||||
if (putpwent(pw, stream) != 0)
|
||||
return errno > 0 ? -errno : -EIO;
|
||||
return errno_or_else(EIO);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -781,7 +782,7 @@ int putspent_sane(const struct spwd *sp, FILE *stream) {
|
||||
|
||||
errno = 0;
|
||||
if (putspent(sp, stream) != 0)
|
||||
return errno > 0 ? -errno : -EIO;
|
||||
return errno_or_else(EIO);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -792,7 +793,7 @@ int putgrent_sane(const struct group *gr, FILE *stream) {
|
||||
|
||||
errno = 0;
|
||||
if (putgrent(gr, stream) != 0)
|
||||
return errno > 0 ? -errno : -EIO;
|
||||
return errno_or_else(EIO);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -804,7 +805,7 @@ int putsgent_sane(const struct sgrp *sg, FILE *stream) {
|
||||
|
||||
errno = 0;
|
||||
if (putsgent(sg, stream) != 0)
|
||||
return errno > 0 ? -errno : -EIO;
|
||||
return errno_or_else(EIO);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -819,7 +820,7 @@ int fgetpwent_sane(FILE *stream, struct passwd **pw) {
|
||||
errno = 0;
|
||||
p = fgetpwent(stream);
|
||||
if (!p && errno != ENOENT)
|
||||
return errno > 0 ? -errno : -EIO;
|
||||
return errno_or_else(EIO);
|
||||
|
||||
*pw = p;
|
||||
return !!p;
|
||||
@@ -834,7 +835,7 @@ int fgetspent_sane(FILE *stream, struct spwd **sp) {
|
||||
errno = 0;
|
||||
s = fgetspent(stream);
|
||||
if (!s && errno != ENOENT)
|
||||
return errno > 0 ? -errno : -EIO;
|
||||
return errno_or_else(EIO);
|
||||
|
||||
*sp = s;
|
||||
return !!s;
|
||||
@@ -849,7 +850,7 @@ int fgetgrent_sane(FILE *stream, struct group **gr) {
|
||||
errno = 0;
|
||||
g = fgetgrent(stream);
|
||||
if (!g && errno != ENOENT)
|
||||
return errno > 0 ? -errno : -EIO;
|
||||
return errno_or_else(EIO);
|
||||
|
||||
*gr = g;
|
||||
return !!g;
|
||||
@@ -865,7 +866,7 @@ int fgetsgent_sane(FILE *stream, struct sgrp **sg) {
|
||||
errno = 0;
|
||||
s = fgetsgent(stream);
|
||||
if (!s && errno != ENOENT)
|
||||
return errno > 0 ? -errno : -EIO;
|
||||
return errno_or_else(EIO);
|
||||
|
||||
*sg = s;
|
||||
return !!s;
|
||||
|
||||
Reference in New Issue
Block a user