X-Git-Url: http://git.ipfire.org/?a=blobdiff_plain;f=sys-utils%2Fipcs.c;h=2d18a13cced6db1640b86f2febf28e2fa4f408ec;hb=b923bdbe528e449c62a96c7ed483673a7951c4ab;hp=5877c46b173df7e2a7cd243432351f417398a51b;hpb=80d00db17ee74d1c650cdc53021244954b0f0afc;p=thirdparty%2Futil-linux.git diff --git a/sys-utils/ipcs.c b/sys-utils/ipcs.c index 5877c46b17..2d18a13cce 100644 --- a/sys-utils/ipcs.c +++ b/sys-utils/ipcs.c @@ -16,7 +16,6 @@ */ #include -#include #include #include "c.h" @@ -47,8 +46,9 @@ static void print_msg (int id, int unit); /* we read time as int64_t from /proc, so cast... */ #define xctime(_x) ctime((time_t *) (_x)) -static void __attribute__ ((__noreturn__)) usage(FILE * out) +static void __attribute__((__noreturn__)) usage(void) { + FILE *out = stdout; fputs(USAGE_HEADER, out); fprintf(out, _(" %1$s [resource-option...] [output-option]\n" " %1$s -m|-q|-s -i \n"), program_invocation_short_name); @@ -58,8 +58,7 @@ static void __attribute__ ((__noreturn__)) usage(FILE * out) fputs(USAGE_OPTIONS, out); fputs(_(" -i, --id print details on resource identified by \n"), out); - fputs(USAGE_HELP, out); - fputs(USAGE_VERSION, out); + printf(USAGE_HELP_OPTIONS(16)); fputs(USAGE_SEPARATOR, out); fputs(_("Resource options:\n"), out); @@ -77,9 +76,9 @@ static void __attribute__ ((__noreturn__)) usage(FILE * out) fputs(_(" -u, --summary show status summary\n"), out); fputs(_(" --human show sizes in human-readable format\n"), out); fputs(_(" -b, --bytes show sizes in bytes\n"), out); - fprintf(out, USAGE_MAN_TAIL("ipcs(1)")); + printf(USAGE_MAN_TAIL("ipcs(1)")); - exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS); + exit(EXIT_SUCCESS); } int main (int argc, char **argv) @@ -109,7 +108,7 @@ int main (int argc, char **argv) setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); - atexit(close_stdout); + close_stdout_atexit(); while ((opt = getopt_long(argc, argv, options, longopts, NULL)) != -1) { switch (opt) { @@ -150,13 +149,13 @@ int main (int argc, char **argv) case 'b': unit = IPC_UNIT_BYTES; break; + case 'h': - usage(stdout); + usage(); case 'V': - printf(UTIL_LINUX_VERSION); - return EXIT_SUCCESS; + print_version(EXIT_SUCCESS); default: - usage(stderr); + errtryhelp(EXIT_FAILURE); } } @@ -199,16 +198,24 @@ static void do_shm (char format, int unit) case LIMITS: { struct ipc_limits lim; + uint64_t tmp, pgsz = getpagesize(); - printf (_("------ Shared Memory Limits --------\n")); - if (ipc_shm_get_limits(&lim)) + if (ipc_shm_get_limits(&lim)) { + printf (_("unable to fetch shared memory limits\n")); return; + } + printf (_("------ Shared Memory Limits --------\n")); 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; @@ -352,9 +359,11 @@ static void do_sem (char format) { struct ipc_limits lim; - printf (_("------ Semaphore Limits --------\n")); - if (ipc_sem_get_limits(&lim)) + if (ipc_sem_get_limits(&lim)) { + printf (_("unable to fetch semaphore limits\n")); return; + } + printf (_("------ Semaphore Limits --------\n")); printf (_("max number of arrays = %d\n"), lim.semmni); printf (_("max semaphores per array = %d\n"), lim.semmsl); printf (_("max semaphores system wide = %d\n"), lim.semmns); @@ -452,8 +461,10 @@ static void do_msg (char format, int unit) { struct ipc_limits lim; - if (ipc_msg_get_limits(&lim)) + if (ipc_msg_get_limits(&lim)) { + printf (_("unable to fetch message limits\n")); return; + } printf (_("------ Messages Limits --------\n")); printf (_("max queues system wide = %d\n"), lim.msgmni); ipc_print_size(unit == IPC_UNIT_DEFAULT ? IPC_UNIT_BYTES : unit, @@ -591,7 +602,7 @@ static void print_shm(int shmid, int unit) ipc_shm_free_info(shmdata); } -void print_msg(int msgid, int unit) +static void print_msg(int msgid, int unit) { struct msg_data *msgdata;