*/
#include "tests_common.h"
+#include <sys/mman.h>
+#include <sys/stat.h>
+#include <sys/types.h>
#include <unistd.h>
#include <grp.h>
#include <errno.h>
return std::string("nullptr");
return std::string("\"") + cstr + "\"";
}
+
+int files_compare(int fd1, int fd2)
+{
+ //for getting files sizes
+ struct stat fs1, fs2;
+
+ //handlers for mmap()
+ void *h1 = MAP_FAILED;
+ void *h2 = MAP_FAILED;
+
+ //getting files information
+ RUNNER_ASSERT_ERRNO_MSG(fstat(fd1, &fs1) == 0, "fstat failed");
+ RUNNER_ASSERT_ERRNO_MSG(fstat(fd2, &fs2) == 0, "fstat failed");
+
+ if (fs1.st_size < fs2.st_size) {
+ return -1;
+ }
+
+ if (fs1.st_size > fs2.st_size) {
+ return 1;
+ }
+
+ //since Linux 2.6.12, mmap returns EINVAL if length is 0
+ //if both lengths are 0, files are actually the same
+ if (0 == fs1.st_size && 0 == fs2.st_size) {
+ return 0;
+ }
+
+ //mapping files to process memory
+ RUNNER_ASSERT_ERRNO_MSG((h1 = mmap(0, fs1.st_size, PROT_READ, MAP_SHARED, fd1, 0 )) != MAP_FAILED,
+ "mmap failed for fd=" << fd1);
+
+ if ((h2 = mmap(0, fs2.st_size, PROT_READ, MAP_SHARED, fd2, 0 )) == MAP_FAILED) {
+ munmap(h1, fs1.st_size);
+ RUNNER_ASSERT_MSG(h2 != MAP_FAILED, "mmap failed for fd=" << fd2
+ << ". " << strerror(errno));
+ }
+
+ int result = memcmp(h1, h2, fs1.st_size);
+ munmap(h1, fs1.st_size);
+ munmap(h2, fs2.st_size);
+
+ return result;
+}
void add_process_group(const char* group_name);
void remove_process_group(const char* group_name);
std::string formatCstr(const char *cstr);
+int files_compare(int fd1, int fd2);
#define RUNNER_TEST_SMACK(Proc) \
void Proc(); \
#include <dpl/log/log.h>
#include <sys/types.h>
#include <sys/stat.h>
-#include <sys/mman.h>
#include <sys/smack.h>
#include <sys/xattr.h>
#include <sys/socket.h>
//This one define is required for sockaddr_un initialization
#define SOCK_PATH "/tmp/test-smack-socket"
-int files_compare(int fd1, int fd2)
-{
- //for getting files sizes
- struct stat fs1, fs2;
-
- //handlers for mmap()
- void *h1 = MAP_FAILED;
- void *h2 = MAP_FAILED;
-
- //getting files information
- RUNNER_ASSERT_ERRNO_MSG(fstat(fd1, &fs1) == 0, "fstat failed");
- RUNNER_ASSERT_ERRNO_MSG(fstat(fd2, &fs2) == 0, "fstat failed");
-
- if (fs1.st_size < fs2.st_size) {
- return -1;
- }
-
- if (fs1.st_size > fs2.st_size) {
- return 1;
- }
-
- //since Linux 2.6.12, mmap returns EINVAL if length is 0
- //if both lengths are 0, files are actually the same
- if (0 == fs1.st_size && 0 == fs2.st_size) {
- return 0;
- }
-
- //mapping files to process memory
- RUNNER_ASSERT_ERRNO_MSG((h1 = mmap(0, fs1.st_size, PROT_READ, MAP_SHARED, fd1, 0 )) != MAP_FAILED,
- "mmap failed for fd=" << fd1);
-
- if ((h2 = mmap(0, fs2.st_size, PROT_READ, MAP_SHARED, fd2, 0 )) == MAP_FAILED) {
- munmap(h1, fs1.st_size);
- RUNNER_ASSERT_MSG(h2 != MAP_FAILED, "mmap failed for fd=" << fd2
- << ". " << strerror(errno));
- }
-
- int result = memcmp(h1, h2, fs1.st_size);
- munmap(h1, fs1.st_size);
- munmap(h2, fs2.st_size);
-
- return result;
-}
-
RUNNER_TEST_GROUP_INIT(libsmack)
/**
* Helper method to reset privileges at the begginning of tests.