summaryrefslogtreecommitdiff
path: root/src/shared
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2014-11-28 20:51:01 +0100
committerLennart Poettering <lennart@poettering.net>2014-11-28 20:55:04 +0100
commitfed1e721fd0c81e60c77120539f34e16c2585634 (patch)
treea0bb21b49530bc896dcd2c540a582e324c6d7785 /src/shared
parent36afca67b67984520c5c9a6ce14af51a68c7c8cf (diff)
treewide: introduce UID_INVALID (and friends) as macro for (uid_t) -1
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/cgroup-util.c6
-rw-r--r--src/shared/macro.h4
-rw-r--r--src/shared/mkdir.c4
-rw-r--r--src/shared/uid-range.c4
-rw-r--r--src/shared/util.c18
5 files changed, 20 insertions, 16 deletions
diff --git a/src/shared/cgroup-util.c b/src/shared/cgroup-util.c
index da8e885226..bc5030ebb2 100644
--- a/src/shared/cgroup-util.c
+++ b/src/shared/cgroup-util.c
@@ -682,7 +682,7 @@ int cg_set_group_access(
assert(path);
- if (mode != (mode_t) -1)
+ if (mode != MODE_INVALID)
mode &= 0777;
r = cg_get_path(controller, path, NULL, &fs);
@@ -704,10 +704,10 @@ int cg_set_task_access(
assert(path);
- if (mode == (mode_t) -1 && uid == (uid_t) -1 && gid == (gid_t) -1)
+ if (mode == MODE_INVALID && uid == UID_INVALID && gid == GID_INVALID)
return 0;
- if (mode != (mode_t) -1)
+ if (mode != MODE_INVALID)
mode &= 0666;
r = cg_get_path(controller, path, "cgroup.procs", &fs);
diff --git a/src/shared/macro.h b/src/shared/macro.h
index 6d4712c30d..9f5e4552b4 100644
--- a/src/shared/macro.h
+++ b/src/shared/macro.h
@@ -423,4 +423,8 @@ do { \
#endif
#endif
+#define UID_INVALID ((uid_t) -1)
+#define GID_INVALID ((gid_t) -1)
+#define MODE_INVALID ((mode_t) -1)
+
#include "log.h"
diff --git a/src/shared/mkdir.c b/src/shared/mkdir.c
index ef3f494cc8..beefd1052a 100644
--- a/src/shared/mkdir.c
+++ b/src/shared/mkdir.c
@@ -44,8 +44,8 @@ int mkdir_safe_internal(const char *path, mode_t mode, uid_t uid, gid_t gid, mkd
if ((st.st_mode & 0007) > (mode & 0007) ||
(st.st_mode & 0070) > (mode & 0070) ||
(st.st_mode & 0700) > (mode & 0700) ||
- (uid != (uid_t) -1 && st.st_uid != uid) ||
- (gid != (gid_t) -1 && st.st_gid != gid) ||
+ (uid != UID_INVALID && st.st_uid != uid) ||
+ (gid != GID_INVALID && st.st_gid != gid) ||
!S_ISDIR(st.st_mode)) {
errno = EEXIST;
return -errno;
diff --git a/src/shared/uid-range.c b/src/shared/uid-range.c
index 74c3be4a13..4794ff45bb 100644
--- a/src/shared/uid-range.c
+++ b/src/shared/uid-range.c
@@ -161,7 +161,7 @@ int uid_range_add_str(UidRange **p, unsigned *n, const char *s) {
}
int uid_range_next_lower(const UidRange *p, unsigned n, uid_t *uid) {
- uid_t closest = (uid_t) -1, candidate;
+ uid_t closest = UID_INVALID, candidate;
unsigned i;
assert(p);
@@ -184,7 +184,7 @@ int uid_range_next_lower(const UidRange *p, unsigned n, uid_t *uid) {
closest = end;
}
- if (closest == (uid_t) -1)
+ if (closest == UID_INVALID)
return -EBUSY;
*uid = closest;
diff --git a/src/shared/util.c b/src/shared/util.c
index f8511ff4aa..4c380b8b90 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -354,7 +354,7 @@ int parse_uid(const char *s, uid_t* ret_uid) {
if ((unsigned long) uid != ul)
return -ERANGE;
- /* Some libc APIs use (uid_t) -1 as special placeholder */
+ /* Some libc APIs use UID_INVALID as special placeholder */
if (uid == (uid_t) 0xFFFFFFFF)
return -ENXIO;
@@ -3167,11 +3167,11 @@ int chmod_and_chown(const char *path, mode_t mode, uid_t uid, gid_t gid) {
* first change the access mode and only then hand out
* ownership to avoid a window where access is too open. */
- if (mode != (mode_t) -1)
+ if (mode != MODE_INVALID)
if (chmod(path, mode) < 0)
return -errno;
- if (uid != (uid_t) -1 || gid != (gid_t) -1)
+ if (uid != UID_INVALID || gid != GID_INVALID)
if (chown(path, uid, gid) < 0)
return -errno;
@@ -3185,11 +3185,11 @@ int fchmod_and_fchown(int fd, mode_t mode, uid_t uid, gid_t gid) {
* first change the access mode and only then hand out
* ownership to avoid a window where access is too open. */
- if (mode != (mode_t) -1)
+ if (mode != MODE_INVALID)
if (fchmod(fd, mode) < 0)
return -errno;
- if (uid != (uid_t) -1 || gid != (gid_t) -1)
+ if (uid != UID_INVALID || gid != GID_INVALID)
if (fchown(fd, uid, gid) < 0)
return -errno;
@@ -3680,7 +3680,7 @@ int touch_file(const char *path, bool parents, usec_t stamp, uid_t uid, gid_t gi
return -errno;
}
- if (uid != (uid_t) -1 || gid != (gid_t) -1) {
+ if (uid != UID_INVALID || gid != GID_INVALID) {
r = fchown(fd, uid, gid);
if (r < 0)
return -errno;
@@ -3701,7 +3701,7 @@ int touch_file(const char *path, bool parents, usec_t stamp, uid_t uid, gid_t gi
}
int touch(const char *path) {
- return touch_file(path, false, USEC_INFINITY, (uid_t) -1, (gid_t) -1, 0);
+ return touch_file(path, false, USEC_INFINITY, UID_INVALID, GID_INVALID, 0);
}
char *unquote(const char *s, const char* quotes) {
@@ -6547,9 +6547,9 @@ int getpeercred(int fd, struct ucred *ucred) {
* to namespacing issues */
if (u.pid <= 0)
return -ENODATA;
- if (u.uid == (uid_t) -1)
+ if (u.uid == UID_INVALID)
return -ENODATA;
- if (u.gid == (gid_t) -1)
+ if (u.gid == GID_INVALID)
return -ENODATA;
*ucred = u;