]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test: cleanup use of ERRNO_IS_PRIVILEGE()
authorDmitry V. Levin <ldv@strace.io>
Fri, 14 Jul 2023 08:00:00 +0000 (08:00 +0000)
committerDmitry V. Levin <ldv@strace.io>
Fri, 28 Jul 2023 12:28:35 +0000 (12:28 +0000)
Given that ERRNO_IS_PRIVILEGE() also matches positive values,
make sure this macro is not called with arguments that do not have
errno semantics.

In this case the arguments passed to ERRNO_IS_PRIVILEGE() are the values
returned by procfs_get_pid_max() and procfs_get_threads_max() which are
not expected to return any positive values, but let's be consistent
anyway and move ERRNO_IS_PRIVILEGE() invocations to the branches where
the return values are known to be negative.

src/test/test-procfs-util.c

index 7c3aa21d6578ec1fe1b67f7056c8beb1654688af..5427e1bec3a14371a56293a7480bbd1ad853745d 100644 (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 || ERRNO_IS_PRIVILEGE(r))
+        if (r == -ENOENT || (r < 0 && ERRNO_IS_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 || ERRNO_IS_PRIVILEGE(r))
+        if (r == -ENOENT || (r < 0 && ERRNO_IS_PRIVILEGE(r)))
                 return log_tests_skipped_errno(r, "can't get threads max");
         assert(r >= 0);
         log_info("kernel.threads-max: %"PRIu64, threads_max);