mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-05-05 07:38:20 +02:00
systemd: merge branch systemd into master
Reimport systemd because it uses STRLEN() macro. We need to when building with -Wvla warning enabled. Related: https://github.com/systemd/systemd/pull/7625
This commit is contained in:
commit
7d074fa6df
8 changed files with 59 additions and 10 deletions
|
|
@ -372,7 +372,7 @@ bool fdname_is_valid(const char *s) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int fd_get_path(int fd, char **ret) {
|
int fd_get_path(int fd, char **ret) {
|
||||||
char procfs_path[strlen("/proc/self/fd/") + DECIMAL_STR_MAX(int)];
|
char procfs_path[STRLEN("/proc/self/fd/") + DECIMAL_STR_MAX(int)];
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
xsprintf(procfs_path, "/proc/self/fd/%i", fd);
|
xsprintf(procfs_path, "/proc/self/fd/%i", fd);
|
||||||
|
|
|
||||||
|
|
@ -170,6 +170,9 @@ int write_string_file_ts(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (flags & WRITE_STRING_FILE_DISABLE_BUFFER)
|
||||||
|
setvbuf(f, NULL, _IONBF, 0);
|
||||||
|
|
||||||
r = write_string_stream_ts(f, line, flags, ts);
|
r = write_string_stream_ts(f, line, flags, ts);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,7 @@ typedef enum {
|
||||||
WRITE_STRING_FILE_AVOID_NEWLINE = 1<<2,
|
WRITE_STRING_FILE_AVOID_NEWLINE = 1<<2,
|
||||||
WRITE_STRING_FILE_VERIFY_ON_FAILURE = 1<<3,
|
WRITE_STRING_FILE_VERIFY_ON_FAILURE = 1<<3,
|
||||||
WRITE_STRING_FILE_SYNC = 1<<4,
|
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
|
/* 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()
|
more flag here: it's about linking: we don't want to pull -lselinux into all users of write_string_file()
|
||||||
|
|
|
||||||
|
|
@ -226,6 +226,38 @@ int sethostname_idempotent(const char *s) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int shorten_overlong(const char *s, char **ret) {
|
||||||
|
char *h, *p;
|
||||||
|
|
||||||
|
/* Shorten an overlong name to HOST_NAME_MAX or to the first dot,
|
||||||
|
* whatever comes earlier. */
|
||||||
|
|
||||||
|
assert(s);
|
||||||
|
|
||||||
|
h = strdup(s);
|
||||||
|
if (!h)
|
||||||
|
return -ENOMEM;
|
||||||
|
|
||||||
|
if (hostname_is_valid(h, false)) {
|
||||||
|
*ret = h;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
p = strchr(h, '.');
|
||||||
|
if (p)
|
||||||
|
*p = 0;
|
||||||
|
|
||||||
|
strshorten(h, HOST_NAME_MAX);
|
||||||
|
|
||||||
|
if (!hostname_is_valid(h, false)) {
|
||||||
|
free(h);
|
||||||
|
return -EDOM;
|
||||||
|
}
|
||||||
|
|
||||||
|
*ret = h;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
int read_etc_hostname_stream(FILE *f, char **ret) {
|
int read_etc_hostname_stream(FILE *f, char **ret) {
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -39,5 +39,7 @@ bool is_gateway_hostname(const char *hostname);
|
||||||
|
|
||||||
int sethostname_idempotent(const char *s);
|
int sethostname_idempotent(const char *s);
|
||||||
|
|
||||||
|
int shorten_overlong(const char *s, char **ret);
|
||||||
|
|
||||||
int read_etc_hostname_stream(FILE *f, char **ret);
|
int read_etc_hostname_stream(FILE *f, char **ret);
|
||||||
int read_etc_hostname(const char *path, char **ret);
|
int read_etc_hostname(const char *path, char **ret);
|
||||||
|
|
|
||||||
|
|
@ -153,6 +153,14 @@ static inline unsigned long ALIGN_POWER2(unsigned long u) {
|
||||||
!__builtin_types_compatible_p(typeof(x), typeof(&*(x))), \
|
!__builtin_types_compatible_p(typeof(x), typeof(&*(x))), \
|
||||||
sizeof(x)/sizeof((x)[0]), \
|
sizeof(x)/sizeof((x)[0]), \
|
||||||
(void)0))
|
(void)0))
|
||||||
|
|
||||||
|
/*
|
||||||
|
* STRLEN - return the length of a string literal, minus the trailing NUL byte.
|
||||||
|
* Contrary to strlen(), this is a constant expression.
|
||||||
|
* @x: a string literal.
|
||||||
|
*/
|
||||||
|
#define STRLEN(x) (sizeof(""x"") - 1)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* container_of - cast a member of a structure out to the containing structure
|
* container_of - cast a member of a structure out to the containing structure
|
||||||
* @ptr: the pointer to the member.
|
* @ptr: the pointer to the member.
|
||||||
|
|
|
||||||
|
|
@ -989,7 +989,7 @@ int dhcp_lease_save(sd_dhcp_lease *lease, const char *lease_file) {
|
||||||
}
|
}
|
||||||
|
|
||||||
LIST_FOREACH(options, option, lease->private_options) {
|
LIST_FOREACH(options, option, lease->private_options) {
|
||||||
char key[strlen("OPTION_000")+1];
|
char key[STRLEN("OPTION_000")+1];
|
||||||
|
|
||||||
xsprintf(key, "OPTION_%" PRIu8, option->tag);
|
xsprintf(key, "OPTION_%" PRIu8, option->tag);
|
||||||
r = serialize_dhcp_option(f, key, option->data, option->length);
|
r = serialize_dhcp_option(f, key, option->data, option->length);
|
||||||
|
|
|
||||||
|
|
@ -702,23 +702,26 @@ int dns_name_change_suffix(const char *name, const char *old_suffix, const char
|
||||||
}
|
}
|
||||||
|
|
||||||
int dns_name_between(const char *a, const char *b, const char *c) {
|
int dns_name_between(const char *a, const char *b, const char *c) {
|
||||||
int n;
|
|
||||||
|
|
||||||
/* Determine if b is strictly greater than a and strictly smaller than c.
|
/* Determine if b is strictly greater than a and strictly smaller than c.
|
||||||
We consider the order of names to be circular, so that if a is
|
We consider the order of names to be circular, so that if a is
|
||||||
strictly greater than c, we consider b to be between them if it is
|
strictly greater than c, we consider b to be between them if it is
|
||||||
either greater than a or smaller than c. This is how the canonical
|
either greater than a or smaller than c. This is how the canonical
|
||||||
DNS name order used in NSEC records work. */
|
DNS name order used in NSEC records work. */
|
||||||
|
|
||||||
n = dns_name_compare_func(a, c);
|
if (dns_name_compare_func(a, c) < 0)
|
||||||
if (n == 0)
|
/*
|
||||||
return -EINVAL;
|
a and c are properly ordered:
|
||||||
else if (n < 0)
|
a<---b--->c
|
||||||
/* a<---b--->c */
|
*/
|
||||||
return dns_name_compare_func(a, b) < 0 &&
|
return dns_name_compare_func(a, b) < 0 &&
|
||||||
dns_name_compare_func(b, c) < 0;
|
dns_name_compare_func(b, c) < 0;
|
||||||
else
|
else
|
||||||
/* <--b--c a--b--> */
|
/*
|
||||||
|
a and c are equal or 'reversed':
|
||||||
|
<--b--c a----->
|
||||||
|
or:
|
||||||
|
<-----c a--b-->
|
||||||
|
*/
|
||||||
return dns_name_compare_func(b, c) < 0 ||
|
return dns_name_compare_func(b, c) < 0 ||
|
||||||
dns_name_compare_func(a, b) < 0;
|
dns_name_compare_func(a, b) < 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue