1
0
mirror of https://github.com/systemd/systemd synced 2024-07-01 07:34:28 +00:00

tree-wide: use cocinnelle to apply _NEG_ macros

This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2023-08-09 16:41:58 +02:00
parent b0be985cdd
commit 13d84288bc
13 changed files with 66 additions and 23 deletions

View File

@ -0,0 +1,46 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
@@
expression r;
@@
- (r < 0 && ERRNO_IS_TRANSIENT(r))
+ ERRNO_IS_NEG_TRANSIENT(r)
@@
expression r;
@@
- (r < 0 && ERRNO_IS_DISCONNECT(r))
+ ERRNO_IS_NEG_DISCONNECT(r)
@@
expression r;
@@
- (r < 0 && ERRNO_IS_ACCEPT_AGAIN(r))
+ ERRNO_IS_NEG_ACCEPT_AGAIN(r)
@@
expression r;
@@
- (r < 0 && ERRNO_IS_RESOURCE(r))
+ ERRNO_IS_NEG_RESOURCE(r)
@@
expression r;
@@
- (r < 0 && ERRNO_IS_NOT_SUPPORTED(r))
+ ERRNO_IS_NEG_NOT_SUPPORTED(r)
@@
expression r;
@@
- (r < 0 && ERRNO_IS_PRIVILEGE(r))
+ ERRNO_IS_NEG_PRIVILEGE(r)
@@
expression r;
@@
- (r < 0 && ERRNO_IS_DISK_SPACE(r))
+ ERRNO_IS_NEG_DISK_SPACE(r)
@@
expression r;
@@
- (r < 0 && ERRNO_IS_DEVICE_ABSENT(r))
+ ERRNO_IS_NEG_DEVICE_ABSENT(r)
@@
expression r;
@@
- (r < 0 && ERRNO_IS_XATTR_ABSENT(r))
+ ERRNO_IS_NEG_XATTR_ABSENT(r)

View File

@ -434,7 +434,7 @@ int sd_netlink_wait(sd_netlink *nl, uint64_t timeout_usec) {
return 0;
r = netlink_poll(nl, false, timeout_usec);
if (r < 0 && ERRNO_IS_TRANSIENT(r)) /* Convert EINTR to "something happened" and give user a chance to run some code before calling back into us */
if (ERRNO_IS_NEG_TRANSIENT(r)) /* Convert EINTR to "something happened" and give user a chance to run some code before calling back into us */
return 1;
return r;
}

View File

@ -2099,7 +2099,7 @@ int dns_transaction_go(DnsTransaction *t) {
dns_transaction_complete(t, DNS_TRANSACTION_RR_TYPE_UNSUPPORTED);
return 0;
}
if (t->scope->protocol == DNS_PROTOCOL_LLMNR && r < 0 && ERRNO_IS_DISCONNECT(r)) {
if (t->scope->protocol == DNS_PROTOCOL_LLMNR && ERRNO_IS_NEG_DISCONNECT(r)) {
/* On LLMNR, if we cannot connect to a host via TCP when doing reverse lookups. This means we cannot
* answer this request with this protocol. */
dns_transaction_complete(t, DNS_TRANSACTION_NOT_FOUND);

View File

@ -135,12 +135,12 @@ static int is_delegated(int cgfd, const char *path) {
assert(cgfd >= 0 || path);
r = getxattr_malloc(cgfd < 0 ? path : FORMAT_PROC_FD_PATH(cgfd), "trusted.delegate", &b);
if (r < 0 && ERRNO_IS_XATTR_ABSENT(r)) {
if (ERRNO_IS_NEG_XATTR_ABSENT(r)) {
/* If the trusted xattr isn't set (preferred), then check the untrusted one. Under the
* assumption that whoever is trusted enough to own the cgroup, is also trusted enough to
* decide if it is delegated or not this should be safe. */
r = getxattr_malloc(cgfd < 0 ? path : FORMAT_PROC_FD_PATH(cgfd), "user.delegate", &b);
if (r < 0 && ERRNO_IS_XATTR_ABSENT(r))
if (ERRNO_IS_NEG_XATTR_ABSENT(r))
return false;
}
if (r < 0)

View File

@ -1279,8 +1279,8 @@ int varlink_wait(Varlink *v, usec_t timeout) {
return events;
r = fd_wait_for_event(fd, events, t);
if (r < 0 && ERRNO_IS_TRANSIENT(r)) /* Treat EINTR as not a timeout, but also nothing happened, and
* the caller gets a chance to call back into us */
if (ERRNO_IS_NEG_TRANSIENT(r)) /* Treat EINTR as not a timeout, but also nothing happened, and
* the caller gets a chance to call back into us */
return 1;
if (r <= 0)
return r;

View File

@ -21,7 +21,7 @@ int main(int argc, char *argv[]) {
assert_se(architecture_from_string(architecture_to_string(1)) == 1);
v = detect_virtualization();
if (v < 0 && ERRNO_IS_PRIVILEGE(v))
if (ERRNO_IS_NEG_PRIVILEGE(v))
return log_tests_skipped("Cannot detect virtualization");
assert_se(v >= 0);

View File

@ -429,7 +429,7 @@ static int intro(void) {
*/
Virtualization v = detect_virtualization();
if (v < 0 && ERRNO_IS_PRIVILEGE(v))
if (ERRNO_IS_NEG_PRIVILEGE(v))
return log_tests_skipped("Cannot detect virtualization");
if (v != VIRTUALIZATION_NONE)

View File

@ -8,7 +8,7 @@ static void test_path_is_encrypted_one(const char *p, int expect) {
int r;
r = path_is_encrypted(p);
if (r == -ENOENT || (r < 0 && ERRNO_IS_PRIVILEGE(r)))
if (r == -ENOENT || ERRNO_IS_NEG_PRIVILEGE(r))
/* This might fail, if btrfs is used and we run in a container. In that case we cannot
* resolve the device node paths that BTRFS_IOC_DEV_INFO returns, because the device nodes
* are unlikely to exist in the container. But if we can't stat() them we cannot determine

View File

@ -39,7 +39,7 @@ static void test_last_cap_file(void) {
int r;
r = read_one_line_file("/proc/sys/kernel/cap_last_cap", &content);
if (r == -ENOENT || (r < 0 && ERRNO_IS_PRIVILEGE(r))) /* kernel pre 3.2 or no access */
if (r == -ENOENT || ERRNO_IS_NEG_PRIVILEGE(r)) /* kernel pre 3.2 or no access */
return;
assert_se(r >= 0);
@ -235,7 +235,7 @@ static void test_ensure_cap_64_bit(void) {
int r;
r = read_one_line_file("/proc/sys/kernel/cap_last_cap", &content);
if (r == -ENOENT || (r < 0 && ERRNO_IS_PRIVILEGE(r))) /* kernel pre 3.2 or no access */
if (r == -ENOENT || ERRNO_IS_NEG_PRIVILEGE(r)) /* kernel pre 3.2 or no access */
return;
assert_se(r >= 0);

View File

@ -490,7 +490,7 @@ TEST(write_string_file_verify) {
int r;
r = read_one_line_file("/proc/version", &buf);
if (r < 0 && ERRNO_IS_PRIVILEGE(r))
if (ERRNO_IS_NEG_PRIVILEGE(r))
return;
assert_se(r >= 0);
assert_se(buf2 = strjoin(buf, "\n"));

View File

@ -470,10 +470,8 @@ TEST(umount_recursive) {
FORK_MOUNTNS_SLAVE,
NULL);
if (r < 0 && ERRNO_IS_PRIVILEGE(r)) {
log_notice("Skipping umount_recursive() test, lacking privileges");
return;
}
if (ERRNO_IS_NEG_PRIVILEGE(r))
return (void) log_notice("Skipping umount_recursive() test, lacking privileges");
assert_se(r >= 0);
if (r == 0) { /* child */
@ -575,10 +573,9 @@ TEST(bind_mount_submounts) {
assert_se(mkdtemp_malloc(NULL, &a) >= 0);
r = mount_nofollow_verbose(LOG_INFO, "tmpfs", a, "tmpfs", 0, NULL);
if (r < 0 && ERRNO_IS_PRIVILEGE(r)) {
(void) log_tests_skipped("Skipping bind_mount_submounts() test, lacking privileges");
return;
}
if (ERRNO_IS_NEG_PRIVILEGE(r))
return (void) log_tests_skipped("Skipping bind_mount_submounts() test, lacking privileges");
assert_se(r >= 0);
assert_se(x = path_join(a, "foo"));

View File

@ -28,14 +28,14 @@ int main(int argc, char *argv[]) {
pid_max = TASKS_MAX;
r = procfs_get_pid_max(&pid_max);
if (r == -ENOENT || (r < 0 && ERRNO_IS_PRIVILEGE(r)))
if (r == -ENOENT || ERRNO_IS_NEG_PRIVILEGE(r))
return log_tests_skipped_errno(r, "can't get pid max");
assert(r >= 0);
log_info("kernel.pid_max: %"PRIu64, pid_max);
threads_max = TASKS_MAX;
r = procfs_get_threads_max(&threads_max);
if (r == -ENOENT || (r < 0 && ERRNO_IS_PRIVILEGE(r)))
if (r == -ENOENT || ERRNO_IS_NEG_PRIVILEGE(r))
return log_tests_skipped_errno(r, "can't get threads max");
assert(r >= 0);
log_info("kernel.threads-max: %"PRIu64, threads_max);

View File

@ -1937,7 +1937,7 @@ static int create_directory_or_subvolume(
} else
r = 0;
if (!subvol || (r < 0 && ERRNO_IS_NOT_SUPPORTED(r)))
if (!subvol || ERRNO_IS_NEG_NOT_SUPPORTED(r))
WITH_UMASK(0000)
r = mkdirat_label(pfd, bn, mode);