| File: | build-scan/../src/test/test-stat-util.c |
| Warning: | line 78, column 9 Value stored to 'fd' is never read |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
| 1 | /* SPDX-License-Identifier: LGPL-2.1+ */ |
| 2 | |
| 3 | #include <fcntl.h> |
| 4 | #include <linux1/magic.h> |
| 5 | #include <unistd.h> |
| 6 | |
| 7 | #include "alloc-util.h" |
| 8 | #include "fd-util.h" |
| 9 | #include "fileio.h" |
| 10 | #include "macro.h" |
| 11 | #include "missing.h" |
| 12 | #include "mount-util.h" |
| 13 | #include "stat-util.h" |
| 14 | |
| 15 | static void test_files_same(void) { |
| 16 | _cleanup_close___attribute__((cleanup(closep))) int fd = -1; |
| 17 | char name[] = "/tmp/test-files_same.XXXXXX"; |
| 18 | char name_alias[] = "/tmp/test-files_same.alias"; |
| 19 | |
| 20 | fd = mkostemp_safe(name); |
| 21 | assert_se(fd >= 0)do { if ((__builtin_expect(!!(!(fd >= 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("fd >= 0"), "../src/test/test-stat-util.c" , 21, __PRETTY_FUNCTION__); } while (0); |
| 22 | assert_se(symlink(name, name_alias) >= 0)do { if ((__builtin_expect(!!(!(symlink(name, name_alias) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("symlink(name, name_alias) >= 0" ), "../src/test/test-stat-util.c", 22, __PRETTY_FUNCTION__); } while (0); |
| 23 | |
| 24 | assert_se(files_same(name, name, 0))do { if ((__builtin_expect(!!(!(files_same(name, name, 0))),0 ))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("files_same(name, name, 0)" ), "../src/test/test-stat-util.c", 24, __PRETTY_FUNCTION__); } while (0); |
| 25 | assert_se(files_same(name, name, AT_SYMLINK_NOFOLLOW))do { if ((__builtin_expect(!!(!(files_same(name, name, 0x100) )),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("files_same(name, name, AT_SYMLINK_NOFOLLOW)" ), "../src/test/test-stat-util.c", 25, __PRETTY_FUNCTION__); } while (0); |
| 26 | assert_se(files_same(name, name_alias, 0))do { if ((__builtin_expect(!!(!(files_same(name, name_alias, 0 ))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("files_same(name, name_alias, 0)" ), "../src/test/test-stat-util.c", 26, __PRETTY_FUNCTION__); } while (0); |
| 27 | assert_se(!files_same(name, name_alias, AT_SYMLINK_NOFOLLOW))do { if ((__builtin_expect(!!(!(!files_same(name, name_alias, 0x100))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("!files_same(name, name_alias, AT_SYMLINK_NOFOLLOW)" ), "../src/test/test-stat-util.c", 27, __PRETTY_FUNCTION__); } while (0); |
| 28 | |
| 29 | unlink(name); |
| 30 | unlink(name_alias); |
| 31 | } |
| 32 | |
| 33 | static void test_is_symlink(void) { |
| 34 | char name[] = "/tmp/test-is_symlink.XXXXXX"; |
| 35 | char name_link[] = "/tmp/test-is_symlink.link"; |
| 36 | _cleanup_close___attribute__((cleanup(closep))) int fd = -1; |
| 37 | |
| 38 | fd = mkostemp_safe(name); |
| 39 | assert_se(fd >= 0)do { if ((__builtin_expect(!!(!(fd >= 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("fd >= 0"), "../src/test/test-stat-util.c" , 39, __PRETTY_FUNCTION__); } while (0); |
| 40 | assert_se(symlink(name, name_link) >= 0)do { if ((__builtin_expect(!!(!(symlink(name, name_link) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("symlink(name, name_link) >= 0" ), "../src/test/test-stat-util.c", 40, __PRETTY_FUNCTION__); } while (0); |
| 41 | |
| 42 | assert_se(is_symlink(name) == 0)do { if ((__builtin_expect(!!(!(is_symlink(name) == 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("is_symlink(name) == 0"), "../src/test/test-stat-util.c" , 42, __PRETTY_FUNCTION__); } while (0); |
| 43 | assert_se(is_symlink(name_link) == 1)do { if ((__builtin_expect(!!(!(is_symlink(name_link) == 1)), 0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("is_symlink(name_link) == 1" ), "../src/test/test-stat-util.c", 43, __PRETTY_FUNCTION__); } while (0); |
| 44 | assert_se(is_symlink("/a/file/which/does/not/exist/i/guess") < 0)do { if ((__builtin_expect(!!(!(is_symlink("/a/file/which/does/not/exist/i/guess" ) < 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("is_symlink(\"/a/file/which/does/not/exist/i/guess\") < 0" ), "../src/test/test-stat-util.c", 44, __PRETTY_FUNCTION__); } while (0); |
| 45 | |
| 46 | unlink(name); |
| 47 | unlink(name_link); |
| 48 | } |
| 49 | |
| 50 | static void test_path_is_fs_type(void) { |
| 51 | /* run might not be a mount point in build chroots */ |
| 52 | if (path_is_mount_point("/run", NULL((void*)0), AT_SYMLINK_FOLLOW0x400) > 0) { |
| 53 | assert_se(path_is_fs_type("/run", TMPFS_MAGIC) > 0)do { if ((__builtin_expect(!!(!(path_is_fs_type("/run", 0x01021994 ) > 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("path_is_fs_type(\"/run\", TMPFS_MAGIC) > 0" ), "../src/test/test-stat-util.c", 53, __PRETTY_FUNCTION__); } while (0); |
| 54 | assert_se(path_is_fs_type("/run", BTRFS_SUPER_MAGIC) == 0)do { if ((__builtin_expect(!!(!(path_is_fs_type("/run", 0x9123683E ) == 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("path_is_fs_type(\"/run\", BTRFS_SUPER_MAGIC) == 0" ), "../src/test/test-stat-util.c", 54, __PRETTY_FUNCTION__); } while (0); |
| 55 | } |
| 56 | assert_se(path_is_fs_type("/proc", PROC_SUPER_MAGIC) > 0)do { if ((__builtin_expect(!!(!(path_is_fs_type("/proc", 0x9fa0 ) > 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("path_is_fs_type(\"/proc\", PROC_SUPER_MAGIC) > 0" ), "../src/test/test-stat-util.c", 56, __PRETTY_FUNCTION__); } while (0); |
| 57 | assert_se(path_is_fs_type("/proc", BTRFS_SUPER_MAGIC) == 0)do { if ((__builtin_expect(!!(!(path_is_fs_type("/proc", 0x9123683E ) == 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("path_is_fs_type(\"/proc\", BTRFS_SUPER_MAGIC) == 0" ), "../src/test/test-stat-util.c", 57, __PRETTY_FUNCTION__); } while (0); |
| 58 | assert_se(path_is_fs_type("/proc", BTRFS_SUPER_MAGIC) == 0)do { if ((__builtin_expect(!!(!(path_is_fs_type("/proc", 0x9123683E ) == 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("path_is_fs_type(\"/proc\", BTRFS_SUPER_MAGIC) == 0" ), "../src/test/test-stat-util.c", 58, __PRETTY_FUNCTION__); } while (0); |
| 59 | assert_se(path_is_fs_type("/i-dont-exist", BTRFS_SUPER_MAGIC) == -ENOENT)do { if ((__builtin_expect(!!(!(path_is_fs_type("/i-dont-exist" , 0x9123683E) == -2)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("path_is_fs_type(\"/i-dont-exist\", BTRFS_SUPER_MAGIC) == -ENOENT" ), "../src/test/test-stat-util.c", 59, __PRETTY_FUNCTION__); } while (0); |
| 60 | } |
| 61 | |
| 62 | static void test_path_is_temporary_fs(void) { |
| 63 | /* run might not be a mount point in build chroots */ |
| 64 | if (path_is_mount_point("/run", NULL((void*)0), AT_SYMLINK_FOLLOW0x400) > 0) |
| 65 | assert_se(path_is_temporary_fs("/run") > 0)do { if ((__builtin_expect(!!(!(path_is_temporary_fs("/run") > 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("path_is_temporary_fs(\"/run\") > 0" ), "../src/test/test-stat-util.c", 65, __PRETTY_FUNCTION__); } while (0); |
| 66 | assert_se(path_is_temporary_fs("/proc") == 0)do { if ((__builtin_expect(!!(!(path_is_temporary_fs("/proc") == 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("path_is_temporary_fs(\"/proc\") == 0" ), "../src/test/test-stat-util.c", 66, __PRETTY_FUNCTION__); } while (0); |
| 67 | assert_se(path_is_temporary_fs("/i-dont-exist") == -ENOENT)do { if ((__builtin_expect(!!(!(path_is_temporary_fs("/i-dont-exist" ) == -2)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("path_is_temporary_fs(\"/i-dont-exist\") == -ENOENT" ), "../src/test/test-stat-util.c", 67, __PRETTY_FUNCTION__); } while (0); |
| 68 | } |
| 69 | |
| 70 | static void test_fd_is_network_ns(void) { |
| 71 | _cleanup_close___attribute__((cleanup(closep))) int fd = -1; |
| 72 | assert_se(fd_is_network_ns(STDIN_FILENO) == 0)do { if ((__builtin_expect(!!(!(fd_is_network_ns(0) == 0)),0) )) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("fd_is_network_ns(STDIN_FILENO) == 0" ), "../src/test/test-stat-util.c", 72, __PRETTY_FUNCTION__); } while (0); |
| 73 | assert_se(fd_is_network_ns(STDERR_FILENO) == 0)do { if ((__builtin_expect(!!(!(fd_is_network_ns(2) == 0)),0) )) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("fd_is_network_ns(STDERR_FILENO) == 0" ), "../src/test/test-stat-util.c", 73, __PRETTY_FUNCTION__); } while (0); |
| 74 | assert_se(fd_is_network_ns(STDOUT_FILENO) == 0)do { if ((__builtin_expect(!!(!(fd_is_network_ns(1) == 0)),0) )) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("fd_is_network_ns(STDOUT_FILENO) == 0" ), "../src/test/test-stat-util.c", 74, __PRETTY_FUNCTION__); } while (0); |
| 75 | |
| 76 | assert_se((fd = open("/proc/self/ns/mnt", O_CLOEXEC|O_RDONLY)) >= 0)do { if ((__builtin_expect(!!(!((fd = open("/proc/self/ns/mnt" , 02000000|00)) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("(fd = open(\"/proc/self/ns/mnt\", O_CLOEXEC|O_RDONLY)) >= 0" ), "../src/test/test-stat-util.c", 76, __PRETTY_FUNCTION__); } while (0); |
| 77 | assert_se(IN_SET(fd_is_network_ns(fd), 0, -EUCLEAN))do { if ((__builtin_expect(!!(!(({ _Bool _found = 0; static __attribute__ ((unused)) char _static_assert__macros_need_to_be_extended[20 - sizeof((int[]){0, -117})/sizeof(int)]; switch(fd_is_network_ns (fd)) { case 0: case -117: _found = 1; break; default: break; } _found; }))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("IN_SET(fd_is_network_ns(fd), 0, -EUCLEAN)"), "../src/test/test-stat-util.c" , 77, __PRETTY_FUNCTION__); } while (0); |
| 78 | fd = safe_close(fd); |
Value stored to 'fd' is never read | |
| 79 | |
| 80 | assert_se((fd = open("/proc/self/ns/net", O_CLOEXEC|O_RDONLY)) >= 0)do { if ((__builtin_expect(!!(!((fd = open("/proc/self/ns/net" , 02000000|00)) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("(fd = open(\"/proc/self/ns/net\", O_CLOEXEC|O_RDONLY)) >= 0" ), "../src/test/test-stat-util.c", 80, __PRETTY_FUNCTION__); } while (0); |
| 81 | assert_se(IN_SET(fd_is_network_ns(fd), 1, -EUCLEAN))do { if ((__builtin_expect(!!(!(({ _Bool _found = 0; static __attribute__ ((unused)) char _static_assert__macros_need_to_be_extended[20 - sizeof((int[]){1, -117})/sizeof(int)]; switch(fd_is_network_ns (fd)) { case 1: case -117: _found = 1; break; default: break; } _found; }))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("IN_SET(fd_is_network_ns(fd), 1, -EUCLEAN)"), "../src/test/test-stat-util.c" , 81, __PRETTY_FUNCTION__); } while (0); |
| 82 | } |
| 83 | |
| 84 | int main(int argc, char *argv[]) { |
| 85 | test_files_same(); |
| 86 | test_is_symlink(); |
| 87 | test_path_is_fs_type(); |
| 88 | test_path_is_temporary_fs(); |
| 89 | test_fd_is_network_ns(); |
| 90 | |
| 91 | return 0; |
| 92 | } |