From a47463a72864a76b0557468daf83741632ea4d72 Mon Sep 17 00:00:00 2001
From: Patrick Mansfield <patrick.mansfield@cpacketnetworks.com>
Date: Mon, 30 Sep 2019 15:59:53 -0700
Subject: [PATCH] Fix crashes when using the "--touch" option.
Fix memory to be mapped read/write, so that the "touch" option can write to it.
Signed-off-by: Patrick Mansfield <patrick.mansfield@cpacketnetworks.com>
---
shm.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/shm.c b/shm.c
index 260eeff..fb592ed 100644
--- a/shm.c
+++ b/shm.c
@@ -119,7 +119,7 @@ void attach_sysvshm(char *name, char *opt)
shmlen = s.shm_segsz;
}
- shmptr = shmat(shmfd, NULL, SHM_RDONLY);
+ shmptr = shmat(shmfd, NULL, 0);
if (shmptr == (void*)-1)
err("shmat");
shmptr += shmoffset;
@@ -134,7 +134,7 @@ void attach_shared(char *name, char *opt)
{
struct stat64 st;
- shmfd = open(name, O_RDONLY);
+ shmfd = open(name, O_RDWR);
if (shmfd < 0) {
errno = 0;
if (shmlen == 0)
@@ -160,7 +160,7 @@ void attach_shared(char *name, char *opt)
/* RED-PEN For shmlen > address space may need to map in pieces.
Left for some poor 32bit soul. */
- shmptr = mmap64(NULL, shmlen, PROT_READ, MAP_SHARED, shmfd, shmoffset);
+ shmptr = mmap64(NULL, shmlen, PROT_READ | PROT_WRITE, MAP_SHARED, shmfd, shmoffset);
if (shmptr == (char*)-1)
err("shm mmap");
--
2.7.5