]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
ipcs: make shmall overflow a bit less worse
authorRuediger Meier <ruediger.meier@ga-group.nl>
Fri, 31 Mar 2017 15:16:07 +0000 (17:16 +0200)
committerRuediger Meier <ruediger.meier@ga-group.nl>
Mon, 3 Apr 2017 07:34:38 +0000 (09:34 +0200)
Still no large integer support but on overflow we print now
the largest possible value, maybe even the largest one which
makes sense at all.

So on x86_64 systems we'll see now:
$ echo "4503599627370496" > /proc/sys/kernel/shmall
$ ipcs -m -l | grep "max total"
max total shared memory (kbytes) = 18014398509481980

rather than this:
$ ipcs -m -l | grep "max total"
max total shared memory (kbytes) = 0

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
sys-utils/ipcs.c
tests/ts/ipcs/functions.sh
tests/ts/ipcs/limits2

index 4f3d23d90762afcc0cd1560d8c92b6133a260ba7..3c4e5df0ead33f73f0dced8d6265e54b8a6ec86c 100644 (file)
@@ -198,6 +198,7 @@ static void do_shm (char format, int unit)
        case LIMITS:
        {
                struct ipc_limits lim;
+               uint64_t tmp, pgsz = getpagesize();
 
                if (ipc_shm_get_limits(&lim)) {
                        printf (_("unable to fetch shared memory limits\n"));
@@ -207,9 +208,14 @@ static void do_shm (char format, int unit)
                printf (_("max number of segments = %ju\n"), lim.shmmni);
                ipc_print_size(unit == IPC_UNIT_DEFAULT ? IPC_UNIT_KB : unit,
                               _("max seg size"), lim.shmmax, "\n", 0);
+
+               tmp = (uint64_t) lim.shmall * pgsz;
+               /* overflow handling, at least we don't print ridiculous small values */
+               if (lim.shmall != 0 && tmp / lim.shmall != pgsz) {
+                       tmp = UINT64_MAX - (UINT64_MAX % pgsz);
+               }
                ipc_print_size(unit == IPC_UNIT_DEFAULT ? IPC_UNIT_KB : unit,
-                              _("max total shared memory"),
-                              (uint64_t) lim.shmall * getpagesize(), "\n", 0);
+                              _("max total shared memory"), tmp, "\n", 0);
                ipc_print_size(unit == IPC_UNIT_DEFAULT ? IPC_UNIT_BYTES : unit,
                               _("min seg size"), lim.shmmin, "\n", 0);
                return;
index a9cf2286d78a935ee2f81678463128e7ecfa630e..586ce42f6543a0a0b3764e7036d96bdba394a122 100644 (file)
@@ -78,6 +78,12 @@ function ipcs_limits_check {
                #echo "IPCS-CMD:   ${IPCS_CMD[$i]}"
                #echo
 
+               # overflow is handled differently because we don't have large
+               # int math, see https://github.com/karelzak/util-linux/issues/51
+               if [ $(bc <<<"$a >= 2^64/1024") -eq 1 ]; then
+                       a=$(bc <<<"(2^64 - $PAGE_SIZE)/1024")
+               fi
+
                if [ x"$a" == x"$b" ]; then
                        echo " OK"
                else
index 4e96ce68031d90586f430a10577183134b97fa29..62a4f5bcb27d21e542d7957129a2b21340ae00cb 100755 (executable)
@@ -27,12 +27,6 @@ ts_check_prog "bc"
 
 . $TS_SELF/functions.sh
 
-# TODO https://github.com/karelzak/util-linux/issues/51
-SHMALL=$(</proc/sys/kernel/shmall)
-if [ $(bc <<<"(2^64 / $PAGE_SIZE) <= $SHMALL") -eq 1 ]; then
-       TS_KNOWN_FAIL="yes"
-fi
-
 ts_log "check for difference between kernel and IPC"
 ipcs_limits_check >> $TS_OUTPUT