chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
util: add files_same() helper function
[elogind.git]
/
src
/
shared
/
util.c
diff --git
a/src/shared/util.c
b/src/shared/util.c
index d28caae6c2ebc0fd034acebf2d06fa77bd1c96cb..10f113bd240975d7f9fc810c21623ad54aba2e67 100644
(file)
--- a/
src/shared/util.c
+++ b/
src/shared/util.c
@@
-3198,19
+3198,27
@@
bool on_tty(void) {
return cached_on_tty;
}
return cached_on_tty;
}
-int
running_in_chroot(void
) {
- struct stat a
= {}, b = {}
;
+int
files_same(const char *filea, const char *fileb
) {
+ struct stat a
, b
;
- /* Only works as root */
- if (stat("/proc/1/root", &a) < 0)
+ if (stat(filea, &a) < 0)
return -errno;
return -errno;
- if (stat(
"/"
, &b) < 0)
+ if (stat(
fileb
, &b) < 0)
return -errno;
return -errno;
- return
- a.st_dev != b.st_dev ||
- a.st_ino != b.st_ino;
+ return a.st_dev == b.st_dev &&
+ a.st_ino == b.st_ino;
+}
+
+int running_in_chroot(void) {
+ int ret;
+
+ ret = files_same("/proc/1/root", "/");
+ if (ret < 0)
+ return ret;
+
+ return ret == 0;
}
static char *ascii_ellipsize_mem(const char *s, size_t old_length, size_t new_length, unsigned percent) {
}
static char *ascii_ellipsize_mem(const char *s, size_t old_length, size_t new_length, unsigned percent) {