=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/ipcrm/ipcrm.c,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- src/usr.bin/ipcrm/ipcrm.c 1996/06/26 05:34:35 1.2 +++ src/usr.bin/ipcrm/ipcrm.c 1997/09/11 07:59:01 1.3 @@ -1,4 +1,5 @@ -/* * $OpenBSD: ipcrm.c,v 1.2 1996/06/26 05:34:35 deraadt Exp $*/ +/* $OpenBSD: ipcrm.c,v 1.3 1997/09/11 07:59:01 deraadt Exp $*/ + /* * Copyright (c) 1994 Adam Glass * All rights reserved. @@ -31,15 +32,17 @@ * */ -#include -#include -#include -#include #include #include #include #include #include +#include +#include +#include +#include +#include +#include #define IPC_TO_STR(x) (x == 'Q' ? "msq" : (x == 'M' ? "shm" : "sem")) #define IPC_TO_STRING(x) (x == 'Q' ? "message queue" : \ @@ -47,125 +50,137 @@ int signaled; -void usage() +void usage __P((void)); +int msgrm __P((key_t, int)); +int shmrm __P((key_t, int)); +int semrm __P((key_t, int)); +void not_configured __P((int)); + +void +usage() { fprintf(stderr, "usage: ipcrm [ [-q msqid] [-m shmid] [-s semid]\n"); fprintf(stderr, " [-Q msgkey] [-M shmkey] [-S semkey] ...]\n"); exit(1); } -int msgrm(key, id) - key_t key; - int id; +int +msgrm(key, id) + key_t key; + int id; { - if (key) { - id = msgget(key, 0); - if (id == -1) - return -1; - } - return msgctl(id, IPC_RMID, NULL); + if (key) { + id = msgget(key, 0); + if (id == -1) + return (-1); + } + return (msgctl(id, IPC_RMID, NULL)); } -int shmrm(key, id) - key_t key; - int id; +int +shmrm(key, id) + key_t key; + int id; { - if (key) { - id = shmget(key, 0, 0); - if (id == -1) - return -1; - } - return shmctl(id, IPC_RMID, NULL); + if (key) { + id = shmget(key, 0, 0); + if (id == -1) + return (-1); + } + return (shmctl(id, IPC_RMID, NULL)); } -int semrm(key, id) - key_t key; - int id; +int +semrm(key, id) + key_t key; + int id; { - union semun arg; + union semun arg; - if (key) { - id = semget(key, 0, 0); - if (id == -1) - return -1; - } - return semctl(id, 0, IPC_RMID, arg); + if (key) { + id = semget(key, 0, 0); + if (id == -1) + return (-1); + } + return (semctl(id, 0, IPC_RMID, arg)); } -void not_configured() +void +not_configured(sig) + int sig; { - signaled++; + signaled++; } - -int main(argc, argv) - int argc; - char *argv[]; +int +main(argc, argv) + int argc; + char *argv[]; { - int c, result, errflg, target_id; - key_t target_key; + int c, result, errflg, target_id; + key_t target_key; - errflg = 0; - signal(SIGSYS, not_configured); - while ((c = getopt(argc, argv, ":q:m:s:Q:M:S:")) != -1) { - - signaled = 0; - switch (c) { - case 'q': - case 'm': - case 's': - target_id = atoi(optarg); - if (c == 'q') - result = msgrm(0, target_id); - else if (c == 'm') - result = shmrm(0, target_id); - else - result = semrm(0, target_id); - if (result < 0) { - errflg++; - if (!signaled) - warn("%sid(%d): ", IPC_TO_STR(toupper(c)), target_id); - else - warnx("%ss are not configured in the running kernel", - IPC_TO_STRING(toupper(c))); - } - break; - case 'Q': - case 'M': - case 'S': - target_key = atol(optarg); - if (target_key == IPC_PRIVATE) { - warnx("can't remove private %ss", IPC_TO_STRING(c)); - continue; - } - if (c == 'Q') - result = msgrm(target_key, 0); - else if (c == 'M') - result = shmrm(target_key, 0); - else - result = semrm(target_key, 0); - if (result < 0) { - errflg++; - if (!signaled) - warn("%key(%ld): ", IPC_TO_STR(c), target_key); - else - warnx("%ss are not configured in the running kernel", - IPC_TO_STRING(c)); - } - break; - case ':': - fprintf(stderr, "option -%c requires an argument\n", optopt); - usage(); - case '?': - fprintf(stderr, "unrecognized option: -%c\n", optopt); - usage(); + errflg = 0; + signal(SIGSYS, not_configured); + while ((c = getopt(argc, argv, ":q:m:s:Q:M:S:")) != -1) { + signaled = 0; + switch (c) { + case 'q': + case 'm': + case 's': + target_id = atoi(optarg); + if (c == 'q') + result = msgrm(0, target_id); + else if (c == 'm') + result = shmrm(0, target_id); + else + result = semrm(0, target_id); + if (result < 0) { + errflg++; + if (!signaled) + warn("%sid(%d): ", + IPC_TO_STR(toupper(c)), target_id); + else + warnx("%ss are not configured in the running kernel", + IPC_TO_STRING(toupper(c))); + } + break; + case 'Q': + case 'M': + case 'S': + target_key = atol(optarg); + if (target_key == IPC_PRIVATE) { + warnx("can't remove private %ss", IPC_TO_STRING(c)); + continue; + } + if (c == 'Q') + result = msgrm(target_key, 0); + else if (c == 'M') + result = shmrm(target_key, 0); + else + result = semrm(target_key, 0); + if (result < 0) { + errflg++; + if (!signaled) + warn("%skey(%ld): ", IPC_TO_STR(c), + target_key); + else + warnx("%ss are not configured in the running kernel", + IPC_TO_STRING(c)); + } + break; + case ':': + fprintf(stderr, "option -%c requires an argument\n", optopt); + usage(); + default: + fprintf(stderr, "unrecognized option: -%c\n", optopt); + usage(); + } } - } - if (optind != argc) { - fprintf(stderr, "unknown argument: %s\n", argv[optind]); - usage(); - } - exit(errflg); + if (optind != argc) { + fprintf(stderr, "unknown argument: %s\n", argv[optind]); + usage(); + } + exit(errflg); } -