]> granicus.if.org Git - strace/commitdiff
ipc: fix printing key_t arguments of msgget, semget, and shmget syscalls
authorDmitry V. Levin <ldv@altlinux.org>
Thu, 8 Sep 2016 12:49:35 +0000 (12:49 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Thu, 8 Sep 2016 16:26:48 +0000 (16:26 +0000)
* 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.

ipc_msg.c
ipc_sem.c
ipc_shm.c
tests/ipc_msg.c
tests/ipc_sem.c
tests/ipc_shm.c

index f04d14d76a26fe224b8a3ed1f33afe13a3ca3ecd..7ef5cda93f426a44abd41dc510b469840b11a93e 100644 (file)
--- a/ipc_msg.c
+++ b/ipc_msg.c
 
 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);
index e6172eefe6a53be3a6fb6b4b13ad5901ec2a4a4f..abcfa857f279d5bf9e6fedb2e13a8ec4d358440d 100644 (file)
--- 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]);
index e8a8206b9be047b666a78d6bf510af347cb6e759..93c8a27d8a699b3fdc9225374f212ba8a0467f06 100644 (file)
--- 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]);
index 2fd7d4f7d0f686e0ce7a241615e8bacc2ec04fc7..7a50007777f1b2cf5997435c8a8c102b1b946ee5 100644 (file)
@@ -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);
index afe74d29a12b446832dfa7a7196fa5035c02f83f..98753f3ccbd88219116bba96ae3217cbaf8767e7 100644 (file)
@@ -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);
index 54723e22ea036ab702ac8d149efa5ad3e6628884..55e5f74d39ff7acae9c74ce7ee74dc225afb0bbe 100644 (file)
@@ -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);