Commit 956d28bb authored by Cyrill Gorcunov's avatar Cyrill Gorcunov Committed by Pavel Emelyanov

zdtm: Extend file_own test for sockets

Signed-off-by: 's avatarCyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent a8840ba7
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include <sys/types.h> #include <sys/types.h>
#include <sys/wait.h> #include <sys/wait.h>
#include <sys/mman.h> #include <sys/mman.h>
#include <sys/socket.h>
#include "zdtmtst.h" #include "zdtmtst.h"
...@@ -26,7 +27,10 @@ static int received_io; ...@@ -26,7 +27,10 @@ static int received_io;
#define MAP(map, i) (((int *)map)[i]) #define MAP(map, i) (((int *)map)[i])
#define MAP_SYNC(map) MAP(map, 0) #define MAP_SYNC(map) MAP(map, 0)
#define MAP_PID(map) MAP(map, 1) #define MAP_PID_PIPE(map) MAP(map, 1)
#define MAP_PID_SOK(map) MAP(map, 2)
#define SK_DATA "packet"
static void signal_handler_io(int status) static void signal_handler_io(int status)
{ {
...@@ -44,6 +48,9 @@ int main(int argc, char ** argv) ...@@ -44,6 +48,9 @@ int main(int argc, char ** argv)
uid_t euid; uid_t euid;
uid_t suid; uid_t suid;
int ssk_pair[2];
char buf[64];
test_init(argc, argv); test_init(argc, argv);
if (getresuid(&ruid, &euid, &suid)) { if (getresuid(&ruid, &euid, &suid)) {
...@@ -62,6 +69,11 @@ int main(int argc, char ** argv) ...@@ -62,6 +69,11 @@ int main(int argc, char ** argv)
exit(1); exit(1);
} }
if (socketpair(AF_UNIX, SOCK_STREAM, 0, ssk_pair) == -1) {
fail("socketpair\n");
exit(1);
}
memset(&saio, 0, sizeof(saio)); memset(&saio, 0, sizeof(saio));
saio.sa_handler = (sig_t)signal_handler_io; saio.sa_handler = (sig_t)signal_handler_io;
sigaction(SIGIO, &saio, 0); sigaction(SIGIO, &saio, 0);
...@@ -82,6 +94,19 @@ int main(int argc, char ** argv) ...@@ -82,6 +94,19 @@ int main(int argc, char ** argv)
fcntl(pipes[0], F_SETFL, fcntl(pipes[0], F_GETFL) | O_NONBLOCK | O_ASYNC); fcntl(pipes[0], F_SETFL, fcntl(pipes[0], F_GETFL) | O_NONBLOCK | O_ASYNC);
fcntl(pipes[1], F_SETFL, fcntl(pipes[1], F_GETFL) | O_NONBLOCK | O_ASYNC); fcntl(pipes[1], F_SETFL, fcntl(pipes[1], F_GETFL) | O_NONBLOCK | O_ASYNC);
fcntl(ssk_pair[0], F_SETOWN, getpid());
fcntl(ssk_pair[0], F_SETSIG, SIGIO);
fcntl(ssk_pair[0], F_SETFL, fcntl(ssk_pair[0], F_GETFL) | O_NONBLOCK | O_ASYNC);
test_msg("main owner ssk_pair[0]: %d\n", fcntl(ssk_pair[0], F_GETOWN));
write(ssk_pair[0], SK_DATA, sizeof(SK_DATA));
read(ssk_pair[1], &buf, sizeof(buf));
if (strcmp(buf, SK_DATA)) {
fail("data corrupted\n");
exit(1);
}
test_msg("stream : '%s'\n", buf);
if (setresuid(-1, euid, -1)) { if (setresuid(-1, euid, -1)) {
fail("setresuid failed"); fail("setresuid failed");
exit(1); exit(1);
...@@ -112,7 +137,16 @@ int main(int argc, char ** argv) ...@@ -112,7 +137,16 @@ int main(int argc, char ** argv)
write(pipes[1], &v, sizeof(v)); write(pipes[1], &v, sizeof(v));
read(pipes[0], &v, sizeof(v)); read(pipes[0], &v, sizeof(v));
MAP_PID(map) = fcntl(pipes[0], F_GETOWN); write(ssk_pair[0], SK_DATA, sizeof(SK_DATA));
read(ssk_pair[1], &buf, sizeof(buf));
if (strcmp(buf, SK_DATA)) {
fail("data corrupted\n");
exit(1);
}
test_msg("stream : '%s'\n", buf);
MAP_PID_PIPE(map) = fcntl(pipes[0], F_GETOWN);
MAP_PID_SOK(map) = fcntl(ssk_pair[0], F_GETOWN);
exit(0); exit(0);
} }
...@@ -127,9 +161,9 @@ int main(int argc, char ** argv) ...@@ -127,9 +161,9 @@ int main(int argc, char ** argv)
waitpid(pid, &status, P_ALL); waitpid(pid, &status, P_ALL);
if (received_io < 1 || MAP_PID(map) != ppid) { if (received_io < 1 || MAP_PID_PIPE(map) != ppid || MAP_PID_SOK(map) != ppid) {
fail("received_io = %d ppid: %d MAP_PID(map): %d\n", fail("received_io = %d ppid: %d MAP_PID_PIPE(map): %d MAP_PID_SOK(map): %d\n",
received_io, ppid, MAP_PID(map)); received_io, ppid, MAP_PID_PIPE(map), MAP_PID_SOK(map));
exit(1); exit(1);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment