Merge pull request #1654 from poettering/util-lib
Various changes to src/basic/
This commit is contained in:
+10
-2
@@ -781,6 +781,14 @@ libbasic_la_SOURCES = \
|
||||
src/basic/refcnt.h \
|
||||
src/basic/util.c \
|
||||
src/basic/util.h \
|
||||
src/basic/string-util.c \
|
||||
src/basic/string-util.h \
|
||||
src/basic/fd-util.c \
|
||||
src/basic/fd-util.h \
|
||||
src/basic/extract-word.c \
|
||||
src/basic/extract-word.h \
|
||||
src/basic/escape.c \
|
||||
src/basic/escape.h \
|
||||
src/basic/cpu-set-util.c \
|
||||
src/basic/cpu-set-util.h \
|
||||
src/basic/lockfile-util.c \
|
||||
@@ -899,7 +907,8 @@ libbasic_la_SOURCES = \
|
||||
src/basic/rm-rf.c \
|
||||
src/basic/rm-rf.h \
|
||||
src/basic/copy.c \
|
||||
src/basic/copy.h
|
||||
src/basic/copy.h \
|
||||
src/basic/formats-util.h
|
||||
|
||||
nodist_libbasic_la_SOURCES = \
|
||||
src/basic/errno-from-name.h \
|
||||
@@ -939,7 +948,6 @@ libshared_la_SOURCES = \
|
||||
src/shared/architecture.h \
|
||||
src/shared/efivars.c \
|
||||
src/shared/efivars.h \
|
||||
src/shared/formats-util.h \
|
||||
src/shared/fstab-util.c \
|
||||
src/shared/fstab-util.h \
|
||||
src/shared/sleep-config.c \
|
||||
|
||||
@@ -850,7 +850,7 @@
|
||||
<example>
|
||||
<title>Build and boot a minimal Fedora distribution in a container</title>
|
||||
|
||||
<programlisting># dnf -y --releasever=23 --installroot=/srv/mycontainer --disablerepo=* --enablerepo=fedora --enablerepo=updates install systemd passwd dnf fedora-release vim-minimal
|
||||
<programlisting># dnf -y --releasever=23 --installroot=/srv/mycontainer --disablerepo='*' --enablerepo=fedora --enablerepo=updates install systemd passwd dnf fedora-release vim-minimal
|
||||
# systemd-nspawn -bD /srv/mycontainer</programlisting>
|
||||
|
||||
<para>This installs a minimal Fedora distribution into the
|
||||
|
||||
@@ -32,7 +32,9 @@
|
||||
#include "macro.h"
|
||||
#include "signal-util.h"
|
||||
#include "socket-util.h"
|
||||
#include "string-util.h"
|
||||
#include "strv.h"
|
||||
#include "fd-util.h"
|
||||
|
||||
static char** arg_listen = NULL;
|
||||
static bool arg_accept = false;
|
||||
|
||||
@@ -19,12 +19,15 @@
|
||||
along with systemd; If not, see <http://www.gnu.org/licenses/>.
|
||||
***/
|
||||
|
||||
#include "util.h"
|
||||
#include "mkdir.h"
|
||||
#include "fileio.h"
|
||||
#include "libudev.h"
|
||||
#include "udev-util.h"
|
||||
|
||||
#include "def.h"
|
||||
#include "escape.h"
|
||||
#include "fileio.h"
|
||||
#include "mkdir.h"
|
||||
#include "string-util.h"
|
||||
#include "udev-util.h"
|
||||
#include "util.h"
|
||||
|
||||
static struct udev_device *find_pci_or_platform_parent(struct udev_device *device) {
|
||||
struct udev_device *parent;
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#include <unistd.h>
|
||||
|
||||
#include "async.h"
|
||||
#include "fd-util.h"
|
||||
#include "log.h"
|
||||
#include "util.h"
|
||||
|
||||
|
||||
+4
-3
@@ -22,11 +22,12 @@
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "macro.h"
|
||||
#include "audit.h"
|
||||
#include "util.h"
|
||||
#include "process-util.h"
|
||||
#include "fd-util.h"
|
||||
#include "fileio.h"
|
||||
#include "macro.h"
|
||||
#include "process-util.h"
|
||||
#include "util.h"
|
||||
|
||||
int audit_session_from_pid(pid_t pid, uint32_t *id) {
|
||||
_cleanup_free_ char *s = NULL;
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
#include <unistd.h>
|
||||
|
||||
#include "barrier.h"
|
||||
#include "fd-util.h"
|
||||
#include "macro.h"
|
||||
#include "util.h"
|
||||
|
||||
|
||||
+11
-10
@@ -20,23 +20,24 @@
|
||||
***/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <sys/vfs.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <sys/vfs.h>
|
||||
#ifdef HAVE_LINUX_BTRFS_H
|
||||
#include <linux/btrfs.h>
|
||||
#endif
|
||||
|
||||
#include "missing.h"
|
||||
#include "util.h"
|
||||
#include "path-util.h"
|
||||
#include "macro.h"
|
||||
#include "copy.h"
|
||||
#include "selinux-util.h"
|
||||
#include "smack-util.h"
|
||||
#include "fileio.h"
|
||||
#include "btrfs-ctree.h"
|
||||
#include "btrfs-util.h"
|
||||
#include "copy.h"
|
||||
#include "fd-util.h"
|
||||
#include "fileio.h"
|
||||
#include "macro.h"
|
||||
#include "missing.h"
|
||||
#include "path-util.h"
|
||||
#include "selinux-util.h"
|
||||
#include "smack-util.h"
|
||||
#include "string-util.h"
|
||||
#include "util.h"
|
||||
|
||||
/* WARNING: Be careful with file system ioctls! When we get an fd, we
|
||||
* need to make sure it either refers to only a regular file or
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "string-util.h"
|
||||
#include "calendarspec.h"
|
||||
|
||||
#define BITS_WEEKDAYS 127
|
||||
|
||||
@@ -19,18 +19,18 @@
|
||||
along with systemd; If not, see <http://www.gnu.org/licenses/>.
|
||||
***/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <grp.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/capability.h>
|
||||
#include <sys/prctl.h>
|
||||
#include "grp.h"
|
||||
#include <unistd.h>
|
||||
|
||||
#include "capability.h"
|
||||
#include "fileio.h"
|
||||
#include "log.h"
|
||||
#include "macro.h"
|
||||
#include "util.h"
|
||||
#include "log.h"
|
||||
#include "fileio.h"
|
||||
#include "capability.h"
|
||||
|
||||
int have_effective_cap(int value) {
|
||||
_cleanup_cap_free_ cap_t cap;
|
||||
|
||||
+20
-17
@@ -19,28 +19,31 @@
|
||||
along with systemd; If not, see <http://www.gnu.org/licenses/>.
|
||||
***/
|
||||
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <dirent.h>
|
||||
#include <errno.h>
|
||||
#include <ftw.h>
|
||||
#include <signal.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <ftw.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "set.h"
|
||||
#include "macro.h"
|
||||
#include "util.h"
|
||||
#include "formats-util.h"
|
||||
#include "process-util.h"
|
||||
#include "path-util.h"
|
||||
#include "unit-name.h"
|
||||
#include "fileio.h"
|
||||
#include "special.h"
|
||||
#include "mkdir.h"
|
||||
#include "login-util.h"
|
||||
#include "cgroup-util.h"
|
||||
#include "extract-word.h"
|
||||
#include "fd-util.h"
|
||||
#include "fileio.h"
|
||||
#include "formats-util.h"
|
||||
#include "login-util.h"
|
||||
#include "macro.h"
|
||||
#include "mkdir.h"
|
||||
#include "path-util.h"
|
||||
#include "process-util.h"
|
||||
#include "set.h"
|
||||
#include "special.h"
|
||||
#include "string-util.h"
|
||||
#include "unit-name.h"
|
||||
#include "util.h"
|
||||
|
||||
int cg_enumerate_processes(const char *controller, const char *path, FILE **_f) {
|
||||
_cleanup_free_ char *fs = NULL;
|
||||
|
||||
@@ -20,15 +20,17 @@
|
||||
***/
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <fcntl.h>
|
||||
#include <linux/rtc.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/time.h>
|
||||
#include <linux/rtc.h>
|
||||
|
||||
#include "macro.h"
|
||||
#include "util.h"
|
||||
#include "clock-util.h"
|
||||
#include "fd-util.h"
|
||||
#include "macro.h"
|
||||
#include "string-util.h"
|
||||
#include "util.h"
|
||||
|
||||
int clock_get_hwclock(struct tm *tm) {
|
||||
_cleanup_close_ int fd = -1;
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
along with systemd; If not, see <http://www.gnu.org/licenses/>.
|
||||
***/
|
||||
|
||||
#include <time.h>
|
||||
|
||||
int clock_is_localtime(void);
|
||||
int clock_set_timezone(int *min);
|
||||
|
||||
+13
-11
@@ -19,20 +19,22 @@
|
||||
along with systemd; If not, see <http://www.gnu.org/licenses/>.
|
||||
***/
|
||||
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <dirent.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "macro.h"
|
||||
#include "util.h"
|
||||
#include "missing.h"
|
||||
#include "log.h"
|
||||
#include "strv.h"
|
||||
#include "path-util.h"
|
||||
#include "hashmap.h"
|
||||
#include "conf-files.h"
|
||||
#include "fd-util.h"
|
||||
#include "hashmap.h"
|
||||
#include "log.h"
|
||||
#include "macro.h"
|
||||
#include "missing.h"
|
||||
#include "path-util.h"
|
||||
#include "string-util.h"
|
||||
#include "strv.h"
|
||||
#include "util.h"
|
||||
|
||||
static int files_add(Hashmap *h, const char *root, const char *path, const char *suffix) {
|
||||
_cleanup_closedir_ DIR *dir = NULL;
|
||||
|
||||
+4
-2
@@ -22,10 +22,12 @@
|
||||
#include <sys/sendfile.h>
|
||||
#include <sys/xattr.h>
|
||||
|
||||
#include "util.h"
|
||||
#include "btrfs-util.h"
|
||||
#include "strv.h"
|
||||
#include "copy.h"
|
||||
#include "fd-util.h"
|
||||
#include "string-util.h"
|
||||
#include "strv.h"
|
||||
#include "util.h"
|
||||
|
||||
#define COPY_BUFFER_SIZE (16*1024)
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
along with systemd; If not, see <http://www.gnu.org/licenses/>.
|
||||
***/
|
||||
|
||||
#include "extract-word.h"
|
||||
#include "util.h"
|
||||
#include "cpu-set-util.h"
|
||||
|
||||
|
||||
@@ -22,11 +22,12 @@
|
||||
#include <limits.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "def.h"
|
||||
#include "string-util.h"
|
||||
#include "strv.h"
|
||||
#include "utf8.h"
|
||||
#include "util.h"
|
||||
#include "env-util.h"
|
||||
#include "def.h"
|
||||
|
||||
#define VALID_CHARS_ENV_NAME \
|
||||
DIGITS LETTERS \
|
||||
|
||||
@@ -0,0 +1,480 @@
|
||||
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
|
||||
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
Copyright 2010 Lennart Poettering
|
||||
|
||||
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 "utf8.h"
|
||||
#include "util.h"
|
||||
|
||||
#include "escape.h"
|
||||
|
||||
size_t cescape_char(char c, char *buf) {
|
||||
char * buf_old = buf;
|
||||
|
||||
switch (c) {
|
||||
|
||||
case '\a':
|
||||
*(buf++) = '\\';
|
||||
*(buf++) = 'a';
|
||||
break;
|
||||
case '\b':
|
||||
*(buf++) = '\\';
|
||||
*(buf++) = 'b';
|
||||
break;
|
||||
case '\f':
|
||||
*(buf++) = '\\';
|
||||
*(buf++) = 'f';
|
||||
break;
|
||||
case '\n':
|
||||
*(buf++) = '\\';
|
||||
*(buf++) = 'n';
|
||||
break;
|
||||
case '\r':
|
||||
*(buf++) = '\\';
|
||||
*(buf++) = 'r';
|
||||
break;
|
||||
case '\t':
|
||||
*(buf++) = '\\';
|
||||
*(buf++) = 't';
|
||||
break;
|
||||
case '\v':
|
||||
*(buf++) = '\\';
|
||||
*(buf++) = 'v';
|
||||
break;
|
||||
case '\\':
|
||||
*(buf++) = '\\';
|
||||
*(buf++) = '\\';
|
||||
break;
|
||||
case '"':
|
||||
*(buf++) = '\\';
|
||||
*(buf++) = '"';
|
||||
break;
|
||||
case '\'':
|
||||
*(buf++) = '\\';
|
||||
*(buf++) = '\'';
|
||||
break;
|
||||
|
||||
default:
|
||||
/* For special chars we prefer octal over
|
||||
* hexadecimal encoding, simply because glib's
|
||||
* g_strescape() does the same */
|
||||
if ((c < ' ') || (c >= 127)) {
|
||||
*(buf++) = '\\';
|
||||
*(buf++) = octchar((unsigned char) c >> 6);
|
||||
*(buf++) = octchar((unsigned char) c >> 3);
|
||||
*(buf++) = octchar((unsigned char) c);
|
||||
} else
|
||||
*(buf++) = c;
|
||||
break;
|
||||
}
|
||||
|
||||
return buf - buf_old;
|
||||
}
|
||||
|
||||
char *cescape(const char *s) {
|
||||
char *r, *t;
|
||||
const char *f;
|
||||
|
||||
assert(s);
|
||||
|
||||
/* Does C style string escaping. May be reversed with
|
||||
* cunescape(). */
|
||||
|
||||
r = new(char, strlen(s)*4 + 1);
|
||||
if (!r)
|
||||
return NULL;
|
||||
|
||||
for (f = s, t = r; *f; f++)
|
||||
t += cescape_char(*f, t);
|
||||
|
||||
*t = 0;
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
int cunescape_one(const char *p, size_t length, char *ret, uint32_t *ret_unicode) {
|
||||
int r = 1;
|
||||
|
||||
assert(p);
|
||||
assert(*p);
|
||||
assert(ret);
|
||||
|
||||
/* Unescapes C style. Returns the unescaped character in ret,
|
||||
* unless we encountered a \u sequence in which case the full
|
||||
* unicode character is returned in ret_unicode, instead. */
|
||||
|
||||
if (length != (size_t) -1 && length < 1)
|
||||
return -EINVAL;
|
||||
|
||||
switch (p[0]) {
|
||||
|
||||
case 'a':
|
||||
*ret = '\a';
|
||||
break;
|
||||
case 'b':
|
||||
*ret = '\b';
|
||||
break;
|
||||
case 'f':
|
||||
*ret = '\f';
|
||||
break;
|
||||
case 'n':
|
||||
*ret = '\n';
|
||||
break;
|
||||
case 'r':
|
||||
*ret = '\r';
|
||||
break;
|
||||
case 't':
|
||||
*ret = '\t';
|
||||
break;
|
||||
case 'v':
|
||||
*ret = '\v';
|
||||
break;
|
||||
case '\\':
|
||||
*ret = '\\';
|
||||
break;
|
||||
case '"':
|
||||
*ret = '"';
|
||||
break;
|
||||
case '\'':
|
||||
*ret = '\'';
|
||||
break;
|
||||
|
||||
case 's':
|
||||
/* This is an extension of the XDG syntax files */
|
||||
*ret = ' ';
|
||||
break;
|
||||
|
||||
case 'x': {
|
||||
/* hexadecimal encoding */
|
||||
int a, b;
|
||||
|
||||
if (length != (size_t) -1 && length < 3)
|
||||
return -EINVAL;
|
||||
|
||||
a = unhexchar(p[1]);
|
||||
if (a < 0)
|
||||
return -EINVAL;
|
||||
|
||||
b = unhexchar(p[2]);
|
||||
if (b < 0)
|
||||
return -EINVAL;
|
||||
|
||||
/* Don't allow NUL bytes */
|
||||
if (a == 0 && b == 0)
|
||||
return -EINVAL;
|
||||
|
||||
*ret = (char) ((a << 4U) | b);
|
||||
r = 3;
|
||||
break;
|
||||
}
|
||||
|
||||
case 'u': {
|
||||
/* C++11 style 16bit unicode */
|
||||
|
||||
int a[4];
|
||||
unsigned i;
|
||||
uint32_t c;
|
||||
|
||||
if (length != (size_t) -1 && length < 5)
|
||||
return -EINVAL;
|
||||
|
||||
for (i = 0; i < 4; i++) {
|
||||
a[i] = unhexchar(p[1 + i]);
|
||||
if (a[i] < 0)
|
||||
return a[i];
|
||||
}
|
||||
|
||||
c = ((uint32_t) a[0] << 12U) | ((uint32_t) a[1] << 8U) | ((uint32_t) a[2] << 4U) | (uint32_t) a[3];
|
||||
|
||||
/* Don't allow 0 chars */
|
||||
if (c == 0)
|
||||
return -EINVAL;
|
||||
|
||||
if (c < 128)
|
||||
*ret = c;
|
||||
else {
|
||||
if (!ret_unicode)
|
||||
return -EINVAL;
|
||||
|
||||
*ret = 0;
|
||||
*ret_unicode = c;
|
||||
}
|
||||
|
||||
r = 5;
|
||||
break;
|
||||
}
|
||||
|
||||
case 'U': {
|
||||
/* C++11 style 32bit unicode */
|
||||
|
||||
int a[8];
|
||||
unsigned i;
|
||||
uint32_t c;
|
||||
|
||||
if (length != (size_t) -1 && length < 9)
|
||||
return -EINVAL;
|
||||
|
||||
for (i = 0; i < 8; i++) {
|
||||
a[i] = unhexchar(p[1 + i]);
|
||||
if (a[i] < 0)
|
||||
return a[i];
|
||||
}
|
||||
|
||||
c = ((uint32_t) a[0] << 28U) | ((uint32_t) a[1] << 24U) | ((uint32_t) a[2] << 20U) | ((uint32_t) a[3] << 16U) |
|
||||
((uint32_t) a[4] << 12U) | ((uint32_t) a[5] << 8U) | ((uint32_t) a[6] << 4U) | (uint32_t) a[7];
|
||||
|
||||
/* Don't allow 0 chars */
|
||||
if (c == 0)
|
||||
return -EINVAL;
|
||||
|
||||
/* Don't allow invalid code points */
|
||||
if (!unichar_is_valid(c))
|
||||
return -EINVAL;
|
||||
|
||||
if (c < 128)
|
||||
*ret = c;
|
||||
else {
|
||||
if (!ret_unicode)
|
||||
return -EINVAL;
|
||||
|
||||
*ret = 0;
|
||||
*ret_unicode = c;
|
||||
}
|
||||
|
||||
r = 9;
|
||||
break;
|
||||
}
|
||||
|
||||
case '0':
|
||||
case '1':
|
||||
case '2':
|
||||
case '3':
|
||||
case '4':
|
||||
case '5':
|
||||
case '6':
|
||||
case '7': {
|
||||
/* octal encoding */
|
||||
int a, b, c;
|
||||
uint32_t m;
|
||||
|
||||
if (length != (size_t) -1 && length < 3)
|
||||
return -EINVAL;
|
||||
|
||||
a = unoctchar(p[0]);
|
||||
if (a < 0)
|
||||
return -EINVAL;
|
||||
|
||||
b = unoctchar(p[1]);
|
||||
if (b < 0)
|
||||
return -EINVAL;
|
||||
|
||||
c = unoctchar(p[2]);
|
||||
if (c < 0)
|
||||
return -EINVAL;
|
||||
|
||||
/* don't allow NUL bytes */
|
||||
if (a == 0 && b == 0 && c == 0)
|
||||
return -EINVAL;
|
||||
|
||||
/* Don't allow bytes above 255 */
|
||||
m = ((uint32_t) a << 6U) | ((uint32_t) b << 3U) | (uint32_t) c;
|
||||
if (m > 255)
|
||||
return -EINVAL;
|
||||
|
||||
*ret = m;
|
||||
r = 3;
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
int cunescape_length_with_prefix(const char *s, size_t length, const char *prefix, UnescapeFlags flags, char **ret) {
|
||||
char *r, *t;
|
||||
const char *f;
|
||||
size_t pl;
|
||||
|
||||
assert(s);
|
||||
assert(ret);
|
||||
|
||||
/* Undoes C style string escaping, and optionally prefixes it. */
|
||||
|
||||
pl = prefix ? strlen(prefix) : 0;
|
||||
|
||||
r = new(char, pl+length+1);
|
||||
if (!r)
|
||||
return -ENOMEM;
|
||||
|
||||
if (prefix)
|
||||
memcpy(r, prefix, pl);
|
||||
|
||||
for (f = s, t = r + pl; f < s + length; f++) {
|
||||
size_t remaining;
|
||||
uint32_t u;
|
||||
char c;
|
||||
int k;
|
||||
|
||||
remaining = s + length - f;
|
||||
assert(remaining > 0);
|
||||
|
||||
if (*f != '\\') {
|
||||
/* A literal literal, copy verbatim */
|
||||
*(t++) = *f;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (remaining == 1) {
|
||||
if (flags & UNESCAPE_RELAX) {
|
||||
/* A trailing backslash, copy verbatim */
|
||||
*(t++) = *f;
|
||||
continue;
|
||||
}
|
||||
|
||||
free(r);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
k = cunescape_one(f + 1, remaining - 1, &c, &u);
|
||||
if (k < 0) {
|
||||
if (flags & UNESCAPE_RELAX) {
|
||||
/* Invalid escape code, let's take it literal then */
|
||||
*(t++) = '\\';
|
||||
continue;
|
||||
}
|
||||
|
||||
free(r);
|
||||
return k;
|
||||
}
|
||||
|
||||
if (c != 0)
|
||||
/* Non-Unicode? Let's encode this directly */
|
||||
*(t++) = c;
|
||||
else
|
||||
/* Unicode? Then let's encode this in UTF-8 */
|
||||
t += utf8_encode_unichar(t, u);
|
||||
|
||||
f += k;
|
||||
}
|
||||
|
||||
*t = 0;
|
||||
|
||||
*ret = r;
|
||||
return t - r;
|
||||
}
|
||||
|
||||
int cunescape_length(const char *s, size_t length, UnescapeFlags flags, char **ret) {
|
||||
return cunescape_length_with_prefix(s, length, NULL, flags, ret);
|
||||
}
|
||||
|
||||
int cunescape(const char *s, UnescapeFlags flags, char **ret) {
|
||||
return cunescape_length(s, strlen(s), flags, ret);
|
||||
}
|
||||
|
||||
char *xescape(const char *s, const char *bad) {
|
||||
char *r, *t;
|
||||
const char *f;
|
||||
|
||||
/* Escapes all chars in bad, in addition to \ and all special
|
||||
* chars, in \xFF style escaping. May be reversed with
|
||||
* cunescape(). */
|
||||
|
||||
r = new(char, strlen(s) * 4 + 1);
|
||||
if (!r)
|
||||
return NULL;
|
||||
|
||||
for (f = s, t = r; *f; f++) {
|
||||
|
||||
if ((*f < ' ') || (*f >= 127) ||
|
||||
(*f == '\\') || strchr(bad, *f)) {
|
||||
*(t++) = '\\';
|
||||
*(t++) = 'x';
|
||||
*(t++) = hexchar(*f >> 4);
|
||||
*(t++) = hexchar(*f);
|
||||
} else
|
||||
*(t++) = *f;
|
||||
}
|
||||
|
||||
*t = 0;
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
static char *strcpy_backslash_escaped(char *t, const char *s, const char *bad) {
|
||||
assert(bad);
|
||||
|
||||
for (; *s; s++) {
|
||||
if (*s == '\\' || strchr(bad, *s))
|
||||
*(t++) = '\\';
|
||||
|
||||
*(t++) = *s;
|
||||
}
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
char *shell_escape(const char *s, const char *bad) {
|
||||
char *r, *t;
|
||||
|
||||
r = new(char, strlen(s)*2+1);
|
||||
if (!r)
|
||||
return NULL;
|
||||
|
||||
t = strcpy_backslash_escaped(r, s, bad);
|
||||
*t = 0;
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
char *shell_maybe_quote(const char *s) {
|
||||
const char *p;
|
||||
char *r, *t;
|
||||
|
||||
assert(s);
|
||||
|
||||
/* Encloses a string in double quotes if necessary to make it
|
||||
* OK as shell string. */
|
||||
|
||||
for (p = s; *p; p++)
|
||||
if (*p <= ' ' ||
|
||||
*p >= 127 ||
|
||||
strchr(SHELL_NEED_QUOTES, *p))
|
||||
break;
|
||||
|
||||
if (!*p)
|
||||
return strdup(s);
|
||||
|
||||
r = new(char, 1+strlen(s)*2+1+1);
|
||||
if (!r)
|
||||
return NULL;
|
||||
|
||||
t = r;
|
||||
*(t++) = '"';
|
||||
t = mempcpy(t, s, p - s);
|
||||
|
||||
t = strcpy_backslash_escaped(t, p, SHELL_NEED_ESCAPE);
|
||||
|
||||
*(t++)= '"';
|
||||
*t = 0;
|
||||
|
||||
return r;
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
|
||||
|
||||
#pragma once
|
||||
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
Copyright 2010 Lennart Poettering
|
||||
|
||||
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 <sys/types.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
/* What characters are special in the shell? */
|
||||
/* must be escaped outside and inside double-quotes */
|
||||
#define SHELL_NEED_ESCAPE "\"\\`$"
|
||||
/* can be escaped or double-quoted */
|
||||
#define SHELL_NEED_QUOTES SHELL_NEED_ESCAPE GLOB_CHARS "'()<>|&;"
|
||||
|
||||
typedef enum UnescapeFlags {
|
||||
UNESCAPE_RELAX = 1,
|
||||
} UnescapeFlags;
|
||||
|
||||
char *cescape(const char *s);
|
||||
size_t cescape_char(char c, char *buf);
|
||||
|
||||
int cunescape(const char *s, UnescapeFlags flags, char **ret);
|
||||
int cunescape_length(const char *s, size_t length, UnescapeFlags flags, char **ret);
|
||||
int cunescape_length_with_prefix(const char *s, size_t length, const char *prefix, UnescapeFlags flags, char **ret);
|
||||
int cunescape_one(const char *p, size_t length, char *ret, uint32_t *ret_unicode);
|
||||
|
||||
char *xescape(const char *s, const char *bad);
|
||||
|
||||
char *shell_escape(const char *s, const char *bad);
|
||||
char *shell_maybe_quote(const char *s);
|
||||
@@ -0,0 +1,284 @@
|
||||
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
|
||||
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
Copyright 2010 Lennart Poettering
|
||||
|
||||
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 "escape.h"
|
||||
#include "utf8.h"
|
||||
#include "util.h"
|
||||
#include "extract-word.h"
|
||||
|
||||
int extract_first_word(const char **p, char **ret, const char *separators, ExtractFlags flags) {
|
||||
_cleanup_free_ char *s = NULL;
|
||||
size_t allocated = 0, sz = 0;
|
||||
int r;
|
||||
|
||||
char quote = 0; /* 0 or ' or " */
|
||||
bool backslash = false; /* whether we've just seen a backslash */
|
||||
bool separator = false; /* whether we've just seen a separator */
|
||||
bool start = true; /* false means we're looking at a value */
|
||||
|
||||
assert(p);
|
||||
assert(ret);
|
||||
|
||||
if (!separators)
|
||||
separators = WHITESPACE;
|
||||
|
||||
/* Bail early if called after last value or with no input */
|
||||
if (!*p)
|
||||
goto finish_force_terminate;
|
||||
|
||||
/* Parses the first word of a string, and returns it in
|
||||
* *ret. Removes all quotes in the process. When parsing fails
|
||||
* (because of an uneven number of quotes or similar), leaves
|
||||
* the pointer *p at the first invalid character. */
|
||||
|
||||
for (;;) {
|
||||
char c = **p;
|
||||
|
||||
if (start) {
|
||||
if (flags & EXTRACT_DONT_COALESCE_SEPARATORS)
|
||||
if (!GREEDY_REALLOC(s, allocated, sz+1))
|
||||
return -ENOMEM;
|
||||
|
||||
if (c == 0)
|
||||
goto finish_force_terminate;
|
||||
else if (strchr(separators, c)) {
|
||||
(*p) ++;
|
||||
if (flags & EXTRACT_DONT_COALESCE_SEPARATORS)
|
||||
goto finish_force_next;
|
||||
continue;
|
||||
}
|
||||
|
||||
/* We found a non-blank character, so we will always
|
||||
* want to return a string (even if it is empty),
|
||||
* allocate it here. */
|
||||
if (!GREEDY_REALLOC(s, allocated, sz+1))
|
||||
return -ENOMEM;
|
||||
|
||||
start = false;
|
||||
}
|
||||
|
||||
if (backslash) {
|
||||
if (!GREEDY_REALLOC(s, allocated, sz+7))
|
||||
return -ENOMEM;
|
||||
|
||||
if (c == 0) {
|
||||
if ((flags & EXTRACT_CUNESCAPE_RELAX) &&
|
||||
(!quote || flags & EXTRACT_RELAX)) {
|
||||
/* If we find an unquoted trailing backslash and we're in
|
||||
* EXTRACT_CUNESCAPE_RELAX mode, keep it verbatim in the
|
||||
* output.
|
||||
*
|
||||
* Unbalanced quotes will only be allowed in EXTRACT_RELAX
|
||||
* mode, EXTRACT_CUNESCAPE_RELAX mode does not allow them.
|
||||
*/
|
||||
s[sz++] = '\\';
|
||||
goto finish_force_terminate;
|
||||
}
|
||||
if (flags & EXTRACT_RELAX)
|
||||
goto finish_force_terminate;
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (flags & EXTRACT_CUNESCAPE) {
|
||||
uint32_t u;
|
||||
|
||||
r = cunescape_one(*p, (size_t) -1, &c, &u);
|
||||
if (r < 0) {
|
||||
if (flags & EXTRACT_CUNESCAPE_RELAX) {
|
||||
s[sz++] = '\\';
|
||||
s[sz++] = c;
|
||||
goto end_escape;
|
||||
}
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
(*p) += r - 1;
|
||||
|
||||
if (c != 0)
|
||||
s[sz++] = c; /* normal explicit char */
|
||||
else
|
||||
sz += utf8_encode_unichar(s + sz, u); /* unicode chars we'll encode as utf8 */
|
||||
} else
|
||||
s[sz++] = c;
|
||||
|
||||
end_escape:
|
||||
backslash = false;
|
||||
|
||||
} else if (quote) { /* inside either single or double quotes */
|
||||
if (c == 0) {
|
||||
if (flags & EXTRACT_RELAX)
|
||||
goto finish_force_terminate;
|
||||
return -EINVAL;
|
||||
} else if (c == quote) /* found the end quote */
|
||||
quote = 0;
|
||||
else if (c == '\\')
|
||||
backslash = true;
|
||||
else {
|
||||
if (!GREEDY_REALLOC(s, allocated, sz+2))
|
||||
return -ENOMEM;
|
||||
|
||||
s[sz++] = c;
|
||||
}
|
||||
|
||||
} else if (separator) {
|
||||
if (c == 0)
|
||||
goto finish_force_terminate;
|
||||
if (!strchr(separators, c))
|
||||
goto finish;
|
||||
|
||||
} else {
|
||||
if (c == 0)
|
||||
goto finish_force_terminate;
|
||||
else if ((c == '\'' || c == '"') && (flags & EXTRACT_QUOTES))
|
||||
quote = c;
|
||||
else if (c == '\\')
|
||||
backslash = true;
|
||||
else if (strchr(separators, c)) {
|
||||
if (flags & EXTRACT_DONT_COALESCE_SEPARATORS) {
|
||||
(*p) ++;
|
||||
goto finish_force_next;
|
||||
}
|
||||
separator = true;
|
||||
} else {
|
||||
if (!GREEDY_REALLOC(s, allocated, sz+2))
|
||||
return -ENOMEM;
|
||||
|
||||
s[sz++] = c;
|
||||
}
|
||||
}
|
||||
|
||||
(*p) ++;
|
||||
}
|
||||
|
||||
finish_force_terminate:
|
||||
*p = NULL;
|
||||
finish:
|
||||
if (!s) {
|
||||
*p = NULL;
|
||||
*ret = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
finish_force_next:
|
||||
s[sz] = 0;
|
||||
*ret = s;
|
||||
s = NULL;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int extract_first_word_and_warn(
|
||||
const char **p,
|
||||
char **ret,
|
||||
const char *separators,
|
||||
ExtractFlags flags,
|
||||
const char *unit,
|
||||
const char *filename,
|
||||
unsigned line,
|
||||
const char *rvalue) {
|
||||
|
||||
/* Try to unquote it, if it fails, warn about it and try again
|
||||
* but this time using EXTRACT_CUNESCAPE_RELAX to keep the
|
||||
* backslashes verbatim in invalid escape sequences. */
|
||||
|
||||
const char *save;
|
||||
int r;
|
||||
|
||||
save = *p;
|
||||
r = extract_first_word(p, ret, separators, flags);
|
||||
if (r >= 0)
|
||||
return r;
|
||||
|
||||
if (r == -EINVAL && !(flags & EXTRACT_CUNESCAPE_RELAX)) {
|
||||
|
||||
/* Retry it with EXTRACT_CUNESCAPE_RELAX. */
|
||||
*p = save;
|
||||
r = extract_first_word(p, ret, separators, flags|EXTRACT_CUNESCAPE_RELAX);
|
||||
if (r >= 0) {
|
||||
/* It worked this time, hence it must have been an invalid escape sequence we could correct. */
|
||||
log_syntax(unit, LOG_WARNING, filename, line, EINVAL, "Invalid escape sequences in line, correcting: \"%s\"", rvalue);
|
||||
return r;
|
||||
}
|
||||
|
||||
/* If it's still EINVAL; then it must be unbalanced quoting, report this. */
|
||||
if (r == -EINVAL)
|
||||
return log_syntax(unit, LOG_ERR, filename, line, r, "Unbalanced quoting, ignoring: \"%s\"", rvalue);
|
||||
}
|
||||
|
||||
/* Can be any error, report it */
|
||||
return log_syntax(unit, LOG_ERR, filename, line, r, "Unable to decode word \"%s\", ignoring: %m", rvalue);
|
||||
}
|
||||
|
||||
int extract_many_words(const char **p, const char *separators, ExtractFlags flags, ...) {
|
||||
va_list ap;
|
||||
char **l;
|
||||
int n = 0, i, c, r;
|
||||
|
||||
/* Parses a number of words from a string, stripping any
|
||||
* quotes if necessary. */
|
||||
|
||||
assert(p);
|
||||
|
||||
/* Count how many words are expected */
|
||||
va_start(ap, flags);
|
||||
for (;;) {
|
||||
if (!va_arg(ap, char **))
|
||||
break;
|
||||
n++;
|
||||
}
|
||||
va_end(ap);
|
||||
|
||||
if (n <= 0)
|
||||
return 0;
|
||||
|
||||
/* Read all words into a temporary array */
|
||||
l = newa0(char*, n);
|
||||
for (c = 0; c < n; c++) {
|
||||
|
||||
r = extract_first_word(p, &l[c], separators, flags);
|
||||
if (r < 0) {
|
||||
int j;
|
||||
|
||||
for (j = 0; j < c; j++)
|
||||
free(l[j]);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
if (r == 0)
|
||||
break;
|
||||
}
|
||||
|
||||
/* If we managed to parse all words, return them in the passed
|
||||
* in parameters */
|
||||
va_start(ap, flags);
|
||||
for (i = 0; i < n; i++) {
|
||||
char **v;
|
||||
|
||||
v = va_arg(ap, char **);
|
||||
assert(v);
|
||||
|
||||
*v = l[i];
|
||||
}
|
||||
va_end(ap);
|
||||
|
||||
return c;
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
|
||||
|
||||
#pragma once
|
||||
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
Copyright 2010 Lennart Poettering
|
||||
|
||||
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 "macro.h"
|
||||
|
||||
typedef enum ExtractFlags {
|
||||
EXTRACT_RELAX = 1,
|
||||
EXTRACT_CUNESCAPE = 2,
|
||||
EXTRACT_CUNESCAPE_RELAX = 4,
|
||||
EXTRACT_QUOTES = 8,
|
||||
EXTRACT_DONT_COALESCE_SEPARATORS = 16,
|
||||
} ExtractFlags;
|
||||
|
||||
int extract_first_word(const char **p, char **ret, const char *separators, ExtractFlags flags);
|
||||
int extract_first_word_and_warn(const char **p, char **ret, const char *separators, ExtractFlags flags, const char *unit, const char *filename, unsigned line, const char *rvalue);
|
||||
int extract_many_words(const char **p, const char *separators, ExtractFlags flags, ...) _sentinel_;
|
||||
@@ -0,0 +1,321 @@
|
||||
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
|
||||
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
Copyright 2010 Lennart Poettering
|
||||
|
||||
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 "fd-util.h"
|
||||
#include "util.h"
|
||||
|
||||
int close_nointr(int fd) {
|
||||
assert(fd >= 0);
|
||||
|
||||
if (close(fd) >= 0)
|
||||
return 0;
|
||||
|
||||
/*
|
||||
* Just ignore EINTR; a retry loop is the wrong thing to do on
|
||||
* Linux.
|
||||
*
|
||||
* http://lkml.indiana.edu/hypermail/linux/kernel/0509.1/0877.html
|
||||
* https://bugzilla.gnome.org/show_bug.cgi?id=682819
|
||||
* http://utcc.utoronto.ca/~cks/space/blog/unix/CloseEINTR
|
||||
* https://sites.google.com/site/michaelsafyan/software-engineering/checkforeintrwheninvokingclosethinkagain
|
||||
*/
|
||||
if (errno == EINTR)
|
||||
return 0;
|
||||
|
||||
return -errno;
|
||||
}
|
||||
|
||||
int safe_close(int fd) {
|
||||
|
||||
/*
|
||||
* Like close_nointr() but cannot fail. Guarantees errno is
|
||||
* unchanged. Is a NOP with negative fds passed, and returns
|
||||
* -1, so that it can be used in this syntax:
|
||||
*
|
||||
* fd = safe_close(fd);
|
||||
*/
|
||||
|
||||
if (fd >= 0) {
|
||||
PROTECT_ERRNO;
|
||||
|
||||
/* The kernel might return pretty much any error code
|
||||
* via close(), but the fd will be closed anyway. The
|
||||
* only condition we want to check for here is whether
|
||||
* the fd was invalid at all... */
|
||||
|
||||
assert_se(close_nointr(fd) != -EBADF);
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
void safe_close_pair(int p[]) {
|
||||
assert(p);
|
||||
|
||||
if (p[0] == p[1]) {
|
||||
/* Special case pairs which use the same fd in both
|
||||
* directions... */
|
||||
p[0] = p[1] = safe_close(p[0]);
|
||||
return;
|
||||
}
|
||||
|
||||
p[0] = safe_close(p[0]);
|
||||
p[1] = safe_close(p[1]);
|
||||
}
|
||||
|
||||
void close_many(const int fds[], unsigned n_fd) {
|
||||
unsigned i;
|
||||
|
||||
assert(fds || n_fd <= 0);
|
||||
|
||||
for (i = 0; i < n_fd; i++)
|
||||
safe_close(fds[i]);
|
||||
}
|
||||
|
||||
int fclose_nointr(FILE *f) {
|
||||
assert(f);
|
||||
|
||||
/* Same as close_nointr(), but for fclose() */
|
||||
|
||||
if (fclose(f) == 0)
|
||||
return 0;
|
||||
|
||||
if (errno == EINTR)
|
||||
return 0;
|
||||
|
||||
return -errno;
|
||||
}
|
||||
|
||||
FILE* safe_fclose(FILE *f) {
|
||||
|
||||
/* Same as safe_close(), but for fclose() */
|
||||
|
||||
if (f) {
|
||||
PROTECT_ERRNO;
|
||||
|
||||
assert_se(fclose_nointr(f) != EBADF);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
DIR* safe_closedir(DIR *d) {
|
||||
|
||||
if (d) {
|
||||
PROTECT_ERRNO;
|
||||
|
||||
assert_se(closedir(d) >= 0 || errno != EBADF);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int fd_nonblock(int fd, bool nonblock) {
|
||||
int flags, nflags;
|
||||
|
||||
assert(fd >= 0);
|
||||
|
||||
flags = fcntl(fd, F_GETFL, 0);
|
||||
if (flags < 0)
|
||||
return -errno;
|
||||
|
||||
if (nonblock)
|
||||
nflags = flags | O_NONBLOCK;
|
||||
else
|
||||
nflags = flags & ~O_NONBLOCK;
|
||||
|
||||
if (nflags == flags)
|
||||
return 0;
|
||||
|
||||
if (fcntl(fd, F_SETFL, nflags) < 0)
|
||||
return -errno;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int fd_cloexec(int fd, bool cloexec) {
|
||||
int flags, nflags;
|
||||
|
||||
assert(fd >= 0);
|
||||
|
||||
flags = fcntl(fd, F_GETFD, 0);
|
||||
if (flags < 0)
|
||||
return -errno;
|
||||
|
||||
if (cloexec)
|
||||
nflags = flags | FD_CLOEXEC;
|
||||
else
|
||||
nflags = flags & ~FD_CLOEXEC;
|
||||
|
||||
if (nflags == flags)
|
||||
return 0;
|
||||
|
||||
if (fcntl(fd, F_SETFD, nflags) < 0)
|
||||
return -errno;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
_pure_ static bool fd_in_set(int fd, const int fdset[], unsigned n_fdset) {
|
||||
unsigned i;
|
||||
|
||||
assert(n_fdset == 0 || fdset);
|
||||
|
||||
for (i = 0; i < n_fdset; i++)
|
||||
if (fdset[i] == fd)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
int close_all_fds(const int except[], unsigned n_except) {
|
||||
_cleanup_closedir_ DIR *d = NULL;
|
||||
struct dirent *de;
|
||||
int r = 0;
|
||||
|
||||
assert(n_except == 0 || except);
|
||||
|
||||
d = opendir("/proc/self/fd");
|
||||
if (!d) {
|
||||
int fd;
|
||||
struct rlimit rl;
|
||||
|
||||
/* When /proc isn't available (for example in chroots)
|
||||
* the fallback is brute forcing through the fd
|
||||
* table */
|
||||
|
||||
assert_se(getrlimit(RLIMIT_NOFILE, &rl) >= 0);
|
||||
for (fd = 3; fd < (int) rl.rlim_max; fd ++) {
|
||||
|
||||
if (fd_in_set(fd, except, n_except))
|
||||
continue;
|
||||
|
||||
if (close_nointr(fd) < 0)
|
||||
if (errno != EBADF && r == 0)
|
||||
r = -errno;
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
while ((de = readdir(d))) {
|
||||
int fd = -1;
|
||||
|
||||
if (hidden_file(de->d_name))
|
||||
continue;
|
||||
|
||||
if (safe_atoi(de->d_name, &fd) < 0)
|
||||
/* Let's better ignore this, just in case */
|
||||
continue;
|
||||
|
||||
if (fd < 3)
|
||||
continue;
|
||||
|
||||
if (fd == dirfd(d))
|
||||
continue;
|
||||
|
||||
if (fd_in_set(fd, except, n_except))
|
||||
continue;
|
||||
|
||||
if (close_nointr(fd) < 0) {
|
||||
/* Valgrind has its own FD and doesn't want to have it closed */
|
||||
if (errno != EBADF && r == 0)
|
||||
r = -errno;
|
||||
}
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
int same_fd(int a, int b) {
|
||||
struct stat sta, stb;
|
||||
pid_t pid;
|
||||
int r, fa, fb;
|
||||
|
||||
assert(a >= 0);
|
||||
assert(b >= 0);
|
||||
|
||||
/* Compares two file descriptors. Note that semantics are
|
||||
* quite different depending on whether we have kcmp() or we
|
||||
* don't. If we have kcmp() this will only return true for
|
||||
* dup()ed file descriptors, but not otherwise. If we don't
|
||||
* have kcmp() this will also return true for two fds of the same
|
||||
* file, created by separate open() calls. Since we use this
|
||||
* call mostly for filtering out duplicates in the fd store
|
||||
* this difference hopefully doesn't matter too much. */
|
||||
|
||||
if (a == b)
|
||||
return true;
|
||||
|
||||
/* Try to use kcmp() if we have it. */
|
||||
pid = getpid();
|
||||
r = kcmp(pid, pid, KCMP_FILE, a, b);
|
||||
if (r == 0)
|
||||
return true;
|
||||
if (r > 0)
|
||||
return false;
|
||||
if (errno != ENOSYS)
|
||||
return -errno;
|
||||
|
||||
/* We don't have kcmp(), use fstat() instead. */
|
||||
if (fstat(a, &sta) < 0)
|
||||
return -errno;
|
||||
|
||||
if (fstat(b, &stb) < 0)
|
||||
return -errno;
|
||||
|
||||
if ((sta.st_mode & S_IFMT) != (stb.st_mode & S_IFMT))
|
||||
return false;
|
||||
|
||||
/* We consider all device fds different, since two device fds
|
||||
* might refer to quite different device contexts even though
|
||||
* they share the same inode and backing dev_t. */
|
||||
|
||||
if (S_ISCHR(sta.st_mode) || S_ISBLK(sta.st_mode))
|
||||
return false;
|
||||
|
||||
if (sta.st_dev != stb.st_dev || sta.st_ino != stb.st_ino)
|
||||
return false;
|
||||
|
||||
/* The fds refer to the same inode on disk, let's also check
|
||||
* if they have the same fd flags. This is useful to
|
||||
* distinguish the read and write side of a pipe created with
|
||||
* pipe(). */
|
||||
fa = fcntl(a, F_GETFL);
|
||||
if (fa < 0)
|
||||
return -errno;
|
||||
|
||||
fb = fcntl(b, F_GETFL);
|
||||
if (fb < 0)
|
||||
return -errno;
|
||||
|
||||
return fa == fb;
|
||||
}
|
||||
|
||||
void cmsg_close_all(struct msghdr *mh) {
|
||||
struct cmsghdr *cmsg;
|
||||
|
||||
assert(mh);
|
||||
|
||||
CMSG_FOREACH(cmsg, mh)
|
||||
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));
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
|
||||
|
||||
#pragma once
|
||||
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
Copyright 2010 Lennart Poettering
|
||||
|
||||
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 <stdio.h>
|
||||
#include <dirent.h>
|
||||
#include <stdbool.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include "macro.h"
|
||||
|
||||
int close_nointr(int fd);
|
||||
int safe_close(int fd);
|
||||
void safe_close_pair(int p[]);
|
||||
|
||||
void close_many(const int fds[], unsigned n_fd);
|
||||
|
||||
int fclose_nointr(FILE *f);
|
||||
FILE* safe_fclose(FILE *f);
|
||||
DIR* safe_closedir(DIR *f);
|
||||
|
||||
static inline void closep(int *fd) {
|
||||
safe_close(*fd);
|
||||
}
|
||||
|
||||
static inline void close_pairp(int (*p)[2]) {
|
||||
safe_close_pair(*p);
|
||||
}
|
||||
|
||||
static inline void fclosep(FILE **f) {
|
||||
safe_fclose(*f);
|
||||
}
|
||||
|
||||
DEFINE_TRIVIAL_CLEANUP_FUNC(FILE*, pclose);
|
||||
DEFINE_TRIVIAL_CLEANUP_FUNC(DIR*, closedir);
|
||||
|
||||
#define _cleanup_close_ _cleanup_(closep)
|
||||
#define _cleanup_fclose_ _cleanup_(fclosep)
|
||||
#define _cleanup_pclose_ _cleanup_(pclosep)
|
||||
#define _cleanup_closedir_ _cleanup_(closedirp)
|
||||
#define _cleanup_close_pair_ _cleanup_(close_pairp)
|
||||
|
||||
int fd_nonblock(int fd, bool nonblock);
|
||||
int fd_cloexec(int fd, bool cloexec);
|
||||
|
||||
int close_all_fds(const int except[], unsigned n_except);
|
||||
|
||||
int same_fd(int a, int b);
|
||||
|
||||
void cmsg_close_all(struct msghdr *mh);
|
||||
+5
-3
@@ -23,11 +23,13 @@
|
||||
#include <dirent.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#include "sd-daemon.h"
|
||||
|
||||
#include "fd-util.h"
|
||||
#include "fdset.h"
|
||||
#include "macro.h"
|
||||
#include "set.h"
|
||||
#include "util.h"
|
||||
#include "macro.h"
|
||||
#include "fdset.h"
|
||||
#include "sd-daemon.h"
|
||||
|
||||
#define MAKE_SET(s) ((Set*) s)
|
||||
#define MAKE_FDSET(s) ((FDSet*) s)
|
||||
|
||||
+6
-3
@@ -21,11 +21,14 @@
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
#include "util.h"
|
||||
#include "ctype.h"
|
||||
#include "escape.h"
|
||||
#include "fd-util.h"
|
||||
#include "fileio.h"
|
||||
#include "string-util.h"
|
||||
#include "strv.h"
|
||||
#include "utf8.h"
|
||||
#include "ctype.h"
|
||||
#include "fileio.h"
|
||||
#include "util.h"
|
||||
|
||||
int write_string_stream(FILE *f, const char *line, bool enforce_newline) {
|
||||
|
||||
|
||||
@@ -19,11 +19,13 @@
|
||||
along with systemd; If not, see <http://www.gnu.org/licenses/>.
|
||||
***/
|
||||
|
||||
#include <sys/utsname.h>
|
||||
#include <ctype.h>
|
||||
#include <sys/utsname.h>
|
||||
|
||||
#include "util.h"
|
||||
#include "fd-util.h"
|
||||
#include "hostname-util.h"
|
||||
#include "string-util.h"
|
||||
#include "util.h"
|
||||
|
||||
bool hostname_is_set(void) {
|
||||
struct utsname u;
|
||||
|
||||
+3
-1
@@ -19,9 +19,11 @@
|
||||
along with systemd; If not, see <http://www.gnu.org/licenses/>.
|
||||
***/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <math.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "macro.h"
|
||||
#include "string-util.h"
|
||||
#include "utf8.h"
|
||||
#include "json.h"
|
||||
|
||||
|
||||
@@ -21,12 +21,13 @@
|
||||
|
||||
#include <sys/mman.h>
|
||||
|
||||
#include "set.h"
|
||||
#include "util.h"
|
||||
#include "utf8.h"
|
||||
#include "strv.h"
|
||||
|
||||
#include "fd-util.h"
|
||||
#include "locale-util.h"
|
||||
#include "set.h"
|
||||
#include "string-util.h"
|
||||
#include "strv.h"
|
||||
#include "utf8.h"
|
||||
#include "util.h"
|
||||
|
||||
static int add_locales_from_archive(Set *locales) {
|
||||
/* Stolen from glibc... */
|
||||
|
||||
@@ -27,9 +27,10 @@
|
||||
#include <limits.h>
|
||||
#include <sys/file.h>
|
||||
|
||||
#include "util.h"
|
||||
#include "lockfile-util.h"
|
||||
#include "fd-util.h"
|
||||
#include "fileio.h"
|
||||
#include "lockfile-util.h"
|
||||
#include "util.h"
|
||||
|
||||
int make_lock_file(const char *p, int operation, LockFile *ret) {
|
||||
_cleanup_close_ int fd = -1;
|
||||
|
||||
+14
-11
@@ -19,26 +19,29 @@
|
||||
along with systemd; If not, see <http://www.gnu.org/licenses/>.
|
||||
***/
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <printf.h>
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/un.h>
|
||||
#include <stddef.h>
|
||||
#include <printf.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "sd-messages.h"
|
||||
#include "log.h"
|
||||
#include "util.h"
|
||||
#include "missing.h"
|
||||
#include "macro.h"
|
||||
#include "socket-util.h"
|
||||
|
||||
#include "fd-util.h"
|
||||
#include "formats-util.h"
|
||||
#include "log.h"
|
||||
#include "macro.h"
|
||||
#include "missing.h"
|
||||
#include "process-util.h"
|
||||
#include "terminal-util.h"
|
||||
#include "signal-util.h"
|
||||
#include "socket-util.h"
|
||||
#include "string-util.h"
|
||||
#include "terminal-util.h"
|
||||
#include "util.h"
|
||||
|
||||
#define SNDBUF_SIZE (8*1024*1024)
|
||||
|
||||
|
||||
+6
-5
@@ -21,14 +21,15 @@
|
||||
along with systemd; If not, see <http://www.gnu.org/licenses/>.
|
||||
***/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
#include <syslog.h>
|
||||
#include <sys/signalfd.h>
|
||||
#include <errno.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/signalfd.h>
|
||||
#include <syslog.h>
|
||||
|
||||
#include "sd-id128.h"
|
||||
|
||||
#include "macro.h"
|
||||
|
||||
typedef enum LogTarget{
|
||||
|
||||
@@ -19,8 +19,9 @@
|
||||
along with systemd; If not, see <http://www.gnu.org/licenses/>.
|
||||
***/
|
||||
|
||||
#include "login-util.h"
|
||||
#include "def.h"
|
||||
#include "string-util.h"
|
||||
#include "login-util.h"
|
||||
|
||||
bool session_id_valid(const char *id) {
|
||||
|
||||
|
||||
@@ -22,5 +22,10 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <unistd.h>
|
||||
|
||||
bool session_id_valid(const char *id);
|
||||
|
||||
static inline bool logind_running(void) {
|
||||
return access("/run/systemd/seats/", F_OK) >= 0;
|
||||
}
|
||||
|
||||
@@ -19,19 +19,20 @@
|
||||
along with systemd; If not, see <http://www.gnu.org/licenses/>.
|
||||
***/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <fcntl.h>
|
||||
#ifdef HAVE_LINUX_MEMFD_H
|
||||
#include <linux/memfd.h>
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/prctl.h>
|
||||
|
||||
#ifdef HAVE_LINUX_MEMFD_H
|
||||
# include <linux/memfd.h>
|
||||
#endif
|
||||
|
||||
#include "util.h"
|
||||
#include "fd-util.h"
|
||||
#include "memfd-util.h"
|
||||
#include "utf8.h"
|
||||
#include "missing.h"
|
||||
#include "string-util.h"
|
||||
#include "utf8.h"
|
||||
#include "util.h"
|
||||
|
||||
int memfd_new(const char *name) {
|
||||
_cleanup_free_ char *g = NULL;
|
||||
|
||||
@@ -21,7 +21,8 @@
|
||||
along with systemd; If not, see <http://www.gnu.org/licenses/>.
|
||||
***/
|
||||
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
int memfd_new(const char *name);
|
||||
int memfd_new_and_map(const char *name, size_t sz, void **p);
|
||||
|
||||
+137
-67
@@ -19,21 +19,23 @@
|
||||
along with systemd; If not, see <http://www.gnu.org/licenses/>.
|
||||
***/
|
||||
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/statvfs.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "macro.h"
|
||||
#include "util.h"
|
||||
#include "log.h"
|
||||
#include "strv.h"
|
||||
#include "path-util.h"
|
||||
#include "missing.h"
|
||||
#include "fd-util.h"
|
||||
#include "fileio.h"
|
||||
#include "log.h"
|
||||
#include "macro.h"
|
||||
#include "missing.h"
|
||||
#include "path-util.h"
|
||||
#include "string-util.h"
|
||||
#include "strv.h"
|
||||
#include "util.h"
|
||||
|
||||
bool path_is_absolute(const char *p) {
|
||||
return p[0] == '/';
|
||||
@@ -84,20 +86,25 @@ int path_get_parent(const char *path, char **_r) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
char **path_split_and_make_absolute(const char *p) {
|
||||
int path_split_and_make_absolute(const char *p, char ***ret) {
|
||||
char **l;
|
||||
int r;
|
||||
|
||||
assert(p);
|
||||
assert(ret);
|
||||
|
||||
l = strv_split(p, ":");
|
||||
if (!l)
|
||||
return NULL;
|
||||
|
||||
if (!path_strv_make_absolute_cwd(l)) {
|
||||
r = path_strv_make_absolute_cwd(l);
|
||||
if (r < 0) {
|
||||
strv_free(l);
|
||||
return NULL;
|
||||
return r;
|
||||
}
|
||||
|
||||
return l;
|
||||
*ret = l;
|
||||
return r;
|
||||
}
|
||||
|
||||
char *path_make_absolute(const char *p, const char *prefix) {
|
||||
@@ -112,22 +119,31 @@ char *path_make_absolute(const char *p, const char *prefix) {
|
||||
return strjoin(prefix, "/", p, NULL);
|
||||
}
|
||||
|
||||
char *path_make_absolute_cwd(const char *p) {
|
||||
_cleanup_free_ char *cwd = NULL;
|
||||
int path_make_absolute_cwd(const char *p, char **ret) {
|
||||
char *c;
|
||||
|
||||
assert(p);
|
||||
assert(ret);
|
||||
|
||||
/* Similar to path_make_absolute(), but prefixes with the
|
||||
* current working directory. */
|
||||
|
||||
if (path_is_absolute(p))
|
||||
return strdup(p);
|
||||
c = strdup(p);
|
||||
else {
|
||||
_cleanup_free_ char *cwd = NULL;
|
||||
|
||||
cwd = get_current_dir_name();
|
||||
if (!cwd)
|
||||
return NULL;
|
||||
cwd = get_current_dir_name();
|
||||
if (!cwd)
|
||||
return -errno;
|
||||
|
||||
return strjoin(cwd, "/", p, NULL);
|
||||
c = strjoin(cwd, "/", p, NULL);
|
||||
}
|
||||
if (!c)
|
||||
return -ENOMEM;
|
||||
|
||||
*ret = c;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int path_make_relative(const char *from_dir, const char *to_path, char **_r) {
|
||||
@@ -215,8 +231,9 @@ int path_make_relative(const char *from_dir, const char *to_path, char **_r) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
char **path_strv_make_absolute_cwd(char **l) {
|
||||
int path_strv_make_absolute_cwd(char **l) {
|
||||
char **s;
|
||||
int r;
|
||||
|
||||
/* Goes through every item in the string list and makes it
|
||||
* absolute. This works in place and won't rollback any
|
||||
@@ -225,15 +242,15 @@ char **path_strv_make_absolute_cwd(char **l) {
|
||||
STRV_FOREACH(s, l) {
|
||||
char *t;
|
||||
|
||||
t = path_make_absolute_cwd(*s);
|
||||
if (!t)
|
||||
return NULL;
|
||||
r = path_make_absolute_cwd(*s, &t);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
free(*s);
|
||||
*s = t;
|
||||
}
|
||||
|
||||
return l;
|
||||
return 0;
|
||||
}
|
||||
|
||||
char **path_strv_resolve(char **l, const char *prefix) {
|
||||
@@ -698,7 +715,6 @@ int path_is_os_tree(const char *path) {
|
||||
/* We use /usr/lib/os-release as flag file if something is an OS */
|
||||
p = strjoina(path, "/usr/lib/os-release");
|
||||
r = access(p, F_OK);
|
||||
|
||||
if (r >= 0)
|
||||
return 1;
|
||||
|
||||
@@ -709,56 +725,66 @@ int path_is_os_tree(const char *path) {
|
||||
return r >= 0;
|
||||
}
|
||||
|
||||
int find_binary(const char *name, bool local, char **filename) {
|
||||
int find_binary(const char *name, char **ret) {
|
||||
int last_error, r;
|
||||
const char *p;
|
||||
|
||||
assert(name);
|
||||
|
||||
if (is_path(name)) {
|
||||
if (local && access(name, X_OK) < 0)
|
||||
if (access(name, X_OK) < 0)
|
||||
return -errno;
|
||||
|
||||
if (filename) {
|
||||
char *p;
|
||||
|
||||
p = path_make_absolute_cwd(name);
|
||||
if (!p)
|
||||
return -ENOMEM;
|
||||
|
||||
*filename = p;
|
||||
if (ret) {
|
||||
r = path_make_absolute_cwd(name, ret);
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
|
||||
return 0;
|
||||
} else {
|
||||
const char *path;
|
||||
const char *word, *state;
|
||||
size_t l;
|
||||
}
|
||||
|
||||
/**
|
||||
* Plain getenv, not secure_getenv, because we want
|
||||
* to actually allow the user to pick the binary.
|
||||
*/
|
||||
path = getenv("PATH");
|
||||
if (!path)
|
||||
path = DEFAULT_PATH;
|
||||
/**
|
||||
* Plain getenv, not secure_getenv, because we want
|
||||
* to actually allow the user to pick the binary.
|
||||
*/
|
||||
p = getenv("PATH");
|
||||
if (!p)
|
||||
p = DEFAULT_PATH;
|
||||
|
||||
FOREACH_WORD_SEPARATOR(word, l, path, ":", state) {
|
||||
_cleanup_free_ char *p = NULL;
|
||||
last_error = -ENOENT;
|
||||
|
||||
if (asprintf(&p, "%.*s/%s", (int) l, word, name) < 0)
|
||||
return -ENOMEM;
|
||||
for (;;) {
|
||||
_cleanup_free_ char *j = NULL, *element = NULL;
|
||||
|
||||
if (access(p, X_OK) < 0)
|
||||
continue;
|
||||
r = extract_first_word(&p, &element, ":", EXTRACT_RELAX|EXTRACT_DONT_COALESCE_SEPARATORS);
|
||||
if (r < 0)
|
||||
return r;
|
||||
if (r == 0)
|
||||
break;
|
||||
|
||||
if (filename) {
|
||||
*filename = path_kill_slashes(p);
|
||||
p = NULL;
|
||||
if (!path_is_absolute(element))
|
||||
continue;
|
||||
|
||||
j = strjoin(element, "/", name, NULL);
|
||||
if (!j)
|
||||
return -ENOMEM;
|
||||
|
||||
if (access(j, X_OK) >= 0) {
|
||||
/* Found it! */
|
||||
|
||||
if (ret) {
|
||||
*ret = path_kill_slashes(j);
|
||||
j = NULL;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
return -ENOENT;
|
||||
last_error = -errno;
|
||||
}
|
||||
|
||||
return last_error;
|
||||
}
|
||||
|
||||
bool paths_check_timestamp(const char* const* paths, usec_t *timestamp, bool update) {
|
||||
@@ -800,7 +826,9 @@ static int binary_is_good(const char *binary) {
|
||||
_cleanup_free_ char *p = NULL, *d = NULL;
|
||||
int r;
|
||||
|
||||
r = find_binary(binary, true, &p);
|
||||
r = find_binary(binary, &p);
|
||||
if (r == -ENOENT)
|
||||
return 0;
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
@@ -808,28 +836,38 @@ static int binary_is_good(const char *binary) {
|
||||
* fsck */
|
||||
|
||||
r = readlink_malloc(p, &d);
|
||||
if (r >= 0 &&
|
||||
(path_equal(d, "/bin/true") ||
|
||||
path_equal(d, "/usr/bin/true") ||
|
||||
path_equal(d, "/dev/null")))
|
||||
return -ENOENT;
|
||||
if (r == -EINVAL) /* not a symlink */
|
||||
return 1;
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
return 0;
|
||||
return !path_equal(d, "true") &&
|
||||
!path_equal(d, "/bin/true") &&
|
||||
!path_equal(d, "/usr/bin/true") &&
|
||||
!path_equal(d, "/dev/null");
|
||||
}
|
||||
|
||||
int fsck_exists(const char *fstype) {
|
||||
const char *checker;
|
||||
|
||||
checker = strjoina("fsck.", fstype);
|
||||
assert(fstype);
|
||||
|
||||
if (streq(fstype, "auto"))
|
||||
return -EINVAL;
|
||||
|
||||
checker = strjoina("fsck.", fstype);
|
||||
return binary_is_good(checker);
|
||||
}
|
||||
|
||||
int mkfs_exists(const char *fstype) {
|
||||
const char *mkfs;
|
||||
|
||||
mkfs = strjoina("mkfs.", fstype);
|
||||
assert(fstype);
|
||||
|
||||
if (streq(fstype, "auto"))
|
||||
return -EINVAL;
|
||||
|
||||
mkfs = strjoina("mkfs.", fstype);
|
||||
return binary_is_good(mkfs);
|
||||
}
|
||||
|
||||
@@ -866,3 +904,35 @@ char *prefix_root(const char *root, const char *path) {
|
||||
strcpy(p, path);
|
||||
return n;
|
||||
}
|
||||
|
||||
int parse_path_argument_and_warn(const char *path, bool suppress_root, char **arg) {
|
||||
char *p;
|
||||
int r;
|
||||
|
||||
/*
|
||||
* This function is intended to be used in command line
|
||||
* parsers, to handle paths that are passed in. It makes the
|
||||
* path absolute, and reduces it to NULL if omitted or
|
||||
* root (the latter optionally).
|
||||
*
|
||||
* NOTE THAT THIS WILL FREE THE PREVIOUS ARGUMENT POINTER ON
|
||||
* SUCCESS! Hence, do not pass in uninitialized pointers.
|
||||
*/
|
||||
|
||||
if (isempty(path)) {
|
||||
*arg = mfree(*arg);
|
||||
return 0;
|
||||
}
|
||||
|
||||
r = path_make_absolute_cwd(path, &p);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to parse path \"%s\" and make it absolute: %m", path);
|
||||
|
||||
path_kill_slashes(p);
|
||||
if (suppress_root && path_equal(p, "/"))
|
||||
p = mfree(p);
|
||||
|
||||
free(*arg);
|
||||
*arg = p;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -36,11 +36,11 @@
|
||||
#endif
|
||||
|
||||
bool is_path(const char *p) _pure_;
|
||||
char** path_split_and_make_absolute(const char *p);
|
||||
int path_split_and_make_absolute(const char *p, char ***ret);
|
||||
int path_get_parent(const char *path, char **parent);
|
||||
bool path_is_absolute(const char *p) _pure_;
|
||||
char* path_make_absolute(const char *p, const char *prefix);
|
||||
char* path_make_absolute_cwd(const char *p);
|
||||
int path_make_absolute_cwd(const char *p, char **ret);
|
||||
int path_make_relative(const char *from_dir, const char *to_path, char **_r);
|
||||
char* path_kill_slashes(char *path);
|
||||
char* path_startswith(const char *path, const char *prefix) _pure_;
|
||||
@@ -49,7 +49,7 @@ bool path_equal(const char *a, const char *b) _pure_;
|
||||
bool path_equal_or_files_same(const char *a, const char *b);
|
||||
char* path_join(const char *root, const char *path, const char *rest);
|
||||
|
||||
char** path_strv_make_absolute_cwd(char **l);
|
||||
int path_strv_make_absolute_cwd(char **l);
|
||||
char** path_strv_resolve(char **l, const char *prefix);
|
||||
char** path_strv_resolve_uniq(char **l, const char *prefix);
|
||||
|
||||
@@ -58,7 +58,7 @@ int path_is_mount_point(const char *path, int flags);
|
||||
int path_is_read_only_fs(const char *path);
|
||||
int path_is_os_tree(const char *path);
|
||||
|
||||
int find_binary(const char *name, bool local, char **filename);
|
||||
int find_binary(const char *name, char **filename);
|
||||
|
||||
bool paths_check_timestamp(const char* const* paths, usec_t *paths_ts_usec, bool update);
|
||||
|
||||
@@ -101,3 +101,5 @@ char *prefix_root(const char *root, const char *path);
|
||||
} \
|
||||
_ret; \
|
||||
})
|
||||
|
||||
int parse_path_argument_and_warn(const char *path, bool suppress_root, char **arg);
|
||||
|
||||
+13
-10
@@ -17,22 +17,25 @@
|
||||
along with systemd; If not, see <http://www.gnu.org/licenses/>.
|
||||
***/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <sys/types.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/wait.h>
|
||||
#include <signal.h>
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <signal.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "escape.h"
|
||||
#include "fd-util.h"
|
||||
#include "fileio.h"
|
||||
#include "util.h"
|
||||
#include "log.h"
|
||||
#include "signal-util.h"
|
||||
#include "process-util.h"
|
||||
#include "signal-util.h"
|
||||
#include "string-util.h"
|
||||
#include "util.h"
|
||||
|
||||
int get_process_state(pid_t pid) {
|
||||
const char *p;
|
||||
|
||||
@@ -17,20 +17,21 @@
|
||||
along with systemd; If not, see <http://www.gnu.org/licenses/>.
|
||||
***/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <errno.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <time.h>
|
||||
#include <linux/random.h>
|
||||
#include <stdint.h>
|
||||
#ifdef HAVE_SYS_AUXV_H
|
||||
#include <sys/auxv.h>
|
||||
#endif
|
||||
#include <linux/random.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "fd-util.h"
|
||||
#include "missing.h"
|
||||
#include "random-util.h"
|
||||
#include "time-util.h"
|
||||
#include "missing.h"
|
||||
#include "util.h"
|
||||
|
||||
int dev_urandom(void *p, size_t n) {
|
||||
|
||||
+4
-2
@@ -19,10 +19,12 @@
|
||||
along with systemd; If not, see <http://www.gnu.org/licenses/>.
|
||||
***/
|
||||
|
||||
#include "util.h"
|
||||
#include "path-util.h"
|
||||
#include "btrfs-util.h"
|
||||
#include "fd-util.h"
|
||||
#include "path-util.h"
|
||||
#include "rm-rf.h"
|
||||
#include "string-util.h"
|
||||
#include "util.h"
|
||||
|
||||
int rm_rf_children(int fd, RemoveFlags flags, struct stat *root_dev) {
|
||||
_cleanup_closedir_ DIR *d = NULL;
|
||||
|
||||
+51
-43
@@ -171,15 +171,15 @@ int mac_selinux_fix(const char *path, bool ignore_enoent, bool ignore_erofs) {
|
||||
int mac_selinux_apply(const char *path, const char *label) {
|
||||
|
||||
#ifdef HAVE_SELINUX
|
||||
assert(path);
|
||||
assert(label);
|
||||
|
||||
if (!mac_selinux_use())
|
||||
return 0;
|
||||
|
||||
assert(path);
|
||||
assert(label);
|
||||
|
||||
if (setfilecon(path, (security_context_t) label) < 0) {
|
||||
log_enforcing("Failed to set SELinux security context %s on path %s: %m", label, path);
|
||||
if (security_getenforce() == 1)
|
||||
if (security_getenforce() > 0)
|
||||
return -errno;
|
||||
}
|
||||
#endif
|
||||
@@ -312,10 +312,10 @@ char* mac_selinux_free(char *label) {
|
||||
}
|
||||
|
||||
int mac_selinux_create_file_prepare(const char *path, mode_t mode) {
|
||||
int r = 0;
|
||||
|
||||
#ifdef HAVE_SELINUX
|
||||
_cleanup_security_context_free_ security_context_t filecon = NULL;
|
||||
int r;
|
||||
|
||||
assert(path);
|
||||
|
||||
@@ -325,34 +325,33 @@ int mac_selinux_create_file_prepare(const char *path, mode_t mode) {
|
||||
if (path_is_absolute(path))
|
||||
r = selabel_lookup_raw(label_hnd, &filecon, path, mode);
|
||||
else {
|
||||
_cleanup_free_ char *newpath;
|
||||
_cleanup_free_ char *newpath = NULL;
|
||||
|
||||
newpath = path_make_absolute_cwd(path);
|
||||
if (!newpath)
|
||||
return -ENOMEM;
|
||||
r = path_make_absolute_cwd(path, &newpath);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = selabel_lookup_raw(label_hnd, &filecon, newpath, mode);
|
||||
}
|
||||
|
||||
/* No context specified by the policy? Proceed without setting it. */
|
||||
if (r < 0 && errno == ENOENT)
|
||||
return 0;
|
||||
if (r < 0) {
|
||||
/* No context specified by the policy? Proceed without setting it. */
|
||||
if (errno == ENOENT)
|
||||
return 0;
|
||||
|
||||
if (r < 0)
|
||||
r = -errno;
|
||||
else {
|
||||
r = setfscreatecon(filecon);
|
||||
if (r < 0) {
|
||||
log_enforcing("Failed to set SELinux security context %s for %s: %m", filecon, path);
|
||||
r = -errno;
|
||||
}
|
||||
log_enforcing("Failed to determine SELinux security context for %s: %m", path);
|
||||
} else {
|
||||
if (setfscreatecon(filecon) >= 0)
|
||||
return 0; /* Success! */
|
||||
|
||||
log_enforcing("Failed to set SELinux security context %s for %s: %m", filecon, path);
|
||||
}
|
||||
|
||||
if (r < 0 && security_getenforce() == 0)
|
||||
r = 0;
|
||||
#endif
|
||||
if (security_getenforce() > 0)
|
||||
return -errno;
|
||||
|
||||
return r;
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
void mac_selinux_create_file_clear(void) {
|
||||
@@ -405,6 +404,7 @@ int mac_selinux_bind(int fd, const struct sockaddr *addr, socklen_t addrlen) {
|
||||
#ifdef HAVE_SELINUX
|
||||
_cleanup_security_context_free_ security_context_t fcon = NULL;
|
||||
const struct sockaddr_un *un;
|
||||
bool context_changed = false;
|
||||
char *path;
|
||||
int r;
|
||||
|
||||
@@ -420,7 +420,7 @@ int mac_selinux_bind(int fd, const struct sockaddr *addr, socklen_t addrlen) {
|
||||
goto skipped;
|
||||
|
||||
/* Filter out anonymous sockets */
|
||||
if (addrlen < sizeof(sa_family_t) + 1)
|
||||
if (addrlen < offsetof(struct sockaddr_un, sun_path) + 1)
|
||||
goto skipped;
|
||||
|
||||
/* Filter out abstract namespace sockets */
|
||||
@@ -433,36 +433,44 @@ int mac_selinux_bind(int fd, const struct sockaddr *addr, socklen_t addrlen) {
|
||||
if (path_is_absolute(path))
|
||||
r = selabel_lookup_raw(label_hnd, &fcon, path, S_IFSOCK);
|
||||
else {
|
||||
_cleanup_free_ char *newpath;
|
||||
_cleanup_free_ char *newpath = NULL;
|
||||
|
||||
newpath = path_make_absolute_cwd(path);
|
||||
if (!newpath)
|
||||
return -ENOMEM;
|
||||
r = path_make_absolute_cwd(path, &newpath);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = selabel_lookup_raw(label_hnd, &fcon, newpath, S_IFSOCK);
|
||||
}
|
||||
|
||||
if (r == 0)
|
||||
r = setfscreatecon(fcon);
|
||||
if (r < 0) {
|
||||
/* No context specified by the policy? Proceed without setting it */
|
||||
if (errno == ENOENT)
|
||||
goto skipped;
|
||||
|
||||
if (r < 0 && errno != ENOENT) {
|
||||
log_enforcing("Failed to set SELinux security context %s for %s: %m", fcon, path);
|
||||
log_enforcing("Failed to determine SELinux security context for %s: %m", path);
|
||||
if (security_getenforce() > 0)
|
||||
return -errno;
|
||||
|
||||
if (security_getenforce() == 1) {
|
||||
r = -errno;
|
||||
goto finish;
|
||||
}
|
||||
} else {
|
||||
if (setfscreatecon(fcon) < 0) {
|
||||
log_enforcing("Failed to set SELinux security context %s for %s: %m", fcon, path);
|
||||
if (security_getenforce() > 0)
|
||||
return -errno;
|
||||
} else
|
||||
context_changed = true;
|
||||
}
|
||||
|
||||
r = bind(fd, addr, addrlen);
|
||||
if (r < 0)
|
||||
r = -errno;
|
||||
r = bind(fd, addr, addrlen) < 0 ? -errno : 0;
|
||||
|
||||
if (context_changed)
|
||||
setfscreatecon(NULL);
|
||||
|
||||
finish:
|
||||
setfscreatecon(NULL);
|
||||
return r;
|
||||
|
||||
skipped:
|
||||
#endif
|
||||
return bind(fd, addr, addrlen) < 0 ? -errno : 0;
|
||||
if (bind(fd, addr, addrlen) < 0)
|
||||
return -errno;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -19,7 +19,9 @@
|
||||
along with systemd; If not, see <http://www.gnu.org/licenses/>.
|
||||
***/
|
||||
|
||||
#include "string-util.h"
|
||||
#include "util.h"
|
||||
|
||||
#include "signal-util.h"
|
||||
|
||||
int reset_all_signal_handlers(void) {
|
||||
|
||||
@@ -19,18 +19,19 @@
|
||||
along with systemd; If not, see <http://www.gnu.org/licenses/>.
|
||||
***/
|
||||
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <sys/stat.h>
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "fd-util.h"
|
||||
#include "macro.h"
|
||||
#include "util.h"
|
||||
#include "mkdir.h"
|
||||
#include "missing.h"
|
||||
#include "mkdir.h"
|
||||
#include "selinux-util.h"
|
||||
#include "socket-util.h"
|
||||
#include "util.h"
|
||||
|
||||
int socket_address_listen(
|
||||
const SocketAddress *a,
|
||||
|
||||
+12
-11
@@ -19,23 +19,24 @@
|
||||
along with systemd; If not, see <http://www.gnu.org/licenses/>.
|
||||
***/
|
||||
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <net/if.h>
|
||||
#include <sys/types.h>
|
||||
#include <stddef.h>
|
||||
#include <netdb.h>
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "macro.h"
|
||||
#include "path-util.h"
|
||||
#include "util.h"
|
||||
#include "socket-util.h"
|
||||
#include "missing.h"
|
||||
#include "fileio.h"
|
||||
#include "formats-util.h"
|
||||
#include "macro.h"
|
||||
#include "missing.h"
|
||||
#include "path-util.h"
|
||||
#include "string-util.h"
|
||||
#include "util.h"
|
||||
#include "socket-util.h"
|
||||
|
||||
int socket_address_parse(SocketAddress *a, const char *s) {
|
||||
char *e, *n;
|
||||
|
||||
@@ -0,0 +1,767 @@
|
||||
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
|
||||
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
Copyright 2010 Lennart Poettering
|
||||
|
||||
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 "gunicode.h"
|
||||
#include "utf8.h"
|
||||
#include "util.h"
|
||||
#include "string-util.h"
|
||||
|
||||
int strcmp_ptr(const char *a, const char *b) {
|
||||
|
||||
/* Like strcmp(), but tries to make sense of NULL pointers */
|
||||
if (a && b)
|
||||
return strcmp(a, b);
|
||||
|
||||
if (!a && b)
|
||||
return -1;
|
||||
|
||||
if (a && !b)
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
char* endswith(const char *s, const char *postfix) {
|
||||
size_t sl, pl;
|
||||
|
||||
assert(s);
|
||||
assert(postfix);
|
||||
|
||||
sl = strlen(s);
|
||||
pl = strlen(postfix);
|
||||
|
||||
if (pl == 0)
|
||||
return (char*) s + sl;
|
||||
|
||||
if (sl < pl)
|
||||
return NULL;
|
||||
|
||||
if (memcmp(s + sl - pl, postfix, pl) != 0)
|
||||
return NULL;
|
||||
|
||||
return (char*) s + sl - pl;
|
||||
}
|
||||
|
||||
char* endswith_no_case(const char *s, const char *postfix) {
|
||||
size_t sl, pl;
|
||||
|
||||
assert(s);
|
||||
assert(postfix);
|
||||
|
||||
sl = strlen(s);
|
||||
pl = strlen(postfix);
|
||||
|
||||
if (pl == 0)
|
||||
return (char*) s + sl;
|
||||
|
||||
if (sl < pl)
|
||||
return NULL;
|
||||
|
||||
if (strcasecmp(s + sl - pl, postfix) != 0)
|
||||
return NULL;
|
||||
|
||||
return (char*) s + sl - pl;
|
||||
}
|
||||
|
||||
char* first_word(const char *s, const char *word) {
|
||||
size_t sl, wl;
|
||||
const char *p;
|
||||
|
||||
assert(s);
|
||||
assert(word);
|
||||
|
||||
/* Checks if the string starts with the specified word, either
|
||||
* followed by NUL or by whitespace. Returns a pointer to the
|
||||
* NUL or the first character after the whitespace. */
|
||||
|
||||
sl = strlen(s);
|
||||
wl = strlen(word);
|
||||
|
||||
if (sl < wl)
|
||||
return NULL;
|
||||
|
||||
if (wl == 0)
|
||||
return (char*) s;
|
||||
|
||||
if (memcmp(s, word, wl) != 0)
|
||||
return NULL;
|
||||
|
||||
p = s + wl;
|
||||
if (*p == 0)
|
||||
return (char*) p;
|
||||
|
||||
if (!strchr(WHITESPACE, *p))
|
||||
return NULL;
|
||||
|
||||
p += strspn(p, WHITESPACE);
|
||||
return (char*) p;
|
||||
}
|
||||
|
||||
static size_t strcspn_escaped(const char *s, const char *reject) {
|
||||
bool escaped = false;
|
||||
int n;
|
||||
|
||||
for (n=0; s[n]; n++) {
|
||||
if (escaped)
|
||||
escaped = false;
|
||||
else if (s[n] == '\\')
|
||||
escaped = true;
|
||||
else if (strchr(reject, s[n]))
|
||||
break;
|
||||
}
|
||||
|
||||
/* if s ends in \, return index of previous char */
|
||||
return n - escaped;
|
||||
}
|
||||
|
||||
/* Split a string into words. */
|
||||
const char* split(const char **state, size_t *l, const char *separator, bool quoted) {
|
||||
const char *current;
|
||||
|
||||
current = *state;
|
||||
|
||||
if (!*current) {
|
||||
assert(**state == '\0');
|
||||
return NULL;
|
||||
}
|
||||
|
||||
current += strspn(current, separator);
|
||||
if (!*current) {
|
||||
*state = current;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (quoted && strchr("\'\"", *current)) {
|
||||
char quotechars[2] = {*current, '\0'};
|
||||
|
||||
*l = strcspn_escaped(current + 1, quotechars);
|
||||
if (current[*l + 1] == '\0' || current[*l + 1] != quotechars[0] ||
|
||||
(current[*l + 2] && !strchr(separator, current[*l + 2]))) {
|
||||
/* right quote missing or garbage at the end */
|
||||
*state = current;
|
||||
return NULL;
|
||||
}
|
||||
*state = current++ + *l + 2;
|
||||
} else if (quoted) {
|
||||
*l = strcspn_escaped(current, separator);
|
||||
if (current[*l] && !strchr(separator, current[*l])) {
|
||||
/* unfinished escape */
|
||||
*state = current;
|
||||
return NULL;
|
||||
}
|
||||
*state = current + *l;
|
||||
} else {
|
||||
*l = strcspn(current, separator);
|
||||
*state = current + *l;
|
||||
}
|
||||
|
||||
return current;
|
||||
}
|
||||
|
||||
char *strnappend(const char *s, const char *suffix, size_t b) {
|
||||
size_t a;
|
||||
char *r;
|
||||
|
||||
if (!s && !suffix)
|
||||
return strdup("");
|
||||
|
||||
if (!s)
|
||||
return strndup(suffix, b);
|
||||
|
||||
if (!suffix)
|
||||
return strdup(s);
|
||||
|
||||
assert(s);
|
||||
assert(suffix);
|
||||
|
||||
a = strlen(s);
|
||||
if (b > ((size_t) -1) - a)
|
||||
return NULL;
|
||||
|
||||
r = new(char, a+b+1);
|
||||
if (!r)
|
||||
return NULL;
|
||||
|
||||
memcpy(r, s, a);
|
||||
memcpy(r+a, suffix, b);
|
||||
r[a+b] = 0;
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
char *strappend(const char *s, const char *suffix) {
|
||||
return strnappend(s, suffix, suffix ? strlen(suffix) : 0);
|
||||
}
|
||||
|
||||
char *strjoin(const char *x, ...) {
|
||||
va_list ap;
|
||||
size_t l;
|
||||
char *r, *p;
|
||||
|
||||
va_start(ap, x);
|
||||
|
||||
if (x) {
|
||||
l = strlen(x);
|
||||
|
||||
for (;;) {
|
||||
const char *t;
|
||||
size_t n;
|
||||
|
||||
t = va_arg(ap, const char *);
|
||||
if (!t)
|
||||
break;
|
||||
|
||||
n = strlen(t);
|
||||
if (n > ((size_t) -1) - l) {
|
||||
va_end(ap);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
l += n;
|
||||
}
|
||||
} else
|
||||
l = 0;
|
||||
|
||||
va_end(ap);
|
||||
|
||||
r = new(char, l+1);
|
||||
if (!r)
|
||||
return NULL;
|
||||
|
||||
if (x) {
|
||||
p = stpcpy(r, x);
|
||||
|
||||
va_start(ap, x);
|
||||
|
||||
for (;;) {
|
||||
const char *t;
|
||||
|
||||
t = va_arg(ap, const char *);
|
||||
if (!t)
|
||||
break;
|
||||
|
||||
p = stpcpy(p, t);
|
||||
}
|
||||
|
||||
va_end(ap);
|
||||
} else
|
||||
r[0] = 0;
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
char *strstrip(char *s) {
|
||||
char *e;
|
||||
|
||||
/* Drops trailing whitespace. Modifies the string in
|
||||
* place. Returns pointer to first non-space character */
|
||||
|
||||
s += strspn(s, WHITESPACE);
|
||||
|
||||
for (e = strchr(s, 0); e > s; e --)
|
||||
if (!strchr(WHITESPACE, e[-1]))
|
||||
break;
|
||||
|
||||
*e = 0;
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
char *delete_chars(char *s, const char *bad) {
|
||||
char *f, *t;
|
||||
|
||||
/* Drops all whitespace, regardless where in the string */
|
||||
|
||||
for (f = s, t = s; *f; f++) {
|
||||
if (strchr(bad, *f))
|
||||
continue;
|
||||
|
||||
*(t++) = *f;
|
||||
}
|
||||
|
||||
*t = 0;
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
char *truncate_nl(char *s) {
|
||||
assert(s);
|
||||
|
||||
s[strcspn(s, NEWLINE)] = 0;
|
||||
return s;
|
||||
}
|
||||
|
||||
char *ascii_strlower(char *t) {
|
||||
char *p;
|
||||
|
||||
assert(t);
|
||||
|
||||
for (p = t; *p; p++)
|
||||
if (*p >= 'A' && *p <= 'Z')
|
||||
*p = *p - 'A' + 'a';
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
bool chars_intersect(const char *a, const char *b) {
|
||||
const char *p;
|
||||
|
||||
/* Returns true if any of the chars in a are in b. */
|
||||
for (p = a; *p; p++)
|
||||
if (strchr(b, *p))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool string_has_cc(const char *p, const char *ok) {
|
||||
const char *t;
|
||||
|
||||
assert(p);
|
||||
|
||||
/*
|
||||
* Check if a string contains control characters. If 'ok' is
|
||||
* non-NULL it may be a string containing additional CCs to be
|
||||
* considered OK.
|
||||
*/
|
||||
|
||||
for (t = p; *t; t++) {
|
||||
if (ok && strchr(ok, *t))
|
||||
continue;
|
||||
|
||||
if (*t > 0 && *t < ' ')
|
||||
return true;
|
||||
|
||||
if (*t == 127)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static char *ascii_ellipsize_mem(const char *s, size_t old_length, size_t new_length, unsigned percent) {
|
||||
size_t x;
|
||||
char *r;
|
||||
|
||||
assert(s);
|
||||
assert(percent <= 100);
|
||||
assert(new_length >= 3);
|
||||
|
||||
if (old_length <= 3 || old_length <= new_length)
|
||||
return strndup(s, old_length);
|
||||
|
||||
r = new0(char, new_length+1);
|
||||
if (!r)
|
||||
return NULL;
|
||||
|
||||
x = (new_length * percent) / 100;
|
||||
|
||||
if (x > new_length - 3)
|
||||
x = new_length - 3;
|
||||
|
||||
memcpy(r, s, x);
|
||||
r[x] = '.';
|
||||
r[x+1] = '.';
|
||||
r[x+2] = '.';
|
||||
memcpy(r + x + 3,
|
||||
s + old_length - (new_length - x - 3),
|
||||
new_length - x - 3);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
char *ellipsize_mem(const char *s, size_t old_length, size_t new_length, unsigned percent) {
|
||||
size_t x;
|
||||
char *e;
|
||||
const char *i, *j;
|
||||
unsigned k, len, len2;
|
||||
|
||||
assert(s);
|
||||
assert(percent <= 100);
|
||||
assert(new_length >= 3);
|
||||
|
||||
/* if no multibyte characters use ascii_ellipsize_mem for speed */
|
||||
if (ascii_is_valid(s))
|
||||
return ascii_ellipsize_mem(s, old_length, new_length, percent);
|
||||
|
||||
if (old_length <= 3 || old_length <= new_length)
|
||||
return strndup(s, old_length);
|
||||
|
||||
x = (new_length * percent) / 100;
|
||||
|
||||
if (x > new_length - 3)
|
||||
x = new_length - 3;
|
||||
|
||||
k = 0;
|
||||
for (i = s; k < x && i < s + old_length; i = utf8_next_char(i)) {
|
||||
int c;
|
||||
|
||||
c = utf8_encoded_to_unichar(i);
|
||||
if (c < 0)
|
||||
return NULL;
|
||||
k += unichar_iswide(c) ? 2 : 1;
|
||||
}
|
||||
|
||||
if (k > x) /* last character was wide and went over quota */
|
||||
x ++;
|
||||
|
||||
for (j = s + old_length; k < new_length && j > i; ) {
|
||||
int c;
|
||||
|
||||
j = utf8_prev_char(j);
|
||||
c = utf8_encoded_to_unichar(j);
|
||||
if (c < 0)
|
||||
return NULL;
|
||||
k += unichar_iswide(c) ? 2 : 1;
|
||||
}
|
||||
assert(i <= j);
|
||||
|
||||
/* we don't actually need to ellipsize */
|
||||
if (i == j)
|
||||
return memdup(s, old_length + 1);
|
||||
|
||||
/* make space for ellipsis */
|
||||
j = utf8_next_char(j);
|
||||
|
||||
len = i - s;
|
||||
len2 = s + old_length - j;
|
||||
e = new(char, len + 3 + len2 + 1);
|
||||
if (!e)
|
||||
return NULL;
|
||||
|
||||
/*
|
||||
printf("old_length=%zu new_length=%zu x=%zu len=%u len2=%u k=%u\n",
|
||||
old_length, new_length, x, len, len2, k);
|
||||
*/
|
||||
|
||||
memcpy(e, s, len);
|
||||
e[len] = 0xe2; /* tri-dot ellipsis: … */
|
||||
e[len + 1] = 0x80;
|
||||
e[len + 2] = 0xa6;
|
||||
|
||||
memcpy(e + len + 3, j, len2 + 1);
|
||||
|
||||
return e;
|
||||
}
|
||||
|
||||
char *ellipsize(const char *s, size_t length, unsigned percent) {
|
||||
return ellipsize_mem(s, strlen(s), length, percent);
|
||||
}
|
||||
|
||||
bool nulstr_contains(const char*nulstr, const char *needle) {
|
||||
const char *i;
|
||||
|
||||
if (!nulstr)
|
||||
return false;
|
||||
|
||||
NULSTR_FOREACH(i, nulstr)
|
||||
if (streq(i, needle))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
char* strshorten(char *s, size_t l) {
|
||||
assert(s);
|
||||
|
||||
if (l < strlen(s))
|
||||
s[l] = 0;
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
char *strreplace(const char *text, const char *old_string, const char *new_string) {
|
||||
const char *f;
|
||||
char *t, *r;
|
||||
size_t l, old_len, new_len;
|
||||
|
||||
assert(text);
|
||||
assert(old_string);
|
||||
assert(new_string);
|
||||
|
||||
old_len = strlen(old_string);
|
||||
new_len = strlen(new_string);
|
||||
|
||||
l = strlen(text);
|
||||
r = new(char, l+1);
|
||||
if (!r)
|
||||
return NULL;
|
||||
|
||||
f = text;
|
||||
t = r;
|
||||
while (*f) {
|
||||
char *a;
|
||||
size_t d, nl;
|
||||
|
||||
if (!startswith(f, old_string)) {
|
||||
*(t++) = *(f++);
|
||||
continue;
|
||||
}
|
||||
|
||||
d = t - r;
|
||||
nl = l - old_len + new_len;
|
||||
a = realloc(r, nl + 1);
|
||||
if (!a)
|
||||
goto oom;
|
||||
|
||||
l = nl;
|
||||
r = a;
|
||||
t = r + d;
|
||||
|
||||
t = stpcpy(t, new_string);
|
||||
f += old_len;
|
||||
}
|
||||
|
||||
*t = 0;
|
||||
return r;
|
||||
|
||||
oom:
|
||||
free(r);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char *strip_tab_ansi(char **ibuf, size_t *_isz) {
|
||||
const char *i, *begin = NULL;
|
||||
enum {
|
||||
STATE_OTHER,
|
||||
STATE_ESCAPE,
|
||||
STATE_BRACKET
|
||||
} state = STATE_OTHER;
|
||||
char *obuf = NULL;
|
||||
size_t osz = 0, isz;
|
||||
FILE *f;
|
||||
|
||||
assert(ibuf);
|
||||
assert(*ibuf);
|
||||
|
||||
/* Strips ANSI color and replaces TABs by 8 spaces */
|
||||
|
||||
isz = _isz ? *_isz : strlen(*ibuf);
|
||||
|
||||
f = open_memstream(&obuf, &osz);
|
||||
if (!f)
|
||||
return NULL;
|
||||
|
||||
for (i = *ibuf; i < *ibuf + isz + 1; i++) {
|
||||
|
||||
switch (state) {
|
||||
|
||||
case STATE_OTHER:
|
||||
if (i >= *ibuf + isz) /* EOT */
|
||||
break;
|
||||
else if (*i == '\x1B')
|
||||
state = STATE_ESCAPE;
|
||||
else if (*i == '\t')
|
||||
fputs(" ", f);
|
||||
else
|
||||
fputc(*i, f);
|
||||
break;
|
||||
|
||||
case STATE_ESCAPE:
|
||||
if (i >= *ibuf + isz) { /* EOT */
|
||||
fputc('\x1B', f);
|
||||
break;
|
||||
} else if (*i == '[') {
|
||||
state = STATE_BRACKET;
|
||||
begin = i + 1;
|
||||
} else {
|
||||
fputc('\x1B', f);
|
||||
fputc(*i, f);
|
||||
state = STATE_OTHER;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case STATE_BRACKET:
|
||||
|
||||
if (i >= *ibuf + isz || /* EOT */
|
||||
(!(*i >= '0' && *i <= '9') && *i != ';' && *i != 'm')) {
|
||||
fputc('\x1B', f);
|
||||
fputc('[', f);
|
||||
state = STATE_OTHER;
|
||||
i = begin-1;
|
||||
} else if (*i == 'm')
|
||||
state = STATE_OTHER;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (ferror(f)) {
|
||||
fclose(f);
|
||||
free(obuf);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
fclose(f);
|
||||
|
||||
free(*ibuf);
|
||||
*ibuf = obuf;
|
||||
|
||||
if (_isz)
|
||||
*_isz = osz;
|
||||
|
||||
return obuf;
|
||||
}
|
||||
|
||||
char *strextend(char **x, ...) {
|
||||
va_list ap;
|
||||
size_t f, l;
|
||||
char *r, *p;
|
||||
|
||||
assert(x);
|
||||
|
||||
l = f = *x ? strlen(*x) : 0;
|
||||
|
||||
va_start(ap, x);
|
||||
for (;;) {
|
||||
const char *t;
|
||||
size_t n;
|
||||
|
||||
t = va_arg(ap, const char *);
|
||||
if (!t)
|
||||
break;
|
||||
|
||||
n = strlen(t);
|
||||
if (n > ((size_t) -1) - l) {
|
||||
va_end(ap);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
l += n;
|
||||
}
|
||||
va_end(ap);
|
||||
|
||||
r = realloc(*x, l+1);
|
||||
if (!r)
|
||||
return NULL;
|
||||
|
||||
p = r + f;
|
||||
|
||||
va_start(ap, x);
|
||||
for (;;) {
|
||||
const char *t;
|
||||
|
||||
t = va_arg(ap, const char *);
|
||||
if (!t)
|
||||
break;
|
||||
|
||||
p = stpcpy(p, t);
|
||||
}
|
||||
va_end(ap);
|
||||
|
||||
*p = 0;
|
||||
*x = r;
|
||||
|
||||
return r + l;
|
||||
}
|
||||
|
||||
char *strrep(const char *s, unsigned n) {
|
||||
size_t l;
|
||||
char *r, *p;
|
||||
unsigned i;
|
||||
|
||||
assert(s);
|
||||
|
||||
l = strlen(s);
|
||||
p = r = malloc(l * n + 1);
|
||||
if (!r)
|
||||
return NULL;
|
||||
|
||||
for (i = 0; i < n; i++)
|
||||
p = stpcpy(p, s);
|
||||
|
||||
*p = 0;
|
||||
return r;
|
||||
}
|
||||
|
||||
int split_pair(const char *s, const char *sep, char **l, char **r) {
|
||||
char *x, *a, *b;
|
||||
|
||||
assert(s);
|
||||
assert(sep);
|
||||
assert(l);
|
||||
assert(r);
|
||||
|
||||
if (isempty(sep))
|
||||
return -EINVAL;
|
||||
|
||||
x = strstr(s, sep);
|
||||
if (!x)
|
||||
return -EINVAL;
|
||||
|
||||
a = strndup(s, x - s);
|
||||
if (!a)
|
||||
return -ENOMEM;
|
||||
|
||||
b = strdup(x + strlen(sep));
|
||||
if (!b) {
|
||||
free(a);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
*l = a;
|
||||
*r = b;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int free_and_strdup(char **p, const char *s) {
|
||||
char *t;
|
||||
|
||||
assert(p);
|
||||
|
||||
/* Replaces a string pointer with an strdup()ed new string,
|
||||
* possibly freeing the old one. */
|
||||
|
||||
if (streq_ptr(*p, s))
|
||||
return 0;
|
||||
|
||||
if (s) {
|
||||
t = strdup(s);
|
||||
if (!t)
|
||||
return -ENOMEM;
|
||||
} else
|
||||
t = NULL;
|
||||
|
||||
free(*p);
|
||||
*p = t;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
void string_erase(char *x) {
|
||||
|
||||
if (!x)
|
||||
return;
|
||||
|
||||
/* A delicious drop of snake-oil! To be called on memory where
|
||||
* we stored passphrases or so, after we used them. */
|
||||
|
||||
memory_erase(x, strlen(x));
|
||||
}
|
||||
|
||||
char *string_free_erase(char *s) {
|
||||
if (!s)
|
||||
return NULL;
|
||||
|
||||
string_erase(s);
|
||||
return mfree(s);
|
||||
}
|
||||
@@ -0,0 +1,170 @@
|
||||
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
|
||||
|
||||
#pragma once
|
||||
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
Copyright 2010 Lennart Poettering
|
||||
|
||||
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 <stdbool.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "macro.h"
|
||||
|
||||
#define streq(a,b) (strcmp((a),(b)) == 0)
|
||||
#define strneq(a, b, n) (strncmp((a), (b), (n)) == 0)
|
||||
#define strcaseeq(a,b) (strcasecmp((a),(b)) == 0)
|
||||
#define strncaseeq(a, b, n) (strncasecmp((a), (b), (n)) == 0)
|
||||
|
||||
int strcmp_ptr(const char *a, const char *b) _pure_;
|
||||
|
||||
static inline bool streq_ptr(const char *a, const char *b) {
|
||||
return strcmp_ptr(a, b) == 0;
|
||||
}
|
||||
|
||||
static inline const char* strempty(const char *s) {
|
||||
return s ? s : "";
|
||||
}
|
||||
|
||||
static inline const char* strnull(const char *s) {
|
||||
return s ? s : "(null)";
|
||||
}
|
||||
|
||||
static inline const char *strna(const char *s) {
|
||||
return s ? s : "n/a";
|
||||
}
|
||||
|
||||
static inline bool isempty(const char *p) {
|
||||
return !p || !p[0];
|
||||
}
|
||||
|
||||
static inline char *startswith(const char *s, const char *prefix) {
|
||||
size_t l;
|
||||
|
||||
l = strlen(prefix);
|
||||
if (strncmp(s, prefix, l) == 0)
|
||||
return (char*) s + l;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static inline char *startswith_no_case(const char *s, const char *prefix) {
|
||||
size_t l;
|
||||
|
||||
l = strlen(prefix);
|
||||
if (strncasecmp(s, prefix, l) == 0)
|
||||
return (char*) s + l;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char *endswith(const char *s, const char *postfix) _pure_;
|
||||
char *endswith_no_case(const char *s, const char *postfix) _pure_;
|
||||
|
||||
char *first_word(const char *s, const char *word) _pure_;
|
||||
|
||||
const char* split(const char **state, size_t *l, const char *separator, bool quoted);
|
||||
|
||||
#define FOREACH_WORD(word, length, s, state) \
|
||||
_FOREACH_WORD(word, length, s, WHITESPACE, false, state)
|
||||
|
||||
#define FOREACH_WORD_SEPARATOR(word, length, s, separator, state) \
|
||||
_FOREACH_WORD(word, length, s, separator, false, state)
|
||||
|
||||
#define FOREACH_WORD_QUOTED(word, length, s, state) \
|
||||
_FOREACH_WORD(word, length, s, WHITESPACE, true, state)
|
||||
|
||||
#define _FOREACH_WORD(word, length, s, separator, quoted, state) \
|
||||
for ((state) = (s), (word) = split(&(state), &(length), (separator), (quoted)); (word); (word) = split(&(state), &(length), (separator), (quoted)))
|
||||
|
||||
char *strappend(const char *s, const char *suffix);
|
||||
char *strnappend(const char *s, const char *suffix, size_t length);
|
||||
|
||||
char *strjoin(const char *x, ...) _sentinel_;
|
||||
|
||||
#define strjoina(a, ...) \
|
||||
({ \
|
||||
const char *_appendees_[] = { a, __VA_ARGS__ }; \
|
||||
char *_d_, *_p_; \
|
||||
int _len_ = 0; \
|
||||
unsigned _i_; \
|
||||
for (_i_ = 0; _i_ < ELEMENTSOF(_appendees_) && _appendees_[_i_]; _i_++) \
|
||||
_len_ += strlen(_appendees_[_i_]); \
|
||||
_p_ = _d_ = alloca(_len_ + 1); \
|
||||
for (_i_ = 0; _i_ < ELEMENTSOF(_appendees_) && _appendees_[_i_]; _i_++) \
|
||||
_p_ = stpcpy(_p_, _appendees_[_i_]); \
|
||||
*_p_ = 0; \
|
||||
_d_; \
|
||||
})
|
||||
|
||||
char *strstrip(char *s);
|
||||
char *delete_chars(char *s, const char *bad);
|
||||
char *truncate_nl(char *s);
|
||||
|
||||
char *ascii_strlower(char *path);
|
||||
|
||||
bool chars_intersect(const char *a, const char *b) _pure_;
|
||||
|
||||
static inline bool _pure_ in_charset(const char *s, const char* charset) {
|
||||
assert(s);
|
||||
assert(charset);
|
||||
return s[strspn(s, charset)] == '\0';
|
||||
}
|
||||
|
||||
bool string_has_cc(const char *p, const char *ok) _pure_;
|
||||
|
||||
char *ellipsize_mem(const char *s, size_t old_length_bytes, size_t new_length_columns, unsigned percent);
|
||||
char *ellipsize(const char *s, size_t length, unsigned percent);
|
||||
|
||||
bool nulstr_contains(const char*nulstr, const char *needle);
|
||||
|
||||
char* strshorten(char *s, size_t l);
|
||||
|
||||
char *strreplace(const char *text, const char *old_string, const char *new_string);
|
||||
|
||||
char *strip_tab_ansi(char **p, size_t *l);
|
||||
|
||||
char *strextend(char **x, ...) _sentinel_;
|
||||
|
||||
char *strrep(const char *s, unsigned n);
|
||||
|
||||
int split_pair(const char *s, const char *sep, char **l, char **r);
|
||||
|
||||
int free_and_strdup(char **p, const char *s);
|
||||
|
||||
/* Normal memmem() requires haystack to be nonnull, which is annoying for zero-length buffers */
|
||||
static inline void *memmem_safe(const void *haystack, size_t haystacklen, const void *needle, size_t needlelen) {
|
||||
|
||||
if (needlelen <= 0)
|
||||
return (void*) haystack;
|
||||
|
||||
if (haystacklen < needlelen)
|
||||
return NULL;
|
||||
|
||||
assert(haystack);
|
||||
assert(needle);
|
||||
|
||||
return memmem(haystack, haystacklen, needle, needlelen);
|
||||
}
|
||||
|
||||
#define memory_erase(p, l) memset((p), 'x', (l))
|
||||
void string_erase(char *x);
|
||||
|
||||
char *string_free_erase(char *s);
|
||||
DEFINE_TRIVIAL_CLEANUP_FUNC(char *, string_free_erase);
|
||||
#define _cleanup_string_free_erase_ _cleanup_(string_free_erasep)
|
||||
+5
-3
@@ -19,11 +19,13 @@
|
||||
along with systemd; If not, see <http://www.gnu.org/licenses/>.
|
||||
***/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "escape.h"
|
||||
#include "string-util.h"
|
||||
#include "util.h"
|
||||
#include "strv.h"
|
||||
|
||||
|
||||
+2
-1
@@ -21,10 +21,11 @@
|
||||
along with systemd; If not, see <http://www.gnu.org/licenses/>.
|
||||
***/
|
||||
|
||||
#include <fnmatch.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
#include <fnmatch.h>
|
||||
|
||||
#include "extract-word.h"
|
||||
#include "util.h"
|
||||
|
||||
char *strv_find(char **l, const char *name) _pure_;
|
||||
|
||||
+17
-15
@@ -17,26 +17,28 @@
|
||||
along with systemd; If not, see <http://www.gnu.org/licenses/>.
|
||||
***/
|
||||
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <signal.h>
|
||||
#include <time.h>
|
||||
#include <assert.h>
|
||||
#include <poll.h>
|
||||
#include <linux/vt.h>
|
||||
#include <linux/tiocl.h>
|
||||
#include <fcntl.h>
|
||||
#include <linux/kd.h>
|
||||
#include <linux/tiocl.h>
|
||||
#include <linux/vt.h>
|
||||
#include <poll.h>
|
||||
#include <signal.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <termios.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "terminal-util.h"
|
||||
#include "time-util.h"
|
||||
#include "process-util.h"
|
||||
#include "util.h"
|
||||
#include "fd-util.h"
|
||||
#include "fileio.h"
|
||||
#include "path-util.h"
|
||||
#include "process-util.h"
|
||||
#include "string-util.h"
|
||||
#include "terminal-util.h"
|
||||
#include "time-util.h"
|
||||
#include "util.h"
|
||||
|
||||
static volatile unsigned cached_columns = 0;
|
||||
static volatile unsigned cached_lines = 0;
|
||||
|
||||
@@ -20,13 +20,15 @@
|
||||
***/
|
||||
|
||||
#include <string.h>
|
||||
#include <sys/timex.h>
|
||||
#include <sys/timerfd.h>
|
||||
#include <sys/timex.h>
|
||||
|
||||
#include "util.h"
|
||||
#include "time-util.h"
|
||||
#include "fd-util.h"
|
||||
#include "path-util.h"
|
||||
#include "string-util.h"
|
||||
#include "strv.h"
|
||||
#include "time-util.h"
|
||||
#include "util.h"
|
||||
|
||||
usec_t now(clockid_t clock_id) {
|
||||
struct timespec ts;
|
||||
|
||||
@@ -22,12 +22,13 @@
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "path-util.h"
|
||||
#include "bus-label.h"
|
||||
#include "def.h"
|
||||
#include "path-util.h"
|
||||
#include "string-util.h"
|
||||
#include "strv.h"
|
||||
#include "util.h"
|
||||
#include "unit-name.h"
|
||||
#include "def.h"
|
||||
#include "strv.h"
|
||||
|
||||
#define VALID_CHARS \
|
||||
DIGITS LETTERS \
|
||||
|
||||
+3
-1745
File diff suppressed because it is too large
Load Diff
@@ -53,25 +53,11 @@
|
||||
#define COMMENTS "#;"
|
||||
#define GLOB_CHARS "*?["
|
||||
|
||||
/* What characters are special in the shell? */
|
||||
/* must be escaped outside and inside double-quotes */
|
||||
#define SHELL_NEED_ESCAPE "\"\\`$"
|
||||
/* can be escaped or double-quoted */
|
||||
#define SHELL_NEED_QUOTES SHELL_NEED_ESCAPE GLOB_CHARS "'()<>|&;"
|
||||
|
||||
#define FORMAT_BYTES_MAX 8
|
||||
|
||||
size_t page_size(void) _pure_;
|
||||
#define PAGE_ALIGN(l) ALIGN_TO((l), page_size())
|
||||
|
||||
#define streq(a,b) (strcmp((a),(b)) == 0)
|
||||
#define strneq(a, b, n) (strncmp((a), (b), (n)) == 0)
|
||||
#define strcaseeq(a,b) (strcasecmp((a),(b)) == 0)
|
||||
#define strncaseeq(a, b, n) (strncasecmp((a), (b), (n)) == 0)
|
||||
|
||||
bool streq_ptr(const char *a, const char *b) _pure_;
|
||||
int strcmp_ptr(const char *a, const char *b) _pure_;
|
||||
|
||||
#define new(t, n) ((t*) malloc_multiply(sizeof(t), (n)))
|
||||
|
||||
#define new0(t, n) ((t*) calloc((n), sizeof(t)))
|
||||
@@ -101,57 +87,6 @@ static inline const char* one_zero(bool b) {
|
||||
return b ? "1" : "0";
|
||||
}
|
||||
|
||||
static inline const char* strempty(const char *s) {
|
||||
return s ? s : "";
|
||||
}
|
||||
|
||||
static inline const char* strnull(const char *s) {
|
||||
return s ? s : "(null)";
|
||||
}
|
||||
|
||||
static inline const char *strna(const char *s) {
|
||||
return s ? s : "n/a";
|
||||
}
|
||||
|
||||
static inline bool isempty(const char *p) {
|
||||
return !p || !p[0];
|
||||
}
|
||||
|
||||
static inline char *startswith(const char *s, const char *prefix) {
|
||||
size_t l;
|
||||
|
||||
l = strlen(prefix);
|
||||
if (strncmp(s, prefix, l) == 0)
|
||||
return (char*) s + l;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static inline char *startswith_no_case(const char *s, const char *prefix) {
|
||||
size_t l;
|
||||
|
||||
l = strlen(prefix);
|
||||
if (strncasecmp(s, prefix, l) == 0)
|
||||
return (char*) s + l;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char *endswith(const char *s, const char *postfix) _pure_;
|
||||
char *endswith_no_case(const char *s, const char *postfix) _pure_;
|
||||
|
||||
char *first_word(const char *s, const char *word) _pure_;
|
||||
|
||||
int close_nointr(int fd);
|
||||
int safe_close(int fd);
|
||||
void safe_close_pair(int p[]);
|
||||
|
||||
void close_many(const int fds[], unsigned n_fd);
|
||||
|
||||
int fclose_nointr(FILE *f);
|
||||
FILE* safe_fclose(FILE *f);
|
||||
DIR* safe_closedir(DIR *f);
|
||||
|
||||
int parse_size(const char *t, uint64_t base, uint64_t *size);
|
||||
|
||||
int parse_boolean(const char *v) _pure_;
|
||||
@@ -218,33 +153,12 @@ static inline int safe_atoi64(const char *s, int64_t *ret_i) {
|
||||
int safe_atou16(const char *s, uint16_t *ret);
|
||||
int safe_atoi16(const char *s, int16_t *ret);
|
||||
|
||||
const char* split(const char **state, size_t *l, const char *separator, bool quoted);
|
||||
|
||||
#define FOREACH_WORD(word, length, s, state) \
|
||||
_FOREACH_WORD(word, length, s, WHITESPACE, false, state)
|
||||
|
||||
#define FOREACH_WORD_SEPARATOR(word, length, s, separator, state) \
|
||||
_FOREACH_WORD(word, length, s, separator, false, state)
|
||||
|
||||
#define FOREACH_WORD_QUOTED(word, length, s, state) \
|
||||
_FOREACH_WORD(word, length, s, WHITESPACE, true, state)
|
||||
|
||||
#define _FOREACH_WORD(word, length, s, separator, quoted, state) \
|
||||
for ((state) = (s), (word) = split(&(state), &(length), (separator), (quoted)); (word); (word) = split(&(state), &(length), (separator), (quoted)))
|
||||
|
||||
char *strappend(const char *s, const char *suffix);
|
||||
char *strnappend(const char *s, const char *suffix, size_t length);
|
||||
|
||||
int readlinkat_malloc(int fd, const char *p, char **ret);
|
||||
int readlink_malloc(const char *p, char **r);
|
||||
int readlink_value(const char *p, char **ret);
|
||||
int readlink_and_make_absolute(const char *p, char **r);
|
||||
int readlink_and_canonicalize(const char *p, char **r);
|
||||
|
||||
char *strstrip(char *s);
|
||||
char *delete_chars(char *s, const char *bad);
|
||||
char *truncate_nl(char *s);
|
||||
|
||||
char *file_in_same_dir(const char *path, const char *filename);
|
||||
|
||||
int rmdir_parents(const char *path, const char *stop);
|
||||
@@ -260,28 +174,11 @@ int unbase32hexchar(char c) _const_;
|
||||
char base64char(int x) _const_;
|
||||
int unbase64char(char c) _const_;
|
||||
|
||||
char *cescape(const char *s);
|
||||
size_t cescape_char(char c, char *buf);
|
||||
|
||||
typedef enum UnescapeFlags {
|
||||
UNESCAPE_RELAX = 1,
|
||||
} UnescapeFlags;
|
||||
|
||||
int cunescape(const char *s, UnescapeFlags flags, char **ret);
|
||||
int cunescape_length(const char *s, size_t length, UnescapeFlags flags, char **ret);
|
||||
int cunescape_length_with_prefix(const char *s, size_t length, const char *prefix, UnescapeFlags flags, char **ret);
|
||||
|
||||
char *xescape(const char *s, const char *bad);
|
||||
|
||||
char *ascii_strlower(char *path);
|
||||
|
||||
bool dirent_is_file(const struct dirent *de) _pure_;
|
||||
bool dirent_is_file_with_suffix(const struct dirent *de, const char *suffix) _pure_;
|
||||
|
||||
bool hidden_file(const char *filename) _pure_;
|
||||
|
||||
bool chars_intersect(const char *a, const char *b) _pure_;
|
||||
|
||||
/* For basic lookup tables with strictly enumerated entries */
|
||||
#define _DEFINE_STRING_TABLE_LOOKUP_TO_STRING(name,type,scope) \
|
||||
scope const char *name##_to_string(type i) { \
|
||||
@@ -338,11 +235,6 @@ ssize_t string_table_lookup(const char * const *table, size_t len, const char *k
|
||||
} \
|
||||
struct __useless_struct_to_allow_trailing_semicolon__
|
||||
|
||||
int fd_nonblock(int fd, bool nonblock);
|
||||
int fd_cloexec(int fd, bool cloexec);
|
||||
|
||||
int close_all_fds(const int except[], unsigned n_except);
|
||||
|
||||
bool fstype_is_network(const char *fstype);
|
||||
|
||||
int flush_fd(int fd);
|
||||
@@ -392,10 +284,6 @@ int files_same(const char *filea, const char *fileb);
|
||||
|
||||
int running_in_chroot(void);
|
||||
|
||||
char *ellipsize(const char *s, size_t length, unsigned percent);
|
||||
/* bytes columns */
|
||||
char *ellipsize_mem(const char *s, size_t old_length, size_t new_length, unsigned percent);
|
||||
|
||||
int touch_file(const char *path, bool parents, usec_t stamp, uid_t uid, gid_t gid, mode_t mode);
|
||||
int touch(const char *path);
|
||||
|
||||
@@ -411,12 +299,8 @@ char *fstab_node_to_udev_node(const char *p);
|
||||
|
||||
void execute_directories(const char* const* directories, usec_t timeout, char *argv[]);
|
||||
|
||||
bool nulstr_contains(const char*nulstr, const char *needle);
|
||||
|
||||
bool plymouth_running(void);
|
||||
|
||||
char* strshorten(char *s, size_t l);
|
||||
|
||||
int symlink_idempotent(const char *from, const char *to);
|
||||
|
||||
int symlink_atomic(const char *from, const char *to);
|
||||
@@ -444,16 +328,8 @@ int dirent_ensure_type(DIR *d, struct dirent *de);
|
||||
|
||||
int get_files_in_directory(const char *path, char ***list);
|
||||
|
||||
char *strjoin(const char *x, ...) _sentinel_;
|
||||
|
||||
bool is_main_thread(void);
|
||||
|
||||
static inline bool _pure_ in_charset(const char *s, const char* charset) {
|
||||
assert(s);
|
||||
assert(charset);
|
||||
return s[strspn(s, charset)] == '\0';
|
||||
}
|
||||
|
||||
int block_get_whole_disk(dev_t d, dev_t *ret);
|
||||
|
||||
#define NULSTR_FOREACH(i, l) \
|
||||
@@ -519,35 +395,16 @@ static inline void freep(void *p) {
|
||||
free(*(void**) p);
|
||||
}
|
||||
|
||||
static inline void closep(int *fd) {
|
||||
safe_close(*fd);
|
||||
}
|
||||
|
||||
static inline void umaskp(mode_t *u) {
|
||||
umask(*u);
|
||||
}
|
||||
|
||||
static inline void close_pairp(int (*p)[2]) {
|
||||
safe_close_pair(*p);
|
||||
}
|
||||
|
||||
static inline void fclosep(FILE **f) {
|
||||
safe_fclose(*f);
|
||||
}
|
||||
|
||||
DEFINE_TRIVIAL_CLEANUP_FUNC(FILE*, pclose);
|
||||
DEFINE_TRIVIAL_CLEANUP_FUNC(DIR*, closedir);
|
||||
DEFINE_TRIVIAL_CLEANUP_FUNC(FILE*, endmntent);
|
||||
|
||||
#define _cleanup_free_ _cleanup_(freep)
|
||||
#define _cleanup_close_ _cleanup_(closep)
|
||||
#define _cleanup_umask_ _cleanup_(umaskp)
|
||||
#define _cleanup_globfree_ _cleanup_(globfree)
|
||||
#define _cleanup_fclose_ _cleanup_(fclosep)
|
||||
#define _cleanup_pclose_ _cleanup_(pclosep)
|
||||
#define _cleanup_closedir_ _cleanup_(closedirp)
|
||||
#define _cleanup_endmntent_ _cleanup_(endmntentp)
|
||||
#define _cleanup_close_pair_ _cleanup_(close_pairp)
|
||||
|
||||
_malloc_ _alloc_(1, 2) static inline void *malloc_multiply(size_t a, size_t b) {
|
||||
if (_unlikely_(b != 0 && a > ((size_t) -1) / b))
|
||||
@@ -573,7 +430,6 @@ _alloc_(2, 3) static inline void *memdup_multiply(const void *p, size_t a, size_
|
||||
bool filename_is_valid(const char *p) _pure_;
|
||||
bool path_is_safe(const char *p) _pure_;
|
||||
bool string_is_safe(const char *p) _pure_;
|
||||
bool string_has_cc(const char *p, const char *ok) _pure_;
|
||||
|
||||
/**
|
||||
* Check if a string contains any glob patterns.
|
||||
@@ -605,10 +461,6 @@ typedef enum DrawSpecialChar {
|
||||
|
||||
const char *draw_special_char(DrawSpecialChar ch);
|
||||
|
||||
char *strreplace(const char *text, const char *old_string, const char *new_string);
|
||||
|
||||
char *strip_tab_ansi(char **p, size_t *l);
|
||||
|
||||
int on_ac_power(void);
|
||||
|
||||
int search_and_fopen(const char *path, const char *mode, const char *root, const char **search, FILE **_f);
|
||||
@@ -657,9 +509,6 @@ int unbase32hexmem(const char *p, size_t l, bool padding, void **mem, size_t *le
|
||||
char *base64mem(const void *p, size_t l);
|
||||
int unbase64mem(const char *p, size_t l, void **mem, size_t *len);
|
||||
|
||||
char *strextend(char **x, ...) _sentinel_;
|
||||
char *strrep(const char *s, unsigned n);
|
||||
|
||||
void* greedy_realloc(void **p, size_t *allocated, size_t need, size_t size);
|
||||
void* greedy_realloc0(void **p, size_t *allocated, size_t need, size_t size);
|
||||
#define GREEDY_REALLOC(array, allocated, need) \
|
||||
@@ -734,10 +583,6 @@ static inline unsigned log2u_round_up(unsigned x) {
|
||||
return log2u(x - 1) + 1;
|
||||
}
|
||||
|
||||
static inline bool logind_running(void) {
|
||||
return access("/run/systemd/seats/", F_OK) >= 0;
|
||||
}
|
||||
|
||||
#define DECIMAL_STR_WIDTH(x) \
|
||||
({ \
|
||||
typeof(x) _x_ = (x); \
|
||||
@@ -774,25 +619,8 @@ int unlink_noerrno(const char *path);
|
||||
(void*)memset(_new_, 0, _size_); \
|
||||
})
|
||||
|
||||
#define strjoina(a, ...) \
|
||||
({ \
|
||||
const char *_appendees_[] = { a, __VA_ARGS__ }; \
|
||||
char *_d_, *_p_; \
|
||||
int _len_ = 0; \
|
||||
unsigned _i_; \
|
||||
for (_i_ = 0; _i_ < ELEMENTSOF(_appendees_) && _appendees_[_i_]; _i_++) \
|
||||
_len_ += strlen(_appendees_[_i_]); \
|
||||
_p_ = _d_ = alloca(_len_ + 1); \
|
||||
for (_i_ = 0; _i_ < ELEMENTSOF(_appendees_) && _appendees_[_i_]; _i_++) \
|
||||
_p_ = stpcpy(_p_, _appendees_[_i_]); \
|
||||
*_p_ = 0; \
|
||||
_d_; \
|
||||
})
|
||||
|
||||
bool id128_is_valid(const char *s) _pure_;
|
||||
|
||||
int split_pair(const char *s, const char *sep, char **l, char **r);
|
||||
|
||||
int shall_restore_state(void);
|
||||
|
||||
/**
|
||||
@@ -807,21 +635,6 @@ static inline void qsort_safe(void *base, size_t nmemb, size_t size, comparison_
|
||||
qsort(base, nmemb, size, compar);
|
||||
}
|
||||
|
||||
/* Normal memmem() requires haystack to be nonnull, which is annoying for zero-length buffers */
|
||||
static inline void *memmem_safe(const void *haystack, size_t haystacklen, const void *needle, size_t needlelen) {
|
||||
|
||||
if (needlelen <= 0)
|
||||
return (void*) haystack;
|
||||
|
||||
if (haystacklen < needlelen)
|
||||
return NULL;
|
||||
|
||||
assert(haystack);
|
||||
assert(needle);
|
||||
|
||||
return memmem(haystack, haystacklen, needle, needlelen);
|
||||
}
|
||||
|
||||
int proc_cmdline(char **ret);
|
||||
int parse_proc_cmdline(int (*parse_word)(const char *key, const char *value));
|
||||
int get_proc_cmdline_key(const char *parameter, char **value);
|
||||
@@ -879,20 +692,6 @@ int is_symlink(const char *path);
|
||||
int is_dir(const char *path, bool follow);
|
||||
int is_device_node(const char *path);
|
||||
|
||||
typedef enum ExtractFlags {
|
||||
EXTRACT_RELAX = 1,
|
||||
EXTRACT_CUNESCAPE = 2,
|
||||
EXTRACT_CUNESCAPE_RELAX = 4,
|
||||
EXTRACT_QUOTES = 8,
|
||||
EXTRACT_DONT_COALESCE_SEPARATORS = 16,
|
||||
} ExtractFlags;
|
||||
|
||||
int extract_first_word(const char **p, char **ret, const char *separators, ExtractFlags flags);
|
||||
int extract_first_word_and_warn(const char **p, char **ret, const char *separators, ExtractFlags flags, const char *unit, const char *filename, unsigned line, const char *rvalue);
|
||||
int extract_many_words(const char **p, const char *separators, ExtractFlags flags, ...) _sentinel_;
|
||||
|
||||
int free_and_strdup(char **p, const char *s);
|
||||
|
||||
#define INOTIFY_EVENT_MAX (sizeof(struct inotify_event) + NAME_MAX + 1)
|
||||
|
||||
#define FOREACH_INOTIFY_EVENT(e, buffer, sz) \
|
||||
@@ -914,8 +713,6 @@ int fd_getcrtime(int fd, usec_t *usec);
|
||||
int path_getcrtime(const char *p, usec_t *usec);
|
||||
int fd_getcrtime_at(int dirfd, const char *name, usec_t *usec, int flags);
|
||||
|
||||
int same_fd(int a, int b);
|
||||
|
||||
int chattr_fd(int fd, unsigned value, unsigned mask);
|
||||
int chattr_path(const char *p, unsigned value, unsigned mask);
|
||||
|
||||
@@ -931,13 +728,8 @@ void sigkill_wait(pid_t *pid);
|
||||
|
||||
int syslog_parse_priority(const char **p, int *priority, bool with_facility);
|
||||
|
||||
void cmsg_close_all(struct msghdr *mh);
|
||||
|
||||
int rename_noreplace(int olddirfd, const char *oldpath, int newdirfd, const char *newpath);
|
||||
|
||||
char *shell_escape(const char *s, const char *bad);
|
||||
char *shell_maybe_quote(const char *s);
|
||||
|
||||
int parse_mode(const char *s, mode_t *ret);
|
||||
|
||||
int mount_move_root(const char *path);
|
||||
@@ -957,10 +749,3 @@ int version(void);
|
||||
bool fdname_is_valid(const char *s);
|
||||
|
||||
bool oom_score_adjust_is_valid(int oa);
|
||||
|
||||
#define memory_erase(p, l) memset((p), 'x', (l))
|
||||
void string_erase(char *x);
|
||||
|
||||
char *string_free_erase(char *s);
|
||||
DEFINE_TRIVIAL_CLEANUP_FUNC(char *, string_free_erase);
|
||||
#define _cleanup_string_free_erase_ _cleanup_(string_free_erasep)
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
along with systemd; If not, see <http://www.gnu.org/licenses/>.
|
||||
***/
|
||||
|
||||
#include "string-util.h"
|
||||
#include "util.h"
|
||||
#include "verbs.h"
|
||||
|
||||
|
||||
+5
-4
@@ -19,14 +19,15 @@
|
||||
along with systemd; If not, see <http://www.gnu.org/licenses/>.
|
||||
***/
|
||||
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "util.h"
|
||||
#include "process-util.h"
|
||||
#include "virt.h"
|
||||
#include "fileio.h"
|
||||
#include "process-util.h"
|
||||
#include "string-util.h"
|
||||
#include "util.h"
|
||||
#include "virt.h"
|
||||
|
||||
static int detect_vm_cpuid(void) {
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "string-util.h"
|
||||
#include "util.h"
|
||||
#include "xml.h"
|
||||
|
||||
|
||||
@@ -28,8 +28,10 @@
|
||||
#include <string.h>
|
||||
|
||||
#include "conf-files.h"
|
||||
#include "fd-util.h"
|
||||
#include "fileio.h"
|
||||
#include "log.h"
|
||||
#include "string-util.h"
|
||||
#include "strv.h"
|
||||
#include "util.h"
|
||||
|
||||
|
||||
@@ -39,7 +39,9 @@
|
||||
|
||||
#include "blkid-util.h"
|
||||
#include "efivars.h"
|
||||
#include "fd-util.h"
|
||||
#include "rm-rf.h"
|
||||
#include "string-util.h"
|
||||
#include "util.h"
|
||||
|
||||
static int verify_esp(const char *p, uint32_t *part, uint64_t *pstart, uint64_t *psize, sd_id128_t *uuid) {
|
||||
|
||||
+19
-16
@@ -33,30 +33,33 @@
|
||||
|
||||
***/
|
||||
|
||||
#include <sys/resource.h>
|
||||
#include <stdio.h>
|
||||
#include <signal.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <time.h>
|
||||
#include <getopt.h>
|
||||
#include <limits.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <getopt.h>
|
||||
#include <limits.h>
|
||||
#include <signal.h>
|
||||
#include <stdbool.h>
|
||||
#include "systemd/sd-journal.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/resource.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "util.h"
|
||||
#include "fileio.h"
|
||||
#include "macro.h"
|
||||
#include "sd-journal.h"
|
||||
|
||||
#include "bootchart.h"
|
||||
#include "conf-parser.h"
|
||||
#include "strxcpyx.h"
|
||||
#include "fd-util.h"
|
||||
#include "fileio.h"
|
||||
#include "list.h"
|
||||
#include "macro.h"
|
||||
#include "path-util.h"
|
||||
#include "store.h"
|
||||
#include "string-util.h"
|
||||
#include "strxcpyx.h"
|
||||
#include "svg.h"
|
||||
#include "bootchart.h"
|
||||
#include "list.h"
|
||||
#include "util.h"
|
||||
|
||||
static int exiting = 0;
|
||||
|
||||
|
||||
+11
-9
@@ -22,22 +22,24 @@
|
||||
along with systemd; If not, see <http://www.gnu.org/licenses/>.
|
||||
***/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <dirent.h>
|
||||
#include <fcntl.h>
|
||||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "util.h"
|
||||
#include "time-util.h"
|
||||
#include "strxcpyx.h"
|
||||
#include "store.h"
|
||||
#include "bootchart.h"
|
||||
#include "cgroup-util.h"
|
||||
#include "fd-util.h"
|
||||
#include "fileio.h"
|
||||
#include "store.h"
|
||||
#include "string-util.h"
|
||||
#include "strxcpyx.h"
|
||||
#include "time-util.h"
|
||||
#include "util.h"
|
||||
|
||||
/*
|
||||
* Alloc a static 4k buffer for stdio - primarily used to increase
|
||||
|
||||
@@ -39,6 +39,7 @@
|
||||
#include "bootchart.h"
|
||||
#include "list.h"
|
||||
#include "utf8.h"
|
||||
#include "fd-util.h"
|
||||
|
||||
#define time_to_graph(t) ((t) * arg_scale_x)
|
||||
#define ps_to_graph(n) ((n) * arg_scale_y)
|
||||
|
||||
@@ -37,9 +37,11 @@
|
||||
#include "bus-xml-policy.h"
|
||||
#include "capability.h"
|
||||
#include "def.h"
|
||||
#include "fd-util.h"
|
||||
#include "formats-util.h"
|
||||
#include "log.h"
|
||||
#include "proxy.h"
|
||||
#include "string-util.h"
|
||||
#include "strv.h"
|
||||
#include "util.h"
|
||||
|
||||
|
||||
@@ -19,15 +19,17 @@
|
||||
along with systemd; If not, see <http://www.gnu.org/licenses/>.
|
||||
***/
|
||||
|
||||
#include "xml.h"
|
||||
#include "fileio.h"
|
||||
#include "strv.h"
|
||||
#include "set.h"
|
||||
#include "conf-files.h"
|
||||
#include "bus-internal.h"
|
||||
#include "bus-xml-policy.h"
|
||||
#include "sd-login.h"
|
||||
|
||||
#include "bus-internal.h"
|
||||
#include "conf-files.h"
|
||||
#include "fileio.h"
|
||||
#include "formats-util.h"
|
||||
#include "set.h"
|
||||
#include "string-util.h"
|
||||
#include "strv.h"
|
||||
#include "xml.h"
|
||||
#include "bus-xml-policy.h"
|
||||
|
||||
static void policy_item_free(PolicyItem *i) {
|
||||
assert(i);
|
||||
|
||||
@@ -21,21 +21,22 @@
|
||||
along with systemd; If not, see <http://www.gnu.org/licenses/>.
|
||||
***/
|
||||
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "util.h"
|
||||
#include "sd-bus.h"
|
||||
|
||||
#include "bus-internal.h"
|
||||
#include "bus-message.h"
|
||||
#include "bus-util.h"
|
||||
#include "strv.h"
|
||||
#include "set.h"
|
||||
#include "driver.h"
|
||||
#include "proxy.h"
|
||||
#include "synthesize.h"
|
||||
#include "env-util.h"
|
||||
#include "proxy.h"
|
||||
#include "set.h"
|
||||
#include "strv.h"
|
||||
#include "synthesize.h"
|
||||
#include "util.h"
|
||||
|
||||
static int get_creds_by_name(sd_bus *bus, const char *name, uint64_t mask, sd_bus_creds **_creds, sd_bus_error *error) {
|
||||
_cleanup_bus_creds_unref_ sd_bus_creds *c = NULL;
|
||||
|
||||
+13
-11
@@ -22,27 +22,29 @@
|
||||
along with systemd; If not, see <http://www.gnu.org/licenses/>.
|
||||
***/
|
||||
|
||||
#include <sys/socket.h>
|
||||
#include <sys/types.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <poll.h>
|
||||
#include <string.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "log.h"
|
||||
#include "util.h"
|
||||
#include "sd-daemon.h"
|
||||
#include "sd-bus.h"
|
||||
#include "sd-daemon.h"
|
||||
|
||||
#include "bus-control.h"
|
||||
#include "bus-internal.h"
|
||||
#include "bus-message.h"
|
||||
#include "bus-util.h"
|
||||
#include "strv.h"
|
||||
#include "bus-control.h"
|
||||
#include "set.h"
|
||||
#include "bus-xml-policy.h"
|
||||
#include "driver.h"
|
||||
#include "proxy.h"
|
||||
#include "synthesize.h"
|
||||
#include "fd-util.h"
|
||||
#include "formats-util.h"
|
||||
#include "log.h"
|
||||
#include "proxy.h"
|
||||
#include "set.h"
|
||||
#include "strv.h"
|
||||
#include "synthesize.h"
|
||||
#include "util.h"
|
||||
|
||||
static int proxy_create_destination(Proxy *p, const char *destination, const char *local_sec, bool negotiate_fds) {
|
||||
_cleanup_bus_flush_close_unref_ sd_bus *b = NULL;
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
***/
|
||||
|
||||
#include "sd-bus.h"
|
||||
|
||||
#include "bus-xml-policy.h"
|
||||
|
||||
typedef struct Proxy Proxy;
|
||||
|
||||
@@ -23,13 +23,14 @@
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include "util.h"
|
||||
#include "sd-bus.h"
|
||||
|
||||
#include "bus-internal.h"
|
||||
#include "bus-match.h"
|
||||
#include "bus-message.h"
|
||||
#include "bus-util.h"
|
||||
#include "bus-match.h"
|
||||
#include "synthesize.h"
|
||||
#include "util.h"
|
||||
|
||||
int synthetic_driver_send(sd_bus *b, sd_bus_message *m) {
|
||||
int r;
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
***/
|
||||
|
||||
#include "sd-bus.h"
|
||||
|
||||
#include "proxy.h"
|
||||
|
||||
int synthetic_driver_send(sd_bus *b, sd_bus_message *m);
|
||||
|
||||
@@ -19,15 +19,17 @@
|
||||
along with systemd; If not, see <http://www.gnu.org/licenses/>.
|
||||
***/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <stddef.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "log.h"
|
||||
#include "util.h"
|
||||
#include "sd-bus.h"
|
||||
#include "strv.h"
|
||||
|
||||
#include "bus-xml-policy.h"
|
||||
#include "log.h"
|
||||
#include "string-util.h"
|
||||
#include "strv.h"
|
||||
#include "util.h"
|
||||
|
||||
static int test_policy_load(Policy *p, const char *name) {
|
||||
_cleanup_free_ char *path = NULL;
|
||||
|
||||
@@ -22,8 +22,9 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "sd-bus.h"
|
||||
#include "log.h"
|
||||
|
||||
#include "bus-util.h"
|
||||
#include "log.h"
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
_cleanup_bus_flush_close_unref_ sd_bus *bus = NULL;
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
#include "bus-error.h"
|
||||
#include "bus-util.h"
|
||||
#include "cgroup-util.h"
|
||||
#include "fd-util.h"
|
||||
#include "fileio.h"
|
||||
#include "hashmap.h"
|
||||
#include "path-util.h"
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
|
||||
#include "log.h"
|
||||
#include "util.h"
|
||||
#include "fd-util.h"
|
||||
|
||||
static bool initialized = false;
|
||||
static int audit_fd;
|
||||
|
||||
+17
-15
@@ -20,29 +20,31 @@
|
||||
***/
|
||||
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
#include <sys/mount.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/epoll.h>
|
||||
#include <sys/stat.h>
|
||||
#include <linux/auto_fs4.h>
|
||||
#include <limits.h>
|
||||
#include <linux/auto_dev-ioctl.h>
|
||||
#include <linux/auto_fs4.h>
|
||||
#include <sys/epoll.h>
|
||||
#include <sys/mount.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "unit.h"
|
||||
#include "async.h"
|
||||
#include "automount.h"
|
||||
#include "mount.h"
|
||||
#include "unit-name.h"
|
||||
#include "special.h"
|
||||
#include "bus-error.h"
|
||||
#include "bus-util.h"
|
||||
#include "dbus-automount.h"
|
||||
#include "fd-util.h"
|
||||
#include "formats-util.h"
|
||||
#include "label.h"
|
||||
#include "mkdir.h"
|
||||
#include "mount.h"
|
||||
#include "path-util.h"
|
||||
#include "dbus-automount.h"
|
||||
#include "bus-util.h"
|
||||
#include "bus-error.h"
|
||||
#include "formats-util.h"
|
||||
#include "process-util.h"
|
||||
#include "async.h"
|
||||
#include "special.h"
|
||||
#include "string-util.h"
|
||||
#include "unit-name.h"
|
||||
#include "unit.h"
|
||||
|
||||
static const UnitActiveState state_translation_table[_AUTOMOUNT_STATE_MAX] = {
|
||||
[AUTOMOUNT_DEAD] = UNIT_INACTIVE,
|
||||
|
||||
+10
-8
@@ -21,17 +21,19 @@
|
||||
|
||||
#include <sys/mman.h>
|
||||
|
||||
#include "special.h"
|
||||
#include "formats-util.h"
|
||||
#include "signal-util.h"
|
||||
#include "bus-kernel.h"
|
||||
#include "bus-internal.h"
|
||||
#include "bus-util.h"
|
||||
#include "kdbus.h"
|
||||
#include "bus-kernel.h"
|
||||
#include "bus-policy.h"
|
||||
#include "service.h"
|
||||
#include "dbus-busname.h"
|
||||
#include "bus-util.h"
|
||||
#include "busname.h"
|
||||
#include "dbus-busname.h"
|
||||
#include "fd-util.h"
|
||||
#include "formats-util.h"
|
||||
#include "kdbus.h"
|
||||
#include "service.h"
|
||||
#include "signal-util.h"
|
||||
#include "special.h"
|
||||
#include "string-util.h"
|
||||
|
||||
static const UnitActiveState state_translation_table[_BUSNAME_STATE_MAX] = {
|
||||
[BUSNAME_DEAD] = UNIT_INACTIVE,
|
||||
|
||||
@@ -24,6 +24,8 @@
|
||||
typedef struct BusName BusName;
|
||||
typedef struct BusNamePolicy BusNamePolicy;
|
||||
|
||||
#include "unit.h"
|
||||
|
||||
typedef enum BusNameResult {
|
||||
BUSNAME_SUCCESS,
|
||||
BUSNAME_FAILURE_RESOURCES,
|
||||
|
||||
+3
-2
@@ -23,11 +23,12 @@
|
||||
#include <fnmatch.h>
|
||||
|
||||
#include "cgroup-util.h"
|
||||
#include "cgroup.h"
|
||||
#include "fd-util.h"
|
||||
#include "path-util.h"
|
||||
#include "process-util.h"
|
||||
#include "special.h"
|
||||
|
||||
#include "cgroup.h"
|
||||
#include "string-util.h"
|
||||
|
||||
#define CGROUP_CPU_QUOTA_PERIOD_USEC ((usec_t) 100 * USEC_PER_MSEC)
|
||||
|
||||
|
||||
@@ -20,8 +20,9 @@
|
||||
***/
|
||||
|
||||
#include "automount.h"
|
||||
#include "dbus-automount.h"
|
||||
#include "bus-util.h"
|
||||
#include "string-util.h"
|
||||
#include "dbus-automount.h"
|
||||
|
||||
static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_result, automount_result, AutomountResult);
|
||||
|
||||
|
||||
@@ -19,10 +19,11 @@
|
||||
along with systemd; If not, see <http://www.gnu.org/licenses/>.
|
||||
***/
|
||||
|
||||
#include "unit.h"
|
||||
#include "busname.h"
|
||||
#include "dbus-busname.h"
|
||||
#include "bus-util.h"
|
||||
#include "busname.h"
|
||||
#include "string-util.h"
|
||||
#include "unit.h"
|
||||
#include "dbus-busname.h"
|
||||
|
||||
static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_result, busname_result, BusNameResult);
|
||||
|
||||
|
||||
@@ -20,10 +20,11 @@
|
||||
***/
|
||||
|
||||
#include "bus-util.h"
|
||||
#include "path-util.h"
|
||||
#include "cgroup-util.h"
|
||||
#include "cgroup.h"
|
||||
#include "dbus-cgroup.h"
|
||||
#include "fd-util.h"
|
||||
#include "path-util.h"
|
||||
|
||||
static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_cgroup_device_policy, cgroup_device_policy, CGroupDevicePolicy);
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
***/
|
||||
|
||||
#include "sd-bus.h"
|
||||
|
||||
#include "cgroup.h"
|
||||
|
||||
extern const sd_bus_vtable bus_cgroup_vtable[];
|
||||
|
||||
+10
-9
@@ -25,19 +25,20 @@
|
||||
#include <seccomp.h>
|
||||
#endif
|
||||
|
||||
#include "bus-util.h"
|
||||
#include "missing.h"
|
||||
#include "ioprio.h"
|
||||
#include "strv.h"
|
||||
#include "fileio.h"
|
||||
#include "execute.h"
|
||||
#include "capability.h"
|
||||
#include "env-util.h"
|
||||
#include "af-list.h"
|
||||
#include "bus-util.h"
|
||||
#include "capability.h"
|
||||
#include "dbus-execute.h"
|
||||
#include "env-util.h"
|
||||
#include "execute.h"
|
||||
#include "fd-util.h"
|
||||
#include "fileio.h"
|
||||
#include "ioprio.h"
|
||||
#include "missing.h"
|
||||
#include "namespace.h"
|
||||
#include "path-util.h"
|
||||
#include "strv.h"
|
||||
#include "utf8.h"
|
||||
#include "dbus-execute.h"
|
||||
|
||||
#ifdef HAVE_SECCOMP
|
||||
#include "seccomp-util.h"
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
***/
|
||||
|
||||
#include "sd-bus.h"
|
||||
|
||||
#include "execute.h"
|
||||
|
||||
#define BUS_EXEC_STATUS_VTABLE(prefix, offset, flags) \
|
||||
|
||||
+6
-4
@@ -19,12 +19,14 @@
|
||||
along with systemd; If not, see <http://www.gnu.org/licenses/>.
|
||||
***/
|
||||
|
||||
#include "log.h"
|
||||
#include "sd-bus.h"
|
||||
#include "selinux-access.h"
|
||||
#include "job.h"
|
||||
#include "dbus-job.h"
|
||||
|
||||
#include "dbus.h"
|
||||
#include "job.h"
|
||||
#include "log.h"
|
||||
#include "selinux-access.h"
|
||||
#include "string-util.h"
|
||||
#include "dbus-job.h"
|
||||
|
||||
static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_type, job_type, JobType);
|
||||
static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_state, job_state, JobState);
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
***/
|
||||
|
||||
#include "sd-bus.h"
|
||||
|
||||
#include "job.h"
|
||||
|
||||
extern const sd_bus_vtable bus_job_vtable[];
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
***/
|
||||
|
||||
#include "sd-bus.h"
|
||||
|
||||
#include "unit.h"
|
||||
#include "kill.h"
|
||||
|
||||
|
||||
+16
-14
@@ -23,25 +23,27 @@
|
||||
#include <sys/prctl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "log.h"
|
||||
#include "strv.h"
|
||||
#include "build.h"
|
||||
#include "install.h"
|
||||
#include "selinux-access.h"
|
||||
#include "watchdog.h"
|
||||
#include "clock-util.h"
|
||||
#include "path-util.h"
|
||||
#include "virt.h"
|
||||
#include "architecture.h"
|
||||
#include "env-util.h"
|
||||
#include "dbus.h"
|
||||
#include "build.h"
|
||||
#include "bus-common-errors.h"
|
||||
#include "clock-util.h"
|
||||
#include "dbus-execute.h"
|
||||
#include "dbus-job.h"
|
||||
#include "dbus-manager.h"
|
||||
#include "dbus-unit.h"
|
||||
#include "dbus-snapshot.h"
|
||||
#include "dbus-execute.h"
|
||||
#include "bus-common-errors.h"
|
||||
#include "dbus-unit.h"
|
||||
#include "dbus.h"
|
||||
#include "env-util.h"
|
||||
#include "fd-util.h"
|
||||
#include "formats-util.h"
|
||||
#include "install.h"
|
||||
#include "log.h"
|
||||
#include "path-util.h"
|
||||
#include "selinux-access.h"
|
||||
#include "string-util.h"
|
||||
#include "strv.h"
|
||||
#include "virt.h"
|
||||
#include "watchdog.h"
|
||||
|
||||
static int property_get_version(
|
||||
sd_bus *bus,
|
||||
|
||||
@@ -19,13 +19,14 @@
|
||||
along with systemd; If not, see <http://www.gnu.org/licenses/>.
|
||||
***/
|
||||
|
||||
#include "unit.h"
|
||||
#include "mount.h"
|
||||
#include "bus-util.h"
|
||||
#include "dbus-cgroup.h"
|
||||
#include "dbus-execute.h"
|
||||
#include "dbus-kill.h"
|
||||
#include "dbus-cgroup.h"
|
||||
#include "mount.h"
|
||||
#include "string-util.h"
|
||||
#include "unit.h"
|
||||
#include "dbus-mount.h"
|
||||
#include "bus-util.h"
|
||||
|
||||
static int property_get_what(
|
||||
sd_bus *bus,
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
***/
|
||||
|
||||
#include "sd-bus.h"
|
||||
|
||||
#include "unit.h"
|
||||
|
||||
extern const sd_bus_vtable bus_mount_vtable[];
|
||||
|
||||
@@ -19,10 +19,11 @@
|
||||
along with systemd; If not, see <http://www.gnu.org/licenses/>.
|
||||
***/
|
||||
|
||||
#include "unit.h"
|
||||
#include "path.h"
|
||||
#include "dbus-path.h"
|
||||
#include "bus-util.h"
|
||||
#include "path.h"
|
||||
#include "string-util.h"
|
||||
#include "unit.h"
|
||||
#include "dbus-path.h"
|
||||
|
||||
static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_result, path_result, PathResult);
|
||||
|
||||
|
||||
@@ -20,15 +20,17 @@
|
||||
***/
|
||||
|
||||
#include "async.h"
|
||||
#include "strv.h"
|
||||
#include "path-util.h"
|
||||
#include "unit.h"
|
||||
#include "service.h"
|
||||
#include "bus-util.h"
|
||||
#include "dbus-cgroup.h"
|
||||
#include "dbus-execute.h"
|
||||
#include "dbus-kill.h"
|
||||
#include "dbus-cgroup.h"
|
||||
#include "dbus-service.h"
|
||||
#include "bus-util.h"
|
||||
#include "fd-util.h"
|
||||
#include "path-util.h"
|
||||
#include "service.h"
|
||||
#include "string-util.h"
|
||||
#include "strv.h"
|
||||
#include "unit.h"
|
||||
|
||||
static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_type, service_type, ServiceType);
|
||||
static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_result, service_result, ServiceResult);
|
||||
|
||||
@@ -19,12 +19,13 @@
|
||||
along with systemd; If not, see <http://www.gnu.org/licenses/>.
|
||||
***/
|
||||
|
||||
#include "unit.h"
|
||||
#include "socket.h"
|
||||
#include "dbus-execute.h"
|
||||
#include "dbus-cgroup.h"
|
||||
#include "dbus-socket.h"
|
||||
#include "bus-util.h"
|
||||
#include "dbus-cgroup.h"
|
||||
#include "dbus-execute.h"
|
||||
#include "socket.h"
|
||||
#include "string-util.h"
|
||||
#include "unit.h"
|
||||
#include "dbus-socket.h"
|
||||
|
||||
static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_result, socket_result, SocketResult);
|
||||
static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_bind_ipv6_only, socket_address_bind_ipv6_only, SocketAddressBindIPv6Only);
|
||||
|
||||
@@ -20,12 +20,13 @@
|
||||
along with systemd; If not, see <http://www.gnu.org/licenses/>.
|
||||
***/
|
||||
|
||||
#include "unit.h"
|
||||
#include "swap.h"
|
||||
#include "dbus-execute.h"
|
||||
#include "dbus-cgroup.h"
|
||||
#include "dbus-swap.h"
|
||||
#include "bus-util.h"
|
||||
#include "dbus-cgroup.h"
|
||||
#include "dbus-execute.h"
|
||||
#include "string-util.h"
|
||||
#include "swap.h"
|
||||
#include "unit.h"
|
||||
#include "dbus-swap.h"
|
||||
|
||||
static int property_get_priority(
|
||||
sd_bus *bus,
|
||||
|
||||
@@ -21,5 +21,6 @@
|
||||
along with systemd; If not, see <http://www.gnu.org/licenses/>.
|
||||
***/
|
||||
|
||||
#include "sd-bus.h"
|
||||
|
||||
extern const sd_bus_vtable bus_target_vtable[];
|
||||
|
||||
@@ -20,13 +20,15 @@
|
||||
***/
|
||||
|
||||
#include "sd-bus.h"
|
||||
|
||||
#include "bus-common-errors.h"
|
||||
#include "cgroup-util.h"
|
||||
#include "dbus.h"
|
||||
#include "log.h"
|
||||
#include "selinux-access.h"
|
||||
#include "cgroup-util.h"
|
||||
#include "strv.h"
|
||||
#include "bus-common-errors.h"
|
||||
#include "special.h"
|
||||
#include "dbus.h"
|
||||
#include "string-util.h"
|
||||
#include "strv.h"
|
||||
#include "dbus-unit.h"
|
||||
|
||||
static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_load_state, unit_load_state, UnitLoadState);
|
||||
|
||||
+19
-16
@@ -19,29 +19,32 @@
|
||||
along with systemd; If not, see <http://www.gnu.org/licenses/>.
|
||||
***/
|
||||
|
||||
#include <sys/epoll.h>
|
||||
#include <errno.h>
|
||||
#include <sys/epoll.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "sd-bus.h"
|
||||
#include "log.h"
|
||||
#include "strv.h"
|
||||
#include "mkdir.h"
|
||||
#include "missing.h"
|
||||
#include "dbus-unit.h"
|
||||
#include "dbus-job.h"
|
||||
#include "dbus-manager.h"
|
||||
#include "dbus-execute.h"
|
||||
#include "dbus-kill.h"
|
||||
#include "dbus-cgroup.h"
|
||||
#include "special.h"
|
||||
#include "dbus.h"
|
||||
#include "bus-util.h"
|
||||
#include "bus-error.h"
|
||||
|
||||
#include "bus-common-errors.h"
|
||||
#include "strxcpyx.h"
|
||||
#include "bus-error.h"
|
||||
#include "bus-internal.h"
|
||||
#include "bus-util.h"
|
||||
#include "dbus-cgroup.h"
|
||||
#include "dbus-execute.h"
|
||||
#include "dbus-job.h"
|
||||
#include "dbus-kill.h"
|
||||
#include "dbus-manager.h"
|
||||
#include "dbus-unit.h"
|
||||
#include "dbus.h"
|
||||
#include "fd-util.h"
|
||||
#include "log.h"
|
||||
#include "missing.h"
|
||||
#include "mkdir.h"
|
||||
#include "selinux-access.h"
|
||||
#include "special.h"
|
||||
#include "string-util.h"
|
||||
#include "strv.h"
|
||||
#include "strxcpyx.h"
|
||||
|
||||
#define CONNECTIONS_MAX 4096
|
||||
|
||||
|
||||
+7
-5
@@ -21,15 +21,17 @@
|
||||
|
||||
#include <errno.h>
|
||||
#include <sys/epoll.h>
|
||||
#include <libudev.h>
|
||||
|
||||
#include "log.h"
|
||||
#include "unit-name.h"
|
||||
#include "libudev.h"
|
||||
|
||||
#include "dbus-device.h"
|
||||
#include "log.h"
|
||||
#include "path-util.h"
|
||||
#include "udev-util.h"
|
||||
#include "unit.h"
|
||||
#include "string-util.h"
|
||||
#include "swap.h"
|
||||
#include "udev-util.h"
|
||||
#include "unit-name.h"
|
||||
#include "unit.h"
|
||||
#include "device.h"
|
||||
|
||||
static const UnitActiveState state_translation_table[_DEVICE_STATE_MAX] = {
|
||||
|
||||
+9
-10
@@ -53,6 +53,9 @@
|
||||
#include "sd-messages.h"
|
||||
|
||||
#include "af-list.h"
|
||||
#ifdef HAVE_APPARMOR
|
||||
#include "apparmor-util.h"
|
||||
#endif
|
||||
#include "async.h"
|
||||
#include "barrier.h"
|
||||
#include "bus-endpoint.h"
|
||||
@@ -61,7 +64,9 @@
|
||||
#include "def.h"
|
||||
#include "env-util.h"
|
||||
#include "errno-list.h"
|
||||
#include "execute.h"
|
||||
#include "exit-status.h"
|
||||
#include "fd-util.h"
|
||||
#include "fileio.h"
|
||||
#include "formats-util.h"
|
||||
#include "ioprio.h"
|
||||
@@ -73,26 +78,20 @@
|
||||
#include "path-util.h"
|
||||
#include "process-util.h"
|
||||
#include "rm-rf.h"
|
||||
#ifdef HAVE_SECCOMP
|
||||
#include "seccomp-util.h"
|
||||
#endif
|
||||
#include "securebits.h"
|
||||
#include "selinux-util.h"
|
||||
#include "signal-util.h"
|
||||
#include "smack-util.h"
|
||||
#include "string-util.h"
|
||||
#include "strv.h"
|
||||
#include "terminal-util.h"
|
||||
#include "unit.h"
|
||||
#include "util.h"
|
||||
#include "utmp-wtmp.h"
|
||||
|
||||
#ifdef HAVE_APPARMOR
|
||||
#include "apparmor-util.h"
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SECCOMP
|
||||
#include "seccomp-util.h"
|
||||
#endif
|
||||
|
||||
#include "execute.h"
|
||||
|
||||
#define IDLE_TIMEOUT_USEC (5*USEC_PER_SEC)
|
||||
#define IDLE_TIMEOUT2_USEC (1*USEC_PER_SEC)
|
||||
|
||||
|
||||
@@ -19,15 +19,16 @@
|
||||
along with systemd; If not, see <http://www.gnu.org/licenses/>.
|
||||
***/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "macro.h"
|
||||
#include "util.h"
|
||||
#include "log.h"
|
||||
#include "fileio.h"
|
||||
#include "hostname-util.h"
|
||||
#include "log.h"
|
||||
#include "macro.h"
|
||||
#include "string-util.h"
|
||||
#include "util.h"
|
||||
#include "hostname-setup.h"
|
||||
|
||||
int hostname_setup(void) {
|
||||
|
||||
@@ -24,9 +24,10 @@
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "fd-util.h"
|
||||
#include "ima-setup.h"
|
||||
#include "util.h"
|
||||
#include "log.h"
|
||||
#include "util.h"
|
||||
|
||||
#define IMA_SECFS_DIR "/sys/kernel/security/ima"
|
||||
#define IMA_SECFS_POLICY IMA_SECFS_DIR "/policy"
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user