X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;ds=inline;f=src%2Fshared%2Futil.c;h=673e0da6b69f38112708581ff81abe65a1675c1b;hb=e724b0639c43c2821613fc4f7f755f87c49a22e8;hp=f9ec14aff4f6b112a58c99498de562b349f38e5f;hpb=aa96c6cb44a6eeccc506ae055aae2519a7f914e1;p=elogind.git diff --git a/src/shared/util.c b/src/shared/util.c index f9ec14aff..673e0da6b 100644 --- a/src/shared/util.c +++ b/src/shared/util.c @@ -1449,7 +1449,7 @@ char *ascii_strlower(char *t) { return t; } -static bool ignore_file_allow_backup(const char *filename) { +_pure_ static bool ignore_file_allow_backup(const char *filename) { assert(filename); return @@ -1512,7 +1512,7 @@ int fd_cloexec(int fd, bool cloexec) { return 0; } -static bool fd_in_set(int fd, const int fdset[], unsigned n_fdset) { +_pure_ static bool fd_in_set(int fd, const int fdset[], unsigned n_fdset) { unsigned i; assert(n_fdset == 0 || fdset); @@ -2770,7 +2770,7 @@ int rm_rf_children_dangerous(int fd, bool only_dirs, bool honour_sticky, struct return ret; } -static int is_temporary_fs(struct statfs *s) { +_pure_ static int is_temporary_fs(struct statfs *s) { assert(s); return F_TYPE_CMP(s->f_type, TMPFS_MAGIC) || @@ -3838,24 +3838,29 @@ bool hostname_is_valid(const char *s) { return true; } -char* hostname_cleanup(char *s) { +char* hostname_cleanup(char *s, bool lowercase) { char *p, *d; bool dot; for (p = s, d = s, dot = true; *p; p++) { if (*p == '.') { - if (dot || p[1] == 0) + if (dot) continue; + *(d++) = '.'; dot = true; - } else + } else if (hostname_valid_char(*p)) { + *(d++) = lowercase ? tolower(*p) : *p; dot = false; + } - if (hostname_valid_char(*p)) - *(d++) = *p; } - *d = 0; + if (dot && d > s) + d[-1] = 0; + else + *d = 0; + strshorten(s, HOST_NAME_MAX); return s; @@ -5090,59 +5095,6 @@ int getenv_for_pid(pid_t pid, const char *field, char **_value) { return r; } -int can_sleep(const char *type) { - char *w, *state; - size_t l, k; - int r; - _cleanup_free_ char *p = NULL; - - assert(type); - - /* If /sys is read-only we cannot sleep */ - if (access("/sys/power/state", W_OK) < 0) - return false; - - r = read_one_line_file("/sys/power/state", &p); - if (r < 0) - return false; - - k = strlen(type); - FOREACH_WORD_SEPARATOR(w, l, p, WHITESPACE, state) - if (l == k && memcmp(w, type, l) == 0) - return true; - - return false; -} - -int can_sleep_disk(const char *type) { - char *w, *state; - size_t l, k; - int r; - _cleanup_free_ char *p = NULL; - - assert(type); - - /* If /sys is read-only we cannot sleep */ - if (access("/sys/power/state", W_OK) < 0 || - access("/sys/power/disk", W_OK) < 0) - return false; - - r = read_one_line_file("/sys/power/disk", &p); - if (r < 0) - return false; - - k = strlen(type); - FOREACH_WORD_SEPARATOR(w, l, p, WHITESPACE, state) { - if (l == k && memcmp(w, type, l) == 0) - return true; - - if (l == k + 2 && w[0] == '[' && memcmp(w + 1, type, l - 2) == 0 && w[l-1] == ']') - return true; - } - - return false; -} - bool is_valid_documentation_url(const char *url) { assert(url);