subsystem_test_helper.c [plain text]
#include <fcntl.h>
#include <string.h>
#include <unistd.h>
#include <subsystem.h>
#include <sys/stat.h>
#include <sys/errno.h>
#include "subsystem_test.h"
#include <stdio.h>
int
main(int argc, char **argv)
{
struct stat stat_buf;
int syscall_return = 0;
int retval = 1;
ino_t inode;
ino_t main_inode;
if (argc != 4) {
return retval;
}
char * behavior = argv[1];
char * filepath = argv[2];
char * write_string = argv[3];
size_t write_string_len = strlen(write_string) + 1;
if (!strcmp(behavior, HELPER_BEHAVIOR_OPEN_OVERFLOW)) {
syscall_return = open_with_subsystem(filepath, O_RDWR);
if (syscall_return < 0) {
if (errno == ENAMETOOLONG) {
retval = 0;
}
} else {
close(syscall_return);
}
} else if (!strcmp(behavior, HELPER_BEHAVIOR_STAT_OVERFLOW)) {
syscall_return = stat_with_subsystem(filepath, &stat_buf);
if ((syscall_return < 0) && (errno == ENAMETOOLONG)) {
retval = 0;
}
}
if (!strcmp(behavior, HELPER_BEHAVIOR_OPEN_O_CREAT)) {
syscall_return = open_with_subsystem(filepath, O_CREAT | O_RDWR);
if ((syscall_return < 0) && (errno == EINVAL)) {
retval = 0;
} else {
close(syscall_return);
}
} else if (!strcmp(behavior, HELPER_BEHAVIOR_STAT_NONE)) {
syscall_return = stat_with_subsystem(filepath, &stat_buf);
if (syscall_return) {
retval = 0;
}
} else if (!strcmp(behavior, HELPER_BEHAVIOR_STAT_MAIN) ||
!strcmp(behavior, HELPER_BEHAVIOR_STAT_NOT_MAIN)) {
syscall_return = stat_with_subsystem(filepath, &stat_buf);
if (!syscall_return) {
inode = stat_buf.st_ino;
syscall_return = stat(filepath, &stat_buf);
if (!syscall_return) {
main_inode = stat_buf.st_ino;
if (!strcmp(behavior, HELPER_BEHAVIOR_STAT_MAIN)) {
if (inode == main_inode) {
retval = 0;
}
} else if (!strcmp(behavior, HELPER_BEHAVIOR_STAT_NOT_MAIN)) {
if (inode != main_inode) {
retval = 0;
}
}
} else if (!strcmp(behavior, HELPER_BEHAVIOR_STAT_NOT_MAIN)) {
retval = 0;
}
}
} else if (!strcmp(behavior, HELPER_BEHAVIOR_OPEN_AND_WRITE)) {
syscall_return = open_with_subsystem(filepath, O_RDWR | O_TRUNC);
if (syscall_return >= 0) {
write(syscall_return, write_string, write_string_len);
close(syscall_return);
retval = 0;
}
}
return retval;
}