]>
Commit | Line | Data |
---|---|---|
53e1b683 | 1 | /* SPDX-License-Identifier: LGPL-2.1+ */ |
f73141d7 | 2 | |
f73141d7 | 3 | #include <fcntl.h> |
72fd79b3 | 4 | #include <limits.h> |
cf0fbc49 | 5 | #include <stdio.h> |
f73141d7 LP |
6 | #include <unistd.h> |
7 | ||
b5efdb8a | 8 | #include "alloc-util.h" |
1e5413f7 | 9 | #include "ctype.h" |
686d13b9 | 10 | #include "env-file.h" |
3ffd4af2 LP |
11 | #include "env-util.h" |
12 | #include "fd-util.h" | |
13 | #include "fileio.h" | |
627d2bac | 14 | #include "fs-util.h" |
897891f0 | 15 | #include "io-util.h" |
6bedfcbb | 16 | #include "parse-util.h" |
3ffd4af2 | 17 | #include "process-util.h" |
b93d3f6b LP |
18 | #include "rm-rf.h" |
19 | #include "socket-util.h" | |
07630cea | 20 | #include "string-util.h" |
3ffd4af2 | 21 | #include "strv.h" |
6d7c4033 | 22 | #include "tests.h" |
e4de7287 | 23 | #include "tmpfile-util.h" |
3ffd4af2 | 24 | #include "util.h" |
f73141d7 LP |
25 | |
26 | static void test_parse_env_file(void) { | |
627d2bac ZJS |
27 | _cleanup_(unlink_tempfilep) char |
28 | t[] = "/tmp/test-fileio-in-XXXXXX", | |
095b30cb | 29 | p[] = "/tmp/test-fileio-out-XXXXXX"; |
f73141d7 | 30 | FILE *f; |
ebc05a09 | 31 | _cleanup_free_ char *one = NULL, *two = NULL, *three = NULL, *four = NULL, *five = NULL, |
e4a8db1f LT |
32 | *six = NULL, *seven = NULL, *eight = NULL, *nine = NULL, *ten = NULL, |
33 | *eleven = NULL, *twelve = NULL, *thirteen = NULL; | |
768100ef | 34 | _cleanup_strv_free_ char **a = NULL, **b = NULL; |
f73141d7 | 35 | char **i; |
768100ef | 36 | unsigned k; |
d8351049 | 37 | int r; |
f73141d7 | 38 | |
d8351049 | 39 | assert_se(fmkostemp_safe(t, "w", &f) == 0); |
f73141d7 LP |
40 | fputs("one=BAR \n" |
41 | "# comment\n" | |
42 | " # comment \n" | |
98f59e59 | 43 | " ; comment \n" |
f73141d7 LP |
44 | " two = bar \n" |
45 | "invalid line\n" | |
98f59e59 | 46 | "invalid line #comment\n" |
f73141d7 LP |
47 | "three = \"333\n" |
48 | "xxxx\"\n" | |
49 | "four = \'44\\\"44\'\n" | |
e4a8db1f | 50 | "five = \"55\\\"55\" \"FIVE\" cinco \n" |
f73141d7 LP |
51 | "six = seis sechs\\\n" |
52 | " sis\n" | |
98f59e59 HH |
53 | "seven=\"sevenval\" #nocomment\n" |
54 | "eight=eightval #nocomment\n" | |
ebc05a09 | 55 | "export nine=nineval\n" |
99003e01 ZJS |
56 | "ten=ignored\n" |
57 | "ten=ignored\n" | |
e4a8db1f LT |
58 | "ten=\n" |
59 | "eleven=\\value\n" | |
60 | "twelve=\"\\value\"\n" | |
61 | "thirteen='\\value'", f); | |
f73141d7 LP |
62 | |
63 | fflush(f); | |
64 | fclose(f); | |
65 | ||
aa8fbc74 | 66 | r = load_env_file(NULL, t, &a); |
ebc05a09 HH |
67 | assert_se(r >= 0); |
68 | ||
69 | STRV_FOREACH(i, a) | |
70 | log_info("Got: <%s>", *i); | |
71 | ||
5fba7bbf TA |
72 | assert_se(streq_ptr(a[0], "one=BAR")); |
73 | assert_se(streq_ptr(a[1], "two=bar")); | |
74 | assert_se(streq_ptr(a[2], "three=333\nxxxx")); | |
e4a8db1f LT |
75 | assert_se(streq_ptr(a[3], "four=44\\\"44")); |
76 | assert_se(streq_ptr(a[4], "five=55\"55FIVEcinco")); | |
5fba7bbf TA |
77 | assert_se(streq_ptr(a[5], "six=seis sechs sis")); |
78 | assert_se(streq_ptr(a[6], "seven=sevenval#nocomment")); | |
79 | assert_se(streq_ptr(a[7], "eight=eightval #nocomment")); | |
80 | assert_se(streq_ptr(a[8], "export nine=nineval")); | |
81 | assert_se(streq_ptr(a[9], "ten=")); | |
e4a8db1f LT |
82 | assert_se(streq_ptr(a[10], "eleven=value")); |
83 | assert_se(streq_ptr(a[11], "twelve=\\value")); | |
84 | assert_se(streq_ptr(a[12], "thirteen=\\value")); | |
85 | assert_se(a[13] == NULL); | |
ebc05a09 | 86 | |
039f0e70 | 87 | strv_env_clean(a); |
ebc05a09 | 88 | |
ebc05a09 HH |
89 | k = 0; |
90 | STRV_FOREACH(i, b) { | |
91 | log_info("Got2: <%s>", *i); | |
92 | assert_se(streq(*i, a[k++])); | |
93 | } | |
94 | ||
f73141d7 | 95 | r = parse_env_file( |
aa8fbc74 | 96 | NULL, t, |
f73141d7 LP |
97 | "one", &one, |
98 | "two", &two, | |
99 | "three", &three, | |
100 | "four", &four, | |
101 | "five", &five, | |
102 | "six", &six, | |
103 | "seven", &seven, | |
db537209 | 104 | "eight", &eight, |
ebc05a09 | 105 | "export nine", &nine, |
e4a8db1f LT |
106 | "ten", &ten, |
107 | "eleven", &eleven, | |
108 | "twelve", &twelve, | |
109 | "thirteen", &thirteen); | |
f73141d7 LP |
110 | |
111 | assert_se(r >= 0); | |
112 | ||
113 | log_info("one=[%s]", strna(one)); | |
114 | log_info("two=[%s]", strna(two)); | |
115 | log_info("three=[%s]", strna(three)); | |
116 | log_info("four=[%s]", strna(four)); | |
117 | log_info("five=[%s]", strna(five)); | |
118 | log_info("six=[%s]", strna(six)); | |
119 | log_info("seven=[%s]", strna(seven)); | |
db537209 | 120 | log_info("eight=[%s]", strna(eight)); |
ebc05a09 HH |
121 | log_info("export nine=[%s]", strna(nine)); |
122 | log_info("ten=[%s]", strna(nine)); | |
e4a8db1f LT |
123 | log_info("eleven=[%s]", strna(eleven)); |
124 | log_info("twelve=[%s]", strna(twelve)); | |
125 | log_info("thirteen=[%s]", strna(thirteen)); | |
f73141d7 LP |
126 | |
127 | assert_se(streq(one, "BAR")); | |
128 | assert_se(streq(two, "bar")); | |
129 | assert_se(streq(three, "333\nxxxx")); | |
e4a8db1f LT |
130 | assert_se(streq(four, "44\\\"44")); |
131 | assert_se(streq(five, "55\"55FIVEcinco")); | |
f73141d7 | 132 | assert_se(streq(six, "seis sechs sis")); |
98f59e59 HH |
133 | assert_se(streq(seven, "sevenval#nocomment")); |
134 | assert_se(streq(eight, "eightval #nocomment")); | |
ebc05a09 HH |
135 | assert_se(streq(nine, "nineval")); |
136 | assert_se(ten == NULL); | |
e4a8db1f LT |
137 | assert_se(streq(eleven, "value")); |
138 | assert_se(streq(twelve, "\\value")); | |
139 | assert_se(streq(thirteen, "\\value")); | |
f73141d7 | 140 | |
d8351049 ZJS |
141 | { |
142 | /* prepare a temporary file to write the environment to */ | |
143 | _cleanup_close_ int fd = mkostemp_safe(p); | |
144 | assert_se(fd >= 0); | |
145 | } | |
146 | ||
095b30cb | 147 | r = write_env_file(p, a); |
98f59e59 HH |
148 | assert_se(r >= 0); |
149 | ||
aa8fbc74 | 150 | r = load_env_file(NULL, p, &b); |
98f59e59 | 151 | assert_se(r >= 0); |
f73141d7 LP |
152 | } |
153 | ||
df8b14b5 LP |
154 | static void test_one_shell_var(const char *file, const char *variable, const char *value) { |
155 | _cleanup_free_ char *cmd = NULL, *from_shell = NULL; | |
649bde89 | 156 | _cleanup_pclose_ FILE *f = NULL; |
df8b14b5 LP |
157 | size_t sz; |
158 | ||
159 | assert_se(cmd = strjoin(". ", file, " && /bin/echo -n \"$", variable, "\"")); | |
160 | assert_se(f = popen(cmd, "re")); | |
161 | assert_se(read_full_stream(f, &from_shell, &sz) >= 0); | |
162 | assert_se(sz == strlen(value)); | |
163 | assert_se(streq(from_shell, value)); | |
164 | } | |
165 | ||
ac4c8d6d | 166 | static void test_parse_multiline_env_file(void) { |
627d2bac ZJS |
167 | _cleanup_(unlink_tempfilep) char |
168 | t[] = "/tmp/test-fileio-in-XXXXXX", | |
ac4c8d6d | 169 | p[] = "/tmp/test-fileio-out-XXXXXX"; |
ac4c8d6d ZJS |
170 | FILE *f; |
171 | _cleanup_strv_free_ char **a = NULL, **b = NULL; | |
172 | char **i; | |
d8351049 | 173 | int r; |
ac4c8d6d | 174 | |
d8351049 | 175 | assert_se(fmkostemp_safe(t, "w", &f) == 0); |
ac4c8d6d | 176 | fputs("one=BAR\\\n" |
6fe31963 LP |
177 | "\\ \\ \\ \\ VAR\\\n" |
178 | "\\\tGAR\n" | |
ac4c8d6d ZJS |
179 | "#comment\n" |
180 | "two=\"bar\\\n" | |
181 | " var\\\n" | |
182 | "\tgar\"\n" | |
183 | "#comment\n" | |
184 | "tri=\"bar \\\n" | |
185 | " var \\\n" | |
186 | "\tgar \"\n", f); | |
187 | ||
6fe31963 | 188 | assert_se(fflush_and_check(f) >= 0); |
ac4c8d6d ZJS |
189 | fclose(f); |
190 | ||
df8b14b5 LP |
191 | test_one_shell_var(t, "one", "BAR VAR\tGAR"); |
192 | test_one_shell_var(t, "two", "bar var\tgar"); | |
193 | test_one_shell_var(t, "tri", "bar var \tgar "); | |
194 | ||
aa8fbc74 | 195 | r = load_env_file(NULL, t, &a); |
ac4c8d6d ZJS |
196 | assert_se(r >= 0); |
197 | ||
198 | STRV_FOREACH(i, a) | |
199 | log_info("Got: <%s>", *i); | |
200 | ||
5fba7bbf TA |
201 | assert_se(streq_ptr(a[0], "one=BAR VAR\tGAR")); |
202 | assert_se(streq_ptr(a[1], "two=bar var\tgar")); | |
203 | assert_se(streq_ptr(a[2], "tri=bar var \tgar ")); | |
ac4c8d6d ZJS |
204 | assert_se(a[3] == NULL); |
205 | ||
d8351049 ZJS |
206 | { |
207 | _cleanup_close_ int fd = mkostemp_safe(p); | |
208 | assert_se(fd >= 0); | |
209 | } | |
210 | ||
ac4c8d6d ZJS |
211 | r = write_env_file(p, a); |
212 | assert_se(r >= 0); | |
213 | ||
aa8fbc74 | 214 | r = load_env_file(NULL, p, &b); |
ac4c8d6d | 215 | assert_se(r >= 0); |
ac4c8d6d ZJS |
216 | } |
217 | ||
37f3ffca | 218 | static void test_merge_env_file(void) { |
627d2bac | 219 | _cleanup_(unlink_tempfilep) char t[] = "/tmp/test-fileio-XXXXXX"; |
9707d552 | 220 | _cleanup_fclose_ FILE *f = NULL; |
37f3ffca RS |
221 | _cleanup_strv_free_ char **a = NULL; |
222 | char **i; | |
d8351049 | 223 | int r; |
37f3ffca | 224 | |
d8351049 | 225 | assert_se(fmkostemp_safe(t, "w", &f) == 0); |
37f3ffca RS |
226 | log_info("/* %s (%s) */", __func__, t); |
227 | ||
37f3ffca RS |
228 | r = write_string_stream(f, |
229 | "one=1 \n" | |
230 | "twelve=${one}2\n" | |
231 | "twentyone=2${one}\n" | |
232 | "one=2\n" | |
ccad1fd0 ZJS |
233 | "twentytwo=2${one}\n" |
234 | "xxx_minus_three=$xxx - 3\n" | |
235 | "xxx=0x$one$one$one\n" | |
b82f58bf RS |
236 | "yyy=${one:-fallback}\n" |
237 | "zzz=${one:+replacement}\n" | |
238 | "zzzz=${foobar:-${nothing}}\n" | |
239 | "zzzzz=${nothing:+${nothing}}\n" | |
b1837133 | 240 | , WRITE_STRING_FILE_AVOID_NEWLINE); |
37f3ffca RS |
241 | assert(r >= 0); |
242 | ||
243 | r = merge_env_file(&a, NULL, t); | |
244 | assert_se(r >= 0); | |
245 | strv_sort(a); | |
246 | ||
247 | STRV_FOREACH(i, a) | |
248 | log_info("Got: <%s>", *i); | |
249 | ||
250 | assert_se(streq(a[0], "one=2")); | |
251 | assert_se(streq(a[1], "twelve=12")); | |
252 | assert_se(streq(a[2], "twentyone=21")); | |
253 | assert_se(streq(a[3], "twentytwo=22")); | |
ccad1fd0 ZJS |
254 | assert_se(streq(a[4], "xxx=0x222")); |
255 | assert_se(streq(a[5], "xxx_minus_three= - 3")); | |
b82f58bf RS |
256 | assert_se(streq(a[6], "yyy=2")); |
257 | assert_se(streq(a[7], "zzz=replacement")); | |
258 | assert_se(streq(a[8], "zzzz=")); | |
259 | assert_se(streq(a[9], "zzzzz=")); | |
260 | assert_se(a[10] == NULL); | |
37f3ffca RS |
261 | |
262 | r = merge_env_file(&a, NULL, t); | |
263 | assert_se(r >= 0); | |
264 | strv_sort(a); | |
265 | ||
266 | STRV_FOREACH(i, a) | |
267 | log_info("Got2: <%s>", *i); | |
268 | ||
269 | assert_se(streq(a[0], "one=2")); | |
270 | assert_se(streq(a[1], "twelve=12")); | |
271 | assert_se(streq(a[2], "twentyone=21")); | |
272 | assert_se(streq(a[3], "twentytwo=22")); | |
ccad1fd0 ZJS |
273 | assert_se(streq(a[4], "xxx=0x222")); |
274 | assert_se(streq(a[5], "xxx_minus_three=0x222 - 3")); | |
b82f58bf RS |
275 | assert_se(streq(a[6], "yyy=2")); |
276 | assert_se(streq(a[7], "zzz=replacement")); | |
277 | assert_se(streq(a[8], "zzzz=")); | |
278 | assert_se(streq(a[9], "zzzzz=")); | |
279 | assert_se(a[10] == NULL); | |
37f3ffca | 280 | } |
ac4c8d6d | 281 | |
184d1904 | 282 | static void test_merge_env_file_invalid(void) { |
627d2bac | 283 | _cleanup_(unlink_tempfilep) char t[] = "/tmp/test-fileio-XXXXXX"; |
9707d552 | 284 | _cleanup_fclose_ FILE *f = NULL; |
184d1904 ZJS |
285 | _cleanup_strv_free_ char **a = NULL; |
286 | char **i; | |
d8351049 | 287 | int r; |
184d1904 | 288 | |
d8351049 | 289 | assert_se(fmkostemp_safe(t, "w", &f) == 0); |
184d1904 ZJS |
290 | log_info("/* %s (%s) */", __func__, t); |
291 | ||
184d1904 ZJS |
292 | r = write_string_stream(f, |
293 | "unset one \n" | |
294 | "unset one= \n" | |
295 | "unset one=1 \n" | |
296 | "one \n" | |
297 | "one = \n" | |
298 | "one two =\n" | |
299 | "\x20two=\n" | |
300 | "#comment=comment\n" | |
301 | ";comment2=comment2\n" | |
302 | "#\n" | |
303 | "\n\n" /* empty line */ | |
b1837133 | 304 | , WRITE_STRING_FILE_AVOID_NEWLINE); |
184d1904 ZJS |
305 | assert(r >= 0); |
306 | ||
307 | r = merge_env_file(&a, NULL, t); | |
308 | assert_se(r >= 0); | |
309 | ||
310 | STRV_FOREACH(i, a) | |
311 | log_info("Got: <%s>", *i); | |
312 | ||
313 | assert_se(strv_isempty(a)); | |
314 | } | |
315 | ||
68fee104 | 316 | static void test_executable_is_script(void) { |
627d2bac | 317 | _cleanup_(unlink_tempfilep) char t[] = "/tmp/test-fileio-XXXXXX"; |
627d2bac | 318 | _cleanup_fclose_ FILE *f = NULL; |
68fee104 | 319 | char *command; |
d8351049 | 320 | int r; |
68fee104 | 321 | |
d8351049 | 322 | assert_se(fmkostemp_safe(t, "w", &f) == 0); |
68fee104 ZJS |
323 | fputs("#! /bin/script -a -b \ngoo goo", f); |
324 | fflush(f); | |
325 | ||
326 | r = executable_is_script(t, &command); | |
327 | assert_se(r > 0); | |
328 | assert_se(streq(command, "/bin/script")); | |
329 | free(command); | |
330 | ||
331 | r = executable_is_script("/bin/sh", &command); | |
332 | assert_se(r == 0); | |
333 | ||
334 | r = executable_is_script("/usr/bin/yum", &command); | |
335 | assert_se(r > 0 || r == -ENOENT); | |
336 | if (r > 0) { | |
337 | assert_se(startswith(command, "/")); | |
338 | free(command); | |
339 | } | |
68fee104 ZJS |
340 | } |
341 | ||
69ab8088 | 342 | static void test_status_field(void) { |
1e5413f7 ZJS |
343 | _cleanup_free_ char *t = NULL, *p = NULL, *s = NULL, *z = NULL; |
344 | unsigned long long total = 0, buffers = 0; | |
442e0083 | 345 | int r; |
69ab8088 | 346 | |
c4cd1d4d | 347 | assert_se(get_proc_field("/proc/self/status", "Threads", WHITESPACE, &t) == 0); |
69ab8088 ZJS |
348 | puts(t); |
349 | assert_se(streq(t, "1")); | |
350 | ||
c4cd1d4d | 351 | r = get_proc_field("/proc/meminfo", "MemTotal", WHITESPACE, &p); |
1e5413f7 | 352 | if (r != -ENOENT) { |
bdf7026e | 353 | assert_se(r == 0); |
1e5413f7 ZJS |
354 | puts(p); |
355 | assert_se(safe_atollu(p, &total) == 0); | |
356 | } | |
69ab8088 | 357 | |
c4cd1d4d | 358 | r = get_proc_field("/proc/meminfo", "Buffers", WHITESPACE, &s); |
1e5413f7 | 359 | if (r != -ENOENT) { |
bdf7026e | 360 | assert_se(r == 0); |
1e5413f7 ZJS |
361 | puts(s); |
362 | assert_se(safe_atollu(s, &buffers) == 0); | |
363 | } | |
69ab8088 | 364 | |
2b01a801 | 365 | if (p) |
bdf7026e | 366 | assert_se(buffers < total); |
1e5413f7 ZJS |
367 | |
368 | /* Seccomp should be a good test for field full of zeros. */ | |
c4cd1d4d | 369 | r = get_proc_field("/proc/meminfo", "Seccomp", WHITESPACE, &z); |
1e5413f7 | 370 | if (r != -ENOENT) { |
bdf7026e | 371 | assert_se(r == 0); |
1e5413f7 ZJS |
372 | puts(z); |
373 | assert_se(safe_atollu(z, &buffers) == 0); | |
374 | } | |
375 | } | |
376 | ||
377 | static void test_capeff(void) { | |
378 | int pid, p; | |
379 | ||
380 | for (pid = 0; pid < 2; pid++) { | |
381 | _cleanup_free_ char *capeff = NULL; | |
382 | int r; | |
383 | ||
384 | r = get_process_capeff(0, &capeff); | |
385 | log_info("capeff: '%s' (r=%d)", capeff, r); | |
386 | ||
4c701096 | 387 | if (IN_SET(r, -ENOENT, -EPERM)) |
1e5413f7 ZJS |
388 | return; |
389 | ||
bdf7026e TA |
390 | assert_se(r == 0); |
391 | assert_se(*capeff); | |
1a7906ae | 392 | p = capeff[strspn(capeff, HEXDIGITS)]; |
bdf7026e | 393 | assert_se(!p || isspace(p)); |
1e5413f7 | 394 | } |
69ab8088 ZJS |
395 | } |
396 | ||
0709b743 | 397 | static void test_write_string_stream(void) { |
627d2bac ZJS |
398 | _cleanup_(unlink_tempfilep) char fn[] = "/tmp/test-write_string_stream-XXXXXX"; |
399 | _cleanup_fclose_ FILE *f = NULL; | |
0709b743 RC |
400 | int fd; |
401 | char buf[64]; | |
402 | ||
646853bd | 403 | fd = mkostemp_safe(fn); |
0709b743 RC |
404 | assert_se(fd >= 0); |
405 | ||
406 | f = fdopen(fd, "r"); | |
407 | assert_se(f); | |
b1837133 | 408 | assert_se(write_string_stream(f, "boohoo", 0) < 0); |
36297390 | 409 | f = safe_fclose(f); |
0709b743 | 410 | |
36297390 | 411 | f = fopen(fn, "r+"); |
0709b743 RC |
412 | assert_se(f); |
413 | ||
b1837133 | 414 | assert_se(write_string_stream(f, "boohoo", 0) == 0); |
0709b743 RC |
415 | rewind(f); |
416 | ||
417 | assert_se(fgets(buf, sizeof(buf), f)); | |
418 | assert_se(streq(buf, "boohoo\n")); | |
36297390 | 419 | f = safe_fclose(f); |
0709b743 | 420 | |
36297390 | 421 | f = fopen(fn, "w+"); |
40beecdb DM |
422 | assert_se(f); |
423 | ||
b1837133 | 424 | assert_se(write_string_stream(f, "boohoo", WRITE_STRING_FILE_AVOID_NEWLINE) == 0); |
40beecdb DM |
425 | rewind(f); |
426 | ||
427 | assert_se(fgets(buf, sizeof(buf), f)); | |
428 | printf(">%s<", buf); | |
429 | assert_se(streq(buf, "boohoo")); | |
0709b743 RC |
430 | } |
431 | ||
432 | static void test_write_string_file(void) { | |
627d2bac | 433 | _cleanup_(unlink_tempfilep) char fn[] = "/tmp/test-write_string_file-XXXXXX"; |
76082570 RC |
434 | char buf[64] = {}; |
435 | _cleanup_close_ int fd; | |
0709b743 | 436 | |
646853bd | 437 | fd = mkostemp_safe(fn); |
0709b743 RC |
438 | assert_se(fd >= 0); |
439 | ||
4c1fc3e4 | 440 | assert_se(write_string_file(fn, "boohoo", WRITE_STRING_FILE_CREATE) == 0); |
0709b743 | 441 | |
cca0efb0 | 442 | assert_se(read(fd, buf, sizeof(buf)) == 7); |
0709b743 | 443 | assert_se(streq(buf, "boohoo\n")); |
0709b743 RC |
444 | } |
445 | ||
e07995a3 | 446 | static void test_write_string_file_no_create(void) { |
627d2bac | 447 | _cleanup_(unlink_tempfilep) char fn[] = "/tmp/test-write_string_file_no_create-XXXXXX"; |
e07995a3 | 448 | _cleanup_close_ int fd; |
2aa07538 | 449 | char buf[64] = {}; |
e07995a3 | 450 | |
646853bd | 451 | fd = mkostemp_safe(fn); |
e07995a3 RC |
452 | assert_se(fd >= 0); |
453 | ||
4c1fc3e4 DM |
454 | assert_se(write_string_file("/a/file/which/does/not/exists/i/guess", "boohoo", 0) < 0); |
455 | assert_se(write_string_file(fn, "boohoo", 0) == 0); | |
e07995a3 | 456 | |
2aa07538 | 457 | assert_se(read(fd, buf, sizeof buf) == (ssize_t) strlen("boohoo\n")); |
e07995a3 | 458 | assert_se(streq(buf, "boohoo\n")); |
e07995a3 RC |
459 | } |
460 | ||
eb3da901 LP |
461 | static void test_write_string_file_verify(void) { |
462 | _cleanup_free_ char *buf = NULL, *buf2 = NULL; | |
463 | int r; | |
464 | ||
3c14dc61 TM |
465 | r = read_one_line_file("/proc/version", &buf); |
466 | if (ERRNO_IS_PRIVILEGE(r)) | |
467 | return; | |
468 | assert_se(r >= 0); | |
dcd6361e | 469 | assert_se(buf2 = strjoin(buf, "\n")); |
eb3da901 | 470 | |
30b84c78 | 471 | r = write_string_file("/proc/version", buf, 0); |
4c701096 | 472 | assert_se(IN_SET(r, -EACCES, -EIO)); |
30b84c78 | 473 | r = write_string_file("/proc/version", buf2, 0); |
4c701096 | 474 | assert_se(IN_SET(r, -EACCES, -EIO)); |
eb3da901 | 475 | |
30b84c78 ZJS |
476 | assert_se(write_string_file("/proc/version", buf, WRITE_STRING_FILE_VERIFY_ON_FAILURE) == 0); |
477 | assert_se(write_string_file("/proc/version", buf2, WRITE_STRING_FILE_VERIFY_ON_FAILURE) == 0); | |
eb3da901 | 478 | |
30b84c78 | 479 | r = write_string_file("/proc/version", buf, WRITE_STRING_FILE_VERIFY_ON_FAILURE|WRITE_STRING_FILE_AVOID_NEWLINE); |
4c701096 | 480 | assert_se(IN_SET(r, -EACCES, -EIO)); |
30b84c78 | 481 | assert_se(write_string_file("/proc/version", buf2, WRITE_STRING_FILE_VERIFY_ON_FAILURE|WRITE_STRING_FILE_AVOID_NEWLINE) == 0); |
eb3da901 LP |
482 | } |
483 | ||
e07995a3 | 484 | static void test_load_env_file_pairs(void) { |
627d2bac ZJS |
485 | _cleanup_(unlink_tempfilep) char fn[] = "/tmp/test-load_env_file_pairs-XXXXXX"; |
486 | int fd, r; | |
e07995a3 RC |
487 | _cleanup_fclose_ FILE *f = NULL; |
488 | _cleanup_strv_free_ char **l = NULL; | |
489 | char **k, **v; | |
490 | ||
646853bd | 491 | fd = mkostemp_safe(fn); |
e07995a3 RC |
492 | assert_se(fd >= 0); |
493 | ||
494 | r = write_string_file(fn, | |
495 | "NAME=\"Arch Linux\"\n" | |
496 | "ID=arch\n" | |
497 | "PRETTY_NAME=\"Arch Linux\"\n" | |
498 | "ANSI_COLOR=\"0;36\"\n" | |
499 | "HOME_URL=\"https://www.archlinux.org/\"\n" | |
500 | "SUPPORT_URL=\"https://bbs.archlinux.org/\"\n" | |
4c1fc3e4 DM |
501 | "BUG_REPORT_URL=\"https://bugs.archlinux.org/\"\n", |
502 | WRITE_STRING_FILE_CREATE); | |
e07995a3 RC |
503 | assert_se(r == 0); |
504 | ||
505 | f = fdopen(fd, "r"); | |
506 | assert_se(f); | |
507 | ||
aa8fbc74 | 508 | r = load_env_file_pairs(f, fn, &l); |
e07995a3 RC |
509 | assert_se(r >= 0); |
510 | ||
511 | assert_se(strv_length(l) == 14); | |
512 | STRV_FOREACH_PAIR(k, v, l) { | |
513 | assert_se(STR_IN_SET(*k, "NAME", "ID", "PRETTY_NAME", "ANSI_COLOR", "HOME_URL", "SUPPORT_URL", "BUG_REPORT_URL")); | |
514 | printf("%s=%s\n", *k, *v); | |
515 | if (streq(*k, "NAME")) assert_se(streq(*v, "Arch Linux")); | |
516 | if (streq(*k, "ID")) assert_se(streq(*v, "arch")); | |
517 | if (streq(*k, "PRETTY_NAME")) assert_se(streq(*v, "Arch Linux")); | |
518 | if (streq(*k, "ANSI_COLOR")) assert_se(streq(*v, "0;36")); | |
519 | if (streq(*k, "HOME_URL")) assert_se(streq(*v, "https://www.archlinux.org/")); | |
520 | if (streq(*k, "SUPPORT_URL")) assert_se(streq(*v, "https://bbs.archlinux.org/")); | |
521 | if (streq(*k, "BUG_REPORT_URL")) assert_se(streq(*v, "https://bugs.archlinux.org/")); | |
522 | } | |
e07995a3 RC |
523 | } |
524 | ||
897891f0 RC |
525 | static void test_search_and_fopen(void) { |
526 | const char *dirs[] = {"/tmp/foo/bar", "/tmp", NULL}; | |
627d2bac | 527 | |
897891f0 | 528 | char name[] = "/tmp/test-search_and_fopen.XXXXXX"; |
627d2bac | 529 | int fd, r; |
897891f0 RC |
530 | FILE *f; |
531 | ||
646853bd | 532 | fd = mkostemp_safe(name); |
897891f0 RC |
533 | assert_se(fd >= 0); |
534 | close(fd); | |
535 | ||
536 | r = search_and_fopen(basename(name), "r", NULL, dirs, &f); | |
537 | assert_se(r >= 0); | |
538 | fclose(f); | |
539 | ||
540 | r = search_and_fopen(name, "r", NULL, dirs, &f); | |
541 | assert_se(r >= 0); | |
542 | fclose(f); | |
543 | ||
544 | r = search_and_fopen(basename(name), "r", "/", dirs, &f); | |
545 | assert_se(r >= 0); | |
546 | fclose(f); | |
547 | ||
548 | r = search_and_fopen("/a/file/which/does/not/exist/i/guess", "r", NULL, dirs, &f); | |
549 | assert_se(r < 0); | |
550 | r = search_and_fopen("afilewhichdoesnotexistiguess", "r", NULL, dirs, &f); | |
551 | assert_se(r < 0); | |
552 | ||
553 | r = unlink(name); | |
554 | assert_se(r == 0); | |
555 | ||
556 | r = search_and_fopen(basename(name), "r", NULL, dirs, &f); | |
557 | assert_se(r < 0); | |
558 | } | |
559 | ||
897891f0 RC |
560 | static void test_search_and_fopen_nulstr(void) { |
561 | const char dirs[] = "/tmp/foo/bar\0/tmp\0"; | |
627d2bac ZJS |
562 | |
563 | _cleanup_(unlink_tempfilep) char name[] = "/tmp/test-search_and_fopen.XXXXXX"; | |
564 | int fd, r; | |
897891f0 RC |
565 | FILE *f; |
566 | ||
646853bd | 567 | fd = mkostemp_safe(name); |
897891f0 RC |
568 | assert_se(fd >= 0); |
569 | close(fd); | |
570 | ||
571 | r = search_and_fopen_nulstr(basename(name), "r", NULL, dirs, &f); | |
572 | assert_se(r >= 0); | |
573 | fclose(f); | |
574 | ||
575 | r = search_and_fopen_nulstr(name, "r", NULL, dirs, &f); | |
576 | assert_se(r >= 0); | |
577 | fclose(f); | |
578 | ||
579 | r = search_and_fopen_nulstr("/a/file/which/does/not/exist/i/guess", "r", NULL, dirs, &f); | |
580 | assert_se(r < 0); | |
581 | r = search_and_fopen_nulstr("afilewhichdoesnotexistiguess", "r", NULL, dirs, &f); | |
582 | assert_se(r < 0); | |
583 | ||
584 | r = unlink(name); | |
585 | assert_se(r == 0); | |
586 | ||
587 | r = search_and_fopen_nulstr(basename(name), "r", NULL, dirs, &f); | |
588 | assert_se(r < 0); | |
589 | } | |
590 | ||
591 | static void test_writing_tmpfile(void) { | |
627d2bac | 592 | _cleanup_(unlink_tempfilep) char name[] = "/tmp/test-systemd_writing_tmpfile.XXXXXX"; |
897891f0 RC |
593 | _cleanup_free_ char *contents = NULL; |
594 | size_t size; | |
9a92e255 | 595 | _cleanup_close_ int fd = -1; |
897891f0 | 596 | struct iovec iov[3]; |
627d2bac | 597 | int r; |
897891f0 | 598 | |
e6a7ec4b LP |
599 | iov[0] = IOVEC_MAKE_STRING("abc\n"); |
600 | iov[1] = IOVEC_MAKE_STRING(ALPHANUMERICAL "\n"); | |
601 | iov[2] = IOVEC_MAKE_STRING(""); | |
897891f0 | 602 | |
646853bd | 603 | fd = mkostemp_safe(name); |
897891f0 RC |
604 | printf("tmpfile: %s", name); |
605 | ||
606 | r = writev(fd, iov, 3); | |
607 | assert_se(r >= 0); | |
608 | ||
609 | r = read_full_file(name, &contents, &size); | |
610 | assert_se(r == 0); | |
611 | printf("contents: %s", contents); | |
612 | assert_se(streq(contents, "abc\n" ALPHANUMERICAL "\n")); | |
897891f0 RC |
613 | } |
614 | ||
615 | static void test_tempfn(void) { | |
616 | char *ret = NULL, *p; | |
617 | ||
618 | assert_se(tempfn_xxxxxx("/foo/bar/waldo", NULL, &ret) >= 0); | |
619 | assert_se(streq_ptr(ret, "/foo/bar/.#waldoXXXXXX")); | |
620 | free(ret); | |
621 | ||
622 | assert_se(tempfn_xxxxxx("/foo/bar/waldo", "[miau]", &ret) >= 0); | |
623 | assert_se(streq_ptr(ret, "/foo/bar/.#[miau]waldoXXXXXX")); | |
624 | free(ret); | |
625 | ||
626 | assert_se(tempfn_random("/foo/bar/waldo", NULL, &ret) >= 0); | |
627 | assert_se(p = startswith(ret, "/foo/bar/.#waldo")); | |
628 | assert_se(strlen(p) == 16); | |
629 | assert_se(in_charset(p, "0123456789abcdef")); | |
630 | free(ret); | |
631 | ||
632 | assert_se(tempfn_random("/foo/bar/waldo", "[wuff]", &ret) >= 0); | |
633 | assert_se(p = startswith(ret, "/foo/bar/.#[wuff]waldo")); | |
634 | assert_se(strlen(p) == 16); | |
635 | assert_se(in_charset(p, "0123456789abcdef")); | |
636 | free(ret); | |
637 | ||
638 | assert_se(tempfn_random_child("/foo/bar/waldo", NULL, &ret) >= 0); | |
639 | assert_se(p = startswith(ret, "/foo/bar/waldo/.#")); | |
640 | assert_se(strlen(p) == 16); | |
641 | assert_se(in_charset(p, "0123456789abcdef")); | |
642 | free(ret); | |
643 | ||
644 | assert_se(tempfn_random_child("/foo/bar/waldo", "[kikiriki]", &ret) >= 0); | |
645 | assert_se(p = startswith(ret, "/foo/bar/waldo/.#[kikiriki]")); | |
646 | assert_se(strlen(p) == 16); | |
647 | assert_se(in_charset(p, "0123456789abcdef")); | |
648 | free(ret); | |
649 | } | |
650 | ||
7f9d1aed | 651 | static const char chars[] = |
cdce33f9 | 652 | "Aąę„”\n루\377"; |
7f9d1aed | 653 | |
6028d766 | 654 | DISABLE_WARNING_TYPE_LIMITS; |
d3bdba38 | 655 | |
7f9d1aed ZJS |
656 | static void test_fgetc(void) { |
657 | _cleanup_fclose_ FILE *f = NULL; | |
658 | char c; | |
659 | ||
673a1e6f | 660 | f = fmemopen_unlocked((void*) chars, sizeof(chars), "re"); |
7f9d1aed ZJS |
661 | assert_se(f); |
662 | ||
72fd79b3 | 663 | for (size_t i = 0; i < sizeof(chars); i++) { |
7f9d1aed ZJS |
664 | assert_se(safe_fgetc(f, &c) == 1); |
665 | assert_se(c == chars[i]); | |
666 | ||
72fd79b3 LP |
667 | if (ungetc(c, f) == EOF) { |
668 | /* EOF is -1, and hence we can't push value 255 in this way – if char is signed */ | |
669 | assert_se(c == (char) EOF); | |
670 | assert_se(CHAR_MIN == -128); /* verify that char is signed on this platform */ | |
671 | } else { | |
672 | assert_se(safe_fgetc(f, &c) == 1); | |
673 | assert_se(c == chars[i]); | |
674 | } | |
7f9d1aed | 675 | |
cdce33f9 | 676 | /* But it works when we push it properly cast */ |
7f9d1aed ZJS |
677 | assert_se(ungetc((unsigned char) c, f) != EOF); |
678 | assert_se(safe_fgetc(f, &c) == 1); | |
679 | assert_se(c == chars[i]); | |
680 | } | |
681 | ||
682 | assert_se(safe_fgetc(f, &c) == 0); | |
683 | } | |
684 | ||
6028d766 | 685 | REENABLE_WARNING; |
d3bdba38 | 686 | |
2c9de139 ZJS |
687 | static const char buffer[] = |
688 | "Some test data\n" | |
7f9d1aed | 689 | "루Non-ascii chars: ąę„”\n" |
838894b0 LP |
690 | "terminators\r\n" |
691 | "and even more\n\r" | |
692 | "now the same with a NUL\n\0" | |
693 | "and more\r\0" | |
694 | "and even more\r\n\0" | |
695 | "and yet even more\n\r\0" | |
2c9de139 ZJS |
696 | "With newlines, and a NUL byte\0" |
697 | "\n" | |
698 | "an empty line\n" | |
699 | "an ignored line\n" | |
700 | "and a very long line that is supposed to be truncated, because it is so long\n"; | |
701 | ||
702 | static void test_read_line_one_file(FILE *f) { | |
4f9a66a3 LP |
703 | _cleanup_free_ char *line = NULL; |
704 | ||
4f9a66a3 LP |
705 | assert_se(read_line(f, (size_t) -1, &line) == 15 && streq(line, "Some test data")); |
706 | line = mfree(line); | |
707 | ||
7f9d1aed | 708 | assert_se(read_line(f, (size_t) -1, &line) > 0 && streq(line, "루Non-ascii chars: ąę„”")); |
838894b0 LP |
709 | line = mfree(line); |
710 | ||
711 | assert_se(read_line(f, (size_t) -1, &line) == 13 && streq(line, "terminators")); | |
712 | line = mfree(line); | |
713 | ||
714 | assert_se(read_line(f, (size_t) -1, &line) == 15 && streq(line, "and even more")); | |
715 | line = mfree(line); | |
716 | ||
717 | assert_se(read_line(f, (size_t) -1, &line) == 25 && streq(line, "now the same with a NUL")); | |
718 | line = mfree(line); | |
719 | ||
720 | assert_se(read_line(f, (size_t) -1, &line) == 10 && streq(line, "and more")); | |
721 | line = mfree(line); | |
722 | ||
723 | assert_se(read_line(f, (size_t) -1, &line) == 16 && streq(line, "and even more")); | |
724 | line = mfree(line); | |
725 | ||
726 | assert_se(read_line(f, (size_t) -1, &line) == 20 && streq(line, "and yet even more")); | |
727 | line = mfree(line); | |
728 | ||
4f9a66a3 LP |
729 | assert_se(read_line(f, 1024, &line) == 30 && streq(line, "With newlines, and a NUL byte")); |
730 | line = mfree(line); | |
731 | ||
732 | assert_se(read_line(f, 1024, &line) == 1 && streq(line, "")); | |
733 | line = mfree(line); | |
734 | ||
735 | assert_se(read_line(f, 1024, &line) == 14 && streq(line, "an empty line")); | |
736 | line = mfree(line); | |
737 | ||
738 | assert_se(read_line(f, (size_t) -1, NULL) == 16); | |
739 | ||
740 | assert_se(read_line(f, 16, &line) == -ENOBUFS); | |
741 | line = mfree(line); | |
742 | ||
743 | /* read_line() stopped when it hit the limit, that means when we continue reading we'll read at the first | |
5238e957 | 744 | * character after the previous limit. Let's make use of that to continue our test. */ |
838894b0 | 745 | assert_se(read_line(f, 1024, &line) == 62 && streq(line, "line that is supposed to be truncated, because it is so long")); |
4f9a66a3 LP |
746 | line = mfree(line); |
747 | ||
748 | assert_se(read_line(f, 1024, &line) == 0 && streq(line, "")); | |
749 | } | |
750 | ||
2c9de139 ZJS |
751 | static void test_read_line(void) { |
752 | _cleanup_fclose_ FILE *f = NULL; | |
2c9de139 | 753 | |
673a1e6f | 754 | f = fmemopen_unlocked((void*) buffer, sizeof(buffer), "re"); |
2c9de139 ZJS |
755 | assert_se(f); |
756 | ||
757 | test_read_line_one_file(f); | |
758 | } | |
759 | ||
760 | static void test_read_line2(void) { | |
627d2bac | 761 | _cleanup_(unlink_tempfilep) char name[] = "/tmp/test-fileio.XXXXXX"; |
2c9de139 ZJS |
762 | int fd; |
763 | _cleanup_fclose_ FILE *f = NULL; | |
764 | ||
765 | fd = mkostemp_safe(name); | |
766 | assert_se(fd >= 0); | |
767 | assert_se((size_t) write(fd, buffer, sizeof(buffer)) == sizeof(buffer)); | |
768 | ||
769 | assert_se(lseek(fd, 0, SEEK_SET) == 0); | |
770 | assert_se(f = fdopen(fd, "r")); | |
771 | ||
772 | test_read_line_one_file(f); | |
773 | } | |
774 | ||
775 | static void test_read_line3(void) { | |
776 | _cleanup_fclose_ FILE *f = NULL; | |
777 | _cleanup_free_ char *line = NULL; | |
778 | int r; | |
779 | ||
30b84c78 | 780 | f = fopen("/proc/uptime", "re"); |
2c9de139 ZJS |
781 | if (!f && IN_SET(errno, ENOENT, EPERM)) |
782 | return; | |
783 | assert_se(f); | |
784 | ||
785 | r = read_line(f, LINE_MAX, &line); | |
b4555637 ZJS |
786 | assert_se(r >= 0); |
787 | if (r == 0) | |
788 | assert_se(line && isempty(line)); | |
789 | else | |
790 | assert_se((size_t) r == strlen(line) + 1); | |
2c9de139 ZJS |
791 | assert_se(read_line(f, LINE_MAX, NULL) == 0); |
792 | } | |
793 | ||
6baac700 LP |
794 | static void test_read_line4(void) { |
795 | static const struct { | |
796 | size_t length; | |
797 | const char *string; | |
798 | } eof_endings[] = { | |
799 | /* Each of these will be followed by EOF and should generate the one same single string */ | |
800 | { 3, "foo" }, | |
801 | { 4, "foo\n" }, | |
802 | { 4, "foo\r" }, | |
803 | { 4, "foo\0" }, | |
804 | { 5, "foo\n\0" }, | |
805 | { 5, "foo\r\0" }, | |
806 | { 5, "foo\r\n" }, | |
807 | { 5, "foo\n\r" }, | |
808 | { 6, "foo\r\n\0" }, | |
809 | { 6, "foo\n\r\0" }, | |
810 | }; | |
811 | ||
812 | size_t i; | |
813 | int r; | |
814 | ||
815 | for (i = 0; i < ELEMENTSOF(eof_endings); i++) { | |
816 | _cleanup_fclose_ FILE *f = NULL; | |
817 | _cleanup_free_ char *s = NULL; | |
818 | ||
673a1e6f | 819 | assert_se(f = fmemopen_unlocked((void*) eof_endings[i].string, eof_endings[i].length, "r")); |
6baac700 LP |
820 | |
821 | r = read_line(f, (size_t) -1, &s); | |
822 | assert_se((size_t) r == eof_endings[i].length); | |
823 | assert_se(streq_ptr(s, "foo")); | |
824 | ||
825 | assert_se(read_line(f, (size_t) -1, NULL) == 0); /* Ensure we hit EOF */ | |
826 | } | |
827 | } | |
828 | ||
3946d576 LP |
829 | static void test_read_nul_string(void) { |
830 | static const char test[] = "string nr. 1\0" | |
831 | "string nr. 2\n\0" | |
517b7760 | 832 | "\377empty string follows\0" |
3946d576 LP |
833 | "\0" |
834 | "final string\n is empty\0" | |
835 | "\0"; | |
836 | ||
837 | _cleanup_fclose_ FILE *f = NULL; | |
838 | _cleanup_free_ char *s = NULL; | |
839 | ||
673a1e6f | 840 | assert_se(f = fmemopen_unlocked((void*) test, sizeof(test)-1, "r")); |
3946d576 LP |
841 | |
842 | assert_se(read_nul_string(f, LONG_LINE_MAX, &s) == 13 && streq_ptr(s, "string nr. 1")); | |
843 | s = mfree(s); | |
844 | ||
845 | assert_se(read_nul_string(f, LONG_LINE_MAX, &s) == 14 && streq_ptr(s, "string nr. 2\n")); | |
846 | s = mfree(s); | |
847 | ||
517b7760 | 848 | assert_se(read_nul_string(f, LONG_LINE_MAX, &s) == 22 && streq_ptr(s, "\377empty string follows")); |
3946d576 LP |
849 | s = mfree(s); |
850 | ||
851 | assert_se(read_nul_string(f, LONG_LINE_MAX, &s) == 1 && streq_ptr(s, "")); | |
852 | s = mfree(s); | |
853 | ||
854 | assert_se(read_nul_string(f, LONG_LINE_MAX, &s) == 23 && streq_ptr(s, "final string\n is empty")); | |
855 | s = mfree(s); | |
856 | ||
857 | assert_se(read_nul_string(f, LONG_LINE_MAX, &s) == 1 && streq_ptr(s, "")); | |
858 | s = mfree(s); | |
859 | ||
860 | assert_se(read_nul_string(f, LONG_LINE_MAX, &s) == 0 && streq_ptr(s, "")); | |
861 | } | |
862 | ||
b93d3f6b LP |
863 | static void test_read_full_file_socket(void) { |
864 | _cleanup_(rm_rf_physical_and_freep) char *z = NULL; | |
865 | _cleanup_close_ int listener = -1; | |
866 | _cleanup_free_ char *data = NULL; | |
867 | union sockaddr_union sa; | |
868 | const char *j; | |
869 | size_t size; | |
870 | pid_t pid; | |
871 | int r; | |
872 | ||
873 | log_info("/* %s */", __func__); | |
874 | ||
875 | listener = socket(AF_UNIX, SOCK_STREAM|SOCK_CLOEXEC, 0); | |
876 | assert_se(listener >= 0); | |
877 | ||
878 | assert_se(mkdtemp_malloc(NULL, &z) >= 0); | |
879 | j = strjoina(z, "/socket"); | |
880 | ||
881 | assert_se(sockaddr_un_set_path(&sa.un, j) >= 0); | |
882 | ||
883 | assert_se(bind(listener, &sa.sa, SOCKADDR_UN_LEN(sa.un)) >= 0); | |
884 | assert_se(listen(listener, 1) >= 0); | |
885 | ||
886 | r = safe_fork("(server)", FORK_DEATHSIG|FORK_LOG, &pid); | |
887 | assert_se(r >= 0); | |
888 | if (r == 0) { | |
889 | _cleanup_close_ int rfd = -1; | |
890 | /* child */ | |
891 | ||
892 | rfd = accept4(listener, NULL, 0, SOCK_CLOEXEC); | |
893 | assert_se(rfd >= 0); | |
894 | ||
895 | #define TEST_STR "This is a test\nreally." | |
896 | ||
897 | assert_se(write(rfd, TEST_STR, strlen(TEST_STR)) == strlen(TEST_STR)); | |
898 | _exit(EXIT_SUCCESS); | |
899 | } | |
900 | ||
901 | assert_se(read_full_file_full(AT_FDCWD, j, 0, &data, &size) == -ENXIO); | |
902 | assert_se(read_full_file_full(AT_FDCWD, j, READ_FULL_FILE_CONNECT_SOCKET, &data, &size) >= 0); | |
903 | assert_se(size == strlen(TEST_STR)); | |
904 | assert_se(streq(data, TEST_STR)); | |
905 | ||
906 | assert_se(wait_for_terminate_and_check("(server)", pid, WAIT_LOG) >= 0); | |
907 | #undef TEST_STR | |
908 | } | |
909 | ||
f73141d7 | 910 | int main(int argc, char *argv[]) { |
6d7c4033 | 911 | test_setup_logging(LOG_DEBUG); |
1e5413f7 | 912 | |
f73141d7 | 913 | test_parse_env_file(); |
ac4c8d6d | 914 | test_parse_multiline_env_file(); |
37f3ffca | 915 | test_merge_env_file(); |
184d1904 | 916 | test_merge_env_file_invalid(); |
68fee104 | 917 | test_executable_is_script(); |
69ab8088 | 918 | test_status_field(); |
1e5413f7 | 919 | test_capeff(); |
0709b743 RC |
920 | test_write_string_stream(); |
921 | test_write_string_file(); | |
e07995a3 | 922 | test_write_string_file_no_create(); |
eb3da901 | 923 | test_write_string_file_verify(); |
e07995a3 | 924 | test_load_env_file_pairs(); |
897891f0 RC |
925 | test_search_and_fopen(); |
926 | test_search_and_fopen_nulstr(); | |
927 | test_writing_tmpfile(); | |
928 | test_tempfn(); | |
7f9d1aed | 929 | test_fgetc(); |
4f9a66a3 | 930 | test_read_line(); |
2c9de139 ZJS |
931 | test_read_line2(); |
932 | test_read_line3(); | |
6baac700 | 933 | test_read_line4(); |
3946d576 | 934 | test_read_nul_string(); |
b93d3f6b | 935 | test_read_full_file_socket(); |
1e5413f7 | 936 | |
f73141d7 LP |
937 | return 0; |
938 | } |