Commit Graph

32 Commits

Author SHA1 Message Date
Karel Zak 86d5de52d4 sys-utils/ipcutils: be careful when call calloc() for uint64 nmembs
Fix: https://github.com/karelzak/util-linux/issues/1395
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-07-29 11:57:17 +02:00
Karel Zak 31862cde0a fix compiler warnings
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-01-21 10:26:25 +01:00
Rosen Penev 042f62dfc5
[clang-tidy] do not use else after return
Found with readability-else-after-return

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2020-04-20 13:20:59 -07:00
Karel Zak e4c6816cc3 ipcs: check return value when read from /proc [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-05-23 15:32:59 +02:00
Ruediger Meier 77845f7bd7 ipcs,chmem: fix access() usage
Some mistakes happened lately when switching from path_exist()
to ul_path_access(). See f09a98de and 8ca31279.

This caused ipcs test failures when running i386 binaries on x86_64
hosts, because the syscall fallback was always used. That's why I
reviewed all similar changes and found another one in chmem.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2018-06-25 16:49:00 +02:00
Karel Zak f09a98de65 ipcs: use new ul_path_* API
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-06-21 13:07:46 +02:00
Karel Zak 9d4f78ef0e ipcs: fix memory leak [coverity scan]
It's not important, but let's keep static analyzes happy.

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-10-12 14:39:54 +02:00
Sebastian Rasmussen 9e93004171 misc: Fix various typos
Fix various typos in error messages, warnings, debug strings,
comments and names of static functions.

Signed-off-by: Sebastian Rasmussen <sebras@gmail.com>
2016-05-31 23:40:21 +02:00
Karel Zak 60ee341ba9 ipcs: make static analyzer happy [clang analyze]
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-03-29 14:02:57 +02:00
Ruediger Meier 73f4f3d925 ipcs: --shmems, upward/backward compatibility
Re-add backward compatibility which got lost in 058e8154.
Initializing unknown struct members to 0xdead is similar to
the fallback.

For upward compatibility ignore columns > 16 but not the whole
line (in case the kernel would add more columns in future).

Reported-by: Benno Schulenberg <bensberg@justemail.net>
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-03-18 15:38:06 +01:00
Ruediger Meier 97fab80eaf ipcs: make sure to parse whole lines for shm_data
We want to parse 16 columns _per_row_ without mixing them up. The
existing code is unsafe for more or less columns and could even
run into endless loops. This patch assures that we parse row-wise
and really skip lines with columns != 16.

Probably somehow we could have also done this with fscanf() only.
Using fgets() additionally makes the code more easy to read and
to improve later.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-03-18 15:38:05 +01:00
Karel Zak 53650755e0 ipcs: fix ipc_sem_get_limits()
Reported-by: https://github.com/AndrewIrcha
Addresses: e5995acda2 (commitcomment-13200369)
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-09-15 09:50:08 +02:00
Sami Kerola 587f90b055 ipcs: remove FIXME markup
The ipc message q_qbytes information is not in /proc, and it is unlikely
it will ever appear to there.

Reference: https://lkml.org/lkml/2012/11/25/18
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2015-01-07 21:57:53 +00:00
Karel Zak 929c257548 ipcs: fix shmctl() usage
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>
2014-12-19 13:42:41 +01:00
Sami Kerola 3ce29d6d46 ipcs: fix two data type errors [AddressSanitizer]
==3218==ERROR: AddressSanitizer: stack-buffer-overflow on address 0x7fffa577e2b0 at pc 0x4501f9 bp 0x7fffa577e130 sp 0x7fffa577e108
WRITE of size 112 at 0x7fffa577e2b0 thread T0
    #0 0x4501f8 in shmctl /home/users/aadgrand/LLVM/releases/ubuntu/final/llvm.src/projects/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc:2502
    #1 0x48bd13 in ipc_shm_get_info /home/travis/build/kerolasa/lelux-utiliteetit/sys-utils/ipcutils.c:157
    #2 0x488884 in do_shm /home/travis/build/kerolasa/lelux-utiliteetit/sys-utils/ipcs.c:279
    #3 0x4844a8 in main /home/travis/build/kerolasa/lelux-utiliteetit/sys-utils/ipcs.c:175
    #4 0x2afb3f8c176c (/lib/x86_64-linux-gnu/libc.so.6+0x2176c)
    #5 0x48408c in _start (/home/travis/build/kerolasa/lelux-utiliteetit/ipcs+0x48408c)

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2014-12-19 11:32:38 +01:00
Ruediger Meier 3d5fcdb19a ipcs: fix memleak in ipc_*_get_info functions
In case of error (maxid < 0) we do not enter following for loop. It will
return 0 and free the structs afterwards because i is still 0.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2014-03-14 00:23:14 +01:00
Ruediger Meier 5078a0d31d ipcs: fix ipc_sem_get_info fallback case
"ipcs -s -i n" (case id >= 0) was broken since v2.22-254-g1e2418a if /sys
is not usable.

See also comments for commit "ipcs: fix ipc_msg_get_info fallback case".

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2014-03-14 00:22:56 +01:00
Ruediger Meier b507e426df ipcs: fix ipc_shm_get_info fallback case
"ipcs -m -i n" (case id >= 0) was broken since v2.22-251-g61e14b4 if /sys
is not usable.

See also comments for commit "ipcs: fix ipc_msg_get_info fallback case".

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2014-03-13 23:24:22 +01:00
Ruediger Meier 08e7d10bd8 ipcs: fix ipc_msg_get_info fallback case
"ipcs -q" (case id < 0) was broken since v2.22-256-g35118df if /sys
is not usable. The main issue was that the use of msqid argument did not
cleanly distinguished between "queue identifier" and "index of kernel's
internal array".

Also now the fallback case and the regular case behave more equally
regarding it's return value (introducing another counter j).

Note that the case id >= 0 now performs a slower lookup. This could be
avoided but then we would better handle both case differently like it
was before the above mentioned cleanup commit.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2014-03-13 23:23:25 +01:00
Ruediger Meier 9bcacde12f ipcs: cleanup jumplabel stlyes
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2014-03-13 09:33:32 +01:00
Karel Zak 873e7a59d7 ipcs: fix size_t overflow
Addresses: https://github.com/karelzak/util-linux/issues/51
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-03-11 11:22:07 +01:00
Karel Zak 7d8ea9df69 ipcs: fix compiler warning [clang -Wuninitialized]
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-03-20 15:20:47 +01:00
Karel Zak 278e7203fa ipcs: fix compiler warnings, use 64bit time
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-12-20 19:52:16 +01:00
Sami Kerola 56692a6701 ipcs: add --human readable size conversion option
Introduces new function ipc_print_size() which will call
size_to_human_string(), and handles the occasional '([k]bytes)' printing
if default size format is requested.

Reviewed-by: Karel Zak <kzak@redhat.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-12-19 11:04:53 +01:00
Sami Kerola 2bd2f79dde ipcs: make individual message queue id printing to use /proc
[kzak@redhat.com: - fix msgctl() call,
		  move q_qbytes to ipc_msg_get_info]

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-11-23 14:58:22 +01:00
Sami Kerola 35118dfc31 ipcs: clean up do_msg(), and add ipc_msg_get_info()
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-11-23 14:58:22 +01:00
Sami Kerola b5504a3d4b ipcs: make individual semaphore id printing to use /proc
And reindent the print_shm() function.

[kzak@redhat.com: move semctl(GET*...) calls to ipcutils.c]

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-11-23 14:58:22 +01:00
Sami Kerola 1e2418a234 ipcs: clean up do_sem(), and add ipc_sem_get_info()
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-11-23 14:58:22 +01:00
Karel Zak 7d94d1cebc ipcs: fix ipc_shm_get_info(), use calloc
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-11-23 14:58:21 +01:00
Karel Zak 61e14b4a61 ipcs: clean up do_shm()
- don't expect maxid as argument in ipc_shm_get_info()
 - if there is @id argument then use it everywhere in ipc_shm_get_info()
 - don't call shmctl() if not necessary in do_shm()

Signed-off-by: Karel Zak <kzak@redhat.com>
2012-11-23 14:58:21 +01:00
Sami Kerola 058e81540f ipcs: read shared memory values from /proc
[kzak@redhat.com: - move to ipcutils.{c,h},
                  - fix datatypes to be arch independent]

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-11-23 14:58:21 +01:00
Sami Kerola e5995acda2 ipcs: determine ipc limits from /proc
Some of the limit values are not dynamic.  Like in kernel these values
are #defined.

[kzak@redhat.com: - use better names for functions,
                  - add ipcutils.{c,h}
                  - read also shmmax from /proc]

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-11-23 14:58:21 +01:00