From: Dmitry V. Levin Date: Thu, 8 Sep 2016 12:49:35 +0000 (+0000) Subject: ipc: fix printing key_t arguments of msgget, semget, and shmget syscalls X-Git-Tag: v4.14~94 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7b93574bc705c2140fdc58fd30c5acefd043571b;p=strace ipc: fix printing key_t arguments of msgget, semget, and shmget syscalls * ipc_msg.c (SYS_FUNC(msgget)): As key_t type in the kernel is __kernel_key_t (i.e. int), cast key_t argument to int and print it using %#x format. * ipc_sem.c (SYS_FUNC(semget)): Likewise. * ipc_shm.c (SYS_FUNC(shmget)): Likewise. * tests/ipc_msg.c (main): Test it. * tests/ipc_sem.c (main): Likewise. * tests/ipc_shm.c (main): Likewise. --- diff --git a/ipc_msg.c b/ipc_msg.c index f04d14d7..7ef5cda9 100644 --- a/ipc_msg.c +++ b/ipc_msg.c @@ -44,10 +44,12 @@ SYS_FUNC(msgget) { - if (tcp->u_arg[0]) - tprintf("%#lx, ", tcp->u_arg[0]); + const int key = (int) tcp->u_arg[0]; + if (key) + tprintf("%#x", key); else - tprints("IPC_PRIVATE, "); + tprints("IPC_PRIVATE"); + tprints(", "); if (printflags(resource_flags, tcp->u_arg[1] & ~0777, NULL) != 0) tprints("|"); print_numeric_umode_t(tcp->u_arg[1] & 0777); diff --git a/ipc_sem.c b/ipc_sem.c index e6172eef..abcfa857 100644 --- a/ipc_sem.c +++ b/ipc_sem.c @@ -101,8 +101,9 @@ SYS_FUNC(semtimedop) SYS_FUNC(semget) { - if (tcp->u_arg[0]) - tprintf("%#lx", tcp->u_arg[0]); + const int key = (int) tcp->u_arg[0]; + if (key) + tprintf("%#x", key); else tprints("IPC_PRIVATE"); tprintf(", %lu, ", tcp->u_arg[1]); diff --git a/ipc_shm.c b/ipc_shm.c index e8a8206b..93c8a27d 100644 --- a/ipc_shm.c +++ b/ipc_shm.c @@ -43,8 +43,9 @@ SYS_FUNC(shmget) { - if (tcp->u_arg[0]) - tprintf("%#lx", tcp->u_arg[0]); + const int key = (int) tcp->u_arg[0]; + if (key) + tprintf("%#x", key); else tprints("IPC_PRIVATE"); tprintf(", %lu, ", tcp->u_arg[1]); diff --git a/tests/ipc_msg.c b/tests/ipc_msg.c index 2fd7d4f7..7a500077 100644 --- a/tests/ipc_msg.c +++ b/tests/ipc_msg.c @@ -45,10 +45,12 @@ cleanup(void) int main(void) { + static const key_t private_key = + (key_t) (0xffffffff00000000ULL | IPC_PRIVATE); int rc; struct msqid_ds ds; - id = msgget(IPC_PRIVATE, 0600); + id = msgget(private_key, 0600); if (id < 0) perror_msg_and_skip("msgget"); printf("msgget\\(IPC_PRIVATE, 0600\\) += %d\n", id); diff --git a/tests/ipc_sem.c b/tests/ipc_sem.c index afe74d29..98753f3c 100644 --- a/tests/ipc_sem.c +++ b/tests/ipc_sem.c @@ -53,12 +53,14 @@ cleanup(void) int main(void) { + static const key_t private_key = + (key_t) (0xffffffff00000000ULL | IPC_PRIVATE); int rc; union semun un; struct semid_ds ds; struct seminfo info; - id = semget(IPC_PRIVATE, 1, 0600); + id = semget(private_key, 1, 0600); if (id < 0) perror_msg_and_skip("semget"); printf("semget\\(IPC_PRIVATE, 1, 0600\\) += %d\n", id); diff --git a/tests/ipc_shm.c b/tests/ipc_shm.c index 54723e22..55e5f74d 100644 --- a/tests/ipc_shm.c +++ b/tests/ipc_shm.c @@ -45,10 +45,12 @@ cleanup(void) int main(void) { + static const key_t private_key = + (key_t) (0xffffffff00000000ULL | IPC_PRIVATE); int rc; struct shmid_ds ds; - id = shmget(IPC_PRIVATE, 1, 0600); + id = shmget(private_key, 1, 0600); if (id < 0) perror_msg_and_skip("shmget"); printf("shmget\\(IPC_PRIVATE, 1, 0600\\) += %d\n", id);