File: | build-scan/../src/test/test-fs-util.c |
Warning: | line 416, column 17 Potential leak of memory pointed to by 'tmpdir_backup' |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | /* SPDX-License-Identifier: LGPL-2.1+ */ | |||
2 | ||||
3 | #include <unistd.h> | |||
4 | ||||
5 | #include "alloc-util.h" | |||
6 | #include "fd-util.h" | |||
7 | #include "fd-util.h" | |||
8 | #include "fileio.h" | |||
9 | #include "fs-util.h" | |||
10 | #include "id128-util.h" | |||
11 | #include "macro.h" | |||
12 | #include "mkdir.h" | |||
13 | #include "path-util.h" | |||
14 | #include "rm-rf.h" | |||
15 | #include "stdio-util.h" | |||
16 | #include "string-util.h" | |||
17 | #include "strv.h" | |||
18 | #include "user-util.h" | |||
19 | #include "util.h" | |||
20 | #include "virt.h" | |||
21 | ||||
22 | static void test_chase_symlinks(void) { | |||
23 | _cleanup_free___attribute__((cleanup(freep))) char *result = NULL((void*)0); | |||
24 | char temp[] = "/tmp/test-chase.XXXXXX"; | |||
25 | const char *top, *p, *pslash, *q, *qslash; | |||
26 | int r, pfd; | |||
27 | ||||
28 | assert_se(mkdtemp(temp))do { if ((__builtin_expect(!!(!(mkdtemp(temp))),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("mkdtemp(temp)"), "../src/test/test-fs-util.c" , 28, __PRETTY_FUNCTION__); } while (0); | |||
29 | ||||
30 | top = strjoina(temp, "/top")({ const char *_appendees_[] = { temp, "/top" }; char *_d_, * _p_; size_t _len_ = 0; size_t _i_; for (_i_ = 0; _i_ < __extension__ (__builtin_choose_expr( !__builtin_types_compatible_p(typeof (_appendees_), typeof(&*(_appendees_))), sizeof(_appendees_ )/sizeof((_appendees_)[0]), ((void)0))) && _appendees_ [_i_]; _i_++) _len_ += strlen(_appendees_[_i_]); _p_ = _d_ = __builtin_alloca (_len_ + 1); for (_i_ = 0; _i_ < __extension__ (__builtin_choose_expr ( !__builtin_types_compatible_p(typeof(_appendees_), typeof(& *(_appendees_))), sizeof(_appendees_)/sizeof((_appendees_)[0] ), ((void)0))) && _appendees_[_i_]; _i_++) _p_ = stpcpy (_p_, _appendees_[_i_]); *_p_ = 0; _d_; }); | |||
31 | assert_se(mkdir(top, 0700) >= 0)do { if ((__builtin_expect(!!(!(mkdir(top, 0700) >= 0)),0) )) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("mkdir(top, 0700) >= 0" ), "../src/test/test-fs-util.c", 31, __PRETTY_FUNCTION__); } while (0); | |||
32 | ||||
33 | p = strjoina(top, "/dot")({ const char *_appendees_[] = { top, "/dot" }; char *_d_, *_p_ ; size_t _len_ = 0; size_t _i_; for (_i_ = 0; _i_ < __extension__ (__builtin_choose_expr( !__builtin_types_compatible_p(typeof (_appendees_), typeof(&*(_appendees_))), sizeof(_appendees_ )/sizeof((_appendees_)[0]), ((void)0))) && _appendees_ [_i_]; _i_++) _len_ += strlen(_appendees_[_i_]); _p_ = _d_ = __builtin_alloca (_len_ + 1); for (_i_ = 0; _i_ < __extension__ (__builtin_choose_expr ( !__builtin_types_compatible_p(typeof(_appendees_), typeof(& *(_appendees_))), sizeof(_appendees_)/sizeof((_appendees_)[0] ), ((void)0))) && _appendees_[_i_]; _i_++) _p_ = stpcpy (_p_, _appendees_[_i_]); *_p_ = 0; _d_; }); | |||
34 | assert_se(symlink(".", p) >= 0)do { if ((__builtin_expect(!!(!(symlink(".", p) >= 0)),0)) ) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("symlink(\".\", p) >= 0" ), "../src/test/test-fs-util.c", 34, __PRETTY_FUNCTION__); } while (0); | |||
35 | ||||
36 | p = strjoina(top, "/dotdot")({ const char *_appendees_[] = { top, "/dotdot" }; char *_d_, *_p_; size_t _len_ = 0; size_t _i_; for (_i_ = 0; _i_ < __extension__ (__builtin_choose_expr( !__builtin_types_compatible_p(typeof (_appendees_), typeof(&*(_appendees_))), sizeof(_appendees_ )/sizeof((_appendees_)[0]), ((void)0))) && _appendees_ [_i_]; _i_++) _len_ += strlen(_appendees_[_i_]); _p_ = _d_ = __builtin_alloca (_len_ + 1); for (_i_ = 0; _i_ < __extension__ (__builtin_choose_expr ( !__builtin_types_compatible_p(typeof(_appendees_), typeof(& *(_appendees_))), sizeof(_appendees_)/sizeof((_appendees_)[0] ), ((void)0))) && _appendees_[_i_]; _i_++) _p_ = stpcpy (_p_, _appendees_[_i_]); *_p_ = 0; _d_; }); | |||
37 | assert_se(symlink("..", p) >= 0)do { if ((__builtin_expect(!!(!(symlink("..", p) >= 0)),0) )) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("symlink(\"..\", p) >= 0" ), "../src/test/test-fs-util.c", 37, __PRETTY_FUNCTION__); } while (0); | |||
38 | ||||
39 | p = strjoina(top, "/dotdota")({ const char *_appendees_[] = { top, "/dotdota" }; char *_d_ , *_p_; size_t _len_ = 0; size_t _i_; for (_i_ = 0; _i_ < __extension__ (__builtin_choose_expr( !__builtin_types_compatible_p(typeof (_appendees_), typeof(&*(_appendees_))), sizeof(_appendees_ )/sizeof((_appendees_)[0]), ((void)0))) && _appendees_ [_i_]; _i_++) _len_ += strlen(_appendees_[_i_]); _p_ = _d_ = __builtin_alloca (_len_ + 1); for (_i_ = 0; _i_ < __extension__ (__builtin_choose_expr ( !__builtin_types_compatible_p(typeof(_appendees_), typeof(& *(_appendees_))), sizeof(_appendees_)/sizeof((_appendees_)[0] ), ((void)0))) && _appendees_[_i_]; _i_++) _p_ = stpcpy (_p_, _appendees_[_i_]); *_p_ = 0; _d_; }); | |||
40 | assert_se(symlink("../a", p) >= 0)do { if ((__builtin_expect(!!(!(symlink("../a", p) >= 0)), 0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("symlink(\"../a\", p) >= 0" ), "../src/test/test-fs-util.c", 40, __PRETTY_FUNCTION__); } while (0); | |||
41 | ||||
42 | p = strjoina(temp, "/a")({ const char *_appendees_[] = { temp, "/a" }; char *_d_, *_p_ ; size_t _len_ = 0; size_t _i_; for (_i_ = 0; _i_ < __extension__ (__builtin_choose_expr( !__builtin_types_compatible_p(typeof (_appendees_), typeof(&*(_appendees_))), sizeof(_appendees_ )/sizeof((_appendees_)[0]), ((void)0))) && _appendees_ [_i_]; _i_++) _len_ += strlen(_appendees_[_i_]); _p_ = _d_ = __builtin_alloca (_len_ + 1); for (_i_ = 0; _i_ < __extension__ (__builtin_choose_expr ( !__builtin_types_compatible_p(typeof(_appendees_), typeof(& *(_appendees_))), sizeof(_appendees_)/sizeof((_appendees_)[0] ), ((void)0))) && _appendees_[_i_]; _i_++) _p_ = stpcpy (_p_, _appendees_[_i_]); *_p_ = 0; _d_; }); | |||
43 | assert_se(symlink("b", p) >= 0)do { if ((__builtin_expect(!!(!(symlink("b", p) >= 0)),0)) ) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("symlink(\"b\", p) >= 0" ), "../src/test/test-fs-util.c", 43, __PRETTY_FUNCTION__); } while (0); | |||
44 | ||||
45 | p = strjoina(temp, "/b")({ const char *_appendees_[] = { temp, "/b" }; char *_d_, *_p_ ; size_t _len_ = 0; size_t _i_; for (_i_ = 0; _i_ < __extension__ (__builtin_choose_expr( !__builtin_types_compatible_p(typeof (_appendees_), typeof(&*(_appendees_))), sizeof(_appendees_ )/sizeof((_appendees_)[0]), ((void)0))) && _appendees_ [_i_]; _i_++) _len_ += strlen(_appendees_[_i_]); _p_ = _d_ = __builtin_alloca (_len_ + 1); for (_i_ = 0; _i_ < __extension__ (__builtin_choose_expr ( !__builtin_types_compatible_p(typeof(_appendees_), typeof(& *(_appendees_))), sizeof(_appendees_)/sizeof((_appendees_)[0] ), ((void)0))) && _appendees_[_i_]; _i_++) _p_ = stpcpy (_p_, _appendees_[_i_]); *_p_ = 0; _d_; }); | |||
46 | assert_se(symlink("/usr", p) >= 0)do { if ((__builtin_expect(!!(!(symlink("/usr", p) >= 0)), 0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("symlink(\"/usr\", p) >= 0" ), "../src/test/test-fs-util.c", 46, __PRETTY_FUNCTION__); } while (0); | |||
47 | ||||
48 | p = strjoina(temp, "/start")({ const char *_appendees_[] = { temp, "/start" }; char *_d_, *_p_; size_t _len_ = 0; size_t _i_; for (_i_ = 0; _i_ < __extension__ (__builtin_choose_expr( !__builtin_types_compatible_p(typeof (_appendees_), typeof(&*(_appendees_))), sizeof(_appendees_ )/sizeof((_appendees_)[0]), ((void)0))) && _appendees_ [_i_]; _i_++) _len_ += strlen(_appendees_[_i_]); _p_ = _d_ = __builtin_alloca (_len_ + 1); for (_i_ = 0; _i_ < __extension__ (__builtin_choose_expr ( !__builtin_types_compatible_p(typeof(_appendees_), typeof(& *(_appendees_))), sizeof(_appendees_)/sizeof((_appendees_)[0] ), ((void)0))) && _appendees_[_i_]; _i_++) _p_ = stpcpy (_p_, _appendees_[_i_]); *_p_ = 0; _d_; }); | |||
49 | assert_se(symlink("top/dot/dotdota", p) >= 0)do { if ((__builtin_expect(!!(!(symlink("top/dot/dotdota", p) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("symlink(\"top/dot/dotdota\", p) >= 0" ), "../src/test/test-fs-util.c", 49, __PRETTY_FUNCTION__); } while (0); | |||
50 | ||||
51 | /* Paths that use symlinks underneath the "root" */ | |||
52 | ||||
53 | r = chase_symlinks(p, NULL((void*)0), 0, &result); | |||
54 | assert_se(r > 0)do { if ((__builtin_expect(!!(!(r > 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("r > 0"), "../src/test/test-fs-util.c" , 54, __PRETTY_FUNCTION__); } while (0); | |||
55 | assert_se(path_equal(result, "/usr"))do { if ((__builtin_expect(!!(!(path_equal(result, "/usr"))), 0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("path_equal(result, \"/usr\")" ), "../src/test/test-fs-util.c", 55, __PRETTY_FUNCTION__); } while (0); | |||
56 | result = mfree(result); | |||
57 | ||||
58 | pslash = strjoina(p, "/")({ const char *_appendees_[] = { p, "/" }; char *_d_, *_p_; size_t _len_ = 0; size_t _i_; for (_i_ = 0; _i_ < __extension__ ( __builtin_choose_expr( !__builtin_types_compatible_p(typeof(_appendees_ ), typeof(&*(_appendees_))), sizeof(_appendees_)/sizeof(( _appendees_)[0]), ((void)0))) && _appendees_[_i_]; _i_ ++) _len_ += strlen(_appendees_[_i_]); _p_ = _d_ = __builtin_alloca (_len_ + 1); for (_i_ = 0; _i_ < __extension__ (__builtin_choose_expr ( !__builtin_types_compatible_p(typeof(_appendees_), typeof(& *(_appendees_))), sizeof(_appendees_)/sizeof((_appendees_)[0] ), ((void)0))) && _appendees_[_i_]; _i_++) _p_ = stpcpy (_p_, _appendees_[_i_]); *_p_ = 0; _d_; }); | |||
59 | r = chase_symlinks(pslash, NULL((void*)0), 0, &result); | |||
60 | assert_se(r > 0)do { if ((__builtin_expect(!!(!(r > 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("r > 0"), "../src/test/test-fs-util.c" , 60, __PRETTY_FUNCTION__); } while (0); | |||
61 | assert_se(path_equal(result, "/usr/"))do { if ((__builtin_expect(!!(!(path_equal(result, "/usr/"))) ,0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("path_equal(result, \"/usr/\")" ), "../src/test/test-fs-util.c", 61, __PRETTY_FUNCTION__); } while (0); | |||
62 | result = mfree(result); | |||
63 | ||||
64 | r = chase_symlinks(p, temp, 0, &result); | |||
65 | assert_se(r == -ENOENT)do { if ((__builtin_expect(!!(!(r == -2)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("r == -ENOENT"), "../src/test/test-fs-util.c" , 65, __PRETTY_FUNCTION__); } while (0); | |||
66 | ||||
67 | r = chase_symlinks(pslash, temp, 0, &result); | |||
68 | assert_se(r == -ENOENT)do { if ((__builtin_expect(!!(!(r == -2)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("r == -ENOENT"), "../src/test/test-fs-util.c" , 68, __PRETTY_FUNCTION__); } while (0); | |||
69 | ||||
70 | q = strjoina(temp, "/usr")({ const char *_appendees_[] = { temp, "/usr" }; char *_d_, * _p_; size_t _len_ = 0; size_t _i_; for (_i_ = 0; _i_ < __extension__ (__builtin_choose_expr( !__builtin_types_compatible_p(typeof (_appendees_), typeof(&*(_appendees_))), sizeof(_appendees_ )/sizeof((_appendees_)[0]), ((void)0))) && _appendees_ [_i_]; _i_++) _len_ += strlen(_appendees_[_i_]); _p_ = _d_ = __builtin_alloca (_len_ + 1); for (_i_ = 0; _i_ < __extension__ (__builtin_choose_expr ( !__builtin_types_compatible_p(typeof(_appendees_), typeof(& *(_appendees_))), sizeof(_appendees_)/sizeof((_appendees_)[0] ), ((void)0))) && _appendees_[_i_]; _i_++) _p_ = stpcpy (_p_, _appendees_[_i_]); *_p_ = 0; _d_; }); | |||
71 | ||||
72 | r = chase_symlinks(p, temp, CHASE_NONEXISTENT, &result); | |||
73 | assert_se(r == 0)do { if ((__builtin_expect(!!(!(r == 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("r == 0"), "../src/test/test-fs-util.c", 73, __PRETTY_FUNCTION__); } while (0); | |||
74 | assert_se(path_equal(result, q))do { if ((__builtin_expect(!!(!(path_equal(result, q))),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("path_equal(result, q)"), "../src/test/test-fs-util.c" , 74, __PRETTY_FUNCTION__); } while (0); | |||
75 | result = mfree(result); | |||
76 | ||||
77 | qslash = strjoina(q, "/")({ const char *_appendees_[] = { q, "/" }; char *_d_, *_p_; size_t _len_ = 0; size_t _i_; for (_i_ = 0; _i_ < __extension__ ( __builtin_choose_expr( !__builtin_types_compatible_p(typeof(_appendees_ ), typeof(&*(_appendees_))), sizeof(_appendees_)/sizeof(( _appendees_)[0]), ((void)0))) && _appendees_[_i_]; _i_ ++) _len_ += strlen(_appendees_[_i_]); _p_ = _d_ = __builtin_alloca (_len_ + 1); for (_i_ = 0; _i_ < __extension__ (__builtin_choose_expr ( !__builtin_types_compatible_p(typeof(_appendees_), typeof(& *(_appendees_))), sizeof(_appendees_)/sizeof((_appendees_)[0] ), ((void)0))) && _appendees_[_i_]; _i_++) _p_ = stpcpy (_p_, _appendees_[_i_]); *_p_ = 0; _d_; }); | |||
78 | ||||
79 | r = chase_symlinks(pslash, temp, CHASE_NONEXISTENT, &result); | |||
80 | assert_se(r == 0)do { if ((__builtin_expect(!!(!(r == 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("r == 0"), "../src/test/test-fs-util.c", 80, __PRETTY_FUNCTION__); } while (0); | |||
81 | assert_se(path_equal(result, qslash))do { if ((__builtin_expect(!!(!(path_equal(result, qslash))), 0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("path_equal(result, qslash)" ), "../src/test/test-fs-util.c", 81, __PRETTY_FUNCTION__); } while (0); | |||
82 | result = mfree(result); | |||
83 | ||||
84 | assert_se(mkdir(q, 0700) >= 0)do { if ((__builtin_expect(!!(!(mkdir(q, 0700) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("mkdir(q, 0700) >= 0" ), "../src/test/test-fs-util.c", 84, __PRETTY_FUNCTION__); } while (0); | |||
85 | ||||
86 | r = chase_symlinks(p, temp, 0, &result); | |||
87 | assert_se(r > 0)do { if ((__builtin_expect(!!(!(r > 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("r > 0"), "../src/test/test-fs-util.c" , 87, __PRETTY_FUNCTION__); } while (0); | |||
88 | assert_se(path_equal(result, q))do { if ((__builtin_expect(!!(!(path_equal(result, q))),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("path_equal(result, q)"), "../src/test/test-fs-util.c" , 88, __PRETTY_FUNCTION__); } while (0); | |||
89 | result = mfree(result); | |||
90 | ||||
91 | r = chase_symlinks(pslash, temp, 0, &result); | |||
92 | assert_se(r > 0)do { if ((__builtin_expect(!!(!(r > 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("r > 0"), "../src/test/test-fs-util.c" , 92, __PRETTY_FUNCTION__); } while (0); | |||
93 | assert_se(path_equal(result, qslash))do { if ((__builtin_expect(!!(!(path_equal(result, qslash))), 0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("path_equal(result, qslash)" ), "../src/test/test-fs-util.c", 93, __PRETTY_FUNCTION__); } while (0); | |||
94 | result = mfree(result); | |||
95 | ||||
96 | p = strjoina(temp, "/slash")({ const char *_appendees_[] = { temp, "/slash" }; char *_d_, *_p_; size_t _len_ = 0; size_t _i_; for (_i_ = 0; _i_ < __extension__ (__builtin_choose_expr( !__builtin_types_compatible_p(typeof (_appendees_), typeof(&*(_appendees_))), sizeof(_appendees_ )/sizeof((_appendees_)[0]), ((void)0))) && _appendees_ [_i_]; _i_++) _len_ += strlen(_appendees_[_i_]); _p_ = _d_ = __builtin_alloca (_len_ + 1); for (_i_ = 0; _i_ < __extension__ (__builtin_choose_expr ( !__builtin_types_compatible_p(typeof(_appendees_), typeof(& *(_appendees_))), sizeof(_appendees_)/sizeof((_appendees_)[0] ), ((void)0))) && _appendees_[_i_]; _i_++) _p_ = stpcpy (_p_, _appendees_[_i_]); *_p_ = 0; _d_; }); | |||
97 | assert_se(symlink("/", p) >= 0)do { if ((__builtin_expect(!!(!(symlink("/", p) >= 0)),0)) ) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("symlink(\"/\", p) >= 0" ), "../src/test/test-fs-util.c", 97, __PRETTY_FUNCTION__); } while (0); | |||
98 | ||||
99 | r = chase_symlinks(p, NULL((void*)0), 0, &result); | |||
100 | assert_se(r > 0)do { if ((__builtin_expect(!!(!(r > 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("r > 0"), "../src/test/test-fs-util.c" , 100, __PRETTY_FUNCTION__); } while (0); | |||
101 | assert_se(path_equal(result, "/"))do { if ((__builtin_expect(!!(!(path_equal(result, "/"))),0)) ) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("path_equal(result, \"/\")" ), "../src/test/test-fs-util.c", 101, __PRETTY_FUNCTION__); } while (0); | |||
102 | result = mfree(result); | |||
103 | ||||
104 | r = chase_symlinks(p, temp, 0, &result); | |||
105 | assert_se(r > 0)do { if ((__builtin_expect(!!(!(r > 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("r > 0"), "../src/test/test-fs-util.c" , 105, __PRETTY_FUNCTION__); } while (0); | |||
106 | assert_se(path_equal(result, temp))do { if ((__builtin_expect(!!(!(path_equal(result, temp))),0) )) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("path_equal(result, temp)" ), "../src/test/test-fs-util.c", 106, __PRETTY_FUNCTION__); } while (0); | |||
107 | result = mfree(result); | |||
108 | ||||
109 | /* Paths that would "escape" outside of the "root" */ | |||
110 | ||||
111 | p = strjoina(temp, "/6dots")({ const char *_appendees_[] = { temp, "/6dots" }; char *_d_, *_p_; size_t _len_ = 0; size_t _i_; for (_i_ = 0; _i_ < __extension__ (__builtin_choose_expr( !__builtin_types_compatible_p(typeof (_appendees_), typeof(&*(_appendees_))), sizeof(_appendees_ )/sizeof((_appendees_)[0]), ((void)0))) && _appendees_ [_i_]; _i_++) _len_ += strlen(_appendees_[_i_]); _p_ = _d_ = __builtin_alloca (_len_ + 1); for (_i_ = 0; _i_ < __extension__ (__builtin_choose_expr ( !__builtin_types_compatible_p(typeof(_appendees_), typeof(& *(_appendees_))), sizeof(_appendees_)/sizeof((_appendees_)[0] ), ((void)0))) && _appendees_[_i_]; _i_++) _p_ = stpcpy (_p_, _appendees_[_i_]); *_p_ = 0; _d_; }); | |||
112 | assert_se(symlink("../../..", p) >= 0)do { if ((__builtin_expect(!!(!(symlink("../../..", p) >= 0 )),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("symlink(\"../../..\", p) >= 0" ), "../src/test/test-fs-util.c", 112, __PRETTY_FUNCTION__); } while (0); | |||
113 | ||||
114 | r = chase_symlinks(p, temp, 0, &result); | |||
115 | assert_se(r > 0 && path_equal(result, temp))do { if ((__builtin_expect(!!(!(r > 0 && path_equal (result, temp))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("r > 0 && path_equal(result, temp)"), "../src/test/test-fs-util.c" , 115, __PRETTY_FUNCTION__); } while (0); | |||
116 | result = mfree(result); | |||
117 | ||||
118 | p = strjoina(temp, "/6dotsusr")({ const char *_appendees_[] = { temp, "/6dotsusr" }; char *_d_ , *_p_; size_t _len_ = 0; size_t _i_; for (_i_ = 0; _i_ < __extension__ (__builtin_choose_expr( !__builtin_types_compatible_p(typeof (_appendees_), typeof(&*(_appendees_))), sizeof(_appendees_ )/sizeof((_appendees_)[0]), ((void)0))) && _appendees_ [_i_]; _i_++) _len_ += strlen(_appendees_[_i_]); _p_ = _d_ = __builtin_alloca (_len_ + 1); for (_i_ = 0; _i_ < __extension__ (__builtin_choose_expr ( !__builtin_types_compatible_p(typeof(_appendees_), typeof(& *(_appendees_))), sizeof(_appendees_)/sizeof((_appendees_)[0] ), ((void)0))) && _appendees_[_i_]; _i_++) _p_ = stpcpy (_p_, _appendees_[_i_]); *_p_ = 0; _d_; }); | |||
119 | assert_se(symlink("../../../usr", p) >= 0)do { if ((__builtin_expect(!!(!(symlink("../../../usr", p) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("symlink(\"../../../usr\", p) >= 0" ), "../src/test/test-fs-util.c", 119, __PRETTY_FUNCTION__); } while (0); | |||
120 | ||||
121 | r = chase_symlinks(p, temp, 0, &result); | |||
122 | assert_se(r > 0 && path_equal(result, q))do { if ((__builtin_expect(!!(!(r > 0 && path_equal (result, q))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("r > 0 && path_equal(result, q)"), "../src/test/test-fs-util.c" , 122, __PRETTY_FUNCTION__); } while (0); | |||
123 | result = mfree(result); | |||
124 | ||||
125 | p = strjoina(temp, "/top/8dotsusr")({ const char *_appendees_[] = { temp, "/top/8dotsusr" }; char *_d_, *_p_; size_t _len_ = 0; size_t _i_; for (_i_ = 0; _i_ < __extension__ (__builtin_choose_expr( !__builtin_types_compatible_p (typeof(_appendees_), typeof(&*(_appendees_))), sizeof(_appendees_ )/sizeof((_appendees_)[0]), ((void)0))) && _appendees_ [_i_]; _i_++) _len_ += strlen(_appendees_[_i_]); _p_ = _d_ = __builtin_alloca (_len_ + 1); for (_i_ = 0; _i_ < __extension__ (__builtin_choose_expr ( !__builtin_types_compatible_p(typeof(_appendees_), typeof(& *(_appendees_))), sizeof(_appendees_)/sizeof((_appendees_)[0] ), ((void)0))) && _appendees_[_i_]; _i_++) _p_ = stpcpy (_p_, _appendees_[_i_]); *_p_ = 0; _d_; }); | |||
126 | assert_se(symlink("../../../../usr", p) >= 0)do { if ((__builtin_expect(!!(!(symlink("../../../../usr", p) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("symlink(\"../../../../usr\", p) >= 0" ), "../src/test/test-fs-util.c", 126, __PRETTY_FUNCTION__); } while (0); | |||
127 | ||||
128 | r = chase_symlinks(p, temp, 0, &result); | |||
129 | assert_se(r > 0 && path_equal(result, q))do { if ((__builtin_expect(!!(!(r > 0 && path_equal (result, q))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("r > 0 && path_equal(result, q)"), "../src/test/test-fs-util.c" , 129, __PRETTY_FUNCTION__); } while (0); | |||
130 | result = mfree(result); | |||
131 | ||||
132 | /* Paths that contain repeated slashes */ | |||
133 | ||||
134 | p = strjoina(temp, "/slashslash")({ const char *_appendees_[] = { temp, "/slashslash" }; char * _d_, *_p_; size_t _len_ = 0; size_t _i_; for (_i_ = 0; _i_ < __extension__ (__builtin_choose_expr( !__builtin_types_compatible_p (typeof(_appendees_), typeof(&*(_appendees_))), sizeof(_appendees_ )/sizeof((_appendees_)[0]), ((void)0))) && _appendees_ [_i_]; _i_++) _len_ += strlen(_appendees_[_i_]); _p_ = _d_ = __builtin_alloca (_len_ + 1); for (_i_ = 0; _i_ < __extension__ (__builtin_choose_expr ( !__builtin_types_compatible_p(typeof(_appendees_), typeof(& *(_appendees_))), sizeof(_appendees_)/sizeof((_appendees_)[0] ), ((void)0))) && _appendees_[_i_]; _i_++) _p_ = stpcpy (_p_, _appendees_[_i_]); *_p_ = 0; _d_; }); | |||
135 | assert_se(symlink("///usr///", p) >= 0)do { if ((__builtin_expect(!!(!(symlink("///usr///", p) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("symlink(\"///usr///\", p) >= 0" ), "../src/test/test-fs-util.c", 135, __PRETTY_FUNCTION__); } while (0); | |||
136 | ||||
137 | r = chase_symlinks(p, NULL((void*)0), 0, &result); | |||
138 | assert_se(r > 0)do { if ((__builtin_expect(!!(!(r > 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("r > 0"), "../src/test/test-fs-util.c" , 138, __PRETTY_FUNCTION__); } while (0); | |||
139 | assert_se(path_equal(result, "/usr"))do { if ((__builtin_expect(!!(!(path_equal(result, "/usr"))), 0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("path_equal(result, \"/usr\")" ), "../src/test/test-fs-util.c", 139, __PRETTY_FUNCTION__); } while (0); | |||
140 | result = mfree(result); | |||
141 | ||||
142 | r = chase_symlinks(p, temp, 0, &result); | |||
143 | assert_se(r > 0)do { if ((__builtin_expect(!!(!(r > 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("r > 0"), "../src/test/test-fs-util.c" , 143, __PRETTY_FUNCTION__); } while (0); | |||
144 | assert_se(path_equal(result, q))do { if ((__builtin_expect(!!(!(path_equal(result, q))),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("path_equal(result, q)"), "../src/test/test-fs-util.c" , 144, __PRETTY_FUNCTION__); } while (0); | |||
145 | result = mfree(result); | |||
146 | ||||
147 | /* Paths using . */ | |||
148 | ||||
149 | r = chase_symlinks("/etc/./.././", NULL((void*)0), 0, &result); | |||
150 | assert_se(r > 0)do { if ((__builtin_expect(!!(!(r > 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("r > 0"), "../src/test/test-fs-util.c" , 150, __PRETTY_FUNCTION__); } while (0); | |||
151 | assert_se(path_equal(result, "/"))do { if ((__builtin_expect(!!(!(path_equal(result, "/"))),0)) ) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("path_equal(result, \"/\")" ), "../src/test/test-fs-util.c", 151, __PRETTY_FUNCTION__); } while (0); | |||
152 | result = mfree(result); | |||
153 | ||||
154 | r = chase_symlinks("/etc/./.././", "/etc", 0, &result); | |||
155 | assert_se(r > 0 && path_equal(result, "/etc"))do { if ((__builtin_expect(!!(!(r > 0 && path_equal (result, "/etc"))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("r > 0 && path_equal(result, \"/etc\")"), "../src/test/test-fs-util.c" , 155, __PRETTY_FUNCTION__); } while (0); | |||
156 | result = mfree(result); | |||
157 | ||||
158 | r = chase_symlinks("/../.././//../../etc", NULL((void*)0), 0, &result); | |||
159 | assert_se(r > 0)do { if ((__builtin_expect(!!(!(r > 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("r > 0"), "../src/test/test-fs-util.c" , 159, __PRETTY_FUNCTION__); } while (0); | |||
160 | assert_se(streq(result, "/etc"))do { if ((__builtin_expect(!!(!((strcmp((result),("/etc")) == 0))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq(result, \"/etc\")" ), "../src/test/test-fs-util.c", 160, __PRETTY_FUNCTION__); } while (0); | |||
161 | result = mfree(result); | |||
162 | ||||
163 | r = chase_symlinks("/../.././//../../test-chase.fsldajfl", NULL((void*)0), CHASE_NONEXISTENT, &result); | |||
164 | assert_se(r == 0)do { if ((__builtin_expect(!!(!(r == 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("r == 0"), "../src/test/test-fs-util.c", 164, __PRETTY_FUNCTION__); } while (0); | |||
165 | assert_se(streq(result, "/test-chase.fsldajfl"))do { if ((__builtin_expect(!!(!((strcmp((result),("/test-chase.fsldajfl" )) == 0))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq(result, \"/test-chase.fsldajfl\")" ), "../src/test/test-fs-util.c", 165, __PRETTY_FUNCTION__); } while (0); | |||
166 | result = mfree(result); | |||
167 | ||||
168 | r = chase_symlinks("/../.././//../../etc", "/", CHASE_PREFIX_ROOT, &result); | |||
169 | assert_se(r > 0)do { if ((__builtin_expect(!!(!(r > 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("r > 0"), "../src/test/test-fs-util.c" , 169, __PRETTY_FUNCTION__); } while (0); | |||
170 | assert_se(streq(result, "/etc"))do { if ((__builtin_expect(!!(!((strcmp((result),("/etc")) == 0))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq(result, \"/etc\")" ), "../src/test/test-fs-util.c", 170, __PRETTY_FUNCTION__); } while (0); | |||
171 | result = mfree(result); | |||
172 | ||||
173 | r = chase_symlinks("/../.././//../../test-chase.fsldajfl", "/", CHASE_PREFIX_ROOT|CHASE_NONEXISTENT, &result); | |||
174 | assert_se(r == 0)do { if ((__builtin_expect(!!(!(r == 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("r == 0"), "../src/test/test-fs-util.c", 174, __PRETTY_FUNCTION__); } while (0); | |||
175 | assert_se(streq(result, "/test-chase.fsldajfl"))do { if ((__builtin_expect(!!(!((strcmp((result),("/test-chase.fsldajfl" )) == 0))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq(result, \"/test-chase.fsldajfl\")" ), "../src/test/test-fs-util.c", 175, __PRETTY_FUNCTION__); } while (0); | |||
176 | result = mfree(result); | |||
177 | ||||
178 | r = chase_symlinks("/etc/machine-id/foo", NULL((void*)0), 0, &result); | |||
179 | assert_se(r == -ENOTDIR)do { if ((__builtin_expect(!!(!(r == -20)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("r == -ENOTDIR"), "../src/test/test-fs-util.c" , 179, __PRETTY_FUNCTION__); } while (0); | |||
180 | result = mfree(result); | |||
181 | ||||
182 | /* Path that loops back to self */ | |||
183 | ||||
184 | p = strjoina(temp, "/recursive-symlink")({ const char *_appendees_[] = { temp, "/recursive-symlink" } ; char *_d_, *_p_; size_t _len_ = 0; size_t _i_; for (_i_ = 0 ; _i_ < __extension__ (__builtin_choose_expr( !__builtin_types_compatible_p (typeof(_appendees_), typeof(&*(_appendees_))), sizeof(_appendees_ )/sizeof((_appendees_)[0]), ((void)0))) && _appendees_ [_i_]; _i_++) _len_ += strlen(_appendees_[_i_]); _p_ = _d_ = __builtin_alloca (_len_ + 1); for (_i_ = 0; _i_ < __extension__ (__builtin_choose_expr ( !__builtin_types_compatible_p(typeof(_appendees_), typeof(& *(_appendees_))), sizeof(_appendees_)/sizeof((_appendees_)[0] ), ((void)0))) && _appendees_[_i_]; _i_++) _p_ = stpcpy (_p_, _appendees_[_i_]); *_p_ = 0; _d_; }); | |||
185 | assert_se(symlink("recursive-symlink", p) >= 0)do { if ((__builtin_expect(!!(!(symlink("recursive-symlink", p ) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ( "symlink(\"recursive-symlink\", p) >= 0"), "../src/test/test-fs-util.c" , 185, __PRETTY_FUNCTION__); } while (0); | |||
186 | r = chase_symlinks(p, NULL((void*)0), 0, &result); | |||
187 | assert_se(r == -ELOOP)do { if ((__builtin_expect(!!(!(r == -40)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("r == -ELOOP"), "../src/test/test-fs-util.c" , 187, __PRETTY_FUNCTION__); } while (0); | |||
188 | ||||
189 | /* Path which doesn't exist */ | |||
190 | ||||
191 | p = strjoina(temp, "/idontexist")({ const char *_appendees_[] = { temp, "/idontexist" }; char * _d_, *_p_; size_t _len_ = 0; size_t _i_; for (_i_ = 0; _i_ < __extension__ (__builtin_choose_expr( !__builtin_types_compatible_p (typeof(_appendees_), typeof(&*(_appendees_))), sizeof(_appendees_ )/sizeof((_appendees_)[0]), ((void)0))) && _appendees_ [_i_]; _i_++) _len_ += strlen(_appendees_[_i_]); _p_ = _d_ = __builtin_alloca (_len_ + 1); for (_i_ = 0; _i_ < __extension__ (__builtin_choose_expr ( !__builtin_types_compatible_p(typeof(_appendees_), typeof(& *(_appendees_))), sizeof(_appendees_)/sizeof((_appendees_)[0] ), ((void)0))) && _appendees_[_i_]; _i_++) _p_ = stpcpy (_p_, _appendees_[_i_]); *_p_ = 0; _d_; }); | |||
192 | r = chase_symlinks(p, NULL((void*)0), 0, &result); | |||
193 | assert_se(r == -ENOENT)do { if ((__builtin_expect(!!(!(r == -2)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("r == -ENOENT"), "../src/test/test-fs-util.c" , 193, __PRETTY_FUNCTION__); } while (0); | |||
194 | ||||
195 | r = chase_symlinks(p, NULL((void*)0), CHASE_NONEXISTENT, &result); | |||
196 | assert_se(r == 0)do { if ((__builtin_expect(!!(!(r == 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("r == 0"), "../src/test/test-fs-util.c", 196, __PRETTY_FUNCTION__); } while (0); | |||
197 | assert_se(path_equal(result, p))do { if ((__builtin_expect(!!(!(path_equal(result, p))),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("path_equal(result, p)"), "../src/test/test-fs-util.c" , 197, __PRETTY_FUNCTION__); } while (0); | |||
198 | result = mfree(result); | |||
199 | ||||
200 | p = strjoina(temp, "/idontexist/meneither")({ const char *_appendees_[] = { temp, "/idontexist/meneither" }; char *_d_, *_p_; size_t _len_ = 0; size_t _i_; for (_i_ = 0; _i_ < __extension__ (__builtin_choose_expr( !__builtin_types_compatible_p (typeof(_appendees_), typeof(&*(_appendees_))), sizeof(_appendees_ )/sizeof((_appendees_)[0]), ((void)0))) && _appendees_ [_i_]; _i_++) _len_ += strlen(_appendees_[_i_]); _p_ = _d_ = __builtin_alloca (_len_ + 1); for (_i_ = 0; _i_ < __extension__ (__builtin_choose_expr ( !__builtin_types_compatible_p(typeof(_appendees_), typeof(& *(_appendees_))), sizeof(_appendees_)/sizeof((_appendees_)[0] ), ((void)0))) && _appendees_[_i_]; _i_++) _p_ = stpcpy (_p_, _appendees_[_i_]); *_p_ = 0; _d_; }); | |||
201 | r = chase_symlinks(p, NULL((void*)0), 0, &result); | |||
202 | assert_se(r == -ENOENT)do { if ((__builtin_expect(!!(!(r == -2)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("r == -ENOENT"), "../src/test/test-fs-util.c" , 202, __PRETTY_FUNCTION__); } while (0); | |||
203 | ||||
204 | r = chase_symlinks(p, NULL((void*)0), CHASE_NONEXISTENT, &result); | |||
205 | assert_se(r == 0)do { if ((__builtin_expect(!!(!(r == 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("r == 0"), "../src/test/test-fs-util.c", 205, __PRETTY_FUNCTION__); } while (0); | |||
206 | assert_se(path_equal(result, p))do { if ((__builtin_expect(!!(!(path_equal(result, p))),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("path_equal(result, p)"), "../src/test/test-fs-util.c" , 206, __PRETTY_FUNCTION__); } while (0); | |||
207 | result = mfree(result); | |||
208 | ||||
209 | /* Path which doesn't exist, but contains weird stuff */ | |||
210 | ||||
211 | p = strjoina(temp, "/idontexist/..")({ const char *_appendees_[] = { temp, "/idontexist/.." }; char *_d_, *_p_; size_t _len_ = 0; size_t _i_; for (_i_ = 0; _i_ < __extension__ (__builtin_choose_expr( !__builtin_types_compatible_p (typeof(_appendees_), typeof(&*(_appendees_))), sizeof(_appendees_ )/sizeof((_appendees_)[0]), ((void)0))) && _appendees_ [_i_]; _i_++) _len_ += strlen(_appendees_[_i_]); _p_ = _d_ = __builtin_alloca (_len_ + 1); for (_i_ = 0; _i_ < __extension__ (__builtin_choose_expr ( !__builtin_types_compatible_p(typeof(_appendees_), typeof(& *(_appendees_))), sizeof(_appendees_)/sizeof((_appendees_)[0] ), ((void)0))) && _appendees_[_i_]; _i_++) _p_ = stpcpy (_p_, _appendees_[_i_]); *_p_ = 0; _d_; }); | |||
212 | r = chase_symlinks(p, NULL((void*)0), 0, &result); | |||
213 | assert_se(r == -ENOENT)do { if ((__builtin_expect(!!(!(r == -2)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("r == -ENOENT"), "../src/test/test-fs-util.c" , 213, __PRETTY_FUNCTION__); } while (0); | |||
214 | ||||
215 | r = chase_symlinks(p, NULL((void*)0), CHASE_NONEXISTENT, &result); | |||
216 | assert_se(r == -ENOENT)do { if ((__builtin_expect(!!(!(r == -2)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("r == -ENOENT"), "../src/test/test-fs-util.c" , 216, __PRETTY_FUNCTION__); } while (0); | |||
217 | ||||
218 | p = strjoina(temp, "/target")({ const char *_appendees_[] = { temp, "/target" }; char *_d_ , *_p_; size_t _len_ = 0; size_t _i_; for (_i_ = 0; _i_ < __extension__ (__builtin_choose_expr( !__builtin_types_compatible_p(typeof (_appendees_), typeof(&*(_appendees_))), sizeof(_appendees_ )/sizeof((_appendees_)[0]), ((void)0))) && _appendees_ [_i_]; _i_++) _len_ += strlen(_appendees_[_i_]); _p_ = _d_ = __builtin_alloca (_len_ + 1); for (_i_ = 0; _i_ < __extension__ (__builtin_choose_expr ( !__builtin_types_compatible_p(typeof(_appendees_), typeof(& *(_appendees_))), sizeof(_appendees_)/sizeof((_appendees_)[0] ), ((void)0))) && _appendees_[_i_]; _i_++) _p_ = stpcpy (_p_, _appendees_[_i_]); *_p_ = 0; _d_; }); | |||
219 | q = strjoina(temp, "/top")({ const char *_appendees_[] = { temp, "/top" }; char *_d_, * _p_; size_t _len_ = 0; size_t _i_; for (_i_ = 0; _i_ < __extension__ (__builtin_choose_expr( !__builtin_types_compatible_p(typeof (_appendees_), typeof(&*(_appendees_))), sizeof(_appendees_ )/sizeof((_appendees_)[0]), ((void)0))) && _appendees_ [_i_]; _i_++) _len_ += strlen(_appendees_[_i_]); _p_ = _d_ = __builtin_alloca (_len_ + 1); for (_i_ = 0; _i_ < __extension__ (__builtin_choose_expr ( !__builtin_types_compatible_p(typeof(_appendees_), typeof(& *(_appendees_))), sizeof(_appendees_)/sizeof((_appendees_)[0] ), ((void)0))) && _appendees_[_i_]; _i_++) _p_ = stpcpy (_p_, _appendees_[_i_]); *_p_ = 0; _d_; }); | |||
220 | assert_se(symlink(q, p) >= 0)do { if ((__builtin_expect(!!(!(symlink(q, p) >= 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("symlink(q, p) >= 0"), "../src/test/test-fs-util.c" , 220, __PRETTY_FUNCTION__); } while (0); | |||
221 | p = strjoina(temp, "/target/idontexist")({ const char *_appendees_[] = { temp, "/target/idontexist" } ; char *_d_, *_p_; size_t _len_ = 0; size_t _i_; for (_i_ = 0 ; _i_ < __extension__ (__builtin_choose_expr( !__builtin_types_compatible_p (typeof(_appendees_), typeof(&*(_appendees_))), sizeof(_appendees_ )/sizeof((_appendees_)[0]), ((void)0))) && _appendees_ [_i_]; _i_++) _len_ += strlen(_appendees_[_i_]); _p_ = _d_ = __builtin_alloca (_len_ + 1); for (_i_ = 0; _i_ < __extension__ (__builtin_choose_expr ( !__builtin_types_compatible_p(typeof(_appendees_), typeof(& *(_appendees_))), sizeof(_appendees_)/sizeof((_appendees_)[0] ), ((void)0))) && _appendees_[_i_]; _i_++) _p_ = stpcpy (_p_, _appendees_[_i_]); *_p_ = 0; _d_; }); | |||
222 | r = chase_symlinks(p, NULL((void*)0), 0, &result); | |||
223 | assert_se(r == -ENOENT)do { if ((__builtin_expect(!!(!(r == -2)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("r == -ENOENT"), "../src/test/test-fs-util.c" , 223, __PRETTY_FUNCTION__); } while (0); | |||
224 | ||||
225 | if (geteuid() == 0) { | |||
226 | p = strjoina(temp, "/priv1")({ const char *_appendees_[] = { temp, "/priv1" }; char *_d_, *_p_; size_t _len_ = 0; size_t _i_; for (_i_ = 0; _i_ < __extension__ (__builtin_choose_expr( !__builtin_types_compatible_p(typeof (_appendees_), typeof(&*(_appendees_))), sizeof(_appendees_ )/sizeof((_appendees_)[0]), ((void)0))) && _appendees_ [_i_]; _i_++) _len_ += strlen(_appendees_[_i_]); _p_ = _d_ = __builtin_alloca (_len_ + 1); for (_i_ = 0; _i_ < __extension__ (__builtin_choose_expr ( !__builtin_types_compatible_p(typeof(_appendees_), typeof(& *(_appendees_))), sizeof(_appendees_)/sizeof((_appendees_)[0] ), ((void)0))) && _appendees_[_i_]; _i_++) _p_ = stpcpy (_p_, _appendees_[_i_]); *_p_ = 0; _d_; }); | |||
227 | assert_se(mkdir(p, 0755) >= 0)do { if ((__builtin_expect(!!(!(mkdir(p, 0755) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("mkdir(p, 0755) >= 0" ), "../src/test/test-fs-util.c", 227, __PRETTY_FUNCTION__); } while (0); | |||
228 | ||||
229 | q = strjoina(p, "/priv2")({ const char *_appendees_[] = { p, "/priv2" }; char *_d_, *_p_ ; size_t _len_ = 0; size_t _i_; for (_i_ = 0; _i_ < __extension__ (__builtin_choose_expr( !__builtin_types_compatible_p(typeof (_appendees_), typeof(&*(_appendees_))), sizeof(_appendees_ )/sizeof((_appendees_)[0]), ((void)0))) && _appendees_ [_i_]; _i_++) _len_ += strlen(_appendees_[_i_]); _p_ = _d_ = __builtin_alloca (_len_ + 1); for (_i_ = 0; _i_ < __extension__ (__builtin_choose_expr ( !__builtin_types_compatible_p(typeof(_appendees_), typeof(& *(_appendees_))), sizeof(_appendees_)/sizeof((_appendees_)[0] ), ((void)0))) && _appendees_[_i_]; _i_++) _p_ = stpcpy (_p_, _appendees_[_i_]); *_p_ = 0; _d_; }); | |||
230 | assert_se(mkdir(q, 0755) >= 0)do { if ((__builtin_expect(!!(!(mkdir(q, 0755) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("mkdir(q, 0755) >= 0" ), "../src/test/test-fs-util.c", 230, __PRETTY_FUNCTION__); } while (0); | |||
231 | ||||
232 | assert_se(chase_symlinks(q, NULL, CHASE_SAFE, NULL) >= 0)do { if ((__builtin_expect(!!(!(chase_symlinks(q, ((void*)0), CHASE_SAFE, ((void*)0)) >= 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("chase_symlinks(q, NULL, CHASE_SAFE, NULL) >= 0" ), "../src/test/test-fs-util.c", 232, __PRETTY_FUNCTION__); } while (0); | |||
233 | ||||
234 | assert_se(chown(q, UID_NOBODY, GID_NOBODY) >= 0)do { if ((__builtin_expect(!!(!(chown(q, ((uid_t) 65534U), (( gid_t) 65534U)) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("chown(q, UID_NOBODY, GID_NOBODY) >= 0"), "../src/test/test-fs-util.c" , 234, __PRETTY_FUNCTION__); } while (0); | |||
235 | assert_se(chase_symlinks(q, NULL, CHASE_SAFE, NULL) >= 0)do { if ((__builtin_expect(!!(!(chase_symlinks(q, ((void*)0), CHASE_SAFE, ((void*)0)) >= 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("chase_symlinks(q, NULL, CHASE_SAFE, NULL) >= 0" ), "../src/test/test-fs-util.c", 235, __PRETTY_FUNCTION__); } while (0); | |||
236 | ||||
237 | assert_se(chown(p, UID_NOBODY, GID_NOBODY) >= 0)do { if ((__builtin_expect(!!(!(chown(p, ((uid_t) 65534U), (( gid_t) 65534U)) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("chown(p, UID_NOBODY, GID_NOBODY) >= 0"), "../src/test/test-fs-util.c" , 237, __PRETTY_FUNCTION__); } while (0); | |||
238 | assert_se(chase_symlinks(q, NULL, CHASE_SAFE, NULL) >= 0)do { if ((__builtin_expect(!!(!(chase_symlinks(q, ((void*)0), CHASE_SAFE, ((void*)0)) >= 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("chase_symlinks(q, NULL, CHASE_SAFE, NULL) >= 0" ), "../src/test/test-fs-util.c", 238, __PRETTY_FUNCTION__); } while (0); | |||
239 | ||||
240 | assert_se(chown(q, 0, 0) >= 0)do { if ((__builtin_expect(!!(!(chown(q, 0, 0) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("chown(q, 0, 0) >= 0" ), "../src/test/test-fs-util.c", 240, __PRETTY_FUNCTION__); } while (0); | |||
241 | assert_se(chase_symlinks(q, NULL, CHASE_SAFE, NULL) == -EPERM)do { if ((__builtin_expect(!!(!(chase_symlinks(q, ((void*)0), CHASE_SAFE, ((void*)0)) == -1)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("chase_symlinks(q, NULL, CHASE_SAFE, NULL) == -EPERM" ), "../src/test/test-fs-util.c", 241, __PRETTY_FUNCTION__); } while (0); | |||
242 | ||||
243 | assert_se(rmdir(q) >= 0)do { if ((__builtin_expect(!!(!(rmdir(q) >= 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("rmdir(q) >= 0"), "../src/test/test-fs-util.c" , 243, __PRETTY_FUNCTION__); } while (0); | |||
244 | assert_se(symlink("/etc/passwd", q) >= 0)do { if ((__builtin_expect(!!(!(symlink("/etc/passwd", q) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("symlink(\"/etc/passwd\", q) >= 0" ), "../src/test/test-fs-util.c", 244, __PRETTY_FUNCTION__); } while (0); | |||
245 | assert_se(chase_symlinks(q, NULL, CHASE_SAFE, NULL) == -EPERM)do { if ((__builtin_expect(!!(!(chase_symlinks(q, ((void*)0), CHASE_SAFE, ((void*)0)) == -1)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("chase_symlinks(q, NULL, CHASE_SAFE, NULL) == -EPERM" ), "../src/test/test-fs-util.c", 245, __PRETTY_FUNCTION__); } while (0); | |||
246 | ||||
247 | assert_se(chown(p, 0, 0) >= 0)do { if ((__builtin_expect(!!(!(chown(p, 0, 0) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("chown(p, 0, 0) >= 0" ), "../src/test/test-fs-util.c", 247, __PRETTY_FUNCTION__); } while (0); | |||
248 | assert_se(chase_symlinks(q, NULL, CHASE_SAFE, NULL) >= 0)do { if ((__builtin_expect(!!(!(chase_symlinks(q, ((void*)0), CHASE_SAFE, ((void*)0)) >= 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("chase_symlinks(q, NULL, CHASE_SAFE, NULL) >= 0" ), "../src/test/test-fs-util.c", 248, __PRETTY_FUNCTION__); } while (0); | |||
249 | } | |||
250 | ||||
251 | p = strjoina(temp, "/machine-id-test")({ const char *_appendees_[] = { temp, "/machine-id-test" }; char *_d_, *_p_; size_t _len_ = 0; size_t _i_; for (_i_ = 0; _i_ < __extension__ (__builtin_choose_expr( !__builtin_types_compatible_p (typeof(_appendees_), typeof(&*(_appendees_))), sizeof(_appendees_ )/sizeof((_appendees_)[0]), ((void)0))) && _appendees_ [_i_]; _i_++) _len_ += strlen(_appendees_[_i_]); _p_ = _d_ = __builtin_alloca (_len_ + 1); for (_i_ = 0; _i_ < __extension__ (__builtin_choose_expr ( !__builtin_types_compatible_p(typeof(_appendees_), typeof(& *(_appendees_))), sizeof(_appendees_)/sizeof((_appendees_)[0] ), ((void)0))) && _appendees_[_i_]; _i_++) _p_ = stpcpy (_p_, _appendees_[_i_]); *_p_ = 0; _d_; }); | |||
252 | assert_se(symlink("/usr/../etc/./machine-id", p) >= 0)do { if ((__builtin_expect(!!(!(symlink("/usr/../etc/./machine-id" , p) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("symlink(\"/usr/../etc/./machine-id\", p) >= 0"), "../src/test/test-fs-util.c" , 252, __PRETTY_FUNCTION__); } while (0); | |||
253 | ||||
254 | pfd = chase_symlinks(p, NULL((void*)0), CHASE_OPEN, NULL((void*)0)); | |||
255 | if (pfd != -ENOENT2) { | |||
256 | _cleanup_close___attribute__((cleanup(closep))) int fd = -1; | |||
257 | sd_id128_t a, b; | |||
258 | ||||
259 | assert_se(pfd >= 0)do { if ((__builtin_expect(!!(!(pfd >= 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("pfd >= 0"), "../src/test/test-fs-util.c" , 259, __PRETTY_FUNCTION__); } while (0); | |||
260 | ||||
261 | fd = fd_reopen(pfd, O_RDONLY00|O_CLOEXEC02000000); | |||
262 | assert_se(fd >= 0)do { if ((__builtin_expect(!!(!(fd >= 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("fd >= 0"), "../src/test/test-fs-util.c" , 262, __PRETTY_FUNCTION__); } while (0); | |||
263 | safe_close(pfd); | |||
264 | ||||
265 | assert_se(id128_read_fd(fd, ID128_PLAIN, &a) >= 0)do { if ((__builtin_expect(!!(!(id128_read_fd(fd, ID128_PLAIN , &a) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("id128_read_fd(fd, ID128_PLAIN, &a) >= 0"), "../src/test/test-fs-util.c" , 265, __PRETTY_FUNCTION__); } while (0); | |||
266 | assert_se(sd_id128_get_machine(&b) >= 0)do { if ((__builtin_expect(!!(!(sd_id128_get_machine(&b) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("sd_id128_get_machine(&b) >= 0" ), "../src/test/test-fs-util.c", 266, __PRETTY_FUNCTION__); } while (0); | |||
267 | assert_se(sd_id128_equal(a, b))do { if ((__builtin_expect(!!(!(sd_id128_equal(a, b))),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("sd_id128_equal(a, b)"), "../src/test/test-fs-util.c" , 267, __PRETTY_FUNCTION__); } while (0); | |||
268 | } | |||
269 | ||||
270 | /* Test CHASE_ONE */ | |||
271 | ||||
272 | p = strjoina(temp, "/start")({ const char *_appendees_[] = { temp, "/start" }; char *_d_, *_p_; size_t _len_ = 0; size_t _i_; for (_i_ = 0; _i_ < __extension__ (__builtin_choose_expr( !__builtin_types_compatible_p(typeof (_appendees_), typeof(&*(_appendees_))), sizeof(_appendees_ )/sizeof((_appendees_)[0]), ((void)0))) && _appendees_ [_i_]; _i_++) _len_ += strlen(_appendees_[_i_]); _p_ = _d_ = __builtin_alloca (_len_ + 1); for (_i_ = 0; _i_ < __extension__ (__builtin_choose_expr ( !__builtin_types_compatible_p(typeof(_appendees_), typeof(& *(_appendees_))), sizeof(_appendees_)/sizeof((_appendees_)[0] ), ((void)0))) && _appendees_[_i_]; _i_++) _p_ = stpcpy (_p_, _appendees_[_i_]); *_p_ = 0; _d_; }); | |||
273 | r = chase_symlinks(p, NULL((void*)0), CHASE_STEP, &result); | |||
274 | assert_se(r == 0)do { if ((__builtin_expect(!!(!(r == 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("r == 0"), "../src/test/test-fs-util.c", 274, __PRETTY_FUNCTION__); } while (0); | |||
275 | p = strjoina(temp, "/top/dot/dotdota")({ const char *_appendees_[] = { temp, "/top/dot/dotdota" }; char *_d_, *_p_; size_t _len_ = 0; size_t _i_; for (_i_ = 0; _i_ < __extension__ (__builtin_choose_expr( !__builtin_types_compatible_p (typeof(_appendees_), typeof(&*(_appendees_))), sizeof(_appendees_ )/sizeof((_appendees_)[0]), ((void)0))) && _appendees_ [_i_]; _i_++) _len_ += strlen(_appendees_[_i_]); _p_ = _d_ = __builtin_alloca (_len_ + 1); for (_i_ = 0; _i_ < __extension__ (__builtin_choose_expr ( !__builtin_types_compatible_p(typeof(_appendees_), typeof(& *(_appendees_))), sizeof(_appendees_)/sizeof((_appendees_)[0] ), ((void)0))) && _appendees_[_i_]; _i_++) _p_ = stpcpy (_p_, _appendees_[_i_]); *_p_ = 0; _d_; }); | |||
276 | assert_se(streq(p, result))do { if ((__builtin_expect(!!(!((strcmp((p),(result)) == 0))) ,0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq(p, result)" ), "../src/test/test-fs-util.c", 276, __PRETTY_FUNCTION__); } while (0); | |||
277 | result = mfree(result); | |||
278 | ||||
279 | r = chase_symlinks(p, NULL((void*)0), CHASE_STEP, &result); | |||
280 | assert_se(r == 0)do { if ((__builtin_expect(!!(!(r == 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("r == 0"), "../src/test/test-fs-util.c", 280, __PRETTY_FUNCTION__); } while (0); | |||
281 | p = strjoina(temp, "/top/./dotdota")({ const char *_appendees_[] = { temp, "/top/./dotdota" }; char *_d_, *_p_; size_t _len_ = 0; size_t _i_; for (_i_ = 0; _i_ < __extension__ (__builtin_choose_expr( !__builtin_types_compatible_p (typeof(_appendees_), typeof(&*(_appendees_))), sizeof(_appendees_ )/sizeof((_appendees_)[0]), ((void)0))) && _appendees_ [_i_]; _i_++) _len_ += strlen(_appendees_[_i_]); _p_ = _d_ = __builtin_alloca (_len_ + 1); for (_i_ = 0; _i_ < __extension__ (__builtin_choose_expr ( !__builtin_types_compatible_p(typeof(_appendees_), typeof(& *(_appendees_))), sizeof(_appendees_)/sizeof((_appendees_)[0] ), ((void)0))) && _appendees_[_i_]; _i_++) _p_ = stpcpy (_p_, _appendees_[_i_]); *_p_ = 0; _d_; }); | |||
282 | assert_se(streq(p, result))do { if ((__builtin_expect(!!(!((strcmp((p),(result)) == 0))) ,0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq(p, result)" ), "../src/test/test-fs-util.c", 282, __PRETTY_FUNCTION__); } while (0); | |||
283 | result = mfree(result); | |||
284 | ||||
285 | r = chase_symlinks(p, NULL((void*)0), CHASE_STEP, &result); | |||
286 | assert_se(r == 0)do { if ((__builtin_expect(!!(!(r == 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("r == 0"), "../src/test/test-fs-util.c", 286, __PRETTY_FUNCTION__); } while (0); | |||
287 | p = strjoina(temp, "/top/../a")({ const char *_appendees_[] = { temp, "/top/../a" }; char *_d_ , *_p_; size_t _len_ = 0; size_t _i_; for (_i_ = 0; _i_ < __extension__ (__builtin_choose_expr( !__builtin_types_compatible_p(typeof (_appendees_), typeof(&*(_appendees_))), sizeof(_appendees_ )/sizeof((_appendees_)[0]), ((void)0))) && _appendees_ [_i_]; _i_++) _len_ += strlen(_appendees_[_i_]); _p_ = _d_ = __builtin_alloca (_len_ + 1); for (_i_ = 0; _i_ < __extension__ (__builtin_choose_expr ( !__builtin_types_compatible_p(typeof(_appendees_), typeof(& *(_appendees_))), sizeof(_appendees_)/sizeof((_appendees_)[0] ), ((void)0))) && _appendees_[_i_]; _i_++) _p_ = stpcpy (_p_, _appendees_[_i_]); *_p_ = 0; _d_; }); | |||
288 | assert_se(streq(p, result))do { if ((__builtin_expect(!!(!((strcmp((p),(result)) == 0))) ,0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq(p, result)" ), "../src/test/test-fs-util.c", 288, __PRETTY_FUNCTION__); } while (0); | |||
289 | result = mfree(result); | |||
290 | ||||
291 | r = chase_symlinks(p, NULL((void*)0), CHASE_STEP, &result); | |||
292 | assert_se(r == 0)do { if ((__builtin_expect(!!(!(r == 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("r == 0"), "../src/test/test-fs-util.c", 292, __PRETTY_FUNCTION__); } while (0); | |||
293 | p = strjoina(temp, "/a")({ const char *_appendees_[] = { temp, "/a" }; char *_d_, *_p_ ; size_t _len_ = 0; size_t _i_; for (_i_ = 0; _i_ < __extension__ (__builtin_choose_expr( !__builtin_types_compatible_p(typeof (_appendees_), typeof(&*(_appendees_))), sizeof(_appendees_ )/sizeof((_appendees_)[0]), ((void)0))) && _appendees_ [_i_]; _i_++) _len_ += strlen(_appendees_[_i_]); _p_ = _d_ = __builtin_alloca (_len_ + 1); for (_i_ = 0; _i_ < __extension__ (__builtin_choose_expr ( !__builtin_types_compatible_p(typeof(_appendees_), typeof(& *(_appendees_))), sizeof(_appendees_)/sizeof((_appendees_)[0] ), ((void)0))) && _appendees_[_i_]; _i_++) _p_ = stpcpy (_p_, _appendees_[_i_]); *_p_ = 0; _d_; }); | |||
294 | assert_se(streq(p, result))do { if ((__builtin_expect(!!(!((strcmp((p),(result)) == 0))) ,0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq(p, result)" ), "../src/test/test-fs-util.c", 294, __PRETTY_FUNCTION__); } while (0); | |||
295 | result = mfree(result); | |||
296 | ||||
297 | r = chase_symlinks(p, NULL((void*)0), CHASE_STEP, &result); | |||
298 | assert_se(r == 0)do { if ((__builtin_expect(!!(!(r == 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("r == 0"), "../src/test/test-fs-util.c", 298, __PRETTY_FUNCTION__); } while (0); | |||
299 | p = strjoina(temp, "/b")({ const char *_appendees_[] = { temp, "/b" }; char *_d_, *_p_ ; size_t _len_ = 0; size_t _i_; for (_i_ = 0; _i_ < __extension__ (__builtin_choose_expr( !__builtin_types_compatible_p(typeof (_appendees_), typeof(&*(_appendees_))), sizeof(_appendees_ )/sizeof((_appendees_)[0]), ((void)0))) && _appendees_ [_i_]; _i_++) _len_ += strlen(_appendees_[_i_]); _p_ = _d_ = __builtin_alloca (_len_ + 1); for (_i_ = 0; _i_ < __extension__ (__builtin_choose_expr ( !__builtin_types_compatible_p(typeof(_appendees_), typeof(& *(_appendees_))), sizeof(_appendees_)/sizeof((_appendees_)[0] ), ((void)0))) && _appendees_[_i_]; _i_++) _p_ = stpcpy (_p_, _appendees_[_i_]); *_p_ = 0; _d_; }); | |||
300 | assert_se(streq(p, result))do { if ((__builtin_expect(!!(!((strcmp((p),(result)) == 0))) ,0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq(p, result)" ), "../src/test/test-fs-util.c", 300, __PRETTY_FUNCTION__); } while (0); | |||
301 | result = mfree(result); | |||
302 | ||||
303 | r = chase_symlinks(p, NULL((void*)0), CHASE_STEP, &result); | |||
304 | assert_se(r == 0)do { if ((__builtin_expect(!!(!(r == 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("r == 0"), "../src/test/test-fs-util.c", 304, __PRETTY_FUNCTION__); } while (0); | |||
305 | assert_se(streq("/usr", result))do { if ((__builtin_expect(!!(!((strcmp(("/usr"),(result)) == 0))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq(\"/usr\", result)" ), "../src/test/test-fs-util.c", 305, __PRETTY_FUNCTION__); } while (0); | |||
306 | result = mfree(result); | |||
307 | ||||
308 | r = chase_symlinks("/usr", NULL((void*)0), CHASE_STEP, &result); | |||
309 | assert_se(r > 0)do { if ((__builtin_expect(!!(!(r > 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("r > 0"), "../src/test/test-fs-util.c" , 309, __PRETTY_FUNCTION__); } while (0); | |||
310 | assert_se(streq("/usr", result))do { if ((__builtin_expect(!!(!((strcmp(("/usr"),(result)) == 0))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq(\"/usr\", result)" ), "../src/test/test-fs-util.c", 310, __PRETTY_FUNCTION__); } while (0); | |||
311 | result = mfree(result); | |||
312 | ||||
313 | assert_se(rm_rf(temp, REMOVE_ROOT|REMOVE_PHYSICAL) >= 0)do { if ((__builtin_expect(!!(!(rm_rf(temp, REMOVE_ROOT|REMOVE_PHYSICAL ) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ( "rm_rf(temp, REMOVE_ROOT|REMOVE_PHYSICAL) >= 0"), "../src/test/test-fs-util.c" , 313, __PRETTY_FUNCTION__); } while (0); | |||
314 | } | |||
315 | ||||
316 | static void test_unlink_noerrno(void) { | |||
317 | char name[] = "/tmp/test-close_nointr.XXXXXX"; | |||
318 | int fd; | |||
319 | ||||
320 | fd = mkostemp_safe(name); | |||
321 | assert_se(fd >= 0)do { if ((__builtin_expect(!!(!(fd >= 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("fd >= 0"), "../src/test/test-fs-util.c" , 321, __PRETTY_FUNCTION__); } while (0); | |||
322 | assert_se(close_nointr(fd) >= 0)do { if ((__builtin_expect(!!(!(close_nointr(fd) >= 0)),0) )) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("close_nointr(fd) >= 0" ), "../src/test/test-fs-util.c", 322, __PRETTY_FUNCTION__); } while (0); | |||
323 | ||||
324 | { | |||
325 | PROTECT_ERRNO__attribute__((cleanup(_reset_errno_))) __attribute__((unused )) int _saved_errno_ = (*__errno_location ()); | |||
326 | errno(*__errno_location ()) = 42; | |||
327 | assert_se(unlink_noerrno(name) >= 0)do { if ((__builtin_expect(!!(!(unlink_noerrno(name) >= 0) ),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("unlink_noerrno(name) >= 0" ), "../src/test/test-fs-util.c", 327, __PRETTY_FUNCTION__); } while (0); | |||
328 | assert_se(errno == 42)do { if ((__builtin_expect(!!(!((*__errno_location ()) == 42) ),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("errno == 42" ), "../src/test/test-fs-util.c", 328, __PRETTY_FUNCTION__); } while (0); | |||
329 | assert_se(unlink_noerrno(name) < 0)do { if ((__builtin_expect(!!(!(unlink_noerrno(name) < 0)) ,0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("unlink_noerrno(name) < 0" ), "../src/test/test-fs-util.c", 329, __PRETTY_FUNCTION__); } while (0); | |||
330 | assert_se(errno == 42)do { if ((__builtin_expect(!!(!((*__errno_location ()) == 42) ),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("errno == 42" ), "../src/test/test-fs-util.c", 330, __PRETTY_FUNCTION__); } while (0); | |||
331 | } | |||
332 | } | |||
333 | ||||
334 | static void test_readlink_and_make_absolute(void) { | |||
335 | char tempdir[] = "/tmp/test-readlink_and_make_absolute"; | |||
336 | char name[] = "/tmp/test-readlink_and_make_absolute/original"; | |||
337 | char name2[] = "test-readlink_and_make_absolute/original"; | |||
338 | char name_alias[] = "/tmp/test-readlink_and_make_absolute-alias"; | |||
339 | char *r = NULL((void*)0); | |||
340 | _cleanup_free___attribute__((cleanup(freep))) char *pwd = NULL((void*)0); | |||
341 | ||||
342 | assert_se(mkdir_safe(tempdir, 0755, getuid(), getgid(), MKDIR_WARN_MODE) >= 0)do { if ((__builtin_expect(!!(!(mkdir_safe(tempdir, 0755, getuid (), getgid(), MKDIR_WARN_MODE) >= 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("mkdir_safe(tempdir, 0755, getuid(), getgid(), MKDIR_WARN_MODE) >= 0" ), "../src/test/test-fs-util.c", 342, __PRETTY_FUNCTION__); } while (0); | |||
343 | assert_se(touch(name) >= 0)do { if ((__builtin_expect(!!(!(touch(name) >= 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("touch(name) >= 0"), "../src/test/test-fs-util.c" , 343, __PRETTY_FUNCTION__); } while (0); | |||
344 | ||||
345 | 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-fs-util.c", 345, __PRETTY_FUNCTION__); } while (0); | |||
346 | assert_se(readlink_and_make_absolute(name_alias, &r) >= 0)do { if ((__builtin_expect(!!(!(readlink_and_make_absolute(name_alias , &r) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("readlink_and_make_absolute(name_alias, &r) >= 0"), "../src/test/test-fs-util.c", 346, __PRETTY_FUNCTION__); } while (0); | |||
347 | assert_se(streq(r, name))do { if ((__builtin_expect(!!(!((strcmp((r),(name)) == 0))),0 ))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq(r, name)" ), "../src/test/test-fs-util.c", 347, __PRETTY_FUNCTION__); } while (0); | |||
348 | free(r); | |||
349 | assert_se(unlink(name_alias) >= 0)do { if ((__builtin_expect(!!(!(unlink(name_alias) >= 0)), 0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("unlink(name_alias) >= 0" ), "../src/test/test-fs-util.c", 349, __PRETTY_FUNCTION__); } while (0); | |||
350 | ||||
351 | assert_se(safe_getcwd(&pwd) >= 0)do { if ((__builtin_expect(!!(!(safe_getcwd(&pwd) >= 0 )),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("safe_getcwd(&pwd) >= 0" ), "../src/test/test-fs-util.c", 351, __PRETTY_FUNCTION__); } while (0); | |||
352 | ||||
353 | assert_se(chdir(tempdir) >= 0)do { if ((__builtin_expect(!!(!(chdir(tempdir) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("chdir(tempdir) >= 0" ), "../src/test/test-fs-util.c", 353, __PRETTY_FUNCTION__); } while (0); | |||
354 | assert_se(symlink(name2, name_alias) >= 0)do { if ((__builtin_expect(!!(!(symlink(name2, name_alias) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("symlink(name2, name_alias) >= 0" ), "../src/test/test-fs-util.c", 354, __PRETTY_FUNCTION__); } while (0); | |||
355 | assert_se(readlink_and_make_absolute(name_alias, &r) >= 0)do { if ((__builtin_expect(!!(!(readlink_and_make_absolute(name_alias , &r) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("readlink_and_make_absolute(name_alias, &r) >= 0"), "../src/test/test-fs-util.c", 355, __PRETTY_FUNCTION__); } while (0); | |||
356 | assert_se(streq(r, name))do { if ((__builtin_expect(!!(!((strcmp((r),(name)) == 0))),0 ))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq(r, name)" ), "../src/test/test-fs-util.c", 356, __PRETTY_FUNCTION__); } while (0); | |||
357 | free(r); | |||
358 | assert_se(unlink(name_alias) >= 0)do { if ((__builtin_expect(!!(!(unlink(name_alias) >= 0)), 0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("unlink(name_alias) >= 0" ), "../src/test/test-fs-util.c", 358, __PRETTY_FUNCTION__); } while (0); | |||
359 | ||||
360 | assert_se(chdir(pwd) >= 0)do { if ((__builtin_expect(!!(!(chdir(pwd) >= 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("chdir(pwd) >= 0"), "../src/test/test-fs-util.c" , 360, __PRETTY_FUNCTION__); } while (0); | |||
361 | ||||
362 | assert_se(rm_rf(tempdir, REMOVE_ROOT|REMOVE_PHYSICAL) >= 0)do { if ((__builtin_expect(!!(!(rm_rf(tempdir, REMOVE_ROOT|REMOVE_PHYSICAL ) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ( "rm_rf(tempdir, REMOVE_ROOT|REMOVE_PHYSICAL) >= 0"), "../src/test/test-fs-util.c" , 362, __PRETTY_FUNCTION__); } while (0); | |||
363 | } | |||
364 | ||||
365 | static void test_get_files_in_directory(void) { | |||
366 | _cleanup_strv_free___attribute__((cleanup(strv_freep))) char **l = NULL((void*)0), **t = NULL((void*)0); | |||
367 | ||||
368 | assert_se(get_files_in_directory("/tmp", &l) >= 0)do { if ((__builtin_expect(!!(!(get_files_in_directory("/tmp" , &l) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("get_files_in_directory(\"/tmp\", &l) >= 0"), "../src/test/test-fs-util.c" , 368, __PRETTY_FUNCTION__); } while (0); | |||
369 | assert_se(get_files_in_directory(".", &t) >= 0)do { if ((__builtin_expect(!!(!(get_files_in_directory(".", & t) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ( "get_files_in_directory(\".\", &t) >= 0"), "../src/test/test-fs-util.c" , 369, __PRETTY_FUNCTION__); } while (0); | |||
370 | assert_se(get_files_in_directory(".", NULL) >= 0)do { if ((__builtin_expect(!!(!(get_files_in_directory(".", ( (void*)0)) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("get_files_in_directory(\".\", NULL) >= 0"), "../src/test/test-fs-util.c" , 370, __PRETTY_FUNCTION__); } while (0); | |||
371 | } | |||
372 | ||||
373 | static void test_var_tmp(void) { | |||
374 | _cleanup_free___attribute__((cleanup(freep))) char *tmpdir_backup = NULL((void*)0), *temp_backup = NULL((void*)0), *tmp_backup = NULL((void*)0); | |||
375 | const char *tmp_dir = NULL((void*)0), *t; | |||
376 | ||||
377 | t = getenv("TMPDIR"); | |||
378 | if (t) { | |||
379 | tmpdir_backup = strdup(t); | |||
380 | assert_se(tmpdir_backup)do { if ((__builtin_expect(!!(!(tmpdir_backup)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("tmpdir_backup"), "../src/test/test-fs-util.c" , 380, __PRETTY_FUNCTION__); } while (0); | |||
381 | } | |||
382 | ||||
383 | t = getenv("TEMP"); | |||
384 | if (t) { | |||
385 | temp_backup = strdup(t); | |||
386 | assert_se(temp_backup)do { if ((__builtin_expect(!!(!(temp_backup)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("temp_backup"), "../src/test/test-fs-util.c" , 386, __PRETTY_FUNCTION__); } while (0); | |||
387 | } | |||
388 | ||||
389 | t = getenv("TMP"); | |||
390 | if (t) { | |||
391 | tmp_backup = strdup(t); | |||
392 | assert_se(tmp_backup)do { if ((__builtin_expect(!!(!(tmp_backup)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("tmp_backup"), "../src/test/test-fs-util.c" , 392, __PRETTY_FUNCTION__); } while (0); | |||
393 | } | |||
394 | ||||
395 | assert_se(unsetenv("TMPDIR") >= 0)do { if ((__builtin_expect(!!(!(unsetenv("TMPDIR") >= 0)), 0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("unsetenv(\"TMPDIR\") >= 0" ), "../src/test/test-fs-util.c", 395, __PRETTY_FUNCTION__); } while (0); | |||
396 | assert_se(unsetenv("TEMP") >= 0)do { if ((__builtin_expect(!!(!(unsetenv("TEMP") >= 0)),0) )) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("unsetenv(\"TEMP\") >= 0" ), "../src/test/test-fs-util.c", 396, __PRETTY_FUNCTION__); } while (0); | |||
397 | assert_se(unsetenv("TMP") >= 0)do { if ((__builtin_expect(!!(!(unsetenv("TMP") >= 0)),0)) ) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("unsetenv(\"TMP\") >= 0" ), "../src/test/test-fs-util.c", 397, __PRETTY_FUNCTION__); } while (0); | |||
398 | ||||
399 | assert_se(var_tmp_dir(&tmp_dir) >= 0)do { if ((__builtin_expect(!!(!(var_tmp_dir(&tmp_dir) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("var_tmp_dir(&tmp_dir) >= 0" ), "../src/test/test-fs-util.c", 399, __PRETTY_FUNCTION__); } while (0); | |||
400 | assert_se(streq(tmp_dir, "/var/tmp"))do { if ((__builtin_expect(!!(!((strcmp((tmp_dir),("/var/tmp" )) == 0))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq(tmp_dir, \"/var/tmp\")" ), "../src/test/test-fs-util.c", 400, __PRETTY_FUNCTION__); } while (0); | |||
401 | ||||
402 | assert_se(setenv("TMPDIR", "/tmp", true) >= 0)do { if ((__builtin_expect(!!(!(setenv("TMPDIR", "/tmp", 1) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("setenv(\"TMPDIR\", \"/tmp\", true) >= 0" ), "../src/test/test-fs-util.c", 402, __PRETTY_FUNCTION__); } while (0); | |||
403 | assert_se(streq(getenv("TMPDIR"), "/tmp"))do { if ((__builtin_expect(!!(!((strcmp((getenv("TMPDIR")),("/tmp" )) == 0))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq(getenv(\"TMPDIR\"), \"/tmp\")" ), "../src/test/test-fs-util.c", 403, __PRETTY_FUNCTION__); } while (0); | |||
404 | ||||
405 | assert_se(var_tmp_dir(&tmp_dir) >= 0)do { if ((__builtin_expect(!!(!(var_tmp_dir(&tmp_dir) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("var_tmp_dir(&tmp_dir) >= 0" ), "../src/test/test-fs-util.c", 405, __PRETTY_FUNCTION__); } while (0); | |||
406 | assert_se(streq(tmp_dir, "/tmp"))do { if ((__builtin_expect(!!(!((strcmp((tmp_dir),("/tmp")) == 0))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq(tmp_dir, \"/tmp\")" ), "../src/test/test-fs-util.c", 406, __PRETTY_FUNCTION__); } while (0); | |||
407 | ||||
408 | assert_se(setenv("TMPDIR", "/88_does_not_exist_88", true) >= 0)do { if ((__builtin_expect(!!(!(setenv("TMPDIR", "/88_does_not_exist_88" , 1) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("setenv(\"TMPDIR\", \"/88_does_not_exist_88\", true) >= 0" ), "../src/test/test-fs-util.c", 408, __PRETTY_FUNCTION__); } while (0); | |||
409 | assert_se(streq(getenv("TMPDIR"), "/88_does_not_exist_88"))do { if ((__builtin_expect(!!(!((strcmp((getenv("TMPDIR")),("/88_does_not_exist_88" )) == 0))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq(getenv(\"TMPDIR\"), \"/88_does_not_exist_88\")" ), "../src/test/test-fs-util.c", 409, __PRETTY_FUNCTION__); } while (0); | |||
410 | ||||
411 | assert_se(var_tmp_dir(&tmp_dir) >= 0)do { if ((__builtin_expect(!!(!(var_tmp_dir(&tmp_dir) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("var_tmp_dir(&tmp_dir) >= 0" ), "../src/test/test-fs-util.c", 411, __PRETTY_FUNCTION__); } while (0); | |||
412 | assert_se(streq(tmp_dir, "/var/tmp"))do { if ((__builtin_expect(!!(!((strcmp((tmp_dir),("/var/tmp" )) == 0))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq(tmp_dir, \"/var/tmp\")" ), "../src/test/test-fs-util.c", 412, __PRETTY_FUNCTION__); } while (0); | |||
413 | ||||
414 | if (tmpdir_backup
| |||
415 | assert_se(setenv("TMPDIR", tmpdir_backup, true) >= 0)do { if ((__builtin_expect(!!(!(setenv("TMPDIR", tmpdir_backup , 1) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("setenv(\"TMPDIR\", tmpdir_backup, true) >= 0"), "../src/test/test-fs-util.c" , 415, __PRETTY_FUNCTION__); } while (0); | |||
416 | assert_se(streq(getenv("TMPDIR"), tmpdir_backup))do { if ((__builtin_expect(!!(!((strcmp((getenv("TMPDIR")),(tmpdir_backup )) == 0))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq(getenv(\"TMPDIR\"), tmpdir_backup)" ), "../src/test/test-fs-util.c", 416, __PRETTY_FUNCTION__); } while (0); | |||
| ||||
417 | } | |||
418 | ||||
419 | if (temp_backup) { | |||
420 | assert_se(setenv("TEMP", temp_backup, true) >= 0)do { if ((__builtin_expect(!!(!(setenv("TEMP", temp_backup, 1 ) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ( "setenv(\"TEMP\", temp_backup, true) >= 0"), "../src/test/test-fs-util.c" , 420, __PRETTY_FUNCTION__); } while (0); | |||
421 | assert_se(streq(getenv("TEMP"), temp_backup))do { if ((__builtin_expect(!!(!((strcmp((getenv("TEMP")),(temp_backup )) == 0))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq(getenv(\"TEMP\"), temp_backup)" ), "../src/test/test-fs-util.c", 421, __PRETTY_FUNCTION__); } while (0); | |||
422 | } | |||
423 | ||||
424 | if (tmp_backup) { | |||
425 | assert_se(setenv("TMP", tmp_backup, true) >= 0)do { if ((__builtin_expect(!!(!(setenv("TMP", tmp_backup, 1) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("setenv(\"TMP\", tmp_backup, true) >= 0" ), "../src/test/test-fs-util.c", 425, __PRETTY_FUNCTION__); } while (0); | |||
426 | assert_se(streq(getenv("TMP"), tmp_backup))do { if ((__builtin_expect(!!(!((strcmp((getenv("TMP")),(tmp_backup )) == 0))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq(getenv(\"TMP\"), tmp_backup)" ), "../src/test/test-fs-util.c", 426, __PRETTY_FUNCTION__); } while (0); | |||
427 | } | |||
428 | } | |||
429 | ||||
430 | static void test_dot_or_dot_dot(void) { | |||
431 | assert_se(!dot_or_dot_dot(NULL))do { if ((__builtin_expect(!!(!(!dot_or_dot_dot(((void*)0)))) ,0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("!dot_or_dot_dot(NULL)" ), "../src/test/test-fs-util.c", 431, __PRETTY_FUNCTION__); } while (0); | |||
432 | assert_se(!dot_or_dot_dot(""))do { if ((__builtin_expect(!!(!(!dot_or_dot_dot(""))),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("!dot_or_dot_dot(\"\")"), "../src/test/test-fs-util.c" , 432, __PRETTY_FUNCTION__); } while (0); | |||
433 | assert_se(!dot_or_dot_dot("xxx"))do { if ((__builtin_expect(!!(!(!dot_or_dot_dot("xxx"))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("!dot_or_dot_dot(\"xxx\")" ), "../src/test/test-fs-util.c", 433, __PRETTY_FUNCTION__); } while (0); | |||
434 | assert_se(dot_or_dot_dot("."))do { if ((__builtin_expect(!!(!(dot_or_dot_dot("."))),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("dot_or_dot_dot(\".\")"), "../src/test/test-fs-util.c" , 434, __PRETTY_FUNCTION__); } while (0); | |||
435 | assert_se(dot_or_dot_dot(".."))do { if ((__builtin_expect(!!(!(dot_or_dot_dot(".."))),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("dot_or_dot_dot(\"..\")"), "../src/test/test-fs-util.c" , 435, __PRETTY_FUNCTION__); } while (0); | |||
436 | assert_se(!dot_or_dot_dot(".foo"))do { if ((__builtin_expect(!!(!(!dot_or_dot_dot(".foo"))),0)) ) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("!dot_or_dot_dot(\".foo\")" ), "../src/test/test-fs-util.c", 436, __PRETTY_FUNCTION__); } while (0); | |||
437 | assert_se(!dot_or_dot_dot("..foo"))do { if ((__builtin_expect(!!(!(!dot_or_dot_dot("..foo"))),0) )) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("!dot_or_dot_dot(\"..foo\")" ), "../src/test/test-fs-util.c", 437, __PRETTY_FUNCTION__); } while (0); | |||
438 | } | |||
439 | ||||
440 | static void test_access_fd(void) { | |||
441 | _cleanup_(rmdir_and_freep)__attribute__((cleanup(rmdir_and_freep))) char *p = NULL((void*)0); | |||
442 | _cleanup_close___attribute__((cleanup(closep))) int fd = -1; | |||
443 | ||||
444 | assert_se(mkdtemp_malloc("/tmp/access-fd.XXXXXX", &p) >= 0)do { if ((__builtin_expect(!!(!(mkdtemp_malloc("/tmp/access-fd.XXXXXX" , &p) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("mkdtemp_malloc(\"/tmp/access-fd.XXXXXX\", &p) >= 0" ), "../src/test/test-fs-util.c", 444, __PRETTY_FUNCTION__); } while (0); | |||
445 | ||||
446 | fd = open(p, O_RDONLY00|O_DIRECTORY0200000|O_CLOEXEC02000000); | |||
447 | assert_se(fd >= 0)do { if ((__builtin_expect(!!(!(fd >= 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("fd >= 0"), "../src/test/test-fs-util.c" , 447, __PRETTY_FUNCTION__); } while (0); | |||
448 | ||||
449 | assert_se(access_fd(fd, R_OK) >= 0)do { if ((__builtin_expect(!!(!(access_fd(fd, 4) >= 0)),0) )) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("access_fd(fd, R_OK) >= 0" ), "../src/test/test-fs-util.c", 449, __PRETTY_FUNCTION__); } while (0); | |||
450 | assert_se(access_fd(fd, F_OK) >= 0)do { if ((__builtin_expect(!!(!(access_fd(fd, 0) >= 0)),0) )) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("access_fd(fd, F_OK) >= 0" ), "../src/test/test-fs-util.c", 450, __PRETTY_FUNCTION__); } while (0); | |||
451 | assert_se(access_fd(fd, W_OK) >= 0)do { if ((__builtin_expect(!!(!(access_fd(fd, 2) >= 0)),0) )) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("access_fd(fd, W_OK) >= 0" ), "../src/test/test-fs-util.c", 451, __PRETTY_FUNCTION__); } while (0); | |||
452 | ||||
453 | assert_se(fchmod(fd, 0000) >= 0)do { if ((__builtin_expect(!!(!(fchmod(fd, 0000) >= 0)),0) )) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("fchmod(fd, 0000) >= 0" ), "../src/test/test-fs-util.c", 453, __PRETTY_FUNCTION__); } while (0); | |||
454 | ||||
455 | assert_se(access_fd(fd, F_OK) >= 0)do { if ((__builtin_expect(!!(!(access_fd(fd, 0) >= 0)),0) )) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("access_fd(fd, F_OK) >= 0" ), "../src/test/test-fs-util.c", 455, __PRETTY_FUNCTION__); } while (0); | |||
456 | ||||
457 | if (geteuid() == 0) { | |||
458 | assert_se(access_fd(fd, R_OK) >= 0)do { if ((__builtin_expect(!!(!(access_fd(fd, 4) >= 0)),0) )) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("access_fd(fd, R_OK) >= 0" ), "../src/test/test-fs-util.c", 458, __PRETTY_FUNCTION__); } while (0); | |||
459 | assert_se(access_fd(fd, W_OK) >= 0)do { if ((__builtin_expect(!!(!(access_fd(fd, 2) >= 0)),0) )) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("access_fd(fd, W_OK) >= 0" ), "../src/test/test-fs-util.c", 459, __PRETTY_FUNCTION__); } while (0); | |||
460 | } else { | |||
461 | assert_se(access_fd(fd, R_OK) == -EACCES)do { if ((__builtin_expect(!!(!(access_fd(fd, 4) == -13)),0)) ) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("access_fd(fd, R_OK) == -EACCES" ), "../src/test/test-fs-util.c", 461, __PRETTY_FUNCTION__); } while (0); | |||
462 | assert_se(access_fd(fd, W_OK) == -EACCES)do { if ((__builtin_expect(!!(!(access_fd(fd, 2) == -13)),0)) ) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("access_fd(fd, W_OK) == -EACCES" ), "../src/test/test-fs-util.c", 462, __PRETTY_FUNCTION__); } while (0); | |||
463 | } | |||
464 | } | |||
465 | ||||
466 | static void test_touch_file(void) { | |||
467 | uid_t test_uid, test_gid; | |||
468 | _cleanup_(rm_rf_physical_and_freep)__attribute__((cleanup(rm_rf_physical_and_freep))) char *p = NULL((void*)0); | |||
469 | struct stat st; | |||
470 | const char *a; | |||
471 | usec_t test_mtime; | |||
472 | int r; | |||
473 | ||||
474 | test_uid = geteuid() == 0 ? 65534 : getuid(); | |||
475 | test_gid = geteuid() == 0 ? 65534 : getgid(); | |||
476 | ||||
477 | test_mtime = usec_sub_unsigned(now(CLOCK_REALTIME0), USEC_PER_WEEK((usec_t) (7ULL*((usec_t) (24ULL*((usec_t) (60ULL*((usec_t) ( 60ULL*((usec_t) 1000000ULL)))))))))); | |||
478 | ||||
479 | assert_se(mkdtemp_malloc("/dev/shm/touch-file-XXXXXX", &p) >= 0)do { if ((__builtin_expect(!!(!(mkdtemp_malloc("/dev/shm/touch-file-XXXXXX" , &p) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("mkdtemp_malloc(\"/dev/shm/touch-file-XXXXXX\", &p) >= 0" ), "../src/test/test-fs-util.c", 479, __PRETTY_FUNCTION__); } while (0); | |||
480 | ||||
481 | a = strjoina(p, "/regular")({ const char *_appendees_[] = { p, "/regular" }; char *_d_, * _p_; size_t _len_ = 0; size_t _i_; for (_i_ = 0; _i_ < __extension__ (__builtin_choose_expr( !__builtin_types_compatible_p(typeof (_appendees_), typeof(&*(_appendees_))), sizeof(_appendees_ )/sizeof((_appendees_)[0]), ((void)0))) && _appendees_ [_i_]; _i_++) _len_ += strlen(_appendees_[_i_]); _p_ = _d_ = __builtin_alloca (_len_ + 1); for (_i_ = 0; _i_ < __extension__ (__builtin_choose_expr ( !__builtin_types_compatible_p(typeof(_appendees_), typeof(& *(_appendees_))), sizeof(_appendees_)/sizeof((_appendees_)[0] ), ((void)0))) && _appendees_[_i_]; _i_++) _p_ = stpcpy (_p_, _appendees_[_i_]); *_p_ = 0; _d_; }); | |||
482 | assert_se(touch_file(a, false, test_mtime, test_uid, test_gid, 0640) >= 0)do { if ((__builtin_expect(!!(!(touch_file(a, 0, test_mtime, test_uid , test_gid, 0640) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("touch_file(a, false, test_mtime, test_uid, test_gid, 0640) >= 0" ), "../src/test/test-fs-util.c", 482, __PRETTY_FUNCTION__); } while (0); | |||
483 | assert_se(lstat(a, &st) >= 0)do { if ((__builtin_expect(!!(!(lstat(a, &st) >= 0)),0 ))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("lstat(a, &st) >= 0" ), "../src/test/test-fs-util.c", 483, __PRETTY_FUNCTION__); } while (0); | |||
484 | assert_se(st.st_uid == test_uid)do { if ((__builtin_expect(!!(!(st.st_uid == test_uid)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("st.st_uid == test_uid"), "../src/test/test-fs-util.c" , 484, __PRETTY_FUNCTION__); } while (0); | |||
485 | assert_se(st.st_gid == test_gid)do { if ((__builtin_expect(!!(!(st.st_gid == test_gid)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("st.st_gid == test_gid"), "../src/test/test-fs-util.c" , 485, __PRETTY_FUNCTION__); } while (0); | |||
486 | assert_se(S_ISREG(st.st_mode))do { if ((__builtin_expect(!!(!(((((st.st_mode)) & 0170000 ) == (0100000)))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("S_ISREG(st.st_mode)"), "../src/test/test-fs-util.c", 486, __PRETTY_FUNCTION__); } while (0); | |||
487 | assert_se((st.st_mode & 0777) == 0640)do { if ((__builtin_expect(!!(!((st.st_mode & 0777) == 0640 )),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("(st.st_mode & 0777) == 0640" ), "../src/test/test-fs-util.c", 487, __PRETTY_FUNCTION__); } while (0); | |||
488 | assert_se(timespec_load(&st.st_mtim) == test_mtime)do { if ((__builtin_expect(!!(!(timespec_load(&st.st_mtim ) == test_mtime)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("timespec_load(&st.st_mtim) == test_mtime"), "../src/test/test-fs-util.c" , 488, __PRETTY_FUNCTION__); } while (0); | |||
489 | ||||
490 | a = strjoina(p, "/dir")({ const char *_appendees_[] = { p, "/dir" }; char *_d_, *_p_ ; size_t _len_ = 0; size_t _i_; for (_i_ = 0; _i_ < __extension__ (__builtin_choose_expr( !__builtin_types_compatible_p(typeof (_appendees_), typeof(&*(_appendees_))), sizeof(_appendees_ )/sizeof((_appendees_)[0]), ((void)0))) && _appendees_ [_i_]; _i_++) _len_ += strlen(_appendees_[_i_]); _p_ = _d_ = __builtin_alloca (_len_ + 1); for (_i_ = 0; _i_ < __extension__ (__builtin_choose_expr ( !__builtin_types_compatible_p(typeof(_appendees_), typeof(& *(_appendees_))), sizeof(_appendees_)/sizeof((_appendees_)[0] ), ((void)0))) && _appendees_[_i_]; _i_++) _p_ = stpcpy (_p_, _appendees_[_i_]); *_p_ = 0; _d_; }); | |||
491 | assert_se(mkdir(a, 0775) >= 0)do { if ((__builtin_expect(!!(!(mkdir(a, 0775) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("mkdir(a, 0775) >= 0" ), "../src/test/test-fs-util.c", 491, __PRETTY_FUNCTION__); } while (0); | |||
492 | assert_se(touch_file(a, false, test_mtime, test_uid, test_gid, 0640) >= 0)do { if ((__builtin_expect(!!(!(touch_file(a, 0, test_mtime, test_uid , test_gid, 0640) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("touch_file(a, false, test_mtime, test_uid, test_gid, 0640) >= 0" ), "../src/test/test-fs-util.c", 492, __PRETTY_FUNCTION__); } while (0); | |||
493 | assert_se(lstat(a, &st) >= 0)do { if ((__builtin_expect(!!(!(lstat(a, &st) >= 0)),0 ))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("lstat(a, &st) >= 0" ), "../src/test/test-fs-util.c", 493, __PRETTY_FUNCTION__); } while (0); | |||
494 | assert_se(st.st_uid == test_uid)do { if ((__builtin_expect(!!(!(st.st_uid == test_uid)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("st.st_uid == test_uid"), "../src/test/test-fs-util.c" , 494, __PRETTY_FUNCTION__); } while (0); | |||
495 | assert_se(st.st_gid == test_gid)do { if ((__builtin_expect(!!(!(st.st_gid == test_gid)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("st.st_gid == test_gid"), "../src/test/test-fs-util.c" , 495, __PRETTY_FUNCTION__); } while (0); | |||
496 | assert_se(S_ISDIR(st.st_mode))do { if ((__builtin_expect(!!(!(((((st.st_mode)) & 0170000 ) == (0040000)))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("S_ISDIR(st.st_mode)"), "../src/test/test-fs-util.c", 496, __PRETTY_FUNCTION__); } while (0); | |||
497 | assert_se((st.st_mode & 0777) == 0640)do { if ((__builtin_expect(!!(!((st.st_mode & 0777) == 0640 )),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("(st.st_mode & 0777) == 0640" ), "../src/test/test-fs-util.c", 497, __PRETTY_FUNCTION__); } while (0); | |||
498 | assert_se(timespec_load(&st.st_mtim) == test_mtime)do { if ((__builtin_expect(!!(!(timespec_load(&st.st_mtim ) == test_mtime)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("timespec_load(&st.st_mtim) == test_mtime"), "../src/test/test-fs-util.c" , 498, __PRETTY_FUNCTION__); } while (0); | |||
499 | ||||
500 | a = strjoina(p, "/fifo")({ const char *_appendees_[] = { p, "/fifo" }; char *_d_, *_p_ ; size_t _len_ = 0; size_t _i_; for (_i_ = 0; _i_ < __extension__ (__builtin_choose_expr( !__builtin_types_compatible_p(typeof (_appendees_), typeof(&*(_appendees_))), sizeof(_appendees_ )/sizeof((_appendees_)[0]), ((void)0))) && _appendees_ [_i_]; _i_++) _len_ += strlen(_appendees_[_i_]); _p_ = _d_ = __builtin_alloca (_len_ + 1); for (_i_ = 0; _i_ < __extension__ (__builtin_choose_expr ( !__builtin_types_compatible_p(typeof(_appendees_), typeof(& *(_appendees_))), sizeof(_appendees_)/sizeof((_appendees_)[0] ), ((void)0))) && _appendees_[_i_]; _i_++) _p_ = stpcpy (_p_, _appendees_[_i_]); *_p_ = 0; _d_; }); | |||
501 | assert_se(mkfifo(a, 0775) >= 0)do { if ((__builtin_expect(!!(!(mkfifo(a, 0775) >= 0)),0)) ) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("mkfifo(a, 0775) >= 0" ), "../src/test/test-fs-util.c", 501, __PRETTY_FUNCTION__); } while (0); | |||
502 | assert_se(touch_file(a, false, test_mtime, test_uid, test_gid, 0640) >= 0)do { if ((__builtin_expect(!!(!(touch_file(a, 0, test_mtime, test_uid , test_gid, 0640) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("touch_file(a, false, test_mtime, test_uid, test_gid, 0640) >= 0" ), "../src/test/test-fs-util.c", 502, __PRETTY_FUNCTION__); } while (0); | |||
503 | assert_se(lstat(a, &st) >= 0)do { if ((__builtin_expect(!!(!(lstat(a, &st) >= 0)),0 ))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("lstat(a, &st) >= 0" ), "../src/test/test-fs-util.c", 503, __PRETTY_FUNCTION__); } while (0); | |||
504 | assert_se(st.st_uid == test_uid)do { if ((__builtin_expect(!!(!(st.st_uid == test_uid)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("st.st_uid == test_uid"), "../src/test/test-fs-util.c" , 504, __PRETTY_FUNCTION__); } while (0); | |||
505 | assert_se(st.st_gid == test_gid)do { if ((__builtin_expect(!!(!(st.st_gid == test_gid)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("st.st_gid == test_gid"), "../src/test/test-fs-util.c" , 505, __PRETTY_FUNCTION__); } while (0); | |||
506 | assert_se(S_ISFIFO(st.st_mode))do { if ((__builtin_expect(!!(!(((((st.st_mode)) & 0170000 ) == (0010000)))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("S_ISFIFO(st.st_mode)"), "../src/test/test-fs-util.c", 506 , __PRETTY_FUNCTION__); } while (0); | |||
507 | assert_se((st.st_mode & 0777) == 0640)do { if ((__builtin_expect(!!(!((st.st_mode & 0777) == 0640 )),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("(st.st_mode & 0777) == 0640" ), "../src/test/test-fs-util.c", 507, __PRETTY_FUNCTION__); } while (0); | |||
508 | assert_se(timespec_load(&st.st_mtim) == test_mtime)do { if ((__builtin_expect(!!(!(timespec_load(&st.st_mtim ) == test_mtime)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("timespec_load(&st.st_mtim) == test_mtime"), "../src/test/test-fs-util.c" , 508, __PRETTY_FUNCTION__); } while (0); | |||
509 | ||||
510 | a = strjoina(p, "/sock")({ const char *_appendees_[] = { p, "/sock" }; char *_d_, *_p_ ; size_t _len_ = 0; size_t _i_; for (_i_ = 0; _i_ < __extension__ (__builtin_choose_expr( !__builtin_types_compatible_p(typeof (_appendees_), typeof(&*(_appendees_))), sizeof(_appendees_ )/sizeof((_appendees_)[0]), ((void)0))) && _appendees_ [_i_]; _i_++) _len_ += strlen(_appendees_[_i_]); _p_ = _d_ = __builtin_alloca (_len_ + 1); for (_i_ = 0; _i_ < __extension__ (__builtin_choose_expr ( !__builtin_types_compatible_p(typeof(_appendees_), typeof(& *(_appendees_))), sizeof(_appendees_)/sizeof((_appendees_)[0] ), ((void)0))) && _appendees_[_i_]; _i_++) _p_ = stpcpy (_p_, _appendees_[_i_]); *_p_ = 0; _d_; }); | |||
511 | assert_se(mknod(a, 0775 | S_IFSOCK, 0) >= 0)do { if ((__builtin_expect(!!(!(mknod(a, 0775 | 0140000, 0) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("mknod(a, 0775 | S_IFSOCK, 0) >= 0" ), "../src/test/test-fs-util.c", 511, __PRETTY_FUNCTION__); } while (0); | |||
512 | assert_se(touch_file(a, false, test_mtime, test_uid, test_gid, 0640) >= 0)do { if ((__builtin_expect(!!(!(touch_file(a, 0, test_mtime, test_uid , test_gid, 0640) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("touch_file(a, false, test_mtime, test_uid, test_gid, 0640) >= 0" ), "../src/test/test-fs-util.c", 512, __PRETTY_FUNCTION__); } while (0); | |||
513 | assert_se(lstat(a, &st) >= 0)do { if ((__builtin_expect(!!(!(lstat(a, &st) >= 0)),0 ))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("lstat(a, &st) >= 0" ), "../src/test/test-fs-util.c", 513, __PRETTY_FUNCTION__); } while (0); | |||
514 | assert_se(st.st_uid == test_uid)do { if ((__builtin_expect(!!(!(st.st_uid == test_uid)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("st.st_uid == test_uid"), "../src/test/test-fs-util.c" , 514, __PRETTY_FUNCTION__); } while (0); | |||
515 | assert_se(st.st_gid == test_gid)do { if ((__builtin_expect(!!(!(st.st_gid == test_gid)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("st.st_gid == test_gid"), "../src/test/test-fs-util.c" , 515, __PRETTY_FUNCTION__); } while (0); | |||
516 | assert_se(S_ISSOCK(st.st_mode))do { if ((__builtin_expect(!!(!(((((st.st_mode)) & 0170000 ) == (0140000)))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("S_ISSOCK(st.st_mode)"), "../src/test/test-fs-util.c", 516 , __PRETTY_FUNCTION__); } while (0); | |||
517 | assert_se((st.st_mode & 0777) == 0640)do { if ((__builtin_expect(!!(!((st.st_mode & 0777) == 0640 )),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("(st.st_mode & 0777) == 0640" ), "../src/test/test-fs-util.c", 517, __PRETTY_FUNCTION__); } while (0); | |||
518 | assert_se(timespec_load(&st.st_mtim) == test_mtime)do { if ((__builtin_expect(!!(!(timespec_load(&st.st_mtim ) == test_mtime)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("timespec_load(&st.st_mtim) == test_mtime"), "../src/test/test-fs-util.c" , 518, __PRETTY_FUNCTION__); } while (0); | |||
519 | ||||
520 | if (geteuid() == 0) { | |||
521 | a = strjoina(p, "/cdev")({ const char *_appendees_[] = { p, "/cdev" }; char *_d_, *_p_ ; size_t _len_ = 0; size_t _i_; for (_i_ = 0; _i_ < __extension__ (__builtin_choose_expr( !__builtin_types_compatible_p(typeof (_appendees_), typeof(&*(_appendees_))), sizeof(_appendees_ )/sizeof((_appendees_)[0]), ((void)0))) && _appendees_ [_i_]; _i_++) _len_ += strlen(_appendees_[_i_]); _p_ = _d_ = __builtin_alloca (_len_ + 1); for (_i_ = 0; _i_ < __extension__ (__builtin_choose_expr ( !__builtin_types_compatible_p(typeof(_appendees_), typeof(& *(_appendees_))), sizeof(_appendees_)/sizeof((_appendees_)[0] ), ((void)0))) && _appendees_[_i_]; _i_++) _p_ = stpcpy (_p_, _appendees_[_i_]); *_p_ = 0; _d_; }); | |||
522 | r = mknod(a, 0775 | S_IFCHR0020000, makedev(0, 0)gnu_dev_makedev (0, 0)); | |||
523 | if (r < 0 && errno(*__errno_location ()) == EPERM1 && detect_container() > 0) { | |||
524 | log_notice("Running in unprivileged container? Skipping remaining tests in %s", __func__)({ int _level = (((5))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/test/test-fs-util.c", 524, __func__, "Running in unprivileged container? Skipping remaining tests in %s" , __func__) : -abs(_e); }); | |||
525 | return; | |||
526 | } | |||
527 | assert_se(r >= 0)do { if ((__builtin_expect(!!(!(r >= 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("r >= 0"), "../src/test/test-fs-util.c" , 527, __PRETTY_FUNCTION__); } while (0); | |||
528 | assert_se(touch_file(a, false, test_mtime, test_uid, test_gid, 0640) >= 0)do { if ((__builtin_expect(!!(!(touch_file(a, 0, test_mtime, test_uid , test_gid, 0640) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("touch_file(a, false, test_mtime, test_uid, test_gid, 0640) >= 0" ), "../src/test/test-fs-util.c", 528, __PRETTY_FUNCTION__); } while (0); | |||
529 | assert_se(lstat(a, &st) >= 0)do { if ((__builtin_expect(!!(!(lstat(a, &st) >= 0)),0 ))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("lstat(a, &st) >= 0" ), "../src/test/test-fs-util.c", 529, __PRETTY_FUNCTION__); } while (0); | |||
530 | assert_se(st.st_uid == test_uid)do { if ((__builtin_expect(!!(!(st.st_uid == test_uid)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("st.st_uid == test_uid"), "../src/test/test-fs-util.c" , 530, __PRETTY_FUNCTION__); } while (0); | |||
531 | assert_se(st.st_gid == test_gid)do { if ((__builtin_expect(!!(!(st.st_gid == test_gid)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("st.st_gid == test_gid"), "../src/test/test-fs-util.c" , 531, __PRETTY_FUNCTION__); } while (0); | |||
532 | assert_se(S_ISCHR(st.st_mode))do { if ((__builtin_expect(!!(!(((((st.st_mode)) & 0170000 ) == (0020000)))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("S_ISCHR(st.st_mode)"), "../src/test/test-fs-util.c", 532, __PRETTY_FUNCTION__); } while (0); | |||
533 | assert_se((st.st_mode & 0777) == 0640)do { if ((__builtin_expect(!!(!((st.st_mode & 0777) == 0640 )),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("(st.st_mode & 0777) == 0640" ), "../src/test/test-fs-util.c", 533, __PRETTY_FUNCTION__); } while (0); | |||
534 | assert_se(timespec_load(&st.st_mtim) == test_mtime)do { if ((__builtin_expect(!!(!(timespec_load(&st.st_mtim ) == test_mtime)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("timespec_load(&st.st_mtim) == test_mtime"), "../src/test/test-fs-util.c" , 534, __PRETTY_FUNCTION__); } while (0); | |||
535 | ||||
536 | a = strjoina(p, "/bdev")({ const char *_appendees_[] = { p, "/bdev" }; char *_d_, *_p_ ; size_t _len_ = 0; size_t _i_; for (_i_ = 0; _i_ < __extension__ (__builtin_choose_expr( !__builtin_types_compatible_p(typeof (_appendees_), typeof(&*(_appendees_))), sizeof(_appendees_ )/sizeof((_appendees_)[0]), ((void)0))) && _appendees_ [_i_]; _i_++) _len_ += strlen(_appendees_[_i_]); _p_ = _d_ = __builtin_alloca (_len_ + 1); for (_i_ = 0; _i_ < __extension__ (__builtin_choose_expr ( !__builtin_types_compatible_p(typeof(_appendees_), typeof(& *(_appendees_))), sizeof(_appendees_)/sizeof((_appendees_)[0] ), ((void)0))) && _appendees_[_i_]; _i_++) _p_ = stpcpy (_p_, _appendees_[_i_]); *_p_ = 0; _d_; }); | |||
537 | assert_se(mknod(a, 0775 | S_IFBLK, makedev(0, 0)) >= 0)do { if ((__builtin_expect(!!(!(mknod(a, 0775 | 0060000, gnu_dev_makedev (0, 0)) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("mknod(a, 0775 | S_IFBLK, makedev(0, 0)) >= 0"), "../src/test/test-fs-util.c" , 537, __PRETTY_FUNCTION__); } while (0); | |||
538 | assert_se(touch_file(a, false, test_mtime, test_uid, test_gid, 0640) >= 0)do { if ((__builtin_expect(!!(!(touch_file(a, 0, test_mtime, test_uid , test_gid, 0640) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("touch_file(a, false, test_mtime, test_uid, test_gid, 0640) >= 0" ), "../src/test/test-fs-util.c", 538, __PRETTY_FUNCTION__); } while (0); | |||
539 | assert_se(lstat(a, &st) >= 0)do { if ((__builtin_expect(!!(!(lstat(a, &st) >= 0)),0 ))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("lstat(a, &st) >= 0" ), "../src/test/test-fs-util.c", 539, __PRETTY_FUNCTION__); } while (0); | |||
540 | assert_se(st.st_uid == test_uid)do { if ((__builtin_expect(!!(!(st.st_uid == test_uid)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("st.st_uid == test_uid"), "../src/test/test-fs-util.c" , 540, __PRETTY_FUNCTION__); } while (0); | |||
541 | assert_se(st.st_gid == test_gid)do { if ((__builtin_expect(!!(!(st.st_gid == test_gid)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("st.st_gid == test_gid"), "../src/test/test-fs-util.c" , 541, __PRETTY_FUNCTION__); } while (0); | |||
542 | assert_se(S_ISBLK(st.st_mode))do { if ((__builtin_expect(!!(!(((((st.st_mode)) & 0170000 ) == (0060000)))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("S_ISBLK(st.st_mode)"), "../src/test/test-fs-util.c", 542, __PRETTY_FUNCTION__); } while (0); | |||
543 | assert_se((st.st_mode & 0777) == 0640)do { if ((__builtin_expect(!!(!((st.st_mode & 0777) == 0640 )),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("(st.st_mode & 0777) == 0640" ), "../src/test/test-fs-util.c", 543, __PRETTY_FUNCTION__); } while (0); | |||
544 | assert_se(timespec_load(&st.st_mtim) == test_mtime)do { if ((__builtin_expect(!!(!(timespec_load(&st.st_mtim ) == test_mtime)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("timespec_load(&st.st_mtim) == test_mtime"), "../src/test/test-fs-util.c" , 544, __PRETTY_FUNCTION__); } while (0); | |||
545 | } | |||
546 | ||||
547 | a = strjoina(p, "/lnk")({ const char *_appendees_[] = { p, "/lnk" }; char *_d_, *_p_ ; size_t _len_ = 0; size_t _i_; for (_i_ = 0; _i_ < __extension__ (__builtin_choose_expr( !__builtin_types_compatible_p(typeof (_appendees_), typeof(&*(_appendees_))), sizeof(_appendees_ )/sizeof((_appendees_)[0]), ((void)0))) && _appendees_ [_i_]; _i_++) _len_ += strlen(_appendees_[_i_]); _p_ = _d_ = __builtin_alloca (_len_ + 1); for (_i_ = 0; _i_ < __extension__ (__builtin_choose_expr ( !__builtin_types_compatible_p(typeof(_appendees_), typeof(& *(_appendees_))), sizeof(_appendees_)/sizeof((_appendees_)[0] ), ((void)0))) && _appendees_[_i_]; _i_++) _p_ = stpcpy (_p_, _appendees_[_i_]); *_p_ = 0; _d_; }); | |||
548 | assert_se(symlink("target", a) >= 0)do { if ((__builtin_expect(!!(!(symlink("target", a) >= 0) ),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("symlink(\"target\", a) >= 0" ), "../src/test/test-fs-util.c", 548, __PRETTY_FUNCTION__); } while (0); | |||
549 | assert_se(touch_file(a, false, test_mtime, test_uid, test_gid, 0640) >= 0)do { if ((__builtin_expect(!!(!(touch_file(a, 0, test_mtime, test_uid , test_gid, 0640) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("touch_file(a, false, test_mtime, test_uid, test_gid, 0640) >= 0" ), "../src/test/test-fs-util.c", 549, __PRETTY_FUNCTION__); } while (0); | |||
550 | assert_se(lstat(a, &st) >= 0)do { if ((__builtin_expect(!!(!(lstat(a, &st) >= 0)),0 ))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("lstat(a, &st) >= 0" ), "../src/test/test-fs-util.c", 550, __PRETTY_FUNCTION__); } while (0); | |||
551 | assert_se(st.st_uid == test_uid)do { if ((__builtin_expect(!!(!(st.st_uid == test_uid)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("st.st_uid == test_uid"), "../src/test/test-fs-util.c" , 551, __PRETTY_FUNCTION__); } while (0); | |||
552 | assert_se(st.st_gid == test_gid)do { if ((__builtin_expect(!!(!(st.st_gid == test_gid)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("st.st_gid == test_gid"), "../src/test/test-fs-util.c" , 552, __PRETTY_FUNCTION__); } while (0); | |||
553 | assert_se(S_ISLNK(st.st_mode))do { if ((__builtin_expect(!!(!(((((st.st_mode)) & 0170000 ) == (0120000)))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("S_ISLNK(st.st_mode)"), "../src/test/test-fs-util.c", 553, __PRETTY_FUNCTION__); } while (0); | |||
554 | assert_se((st.st_mode & 0777) == 0640)do { if ((__builtin_expect(!!(!((st.st_mode & 0777) == 0640 )),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("(st.st_mode & 0777) == 0640" ), "../src/test/test-fs-util.c", 554, __PRETTY_FUNCTION__); } while (0); | |||
555 | assert_se(timespec_load(&st.st_mtim) == test_mtime)do { if ((__builtin_expect(!!(!(timespec_load(&st.st_mtim ) == test_mtime)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("timespec_load(&st.st_mtim) == test_mtime"), "../src/test/test-fs-util.c" , 555, __PRETTY_FUNCTION__); } while (0); | |||
556 | } | |||
557 | ||||
558 | static void test_unlinkat_deallocate(void) { | |||
559 | _cleanup_free___attribute__((cleanup(freep))) char *p = NULL((void*)0); | |||
560 | _cleanup_close___attribute__((cleanup(closep))) int fd = -1; | |||
561 | struct stat st; | |||
562 | ||||
563 | assert_se(tempfn_random_child(NULL, "unlink-deallocation", &p) >= 0)do { if ((__builtin_expect(!!(!(tempfn_random_child(((void*)0 ), "unlink-deallocation", &p) >= 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("tempfn_random_child(NULL, \"unlink-deallocation\", &p) >= 0" ), "../src/test/test-fs-util.c", 563, __PRETTY_FUNCTION__); } while (0); | |||
564 | ||||
565 | fd = open(p, O_WRONLY01|O_CLOEXEC02000000|O_CREAT0100|O_EXCL0200, 0600); | |||
566 | assert_se(fd >= 0)do { if ((__builtin_expect(!!(!(fd >= 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("fd >= 0"), "../src/test/test-fs-util.c" , 566, __PRETTY_FUNCTION__); } while (0); | |||
567 | ||||
568 | assert_se(write(fd, "hallo\n", 6) == 6)do { if ((__builtin_expect(!!(!(write(fd, "hallo\n", 6) == 6) ),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("write(fd, \"hallo\\n\", 6) == 6" ), "../src/test/test-fs-util.c", 568, __PRETTY_FUNCTION__); } while (0); | |||
569 | ||||
570 | assert_se(fstat(fd, &st) >= 0)do { if ((__builtin_expect(!!(!(fstat(fd, &st) >= 0)), 0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("fstat(fd, &st) >= 0" ), "../src/test/test-fs-util.c", 570, __PRETTY_FUNCTION__); } while (0); | |||
571 | assert_se(st.st_size == 6)do { if ((__builtin_expect(!!(!(st.st_size == 6)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("st.st_size == 6"), "../src/test/test-fs-util.c" , 571, __PRETTY_FUNCTION__); } while (0); | |||
572 | assert_se(st.st_blocks > 0)do { if ((__builtin_expect(!!(!(st.st_blocks > 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("st.st_blocks > 0"), "../src/test/test-fs-util.c" , 572, __PRETTY_FUNCTION__); } while (0); | |||
573 | assert_se(st.st_nlink == 1)do { if ((__builtin_expect(!!(!(st.st_nlink == 1)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("st.st_nlink == 1"), "../src/test/test-fs-util.c" , 573, __PRETTY_FUNCTION__); } while (0); | |||
574 | ||||
575 | assert_se(unlinkat_deallocate(AT_FDCWD, p, 0) >= 0)do { if ((__builtin_expect(!!(!(unlinkat_deallocate(-100, p, 0 ) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ( "unlinkat_deallocate(AT_FDCWD, p, 0) >= 0"), "../src/test/test-fs-util.c" , 575, __PRETTY_FUNCTION__); } while (0); | |||
576 | ||||
577 | assert_se(fstat(fd, &st) >= 0)do { if ((__builtin_expect(!!(!(fstat(fd, &st) >= 0)), 0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("fstat(fd, &st) >= 0" ), "../src/test/test-fs-util.c", 577, __PRETTY_FUNCTION__); } while (0); | |||
578 | assert_se(IN_SET(st.st_size, 0, 6))do { if ((__builtin_expect(!!(!(({ _Bool _found = 0; static __attribute__ ((unused)) char _static_assert__macros_need_to_be_extended[20 - sizeof((int[]){0, 6})/sizeof(int)]; switch(st.st_size) { case 0: case 6: _found = 1; break; default: break; } _found; }))) ,0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("IN_SET(st.st_size, 0, 6)" ), "../src/test/test-fs-util.c", 578, __PRETTY_FUNCTION__); } while (0); /* depending on whether hole punching worked the size will be 6 (it worked) or 0 (we had to resort to truncation) */ | |||
579 | assert_se(st.st_blocks == 0)do { if ((__builtin_expect(!!(!(st.st_blocks == 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("st.st_blocks == 0"), "../src/test/test-fs-util.c" , 579, __PRETTY_FUNCTION__); } while (0); | |||
580 | assert_se(st.st_nlink == 0)do { if ((__builtin_expect(!!(!(st.st_nlink == 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("st.st_nlink == 0"), "../src/test/test-fs-util.c" , 580, __PRETTY_FUNCTION__); } while (0); | |||
581 | } | |||
582 | ||||
583 | static void test_fsync_directory_of_file(void) { | |||
584 | _cleanup_close___attribute__((cleanup(closep))) int fd = -1; | |||
585 | ||||
586 | fd = open_tmpfile_unlinkable(NULL((void*)0), O_RDWR02); | |||
587 | assert_se(fd >= 0)do { if ((__builtin_expect(!!(!(fd >= 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("fd >= 0"), "../src/test/test-fs-util.c" , 587, __PRETTY_FUNCTION__); } while (0); | |||
588 | ||||
589 | assert_se(fsync_directory_of_file(fd) >= 0)do { if ((__builtin_expect(!!(!(fsync_directory_of_file(fd) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("fsync_directory_of_file(fd) >= 0" ), "../src/test/test-fs-util.c", 589, __PRETTY_FUNCTION__); } while (0); | |||
590 | } | |||
591 | ||||
592 | int main(int argc, char *argv[]) { | |||
593 | test_unlink_noerrno(); | |||
594 | test_get_files_in_directory(); | |||
595 | test_readlink_and_make_absolute(); | |||
596 | test_var_tmp(); | |||
| ||||
597 | test_chase_symlinks(); | |||
598 | test_dot_or_dot_dot(); | |||
599 | test_access_fd(); | |||
600 | test_touch_file(); | |||
601 | test_unlinkat_deallocate(); | |||
602 | test_fsync_directory_of_file(); | |||
603 | ||||
604 | return 0; | |||
605 | } |