mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager
synced 2024-10-15 12:34:55 +00:00
systemd: update code from upstream (2018-06-15)
This is a direct dump from systemd git. ====== SYSTEMD_DIR=../systemd COMMIT=88f375b8c28806633d22ed99f6a5f1194c78ed73 ( cd "$SYSTEMD_DIR" git checkout "$COMMIT" git reset --hard git clean -fdx ) git ls-files :/src/systemd/src/ \ :/shared/nm-utils/siphash24.h \ :/shared/nm-utils/unaligned.h | \ xargs -d '\n' rm -f nm_copy_sd() { mkdir -p "./src/systemd/$(dirname "$1")" cp "$SYSTEMD_DIR/$1" "./src/systemd/$1" } nm_copy_sd_shared() { mkdir -p "./shared/nm-utils/" cp "$SYSTEMD_DIR/$1" "./shared/nm-utils/${1##*/}" } nm_copy_sd "src/basic/alloc-util.c" nm_copy_sd "src/basic/alloc-util.h" nm_copy_sd "src/basic/async.h" nm_copy_sd "src/basic/escape.c" nm_copy_sd "src/basic/escape.h" nm_copy_sd "src/basic/ether-addr-util.c" nm_copy_sd "src/basic/ether-addr-util.h" nm_copy_sd "src/basic/extract-word.c" nm_copy_sd "src/basic/extract-word.h" nm_copy_sd "src/basic/fileio.c" nm_copy_sd "src/basic/fileio.h" nm_copy_sd "src/basic/fd-util.c" nm_copy_sd "src/basic/fd-util.h" nm_copy_sd "src/basic/fs-util.c" nm_copy_sd "src/basic/fs-util.h" nm_copy_sd "src/basic/hash-funcs.c" nm_copy_sd "src/basic/hash-funcs.h" nm_copy_sd "src/basic/hashmap.c" nm_copy_sd "src/basic/hashmap.h" nm_copy_sd "src/basic/hexdecoct.c" nm_copy_sd "src/basic/hexdecoct.h" nm_copy_sd "src/basic/hostname-util.c" nm_copy_sd "src/basic/hostname-util.h" nm_copy_sd "src/basic/in-addr-util.c" nm_copy_sd "src/basic/in-addr-util.h" nm_copy_sd "src/basic/io-util.c" nm_copy_sd "src/basic/io-util.h" nm_copy_sd "src/basic/list.h" nm_copy_sd "src/basic/log.h" nm_copy_sd "src/basic/macro.h" nm_copy_sd "src/basic/mempool.h" nm_copy_sd "src/basic/mempool.c" nm_copy_sd "src/basic/parse-util.c" nm_copy_sd "src/basic/parse-util.h" nm_copy_sd "src/basic/path-util.c" nm_copy_sd "src/basic/path-util.h" nm_copy_sd "src/basic/prioq.h" nm_copy_sd "src/basic/prioq.c" nm_copy_sd "src/basic/process-util.h" nm_copy_sd "src/basic/process-util.c" nm_copy_sd "src/basic/random-util.c" nm_copy_sd "src/basic/random-util.h" nm_copy_sd "src/basic/refcnt.h" nm_copy_sd "src/basic/set.h" nm_copy_sd "src/basic/signal-util.h" nm_copy_sd "src/basic/siphash24.h" nm_copy_sd "src/basic/socket-util.c" nm_copy_sd "src/basic/socket-util.h" nm_copy_sd "src/basic/sparse-endian.h" nm_copy_sd "src/basic/stat-util.c" nm_copy_sd "src/basic/stat-util.h" nm_copy_sd "src/basic/stdio-util.h" nm_copy_sd "src/basic/string-table.c" nm_copy_sd "src/basic/string-table.h" nm_copy_sd "src/basic/string-util.c" nm_copy_sd "src/basic/string-util.h" nm_copy_sd "src/basic/strv.c" nm_copy_sd "src/basic/strv.h" nm_copy_sd "src/basic/time-util.c" nm_copy_sd "src/basic/time-util.h" nm_copy_sd "src/basic/umask-util.h" nm_copy_sd_shared "src/basic/unaligned.h" nm_copy_sd "src/basic/utf8.c" nm_copy_sd "src/basic/utf8.h" nm_copy_sd "src/basic/util.c" nm_copy_sd "src/basic/util.h" nm_copy_sd "src/libsystemd-network/arp-util.c" nm_copy_sd "src/libsystemd-network/arp-util.h" nm_copy_sd "src/libsystemd-network/dhcp6-internal.h" nm_copy_sd "src/libsystemd-network/dhcp6-lease-internal.h" nm_copy_sd "src/libsystemd-network/dhcp6-network.c" nm_copy_sd "src/libsystemd-network/dhcp6-option.c" nm_copy_sd "src/libsystemd-network/dhcp6-protocol.h" nm_copy_sd "src/libsystemd-network/dhcp-identifier.c" nm_copy_sd "src/libsystemd-network/dhcp-identifier.h" nm_copy_sd "src/libsystemd-network/dhcp-internal.h" nm_copy_sd "src/libsystemd-network/dhcp-lease-internal.h" nm_copy_sd "src/libsystemd-network/dhcp-network.c" nm_copy_sd "src/libsystemd-network/dhcp-option.c" nm_copy_sd "src/libsystemd-network/dhcp-packet.c" nm_copy_sd "src/libsystemd-network/dhcp-protocol.h" nm_copy_sd "src/libsystemd-network/lldp-internal.h" nm_copy_sd "src/libsystemd-network/lldp-neighbor.c" nm_copy_sd "src/libsystemd-network/lldp-neighbor.h" nm_copy_sd "src/libsystemd-network/lldp-network.c" nm_copy_sd "src/libsystemd-network/lldp-network.h" nm_copy_sd "src/libsystemd-network/network-internal.c" nm_copy_sd "src/libsystemd-network/network-internal.h" nm_copy_sd "src/libsystemd-network/sd-dhcp6-client.c" nm_copy_sd "src/libsystemd-network/sd-dhcp6-lease.c" nm_copy_sd "src/libsystemd-network/sd-dhcp-client.c" nm_copy_sd "src/libsystemd-network/sd-dhcp-lease.c" nm_copy_sd "src/libsystemd-network/sd-ipv4ll.c" nm_copy_sd "src/libsystemd-network/sd-ipv4acd.c" nm_copy_sd "src/libsystemd-network/sd-lldp.c" nm_copy_sd "src/libsystemd/sd-event/sd-event.c" nm_copy_sd "src/libsystemd/sd-id128/id128-util.c" nm_copy_sd "src/libsystemd/sd-id128/id128-util.h" nm_copy_sd "src/libsystemd/sd-id128/sd-id128.c" nm_copy_sd "src/shared/dns-domain.c" nm_copy_sd "src/shared/dns-domain.h" nm_copy_sd "src/systemd/_sd-common.h" nm_copy_sd "src/systemd/sd-dhcp6-client.h" nm_copy_sd "src/systemd/sd-dhcp6-lease.h" nm_copy_sd "src/systemd/sd-dhcp-client.h" nm_copy_sd "src/systemd/sd-dhcp-lease.h" nm_copy_sd "src/systemd/sd-event.h" nm_copy_sd "src/systemd/sd-ndisc.h" nm_copy_sd "src/systemd/sd-id128.h" nm_copy_sd "src/systemd/sd-ipv4acd.h" nm_copy_sd "src/systemd/sd-ipv4ll.h" nm_copy_sd "src/systemd/sd-lldp.h"
This commit is contained in:
parent
ac170893e9
commit
353810ccc1
|
@ -1,200 +0,0 @@
|
|||
/*
|
||||
SipHash reference C implementation
|
||||
|
||||
Written in 2012 by
|
||||
Jean-Philippe Aumasson <jeanphilippe.aumasson@gmail.com>
|
||||
Daniel J. Bernstein <djb@cr.yp.to>
|
||||
|
||||
To the extent possible under law, the author(s) have dedicated all copyright
|
||||
and related and neighboring rights to this software to the public domain
|
||||
worldwide. This software is distributed without any warranty.
|
||||
|
||||
You should have received a copy of the CC0 Public Domain Dedication along with
|
||||
this software. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
|
||||
|
||||
(Minimal changes made by Lennart Poettering, to make clean for inclusion in systemd)
|
||||
(Refactored by Tom Gundersen to split up in several functions and follow systemd
|
||||
coding style)
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "macro.h"
|
||||
#include "siphash24.h"
|
||||
#include "unaligned.h"
|
||||
|
||||
static inline uint64_t rotate_left(uint64_t x, uint8_t b) {
|
||||
assert(b < 64);
|
||||
|
||||
return (x << b) | (x >> (64 - b));
|
||||
}
|
||||
|
||||
static inline void sipround(struct siphash *state) {
|
||||
assert(state);
|
||||
|
||||
state->v0 += state->v1;
|
||||
state->v1 = rotate_left(state->v1, 13);
|
||||
state->v1 ^= state->v0;
|
||||
state->v0 = rotate_left(state->v0, 32);
|
||||
state->v2 += state->v3;
|
||||
state->v3 = rotate_left(state->v3, 16);
|
||||
state->v3 ^= state->v2;
|
||||
state->v0 += state->v3;
|
||||
state->v3 = rotate_left(state->v3, 21);
|
||||
state->v3 ^= state->v0;
|
||||
state->v2 += state->v1;
|
||||
state->v1 = rotate_left(state->v1, 17);
|
||||
state->v1 ^= state->v2;
|
||||
state->v2 = rotate_left(state->v2, 32);
|
||||
}
|
||||
|
||||
void siphash24_init(struct siphash *state, const uint8_t k[16]) {
|
||||
uint64_t k0, k1;
|
||||
|
||||
assert(state);
|
||||
assert(k);
|
||||
|
||||
k0 = unaligned_read_le64(k);
|
||||
k1 = unaligned_read_le64(k + 8);
|
||||
|
||||
*state = (struct siphash) {
|
||||
/* "somepseudorandomlygeneratedbytes" */
|
||||
.v0 = 0x736f6d6570736575ULL ^ k0,
|
||||
.v1 = 0x646f72616e646f6dULL ^ k1,
|
||||
.v2 = 0x6c7967656e657261ULL ^ k0,
|
||||
.v3 = 0x7465646279746573ULL ^ k1,
|
||||
.padding = 0,
|
||||
.inlen = 0,
|
||||
};
|
||||
}
|
||||
|
||||
void siphash24_compress(const void *_in, size_t inlen, struct siphash *state) {
|
||||
|
||||
const uint8_t *in = _in;
|
||||
const uint8_t *end = in + inlen;
|
||||
size_t left = state->inlen & 7;
|
||||
uint64_t m;
|
||||
|
||||
assert(in);
|
||||
assert(state);
|
||||
|
||||
/* Update total length */
|
||||
state->inlen += inlen;
|
||||
|
||||
/* If padding exists, fill it out */
|
||||
if (left > 0) {
|
||||
for ( ; in < end && left < 8; in ++, left ++)
|
||||
state->padding |= ((uint64_t) *in) << (left * 8);
|
||||
|
||||
if (in == end && left < 8)
|
||||
/* We did not have enough input to fill out the padding completely */
|
||||
return;
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("(%3zu) v0 %08x %08x\n", state->inlen, (uint32_t) (state->v0 >> 32), (uint32_t) state->v0);
|
||||
printf("(%3zu) v1 %08x %08x\n", state->inlen, (uint32_t) (state->v1 >> 32), (uint32_t) state->v1);
|
||||
printf("(%3zu) v2 %08x %08x\n", state->inlen, (uint32_t) (state->v2 >> 32), (uint32_t) state->v2);
|
||||
printf("(%3zu) v3 %08x %08x\n", state->inlen, (uint32_t) (state->v3 >> 32), (uint32_t) state->v3);
|
||||
printf("(%3zu) compress padding %08x %08x\n", state->inlen, (uint32_t) (state->padding >> 32), (uint32_t)state->padding);
|
||||
#endif
|
||||
|
||||
state->v3 ^= state->padding;
|
||||
sipround(state);
|
||||
sipround(state);
|
||||
state->v0 ^= state->padding;
|
||||
|
||||
state->padding = 0;
|
||||
}
|
||||
|
||||
end -= (state->inlen % sizeof(uint64_t));
|
||||
|
||||
for ( ; in < end; in += 8) {
|
||||
m = unaligned_read_le64(in);
|
||||
#ifdef DEBUG
|
||||
printf("(%3zu) v0 %08x %08x\n", state->inlen, (uint32_t) (state->v0 >> 32), (uint32_t) state->v0);
|
||||
printf("(%3zu) v1 %08x %08x\n", state->inlen, (uint32_t) (state->v1 >> 32), (uint32_t) state->v1);
|
||||
printf("(%3zu) v2 %08x %08x\n", state->inlen, (uint32_t) (state->v2 >> 32), (uint32_t) state->v2);
|
||||
printf("(%3zu) v3 %08x %08x\n", state->inlen, (uint32_t) (state->v3 >> 32), (uint32_t) state->v3);
|
||||
printf("(%3zu) compress %08x %08x\n", state->inlen, (uint32_t) (m >> 32), (uint32_t) m);
|
||||
#endif
|
||||
state->v3 ^= m;
|
||||
sipround(state);
|
||||
sipround(state);
|
||||
state->v0 ^= m;
|
||||
}
|
||||
|
||||
left = state->inlen & 7;
|
||||
switch (left) {
|
||||
case 7:
|
||||
state->padding |= ((uint64_t) in[6]) << 48;
|
||||
_fallthrough_;
|
||||
case 6:
|
||||
state->padding |= ((uint64_t) in[5]) << 40;
|
||||
_fallthrough_;
|
||||
case 5:
|
||||
state->padding |= ((uint64_t) in[4]) << 32;
|
||||
_fallthrough_;
|
||||
case 4:
|
||||
state->padding |= ((uint64_t) in[3]) << 24;
|
||||
_fallthrough_;
|
||||
case 3:
|
||||
state->padding |= ((uint64_t) in[2]) << 16;
|
||||
_fallthrough_;
|
||||
case 2:
|
||||
state->padding |= ((uint64_t) in[1]) << 8;
|
||||
_fallthrough_;
|
||||
case 1:
|
||||
state->padding |= ((uint64_t) in[0]);
|
||||
_fallthrough_;
|
||||
case 0:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
uint64_t siphash24_finalize(struct siphash *state) {
|
||||
uint64_t b;
|
||||
|
||||
assert(state);
|
||||
|
||||
b = state->padding | (((uint64_t) state->inlen) << 56);
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("(%3zu) v0 %08x %08x\n", state->inlen, (uint32_t) (state->v0 >> 32), (uint32_t) state->v0);
|
||||
printf("(%3zu) v1 %08x %08x\n", state->inlen, (uint32_t) (state->v1 >> 32), (uint32_t) state->v1);
|
||||
printf("(%3zu) v2 %08x %08x\n", state->inlen, (uint32_t) (state->v2 >> 32), (uint32_t) state->v2);
|
||||
printf("(%3zu) v3 %08x %08x\n", state->inlen, (uint32_t) (state->v3 >> 32), (uint32_t) state->v3);
|
||||
printf("(%3zu) padding %08x %08x\n", state->inlen, (uint32_t) (state->padding >> 32), (uint32_t) state->padding);
|
||||
#endif
|
||||
|
||||
state->v3 ^= b;
|
||||
sipround(state);
|
||||
sipround(state);
|
||||
state->v0 ^= b;
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("(%3zu) v0 %08x %08x\n", state->inlen, (uint32_t) (state->v0 >> 32), (uint32_t) state->v0);
|
||||
printf("(%3zu) v1 %08x %08x\n", state->inlen, (uint32_t) (state->v1 >> 32), (uint32_t) state->v1);
|
||||
printf("(%3zu) v2 %08x %08x\n", state->inlen, (uint32_t) (state->v2 >> 32), (uint32_t) state->v2);
|
||||
printf("(%3zu) v3 %08x %08x\n", state->inlen, (uint32_t) (state->v3 >> 32), (uint32_t) state->v3);
|
||||
#endif
|
||||
state->v2 ^= 0xff;
|
||||
|
||||
sipround(state);
|
||||
sipround(state);
|
||||
sipround(state);
|
||||
sipround(state);
|
||||
|
||||
return state->v0 ^ state->v1 ^ state->v2 ^ state->v3;
|
||||
}
|
||||
|
||||
uint64_t siphash24(const void *in, size_t inlen, const uint8_t k[16]) {
|
||||
struct siphash state;
|
||||
|
||||
assert(in);
|
||||
assert(k);
|
||||
|
||||
siphash24_init(&state, k);
|
||||
siphash24_compress(in, inlen, &state);
|
||||
|
||||
return siphash24_finalize(&state);
|
||||
}
|
|
@ -2,9 +2,7 @@
|
|||
#pragma once
|
||||
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
Copyright 2014 Tom Gundersen
|
||||
Copyright © 2014 Tom Gundersen
|
||||
***/
|
||||
|
||||
#include <endian.h>
|
||||
|
|
|
@ -1,9 +1,4 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
Copyright 2010 Lennart Poettering
|
||||
***/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
|
|
@ -1,12 +1,6 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
#pragma once
|
||||
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
Copyright 2010 Lennart Poettering
|
||||
***/
|
||||
|
||||
#include <alloca.h>
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
|
|
|
@ -1,12 +1,6 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
#pragma once
|
||||
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
Copyright 2013 Lennart Poettering
|
||||
***/
|
||||
|
||||
int asynchronous_job(void* (*func)(void *p), void *arg);
|
||||
|
||||
int asynchronous_sync(pid_t *ret_pid);
|
||||
|
|
|
@ -1,9 +1,4 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
Copyright 2010 Lennart Poettering
|
||||
***/
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
|
@ -15,8 +10,10 @@
|
|||
#include "macro.h"
|
||||
#include "utf8.h"
|
||||
|
||||
size_t cescape_char(char c, char *buf) {
|
||||
char * buf_old = buf;
|
||||
int cescape_char(char c, char *buf) {
|
||||
char *buf_old = buf;
|
||||
|
||||
/* Needs space for 4 characters in the buffer */
|
||||
|
||||
switch (c) {
|
||||
|
||||
|
|
|
@ -1,12 +1,6 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
#pragma once
|
||||
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
Copyright 2010 Lennart Poettering
|
||||
***/
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
@ -45,7 +39,7 @@ typedef enum EscapeStyle {
|
|||
|
||||
char *cescape(const char *s);
|
||||
char *cescape_length(const char *s, size_t n);
|
||||
size_t cescape_char(char c, char *buf);
|
||||
int 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);
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
Copyright 2014 Tom Gundersen
|
||||
Copyright © 2014 Tom Gundersen
|
||||
***/
|
||||
|
||||
#include <errno.h>
|
||||
|
|
|
@ -2,9 +2,7 @@
|
|||
#pragma once
|
||||
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
Copyright 2014 Tom Gundersen
|
||||
Copyright © 2014 Tom Gundersen
|
||||
***/
|
||||
|
||||
#include <net/ethernet.h>
|
||||
|
|
|
@ -1,9 +1,4 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
Copyright 2010 Lennart Poettering
|
||||
***/
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdarg.h>
|
||||
|
|
|
@ -1,12 +1,6 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
#pragma once
|
||||
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
Copyright 2010 Lennart Poettering
|
||||
***/
|
||||
|
||||
#include "macro.h"
|
||||
|
||||
typedef enum ExtractFlags {
|
||||
|
|
|
@ -1,9 +1,4 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
Copyright 2010 Lennart Poettering
|
||||
***/
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
|
@ -12,10 +7,13 @@
|
|||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "alloc-util.h"
|
||||
#include "copy.h"
|
||||
#include "dirent-util.h"
|
||||
#include "fd-util.h"
|
||||
#include "fileio.h"
|
||||
#include "fs-util.h"
|
||||
#include "io-util.h"
|
||||
#include "macro.h"
|
||||
#include "memfd-util.h"
|
||||
#include "missing.h"
|
||||
|
@ -562,6 +560,201 @@ try_dev_shm_without_o_tmpfile:
|
|||
return -EOPNOTSUPP;
|
||||
}
|
||||
|
||||
/* When the data is smaller or equal to 64K, try to place the copy in a memfd/pipe */
|
||||
#define DATA_FD_MEMORY_LIMIT (64U*1024U)
|
||||
|
||||
/* If memfd/pipe didn't work out, then let's use a file in /tmp up to a size of 1M. If it's large than that use /var/tmp instead. */
|
||||
#define DATA_FD_TMP_LIMIT (1024U*1024U)
|
||||
|
||||
int fd_duplicate_data_fd(int fd) {
|
||||
|
||||
_cleanup_close_ int copy_fd = -1, tmp_fd = -1;
|
||||
_cleanup_free_ void *remains = NULL;
|
||||
size_t remains_size = 0;
|
||||
const char *td;
|
||||
struct stat st;
|
||||
int r;
|
||||
|
||||
/* Creates a 'data' fd from the specified source fd, containing all the same data in a read-only fashion, but
|
||||
* independent of it (i.e. the source fd can be closed and unmounted after this call succeeded). Tries to be
|
||||
* somewhat smart about where to place the data. In the best case uses a memfd(). If memfd() are not supported
|
||||
* uses a pipe instead. For larger data will use an unlinked file in /tmp, and for even larger data one in
|
||||
* /var/tmp. */
|
||||
|
||||
if (fstat(fd, &st) < 0)
|
||||
return -errno;
|
||||
|
||||
/* For now, let's only accept regular files, sockets, pipes and char devices */
|
||||
if (S_ISDIR(st.st_mode))
|
||||
return -EISDIR;
|
||||
if (S_ISLNK(st.st_mode))
|
||||
return -ELOOP;
|
||||
if (!S_ISREG(st.st_mode) && !S_ISSOCK(st.st_mode) && !S_ISFIFO(st.st_mode) && !S_ISCHR(st.st_mode))
|
||||
return -EBADFD;
|
||||
|
||||
/* If we have reason to believe the data is bounded in size, then let's use memfds or pipes as backing fd. Note
|
||||
* that we use the reported regular file size only as a hint, given that there are plenty special files in
|
||||
* /proc and /sys which report a zero file size but can be read from. */
|
||||
|
||||
if (!S_ISREG(st.st_mode) || st.st_size < DATA_FD_MEMORY_LIMIT) {
|
||||
|
||||
/* Try a memfd first */
|
||||
copy_fd = memfd_new("data-fd");
|
||||
if (copy_fd >= 0) {
|
||||
off_t f;
|
||||
|
||||
r = copy_bytes(fd, copy_fd, DATA_FD_MEMORY_LIMIT, 0);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
f = lseek(copy_fd, 0, SEEK_SET);
|
||||
if (f != 0)
|
||||
return -errno;
|
||||
|
||||
if (r == 0) {
|
||||
/* Did it fit into the limit? If so, we are done. */
|
||||
r = memfd_set_sealed(copy_fd);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
return TAKE_FD(copy_fd);
|
||||
}
|
||||
|
||||
/* Hmm, pity, this didn't fit. Let's fall back to /tmp then, see below */
|
||||
|
||||
} else {
|
||||
_cleanup_(close_pairp) int pipefds[2] = { -1, -1 };
|
||||
int isz;
|
||||
|
||||
/* If memfds aren't available, use a pipe. Set O_NONBLOCK so that we will get EAGAIN rather
|
||||
* then block indefinitely when we hit the pipe size limit */
|
||||
|
||||
if (pipe2(pipefds, O_CLOEXEC|O_NONBLOCK) < 0)
|
||||
return -errno;
|
||||
|
||||
isz = fcntl(pipefds[1], F_GETPIPE_SZ, 0);
|
||||
if (isz < 0)
|
||||
return -errno;
|
||||
|
||||
/* Try to enlarge the pipe size if necessary */
|
||||
if ((size_t) isz < DATA_FD_MEMORY_LIMIT) {
|
||||
|
||||
(void) fcntl(pipefds[1], F_SETPIPE_SZ, DATA_FD_MEMORY_LIMIT);
|
||||
|
||||
isz = fcntl(pipefds[1], F_GETPIPE_SZ, 0);
|
||||
if (isz < 0)
|
||||
return -errno;
|
||||
}
|
||||
|
||||
if ((size_t) isz >= DATA_FD_MEMORY_LIMIT) {
|
||||
|
||||
r = copy_bytes_full(fd, pipefds[1], DATA_FD_MEMORY_LIMIT, 0, &remains, &remains_size);
|
||||
if (r < 0 && r != -EAGAIN)
|
||||
return r; /* If we get EAGAIN it could be because of the source or because of
|
||||
* the destination fd, we can't know, as sendfile() and friends won't
|
||||
* tell us. Hence, treat this as reason to fall back, just to be
|
||||
* sure. */
|
||||
if (r == 0) {
|
||||
/* Everything fit in, yay! */
|
||||
(void) fd_nonblock(pipefds[0], false);
|
||||
|
||||
return TAKE_FD(pipefds[0]);
|
||||
}
|
||||
|
||||
/* Things didn't fit in. But we read data into the pipe, let's remember that, so that
|
||||
* when writing the new file we incorporate this first. */
|
||||
copy_fd = TAKE_FD(pipefds[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* If we have reason to believe this will fit fine in /tmp, then use that as first fallback. */
|
||||
if ((!S_ISREG(st.st_mode) || st.st_size < DATA_FD_TMP_LIMIT) &&
|
||||
(DATA_FD_MEMORY_LIMIT + remains_size) < DATA_FD_TMP_LIMIT) {
|
||||
off_t f;
|
||||
|
||||
tmp_fd = open_tmpfile_unlinkable(NULL /* NULL as directory means /tmp */, O_RDWR|O_CLOEXEC);
|
||||
if (tmp_fd < 0)
|
||||
return tmp_fd;
|
||||
|
||||
if (copy_fd >= 0) {
|
||||
/* If we tried a memfd/pipe first and it ended up being too large, then copy this into the
|
||||
* temporary file first. */
|
||||
|
||||
r = copy_bytes(copy_fd, tmp_fd, UINT64_MAX, 0);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
assert(r == 0);
|
||||
}
|
||||
|
||||
if (remains_size > 0) {
|
||||
/* If there were remaining bytes (i.e. read into memory, but not written out yet) from the
|
||||
* failed copy operation, let's flush them out next. */
|
||||
|
||||
r = loop_write(tmp_fd, remains, remains_size, false);
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
|
||||
r = copy_bytes(fd, tmp_fd, DATA_FD_TMP_LIMIT - DATA_FD_MEMORY_LIMIT - remains_size, COPY_REFLINK);
|
||||
if (r < 0)
|
||||
return r;
|
||||
if (r == 0)
|
||||
goto finish; /* Yay, it fit in */
|
||||
|
||||
/* It didn't fit in. Let's not forget to use what we already used */
|
||||
f = lseek(tmp_fd, 0, SEEK_SET);
|
||||
if (f != 0)
|
||||
return -errno;
|
||||
|
||||
safe_close(copy_fd);
|
||||
copy_fd = TAKE_FD(tmp_fd);
|
||||
|
||||
remains = mfree(remains);
|
||||
remains_size = 0;
|
||||
}
|
||||
|
||||
/* As last fallback use /var/tmp */
|
||||
r = var_tmp_dir(&td);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
tmp_fd = open_tmpfile_unlinkable(td, O_RDWR|O_CLOEXEC);
|
||||
if (tmp_fd < 0)
|
||||
return tmp_fd;
|
||||
|
||||
if (copy_fd >= 0) {
|
||||
/* If we tried a memfd/pipe first, or a file in /tmp, and it ended up being too large, than copy this
|
||||
* into the temporary file first. */
|
||||
r = copy_bytes(copy_fd, tmp_fd, UINT64_MAX, COPY_REFLINK);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
assert(r == 0);
|
||||
}
|
||||
|
||||
if (remains_size > 0) {
|
||||
/* Then, copy in any read but not yet written bytes. */
|
||||
r = loop_write(tmp_fd, remains, remains_size, false);
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
|
||||
/* Copy in the rest */
|
||||
r = copy_bytes(fd, tmp_fd, UINT64_MAX, COPY_REFLINK);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
assert(r == 0);
|
||||
|
||||
finish:
|
||||
/* Now convert the O_RDWR file descriptor into an O_RDONLY one (and as side effect seek to the beginning of the
|
||||
* file again */
|
||||
|
||||
return fd_reopen(tmp_fd, O_RDONLY|O_CLOEXEC);
|
||||
}
|
||||
|
||||
int fd_move_above_stdio(int fd) {
|
||||
int flags, copy;
|
||||
PROTECT_ERRNO;
|
||||
|
@ -732,3 +925,27 @@ int fd_reopen(int fd, int flags) {
|
|||
|
||||
return new_fd;
|
||||
}
|
||||
|
||||
int read_nr_open(void) {
|
||||
_cleanup_free_ char *nr_open = NULL;
|
||||
int r;
|
||||
|
||||
/* Returns the kernel's current fd limit, either by reading it of /proc/sys if that works, or using the
|
||||
* hard-coded default compiled-in value of current kernels (1M) if not. This call will never fail. */
|
||||
|
||||
r = read_one_line_file("/proc/sys/fs/nr_open", &nr_open);
|
||||
if (r < 0)
|
||||
log_debug_errno(r, "Failed to read /proc/sys/fs/nr_open, ignoring: %m");
|
||||
else {
|
||||
int v;
|
||||
|
||||
r = safe_atoi(nr_open, &v);
|
||||
if (r < 0)
|
||||
log_debug_errno(r, "Failed to parse /proc/sys/fs/nr_open value '%s', ignoring: %m", nr_open);
|
||||
else
|
||||
return v;
|
||||
}
|
||||
|
||||
/* If we fail, fallback to the hard-coded kernel limit of 1024 * 1024. */
|
||||
return 1024 * 1024;
|
||||
}
|
||||
|
|
|
@ -1,12 +1,6 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
#pragma once
|
||||
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
Copyright 2010 Lennart Poettering
|
||||
***/
|
||||
|
||||
#include <dirent.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
|
@ -81,6 +75,8 @@ enum {
|
|||
|
||||
int acquire_data_fd(const void *data, size_t size, unsigned flags);
|
||||
|
||||
int fd_duplicate_data_fd(int fd);
|
||||
|
||||
/* Hint: ENETUNREACH happens if we try to connect to "non-existing" special IP addresses, such as ::5 */
|
||||
#define ERRNO_IS_DISCONNECT(r) \
|
||||
IN_SET(r, ENOTCONN, ECONNRESET, ECONNREFUSED, ECONNABORTED, EPIPE, ENETUNREACH)
|
||||
|
@ -106,3 +102,5 @@ static inline int make_null_stdio(void) {
|
|||
})
|
||||
|
||||
int fd_reopen(int fd, int flags);
|
||||
|
||||
int read_nr_open(void);
|
||||
|
|
|
@ -1,9 +1,4 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
Copyright 2010 Lennart Poettering
|
||||
***/
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
|
@ -206,6 +201,25 @@ fail:
|
|||
return 0;
|
||||
}
|
||||
|
||||
int write_string_filef(
|
||||
const char *fn,
|
||||
WriteStringFileFlags flags,
|
||||
const char *format, ...) {
|
||||
|
||||
_cleanup_free_ char *p = NULL;
|
||||
va_list ap;
|
||||
int r;
|
||||
|
||||
va_start(ap, format);
|
||||
r = vasprintf(&p, format, ap);
|
||||
va_end(ap);
|
||||
|
||||
if (r < 0)
|
||||
return -ENOMEM;
|
||||
|
||||
return write_string_file(fn, p, flags);
|
||||
}
|
||||
|
||||
int read_one_line_file(const char *fn, char **line) {
|
||||
_cleanup_fclose_ FILE *f = NULL;
|
||||
int r;
|
||||
|
@ -263,29 +277,35 @@ int verify_file(const char *fn, const char *blob, bool accept_extra_nl) {
|
|||
}
|
||||
|
||||
int read_full_stream(FILE *f, char **contents, size_t *size) {
|
||||
size_t n, l;
|
||||
_cleanup_free_ char *buf = NULL;
|
||||
struct stat st;
|
||||
size_t n, l;
|
||||
int fd;
|
||||
|
||||
assert(f);
|
||||
assert(contents);
|
||||
|
||||
if (fstat(fileno(f), &st) < 0)
|
||||
return -errno;
|
||||
|
||||
n = LINE_MAX;
|
||||
|
||||
if (S_ISREG(st.st_mode)) {
|
||||
fd = fileno(f);
|
||||
if (fd >= 0) { /* If the FILE* object is backed by an fd (as opposed to memory or such, see fmemopen(), let's
|
||||
* optimize our buffering) */
|
||||
|
||||
/* Safety check */
|
||||
if (st.st_size > READ_FULL_BYTES_MAX)
|
||||
return -E2BIG;
|
||||
if (fstat(fileno(f), &st) < 0)
|
||||
return -errno;
|
||||
|
||||
/* Start with the right file size, but be prepared for files from /proc which generally report a file
|
||||
* size of 0. Note that we increase the size to read here by one, so that the first read attempt
|
||||
* already makes us notice the EOF. */
|
||||
if (st.st_size > 0)
|
||||
n = st.st_size + 1;
|
||||
if (S_ISREG(st.st_mode)) {
|
||||
|
||||
/* Safety check */
|
||||
if (st.st_size > READ_FULL_BYTES_MAX)
|
||||
return -E2BIG;
|
||||
|
||||
/* Start with the right file size, but be prepared for files from /proc which generally report a file
|
||||
* size of 0. Note that we increase the size to read here by one, so that the first read attempt
|
||||
* already makes us notice the EOF. */
|
||||
if (st.st_size > 0)
|
||||
n = st.st_size + 1;
|
||||
}
|
||||
}
|
||||
|
||||
l = 0;
|
||||
|
@ -676,21 +696,41 @@ static int parse_env_file_push(
|
|||
return 0;
|
||||
}
|
||||
|
||||
int parse_env_file(
|
||||
int parse_env_filev(
|
||||
FILE *f,
|
||||
const char *fname,
|
||||
const char *newline, ...) {
|
||||
const char *newline,
|
||||
va_list ap) {
|
||||
|
||||
va_list ap;
|
||||
int r, n_pushed = 0;
|
||||
va_list aq;
|
||||
|
||||
if (!newline)
|
||||
newline = NEWLINE;
|
||||
|
||||
va_copy(aq, ap);
|
||||
r = parse_env_file_internal(f, fname, newline, parse_env_file_push, &aq, &n_pushed);
|
||||
va_end(aq);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
return n_pushed;
|
||||
}
|
||||
|
||||
int parse_env_file(
|
||||
FILE *f,
|
||||
const char *fname,
|
||||
const char *newline,
|
||||
...) {
|
||||
|
||||
va_list ap;
|
||||
int r;
|
||||
|
||||
va_start(ap, newline);
|
||||
r = parse_env_file_internal(NULL, fname, newline, parse_env_file_push, &ap, &n_pushed);
|
||||
r = parse_env_filev(f, fname, newline, ap);
|
||||
va_end(ap);
|
||||
|
||||
return r < 0 ? r : n_pushed;
|
||||
return r;
|
||||
}
|
||||
|
||||
static int load_env_file_push(
|
||||
|
@ -1208,7 +1248,7 @@ int tempfn_xxxxxx(const char *p, const char *extra, char **ret) {
|
|||
|
||||
strcpy(stpcpy(stpcpy(stpcpy(mempcpy(t, p, fn - p), ".#"), extra), fn), "XXXXXX");
|
||||
|
||||
*ret = path_kill_slashes(t);
|
||||
*ret = path_simplify(t, false);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -1249,7 +1289,7 @@ int tempfn_random(const char *p, const char *extra, char **ret) {
|
|||
|
||||
*x = 0;
|
||||
|
||||
*ret = path_kill_slashes(t);
|
||||
*ret = path_simplify(t, false);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -1289,7 +1329,7 @@ int tempfn_random_child(const char *p, const char *extra, char **ret) {
|
|||
|
||||
*x = 0;
|
||||
|
||||
*ret = path_kill_slashes(t);
|
||||
*ret = path_simplify(t, false);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -1515,21 +1555,29 @@ int read_nul_string(FILE *f, char **ret) {
|
|||
}
|
||||
|
||||
int mkdtemp_malloc(const char *template, char **ret) {
|
||||
char *p;
|
||||
_cleanup_free_ char *p = NULL;
|
||||
int r;
|
||||
|
||||
assert(template);
|
||||
assert(ret);
|
||||
|
||||
p = strdup(template);
|
||||
if (template)
|
||||
p = strdup(template);
|
||||
else {
|
||||
const char *tmp;
|
||||
|
||||
r = tmp_dir(&tmp);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
p = strjoin(tmp, "/XXXXXX");
|
||||
}
|
||||
if (!p)
|
||||
return -ENOMEM;
|
||||
|
||||
if (!mkdtemp(p)) {
|
||||
free(p);
|
||||
if (!mkdtemp(p))
|
||||
return -errno;
|
||||
}
|
||||
|
||||
*ret = p;
|
||||
*ret = TAKE_PTR(p);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,12 +1,6 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
#pragma once
|
||||
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
Copyright 2010 Lennart Poettering
|
||||
***/
|
||||
|
||||
#include <dirent.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
|
@ -17,12 +11,12 @@
|
|||
#include "time-util.h"
|
||||
|
||||
typedef enum {
|
||||
WRITE_STRING_FILE_CREATE = 1<<0,
|
||||
WRITE_STRING_FILE_ATOMIC = 1<<1,
|
||||
WRITE_STRING_FILE_AVOID_NEWLINE = 1<<2,
|
||||
WRITE_STRING_FILE_VERIFY_ON_FAILURE = 1<<3,
|
||||
WRITE_STRING_FILE_SYNC = 1<<4,
|
||||
WRITE_STRING_FILE_DISABLE_BUFFER = 1<<5,
|
||||
WRITE_STRING_FILE_CREATE = 1 << 0,
|
||||
WRITE_STRING_FILE_ATOMIC = 1 << 1,
|
||||
WRITE_STRING_FILE_AVOID_NEWLINE = 1 << 2,
|
||||
WRITE_STRING_FILE_VERIFY_ON_FAILURE = 1 << 3,
|
||||
WRITE_STRING_FILE_SYNC = 1 << 4,
|
||||
WRITE_STRING_FILE_DISABLE_BUFFER = 1 << 5,
|
||||
|
||||
/* And before you wonder, why write_string_file_atomic_label_ts() is a separate function instead of just one
|
||||
more flag here: it's about linking: we don't want to pull -lselinux into all users of write_string_file()
|
||||
|
@ -39,13 +33,16 @@ static inline int write_string_file(const char *fn, const char *line, WriteStrin
|
|||
return write_string_file_ts(fn, line, flags, NULL);
|
||||
}
|
||||
|
||||
int write_string_filef(const char *fn, WriteStringFileFlags flags, const char *format, ...) _printf_(3, 4);
|
||||
|
||||
int read_one_line_file(const char *fn, char **line);
|
||||
int read_full_file(const char *fn, char **contents, size_t *size);
|
||||
int read_full_stream(FILE *f, char **contents, size_t *size);
|
||||
|
||||
int verify_file(const char *fn, const char *blob, bool accept_extra_nl);
|
||||
|
||||
int parse_env_file(const char *fname, const char *separator, ...) _sentinel_;
|
||||
int parse_env_filev(FILE *f, const char *fname, const char *separator, va_list ap);
|
||||
int parse_env_file(FILE *f, const char *fname, const char *separator, ...) _sentinel_;
|
||||
int load_env_file(FILE *f, const char *fname, const char *separator, char ***l);
|
||||
int load_env_file_pairs(FILE *f, const char *fname, const char *separator, char ***l);
|
||||
|
||||
|
|
|
@ -1,9 +1,4 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
Copyright 2010 Lennart Poettering
|
||||
***/
|
||||
|
||||
#include <errno.h>
|
||||
#include <stddef.h>
|
||||
|
@ -230,6 +225,22 @@ int chmod_and_chown(const char *path, mode_t mode, uid_t uid, gid_t gid) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int fchmod_and_chown(int fd, mode_t mode, uid_t uid, gid_t gid) {
|
||||
/* Under the assumption that we are running privileged we
|
||||
* first change the access mode and only then hand out
|
||||
* ownership to avoid a window where access is too open. */
|
||||
|
||||
if (mode != MODE_INVALID)
|
||||
if (fchmod(fd, mode) < 0)
|
||||
return -errno;
|
||||
|
||||
if (uid != UID_INVALID || gid != GID_INVALID)
|
||||
if (fchown(fd, uid, gid) < 0)
|
||||
return -errno;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int fchmod_umask(int fd, mode_t m) {
|
||||
mode_t u;
|
||||
int r;
|
||||
|
@ -242,7 +253,7 @@ int fchmod_umask(int fd, mode_t m) {
|
|||
}
|
||||
|
||||
int fchmod_opath(int fd, mode_t m) {
|
||||
char procfs_path[strlen("/proc/self/fd/") + DECIMAL_STR_MAX(int)];
|
||||
char procfs_path[STRLEN("/proc/self/fd/") + DECIMAL_STR_MAX(int)];
|
||||
|
||||
/* This function operates also on fd that might have been opened with
|
||||
* O_PATH. Indeed fchmodat() doesn't have the AT_EMPTY_PATH flag like
|
||||
|
@ -602,10 +613,10 @@ int chase_symlinks(const char *path, const char *original_root, unsigned flags,
|
|||
assert(path);
|
||||
|
||||
/* Either the file may be missing, or we return an fd to the final object, but both make no sense */
|
||||
if ((flags & (CHASE_NONEXISTENT|CHASE_OPEN)) == (CHASE_NONEXISTENT|CHASE_OPEN))
|
||||
if (FLAGS_SET(flags, CHASE_NONEXISTENT | CHASE_OPEN))
|
||||
return -EINVAL;
|
||||
|
||||
if ((flags & (CHASE_STEP|CHASE_OPEN)) == (CHASE_STEP|CHASE_OPEN))
|
||||
if (FLAGS_SET(flags, CHASE_STEP | CHASE_OPEN))
|
||||
return -EINVAL;
|
||||
|
||||
if (isempty(path))
|
||||
|
@ -1066,6 +1077,15 @@ int access_fd(int fd, int mode) {
|
|||
return r;
|
||||
}
|
||||
|
||||
void unlink_tempfilep(char (*p)[]) {
|
||||
/* If the file is created with mkstemp(), it will (almost always)
|
||||
* change the suffix. Treat this as a sign that the file was
|
||||
* successfully created. We ignore both the rare case where the
|
||||
* original suffix is used and unlink failures. */
|
||||
if (!endswith(*p, ".XXXXXX"))
|
||||
(void) unlink_noerrno(*p);
|
||||
}
|
||||
|
||||
int unlinkat_deallocate(int fd, const char *name, int flags) {
|
||||
_cleanup_close_ int truncate_fd = -1;
|
||||
struct stat st;
|
||||
|
@ -1146,9 +1166,9 @@ int fsync_directory_of_file(int fd) {
|
|||
|
||||
r = fd_get_path(fd, &path);
|
||||
if (r < 0) {
|
||||
log_debug("Failed to query /proc/self/fd/%d%s: %m",
|
||||
fd,
|
||||
r == -EOPNOTSUPP ? ", ignoring" : "");
|
||||
log_debug_errno(r, "Failed to query /proc/self/fd/%d%s: %m",
|
||||
fd,
|
||||
r == -EOPNOTSUPP ? ", ignoring" : "");
|
||||
|
||||
if (r == -EOPNOTSUPP)
|
||||
/* If /proc is not available, we're most likely running in some
|
||||
|
|
|
@ -1,12 +1,6 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
#pragma once
|
||||
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
Copyright 2010 Lennart Poettering
|
||||
***/
|
||||
|
||||
#include <dirent.h>
|
||||
#include <fcntl.h>
|
||||
#include <limits.h>
|
||||
|
@ -31,6 +25,7 @@ int readlink_value(const char *p, char **ret);
|
|||
int readlink_and_make_absolute(const char *p, char **r);
|
||||
|
||||
int chmod_and_chown(const char *path, mode_t mode, uid_t uid, gid_t gid);
|
||||
int fchmod_and_chown(int fd, mode_t mode, uid_t uid, gid_t gid);
|
||||
|
||||
int fchmod_umask(int fd, mode_t mode);
|
||||
int fchmod_opath(int fd, mode_t m);
|
||||
|
@ -70,13 +65,13 @@ union inotify_event_buffer {
|
|||
int inotify_add_watch_fd(int fd, int what, uint32_t mask);
|
||||
|
||||
enum {
|
||||
CHASE_PREFIX_ROOT = 1U << 0, /* If set, the specified path will be prefixed by the specified root before beginning the iteration */
|
||||
CHASE_NONEXISTENT = 1U << 1, /* If set, it's OK if the path doesn't actually exist. */
|
||||
CHASE_NO_AUTOFS = 1U << 2, /* If set, return -EREMOTE if autofs mount point found */
|
||||
CHASE_SAFE = 1U << 3, /* If set, return EPERM if we ever traverse from unprivileged to privileged files or directories */
|
||||
CHASE_OPEN = 1U << 4, /* If set, return an O_PATH object to the final component */
|
||||
CHASE_TRAIL_SLASH = 1U << 5, /* If set, any trailing slash will be preserved */
|
||||
CHASE_STEP = 1U << 6, /* If set, just execute a single step of the normalization */
|
||||
CHASE_PREFIX_ROOT = 1 << 0, /* If set, the specified path will be prefixed by the specified root before beginning the iteration */
|
||||
CHASE_NONEXISTENT = 1 << 1, /* If set, it's OK if the path doesn't actually exist. */
|
||||
CHASE_NO_AUTOFS = 1 << 2, /* If set, return -EREMOTE if autofs mount point found */
|
||||
CHASE_SAFE = 1 << 3, /* If set, return EPERM if we ever traverse from unprivileged to privileged files or directories */
|
||||
CHASE_OPEN = 1 << 4, /* If set, return an O_PATH object to the final component */
|
||||
CHASE_TRAIL_SLASH = 1 << 5, /* If set, any trailing slash will be preserved */
|
||||
CHASE_STEP = 1 << 6, /* If set, just execute a single step of the normalization */
|
||||
};
|
||||
|
||||
/* How many iterations to execute before returning -ELOOP */
|
||||
|
@ -104,6 +99,7 @@ DEFINE_TRIVIAL_CLEANUP_FUNC(char*, unlink_and_free);
|
|||
|
||||
int access_fd(int fd, int mode);
|
||||
|
||||
void unlink_tempfilep(char (*p)[]);
|
||||
int unlinkat_deallocate(int fd, const char *name, int flags);
|
||||
|
||||
int fsync_directory_of_file(int fd);
|
||||
|
|
|
@ -1,9 +1,6 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
Copyright 2010 Lennart Poettering
|
||||
Copyright 2014 Michal Schmidt
|
||||
Copyright © 2014 Michal Schmidt
|
||||
***/
|
||||
|
||||
#include <string.h>
|
||||
|
|
|
@ -2,10 +2,7 @@
|
|||
#pragma once
|
||||
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
Copyright 2010 Lennart Poettering
|
||||
Copyright 2014 Michal Schmidt
|
||||
Copyright © 2014 Michal Schmidt
|
||||
***/
|
||||
|
||||
#include "macro.h"
|
||||
|
|
|
@ -1,9 +1,6 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
Copyright 2010 Lennart Poettering
|
||||
Copyright 2014 Michal Schmidt
|
||||
Copyright © 2014 Michal Schmidt
|
||||
***/
|
||||
|
||||
#include <errno.h>
|
||||
|
|
|
@ -2,10 +2,7 @@
|
|||
#pragma once
|
||||
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
Copyright 2010 Lennart Poettering
|
||||
Copyright 2014 Michal Schmidt
|
||||
Copyright © 2014 Michal Schmidt
|
||||
***/
|
||||
|
||||
#include <limits.h>
|
||||
|
|
|
@ -1,9 +1,4 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
Copyright 2010 Lennart Poettering
|
||||
***/
|
||||
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
|
|
|
@ -1,12 +1,6 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
#pragma once
|
||||
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
Copyright 2010 Lennart Poettering
|
||||
***/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
|
|
|
@ -1,9 +1,4 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
Copyright 2015 Lennart Poettering
|
||||
***/
|
||||
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
|
|
|
@ -1,12 +1,6 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
#pragma once
|
||||
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
Copyright 2010-2015 Lennart Poettering
|
||||
***/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
|
||||
|
|
|
@ -1,9 +1,4 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
Copyright 2014 Lennart Poettering
|
||||
***/
|
||||
|
||||
#include <arpa/inet.h>
|
||||
#include <endian.h>
|
||||
|
|
|
@ -1,12 +1,6 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
#pragma once
|
||||
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
Copyright 2014 Lennart Poettering
|
||||
***/
|
||||
|
||||
#include <netinet/in.h>
|
||||
#include <stddef.h>
|
||||
#include <sys/socket.h>
|
||||
|
|
|
@ -1,9 +1,4 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
Copyright 2010 Lennart Poettering
|
||||
***/
|
||||
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
|
|
|
@ -1,12 +1,6 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
#pragma once
|
||||
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
Copyright 2010 Lennart Poettering
|
||||
***/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
|
|
@ -1,12 +1,6 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
#pragma once
|
||||
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
Copyright 2010 Lennart Poettering
|
||||
***/
|
||||
|
||||
/* The head of the linked list. Use this in the structure that shall
|
||||
* contain the head of the linked list */
|
||||
#define LIST_HEAD(t,name) \
|
||||
|
|
|
@ -1,12 +1,6 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
#pragma once
|
||||
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
Copyright 2010 Lennart Poettering
|
||||
***/
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
|
@ -245,7 +239,7 @@ int log_emergency_level(void);
|
|||
/* Structured logging */
|
||||
#define log_struct_errno(level, error, ...) \
|
||||
log_struct_internal(LOG_REALM_PLUS_LEVEL(LOG_REALM, level), \
|
||||
error, __FILE__, __LINE__, __func__, __VA_ARGS__)
|
||||
error, __FILE__, __LINE__, __func__, __VA_ARGS__, NULL)
|
||||
#define log_struct(level, ...) log_struct_errno(level, 0, __VA_ARGS__)
|
||||
|
||||
#define log_struct_iovec_errno(level, error, iovec, n_iovec) \
|
||||
|
@ -284,6 +278,8 @@ void log_set_open_when_needed(bool b);
|
|||
* stderr, the console or kmsg */
|
||||
void log_set_prohibit_ipc(bool b);
|
||||
|
||||
int log_dup_console(void);
|
||||
|
||||
int log_syntax_internal(
|
||||
const char *unit,
|
||||
int level,
|
||||
|
|
|
@ -1,12 +1,6 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
#pragma once
|
||||
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
Copyright 2010 Lennart Poettering
|
||||
***/
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <stdbool.h>
|
||||
#include <sys/param.h>
|
||||
|
@ -357,6 +351,8 @@ static inline unsigned long ALIGN_POWER2(unsigned long u) {
|
|||
|
||||
#define SET_FLAG(v, flag, b) \
|
||||
(v) = (b) ? ((v) | (flag)) : ((v) & ~(flag))
|
||||
#define FLAGS_SET(v, flags) \
|
||||
(((v) & (flags)) == (flags))
|
||||
|
||||
#define CASE_F(X) case X:
|
||||
#define CASE_F_1(CASE, X) CASE_F(X)
|
||||
|
|
|
@ -1,9 +1,6 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
Copyright 2010-2014 Lennart Poettering
|
||||
Copyright 2014 Michal Schmidt
|
||||
Copyright © 2014 Michal Schmidt
|
||||
***/
|
||||
|
||||
#include <stdint.h>
|
||||
|
|
|
@ -2,10 +2,7 @@
|
|||
#pragma once
|
||||
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
Copyright 2011-2014 Lennart Poettering
|
||||
Copyright 2014 Michal Schmidt
|
||||
Copyright © 2014 Michal Schmidt
|
||||
***/
|
||||
|
||||
#include <stddef.h>
|
||||
|
@ -29,7 +26,6 @@ static struct mempool pool_name = { \
|
|||
.at_least = alloc_at_least, \
|
||||
}
|
||||
|
||||
|
||||
#if VALGRIND
|
||||
void mempool_drop(struct mempool *mp);
|
||||
#endif
|
||||
|
|
|
@ -1,9 +1,4 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
Copyright 2010 Lennart Poettering
|
||||
***/
|
||||
|
||||
#include <errno.h>
|
||||
#include <inttypes.h>
|
||||
|
@ -632,6 +627,58 @@ int parse_percent(const char *p) {
|
|||
return v;
|
||||
}
|
||||
|
||||
int parse_permille_unbounded(const char *p) {
|
||||
const char *pc, *pm, *dot, *n;
|
||||
int r, q, v;
|
||||
|
||||
pm = endswith(p, "‰");
|
||||
if (pm) {
|
||||
n = strndupa(p, pm - p);
|
||||
r = safe_atoi(n, &v);
|
||||
if (r < 0)
|
||||
return r;
|
||||
} else {
|
||||
pc = endswith(p, "%");
|
||||
if (!pc)
|
||||
return -EINVAL;
|
||||
|
||||
dot = memchr(p, '.', pc - p);
|
||||
if (dot) {
|
||||
if (dot + 2 != pc)
|
||||
return -EINVAL;
|
||||
if (dot[1] < '0' || dot[1] > '9')
|
||||
return -EINVAL;
|
||||
q = dot[1] - '0';
|
||||
n = strndupa(p, dot - p);
|
||||
} else {
|
||||
q = 0;
|
||||
n = strndupa(p, pc - p);
|
||||
}
|
||||
r = safe_atoi(n, &v);
|
||||
if (r < 0)
|
||||
return r;
|
||||
if (v > (INT_MAX - q) / 10)
|
||||
return -ERANGE;
|
||||
|
||||
v = v * 10 + q;
|
||||
}
|
||||
|
||||
if (v < 0)
|
||||
return -ERANGE;
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
int parse_permille(const char *p) {
|
||||
int v;
|
||||
|
||||
v = parse_permille_unbounded(p);
|
||||
if (v > 1000)
|
||||
return -ERANGE;
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
int parse_nice(const char *p, int *ret) {
|
||||
int n, r;
|
||||
|
||||
|
|
|
@ -1,12 +1,6 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
#pragma once
|
||||
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
Copyright 2010 Lennart Poettering
|
||||
***/
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <limits.h>
|
||||
#include <stddef.h>
|
||||
|
@ -115,6 +109,9 @@ int parse_fractional_part_u(const char **s, size_t digits, unsigned *res);
|
|||
int parse_percent_unbounded(const char *p);
|
||||
int parse_percent(const char *p);
|
||||
|
||||
int parse_permille_unbounded(const char *p);
|
||||
int parse_permille(const char *p);
|
||||
|
||||
int parse_nice(const char *p, int *ret);
|
||||
|
||||
int parse_ip_port(const char *s, uint16_t *ret);
|
||||
|
|
|
@ -1,9 +1,4 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
Copyright 2010-2012 Lennart Poettering
|
||||
***/
|
||||
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
|
@ -32,6 +27,7 @@
|
|||
#include "string-util.h"
|
||||
#include "strv.h"
|
||||
#include "time-util.h"
|
||||
#include "utf8.h"
|
||||
|
||||
bool path_is_absolute(const char *p) {
|
||||
return p[0] == '/';
|
||||
|
@ -127,8 +123,8 @@ 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 *r, *p;
|
||||
unsigned n_parents;
|
||||
char *f, *t, *r, *p;
|
||||
unsigned n_parents = 0;
|
||||
|
||||
assert(from_dir);
|
||||
assert(to_path);
|
||||
|
@ -136,85 +132,81 @@ int path_make_relative(const char *from_dir, const char *to_path, char **_r) {
|
|||
|
||||
/* Strips the common part, and adds ".." elements as necessary. */
|
||||
|
||||
if (!path_is_absolute(from_dir))
|
||||
if (!path_is_absolute(from_dir) || !path_is_absolute(to_path))
|
||||
return -EINVAL;
|
||||
|
||||
if (!path_is_absolute(to_path))
|
||||
return -EINVAL;
|
||||
f = strdupa(from_dir);
|
||||
t = strdupa(to_path);
|
||||
|
||||
path_simplify(f, true);
|
||||
path_simplify(t, true);
|
||||
|
||||
/* Skip the common part. */
|
||||
for (;;) {
|
||||
size_t a, b;
|
||||
|
||||
from_dir += strspn(from_dir, "/");
|
||||
to_path += strspn(to_path, "/");
|
||||
f += *f == '/';
|
||||
t += *t == '/';
|
||||
|
||||
if (!*from_dir) {
|
||||
if (!*to_path)
|
||||
if (!*f) {
|
||||
if (!*t)
|
||||
/* from_dir equals to_path. */
|
||||
r = strdup(".");
|
||||
else
|
||||
/* from_dir is a parent directory of to_path. */
|
||||
r = strdup(to_path);
|
||||
r = strdup(t);
|
||||
if (!r)
|
||||
return -ENOMEM;
|
||||
|
||||
path_kill_slashes(r);
|
||||
|
||||
*_r = r;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!*to_path)
|
||||
if (!*t)
|
||||
break;
|
||||
|
||||
a = strcspn(from_dir, "/");
|
||||
b = strcspn(to_path, "/");
|
||||
a = strcspn(f, "/");
|
||||
b = strcspn(t, "/");
|
||||
|
||||
if (a != b)
|
||||
if (a != b || memcmp(f, t, a) != 0)
|
||||
break;
|
||||
|
||||
if (memcmp(from_dir, to_path, a) != 0)
|
||||
break;
|
||||
|
||||
from_dir += a;
|
||||
to_path += b;
|
||||
f += a;
|
||||
t += b;
|
||||
}
|
||||
|
||||
/* If we're here, then "from_dir" has one or more elements that need to
|
||||
* be replaced with "..". */
|
||||
|
||||
/* Count the number of necessary ".." elements. */
|
||||
for (n_parents = 0;;) {
|
||||
for (; *f;) {
|
||||
size_t w;
|
||||
|
||||
from_dir += strspn(from_dir, "/");
|
||||
|
||||
if (!*from_dir)
|
||||
break;
|
||||
|
||||
w = strcspn(from_dir, "/");
|
||||
w = strcspn(f, "/");
|
||||
|
||||
/* If this includes ".." we can't do a simple series of "..", refuse */
|
||||
if (w == 2 && from_dir[0] == '.' && from_dir[1] == '.')
|
||||
if (w == 2 && f[0] == '.' && f[1] == '.')
|
||||
return -EINVAL;
|
||||
|
||||
/* Count number of elements, except if they are "." */
|
||||
if (w != 1 || from_dir[0] != '.')
|
||||
n_parents++;
|
||||
/* Count number of elements */
|
||||
n_parents++;
|
||||
|
||||
from_dir += w;
|
||||
f += w;
|
||||
f += *f == '/';
|
||||
}
|
||||
|
||||
r = new(char, n_parents * 3 + strlen(to_path) + 1);
|
||||
r = new(char, n_parents * 3 + strlen(t) + 1);
|
||||
if (!r)
|
||||
return -ENOMEM;
|
||||
|
||||
for (p = r; n_parents > 0; n_parents--)
|
||||
p = mempcpy(p, "../", 3);
|
||||
|
||||
strcpy(p, to_path);
|
||||
path_kill_slashes(r);
|
||||
if (*t)
|
||||
strcpy(p, t);
|
||||
else
|
||||
/* Remove trailing slash */
|
||||
*(--p) = 0;
|
||||
|
||||
*_r = r;
|
||||
return 0;
|
||||
|
@ -235,7 +227,7 @@ int path_strv_make_absolute_cwd(char **l) {
|
|||
if (r < 0)
|
||||
return r;
|
||||
|
||||
path_kill_slashes(t);
|
||||
path_simplify(t, false);
|
||||
free_and_replace(*s, t);
|
||||
}
|
||||
|
||||
|
@ -335,17 +327,30 @@ char **path_strv_resolve_uniq(char **l, const char *root) {
|
|||
return strv_uniq(l);
|
||||
}
|
||||
|
||||
char *path_kill_slashes(char *path) {
|
||||
char *path_simplify(char *path, bool kill_dots) {
|
||||
char *f, *t;
|
||||
bool slash = false;
|
||||
bool slash = false, ignore_slash = false, absolute;
|
||||
|
||||
/* Removes redundant inner and trailing slashes. Modifies the
|
||||
* passed string in-place.
|
||||
assert(path);
|
||||
|
||||
/* Removes redundant inner and trailing slashes. Also removes unnecessary dots
|
||||
* if kill_dots is true. Modifies the passed string in-place.
|
||||
*
|
||||
* ///foo///bar/ becomes /foo/bar
|
||||
* ///foo//./bar/. becomes /foo/./bar/. (if kill_dots is false)
|
||||
* ///foo//./bar/. becomes /foo/bar (if kill_dots is true)
|
||||
* .//./foo//./bar/. becomes ./foo/bar (if kill_dots is false)
|
||||
* .//./foo//./bar/. becomes foo/bar (if kill_dots is true)
|
||||
*/
|
||||
|
||||
for (f = path, t = path; *f; f++) {
|
||||
absolute = path_is_absolute(path);
|
||||
|
||||
f = path;
|
||||
if (kill_dots && *f == '.' && IN_SET(f[1], 0, '/')) {
|
||||
ignore_slash = true;
|
||||
f++;
|
||||
}
|
||||
|
||||
for (t = path; *f; f++) {
|
||||
|
||||
if (*f == '/') {
|
||||
slash = true;
|
||||
|
@ -353,17 +358,21 @@ char *path_kill_slashes(char *path) {
|
|||
}
|
||||
|
||||
if (slash) {
|
||||
if (kill_dots && *f == '.' && IN_SET(f[1], 0, '/'))
|
||||
continue;
|
||||
|
||||
slash = false;
|
||||
*(t++) = '/';
|
||||
if (ignore_slash)
|
||||
ignore_slash = false;
|
||||
else
|
||||
*(t++) = '/';
|
||||
}
|
||||
|
||||
*(t++) = *f;
|
||||
}
|
||||
|
||||
/* Special rule, if we are talking of the root directory, a
|
||||
trailing slash is good */
|
||||
|
||||
if (t == path && slash)
|
||||
/* Special rule, if we are talking of the root directory, a trailing slash is good */
|
||||
if (absolute && t == path)
|
||||
*(t++) = '/';
|
||||
|
||||
*t = 0;
|
||||
|
@ -530,7 +539,7 @@ int find_binary(const char *name, char **ret) {
|
|||
/* Found it! */
|
||||
|
||||
if (ret) {
|
||||
*ret = path_kill_slashes(j);
|
||||
*ret = path_simplify(j, false);
|
||||
j = NULL;
|
||||
}
|
||||
|
||||
|
@ -684,12 +693,11 @@ int parse_path_argument_and_warn(const char *path, bool suppress_root, char **ar
|
|||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to parse path \"%s\" and make it absolute: %m", path);
|
||||
|
||||
path_kill_slashes(p);
|
||||
path_simplify(p, false);
|
||||
if (suppress_root && empty_or_root(p))
|
||||
p = mfree(p);
|
||||
|
||||
free(*arg);
|
||||
*arg = p;
|
||||
free_and_replace(*arg, p);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -873,17 +881,36 @@ bool hidden_or_backup_file(const char *filename) {
|
|||
|
||||
bool is_device_path(const char *path) {
|
||||
|
||||
/* Returns true on paths that refer to a device, either in
|
||||
* sysfs or in /dev */
|
||||
/* Returns true on paths that likely refer to a device, either by path in sysfs or to something in /dev */
|
||||
|
||||
return path_startswith(path, "/dev/") ||
|
||||
path_startswith(path, "/sys/");
|
||||
return PATH_STARTSWITH_SET(path, "/dev/", "/sys/");
|
||||
}
|
||||
|
||||
bool is_deviceallow_pattern(const char *path) {
|
||||
return path_startswith(path, "/dev/") ||
|
||||
startswith(path, "block-") ||
|
||||
startswith(path, "char-");
|
||||
bool valid_device_node_path(const char *path) {
|
||||
|
||||
/* Some superficial checks whether the specified path is a valid device node path, all without looking at the
|
||||
* actual device node. */
|
||||
|
||||
if (!PATH_STARTSWITH_SET(path, "/dev/", "/run/systemd/inaccessible/"))
|
||||
return false;
|
||||
|
||||
if (endswith(path, "/")) /* can't be a device node if it ends in a slash */
|
||||
return false;
|
||||
|
||||
return path_is_normalized(path);
|
||||
}
|
||||
|
||||
bool valid_device_allow_pattern(const char *path) {
|
||||
assert(path);
|
||||
|
||||
/* Like valid_device_node_path(), but also allows full-subsystem expressions, like DeviceAllow= and DeviceDeny=
|
||||
* accept it */
|
||||
|
||||
if (startswith(path, "block-") ||
|
||||
startswith(path, "char-"))
|
||||
return true;
|
||||
|
||||
return valid_device_node_path(path);
|
||||
}
|
||||
|
||||
int systemd_installation_has_version(const char *root, unsigned minimal_version) {
|
||||
|
@ -919,7 +946,7 @@ int systemd_installation_has_version(const char *root, unsigned minimal_version)
|
|||
if (r < 0)
|
||||
return r;
|
||||
|
||||
assert_se((c = endswith(path, "*.so")));
|
||||
assert_se(c = endswith(path, "*.so"));
|
||||
*c = '\0'; /* truncate the glob part */
|
||||
|
||||
STRV_FOREACH(name, names) {
|
||||
|
@ -977,3 +1004,50 @@ bool empty_or_root(const char *root) {
|
|||
|
||||
return root[strspn(root, "/")] == 0;
|
||||
}
|
||||
|
||||
int path_simplify_and_warn(
|
||||
char *path,
|
||||
unsigned flag,
|
||||
const char *unit,
|
||||
const char *filename,
|
||||
unsigned line,
|
||||
const char *lvalue) {
|
||||
|
||||
bool absolute, fatal = flag & PATH_CHECK_FATAL;
|
||||
|
||||
assert(!FLAGS_SET(flag, PATH_CHECK_ABSOLUTE | PATH_CHECK_RELATIVE));
|
||||
|
||||
if (!utf8_is_valid(path)) {
|
||||
log_syntax_invalid_utf8(unit, LOG_ERR, filename, line, path);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (flag & (PATH_CHECK_ABSOLUTE | PATH_CHECK_RELATIVE)) {
|
||||
absolute = path_is_absolute(path);
|
||||
|
||||
if (!absolute && (flag & PATH_CHECK_ABSOLUTE)) {
|
||||
log_syntax(unit, LOG_ERR, filename, line, 0,
|
||||
"%s= path is not absolute%s: %s",
|
||||
lvalue, fatal ? "" : ", ignoring", path);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (absolute && (flag & PATH_CHECK_RELATIVE)) {
|
||||
log_syntax(unit, LOG_ERR, filename, line, 0,
|
||||
"%s= path is absolute%s: %s",
|
||||
lvalue, fatal ? "" : ", ignoring", path);
|
||||
return -EINVAL;
|
||||
}
|
||||
}
|
||||
|
||||
path_simplify(path, true);
|
||||
|
||||
if (!path_is_normalized(path)) {
|
||||
log_syntax(unit, LOG_ERR, filename, line, 0,
|
||||
"%s= path is not normalized%s: %s",
|
||||
lvalue, fatal ? "" : ", ignoring", path);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -1,12 +1,6 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
#pragma once
|
||||
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
Copyright 2010-2012 Lennart Poettering
|
||||
***/
|
||||
|
||||
#include <alloca.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
|
@ -50,12 +44,12 @@ char* path_make_absolute(const char *p, const char *prefix);
|
|||
int safe_getcwd(char **ret);
|
||||
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_;
|
||||
int path_compare(const char *a, const char *b) _pure_;
|
||||
bool path_equal(const char *a, const char *b) _pure_;
|
||||
bool path_equal_or_files_same(const char *a, const char *b, int flags);
|
||||
char* path_join(const char *root, const char *path, const char *rest);
|
||||
char* path_simplify(char *path, bool kill_dots);
|
||||
|
||||
static inline bool path_equal_ptr(const char *a, const char *b) {
|
||||
return !!a == !!b && (!a || path_equal(a, b));
|
||||
|
@ -101,11 +95,11 @@ int mkfs_exists(const char *fstype);
|
|||
* the tree, to root. Also returns "" (and not "/"!) for the root
|
||||
* directory. Excludes the specified directory itself */
|
||||
#define PATH_FOREACH_PREFIX(prefix, path) \
|
||||
for (char *_slash = ({ path_kill_slashes(strcpy(prefix, path)); streq(prefix, "/") ? NULL : strrchr(prefix, '/'); }); _slash && ((*_slash = 0), true); _slash = strrchr((prefix), '/'))
|
||||
for (char *_slash = ({ path_simplify(strcpy(prefix, path), false); streq(prefix, "/") ? NULL : strrchr(prefix, '/'); }); _slash && ((*_slash = 0), true); _slash = strrchr((prefix), '/'))
|
||||
|
||||
/* Same as PATH_FOREACH_PREFIX but also includes the specified path itself */
|
||||
#define PATH_FOREACH_PREFIX_MORE(prefix, path) \
|
||||
for (char *_slash = ({ path_kill_slashes(strcpy(prefix, path)); if (streq(prefix, "/")) prefix[0] = 0; strrchr(prefix, 0); }); _slash && ((*_slash = 0), true); _slash = strrchr((prefix), '/'))
|
||||
for (char *_slash = ({ path_simplify(strcpy(prefix, path), false); if (streq(prefix, "/")) prefix[0] = 0; strrchr(prefix, 0); }); _slash && ((*_slash = 0), true); _slash = strrchr((prefix), '/'))
|
||||
|
||||
char *prefix_root(const char *root, const char *path);
|
||||
|
||||
|
@ -147,7 +141,9 @@ char *file_in_same_dir(const char *path, const char *filename);
|
|||
bool hidden_or_backup_file(const char *filename) _pure_;
|
||||
|
||||
bool is_device_path(const char *path);
|
||||
bool is_deviceallow_pattern(const char *path);
|
||||
|
||||
bool valid_device_node_path(const char *path);
|
||||
bool valid_device_allow_pattern(const char *path);
|
||||
|
||||
int systemd_installation_has_version(const char *root, unsigned minimal_version);
|
||||
|
||||
|
@ -167,3 +163,11 @@ bool empty_or_root(const char *root);
|
|||
static inline const char *empty_to_root(const char *path) {
|
||||
return isempty(path) ? "/" : path;
|
||||
}
|
||||
|
||||
enum {
|
||||
PATH_CHECK_FATAL = 1 << 0, /* If not set, then error message is appended with 'ignoring'. */
|
||||
PATH_CHECK_ABSOLUTE = 1 << 1,
|
||||
PATH_CHECK_RELATIVE = 1 << 2,
|
||||
};
|
||||
|
||||
int path_simplify_and_warn(char *path, unsigned flag, const char *unit, const char *filename, unsigned line, const char *lvalue);
|
||||
|
|
|
@ -1,9 +1,4 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
Copyright 2013 Lennart Poettering
|
||||
***/
|
||||
|
||||
/*
|
||||
* Priority Queue
|
||||
|
|
|
@ -1,12 +1,6 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
#pragma once
|
||||
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
Copyright 2013 Lennart Poettering
|
||||
***/
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "hashmap.h"
|
||||
|
|
|
@ -1,9 +1,4 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
Copyright 2010 Lennart Poettering
|
||||
***/
|
||||
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
|
@ -17,6 +12,7 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/mount.h>
|
||||
#include <sys/personality.h>
|
||||
#include <sys/prctl.h>
|
||||
#include <sys/types.h>
|
||||
|
@ -75,20 +71,31 @@ int get_process_state(pid_t pid) {
|
|||
return (unsigned char) state;
|
||||
}
|
||||
|
||||
int get_process_comm(pid_t pid, char **name) {
|
||||
int get_process_comm(pid_t pid, char **ret) {
|
||||
_cleanup_free_ char *escaped = NULL, *comm = NULL;
|
||||
const char *p;
|
||||
int r;
|
||||
|
||||
assert(name);
|
||||
assert(ret);
|
||||
assert(pid >= 0);
|
||||
|
||||
escaped = new(char, TASK_COMM_LEN);
|
||||
if (!escaped)
|
||||
return -ENOMEM;
|
||||
|
||||
p = procfs_file_alloca(pid, "comm");
|
||||
|
||||
r = read_one_line_file(p, name);
|
||||
r = read_one_line_file(p, &comm);
|
||||
if (r == -ENOENT)
|
||||
return -ESRCH;
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
return r;
|
||||
/* Escape unprintable characters, just in case, but don't grow the string beyond the underlying size */
|
||||
cellescape(escaped, TASK_COMM_LEN, comm);
|
||||
|
||||
*ret = TAKE_PTR(escaped);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int get_process_cmdline(pid_t pid, size_t max_length, bool comm_fallback, char **line) {
|
||||
|
@ -246,15 +253,10 @@ int get_process_cmdline(pid_t pid, size_t max_length, bool comm_fallback, char *
|
|||
memcpy(ans, "[...]", max_length-1);
|
||||
ans[max_length-1] = 0;
|
||||
} else {
|
||||
char *e;
|
||||
|
||||
t[max_length - 6] = 0;
|
||||
|
||||
/* Chop off final spaces */
|
||||
e = strchr(t, 0);
|
||||
while (e > t && isspace(e[-1]))
|
||||
e--;
|
||||
*e = 0;
|
||||
delete_trailing_chars(t, WHITESPACE);
|
||||
|
||||
ans = strjoin("[", t, "...]");
|
||||
}
|
||||
|
@ -295,7 +297,7 @@ int rename_process(const char name[]) {
|
|||
* can use PR_SET_NAME, which sets the thread name for the calling thread. */
|
||||
if (prctl(PR_SET_NAME, name) < 0)
|
||||
log_debug_errno(errno, "PR_SET_NAME failed: %m");
|
||||
if (l > 15) /* Linux process names can be 15 chars at max */
|
||||
if (l >= TASK_COMM_LEN) /* Linux process names can be 15 chars at max */
|
||||
truncated = true;
|
||||
|
||||
/* Second step, change glibc's ID of the process name. */
|
||||
|
@ -739,14 +741,17 @@ int wait_for_terminate_and_check(const char *name, pid_t pid, WaitFlags flags) {
|
|||
|
||||
/*
|
||||
* Return values:
|
||||
* < 0 : wait_for_terminate_with_timeout() failed to get the state of the
|
||||
* process, the process timed out, the process was terminated by a
|
||||
* signal, or failed for an unknown reason.
|
||||
*
|
||||
* < 0 : wait_for_terminate_with_timeout() failed to get the state of the process, the process timed out, the process
|
||||
* was terminated by a signal, or failed for an unknown reason.
|
||||
*
|
||||
* >=0 : The process terminated normally with no failures.
|
||||
*
|
||||
* Success is indicated by a return value of zero, a timeout is indicated
|
||||
* by ETIMEDOUT, and all other child failure states are indicated by error
|
||||
* is indicated by a non-zero value.
|
||||
* Success is indicated by a return value of zero, a timeout is indicated by ETIMEDOUT, and all other child failure
|
||||
* states are indicated by error is indicated by a non-zero value.
|
||||
*
|
||||
* This call assumes SIGCHLD has been blocked already, in particular before the child to wait for has been forked off
|
||||
* to remain entirely race-free.
|
||||
*/
|
||||
int wait_for_terminate_with_timeout(pid_t pid, usec_t timeout) {
|
||||
sigset_t mask;
|
||||
|
@ -1344,6 +1349,16 @@ int safe_fork_full(
|
|||
}
|
||||
}
|
||||
|
||||
if (FLAGS_SET(flags, FORK_NEW_MOUNTNS | FORK_MOUNTNS_SLAVE)) {
|
||||
|
||||
/* Optionally, make sure we never propagate mounts to the host. */
|
||||
|
||||
if (mount(NULL, "/", NULL, MS_SLAVE | MS_REC, NULL) < 0) {
|
||||
log_full_errno(prio, errno, "Failed to remount root directory as MS_SLAVE: %m");
|
||||
_exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
if (flags & FORK_CLOSE_ALL_FDS) {
|
||||
/* Close the logs here in case it got reopened above, as close_all_fds() would close them for us */
|
||||
log_close();
|
||||
|
|
|
@ -1,12 +1,6 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
#pragma once
|
||||
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
Copyright 2010 Lennart Poettering
|
||||
***/
|
||||
|
||||
#include <alloca.h>
|
||||
#include <errno.h>
|
||||
#include <sched.h>
|
||||
|
@ -51,8 +45,8 @@ int get_process_ppid(pid_t pid, pid_t *ppid);
|
|||
int wait_for_terminate(pid_t pid, siginfo_t *status);
|
||||
|
||||
typedef enum WaitFlags {
|
||||
WAIT_LOG_ABNORMAL = 1U << 0,
|
||||
WAIT_LOG_NON_ZERO_EXIT_STATUS = 1U << 1,
|
||||
WAIT_LOG_ABNORMAL = 1 << 0,
|
||||
WAIT_LOG_NON_ZERO_EXIT_STATUS = 1 << 1,
|
||||
|
||||
/* A shortcut for requesting the most complete logging */
|
||||
WAIT_LOG = WAIT_LOG_ABNORMAL|WAIT_LOG_NON_ZERO_EXIT_STATUS,
|
||||
|
@ -155,14 +149,15 @@ void reset_cached_pid(void);
|
|||
int must_be_root(void);
|
||||
|
||||
typedef enum ForkFlags {
|
||||
FORK_RESET_SIGNALS = 1U << 0,
|
||||
FORK_CLOSE_ALL_FDS = 1U << 1,
|
||||
FORK_DEATHSIG = 1U << 2,
|
||||
FORK_NULL_STDIO = 1U << 3,
|
||||
FORK_REOPEN_LOG = 1U << 4,
|
||||
FORK_LOG = 1U << 5,
|
||||
FORK_WAIT = 1U << 6,
|
||||
FORK_NEW_MOUNTNS = 1U << 7,
|
||||
FORK_RESET_SIGNALS = 1 << 0,
|
||||
FORK_CLOSE_ALL_FDS = 1 << 1,
|
||||
FORK_DEATHSIG = 1 << 2,
|
||||
FORK_NULL_STDIO = 1 << 3,
|
||||
FORK_REOPEN_LOG = 1 << 4,
|
||||
FORK_LOG = 1 << 5,
|
||||
FORK_WAIT = 1 << 6,
|
||||
FORK_NEW_MOUNTNS = 1 << 7,
|
||||
FORK_MOUNTNS_SLAVE = 1 << 8,
|
||||
} ForkFlags;
|
||||
|
||||
int safe_fork_full(const char *name, const int except_fds[], size_t n_except_fds, ForkFlags flags, pid_t *ret_pid);
|
||||
|
|
|
@ -1,9 +1,4 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
Copyright 2010 Lennart Poettering
|
||||
***/
|
||||
|
||||
#include <elf.h>
|
||||
#include <errno.h>
|
||||
|
@ -46,7 +41,7 @@ int acquire_random_bytes(void *p, size_t n, bool high_quality_required) {
|
|||
* for us. */
|
||||
|
||||
/* Use the getrandom() syscall unless we know we don't have it. */
|
||||
if (have_syscall != 0) {
|
||||
if (have_syscall != 0 && !HAS_FEATURE_MEMORY_SANITIZER) {
|
||||
r = getrandom(p, n, GRND_NONBLOCK);
|
||||
if (r > 0) {
|
||||
have_syscall = true;
|
||||
|
|
|
@ -1,12 +1,6 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
#pragma once
|
||||
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
Copyright 2010 Lennart Poettering
|
||||
***/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
|
|
@ -1,12 +1,6 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
#pragma once
|
||||
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
Copyright 2013 Lennart Poettering
|
||||
***/
|
||||
|
||||
/* A type-safe atomic refcounter.
|
||||
*
|
||||
* DO NOT USE THIS UNLESS YOU ACTUALLY CARE ABOUT THREAD SAFETY! */
|
||||
|
|
|
@ -1,12 +1,6 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
#pragma once
|
||||
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
Copyright 2010 Lennart Poettering
|
||||
***/
|
||||
|
||||
#include "extract-word.h"
|
||||
#include "hashmap.h"
|
||||
#include "macro.h"
|
||||
|
|
|
@ -1,12 +1,6 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
#pragma once
|
||||
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
Copyright 2010-2015 Lennart Poettering
|
||||
***/
|
||||
|
||||
#include <signal.h>
|
||||
|
||||
#include "macro.h"
|
||||
|
|
|
@ -1,9 +1,4 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
Copyright 2010 Lennart Poettering
|
||||
***/
|
||||
|
||||
#include <arpa/inet.h>
|
||||
#include <errno.h>
|
||||
|
@ -790,7 +785,7 @@ static const char* const socket_address_bind_ipv6_only_table[_SOCKET_ADDRESS_BIN
|
|||
|
||||
DEFINE_STRING_TABLE_LOOKUP(socket_address_bind_ipv6_only, SocketAddressBindIPv6Only);
|
||||
|
||||
SocketAddressBindIPv6Only parse_socket_address_bind_ipv6_only_or_bool(const char *n) {
|
||||
SocketAddressBindIPv6Only socket_address_bind_ipv6_only_or_bool_from_string(const char *n) {
|
||||
int r;
|
||||
|
||||
r = parse_boolean(n);
|
||||
|
|
|
@ -1,12 +1,6 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
#pragma once
|
||||
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
Copyright 2010 Lennart Poettering
|
||||
***/
|
||||
|
||||
#include <netinet/ether.h>
|
||||
#include <netinet/in.h>
|
||||
#include <stdbool.h>
|
||||
|
@ -116,7 +110,7 @@ int socknameinfo_pretty(union sockaddr_union *sa, socklen_t salen, char **_ret);
|
|||
|
||||
const char* socket_address_bind_ipv6_only_to_string(SocketAddressBindIPv6Only b) _const_;
|
||||
SocketAddressBindIPv6Only socket_address_bind_ipv6_only_from_string(const char *s) _pure_;
|
||||
SocketAddressBindIPv6Only parse_socket_address_bind_ipv6_only_or_bool(const char *s);
|
||||
SocketAddressBindIPv6Only socket_address_bind_ipv6_only_or_bool_from_string(const char *s);
|
||||
|
||||
int netlink_family_to_string_alloc(int b, char **s);
|
||||
int netlink_family_from_string(const char *s) _pure_;
|
||||
|
|
|
@ -1,9 +1,4 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
Copyright 2010-2012 Lennart Poettering
|
||||
***/
|
||||
|
||||
#include <dirent.h>
|
||||
#include <errno.h>
|
||||
|
@ -132,32 +127,6 @@ int path_is_read_only_fs(const char *path) {
|
|||
return false;
|
||||
}
|
||||
|
||||
int path_is_os_tree(const char *path) {
|
||||
int r;
|
||||
|
||||
assert(path);
|
||||
|
||||
/* Does the path exist at all? If not, generate an error immediately. This is useful so that a missing root dir
|
||||
* always results in -ENOENT, and we can properly distuingish the case where the whole root doesn't exist from
|
||||
* the case where just the os-release file is missing. */
|
||||
if (laccess(path, F_OK) < 0)
|
||||
return -errno;
|
||||
|
||||
/* We use /usr/lib/os-release as flag file if something is an OS */
|
||||
r = chase_symlinks("/usr/lib/os-release", path, CHASE_PREFIX_ROOT, NULL);
|
||||
if (r == -ENOENT) {
|
||||
|
||||
/* Also check for the old location in /etc, just in case. */
|
||||
r = chase_symlinks("/etc/os-release", path, CHASE_PREFIX_ROOT, NULL);
|
||||
if (r == -ENOENT)
|
||||
return 0; /* We got nothing */
|
||||
}
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int files_same(const char *filea, const char *fileb, int flags) {
|
||||
struct stat a, b;
|
||||
|
||||
|
|
|
@ -1,12 +1,6 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
#pragma once
|
||||
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
Copyright 2010-2012 Lennart Poettering
|
||||
***/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <sys/stat.h>
|
||||
|
@ -35,7 +29,6 @@ int null_or_empty_path(const char *fn);
|
|||
int null_or_empty_fd(int fd);
|
||||
|
||||
int path_is_read_only_fs(const char *path);
|
||||
int path_is_os_tree(const char *path);
|
||||
|
||||
int files_same(const char *filea, const char *fileb, int flags);
|
||||
|
||||
|
|
|
@ -1,12 +1,6 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
#pragma once
|
||||
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
Copyright 2010 Lennart Poettering
|
||||
***/
|
||||
|
||||
#include <printf.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
|
|
|
@ -1,9 +1,4 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
Copyright 2010 Lennart Poettering
|
||||
***/
|
||||
|
||||
#include "string-table.h"
|
||||
#include "string-util.h"
|
||||
|
|
|
@ -2,12 +2,6 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
Copyright 2010 Lennart Poettering
|
||||
***/
|
||||
|
||||
#include <errno.h>
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
|
@ -77,7 +71,6 @@ ssize_t string_table_lookup(const char * const *table, size_t len, const char *k
|
|||
return (type) -1; \
|
||||
} \
|
||||
|
||||
|
||||
#define _DEFINE_STRING_TABLE_LOOKUP(name,type,scope) \
|
||||
_DEFINE_STRING_TABLE_LOOKUP_TO_STRING(name,type,scope) \
|
||||
_DEFINE_STRING_TABLE_LOOKUP_FROM_STRING(name,type,scope)
|
||||
|
@ -102,3 +95,18 @@ ssize_t string_table_lookup(const char * const *table, size_t len, const char *k
|
|||
_DEFINE_STRING_TABLE_LOOKUP_TO_STRING_FALLBACK(name,type,max,static)
|
||||
#define DEFINE_PRIVATE_STRING_TABLE_LOOKUP_FROM_STRING_FALLBACK(name,type,max) \
|
||||
_DEFINE_STRING_TABLE_LOOKUP_FROM_STRING_FALLBACK(name,type,max,static)
|
||||
|
||||
#define DUMP_STRING_TABLE(name,type,max) \
|
||||
do { \
|
||||
type _k; \
|
||||
flockfile(stdout); \
|
||||
for (_k = 0; _k < (max); _k++) { \
|
||||
const char *_t; \
|
||||
_t = name##_to_string(_k); \
|
||||
if (!_t) \
|
||||
continue; \
|
||||
fputs_unlocked(_t, stdout); \
|
||||
fputc_unlocked('\n', stdout); \
|
||||
} \
|
||||
funlockfile(stdout); \
|
||||
} while(false)
|
||||
|
|
|
@ -1,9 +1,4 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
Copyright 2010 Lennart Poettering
|
||||
***/
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdarg.h>
|
||||
|
@ -14,6 +9,7 @@
|
|||
#include <string.h>
|
||||
|
||||
#include "alloc-util.h"
|
||||
#include "escape.h"
|
||||
#include "gunicode.h"
|
||||
#include "locale-util.h"
|
||||
#include "macro.h"
|
||||
|
@ -268,23 +264,12 @@ char *strjoin_real(const char *x, ...) {
|
|||
}
|
||||
|
||||
char *strstrip(char *s) {
|
||||
char *e;
|
||||
|
||||
if (!s)
|
||||
return NULL;
|
||||
|
||||
/* Drops trailing whitespace. Modifies the string in
|
||||
* place. Returns pointer to first non-space character */
|
||||
/* 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;
|
||||
return delete_trailing_chars(skip_leading_chars(s, WHITESPACE), WHITESPACE);
|
||||
}
|
||||
|
||||
char *delete_chars(char *s, const char *bad) {
|
||||
|
@ -453,9 +438,23 @@ bool string_has_cc(const char *p, const char *ok) {
|
|||
return false;
|
||||
}
|
||||
|
||||
static int write_ellipsis(char *buf, bool unicode) {
|
||||
if (unicode || is_locale_utf8()) {
|
||||
buf[0] = 0xe2; /* tri-dot ellipsis: … */
|
||||
buf[1] = 0x80;
|
||||
buf[2] = 0xa6;
|
||||
} else {
|
||||
buf[0] = '.';
|
||||
buf[1] = '.';
|
||||
buf[2] = '.';
|
||||
}
|
||||
|
||||
return 3;
|
||||
}
|
||||
|
||||
static char *ascii_ellipsize_mem(const char *s, size_t old_length, size_t new_length, unsigned percent) {
|
||||
size_t x, need_space;
|
||||
char *r;
|
||||
size_t x, need_space, suffix_len;
|
||||
char *t;
|
||||
|
||||
assert(s);
|
||||
assert(percent <= 100);
|
||||
|
@ -491,8 +490,8 @@ static char *ascii_ellipsize_mem(const char *s, size_t old_length, size_t new_le
|
|||
* either for the UTF-8 encoded character or for three ASCII characters. */
|
||||
need_space = is_locale_utf8() ? 1 : 3;
|
||||
|
||||
r = new(char, new_length+3);
|
||||
if (!r)
|
||||
t = new(char, new_length+3);
|
||||
if (!t)
|
||||
return NULL;
|
||||
|
||||
assert(new_length >= need_space);
|
||||
|
@ -500,23 +499,13 @@ static char *ascii_ellipsize_mem(const char *s, size_t old_length, size_t new_le
|
|||
x = ((new_length - need_space) * percent + 50) / 100;
|
||||
assert(x <= new_length - need_space);
|
||||
|
||||
memcpy(r, s, x);
|
||||
memcpy(t, s, x);
|
||||
write_ellipsis(t + x, false);
|
||||
suffix_len = new_length - x - need_space;
|
||||
memcpy(t + x + 3, s + old_length - suffix_len, suffix_len);
|
||||
*(t + x + 3 + suffix_len) = '\0';
|
||||
|
||||
if (is_locale_utf8()) {
|
||||
r[x+0] = 0xe2; /* tri-dot ellipsis: … */
|
||||
r[x+1] = 0x80;
|
||||
r[x+2] = 0xa6;
|
||||
} else {
|
||||
r[x+0] = '.';
|
||||
r[x+1] = '.';
|
||||
r[x+2] = '.';
|
||||
}
|
||||
|
||||
memcpy(r + x + 3,
|
||||
s + old_length - (new_length - x - need_space),
|
||||
new_length - x - need_space + 1);
|
||||
|
||||
return r;
|
||||
return t;
|
||||
}
|
||||
|
||||
char *ellipsize_mem(const char *s, size_t old_length, size_t new_length, unsigned percent) {
|
||||
|
@ -547,42 +536,56 @@ char *ellipsize_mem(const char *s, size_t old_length, size_t new_length, unsigne
|
|||
return strdup("");
|
||||
|
||||
/* If no multibyte characters use ascii_ellipsize_mem for speed */
|
||||
if (ascii_is_valid(s))
|
||||
if (ascii_is_valid_n(s, old_length))
|
||||
return ascii_ellipsize_mem(s, old_length, new_length, percent);
|
||||
|
||||
x = ((new_length - 1) * percent) / 100;
|
||||
assert(x <= new_length - 1);
|
||||
|
||||
k = 0;
|
||||
for (i = s; k < x && i < s + old_length; i = utf8_next_char(i)) {
|
||||
for (i = s; i < s + old_length; i = utf8_next_char(i)) {
|
||||
char32_t c;
|
||||
int w;
|
||||
|
||||
r = utf8_encoded_to_unichar(i, &c);
|
||||
if (r < 0)
|
||||
return NULL;
|
||||
k += unichar_iswide(c) ? 2 : 1;
|
||||
|
||||
w = unichar_iswide(c) ? 2 : 1;
|
||||
if (k + w <= x)
|
||||
k += w;
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
if (k > x) /* last character was wide and went over quota */
|
||||
x++;
|
||||
|
||||
for (j = s + old_length; k < new_length && j > i; ) {
|
||||
for (j = s + old_length; j > i; ) {
|
||||
char32_t c;
|
||||
int w;
|
||||
const char *jj;
|
||||
|
||||
j = utf8_prev_char(j);
|
||||
r = utf8_encoded_to_unichar(j, &c);
|
||||
jj = utf8_prev_char(j);
|
||||
r = utf8_encoded_to_unichar(jj, &c);
|
||||
if (r < 0)
|
||||
return NULL;
|
||||
k += unichar_iswide(c) ? 2 : 1;
|
||||
|
||||
w = unichar_iswide(c) ? 2 : 1;
|
||||
if (k + w <= new_length) {
|
||||
k += w;
|
||||
j = jj;
|
||||
} else
|
||||
break;
|
||||
}
|
||||
assert(i <= j);
|
||||
|
||||
/* we don't actually need to ellipsize */
|
||||
if (i == j)
|
||||
return memdup(s, old_length + 1);
|
||||
return memdup_suffix0(s, old_length);
|
||||
|
||||
/* make space for ellipsis */
|
||||
j = utf8_next_char(j);
|
||||
/* make space for ellipsis, if possible */
|
||||
if (j < s + old_length)
|
||||
j = utf8_next_char(j);
|
||||
else if (i > s)
|
||||
i = utf8_prev_char(i);
|
||||
|
||||
len = i - s;
|
||||
len2 = s + old_length - j;
|
||||
|
@ -596,21 +599,81 @@ char *ellipsize_mem(const char *s, size_t old_length, size_t new_length, unsigne
|
|||
*/
|
||||
|
||||
memcpy(e, s, len);
|
||||
e[len + 0] = 0xe2; /* tri-dot ellipsis: … */
|
||||
e[len + 1] = 0x80;
|
||||
e[len + 2] = 0xa6;
|
||||
|
||||
memcpy(e + len + 3, j, len2 + 1);
|
||||
write_ellipsis(e + len, true);
|
||||
memcpy(e + len + 3, j, len2);
|
||||
*(e + len + 3 + len2) = '\0';
|
||||
|
||||
return e;
|
||||
}
|
||||
|
||||
char *ellipsize(const char *s, size_t length, unsigned percent) {
|
||||
char *cellescape(char *buf, size_t len, const char *s) {
|
||||
/* Escape and ellipsize s into buffer buf of size len. Only non-control ASCII
|
||||
* characters are copied as they are, everything else is escaped. The result
|
||||
* is different then if escaping and ellipsization was performed in two
|
||||
* separate steps, because each sequence is either stored in full or skipped.
|
||||
*
|
||||
* This function should be used for logging about strings which expected to
|
||||
* be plain ASCII in a safe way.
|
||||
*
|
||||
* An ellipsis will be used if s is too long. It was always placed at the
|
||||
* very end.
|
||||
*/
|
||||
|
||||
if (length == (size_t) -1)
|
||||
return strdup(s);
|
||||
size_t i = 0, last_char_width[4] = {}, k = 0, j;
|
||||
|
||||
return ellipsize_mem(s, strlen(s), length, percent);
|
||||
assert(len > 0); /* at least a terminating NUL */
|
||||
|
||||
for (;;) {
|
||||
char four[4];
|
||||
int w;
|
||||
|
||||
if (*s == 0) /* terminating NUL detected? then we are done! */
|
||||
goto done;
|
||||
|
||||
w = cescape_char(*s, four);
|
||||
if (i + w + 1 > len) /* This character doesn't fit into the buffer anymore? In that case let's
|
||||
* ellipsize at the previous location */
|
||||
break;
|
||||
|
||||
/* OK, there was space, let's add this escaped character to the buffer */
|
||||
memcpy(buf + i, four, w);
|
||||
i += w;
|
||||
|
||||
/* And remember its width in the ring buffer */
|
||||
last_char_width[k] = w;
|
||||
k = (k + 1) % 4;
|
||||
|
||||
s++;
|
||||
}
|
||||
|
||||
/* Ellipsation is necessary. This means we might need to truncate the string again to make space for 4
|
||||
* characters ideally, but the buffer is shorter than that in the first place take what we can get */
|
||||
for (j = 0; j < ELEMENTSOF(last_char_width); j++) {
|
||||
|
||||
if (i + 4 <= len) /* nice, we reached our space goal */
|
||||
break;
|
||||
|
||||
k = k == 0 ? 3 : k - 1;
|
||||
if (last_char_width[k] == 0) /* bummer, we reached the beginning of the strings */
|
||||
break;
|
||||
|
||||
assert(i >= last_char_width[k]);
|
||||
i -= last_char_width[k];
|
||||
}
|
||||
|
||||
if (i + 4 <= len) /* yay, enough space */
|
||||
i += write_ellipsis(buf + i, false);
|
||||
else if (i + 3 <= len) { /* only space for ".." */
|
||||
buf[i++] = '.';
|
||||
buf[i++] = '.';
|
||||
} else if (i + 2 <= len) /* only space for a single "." */
|
||||
buf[i++] = '.';
|
||||
else
|
||||
assert(i + 1 <= len);
|
||||
|
||||
done:
|
||||
buf[i] = '\0';
|
||||
return buf;
|
||||
}
|
||||
|
||||
bool nulstr_contains(const char *nulstr, const char *needle) {
|
||||
|
|
|
@ -1,12 +1,6 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
#pragma once
|
||||
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
Copyright 2010 Lennart Poettering
|
||||
***/
|
||||
|
||||
#include <alloca.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
|
@ -156,7 +150,14 @@ static inline bool _pure_ in_charset(const char *s, const char* charset) {
|
|||
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);
|
||||
static inline char *ellipsize(const char *s, size_t length, unsigned percent) {
|
||||
return ellipsize_mem(s, strlen(s), length, percent);
|
||||
}
|
||||
|
||||
char *cellescape(char *buf, size_t len, const char *s);
|
||||
|
||||
/* This limit is arbitrary, enough to give some idea what the string contains */
|
||||
#define CELLESCAPE_DEFAULT_LENGTH 64
|
||||
|
||||
bool nulstr_contains(const char *nulstr, const char *needle);
|
||||
|
||||
|
@ -209,3 +210,21 @@ static inline size_t strlen_ptr(const char *s) {
|
|||
|
||||
return strlen(s);
|
||||
}
|
||||
|
||||
/* Like startswith(), but operates on arbitrary memory blocks */
|
||||
static inline void *memory_startswith(const void *p, size_t sz, const char *token) {
|
||||
size_t n;
|
||||
|
||||
assert(token);
|
||||
|
||||
n = strlen(token);
|
||||
if (sz < n)
|
||||
return NULL;
|
||||
|
||||
assert(p);
|
||||
|
||||
if (memcmp(p, token, n) != 0)
|
||||
return NULL;
|
||||
|
||||
return (uint8_t*) p + n;
|
||||
}
|
||||
|
|
|
@ -1,9 +1,4 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
Copyright 2010 Lennart Poettering
|
||||
***/
|
||||
|
||||
#include <errno.h>
|
||||
#include <fnmatch.h>
|
||||
|
|
|
@ -1,12 +1,6 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
#pragma once
|
||||
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
Copyright 2010 Lennart Poettering
|
||||
***/
|
||||
|
||||
#include <fnmatch.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
|
|
|
@ -1,9 +1,4 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
Copyright 2010 Lennart Poettering
|
||||
***/
|
||||
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
|
@ -282,8 +277,11 @@ static char *format_timestamp_internal(
|
|||
return NULL; /* Timestamp is unset */
|
||||
|
||||
/* Let's not format times with years > 9999 */
|
||||
if (t > USEC_TIMESTAMP_FORMATTABLE_MAX)
|
||||
return NULL;
|
||||
if (t > USEC_TIMESTAMP_FORMATTABLE_MAX) {
|
||||
assert(l >= strlen("--- XXXX-XX-XX XX:XX:XX") + 1);
|
||||
strcpy(buf, "--- XXXX-XX-XX XX:XX:XX");
|
||||
return buf;
|
||||
}
|
||||
|
||||
sec = (time_t) (t / USEC_PER_SEC); /* Round down */
|
||||
|
||||
|
@ -481,7 +479,7 @@ char *format_timespan(char *buf, size_t l, usec_t t, usec_t accuracy) {
|
|||
/* Let's see if we should shows this in dot notation */
|
||||
if (t < USEC_PER_MINUTE && b > 0) {
|
||||
usec_t cc;
|
||||
int j;
|
||||
signed char j;
|
||||
|
||||
j = 0;
|
||||
for (cc = table[i].usec; cc > 1; cc /= 10)
|
||||
|
@ -1308,6 +1306,9 @@ bool timezone_is_valid(const char *name, int log_level) {
|
|||
if (slash)
|
||||
return false;
|
||||
|
||||
if (p - name >= PATH_MAX)
|
||||
return false;
|
||||
|
||||
t = strjoina("/usr/share/zoneinfo/", name);
|
||||
|
||||
fd = open(t, O_RDONLY|O_CLOEXEC);
|
||||
|
@ -1460,3 +1461,27 @@ bool in_utc_timezone(void) {
|
|||
|
||||
return timezone == 0 && daylight == 0;
|
||||
}
|
||||
|
||||
int time_change_fd(void) {
|
||||
|
||||
/* We only care for the cancellation event, hence we set the timeout to the latest possible value. */
|
||||
static const struct itimerspec its = {
|
||||
.it_value.tv_sec = TIME_T_MAX,
|
||||
};
|
||||
|
||||
_cleanup_close_ int fd;
|
||||
|
||||
assert_cc(sizeof(time_t) == sizeof(TIME_T_MAX));
|
||||
|
||||
/* Uses TFD_TIMER_CANCEL_ON_SET to get notifications whenever CLOCK_REALTIME makes a jump relative to
|
||||
* CLOCK_MONOTONIC. */
|
||||
|
||||
fd = timerfd_create(CLOCK_REALTIME, TFD_NONBLOCK|TFD_CLOEXEC);
|
||||
if (fd < 0)
|
||||
return -errno;
|
||||
|
||||
if (timerfd_settime(fd, TFD_TIMER_ABSTIME|TFD_TIMER_CANCEL_ON_SET, &its, NULL) < 0)
|
||||
return -errno;
|
||||
|
||||
return TAKE_FD(fd);
|
||||
}
|
||||
|
|
|
@ -1,12 +1,6 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
#pragma once
|
||||
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
Copyright 2010 Lennart Poettering
|
||||
***/
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
|
@ -183,5 +177,7 @@ static inline usec_t usec_sub_signed(usec_t timestamp, int64_t delta) {
|
|||
/* With a 32bit time_t we can't go beyond 2038... */
|
||||
#define USEC_TIMESTAMP_FORMATTABLE_MAX ((usec_t) 2147483647000000)
|
||||
#else
|
||||
#error "Yuck, time_t is neither 4 not 8 bytes wide?"
|
||||
#error "Yuck, time_t is neither 4 nor 8 bytes wide?"
|
||||
#endif
|
||||
|
||||
int time_change_fd(void);
|
||||
|
|
|
@ -1,12 +1,6 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
#pragma once
|
||||
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
Copyright 2010 Lennart Poettering
|
||||
***/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
|
|
|
@ -1,9 +1,6 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
Copyright 2008-2011 Kay Sievers
|
||||
Copyright 2012 Lennart Poettering
|
||||
Copyright © 2008-2011 Kay Sievers
|
||||
***/
|
||||
|
||||
/* Parts of this file are based on the GLIB utf8 validation functions. The
|
||||
|
@ -247,6 +244,9 @@ char *utf8_escape_non_printable(const char *str) {
|
|||
char *ascii_is_valid(const char *str) {
|
||||
const char *p;
|
||||
|
||||
/* Check whether the string consists of valid ASCII bytes,
|
||||
* i.e values between 0 and 127, inclusive. */
|
||||
|
||||
assert(str);
|
||||
|
||||
for (p = str; *p; p++)
|
||||
|
@ -256,6 +256,21 @@ char *ascii_is_valid(const char *str) {
|
|||
return (char*) str;
|
||||
}
|
||||
|
||||
char *ascii_is_valid_n(const char *str, size_t len) {
|
||||
size_t i;
|
||||
|
||||
/* Very similar to ascii_is_valid(), but checks exactly len
|
||||
* bytes and rejects any NULs in that range. */
|
||||
|
||||
assert(str);
|
||||
|
||||
for (i = 0; i < len; i++)
|
||||
if ((unsigned char) str[i] >= 128 || str[i] == 0)
|
||||
return NULL;
|
||||
|
||||
return (char*) str;
|
||||
}
|
||||
|
||||
/**
|
||||
* utf8_encode_unichar() - Encode single UCS-4 character as UTF-8
|
||||
* @out_utf8: output buffer of at least 4 bytes or NULL
|
||||
|
|
|
@ -1,12 +1,6 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
#pragma once
|
||||
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
Copyright 2012 Lennart Poettering
|
||||
***/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
@ -22,6 +16,7 @@ bool unichar_is_valid(char32_t c);
|
|||
|
||||
const char *utf8_is_valid(const char *s) _pure_;
|
||||
char *ascii_is_valid(const char *s) _pure_;
|
||||
char *ascii_is_valid_n(const char *str, size_t len);
|
||||
|
||||
bool utf8_is_printable_newline(const char* str, size_t length, bool newline) _pure_;
|
||||
#define utf8_is_printable(str, length) utf8_is_printable_newline(str, length, true)
|
||||
|
|
|
@ -1,9 +1,4 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
Copyright 2010 Lennart Poettering
|
||||
***/
|
||||
|
||||
#include <alloca.h>
|
||||
#include <errno.h>
|
||||
|
@ -264,7 +259,7 @@ int container_get_leader(const char *machine, pid_t *pid) {
|
|||
return -EINVAL;
|
||||
|
||||
p = strjoina("/run/systemd/machines/", machine);
|
||||
r = parse_env_file(p, NEWLINE, "LEADER", &s, "CLASS", &class, NULL);
|
||||
r = parse_env_file(NULL, p, NEWLINE, "LEADER", &s, "CLASS", &class, NULL);
|
||||
if (r == -ENOENT)
|
||||
return -EHOSTDOWN;
|
||||
if (r < 0)
|
||||
|
@ -405,6 +400,7 @@ uint64_t physical_memory(void) {
|
|||
uint64_t mem, lim;
|
||||
size_t ps;
|
||||
long sc;
|
||||
int r;
|
||||
|
||||
/* We return this as uint64_t in case we are running as 32bit process on a 64bit kernel with huge amounts of
|
||||
* memory.
|
||||
|
@ -418,13 +414,40 @@ uint64_t physical_memory(void) {
|
|||
ps = page_size();
|
||||
mem = (uint64_t) sc * (uint64_t) ps;
|
||||
|
||||
if (cg_get_root_path(&root) < 0)
|
||||
r = cg_get_root_path(&root);
|
||||
if (r < 0) {
|
||||
log_debug_errno(r, "Failed to determine root cgroup, ignoring cgroup memory limit: %m");
|
||||
return mem;
|
||||
}
|
||||
|
||||
if (cg_get_attribute("memory", root, "memory.limit_in_bytes", &value))
|
||||
r = cg_all_unified();
|
||||
if (r < 0) {
|
||||
log_debug_errno(r, "Failed to determine root unified mode, ignoring cgroup memory limit: %m");
|
||||
return mem;
|
||||
}
|
||||
if (r > 0) {
|
||||
r = cg_get_attribute("memory", root, "memory.max", &value);
|
||||
if (r < 0) {
|
||||
log_debug_errno(r, "Failed to read memory.max cgroup attribute, ignoring cgroup memory limit: %m");
|
||||
return mem;
|
||||
}
|
||||
|
||||
if (safe_atou64(value, &lim) < 0)
|
||||
if (streq(value, "max"))
|
||||
return mem;
|
||||
} else {
|
||||
r = cg_get_attribute("memory", root, "memory.limit_in_bytes", &value);
|
||||
if (r < 0) {
|
||||
log_debug_errno(r, "Failed to read memory.limit_in_bytes cgroup attribute, ignoring cgroup memory limit: %m");
|
||||
return mem;
|
||||
}
|
||||
}
|
||||
|
||||
r = safe_atou64(value, &lim);
|
||||
if (r < 0) {
|
||||
log_debug_errno(r, "Failed to parse cgroup memory limit '%s', ignoring: %m", value);
|
||||
return mem;
|
||||
}
|
||||
if (lim == UINT64_MAX)
|
||||
return mem;
|
||||
|
||||
/* Make sure the limit is a multiple of our own page size */
|
||||
|
@ -465,6 +488,7 @@ uint64_t system_tasks_max(void) {
|
|||
|
||||
uint64_t a = TASKS_MAX, b = TASKS_MAX;
|
||||
_cleanup_free_ char *root = NULL;
|
||||
int r;
|
||||
|
||||
/* Determine the maximum number of tasks that may run on this system. We check three sources to determine this
|
||||
* limit:
|
||||
|
@ -475,13 +499,24 @@ uint64_t system_tasks_max(void) {
|
|||
*
|
||||
* And then pick the smallest of the three */
|
||||
|
||||
(void) procfs_tasks_get_limit(&a);
|
||||
r = procfs_tasks_get_limit(&a);
|
||||
if (r < 0)
|
||||
log_debug_errno(r, "Failed to read maximum number of tasks from /proc, ignoring: %m");
|
||||
|
||||
if (cg_get_root_path(&root) >= 0) {
|
||||
r = cg_get_root_path(&root);
|
||||
if (r < 0)
|
||||
log_debug_errno(r, "Failed to determine cgroup root path, ignoring: %m");
|
||||
else {
|
||||
_cleanup_free_ char *value = NULL;
|
||||
|
||||
if (cg_get_attribute("pids", root, "pids.max", &value) >= 0)
|
||||
(void) safe_atou64(value, &b);
|
||||
r = cg_get_attribute("pids", root, "pids.max", &value);
|
||||
if (r < 0)
|
||||
log_debug_errno(r, "Failed to read pids.max attribute of cgroup root, ignoring: %m");
|
||||
else if (!streq(value, "max")) {
|
||||
r = safe_atou64(value, &b);
|
||||
if (r < 0)
|
||||
log_debug_errno(r, "Failed to parse pids.max attribute of cgroup root, ignoring: %m");
|
||||
}
|
||||
}
|
||||
|
||||
return MIN3(TASKS_MAX,
|
||||
|
|
|
@ -1,12 +1,6 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
#pragma once
|
||||
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
Copyright 2010 Lennart Poettering
|
||||
***/
|
||||
|
||||
#include <alloca.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
Copyright (C) 2014 Axis Communications AB. All rights reserved.
|
||||
Copyright (C) 2015 Tom Gundersen
|
||||
Copyright © 2014 Axis Communications AB. All rights reserved.
|
||||
Copyright © 2015 Tom Gundersen
|
||||
***/
|
||||
|
||||
#include <linux/filter.h>
|
||||
|
|
|
@ -2,9 +2,7 @@
|
|||
#pragma once
|
||||
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
Copyright (C) 2014 Axis Communications AB. All rights reserved.
|
||||
Copyright © 2014 Axis Communications AB. All rights reserved.
|
||||
***/
|
||||
|
||||
#include <netinet/if_ether.h>
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
Copyright (C) 2015 Tom Gundersen <teg@jklmen>
|
||||
Copyright © 2015 Tom Gundersen <teg@jklmen>
|
||||
***/
|
||||
|
||||
#include "libudev.h"
|
||||
|
|
|
@ -2,9 +2,7 @@
|
|||
#pragma once
|
||||
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
Copyright (C) 2015 Tom Gundersen <teg@jklmen>
|
||||
Copyright © 2015 Tom Gundersen <teg@jklmen>
|
||||
***/
|
||||
|
||||
#include "sd-id128.h"
|
||||
|
|
|
@ -2,10 +2,8 @@
|
|||
#pragma once
|
||||
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
Copyright (C) 2013 Intel Corporation. All rights reserved.
|
||||
Copyright (C) 2014 Tom Gundersen
|
||||
Copyright © 2013 Intel Corporation. All rights reserved.
|
||||
Copyright © 2014 Tom Gundersen
|
||||
***/
|
||||
|
||||
#include <linux/if_packet.h>
|
||||
|
|
|
@ -2,10 +2,8 @@
|
|||
#pragma once
|
||||
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
Copyright (C) 2013 Intel Corporation. All rights reserved.
|
||||
Copyright (C) 2014 Tom Gundersen
|
||||
Copyright © 2013 Intel Corporation. All rights reserved.
|
||||
Copyright © 2014 Tom Gundersen
|
||||
***/
|
||||
|
||||
#include <stdint.h>
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
Copyright (C) 2013 Intel Corporation. All rights reserved.
|
||||
Copyright © 2013 Intel Corporation. All rights reserved.
|
||||
***/
|
||||
|
||||
#include <errno.h>
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
Copyright (C) 2013 Intel Corporation. All rights reserved.
|
||||
Copyright © 2013 Intel Corporation. All rights reserved.
|
||||
***/
|
||||
|
||||
#include <errno.h>
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
Copyright (C) 2013 Intel Corporation. All rights reserved.
|
||||
Copyright (C) 2014 Tom Gundersen
|
||||
Copyright © 2013 Intel Corporation. All rights reserved.
|
||||
Copyright © 2014 Tom Gundersen
|
||||
***/
|
||||
|
||||
#include <errno.h>
|
||||
|
|
|
@ -2,9 +2,7 @@
|
|||
#pragma once
|
||||
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
Copyright (C) 2013 Intel Corporation. All rights reserved.
|
||||
Copyright © 2013 Intel Corporation. All rights reserved.
|
||||
***/
|
||||
|
||||
#include <netinet/ip.h>
|
||||
|
|
|
@ -2,9 +2,7 @@
|
|||
#pragma once
|
||||
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
Copyright (C) 2014-2015 Intel Corporation. All rights reserved.
|
||||
Copyright © 2014-2015 Intel Corporation. All rights reserved.
|
||||
***/
|
||||
|
||||
#include <net/ethernet.h>
|
||||
|
|
|
@ -2,10 +2,8 @@
|
|||
#pragma once
|
||||
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
Copyright (C) 2014 Tom Gundersen
|
||||
Copyright (C) 2014-2015 Intel Corporation. All rights reserved.
|
||||
Copyright © 2014 Tom Gundersen
|
||||
Copyright © 2014-2015 Intel Corporation. All rights reserved.
|
||||
***/
|
||||
|
||||
#include <stdint.h>
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
Copyright (C) 2014 Intel Corporation. All rights reserved.
|
||||
Copyright © 2014 Intel Corporation. All rights reserved.
|
||||
***/
|
||||
|
||||
#include <errno.h>
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
Copyright (C) 2014-2015 Intel Corporation. All rights reserved.
|
||||
Copyright © 2014-2015 Intel Corporation. All rights reserved.
|
||||
***/
|
||||
|
||||
#include <errno.h>
|
||||
|
@ -141,7 +139,7 @@ int dhcp6_option_append_ia(uint8_t **buf, size_t *buflen, DHCP6IA *ia) {
|
|||
}
|
||||
|
||||
int dhcp6_option_append_fqdn(uint8_t **buf, size_t *buflen, const char *fqdn) {
|
||||
uint8_t buffer[1 + DNS_WIRE_FOMAT_HOSTNAME_MAX];
|
||||
uint8_t buffer[1 + DNS_WIRE_FORMAT_HOSTNAME_MAX];
|
||||
int r;
|
||||
|
||||
assert_return(buf && *buf && buflen && fqdn, -EINVAL);
|
||||
|
|
|
@ -2,9 +2,7 @@
|
|||
#pragma once
|
||||
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
Copyright (C) 2014 Intel Corporation. All rights reserved.
|
||||
Copyright © 2014 Intel Corporation. All rights reserved.
|
||||
***/
|
||||
|
||||
#include <netinet/ip6.h>
|
||||
|
|
|
@ -2,10 +2,8 @@
|
|||
#pragma once
|
||||
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
Copyright (C) 2014 Tom Gundersen
|
||||
Copyright (C) 2014 Susant Sahani
|
||||
Copyright © 2014 Tom Gundersen
|
||||
Copyright © 2014 Susant Sahani
|
||||
***/
|
||||
|
||||
#include "sd-event.h"
|
||||
|
|
|
@ -1,9 +1,4 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
Copyright 2016 Lennart Poettering
|
||||
***/
|
||||
|
||||
#include "alloc-util.h"
|
||||
#include "escape.h"
|
||||
|
|
|
@ -1,12 +1,6 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
#pragma once
|
||||
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
Copyright 2016 Lennart Poettering
|
||||
***/
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <stdbool.h>
|
||||
#include <sys/types.h>
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
Copyright (C) 2014 Tom Gundersen
|
||||
Copyright (C) 2014 Susant Sahani
|
||||
Copyright © 2014 Tom Gundersen
|
||||
Copyright © 2014 Susant Sahani
|
||||
***/
|
||||
|
||||
#include <linux/filter.h>
|
||||
|
|
|
@ -2,10 +2,8 @@
|
|||
#pragma once
|
||||
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
Copyright (C) 2014 Tom Gundersen
|
||||
Copyright (C) 2014 Susant Sahani
|
||||
Copyright © 2014 Tom Gundersen
|
||||
Copyright © 2014 Susant Sahani
|
||||
***/
|
||||
|
||||
#include "sd-event.h"
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
Copyright (C) 2013 Tom Gundersen <teg@jklm.no>
|
||||
Copyright © 2013 Tom Gundersen <teg@jklm.no>
|
||||
***/
|
||||
|
||||
#include <arpa/inet.h>
|
||||
|
|
|
@ -2,9 +2,7 @@
|
|||
#pragma once
|
||||
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
Copyright (C) 2013 Tom Gundersen <teg@jklm.no>
|
||||
Copyright © 2013 Tom Gundersen <teg@jklm.no>
|
||||
***/
|
||||
|
||||
#include <stdbool.h>
|
||||
|
@ -12,6 +10,7 @@
|
|||
#include "sd-dhcp-lease.h"
|
||||
|
||||
#include "condition.h"
|
||||
#include "conf-parser.h"
|
||||
#include "set.h"
|
||||
#include "udev.h"
|
||||
|
||||
|
@ -35,33 +34,13 @@ bool net_match_config(Set *match_mac,
|
|||
const char *dev_type,
|
||||
const char *dev_name);
|
||||
|
||||
int config_parse_net_condition(const char *unit, const char *filename, unsigned line,
|
||||
const char *section, unsigned section_line, const char *lvalue,
|
||||
int ltype, const char *rvalue, void *data, void *userdata);
|
||||
|
||||
int config_parse_hwaddr(const char *unit, const char *filename, unsigned line,
|
||||
const char *section, unsigned section_line, const char *lvalue,
|
||||
int ltype, const char *rvalue, void *data, void *userdata);
|
||||
|
||||
int config_parse_hwaddrs(const char *unit, const char *filename, unsigned line,
|
||||
const char *section, unsigned section_line, const char *lvalue,
|
||||
int ltype, const char *rvalue, void *data, void *userdata);
|
||||
|
||||
int config_parse_ifnames(const char *unit, const char *filename, unsigned line,
|
||||
const char *section, unsigned section_line, const char *lvalue,
|
||||
int ltype, const char *rvalue, void *data, void *userdata);
|
||||
|
||||
int config_parse_ifalias(const char *unit, const char *filename, unsigned line,
|
||||
const char *section, unsigned section_line, const char *lvalue,
|
||||
int ltype, const char *rvalue, void *data, void *userdata);
|
||||
|
||||
int config_parse_iaid(const char *unit, const char *filename, unsigned line,
|
||||
const char *section, unsigned section_line, const char *lvalue,
|
||||
int ltype, const char *rvalue, void *data, void *userdata);
|
||||
|
||||
int config_parse_bridge_port_priority(const char *unit, const char *filename, unsigned line,
|
||||
const char *section, unsigned section_line, const char *lvalue,
|
||||
int ltype, const char *rvalue, void *data, void *userdata);
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_net_condition);
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_hwaddr);
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_hwaddrs);
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_ifnames);
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_ifalias);
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_iaid);
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_bridge_port_priority);
|
||||
|
||||
int net_get_unique_predictable_data(struct udev_device *device, uint64_t *result);
|
||||
const char *net_get_name(struct udev_device *device);
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
Copyright (C) 2013 Intel Corporation. All rights reserved.
|
||||
Copyright © 2013 Intel Corporation. All rights reserved.
|
||||
***/
|
||||
|
||||
#include <errno.h>
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
Copyright (C) 2013 Intel Corporation. All rights reserved.
|
||||
Copyright (C) 2014 Tom Gundersen
|
||||
Copyright © 2013 Intel Corporation. All rights reserved.
|
||||
Copyright © 2014 Tom Gundersen
|
||||
***/
|
||||
|
||||
#include <arpa/inet.h>
|
||||
|
@ -1034,7 +1032,7 @@ int dhcp_lease_load(sd_dhcp_lease **ret, const char *lease_file) {
|
|||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = parse_env_file(lease_file, NEWLINE,
|
||||
r = parse_env_file(NULL, lease_file, NEWLINE,
|
||||
"ADDRESS", &address,
|
||||
"ROUTER", &router,
|
||||
"NETMASK", &netmask,
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
Copyright (C) 2014-2015 Intel Corporation. All rights reserved.
|
||||
Copyright © 2014-2015 Intel Corporation. All rights reserved.
|
||||
***/
|
||||
|
||||
#include <errno.h>
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
Copyright (C) 2014 Tom Gundersen
|
||||
Copyright (C) 2014-2015 Intel Corporation. All rights reserved.
|
||||
Copyright © 2014 Tom Gundersen
|
||||
Copyright © 2014-2015 Intel Corporation. All rights reserved.
|
||||
***/
|
||||
|
||||
#include <errno.h>
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
Copyright (C) 2014 Axis Communications AB. All rights reserved.
|
||||
Copyright (C) 2015 Tom Gundersen
|
||||
Copyright © 2014 Axis Communications AB. All rights reserved.
|
||||
Copyright © 2015 Tom Gundersen
|
||||
***/
|
||||
|
||||
#include <arpa/inet.h>
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
Copyright (C) 2014 Axis Communications AB. All rights reserved.
|
||||
Copyright (C) 2015 Tom Gundersen
|
||||
Copyright © 2014 Axis Communications AB. All rights reserved.
|
||||
Copyright © 2015 Tom Gundersen
|
||||
***/
|
||||
|
||||
#include <arpa/inet.h>
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
Copyright (C) 2014 Tom Gundersen
|
||||
Copyright (C) 2014 Susant Sahani
|
||||
Copyright © 2014 Tom Gundersen
|
||||
Copyright © 2014 Susant Sahani
|
||||
***/
|
||||
|
||||
#include <arpa/inet.h>
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,8 +1,5 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
Copyright 2016 Lennart Poettering
|
||||
***/
|
||||
|
||||
#include <errno.h>
|
||||
|
|
|
@ -2,9 +2,6 @@
|
|||
#pragma once
|
||||
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
Copyright 2016 Lennart Poettering
|
||||
***/
|
||||
|
||||
#include <stdbool.h>
|
||||
|
|
|
@ -1,8 +1,5 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
Copyright 2011 Lennart Poettering
|
||||
***/
|
||||
|
||||
#include <errno.h>
|
||||
|
@ -98,7 +95,7 @@ _public_ int sd_id128_get_machine(sd_id128_t *ret) {
|
|||
return r;
|
||||
|
||||
if (sd_id128_is_null(saved_machine_id))
|
||||
return -EINVAL;
|
||||
return -ENOMEDIUM;
|
||||
}
|
||||
|
||||
*ret = saved_machine_id;
|
||||
|
|
|
@ -1,8 +1,5 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
Copyright 2014 Lennart Poettering
|
||||
***/
|
||||
|
||||
#if HAVE_LIBIDN2
|
||||
|
@ -353,10 +350,7 @@ int dns_label_undo_idna(const char *encoded, size_t encoded_size, char *decoded,
|
|||
if (encoded_size <= 0 || encoded_size > DNS_LABEL_MAX)
|
||||
return -EINVAL;
|
||||
|
||||
if (encoded_size < sizeof(IDNA_ACE_PREFIX)-1)
|
||||
return 0;
|
||||
|
||||
if (memcmp(encoded, IDNA_ACE_PREFIX, sizeof(IDNA_ACE_PREFIX) -1) != 0)
|
||||
if (!memory_startswith(encoded, encoded_size, IDNA_ACE_PREFIX))
|
||||
return 0;
|
||||
|
||||
input = stringprep_utf8_to_ucs4(encoded, encoded_size, &input_size);
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue