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: fix copy-paste error and actually set the new hostname
[elogind.git]
/
src
/
shared
/
util.c
diff --git
a/src/shared/util.c
b/src/shared/util.c
index 5f6249eb045d2fbb938af32e135a6811695f5c77..4143f6d643ebca2cb02c105ba0504d1a55d9f72d 100644
(file)
--- a/
src/shared/util.c
+++ b/
src/shared/util.c
@@
-6933,10
+6933,21
@@
int is_symlink(const char *path) {
if (lstat(path, &info) < 0)
return -errno;
if (lstat(path, &info) < 0)
return -errno;
- if (S_ISLNK(info.st_mode))
- return 1;
+ return !!S_ISLNK(info.st_mode);
+}
- return 0;
+int is_dir(const char* path, bool follow) {
+ struct stat st;
+
+ if (follow) {
+ if (stat(path, &st) < 0)
+ return -errno;
+ } else {
+ if (lstat(path, &st) < 0)
+ return -errno;
+ }
+
+ return !!S_ISDIR(st.st_mode);
}
int unquote_first_word(const char **p, char **ret) {
}
int unquote_first_word(const char **p, char **ret) {
@@
-7164,3
+7175,23
@@
int free_and_strdup(char **p, const char *s) {
return 0;
}
return 0;
}
+
+int sethostname_idempotent(const char *s) {
+ int r;
+ char buf[HOST_NAME_MAX + 1] = {};
+
+ assert(s);
+
+ r = gethostname(buf, sizeof(buf));
+ if (r < 0)
+ return -errno;
+
+ if (streq(buf, s))
+ return 0;
+
+ r = sethostname(s, strlen(s));
+ if (r < 0)
+ return -errno;
+
+ return 1;
+}