summaryrefslogtreecommitdiffstats
path: root/src/test/test-socket-util.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/test/test-socket-util.c37
1 files changed, 17 insertions, 20 deletions
diff --git a/src/test/test-socket-util.c b/src/test/test-socket-util.c
index e9c776a..e34aa10 100644
--- a/src/test/test-socket-util.c
+++ b/src/test/test-socket-util.c
@@ -69,7 +69,7 @@ static void test_socket_print_unix_one(const char *in, size_t len_in, const char
assert_se(socket_address_print(&a, &out) >= 0);
assert_se(c = cescape(in));
log_info("\"%s\" → \"%s\" (expect \"%s\")", in, out, expected);
- assert_se(streq(out, expected));
+ ASSERT_STREQ(out, expected);
}
TEST(socket_print_unix) {
@@ -168,7 +168,7 @@ TEST(getpeercred_getpeergroups) {
uid_t test_uid;
gid_t test_gid;
struct ucred ucred;
- int pair[2];
+ int pair[2] = EBADF_PAIR;
if (geteuid() == 0) {
test_uid = 1;
@@ -176,10 +176,7 @@ TEST(getpeercred_getpeergroups) {
test_gids = (gid_t*) gids;
n_test_gids = ELEMENTSOF(gids);
- assert_se(setgroups(n_test_gids, test_gids) >= 0);
- assert_se(setresgid(test_gid, test_gid, test_gid) >= 0);
- assert_se(setresuid(test_uid, test_uid, test_uid) >= 0);
-
+ assert_se(fully_set_uid_gid(test_uid, test_gid, test_gids, n_test_gids) >= 0);
} else {
long ngroups_max;
@@ -223,7 +220,7 @@ TEST(getpeercred_getpeergroups) {
TEST(passfd_read) {
static const char file_contents[] = "test contents for passfd";
- _cleanup_close_pair_ int pair[2];
+ _cleanup_close_pair_ int pair[2] = EBADF_PAIR;
int r;
assert_se(socketpair(AF_UNIX, SOCK_DGRAM, 0, pair) >= 0);
@@ -249,7 +246,7 @@ TEST(passfd_read) {
/* Parent */
char buf[64];
struct iovec iov = IOVEC_MAKE(buf, sizeof(buf)-1);
- _cleanup_close_ int fd;
+ _cleanup_close_ int fd = -EBADF;
pair[1] = safe_close(pair[1]);
@@ -259,11 +256,11 @@ TEST(passfd_read) {
r = read(fd, buf, sizeof(buf)-1);
assert_se(r >= 0);
buf[r] = 0;
- assert_se(streq(buf, file_contents));
+ ASSERT_STREQ(buf, file_contents);
}
TEST(passfd_contents_read) {
- _cleanup_close_pair_ int pair[2];
+ _cleanup_close_pair_ int pair[2] = EBADF_PAIR;
static const char file_contents[] = "test contents in the file";
static const char wire_contents[] = "test contents on the wire";
int r;
@@ -293,7 +290,7 @@ TEST(passfd_contents_read) {
/* Parent */
char buf[64];
struct iovec iov = IOVEC_MAKE(buf, sizeof(buf)-1);
- _cleanup_close_ int fd;
+ _cleanup_close_ int fd = -EBADF;
ssize_t k;
pair[1] = safe_close(pair[1]);
@@ -301,17 +298,17 @@ TEST(passfd_contents_read) {
k = receive_one_fd_iov(pair[0], &iov, 1, MSG_DONTWAIT, &fd);
assert_se(k > 0);
buf[k] = 0;
- assert_se(streq(buf, wire_contents));
+ ASSERT_STREQ(buf, wire_contents);
assert_se(fd >= 0);
r = read(fd, buf, sizeof(buf)-1);
assert_se(r >= 0);
buf[r] = 0;
- assert_se(streq(buf, file_contents));
+ ASSERT_STREQ(buf, file_contents);
}
TEST(pass_many_fds_contents_read) {
- _cleanup_close_pair_ int pair[2];
+ _cleanup_close_pair_ int pair[2] = EBADF_PAIR;
static const char file_contents[][STRLEN("test contents in the fileX") + 1] = {
"test contents in the file0",
"test contents in the file1",
@@ -361,7 +358,7 @@ TEST(pass_many_fds_contents_read) {
k = receive_many_fds_iov(pair[0], &iov, 1, &fds, &n_fds, MSG_DONTWAIT);
assert_se(k > 0);
buf[k] = 0;
- assert_se(streq(buf, wire_contents));
+ ASSERT_STREQ(buf, wire_contents);
assert_se(n_fds == 3);
@@ -370,13 +367,13 @@ TEST(pass_many_fds_contents_read) {
r = read(fds[i], buf, sizeof(buf)-1);
assert_se(r >= 0);
buf[r] = 0;
- assert_se(streq(buf, file_contents[i]));
+ ASSERT_STREQ(buf, file_contents[i]);
safe_close(fds[i]);
}
}
TEST(receive_nopassfd) {
- _cleanup_close_pair_ int pair[2];
+ _cleanup_close_pair_ int pair[2] = EBADF_PAIR;
static const char wire_contents[] = "no fd passed here";
int r;
@@ -406,14 +403,14 @@ TEST(receive_nopassfd) {
k = receive_one_fd_iov(pair[0], &iov, 1, MSG_DONTWAIT, &fd);
assert_se(k > 0);
buf[k] = 0;
- assert_se(streq(buf, wire_contents));
+ ASSERT_STREQ(buf, wire_contents);
/* no fd passed here, confirm it was reset */
assert_se(fd == -EBADF);
}
TEST(send_nodata_nofd) {
- _cleanup_close_pair_ int pair[2];
+ _cleanup_close_pair_ int pair[2] = EBADF_PAIR;
int r;
assert_se(socketpair(AF_UNIX, SOCK_DGRAM, 0, pair) >= 0);
@@ -446,7 +443,7 @@ TEST(send_nodata_nofd) {
}
TEST(send_emptydata) {
- _cleanup_close_pair_ int pair[2];
+ _cleanup_close_pair_ int pair[2] = EBADF_PAIR;
int r;
assert_se(socketpair(AF_UNIX, SOCK_DGRAM, 0, pair) >= 0);