]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
ipcs: fix shmctl() usage
authorKarel Zak <kzak@redhat.com>
Fri, 19 Dec 2014 12:42:41 +0000 (13:42 +0100)
committerKarel Zak <kzak@redhat.com>
Fri, 19 Dec 2014 12:42:41 +0000 (13:42 +0100)
The function shmctl() has to be called with 'struct shmid_ds', and if
you need 'struct shminfo' then the right way is to cast:

bad way:
  struct shm_info info;

  shmctl(0, SHM_INFO, &info);

right way:
  struct shmid_ds buf;
  struct shm_info *info;

  shmctl(0, SHM_INFO, &buf);
  info = (struct shm_info *) &buf);

The patch also fixes bug in ipc_shm_get_limits() where is missing
lim->shmmax in code based on shmctl().

Signed-off-by: Karel Zak <kzak@redhat.com>
sys-utils/ipcrm.c
sys-utils/ipcs.c
sys-utils/ipcutils.c

index 6443f48fb2b499463bd456ff16302f52146e18c3..5fe3df849f27b7dbe2185821906b325a030d6f03 100644 (file)
@@ -235,7 +235,6 @@ static int remove_all(type_id type)
        int id, rm_me, maxid;
 
        struct shmid_ds shmseg;
-       struct shm_info shm_info;
 
        struct semid_ds semary;
        struct seminfo seminfo;
@@ -245,8 +244,7 @@ static int remove_all(type_id type)
        struct msginfo msginfo;
 
        if (type == SHM || type == ALL) {
-               maxid =
-                   shmctl(0, SHM_INFO, (struct shmid_ds *)(void *)&shm_info);
+               maxid = shmctl(0, SHM_INFO, &shmseg);
                if (maxid < 0)
                        errx(EXIT_FAILURE,
                             _("kernel not configured for shared memory"));
index 9ce536612772bf0d450d525cffe176ca8224aecd..a2d7f12ad4f08d1f2f827eee2bc3db768f06f009 100644 (file)
@@ -209,9 +209,11 @@ static void do_shm (char format, int unit)
        case STATUS:
        {
                int maxid;
-               struct shm_info shm_info;
+               struct shmid_ds shmbuf;
+               struct shm_info *shm_info;
 
-               maxid = shmctl (0, SHM_INFO, (struct shmid_ds *) &shm_info);
+               maxid = shmctl (0, SHM_INFO, &shmbuf);
+               shm_info =  (struct shm_info *) &shmbuf;
                if (maxid < 0) {
                        printf (_("kernel not configured for shared memory\n"));
                        return;
@@ -234,11 +236,11 @@ static void do_shm (char format, int unit)
                          "pages resident  %ld\n"
                          "pages swapped   %ld\n"
                          "Swap performance: %ld attempts\t %ld successes\n"),
-                       shm_info.used_ids,
-                       shm_info.shm_tot,
-                       shm_info.shm_rss,
-                       shm_info.shm_swp,
-                       shm_info.swap_attempts, shm_info.swap_successes);
+                       shm_info->used_ids,
+                       shm_info->shm_tot,
+                       shm_info->shm_rss,
+                       shm_info->shm_swp,
+                       shm_info->swap_attempts, shm_info->swap_successes);
                return;
        }
 
index 3d5249c939ae5ec097d45adb102fe9e9353c41ee..d1858a06ad335d153b8b9e0ead125ba4fad594c7 100644 (file)
@@ -1,4 +1,3 @@
-
 #include <inttypes.h>
 
 #include "c.h"
@@ -82,12 +81,15 @@ int ipc_shm_get_limits(struct ipc_limits *lim)
                lim->shmmni = path_read_u64(_PATH_PROC_IPC_SHMMNI);
 
        } else {
-               struct shminfo shminfo;
+               struct shminfo *shminfo;
+               struct shmid_ds shmbuf;
 
-               if (shmctl(0, IPC_INFO, (struct shmid_ds *) &shminfo) < 0)
+               if (shmctl(0, IPC_INFO, &shmbuf) < 0)
                        return 1;
-               lim->shmmni = shminfo.shmmni;
-               lim->shmall = shminfo.shmall;
+               shminfo = (struct shminfo *) &shmbuf;
+               lim->shmmni = shminfo->shmmni;
+               lim->shmall = shminfo->shmall;
+               lim->shmmax = shminfo->shmmax;
        }
 
        return 0;