]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
test: More portable use of mmap(MAP_ANON)
authorWillem Jan Withagen <wjw@digiware.nl>
Wed, 3 Aug 2016 13:05:52 +0000 (15:05 +0200)
committerWillem Jan Withagen <wjw@digiware.nl>
Thu, 4 Aug 2016 17:06:47 +0000 (19:06 +0200)
From the Linux manual:
  MAP_ANONYMOUS
     The  mapping  is  not  backed  by any file; its contents
     are initialized to zero.  The fd and offset arguments are
     ignored; however, some implementations require fd to be -1
     if MAP_ANONYMOUS (or MAP_ANON) is specified, and portable
     applications  should  ensure  this.

FreeBSD is such a case, it wil just return an error.

 - Used in:
     src/test/on_exit.cc
     src/test/system/cross_process_sem.cc

Signed-off-by: Willem Jan Withagen <wjw@digiware.nl>
src/test/on_exit.cc
src/test/system/cross_process_sem.cc

index 26f357efa10e483759a59266f94fb411fdccd05c..48c19fca468efe6a1d5ac567ccd457ae251377cf 100644 (file)
@@ -64,7 +64,7 @@ int main(int argc, char **argv)
 
   // shared mem for exit tests
   shared_val = (int*)mmap(NULL, sizeof(int),
-      PROT_READ|PROT_WRITE, MAP_SHARED|MAP_ANONYMOUS, 0, 0);
+      PROT_READ|PROT_WRITE, MAP_SHARED|MAP_ANONYMOUS, -1, 0);
   assert(shared_val != MAP_FAILED);
 
   // test normal exit returning from main
index 667ba1cc861366937e62e34dd2c74c83a23010d8..5785a6626b0d64a2c869c49408a1d4696f79e279 100644 (file)
@@ -36,7 +36,7 @@ create(int initial_val, CrossProcessSem** res)
 {
   struct cross_process_sem_data_t *data = static_cast < cross_process_sem_data_t*> (
     mmap(NULL, sizeof(struct cross_process_sem_data_t),
-       PROT_READ|PROT_WRITE, MAP_SHARED|MAP_ANONYMOUS, 0, 0));
+       PROT_READ|PROT_WRITE, MAP_SHARED|MAP_ANONYMOUS, -1, 0));
   if (data == MAP_FAILED) {
     int err = errno;
     return err;