libbasic_la_SOURCES = \
src/basic/missing.h \
+ src/basic/musl_missing.h \
+ src/basic/musl_missing.c \
src/basic/capability.c \
src/basic/capability.h \
src/basic/conf-files.c \
src/basic/rm-rf.c \
src/basic/rm-rf.h \
src/basic/copy.c \
- src/basic/copy.h
+ src/basic/copy.h \
+ src/basic/parse-printf-format.c \
+ src/basic/parse-printf-format.h
nodist_libbasic_la_SOURCES = \
src/basic/errno-from-name.h \
# Find running cgroup controller
with_cgroupctrl=
AS_IF( [test -f /proc/self/cgroup],
- [with_cgroupctrl=`grep "^1:" /proc/self/cgroup | cut -d ':' -f 2`])
+ [with_cgroupctrl=`grep "^1:name=" /proc/self/cgroup | cut -d ':' -f 2`])
AS_IF( [test -z "$with_cgroupctrl"],
- AC_MSG_ERROR([No running cgroup controller found]))
+ [with_cgroupctrl="name=elogind"])
# ------------------------------------------------------------------------------
AC_CHECK_HEADERS([linux/btrfs.h], [], [])
AC_CHECK_HEADERS([linux/memfd.h], [], [])
+AC_CHECK_HEADERS([printf.h], [have_printf_h=yes], [have_printf_h=no])
+AS_IF([test x$have_printf_h = xyes], [
+ AC_DEFINE(HAVE_PRINTF_H, 1, [Define if printf.h was found])
+])
+
+
+
# unconditionally pull-in librt with old glibc versions
dnl AC_SEARCH_LIBS([clock_gettime], [rt], [], [])
dnl AC_SEARCH_LIBS([mq_unlink], [rt], [], [])
if (e)
return e;
- return controller;
+ return controller;
}
static int join_path_legacy(const char *controller, const char *path, const char *suffix, char **fs) {
r = join_path_unified(path, suffix, fs);
else
r = join_path_legacy(controller, path, suffix, fs);
- if (r < 0)
- return r;
+
+ if (r < 0)
+ return r;
path_kill_slashes(*fs);
return 0;
}
fs = procfs_file_alloca(pid, "cgroup");
+ log_debug_elogind("Searching for PID %u in \"%s\" (controller \"%s\")",
+ pid, fs, controller);
f = fopen(fs, "re");
if (!f)
return errno == ENOENT ? -ESRCH : -errno;
continue;
}
+ log_debug_elogind("Found %s:%s", line, e+1);
p = strdup(e + 1);
if (!p)
return -ENOMEM;
* via the "cgroup.populated" attribute. */
r = cg_get_path(controller, path, "cgroup.populated", &populated);
- if (r < 0)
- return r;
+ if (r < 0)
+ return r;
r = read_one_line_file(populated, &t);
if (r == -ENOENT)
return streq(t, "0");
} else {
- _cleanup_closedir_ DIR *d = NULL;
- char *fn;
+ _cleanup_closedir_ DIR *d = NULL;
+ char *fn;
r = cg_is_empty(controller, path);
- if (r <= 0)
- return r;
+ if (r <= 0)
+ return r;
- r = cg_enumerate_subgroups(controller, path, &d);
- if (r == -ENOENT)
- return 1;
- if (r < 0)
+ r = cg_enumerate_subgroups(controller, path, &d);
+ if (r == -ENOENT)
+ return 1;
+ if (r < 0)
return r;
- while ((r = cg_read_subgroup(d, &fn)) > 0) {
- _cleanup_free_ char *p = NULL;
+ while ((r = cg_read_subgroup(d, &fn)) > 0) {
+ _cleanup_free_ char *p = NULL;
- p = strjoin(path, "/", fn, NULL);
- free(fn);
- if (!p)
- return -ENOMEM;
+ p = strjoin(path, "/", fn, NULL);
+ free(fn);
+ if (!p)
+ return -ENOMEM;
r = cg_is_empty_recursive(controller, p);
- if (r <= 0)
+ if (r <= 0)
+ return r;
+ }
+ if (r < 0)
return r;
- }
- if (r < 0)
- return r;
return true;
}
if (memcmp(p, n, l) != 0)
continue;
- need_prefix = true;
+ need_prefix = true;
break;
}
}
if (need_prefix)
return strappend("_", p);
- return strdup(p);
+ return strdup(p);
}
char *cg_unescape(const char *p) {
#include <sys/socket.h>
#include <sys/un.h>
#include <stddef.h>
-#include <printf.h>
+#include "parse-printf-format.h"
#include "sd-messages.h"
#include "log.h"
#include "util.h"
#include <linux/capability.h>
#include <linux/neighbour.h>
+#include "musl_missing.h"
+
#ifdef ARCH_MIPS
#include <asm/sgidefs.h>
#endif
--- /dev/null
+#ifndef __GLIBC__
+#include <string.h>
+#include "util.h"
+
+char *program_invocation_name = NULL;
+char *program_invocation_short_name = NULL;
+#endif // __GLIBC__
+
+#include "musl_missing.h"
+
+static void elogind_free_program_name(void) {
+#ifndef __GLIBC__
+ if (program_invocation_name)
+ program_invocation_name = mfree(program_invocation_name);
+ if (program_invocation_short_name)
+ program_invocation_short_name = mfree(program_invocation_short_name);
+#endif // __GLIBC__
+}
+
+void elogind_set_program_name(const char* pcall) {
+ assert(pcall && pcall[0]);
+ elogind_free_program_name();
+#ifndef __GLIBC__
+ program_invocation_name = strdup(pcall);
+ program_invocation_short_name = strdup(basename(pcall));
+ atexit(elogind_free_program_name);
+#endif // __GLIBC__
+}
+
--- /dev/null
+#pragma once
+#ifndef ELOGIND_BASIC_MUSL_MISSING_H_INCLUDED
+#define ELOGIND_BASIC_MUSL_MISSING_H_INCLUDED
+
+
+/****************************************************************
+ * musl_missing.h - work around glibc extensions for musl libc.
+ *
+ * Implements glibc functions missing in musl libc as macros.
+ * Is to be included where these functions are used.
+ * Also defines some glibc only constants as either 0 or
+ * as found in the corresponding glibc header file.
+ *
+ * Juergen Buchmueller <pullmoll@t-online.de> for Void Linux
+ * Public Domain; no warranties whatsoever. Thank you Mr. P.
+ *
+ ****************************************************************/
+
+
+void elogind_set_program_name(const char* pcall);
+
+#if !defined(__GLIBC__)
+#include "config.h"
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#define strerror_r(e, m, k) (strerror_r(e, m, k) < 0 ? strdup("strerror_r() failed") : m);
+
+#ifndef _ERRNO_H
+extern char *program_invocation_name;
+extern char *program_invocation_short_name;
+#endif // errno.h included beforehand
+
+/*
+ * Possibly TODO according to http://man7.org/linux/man-pages/man3/getenv.3.html
+ * + test if the process's effective user ID does not match its real user ID or
+ * the process's effective group ID does not match its real group ID;
+ * typically this is the result of executing a set-user-ID or set-
+ * group-ID program. Is calling issetugid() sufficient here?
+ * + test if the effective capability bit was set on the executable file
+ * + test if the process has a nonempty permitted capability set
+ */
+#if !defined(HAVE_SECURE_GETENV) && !defined(HAVE___SECURE_GETENV)
+# define secure_getenv(name) \
+ (issetugid() ? NULL : getenv(name))
+# define HAVE_SECURE_GETENV 1
+#endif // HAVE_[__]SECURE_GETENV
+
+/* Poor man's basename */
+#define basename(path) \
+ (strrchr(path, '/') ? strrchr(path, '/')+1 : path)
+
+/* strndupa may already be defined in another compatibility header */
+#if !defined(strndupa)
+#define strndupa(src, n) \
+ (__extension__ ({const char *in = (src); \
+ size_t len = strnlen(in, (n)) + 1; \
+ char *out = (char *) alloca(len); \
+ out[len-1] = '\0'; \
+ (char *) memcpy(out, in, len-1);}) \
+ )
+#endif
+
+/* See http://man7.org/linux/man-pages/man3/canonicalize_file_name.3.html */
+#define canonicalize_file_name(path) \
+ realpath(path, NULL)
+
+typedef int (*__compar_fn_t)(const void *, const void *);
+
+/* GLOB_BRACE is another glibc extension - ignore it for musl libc */
+#define GLOB_BRACE 0
+
+/* getnameinfo(3) glibc extensions are undefined in musl libc */
+#define NI_IDN 0
+#define NI_IDN_USE_STD3_ASCII_RULES 0
+
+/* Taken from glibc's net/if_arp.h */
+#if !defined(ARPHRD_IEEE802154_PHY)
+#define ARPHRD_IEEE802154_PHY 805 /* IEEE 802.15.4 PHY header. */
+#endif
+
+/* Shorthand for type of comparison functions. */
+#ifndef __COMPAR_FN_T
+# define __COMPAR_FN_T
+typedef int (*__compar_fn_t) (const void *, const void *);
+typedef __compar_fn_t comparison_fn_t;
+#endif
+
+
+#endif // !defined(__GLIBC__)
+
+#endif // ELOGIND_BASIC_MUSL_MISSING_H_INCLUDED
+
--- /dev/null
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
+
+/***
+ This file is part of systemd.
+
+ Copyright 2014 Emil Renner Berthing <systemd@esmil.dk>
+
+ With parts from the musl C library
+ Copyright 2005-2014 Rich Felker, et al.
+
+ systemd is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 2.1 of the License, or
+ (at your option) any later version.
+
+ systemd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with systemd; If not, see <http://www.gnu.org/licenses/>.
+***/
+
+#include <stddef.h>
+#include <string.h>
+
+#include "parse-printf-format.h"
+
+#ifndef HAVE_PRINTF_H
+
+static const char *consume_nonarg(const char *fmt)
+{
+ do {
+ if (*fmt == '\0')
+ return fmt;
+ } while (*fmt++ != '%');
+ return fmt;
+}
+
+static const char *consume_num(const char *fmt)
+{
+ for (;*fmt >= '0' && *fmt <= '9'; fmt++)
+ /* do nothing */;
+ return fmt;
+}
+
+static const char *consume_argn(const char *fmt, size_t *arg)
+{
+ const char *p = fmt;
+ size_t val = 0;
+
+ if (*p < '1' || *p > '9')
+ return fmt;
+ do {
+ val = 10*val + (*p++ - '0');
+ } while (*p >= '0' && *p <= '9');
+
+ if (*p != '$')
+ return fmt;
+ *arg = val;
+ return p+1;
+}
+
+static const char *consume_flags(const char *fmt)
+{
+ while (1) {
+ switch (*fmt) {
+ case '#':
+ case '0':
+ case '-':
+ case ' ':
+ case '+':
+ case '\'':
+ case 'I':
+ fmt++;
+ continue;
+ }
+ return fmt;
+ }
+}
+
+enum state {
+ BARE,
+ LPRE,
+ LLPRE,
+ HPRE,
+ HHPRE,
+ BIGLPRE,
+ ZTPRE,
+ JPRE,
+ STOP
+};
+
+enum type {
+ NONE,
+ PTR,
+ INT,
+ UINT,
+ ULLONG,
+ LONG,
+ ULONG,
+ SHORT,
+ USHORT,
+ CHAR,
+ UCHAR,
+ LLONG,
+ SIZET,
+ IMAX,
+ UMAX,
+ PDIFF,
+ UIPTR,
+ DBL,
+ LDBL,
+ MAXTYPE
+};
+
+static const short pa_types[MAXTYPE] = {
+ [NONE] = PA_INT,
+ [PTR] = PA_POINTER,
+ [INT] = PA_INT,
+ [UINT] = PA_INT,
+ [ULLONG] = PA_INT | PA_FLAG_LONG_LONG,
+ [LONG] = PA_INT | PA_FLAG_LONG,
+ [ULONG] = PA_INT | PA_FLAG_LONG,
+ [SHORT] = PA_INT | PA_FLAG_SHORT,
+ [USHORT] = PA_INT | PA_FLAG_SHORT,
+ [CHAR] = PA_CHAR,
+ [UCHAR] = PA_CHAR,
+ [LLONG] = PA_INT | PA_FLAG_LONG_LONG,
+ [SIZET] = PA_INT | PA_FLAG_LONG,
+ [IMAX] = PA_INT | PA_FLAG_LONG_LONG,
+ [UMAX] = PA_INT | PA_FLAG_LONG_LONG,
+ [PDIFF] = PA_INT | PA_FLAG_LONG_LONG,
+ [UIPTR] = PA_INT | PA_FLAG_LONG,
+ [DBL] = PA_DOUBLE,
+ [LDBL] = PA_DOUBLE | PA_FLAG_LONG_DOUBLE
+};
+
+#define S(x) [(x)-'A']
+#define E(x) (STOP + (x))
+
+static const unsigned char states[]['z'-'A'+1] = {
+ { /* 0: bare types */
+ S('d') = E(INT), S('i') = E(INT),
+ S('o') = E(UINT),S('u') = E(UINT),S('x') = E(UINT), S('X') = E(UINT),
+ S('e') = E(DBL), S('f') = E(DBL), S('g') = E(DBL), S('a') = E(DBL),
+ S('E') = E(DBL), S('F') = E(DBL), S('G') = E(DBL), S('A') = E(DBL),
+ S('c') = E(CHAR),S('C') = E(INT),
+ S('s') = E(PTR), S('S') = E(PTR), S('p') = E(UIPTR),S('n') = E(PTR),
+ S('m') = E(NONE),
+ S('l') = LPRE, S('h') = HPRE, S('L') = BIGLPRE,
+ S('z') = ZTPRE, S('j') = JPRE, S('t') = ZTPRE
+ }, { /* 1: l-prefixed */
+ S('d') = E(LONG), S('i') = E(LONG),
+ S('o') = E(ULONG),S('u') = E(ULONG),S('x') = E(ULONG),S('X') = E(ULONG),
+ S('e') = E(DBL), S('f') = E(DBL), S('g') = E(DBL), S('a') = E(DBL),
+ S('E') = E(DBL), S('F') = E(DBL), S('G') = E(DBL), S('A') = E(DBL),
+ S('c') = E(INT), S('s') = E(PTR), S('n') = E(PTR),
+ S('l') = LLPRE
+ }, { /* 2: ll-prefixed */
+ S('d') = E(LLONG), S('i') = E(LLONG),
+ S('o') = E(ULLONG),S('u') = E(ULLONG),
+ S('x') = E(ULLONG),S('X') = E(ULLONG),
+ S('n') = E(PTR)
+ }, { /* 3: h-prefixed */
+ S('d') = E(SHORT), S('i') = E(SHORT),
+ S('o') = E(USHORT),S('u') = E(USHORT),
+ S('x') = E(USHORT),S('X') = E(USHORT),
+ S('n') = E(PTR),
+ S('h') = HHPRE
+ }, { /* 4: hh-prefixed */
+ S('d') = E(CHAR), S('i') = E(CHAR),
+ S('o') = E(UCHAR),S('u') = E(UCHAR),
+ S('x') = E(UCHAR),S('X') = E(UCHAR),
+ S('n') = E(PTR)
+ }, { /* 5: L-prefixed */
+ S('e') = E(LDBL),S('f') = E(LDBL),S('g') = E(LDBL), S('a') = E(LDBL),
+ S('E') = E(LDBL),S('F') = E(LDBL),S('G') = E(LDBL), S('A') = E(LDBL),
+ S('n') = E(PTR)
+ }, { /* 6: z- or t-prefixed (assumed to be same size) */
+ S('d') = E(PDIFF),S('i') = E(PDIFF),
+ S('o') = E(SIZET),S('u') = E(SIZET),
+ S('x') = E(SIZET),S('X') = E(SIZET),
+ S('n') = E(PTR)
+ }, { /* 7: j-prefixed */
+ S('d') = E(IMAX), S('i') = E(IMAX),
+ S('o') = E(UMAX), S('u') = E(UMAX),
+ S('x') = E(UMAX), S('X') = E(UMAX),
+ S('n') = E(PTR)
+ }
+};
+
+size_t parse_printf_format(const char *fmt, size_t n, int *types)
+{
+ size_t i = 0;
+ size_t last = 0;
+
+ memset(types, 0, n);
+
+ while (1) {
+ size_t arg;
+ unsigned int state;
+
+ fmt = consume_nonarg(fmt);
+ if (*fmt == '\0')
+ break;
+ if (*fmt == '%') {
+ fmt++;
+ continue;
+ }
+ arg = 0;
+ fmt = consume_argn(fmt, &arg);
+ /* flags */
+ fmt = consume_flags(fmt);
+ /* width */
+ if (*fmt == '*') {
+ size_t warg = 0;
+ fmt = consume_argn(fmt+1, &warg);
+ if (warg == 0)
+ warg = ++i;
+ if (warg > last)
+ last = warg;
+ if (warg <= n && types[warg-1] == NONE)
+ types[warg-1] = INT;
+ } else
+ fmt = consume_num(fmt);
+ /* precision */
+ if (*fmt == '.') {
+ fmt++;
+ if (*fmt == '*') {
+ size_t parg = 0;
+ fmt = consume_argn(fmt+1, &parg);
+ if (parg == 0)
+ parg = ++i;
+ if (parg > last)
+ last = parg;
+ if (parg <= n && types[parg-1] == NONE)
+ types[parg-1] = INT;
+ } else {
+ if (*fmt == '-')
+ fmt++;
+ fmt = consume_num(fmt);
+ }
+ }
+ /* length modifier and conversion specifier */
+ state = BARE;
+ do {
+ unsigned char c = *fmt++;
+
+ if (c < 'A' || c > 'z')
+ continue;
+ state = states[state]S(c);
+ if (state == 0)
+ continue;
+ } while (state < STOP);
+
+ if (state == E(NONE))
+ continue;
+
+ if (arg == 0)
+ arg = ++i;
+ if (arg > last)
+ last = arg;
+ if (arg <= n)
+ types[arg-1] = state - STOP;
+ }
+
+ if (last > n)
+ last = n;
+ for (i = 0; i < last; i++)
+ types[i] = pa_types[types[i]];
+
+ return last;
+}
+
+#endif // HAVE_PRINTF_H
--- /dev/null
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
+
+/***
+ This file is part of systemd.
+
+ Copyright 2014 Emil Renner Berthing <systemd@esmil.dk>
+
+ With parts from the GNU C Library
+ Copyright 1991-2014 Free Software Foundation, Inc.
+
+ systemd is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 2.1 of the License, or
+ (at your option) any later version.
+
+ systemd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with systemd; If not, see <http://www.gnu.org/licenses/>.
+***/
+
+#pragma once
+
+#include "config.h"
+
+#ifdef HAVE_PRINTF_H
+#include <printf.h>
+#else
+
+#include <stddef.h>
+
+enum { /* C type: */
+ PA_INT, /* int */
+ PA_CHAR, /* int, cast to char */
+ PA_WCHAR, /* wide char */
+ PA_STRING, /* const char *, a '\0'-terminated string */
+ PA_WSTRING, /* const wchar_t *, wide character string */
+ PA_POINTER, /* void * */
+ PA_FLOAT, /* float */
+ PA_DOUBLE, /* double */
+ PA_LAST
+};
+
+/* Flag bits that can be set in a type returned by `parse_printf_format'. */
+#define PA_FLAG_MASK 0xff00
+#define PA_FLAG_LONG_LONG (1 << 8)
+#define PA_FLAG_LONG_DOUBLE PA_FLAG_LONG_LONG
+#define PA_FLAG_LONG (1 << 9)
+#define PA_FLAG_SHORT (1 << 10)
+#define PA_FLAG_PTR (1 << 11)
+
+size_t parse_printf_format(const char *fmt, size_t n, int *types);
+
+#endif /* HAVE_PRINTF_H */
+
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
+#include <sys/types.h>
#include <sys/socket.h>
#include <stdbool.h>
uint8_t raw[INOTIFY_EVENT_MAX];
};
-#define laccess(path, mode) faccessat(AT_FDCWD, (path), (mode), AT_SYMLINK_NOFOLLOW)
+#ifdef __GLIBC__
+ #define laccess(path, mode) faccessat(AT_FDCWD, (path), (mode), AT_SYMLINK_NOFOLLOW)
+#else
+ #define laccess(path, mode) faccessat(AT_FDCWD, (path), (mode), 0)
+#endif
// UNNEEDED int ptsname_malloc(int fd, char **ret);
return EXIT_FAILURE;
}
+ elogind_set_program_name(argv[0]);
log_set_target(LOG_TARGET_AUTO);
log_parse_environment();
log_open();
if (i->f)
fclose(i->f);
- free(i->introspection);
+ free(i->introspection);
zero(*i);
}
}
int main(int argc, char* argv[]) {
+ elogind_set_program_name(argv[0]);
log_parse_environment();
log_open();
_cleanup_bus_flush_close_unref_ sd_bus *bus = NULL;
int r;
+ elogind_set_program_name(argv[0]);
log_parse_environment();
log_open();
int r;
setlocale(LC_ALL, "");
+ elogind_set_program_name(argv[0]);
log_parse_environment();
log_open();
Manager *m = NULL;
int r;
+ elogind_set_program_name(argv[0]);
log_set_target(LOG_TARGET_AUTO);
log_set_facility(LOG_AUTH);
log_parse_environment();
#include "macro.h"
#include "login-util.h"
+#include "musl_missing.h"
static void test_session_id_valid(void) {
assert_se(session_id_valid("c1"));
}
int main(int argc, char* argv[]) {
+ elogind_set_program_name(argv[0]);
log_parse_environment();
log_open();
/* Inform pager that we are done */
fclose(stdout);
+#if defined(__GLIBC__)
stdout = NULL;
+#endif // in musl-libc this is a const
fclose(stderr);
+#if defined(__GLIBC__)
stderr = NULL;
+#endif // in musl-libc this is a const
kill(pager_pid, SIGCONT);
(void) wait_for_terminate(pager_pid, NULL);