#include "strv.h"
#include "tests.h"
#include "tmpfile-util.h"
-#include "util.h"
TEST(parse_env_file) {
_cleanup_(unlink_tempfilep) char
char name[] = "/tmp/test-search_and_fopen.XXXXXX";
_cleanup_fclose_ FILE *f = NULL;
_cleanup_free_ char *p = NULL;
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
const char *e;
int r;
f = safe_fclose(f);
p = mfree(p);
- r = search_and_fopen("/a/file/which/does/not/exist/i/guess", "r", NULL, (const char**) dirs, &f, &p);
+ r = search_and_fopen("/a/file/which/does/not/exist/i/guess", "re", NULL, (const char**) dirs, &f, &p);
assert_se(r == -ENOENT);
- r = search_and_fopen("afilewhichdoesnotexistiguess", "r", NULL, (const char**) dirs, &f, &p);
+ r = search_and_fopen("afilewhichdoesnotexistiguess", "re", NULL, (const char**) dirs, &f, &p);
assert_se(r == -ENOENT);
r = unlink(name);
assert_se(r == 0);
- r = search_and_fopen(basename(name), "r", NULL, (const char**) dirs, &f, &p);
+ r = search_and_fopen(basename(name), "re", NULL, (const char**) dirs, &f, &p);
assert_se(r == -ENOENT);
}
_cleanup_(unlink_tempfilep) char name[] = "/tmp/test-search_and_fopen.XXXXXX";
_cleanup_fclose_ FILE *f = NULL;
_cleanup_free_ char *p = NULL;
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
const char *e;
int r;
f = safe_fclose(f);
p = mfree(p);
- r = search_and_fopen_nulstr("/a/file/which/does/not/exist/i/guess", "r", NULL, dirs, &f, &p);
+ r = search_and_fopen_nulstr("/a/file/which/does/not/exist/i/guess", "re", NULL, dirs, &f, &p);
assert_se(r == -ENOENT);
- r = search_and_fopen_nulstr("afilewhichdoesnotexistiguess", "r", NULL, dirs, &f, &p);
+ r = search_and_fopen_nulstr("afilewhichdoesnotexistiguess", "re", NULL, dirs, &f, &p);
assert_se(r == -ENOENT);
r = unlink(name);
assert_se(r == 0);
- r = search_and_fopen_nulstr(basename(name), "r", NULL, dirs, &f, &p);
+ r = search_and_fopen_nulstr(basename(name), "re", NULL, dirs, &f, &p);
assert_se(r == -ENOENT);
}
_cleanup_(unlink_tempfilep) char name[] = "/tmp/test-systemd_writing_tmpfile.XXXXXX";
_cleanup_free_ char *contents = NULL;
size_t size;
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
int r;
struct iovec iov[] = {
_cleanup_fclose_ FILE *f = NULL;
char c;
- assert_se(f = fmemopen_unlocked((void*) chars, sizeof(chars), "re"));
+ assert_se(f = fmemopen_unlocked((void*) chars, sizeof(chars), "r"));
for (size_t i = 0; i < sizeof(chars); i++) {
assert_se(safe_fgetc(f, &c) == 1);
TEST(read_line1) {
_cleanup_fclose_ FILE *f = NULL;
- assert_se(f = fmemopen_unlocked((void*) buffer, sizeof(buffer), "re"));
+ assert_se(f = fmemopen_unlocked((void*) buffer, sizeof(buffer), "r"));
test_read_line_one_file(f);
}
_cleanup_close_ int listener = -1;
_cleanup_free_ char *data = NULL, *clientname = NULL;
union sockaddr_union sa;
- const char *j;
+ const char *j, *jj;
size_t size;
pid_t pid;
int r;
assert_se(bind(listener, &sa.sa, SOCKADDR_UN_LEN(sa.un)) >= 0);
assert_se(listen(listener, 1) >= 0);
+ /* Make sure the socket doesn't fit into a struct sockaddr_un, but we can still access it */
+ jj = strjoina(z, "/a_very_long_patha_very_long_patha_very_long_patha_very_long_patha_very_long_patha_very_long_patha_very_long_patha_very_long_path");
+ assert_se(strlen(jj) > sizeof_field(struct sockaddr_un, sun_path));
+ assert_se(rename(j, jj) >= 0);
+
/* Bind the *client* socket to some randomized name, to verify that this works correctly. */
assert_se(asprintf(&clientname, "@%" PRIx64 "/test-bindname", random_u64()) >= 0);
if (r == 0) {
union sockaddr_union peer = {};
socklen_t peerlen = sizeof(peer);
- _cleanup_close_ int rfd = -1;
+ _cleanup_close_ int rfd = -EBADF;
/* child */
rfd = accept4(listener, NULL, 0, SOCK_CLOEXEC);
_exit(EXIT_SUCCESS);
}
- assert_se(read_full_file_full(AT_FDCWD, j, UINT64_MAX, SIZE_MAX, 0, NULL, &data, &size) == -ENXIO);
- assert_se(read_full_file_full(AT_FDCWD, j, UINT64_MAX, SIZE_MAX, READ_FULL_FILE_CONNECT_SOCKET, clientname, &data, &size) >= 0);
+ assert_se(read_full_file_full(AT_FDCWD, jj, UINT64_MAX, SIZE_MAX, 0, NULL, &data, &size) == -ENXIO);
+ assert_se(read_full_file_full(AT_FDCWD, jj, UINT64_MAX, SIZE_MAX, READ_FULL_FILE_CONNECT_SOCKET, clientname, &data, &size) >= 0);
assert_se(size == strlen(TEST_STR));
assert_se(streq(data, TEST_STR));