X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Fshared%2Futil.c;h=dc6528013bb0a7fded44e17a9e84e3eb5473b9f8;hp=11cab6dcf1710f590b2a879f019f274ead1e6020;hb=1c8da044469acabcfc479ba3276954da53210830;hpb=40672b99c7da7efd317fc31612504fe7d5ab0b65 diff --git a/src/shared/util.c b/src/shared/util.c index 11cab6dcf..dc6528013 100644 --- a/src/shared/util.c +++ b/src/shared/util.c @@ -25,6 +25,8 @@ #include #include #include +#include +#include #include #include #include @@ -39,7 +41,7 @@ #include #include #include -#include +#include #include #include #include @@ -60,16 +62,21 @@ #include #include #include -#include #include #include #include + +/* When we include libgen.h because we need dirname() we immediately + * undefine basename() since libgen.h defines it as a macro to the XDG + * version which is really broken. */ +#include #undef basename #ifdef HAVE_SYS_AUXV_H #include #endif +#include "config.h" #include "macro.h" #include "util.h" #include "ioprio.h" @@ -5778,6 +5785,11 @@ void *xbsearch_r(const void *key, const void *base, size_t nmemb, size_t size, return NULL; } +void init_gettext(void) { + setlocale(LC_ALL, ""); + textdomain(GETTEXT_PACKAGE); +} + bool is_locale_utf8(void) { const char *set; static int cached_answer = -1; @@ -6452,7 +6464,7 @@ int container_get_leader(const char *machine, pid_t *pid) { assert(machine); assert(pid); - p = strappenda("/run/systemd/machines/", machine); + p = strjoina("/run/systemd/machines/", machine); r = parse_env_file(p, NEWLINE, "LEADER", &s, "CLASS", &class, NULL); if (r == -ENOENT) return -EHOSTDOWN; @@ -6691,7 +6703,7 @@ int open_tmpfile(const char *path, int flags) { #endif /* Fall back to unguessable name + unlinking */ - p = strappenda(path, "/systemd-tmp-XXXXXX"); + p = strjoina(path, "/systemd-tmp-XXXXXX"); fd = mkostemp_safe(p, flags); if (fd < 0) @@ -7220,7 +7232,7 @@ int take_password_lock(const char *root) { * awfully racy, and thus we just won't do them. */ if (root) - path = strappenda(root, "/etc/.pwd.lock"); + path = strjoina(root, "/etc/.pwd.lock"); else path = "/etc/.pwd.lock"; @@ -8085,3 +8097,26 @@ int syslog_parse_priority(const char **p, int *priority, bool with_facility) { *p += k; return 1; } + +ssize_t string_table_lookup(const char * const *table, size_t len, const char *key) { + size_t i; + + if (!key) + return -1; + + for (i = 0; i < len; ++i) + if (streq_ptr(table[i], key)) + return (ssize_t)i; + + return -1; +} + +void cmsg_close_all(struct msghdr *mh) { + struct cmsghdr *cmsg; + + assert(mh); + + for (cmsg = CMSG_FIRSTHDR(mh); cmsg; cmsg = CMSG_NXTHDR(mh, cmsg)) + if (cmsg->cmsg_level == SOL_SOCKET && cmsg->cmsg_type == SCM_RIGHTS) + close_many((int*) CMSG_DATA(cmsg), (cmsg->cmsg_len - CMSG_LEN(0)) / sizeof(int)); +}