summaryrefslogtreecommitdiff
path: root/src/basic
diff options
context:
space:
mode:
Diffstat (limited to 'src/basic')
-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
9 files changed, 74 insertions, 113 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);
}