Skip to content

Commit cc26cdc

Browse files
authored
Merge pull request #1352 from martin-frbg/issue1351
Output an error message when shmat() fails
2 parents c6968ed + d857682 commit cc26cdc

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)