]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lsipc: fix semaphore USED counter
authorKarel Zak <kzak@redhat.com>
Tue, 26 Mar 2024 11:45:24 +0000 (12:45 +0100)
committerKarel Zak <kzak@redhat.com>
Tue, 26 Mar 2024 12:00:09 +0000 (13:00 +0100)
The code incorrectly counts only with the first item in the linked
list (due to a typo). It seems rather fragile to use "semds" and
"semdsp" as variable names in the same code ...

 # lsipc -gs

Old:

 KEY ID PERMS OWNER NSEMS RESOURCE DESCRIPTION                                LIMIT USED  USE%
                          SEMMNI   Number of semaphore identifiers            32000    3 0.01%
                          SEMMNS   Total number of semaphores            1024000000  369 0.00%
                          SEMMSL   Max semaphores per semaphore set.          32000    -     -
                          SEMOPM   Max number of operations per semop(2)        500    -     -
                          SEMVMX   Semaphore max value                        32767    -     -

Fixed:

 KEY ID PERMS OWNER NSEMS RESOURCE DESCRIPTION                                LIMIT USED  USE%
                          SEMMNI   Number of semaphore identifiers            32000    3 0.01%
                          SEMMNS   Total number of semaphores            1024000000  156 0.00%
                          SEMMSL   Max semaphores per semaphore set.          32000    -     -
                          SEMOPM   Max number of operations per semop(2)        500    -     -
                          SEMVMX   Semaphore max value                        32767    -     -

Addresses: https://issues.redhat.com/browse/RHEL-30269
Signed-off-by: Karel Zak <kzak@redhat.com>
sys-utils/lsipc.c

index 2c55611128e19c52513bd15cbc71358ffe417562..515788c13d4c916c0a74586e2ca7dad082ea183d 100644 (file)
@@ -717,16 +717,18 @@ static void do_sem(int id, struct lsipc_control *ctl, struct libscols_table *tb)
 
 static void do_sem_global(struct lsipc_control *ctl, struct libscols_table *tb)
 {
-       struct sem_data *semds, *semdsp;
+       struct sem_data *semds;
        struct ipc_limits lim;
        int nsems = 0, nsets = 0;
 
        ipc_sem_get_limits(&lim);
 
        if (ipc_sem_get_info(-1, &semds) > 0) {
-               for (semdsp = semds; semdsp->next != NULL; semdsp = semdsp->next) {
+               struct sem_data *p;
+
+               for (p = semds; p->next != NULL; p = p->next) {
                        ++nsets;
-                       nsems += semds->sem_nsems;
+                       nsems += p->sem_nsems;
                }
                ipc_sem_free_info(semds);
        }