util: split out escaping code into escape.[ch]
This really deserves its own file, given how much code this is now.
This commit is contained in:
parent
dea7b6b043
commit
4f5dd3943b
|
@ -783,6 +783,8 @@ libbasic_la_SOURCES = \
|
|||
src/basic/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 \
|
||||
|
|
|
@ -19,12 +19,13 @@
|
|||
along with systemd; If not, see <http://www.gnu.org/licenses/>.
|
||||
***/
|
||||
|
||||
#include "util.h"
|
||||
#include "mkdir.h"
|
||||
#include "def.h"
|
||||
#include "escape.h"
|
||||
#include "fileio.h"
|
||||
#include "libudev.h"
|
||||
#include "mkdir.h"
|
||||
#include "udev-util.h"
|
||||
#include "def.h"
|
||||
#include "util.h"
|
||||
|
||||
static struct udev_device *find_pci_or_platform_parent(struct udev_device *device) {
|
||||
struct udev_device *parent;
|
||||
|
|
|
@ -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);
|
|
@ -19,6 +19,7 @@
|
|||
along with systemd; If not, see <http://www.gnu.org/licenses/>.
|
||||
***/
|
||||
|
||||
#include "escape.h"
|
||||
#include "utf8.h"
|
||||
#include "util.h"
|
||||
|
||||
|
|
|
@ -21,10 +21,11 @@
|
|||
|
||||
#include <unistd.h>
|
||||
|
||||
#include "util.h"
|
||||
#include "ctype.h"
|
||||
#include "escape.h"
|
||||
#include "strv.h"
|
||||
#include "utf8.h"
|
||||
#include "ctype.h"
|
||||
#include "util.h"
|
||||
#include "fileio.h"
|
||||
|
||||
int write_string_stream(FILE *f, const char *line, bool enforce_newline) {
|
||||
|
|
|
@ -17,21 +17,22 @@
|
|||
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 "fileio.h"
|
||||
#include "util.h"
|
||||
#include "log.h"
|
||||
#include "signal-util.h"
|
||||
#include "util.h"
|
||||
#include "process-util.h"
|
||||
|
||||
int get_process_state(pid_t pid) {
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "escape.h"
|
||||
#include "util.h"
|
||||
#include "strv.h"
|
||||
|
||||
|
|
458
src/basic/util.c
458
src/basic/util.c
|
@ -77,6 +77,7 @@
|
|||
#include "def.h"
|
||||
#include "device-nodes.h"
|
||||
#include "env-util.h"
|
||||
#include "escape.h"
|
||||
#include "exit-status.h"
|
||||
#include "fileio.h"
|
||||
#include "formats-util.h"
|
||||
|
@ -96,8 +97,8 @@
|
|||
#include "strv.h"
|
||||
#include "terminal-util.h"
|
||||
#include "utf8.h"
|
||||
#include "util.h"
|
||||
#include "virt.h"
|
||||
#include "util.h"
|
||||
|
||||
/* Put this test here for a lack of better place */
|
||||
assert_cc(EAGAIN == EWOULDBLOCK);
|
||||
|
@ -214,69 +215,6 @@ char* first_word(const char *s, const char *word) {
|
|||
return (char*) p;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
int close_nointr(int fd) {
|
||||
assert(fd >= 0);
|
||||
|
||||
|
@ -1566,338 +1504,6 @@ int undecchar(char c) {
|
|||
return -EINVAL;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
char *ascii_strlower(char *t) {
|
||||
char *p;
|
||||
|
||||
|
@ -6242,66 +5848,6 @@ int rename_noreplace(int olddirfd, const char *oldpath, int newdirfd, const char
|
|||
return 0;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
int parse_mode(const char *s, mode_t *ret) {
|
||||
char *x;
|
||||
long l;
|
||||
|
|
|
@ -53,12 +53,6 @@
|
|||
#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_;
|
||||
|
@ -260,20 +254,6 @@ 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);
|
||||
int cunescape_one(const char *p, size_t length, char *ret, uint32_t *ret_unicode);
|
||||
|
||||
char *xescape(const char *s, const char *bad);
|
||||
|
||||
char *ascii_strlower(char *path);
|
||||
|
||||
bool dirent_is_file(const struct dirent *de) _pure_;
|
||||
|
@ -924,9 +904,6 @@ 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);
|
||||
|
|
|
@ -23,17 +23,20 @@
|
|||
|
||||
#include "sd-id128.h"
|
||||
#include "sd-messages.h"
|
||||
#include "set.h"
|
||||
#include "unit.h"
|
||||
#include "macro.h"
|
||||
#include "strv.h"
|
||||
#include "log.h"
|
||||
#include "dbus-job.h"
|
||||
#include "special.h"
|
||||
|
||||
#include "async.h"
|
||||
#include "virt.h"
|
||||
#include "dbus-job.h"
|
||||
#include "dbus.h"
|
||||
#include "escape.h"
|
||||
#include "log.h"
|
||||
#include "macro.h"
|
||||
#include "set.h"
|
||||
#include "special.h"
|
||||
#include "strv.h"
|
||||
#include "terminal-util.h"
|
||||
#include "unit.h"
|
||||
#include "virt.h"
|
||||
#include "job.h"
|
||||
|
||||
Job* job_new_raw(Unit *unit) {
|
||||
Job *j;
|
||||
|
|
|
@ -42,6 +42,7 @@
|
|||
#include "cpu-set-util.h"
|
||||
#include "env-util.h"
|
||||
#include "errno-list.h"
|
||||
#include "escape.h"
|
||||
#include "ioprio.h"
|
||||
#include "log.h"
|
||||
#include "missing.h"
|
||||
|
|
|
@ -51,6 +51,7 @@
|
|||
#include "dbus-unit.h"
|
||||
#include "dbus.h"
|
||||
#include "env-util.h"
|
||||
#include "escape.h"
|
||||
#include "exit-status.h"
|
||||
#include "hashmap.h"
|
||||
#include "locale-setup.h"
|
||||
|
|
|
@ -20,26 +20,28 @@
|
|||
***/
|
||||
|
||||
#include <errno.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/epoll.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include "manager.h"
|
||||
#include "unit.h"
|
||||
#include "mount.h"
|
||||
#include "log.h"
|
||||
#include "sd-messages.h"
|
||||
#include "strv.h"
|
||||
#include "mkdir.h"
|
||||
#include "path-util.h"
|
||||
#include "mount-setup.h"
|
||||
#include "unit-name.h"
|
||||
|
||||
#include "dbus-mount.h"
|
||||
#include "special.h"
|
||||
#include "escape.h"
|
||||
#include "exit-status.h"
|
||||
#include "fstab-util.h"
|
||||
#include "formats-util.h"
|
||||
#include "fstab-util.h"
|
||||
#include "log.h"
|
||||
#include "manager.h"
|
||||
#include "mkdir.h"
|
||||
#include "mount-setup.h"
|
||||
#include "mount.h"
|
||||
#include "path-util.h"
|
||||
#include "smack-util.h"
|
||||
#include "special.h"
|
||||
#include "strv.h"
|
||||
#include "unit-name.h"
|
||||
#include "unit.h"
|
||||
|
||||
#define RETRY_UMOUNT_MAX 32
|
||||
|
||||
|
|
|
@ -24,30 +24,31 @@
|
|||
#include <unistd.h>
|
||||
|
||||
#include "async.h"
|
||||
#include "manager.h"
|
||||
#include "unit.h"
|
||||
#include "service.h"
|
||||
#include "load-fragment.h"
|
||||
#include "bus-error.h"
|
||||
#include "bus-kernel.h"
|
||||
#include "bus-util.h"
|
||||
#include "dbus-service.h"
|
||||
#include "def.h"
|
||||
#include "env-util.h"
|
||||
#include "escape.h"
|
||||
#include "exit-status.h"
|
||||
#include "fileio.h"
|
||||
#include "formats-util.h"
|
||||
#include "load-dropin.h"
|
||||
#include "load-fragment.h"
|
||||
#include "log.h"
|
||||
#include "manager.h"
|
||||
#include "path-util.h"
|
||||
#include "process-util.h"
|
||||
#include "signal-util.h"
|
||||
#include "special.h"
|
||||
#include "strv.h"
|
||||
#include "unit-name.h"
|
||||
#include "unit-printf.h"
|
||||
#include "dbus-service.h"
|
||||
#include "special.h"
|
||||
#include "exit-status.h"
|
||||
#include "def.h"
|
||||
#include "path-util.h"
|
||||
#include "util.h"
|
||||
#include "unit.h"
|
||||
#include "utf8.h"
|
||||
#include "env-util.h"
|
||||
#include "fileio.h"
|
||||
#include "bus-error.h"
|
||||
#include "bus-util.h"
|
||||
#include "bus-kernel.h"
|
||||
#include "formats-util.h"
|
||||
#include "process-util.h"
|
||||
#include "signal-util.h"
|
||||
#include "util.h"
|
||||
#include "service.h"
|
||||
|
||||
static const UnitActiveState state_translation_table[_SERVICE_STATE_MAX] = {
|
||||
[SERVICE_DEAD] = UNIT_INACTIVE,
|
||||
|
|
|
@ -20,22 +20,23 @@
|
|||
***/
|
||||
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <libudev.h>
|
||||
#include <sys/epoll.h>
|
||||
#include <sys/stat.h>
|
||||
#include <libudev.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "unit.h"
|
||||
#include "swap.h"
|
||||
#include "unit-name.h"
|
||||
#include "dbus-swap.h"
|
||||
#include "special.h"
|
||||
#include "escape.h"
|
||||
#include "exit-status.h"
|
||||
#include "path-util.h"
|
||||
#include "virt.h"
|
||||
#include "udev-util.h"
|
||||
#include "fstab-util.h"
|
||||
#include "formats-util.h"
|
||||
#include "fstab-util.h"
|
||||
#include "path-util.h"
|
||||
#include "special.h"
|
||||
#include "udev-util.h"
|
||||
#include "unit-name.h"
|
||||
#include "unit.h"
|
||||
#include "virt.h"
|
||||
#include "swap.h"
|
||||
|
||||
static const UnitActiveState state_translation_table[_SWAP_STATE_MAX] = {
|
||||
[SWAP_DEAD] = UNIT_INACTIVE,
|
||||
|
|
|
@ -21,20 +21,21 @@
|
|||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <linux/dm-ioctl.h>
|
||||
#include <linux/loop.h>
|
||||
#include <string.h>
|
||||
#include <sys/mount.h>
|
||||
#include <sys/swap.h>
|
||||
#include <linux/loop.h>
|
||||
#include <linux/dm-ioctl.h>
|
||||
|
||||
#include "escape.h"
|
||||
#include "libudev.h"
|
||||
#include "list.h"
|
||||
#include "mount-setup.h"
|
||||
#include "umount.h"
|
||||
#include "path-util.h"
|
||||
#include "udev-util.h"
|
||||
#include "util.h"
|
||||
#include "virt.h"
|
||||
#include "libudev.h"
|
||||
#include "udev-util.h"
|
||||
#include "umount.h"
|
||||
|
||||
typedef struct MountPoint {
|
||||
char *path;
|
||||
|
|
|
@ -20,36 +20,39 @@
|
|||
***/
|
||||
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "sd-id128.h"
|
||||
#include "sd-messages.h"
|
||||
#include "set.h"
|
||||
#include "macro.h"
|
||||
#include "strv.h"
|
||||
#include "path-util.h"
|
||||
#include "log.h"
|
||||
#include "cgroup-util.h"
|
||||
#include "missing.h"
|
||||
#include "mkdir.h"
|
||||
#include "fileio-label.h"
|
||||
#include "formats-util.h"
|
||||
#include "process-util.h"
|
||||
#include "virt.h"
|
||||
|
||||
#include "bus-common-errors.h"
|
||||
#include "bus-util.h"
|
||||
#include "dropin.h"
|
||||
#include "unit-name.h"
|
||||
#include "special.h"
|
||||
#include "unit.h"
|
||||
#include "load-fragment.h"
|
||||
#include "load-dropin.h"
|
||||
#include "dbus.h"
|
||||
#include "cgroup-util.h"
|
||||
#include "dbus-unit.h"
|
||||
#include "dbus.h"
|
||||
#include "dropin.h"
|
||||
#include "escape.h"
|
||||
#include "execute.h"
|
||||
#include "fileio-label.h"
|
||||
#include "formats-util.h"
|
||||
#include "load-dropin.h"
|
||||
#include "load-fragment.h"
|
||||
#include "log.h"
|
||||
#include "macro.h"
|
||||
#include "missing.h"
|
||||
#include "mkdir.h"
|
||||
#include "path-util.h"
|
||||
#include "process-util.h"
|
||||
#include "set.h"
|
||||
#include "special.h"
|
||||
#include "strv.h"
|
||||
#include "unit-name.h"
|
||||
#include "virt.h"
|
||||
|
||||
#include "unit.h"
|
||||
|
||||
const UnitVTable * const unit_vtable[_UNIT_TYPE_MAX] = {
|
||||
[UNIT_SERVICE] = &service_vtable,
|
||||
|
|
|
@ -23,17 +23,18 @@
|
|||
#include <errno.h>
|
||||
#include <sys/mman.h>
|
||||
#include <mntent.h>
|
||||
|
||||
#include <libcryptsetup.h>
|
||||
|
||||
#include "sd-device.h"
|
||||
|
||||
#include "ask-password-api.h"
|
||||
#include "device-util.h"
|
||||
#include "escape.h"
|
||||
#include "fileio.h"
|
||||
#include "log.h"
|
||||
#include "util.h"
|
||||
#include "path-util.h"
|
||||
#include "strv.h"
|
||||
#include "ask-password-api.h"
|
||||
#include "sd-device.h"
|
||||
#include "device-util.h"
|
||||
#include "util.h"
|
||||
|
||||
static const char *arg_type = NULL; /* CRYPT_LUKS1, CRYPT_TCRYPT or CRYPT_PLAIN */
|
||||
static char *arg_cipher = NULL;
|
||||
|
|
|
@ -21,17 +21,18 @@
|
|||
|
||||
#include <sys/prctl.h>
|
||||
|
||||
#include "util.h"
|
||||
#include "strv.h"
|
||||
#include "copy.h"
|
||||
#include "rm-rf.h"
|
||||
#include "btrfs-util.h"
|
||||
#include "capability.h"
|
||||
#include "pull-job.h"
|
||||
#include "pull-common.h"
|
||||
#include "copy.h"
|
||||
#include "escape.h"
|
||||
#include "process-util.h"
|
||||
#include "pull-job.h"
|
||||
#include "rm-rf.h"
|
||||
#include "signal-util.h"
|
||||
#include "siphash24.h"
|
||||
#include "strv.h"
|
||||
#include "util.h"
|
||||
#include "pull-common.h"
|
||||
|
||||
#define FILENAME_ESCAPE "/.#\"\'"
|
||||
#define HASH_URL_THRESHOLD_LENGTH (_POSIX_PATH_MAX - 16)
|
||||
|
|
|
@ -36,14 +36,15 @@
|
|||
#include "sd-daemon.h"
|
||||
|
||||
#include "conf-parser.h"
|
||||
#include "escape.h"
|
||||
#include "fileio.h"
|
||||
#include "journal-file.h"
|
||||
#include "journal-remote-write.h"
|
||||
#include "journald-native.h"
|
||||
#include "macro.h"
|
||||
#include "signal-util.h"
|
||||
#include "socket-util.h"
|
||||
#include "strv.h"
|
||||
#include "journal-remote-write.h"
|
||||
#include "journal-remote.h"
|
||||
|
||||
#define REMOTE_JOURNAL_PATH "/var/log/journal/remote"
|
||||
|
|
|
@ -20,10 +20,10 @@
|
|||
***/
|
||||
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/prctl.h>
|
||||
#include <sys/xattr.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#ifdef HAVE_ELFUTILS
|
||||
# include <dwarf.h>
|
||||
|
@ -32,23 +32,25 @@
|
|||
|
||||
#include "sd-journal.h"
|
||||
#include "sd-login.h"
|
||||
#include "log.h"
|
||||
#include "util.h"
|
||||
#include "fileio.h"
|
||||
#include "strv.h"
|
||||
#include "macro.h"
|
||||
#include "mkdir.h"
|
||||
#include "special.h"
|
||||
#include "cgroup-util.h"
|
||||
#include "conf-parser.h"
|
||||
#include "copy.h"
|
||||
#include "stacktrace.h"
|
||||
#include "compress.h"
|
||||
|
||||
#include "acl-util.h"
|
||||
#include "capability.h"
|
||||
#include "journald-native.h"
|
||||
#include "cgroup-util.h"
|
||||
#include "compress.h"
|
||||
#include "conf-parser.h"
|
||||
#include "copy.h"
|
||||
#include "coredump-vacuum.h"
|
||||
#include "escape.h"
|
||||
#include "fileio.h"
|
||||
#include "journald-native.h"
|
||||
#include "log.h"
|
||||
#include "macro.h"
|
||||
#include "mkdir.h"
|
||||
#include "process-util.h"
|
||||
#include "special.h"
|
||||
#include "stacktrace.h"
|
||||
#include "strv.h"
|
||||
#include "util.h"
|
||||
|
||||
/* The maximum size up to which we process coredumps */
|
||||
#define PROCESS_SIZE_MAX ((uint64_t) (2LLU*1024LLU*1024LLU*1024LLU))
|
||||
|
|
|
@ -19,20 +19,21 @@
|
|||
along with systemd; If not, see <http://www.gnu.org/licenses/>.
|
||||
***/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <sys/epoll.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/epoll.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/socket.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "systemd/sd-messages.h"
|
||||
#include <libudev.h>
|
||||
#include "libudev.h"
|
||||
#include "sd-messages.h"
|
||||
|
||||
#include "journald-server.h"
|
||||
#include "journald-kmsg.h"
|
||||
#include "journald-syslog.h"
|
||||
#include "escape.h"
|
||||
#include "formats-util.h"
|
||||
#include "journald-server.h"
|
||||
#include "journald-syslog.h"
|
||||
#include "process-util.h"
|
||||
#include "journald-kmsg.h"
|
||||
|
||||
void server_forward_kmsg(
|
||||
Server *s,
|
||||
|
|
|
@ -26,18 +26,20 @@
|
|||
#include <selinux/selinux.h>
|
||||
#endif
|
||||
|
||||
#include "sd-event.h"
|
||||
#include "sd-daemon.h"
|
||||
#include "socket-util.h"
|
||||
#include "selinux-util.h"
|
||||
#include "mkdir.h"
|
||||
#include "sd-event.h"
|
||||
|
||||
#include "escape.h"
|
||||
#include "fileio.h"
|
||||
#include "journald-server.h"
|
||||
#include "journald-stream.h"
|
||||
#include "journald-syslog.h"
|
||||
#include "journald-kmsg.h"
|
||||
#include "journald-console.h"
|
||||
#include "journald-kmsg.h"
|
||||
#include "journald-server.h"
|
||||
#include "journald-syslog.h"
|
||||
#include "journald-wall.h"
|
||||
#include "mkdir.h"
|
||||
#include "selinux-util.h"
|
||||
#include "socket-util.h"
|
||||
#include "journald-stream.h"
|
||||
|
||||
#define STDOUT_STREAMS_MAX 4096
|
||||
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
#include "bus-type.h"
|
||||
#include "bus-util.h"
|
||||
#include "busctl-introspect.h"
|
||||
#include "escape.h"
|
||||
#include "log.h"
|
||||
#include "pager.h"
|
||||
#include "path-util.h"
|
||||
|
|
|
@ -19,20 +19,21 @@
|
|||
along with systemd; If not, see <http://www.gnu.org/licenses/>.
|
||||
***/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <sys/inotify.h>
|
||||
#include <poll.h>
|
||||
#include <string.h>
|
||||
#include <sys/inotify.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "util.h"
|
||||
#include "cgroup-util.h"
|
||||
#include "macro.h"
|
||||
#include "strv.h"
|
||||
#include "escape.h"
|
||||
#include "fileio.h"
|
||||
#include "login-util.h"
|
||||
#include "formats-util.h"
|
||||
#include "hostname-util.h"
|
||||
#include "login-util.h"
|
||||
#include "macro.h"
|
||||
#include "strv.h"
|
||||
#include "util.h"
|
||||
#include "sd-login.h"
|
||||
|
||||
/* Error codes:
|
||||
|
|
|
@ -22,12 +22,13 @@
|
|||
#include <errno.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "util.h"
|
||||
#include "formats-util.h"
|
||||
#include "acl-util.h"
|
||||
#include "escape.h"
|
||||
#include "formats-util.h"
|
||||
#include "set.h"
|
||||
#include "logind-acl.h"
|
||||
#include "udev-util.h"
|
||||
#include "util.h"
|
||||
#include "logind-acl.h"
|
||||
|
||||
static int flush_acl(acl_t acl) {
|
||||
acl_entry_t i;
|
||||
|
|
|
@ -20,29 +20,31 @@
|
|||
***/
|
||||
|
||||
#include <errno.h>
|
||||
#include <pwd.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <pwd.h>
|
||||
|
||||
#include "sd-messages.h"
|
||||
#include "strv.h"
|
||||
|
||||
#include "audit.h"
|
||||
#include "bus-common-errors.h"
|
||||
#include "bus-error.h"
|
||||
#include "bus-util.h"
|
||||
#include "efivars.h"
|
||||
#include "escape.h"
|
||||
#include "fileio-label.h"
|
||||
#include "formats-util.h"
|
||||
#include "logind.h"
|
||||
#include "mkdir.h"
|
||||
#include "path-util.h"
|
||||
#include "special.h"
|
||||
#include "sleep-config.h"
|
||||
#include "fileio-label.h"
|
||||
#include "unit-name.h"
|
||||
#include "audit.h"
|
||||
#include "bus-util.h"
|
||||
#include "bus-error.h"
|
||||
#include "bus-common-errors.h"
|
||||
#include "udev-util.h"
|
||||
#include "selinux-util.h"
|
||||
#include "efivars.h"
|
||||
#include "logind.h"
|
||||
#include "formats-util.h"
|
||||
#include "process-util.h"
|
||||
#include "selinux-util.h"
|
||||
#include "sleep-config.h"
|
||||
#include "special.h"
|
||||
#include "strv.h"
|
||||
#include "terminal-util.h"
|
||||
#include "udev-util.h"
|
||||
#include "unit-name.h"
|
||||
#include "utmp-wtmp.h"
|
||||
|
||||
int manager_get_session_from_creds(Manager *m, sd_bus_message *message, const char *name, sd_bus_error *error, Session **ret) {
|
||||
|
|
|
@ -24,11 +24,12 @@
|
|||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "util.h"
|
||||
#include "mkdir.h"
|
||||
#include "logind-inhibit.h"
|
||||
#include "escape.h"
|
||||
#include "fileio.h"
|
||||
#include "formats-util.h"
|
||||
#include "mkdir.h"
|
||||
#include "util.h"
|
||||
#include "logind-inhibit.h"
|
||||
|
||||
Inhibitor* inhibitor_new(Manager *m, const char* id) {
|
||||
Inhibitor *i;
|
||||
|
|
|
@ -21,24 +21,26 @@
|
|||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <linux/vt.h>
|
||||
#include <linux/kd.h>
|
||||
#include <linux/vt.h>
|
||||
#include <signal.h>
|
||||
#include <string.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "sd-messages.h"
|
||||
#include "util.h"
|
||||
|
||||
#include "audit.h"
|
||||
#include "bus-error.h"
|
||||
#include "bus-util.h"
|
||||
#include "escape.h"
|
||||
#include "fileio.h"
|
||||
#include "formats-util.h"
|
||||
#include "mkdir.h"
|
||||
#include "path-util.h"
|
||||
#include "fileio.h"
|
||||
#include "audit.h"
|
||||
#include "bus-util.h"
|
||||
#include "bus-error.h"
|
||||
#include "logind-session.h"
|
||||
#include "formats-util.h"
|
||||
#include "terminal-util.h"
|
||||
#include "util.h"
|
||||
#include "logind-session.h"
|
||||
|
||||
#define RELEASE_USEC (20*USEC_PER_SEC)
|
||||
|
||||
|
|
|
@ -19,26 +19,27 @@
|
|||
along with systemd; If not, see <http://www.gnu.org/licenses/>.
|
||||
***/
|
||||
|
||||
#include <sys/mount.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <sys/mount.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "util.h"
|
||||
#include "mkdir.h"
|
||||
#include "rm-rf.h"
|
||||
#include "hashmap.h"
|
||||
#include "bus-error.h"
|
||||
#include "bus-util.h"
|
||||
#include "clean-ipc.h"
|
||||
#include "conf-parser.h"
|
||||
#include "escape.h"
|
||||
#include "fileio.h"
|
||||
#include "formats-util.h"
|
||||
#include "hashmap.h"
|
||||
#include "label.h"
|
||||
#include "mkdir.h"
|
||||
#include "path-util.h"
|
||||
#include "rm-rf.h"
|
||||
#include "smack-util.h"
|
||||
#include "special.h"
|
||||
#include "unit-name.h"
|
||||
#include "bus-util.h"
|
||||
#include "bus-error.h"
|
||||
#include "conf-parser.h"
|
||||
#include "clean-ipc.h"
|
||||
#include "smack-util.h"
|
||||
#include "formats-util.h"
|
||||
#include "label.h"
|
||||
#include "util.h"
|
||||
#include "logind-user.h"
|
||||
|
||||
User* user_new(Manager *m, uid_t uid, gid_t gid, const char *name) {
|
||||
|
|
|
@ -27,15 +27,16 @@
|
|||
|
||||
#include "bus-error.h"
|
||||
#include "bus-util.h"
|
||||
#include "escape.h"
|
||||
#include "fileio.h"
|
||||
#include "formats-util.h"
|
||||
#include "hashmap.h"
|
||||
#include "machine-dbus.h"
|
||||
#include "mkdir.h"
|
||||
#include "special.h"
|
||||
#include "terminal-util.h"
|
||||
#include "unit-name.h"
|
||||
#include "util.h"
|
||||
#include "machine-dbus.h"
|
||||
#include "machine.h"
|
||||
|
||||
Machine* machine_new(Manager *manager, MachineClass class, const char *name) {
|
||||
|
|
|
@ -19,17 +19,18 @@
|
|||
along with systemd; If not, see <http://www.gnu.org/licenses/>.
|
||||
***/
|
||||
|
||||
#include <sys/mount.h>
|
||||
#include <linux/magic.h>
|
||||
#include <sys/mount.h>
|
||||
|
||||
#include "util.h"
|
||||
#include "rm-rf.h"
|
||||
#include "strv.h"
|
||||
#include "path-util.h"
|
||||
#include "mkdir.h"
|
||||
#include "label.h"
|
||||
#include "set.h"
|
||||
#include "cgroup-util.h"
|
||||
#include "escape.h"
|
||||
#include "label.h"
|
||||
#include "mkdir.h"
|
||||
#include "path-util.h"
|
||||
#include "rm-rf.h"
|
||||
#include "set.h"
|
||||
#include "strv.h"
|
||||
#include "util.h"
|
||||
|
||||
#include "nspawn-mount.h"
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#include "libudev.h"
|
||||
#include "sd-daemon.h"
|
||||
|
||||
#include "escape.h"
|
||||
#include "fileio.h"
|
||||
#include "mkdir.h"
|
||||
#include "udev-util.h"
|
||||
|
|
|
@ -21,9 +21,9 @@
|
|||
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include "sd-bus.h"
|
||||
#include "sd-daemon.h"
|
||||
#include "sd-event.h"
|
||||
#include "sd-bus.h"
|
||||
|
||||
#include "bus-error.h"
|
||||
#include "bus-internal.h"
|
||||
|
@ -32,6 +32,7 @@
|
|||
#include "cgroup-util.h"
|
||||
#include "def.h"
|
||||
#include "env-util.h"
|
||||
#include "escape.h"
|
||||
#include "macro.h"
|
||||
#include "missing.h"
|
||||
#include "path-util.h"
|
||||
|
|
|
@ -19,12 +19,13 @@
|
|||
along with systemd; If not, see <http://www.gnu.org/licenses/>.
|
||||
***/
|
||||
|
||||
#include "dropin.h"
|
||||
#include "util.h"
|
||||
#include "strv.h"
|
||||
#include "mkdir.h"
|
||||
#include "fileio-label.h"
|
||||
#include "conf-files.h"
|
||||
#include "escape.h"
|
||||
#include "fileio-label.h"
|
||||
#include "mkdir.h"
|
||||
#include "strv.h"
|
||||
#include "util.h"
|
||||
#include "dropin.h"
|
||||
|
||||
int drop_in_file(const char *dir, const char *unit, unsigned level,
|
||||
const char *name, char **_p, char **_q) {
|
||||
|
|
|
@ -21,15 +21,16 @@
|
|||
|
||||
#include <unistd.h>
|
||||
|
||||
#include "util.h"
|
||||
#include "special.h"
|
||||
#include "mkdir.h"
|
||||
#include "unit-name.h"
|
||||
#include "generator.h"
|
||||
#include "path-util.h"
|
||||
#include "fstab-util.h"
|
||||
#include "fileio.h"
|
||||
#include "dropin.h"
|
||||
#include "escape.h"
|
||||
#include "fileio.h"
|
||||
#include "fstab-util.h"
|
||||
#include "mkdir.h"
|
||||
#include "path-util.h"
|
||||
#include "special.h"
|
||||
#include "unit-name.h"
|
||||
#include "util.h"
|
||||
#include "generator.h"
|
||||
|
||||
static int write_fsck_sysroot_service(const char *dir, const char *what) {
|
||||
_cleanup_free_ char *device = NULL, *escaped = NULL;
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
#include "conf-parser.h"
|
||||
#include "cpu-set-util.h"
|
||||
#include "def.h"
|
||||
#include "escape.h"
|
||||
#include "fileio.h"
|
||||
#include "mkdir.h"
|
||||
#include "process-util.h"
|
||||
|
|
|
@ -43,6 +43,7 @@
|
|||
#include "capability.h"
|
||||
#include "conf-files.h"
|
||||
#include "copy.h"
|
||||
#include "escape.h"
|
||||
#include "formats-util.h"
|
||||
#include "label.h"
|
||||
#include "log.h"
|
||||
|
|
|
@ -15,27 +15,28 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
#include <limits.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <fcntl.h>
|
||||
#include <ctype.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <dirent.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <fnmatch.h>
|
||||
#include <limits.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "udev.h"
|
||||
#include "path-util.h"
|
||||
#include "conf-files.h"
|
||||
#include "escape.h"
|
||||
#include "path-util.h"
|
||||
#include "strbuf.h"
|
||||
#include "strv.h"
|
||||
#include "util.h"
|
||||
#include "sysctl-util.h"
|
||||
#include "util.h"
|
||||
#include "udev.h"
|
||||
|
||||
#define PREALLOC_TOKEN 2048
|
||||
|
||||
|
@ -51,7 +52,8 @@ static const char* const rules_dirs[] = {
|
|||
"/etc/udev/rules.d",
|
||||
"/run/udev/rules.d",
|
||||
UDEVLIBEXECDIR "/rules.d",
|
||||
NULL};
|
||||
NULL
|
||||
};
|
||||
|
||||
struct udev_rules {
|
||||
struct udev *udev;
|
||||
|
|
Loading…
Reference in New Issue