Mirror of git://git.busybox.net/busybox with our patches on top
Source
/* vi: set sw=4 ts=4: */
/*
* ipcrm.c - utility to allow removal of IPC objects and data structures.
*
* 01 Sept 2004 - Rodney Radford <rradford@mindspring.com>
* Adapted for busybox from util-linux-2.12a.
*
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
/* X/OPEN tells us to use <sys/{types,ipc,sem}.h> for semctl() */
/* X/OPEN tells us to use <sys/{types,ipc,msg}.h> for msgctl() */
/* union semun is defined by including <sys/sem.h> */
/* according to X/OPEN we have to define it ourselves */
union semun {
int val;
struct semid_ds *buf;
unsigned short *array;
struct seminfo *__buf;
};
typedef enum type_id {
SHM,
SEM,
MSG
} type_id;
static int remove_ids(type_id type, int argc, char **argv)
{
unsigned long id;
int ret = 0; /* silence gcc */
int nb_errors = 0;
union semun arg;
arg.val = 0;
while (argc) {
id = bb_strtoul(argv[0], NULL, 10);
if (errno || id > INT_MAX) {
bb_error_msg("invalid id: %s", argv[0]);
nb_errors++;
} else {
if (type == SEM)
ret = semctl(id, 0, IPC_RMID, arg);
else if (type == MSG)
ret = msgctl(id, IPC_RMID, NULL);
else if (type == SHM)
ret = shmctl(id, IPC_RMID, NULL);