summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDaniel Mack <daniel@zonque.org>2016-10-18 17:57:10 +0200
committerSven Eden <yamakuzure@gmx.net>2017-11-20 17:28:50 +0100
commitb605cf820c4831451fd009825a914d6f98045219 (patch)
tree6320971d755d18f28b3387d9de29ea28052d57a8 /src
parent294d3039be600ee7fbe43222fcf7084c99e63b94 (diff)
Add abstraction model for BPF programs
This object takes a number of bpf_insn members and wraps them together with the in-kernel reference id. Will be needed by the firewall code.
Diffstat (limited to 'src')
-rw-r--r--src/basic/cgroup-util.c5
-rw-r--r--src/basic/def.h2
-rw-r--r--src/basic/fileio.c95
-rw-r--r--src/basic/fileio.h2
-rw-r--r--src/basic/fs-util.c2
-rw-r--r--src/basic/meson.build20
-rw-r--r--src/basic/missing_syscall.h32
-rw-r--r--src/basic/terminal-util.c1
-rw-r--r--src/basic/time-util.c28
-rw-r--r--src/libelogind/sd-bus/sd-bus.c1
-rw-r--r--src/libelogind/sd-daemon/sd-daemon.c1
-rw-r--r--src/libelogind/sd-event/test-event.c1
-rw-r--r--src/libelogind/sd-login/test-login.c1
-rw-r--r--src/login/logind-session.c1
-rw-r--r--src/login/logind.c5
-rw-r--r--src/shared/conf-parser.c49
-rw-r--r--src/shared/udev-util.c1
-rw-r--r--src/sleep/sleep.c2
-rw-r--r--src/test/meson.build4
-rw-r--r--src/test/test-cgroup.c1
-rw-r--r--src/test/test-conf-parser.c136
-rw-r--r--src/test/test-log.c1
-rw-r--r--src/test/test-signal-util.c1
23 files changed, 101 insertions, 291 deletions
diff --git a/src/basic/cgroup-util.c b/src/basic/cgroup-util.c
index 49441156f..83fd7e5f8 100644
--- a/src/basic/cgroup-util.c
+++ b/src/basic/cgroup-util.c
@@ -1007,7 +1007,7 @@ int cg_get_xattr(const char *controller, const char *path, const char *name, voi
int cg_pid_get_path(const char *controller, pid_t pid, char **path) {
_cleanup_fclose_ FILE *f = NULL;
char line[LINE_MAX];
- const char *fs, *controller_str = NULL;
+ const char *fs, *controller_str;
size_t cs = 0;
int unified;
@@ -2385,6 +2385,7 @@ int cg_mask_supported(CGroupMask *ret) {
#if 0 /// UNNEEDED by elogind
int cg_kernel_controllers(Set *controllers) {
_cleanup_fclose_ FILE *f = NULL;
+ char buf[LINE_MAX];
int r;
assert(controllers);
@@ -2402,7 +2403,7 @@ int cg_kernel_controllers(Set *controllers) {
}
/* Ignore the header line */
- (void) read_line(f, (size_t) -1, NULL);
+ (void) fgets(buf, sizeof(buf), f);
for (;;) {
char *controller;
diff --git a/src/basic/def.h b/src/basic/def.h
index 1571f921b..d30b4a106 100644
--- a/src/basic/def.h
+++ b/src/basic/def.h
@@ -96,5 +96,3 @@
"/usr/local/lib/" n "\0" \
"/usr/lib/" n "\0" \
_CONF_PATHS_SPLIT_USR(n)
-
-#define LONG_LINE_MAX (1U*1024U*1024U)
diff --git a/src/basic/fileio.c b/src/basic/fileio.c
index 196d6204d..412c80f1e 100644
--- a/src/basic/fileio.c
+++ b/src/basic/fileio.c
@@ -30,7 +30,7 @@
#include "alloc-util.h"
#include "ctype.h"
-#include "def.h"
+#include "env-util.h"
#include "escape.h"
#include "fd-util.h"
#include "fileio.h"
@@ -177,7 +177,7 @@ fail:
int read_one_line_file(const char *fn, char **line) {
_cleanup_fclose_ FILE *f = NULL;
- int r;
+ char t[LINE_MAX], *c;
assert(fn);
assert(line);
@@ -186,8 +186,21 @@ int read_one_line_file(const char *fn, char **line) {
if (!f)
return -errno;
- r = read_line(f, LONG_LINE_MAX, line);
- return r < 0 ? r : 0;
+ if (!fgets(t, sizeof(t), f)) {
+
+ if (ferror(f))
+ return errno > 0 ? -errno : -EIO;
+
+ t[0] = 0;
+ }
+
+ c = strdup(t);
+ if (!c)
+ return -ENOMEM;
+ truncate_nl(c);
+
+ *line = c;
+ return 0;
}
int verify_file(const char *fn, const char *blob, bool accept_extra_nl) {
@@ -1525,77 +1538,3 @@ int mkdtemp_malloc(const char *template, char **ret) {
return 0;
}
#endif // 0
-
-static inline void funlockfilep(FILE **f) {
- funlockfile(*f);
-}
-
-int read_line(FILE *f, size_t limit, char **ret) {
- _cleanup_free_ char *buffer = NULL;
- size_t n = 0, allocated = 0, count = 0;
-
- assert(f);
-
- /* Something like a bounded version of getline().
- *
- * Considers EOF, \n and \0 end of line delimiters, and does not include these delimiters in the string
- * returned.
- *
- * Returns the number of bytes read from the files (i.e. including delimiters — this hence usually differs from
- * the number of characters in the returned string). When EOF is hit, 0 is returned.
- *
- * The input parameter limit is the maximum numbers of characters in the returned string, i.e. excluding
- * delimiters. If the limit is hit we fail and return -ENOBUFS.
- *
- * If a line shall be skipped ret may be initialized as NULL. */
-
- if (ret) {
- if (!GREEDY_REALLOC(buffer, allocated, 1))
- return -ENOMEM;
- }
-
- {
- _cleanup_(funlockfilep) FILE *flocked = f;
- flockfile(f);
-
- for (;;) {
- int c;
-
- if (n >= limit)
- return -ENOBUFS;
-
- errno = 0;
- c = fgetc_unlocked(f);
- if (c == EOF) {
- /* if we read an error, and have no data to return, then propagate the error */
- if (ferror_unlocked(f) && n == 0)
- return errno > 0 ? -errno : -EIO;
-
- break;
- }
-
- count++;
-
- if (IN_SET(c, '\n', 0)) /* Reached a delimiter */
- break;
-
- if (ret) {
- if (!GREEDY_REALLOC(buffer, allocated, n + 2))
- return -ENOMEM;
-
- buffer[n] = (char) c;
- }
-
- n++;
- }
- }
-
- if (ret) {
- buffer[n] = 0;
-
- *ret = buffer;
- buffer = NULL;
- }
-
- return (int) count;
-}
diff --git a/src/basic/fileio.h b/src/basic/fileio.h
index 2ff3b434d..f76c3243e 100644
--- a/src/basic/fileio.h
+++ b/src/basic/fileio.h
@@ -113,5 +113,3 @@ int read_nul_string(FILE *f, char **ret);
int mkdtemp_malloc(const char *template, char **ret);
#endif // 0
-
-int read_line(FILE *f, size_t limit, char **ret);
diff --git a/src/basic/fs-util.c b/src/basic/fs-util.c
index c8b5ad432..3701528ed 100644
--- a/src/basic/fs-util.c
+++ b/src/basic/fs-util.c
@@ -38,8 +38,8 @@
#include "mkdir.h"
#include "parse-util.h"
#include "path-util.h"
-#include "process-util.h"
#include "stat-util.h"
+#include "stdio-util.h"
#include "string-util.h"
#include "strv.h"
//#include "time-util.h"
diff --git a/src/basic/meson.build b/src/basic/meson.build
index 10acb9aef..51e5b1b16 100644
--- a/src/basic/meson.build
+++ b/src/basic/meson.build
@@ -1,5 +1,7 @@
#if 0 /// elogind has a shorter list
# basic_sources_plain = files('''
+# MurmurHash2.c
+# MurmurHash2.h
# af-list.c
# af-list.h
# alloc-util.c
@@ -17,6 +19,8 @@
# bitmap.c
# bitmap.h
# blkid-util.h
+# bpf-program.c
+# bpf-program.h
# btrfs-ctree.h
# btrfs-util.c
# btrfs-util.h
@@ -25,10 +29,10 @@
# bus-label.h
# calendarspec.c
# calendarspec.h
-# capability-util.c
-# capability-util.h
# cap-list.c
# cap-list.h
+# capability-util.c
+# capability-util.h
# cgroup-util.c
# cgroup-util.h
# chattr-util.c
@@ -62,10 +66,10 @@
# extract-word.h
# fd-util.c
# fd-util.h
-# fileio.c
-# fileio.h
# fileio-label.c
# fileio-label.h
+# fileio.c
+# fileio.h
# format-util.h
# fs-util.c
# fs-util.h
@@ -83,9 +87,9 @@
# hostname-util.h
# in-addr-util.c
# in-addr-util.h
-# ioprio.h
# io-util.c
# io-util.h
+# ioprio.h
# journal-importer.c
# journal-importer.h
# khash.c
@@ -107,13 +111,11 @@
# mempool.c
# mempool.h
# missing_syscall.h
+# mkdir-label.c
# mkdir.c
# mkdir.h
-# mkdir-label.c
# mount-util.c
# mount-util.h
-# MurmurHash2.c
-# MurmurHash2.h
# nss-util.h
# ordered-set.c
# ordered-set.h
@@ -139,9 +141,9 @@
# rlimit-util.h
# rm-rf.c
# rm-rf.h
-# securebits.h
# securebits-util.c
# securebits-util.h
+# securebits.h
# selinux-util.c
# selinux-util.h
# set.h
diff --git a/src/basic/missing_syscall.h b/src/basic/missing_syscall.h
index 664724c00..2f596cf54 100644
--- a/src/basic/missing_syscall.h
+++ b/src/basic/missing_syscall.h
@@ -23,6 +23,8 @@
/* Missing glibc definitions to access certain kernel APIs */
#if 0 /// UNNEEDED by elogind
+#include <sys/types.h>
+
#if !HAVE_DECL_PIVOT_ROOT
static inline int pivot_root(const char *new_root, const char *put_old) {
return syscall(SYS_pivot_root, new_root, put_old);
@@ -318,3 +320,33 @@ static inline ssize_t copy_file_range(int fd_in, loff_t *off_in,
# endif
}
#endif
+
+#if !HAVE_DECL_BPF
+# ifndef __NR_bpf
+# if defined __i386__
+# define __NR_bpf 357
+# elif defined __x86_64__
+# define __NR_bpf 321
+# elif defined __aarch64__
+# define __NR_bpf 280
+# elif defined __sparc__
+# define __NR_bpf 349
+# elif defined __s390__
+# define __NR_bpf 351
+# else
+# warning "__NR_bpf not defined for your architecture"
+# endif
+# endif
+
+union bpf_attr;
+
+static inline int bpf(int cmd, union bpf_attr *attr, size_t size) {
+#ifdef __NR_bpf
+ return (int) syscall(__NR_bpf, cmd, attr, size);
+#else
+ errno = ENOSYS;
+ return -1;
+#endif
+}
+
+#endif
diff --git a/src/basic/terminal-util.c b/src/basic/terminal-util.c
index d580c6dac..6de772117 100644
--- a/src/basic/terminal-util.c
+++ b/src/basic/terminal-util.c
@@ -47,7 +47,6 @@
#include "log.h"
#include "macro.h"
#include "parse-util.h"
-#include "path-util.h"
#include "process-util.h"
#include "socket-util.h"
#include "stat-util.h"
diff --git a/src/basic/time-util.c b/src/basic/time-util.c
index fc94c945e..f0b9cc183 100644
--- a/src/basic/time-util.c
+++ b/src/basic/time-util.c
@@ -861,13 +861,13 @@ parse_usec:
}
from_tm:
- if (weekday >= 0 && tm.tm_wday != weekday)
- return -EINVAL;
-
x = mktime_or_timegm(&tm, utc);
if (x < 0)
return -EINVAL;
+ if (weekday >= 0 && tm.tm_wday != weekday)
+ return -EINVAL;
+
ret = (usec_t) x * USEC_PER_SEC + x_usec;
if (ret > USEC_TIMESTAMP_FORMATTABLE_MAX)
return -EINVAL;
@@ -895,18 +895,20 @@ typedef struct ParseTimestampResult {
} ParseTimestampResult;
int parse_timestamp(const char *t, usec_t *usec) {
- char *last_space, *tz = NULL;
+ char *last_space, *timezone = NULL;
ParseTimestampResult *shared, tmp;
int r;
pid_t pid;
last_space = strrchr(t, ' ');
if (last_space != NULL && timezone_is_valid(last_space + 1))
- tz = last_space + 1;
+ timezone = last_space + 1;
- if (tz == NULL || endswith_no_case(t, " UTC"))
+ if (timezone == NULL || endswith_no_case(t, " UTC"))
return parse_timestamp_impl(t, usec, false);
+ t = strndupa(t, last_space - t);
+
shared = mmap(NULL, sizeof *shared, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_ANONYMOUS, -1, 0);
if (shared == MAP_FAILED)
return negative_errno();
@@ -920,24 +922,14 @@ int parse_timestamp(const char *t, usec_t *usec) {
}
if (pid == 0) {
- bool with_tz = true;
-
- if (setenv("TZ", tz, 1) != 0) {
+ if (setenv("TZ", timezone, 1) != 0) {
shared->return_value = negative_errno();
_exit(EXIT_FAILURE);
}
tzset();
- /* If there is a timezone that matches the tzname fields, leave the parsing to the implementation.
- * Otherwise just cut it off */
- with_tz = !STR_IN_SET(tz, tzname[0], tzname[1]);
-
- /*cut off the timezone if we dont need it*/
- if (with_tz)
- t = strndupa(t, last_space - t);
-
- shared->return_value = parse_timestamp_impl(t, &shared->usec, with_tz);
+ shared->return_value = parse_timestamp_impl(t, &shared->usec, true);
_exit(EXIT_SUCCESS);
}
diff --git a/src/libelogind/sd-bus/sd-bus.c b/src/libelogind/sd-bus/sd-bus.c
index d9800f1cd..7bc0c056b 100644
--- a/src/libelogind/sd-bus/sd-bus.c
+++ b/src/libelogind/sd-bus/sd-bus.c
@@ -49,7 +49,6 @@
#include "macro.h"
#include "missing.h"
#include "parse-util.h"
-#include "process-util.h"
#include "string-util.h"
#include "strv.h"
#include "util.h"
diff --git a/src/libelogind/sd-daemon/sd-daemon.c b/src/libelogind/sd-daemon/sd-daemon.c
index 06d3c64ff..85459e166 100644
--- a/src/libelogind/sd-daemon/sd-daemon.c
+++ b/src/libelogind/sd-daemon/sd-daemon.c
@@ -38,7 +38,6 @@
#include "fs-util.h"
#include "parse-util.h"
#include "path-util.h"
-#include "process-util.h"
#include "socket-util.h"
#include "strv.h"
#include "util.h"
diff --git a/src/libelogind/sd-event/test-event.c b/src/libelogind/sd-event/test-event.c
index 656f08d56..1a581ae23 100644
--- a/src/libelogind/sd-event/test-event.c
+++ b/src/libelogind/sd-event/test-event.c
@@ -24,7 +24,6 @@
#include "fd-util.h"
#include "log.h"
#include "macro.h"
-#include "process-util.h"
#include "signal-util.h"
#include "util.h"
diff --git a/src/libelogind/sd-login/test-login.c b/src/libelogind/sd-login/test-login.c
index 58a1cedde..d87467709 100644
--- a/src/libelogind/sd-login/test-login.c
+++ b/src/libelogind/sd-login/test-login.c
@@ -306,4 +306,3 @@ int main(int argc, char* argv[]) {
return 0;
}
-
diff --git a/src/login/logind-session.c b/src/login/logind-session.c
index d2125112d..142ba55e9 100644
--- a/src/login/logind-session.c
+++ b/src/login/logind-session.c
@@ -33,7 +33,6 @@
#include "bus-error.h"
#include "bus-util.h"
#include "escape.h"
-#include "extract-word.h"
#include "fd-util.h"
#include "fileio.h"
#include "format-util.h"
diff --git a/src/login/logind.c b/src/login/logind.c
index 7452c5b82..89c6a49e8 100644
--- a/src/login/logind.c
+++ b/src/login/logind.c
@@ -1140,7 +1140,6 @@ static int manager_dispatch_reload_signal(sd_event_source *s, const struct signa
#if 1 /// elogind needs an Add-On for sleep configuration
elogind_manager_reset_config(m);
#endif // 1
-
return 0;
}
@@ -1164,7 +1163,6 @@ static int manager_startup(Manager *m) {
#if 1 /// elogind needs some extra preparations before connecting...
elogind_manager_startup(m);
#endif // 1
-
/* Connect to console */
r = manager_connect_console(m);
if (r < 0)
@@ -1343,14 +1341,13 @@ int main(int argc, char *argv[]) {
#if 1 /// elogind needs an Add-On for sleep configuration
elogind_manager_reset_config(m);
#endif // 1
-
r = manager_startup(m);
if (r < 0) {
log_error_errno(r, "Failed to fully start up daemon: %m");
goto finish;
}
- log_debug("elogind running as pid "PID_FMT, getpid());
+ log_debug("elogind running as pid "PID_FMT, getpid_cached());
sd_notify(false,
"READY=1\n"
diff --git a/src/shared/conf-parser.c b/src/shared/conf-parser.c
index 2005671fe..ab66bfe60 100644
--- a/src/shared/conf-parser.c
+++ b/src/shared/conf-parser.c
@@ -28,10 +28,8 @@
#include "alloc-util.h"
#include "conf-files.h"
#include "conf-parser.h"
-#include "def.h"
#include "extract-word.h"
#include "fd-util.h"
-#include "fileio.h"
#include "fs-util.h"
#include "log.h"
#include "macro.h"
@@ -317,44 +315,24 @@ int config_parse(const char *unit,
fd_warn_permissions(filename, fileno(f));
for (;;) {
- _cleanup_free_ char *buf = NULL;
- char *l, *p, *c = NULL, *e;
+ char buf[LINE_MAX], *l, *p, *c = NULL, *e;
bool escaped = false;
- r = read_line(f, LONG_LINE_MAX, &buf);
- if (r == 0)
- break;
- if (r == -ENOBUFS) {
- if (warn)
- log_error_errno(r, "%s:%u: Line too long", filename, line);
+ if (!fgets(buf, sizeof buf, f)) {
+ if (feof(f))
+ break;
- return r;
- }
- if (r < 0) {
- if (warn)
- log_error_errno(r, "%s:%u: Error while reading configuration file: %m", filename, line);
-
- return r;
+ return log_error_errno(errno, "Failed to read configuration file '%s': %m", filename);
}
l = buf;
- if (allow_bom) {
- char *q;
+ if (allow_bom && startswith(l, UTF8_BYTE_ORDER_MARK))
+ l += strlen(UTF8_BYTE_ORDER_MARK);
+ allow_bom = false;
- q = startswith(buf, UTF8_BYTE_ORDER_MARK);
- if (q) {
- l = q;
- allow_bom = false;
- }
- }
+ truncate_nl(l);
if (continuation) {
- if (strlen(continuation) + strlen(l) > LONG_LINE_MAX) {
- if (warn)
- log_error("%s:%u: Continuation line too long", filename, line);
- return -ENOBUFS;
- }
-
c = strappend(continuation, l);
if (!c) {
if (warn)
@@ -408,7 +386,8 @@ int config_parse(const char *unit,
if (r < 0) {
if (warn)
- log_warning_errno(r, "%s:%u: Failed to parse file: %m", filename, line);
+ log_warning_errno(r, "Failed to parse file '%s': %m",
+ filename);
return r;
}
}
@@ -755,6 +734,11 @@ int config_parse_path(
assert(rvalue);
assert(data);
+ if (isempty(rvalue)) {
+ n = NULL;
+ goto finalize;
+ }
+
if (!utf8_is_valid(rvalue)) {
log_syntax_invalid_utf8(unit, LOG_ERR, filename, line, rvalue);
return fatal ? -ENOEXEC : 0;
@@ -773,6 +757,7 @@ int config_parse_path(
path_kill_slashes(n);
+finalize:
free(*s);
*s = n;
diff --git a/src/shared/udev-util.c b/src/shared/udev-util.c
index ed32f0305..f708dcfa1 100644
--- a/src/shared/udev-util.c
+++ b/src/shared/udev-util.c
@@ -19,7 +19,6 @@
#include <string.h>
-#include "alloc-util.h"
#include "fileio.h"
#include "log.h"
#include "string-util.h"
diff --git a/src/sleep/sleep.c b/src/sleep/sleep.c
index c6dd13197..01fa22349 100644
--- a/src/sleep/sleep.c
+++ b/src/sleep/sleep.c
@@ -69,7 +69,7 @@ static int write_state(FILE **f, char **states) {
STRV_FOREACH(state, states) {
int k;
- k = write_string_stream(*f, *state, 0);
+ k = write_string_stream(*f, *state, true);
if (k == 0)
return 0;
log_debug_errno(k, "Failed to write '%s' to /sys/power/state: %m",
diff --git a/src/test/meson.build b/src/test/meson.build
index e39ab46e8..7e1adb3d1 100644
--- a/src/test/meson.build
+++ b/src/test/meson.build
@@ -300,11 +300,11 @@ tests += [
# [],
# []],
#
-# [['src/test/test-barrier.c'],
+# [['src/test/test-in-addr-util.c'],
# [],
# []],
#
-# [['src/test/test-in-addr-util.c'],
+# [['src/test/test-barrier.c'],
# [],
# []],
#
diff --git a/src/test/test-cgroup.c b/src/test/test-cgroup.c
index 2ed91c780..71e318a15 100644
--- a/src/test/test-cgroup.c
+++ b/src/test/test-cgroup.c
@@ -22,7 +22,6 @@
#include "cgroup-util.h"
#include "path-util.h"
-#include "process-util.h"
#include "string-util.h"
#include "util.h"
diff --git a/src/test/test-conf-parser.c b/src/test/test-conf-parser.c
index fe94b336a..a66ed1bd3 100644
--- a/src/test/test-conf-parser.c
+++ b/src/test/test-conf-parser.c
@@ -18,8 +18,6 @@
***/
#include "conf-parser.h"
-#include "fd-util.h"
-#include "fileio.h"
#include "log.h"
#include "macro.h"
#include "string-util.h"
@@ -27,10 +25,12 @@
#include "util.h"
static void test_config_parse_path_one(const char *rvalue, const char *expected) {
- _cleanup_free_ char *path = NULL;
+ char *path = NULL;
assert_se(config_parse_path("unit", "filename", 1, "section", 1, "lvalue", 0, rvalue, &path, NULL) >= 0);
assert_se(streq_ptr(expected, path));
+
+ free(path);
}
static void test_config_parse_log_level_one(const char *rvalue, int expected) {
@@ -80,10 +80,12 @@ static void test_config_parse_unsigned_one(const char *rvalue, unsigned expected
}
static void test_config_parse_strv_one(const char *rvalue, char **expected) {
- _cleanup_strv_free_ char **strv = NULL;
+ char **strv = 0;
assert_se(config_parse_strv("unit", "filename", 1, "section", 1, "lvalue", 0, rvalue, &strv, NULL) >= 0);
assert_se(strv_equal(expected, strv));
+
+ strv_free(strv);
}
static void test_config_parse_mode_one(const char *rvalue, mode_t expected) {
@@ -237,130 +239,7 @@ static void test_config_parse_iec_uint64(void) {
}
#endif // 0
-#define x10(x) x x x x x x x x x x
-#define x100(x) x10(x10(x))
-#define x1000(x) x10(x100(x))
-
-static const char* const config_file[] = {
- "[Section]\n"
- "setting1=1\n",
-
- "[Section]\n"
- "setting1=1", /* no terminating newline */
-
- "\n\n\n\n[Section]\n\n\n"
- "setting1=1", /* some whitespace, no terminating newline */
-
- "[Section]\n"
- "[Section]\n"
- "setting1=1\n"
- "setting1=2\n"
- "setting1=1\n", /* repeated settings */
-
- "[Section]\n"
- "setting1=1\\\n" /* normal continuation */
- "2\\\n"
- "3\n",
-
- "[Section]\n"
- "setting1=1\\\\\\\n" /* continuation with trailing escape symbols */
- "\\\\2\n", /* note that C requires one level of escaping, so the
- * parser gets "…1 BS BS BS NL BS BS 2 NL", which
- * it translates into "…1 BS BS SP BS BS 2" */
-
- "\n[Section]\n\n"
- "setting1=" /* a line above LINE_MAX length */
- x1000("ABCD")
- "\n",
-
- "[Section]\n"
- "setting1=" /* a line above LINE_MAX length, with continuation */
- x1000("ABCD") "\\\n"
- "foobar",
-
- "[Section]\n"
- "setting1=" /* a line above the allowed limit: 9 + 1050000 + 1 */
- x1000(x1000("x") x10("abcde")) "\n",
-
- "[Section]\n"
- "setting1=" /* many continuation lines, together above the limit */
- x1000(x1000("x") x10("abcde") "\\\n") "xxx",
-};
-
-static void test_config_parse(unsigned i, const char *s) {
- char name[] = "/tmp/test-conf-parser.XXXXXX";
- int fd, r;
- _cleanup_fclose_ FILE *f = NULL;
- _cleanup_free_ char *setting1 = NULL;
-
- const ConfigTableItem items[] = {
- { "Section", "setting1", config_parse_string, 0, &setting1},
- {}
- };
-
- log_info("== %s[%i] ==", __func__, i);
-
- fd = mkostemp_safe(name);
- assert_se(fd >= 0);
- assert_se((size_t) write(fd, s, strlen(s)) == strlen(s));
-
- assert_se(lseek(fd, 0, SEEK_SET) == 0);
- assert_se(f = fdopen(fd, "r"));
-
- /*
- int config_parse(const char *unit,
- const char *filename,
- FILE *f,
- const char *sections,
- ConfigItemLookup lookup,
- const void *table,
- bool relaxed,
- bool allow_include,
- bool warn,
- void *userdata)
- */
-
- r = config_parse(NULL, name, f,
- "Section\0",
- config_item_table_lookup, items,
- false, false, true, NULL);
-
- switch (i) {
- case 0 ... 3:
- assert_se(r == 0);
- assert_se(streq(setting1, "1"));
- break;
-
- case 4:
- assert_se(r == 0);
- assert_se(streq(setting1, "1 2 3"));
- break;
-
- case 5:
- assert_se(r == 0);
- assert_se(streq(setting1, "1\\\\ \\\\2"));
- break;
-
- case 6:
- assert_se(r == 0);
- assert_se(streq(setting1, x1000("ABCD")));
- break;
-
- case 7:
- assert_se(r == 0);
- assert_se(streq(setting1, x1000("ABCD") " foobar"));
- break;
-
- case 8 ... 9:
- assert_se(r == -ENOBUFS);
- assert_se(setting1 == NULL);
- break;
- }
-}
-
int main(int argc, char **argv) {
- unsigned i;
-
log_parse_environment();
log_open();
@@ -383,8 +262,5 @@ int main(int argc, char **argv) {
test_config_parse_iec_uint64();
#endif // 0
- for (i = 0; i < ELEMENTSOF(config_file); i++)
- test_config_parse(i, config_file[i]);
-
return 0;
}
diff --git a/src/test/test-log.c b/src/test/test-log.c
index ec1bc2a63..8ab569f47 100644
--- a/src/test/test-log.c
+++ b/src/test/test-log.c
@@ -22,7 +22,6 @@
#include "format-util.h"
#include "log.h"
-#include "process-util.h"
#include "util.h"
assert_cc(LOG_REALM_REMOVE_LEVEL(LOG_REALM_PLUS_LEVEL(LOG_REALM_SYSTEMD, LOG_FTP | LOG_DEBUG))
diff --git a/src/test/test-signal-util.c b/src/test/test-signal-util.c
index 1830396ac..92e392778 100644
--- a/src/test/test-signal-util.c
+++ b/src/test/test-signal-util.c
@@ -21,7 +21,6 @@
#include <unistd.h>
#include "macro.h"
-#include "process-util.h"
#include "signal-util.h"
static void test_block_signals(void) {