Skip to content

Commit d857682

Browse files
authored
Output an error message when shmat() fails
Observed in #1351 with SELinux as the likely culprit. Without the message, the user saw a segfault with no apparent reason
1 parent c460027 commit d857682

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

driver/others/init.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
7878

7979
#include <sys/sysinfo.h>
8080
#include <sys/syscall.h>
81+
#include <sys/types.h>
82+
#include <errno.h>
8183
#include <sys/shm.h>
8284
#include <fcntl.h>
8385
#include <sched.h>
@@ -659,8 +661,9 @@ static void open_shmem(void) {
659661
exit(1);
660662
}
661663

662-
if (shmid != -1) common = (shm_t *)shmat(shmid, NULL, 0);
663-
664+
if (shmid != -1) {
665+
if ( (common = shmat(shmid, NULL, 0)) == (void*)-1) perror ("Attaching shared memory segment");
666+
}
664667
#ifdef DEBUG
665668
fprintf(stderr, "Shared Memory id = %x Address = %p\n", shmid, common);
666669
#endif

0 commit comments

Comments
 (0)