diff options
author | Karel Zak | 2006-12-07 00:25:54 +0100 |
---|---|---|
committer | Karel Zak | 2006-12-07 00:25:54 +0100 |
commit | 1d4ad1decc539c9729b592e6050460d6487c95f4 (patch) | |
tree | c158c5f5baf15ea4bab5c05b2f6e2bdaca332c29 /sys-utils | |
parent | Imported from util-linux-2.11o tarball. (diff) | |
download | kernel-qcow2-util-linux-1d4ad1decc539c9729b592e6050460d6487c95f4.tar.gz kernel-qcow2-util-linux-1d4ad1decc539c9729b592e6050460d6487c95f4.tar.xz kernel-qcow2-util-linux-1d4ad1decc539c9729b592e6050460d6487c95f4.zip |
Imported from util-linux-2.11q tarball.
Diffstat (limited to 'sys-utils')
-rw-r--r-- | sys-utils/ipcrm.8 | 94 | ||||
-rw-r--r-- | sys-utils/ipcrm.c | 174 | ||||
-rw-r--r-- | sys-utils/readprofile.c | 15 |
3 files changed, 252 insertions, 31 deletions
diff --git a/sys-utils/ipcrm.8 b/sys-utils/ipcrm.8 index 1a0107d7c..f8281d377 100644 --- a/sys-utils/ipcrm.8 +++ b/sys-utils/ipcrm.8 @@ -1,15 +1,89 @@ -.\" Copyright 1993 Rickard E. Faith (faith@cs.unc.edu) +.\" Copyright 2002 Andre C. Mazzone (linuxdev@karagee.com) .\" May be distributed under the GNU General Public License -.TH IPCRM 8 "9 October 1993" "Linux 0.99" "Linux Programmer's Manual" +.TH IPCRM 8 "last change: 19 March 2002" "ipcrm" "Linux Programmer's Manual" .SH NAME -ipcs \- provide information on ipc facilities +ipcrm \- remove a message queue, semaphore set or shared memory id .SH SYNOPSIS -.BI "ipcrm [ shm | msg | sem ] " id ... -.SH DESCRIPTION .B ipcrm -will remove the resource(s) specified by -.IR id . +[ +.I options +] + +deprecated usage + +.BI ipcrm +[ +.I shm +| +.I msg +| +.I sem +] +.IR id ... +.SH DESCRIPTION +.I ipcrm +will remove messages, semphores or shared memory segments specified by +.IR key " or" " id" . +.SH OPTIONS +The identifiers are specified thus: +.TP +.BI \-q " msgid" +removes the message queue identified by +.I msgid +from the system along with its associated data structures. +.TP +.BI \-m " shmid" +removes the shared memory segment identified by +.I shmid +from the system along with its associated data structures after the last +detach is performed. +.TP +.BI \-s " semid" +removes the semaphore identified by +.IR semid +from the system along with its associated data structures. +.TP +.BI \-Q " msgkey" +removes the message queue created with +.I msgkey +from the system along with its associated data structures. +.TP +.BI \-M " shmkey" +removes the shared memory segment created with +.I shmkey +from the system along with its associated data structures after the last +detach is performed. +.TP +.BI \-S " semkey" +removes the semaphore created with +.IR semkey +from the system along with its associated data structures. +.LP +The details of the removes are described in +.IR msgctl (2), +.IR shmctl (2), +and +.IR semctl (2). +The identifiers and keys may be found by using +.IR ipcs (8). +.SH NOTES +In its first implementation, ipcrm used the deprecated syntax shown in the +.BR SYNOPSIS . +Functionality present in other *nix implementations of ipcrm has since +been added, namely the ability to delete resources by key (not just +identifier), and to respect the same command-line syntax. For backward +compatibility the previous syntax is still supported. +.SH AUTHORS +Andre C. Mazzone (linuxdev@karagee.com) +.br +Krishna Balasubramanian (balasub@cis.ohio-state.edu) +.nh .SH SEE ALSO -.BR ipcs (8) -.SH AUTHOR -krishna balasubramanian (balasub@cis.ohio-state.edu) +.BR ipcs (8), +.BR msgctl (2), +.BR msgget (2), +.BR semctl (2), +.BR semget (2), +.BR shmctl (2), +.BR shmget (2) + diff --git a/sys-utils/ipcrm.c b/sys-utils/ipcrm.c index 3e3a9ba02..09ba14454 100644 --- a/sys-utils/ipcrm.c +++ b/sys-utils/ipcrm.c @@ -21,6 +21,11 @@ #include <sys/sem.h> #include "nls.h" +/* for getopt */ +#include <unistd.h> +/* for tolower and isupper */ +#include <ctype.h> + #if defined (__GNU_LIBRARY__) && !defined(_SEM_SEMUN_UNDEFINED) /* union semun is defined by including <sys/sem.h> */ #else @@ -33,6 +38,8 @@ union semun { }; #endif +static void usage(char *); + char *execname; typedef enum type_id { @@ -86,41 +93,36 @@ remove_ids(type_id type, int argc, char **argv) { return(nb_errors); } -static void display_usage(void) +static void deprecate_display_usage(void) { - printf (_("usage: %s {shm | msg | sem} id ...\n"), execname); + usage(execname); + printf (_("deprecated usage: %s {shm | msg | sem} id ...\n"), + execname); } -int main(int argc, char **argv) +static int deprecated_main(int argc, char **argv) { execname = argv[0]; - setlocale(LC_ALL, ""); - bindtextdomain(PACKAGE, LOCALEDIR); - textdomain(PACKAGE); - if (argc < 3) { - display_usage(); + deprecate_display_usage(); exit(1); } if (!strcmp(argv[1], "shm")) { - if (remove_ids(SHM, argc-2, &argv[2])) { + if (remove_ids(SHM, argc-2, &argv[2])) exit(1); - } } else if (!strcmp(argv[1], "msg")) { - if (remove_ids(MSG, argc-2, &argv[2])) { + if (remove_ids(MSG, argc-2, &argv[2])) exit(1); - } } else if (!strcmp(argv[1], "sem")) { - if (remove_ids(SEM, argc-2, &argv[2])) { + if (remove_ids(SEM, argc-2, &argv[2])) exit(1); - } } else { - display_usage(); + deprecate_display_usage(); printf (_("unknown resource type: %s\n"), argv[1]); exit(1); } @@ -128,4 +130,144 @@ int main(int argc, char **argv) printf (_("resource(s) deleted\n")); return 0; } - + + +/* print the new usage */ +static void +usage(char *progname) +{ + fprintf(stderr, + _("usage: %s [ [-q msqid] [-m shmid] [-s semid]\n" + " [-Q msgkey] [-M shmkey] [-S semkey] ... ]\n"), + progname); +} + +int main(int argc, char **argv) +{ + int c; + int error = 0; + char *prog = argv[0]; + + /* if the command is executed without parameters, do nothing */ + if (argc == 1) + return 0; + + setlocale(LC_ALL, ""); + bindtextdomain(PACKAGE, LOCALEDIR); + textdomain(PACKAGE); + + /* check to see if the command is being invoked in the old way if so + then run the old code */ + if (strcmp(argv[1], "shm") == 0 || + strcmp(argv[1], "msg") == 0 || + strcmp(argv[1], "sem") == 0) + return deprecated_main(argc, argv); + + /* process new syntax to conform with SYSV ipcrm */ + while ((c = getopt(argc, argv, "q:m:s:Q:M:S:")) != -1) { + int result; + int id = 0; + int iskey = isupper(c); + + /* needed to delete semaphores */ + union semun arg; + arg.val = 0; + + /* we don't need case information any more */ + c = tolower(c); + + /* make sure the option is in range */ + if (c != 'q' && c != 'm' && c != 's') { + fprintf(stderr, _("%s: illegal option -- %c\n"), + prog, c); + usage(prog); + error++; + } + + if (iskey) { + /* keys are in hex or decimal */ + key_t key = strtoul(optarg, NULL, 0); + if (key == IPC_PRIVATE) { + error++; + fprintf(stderr, _("%s: illegal key (%s)\n"), + prog, optarg); + continue; + } + + /* convert key to id */ + id = ((c == 'q') ? msgget(key, 0) : + (c == 'm') ? shmget(key, 0, 0) : + semget(key, 0, 0)); + + if (id < 0) { + char *errmsg; + error++; + switch(errno) { + case EACCES: + errmsg = _("permission denied for key"); + break; + case EIDRM: + errmsg = _("already removed key"); + break; + case ENOENT: + errmsg = _("invalid key"); + break; + default: + errmsg = _("unknown error in key"); + break; + } + fprintf(stderr, "%s: %s (%s)\n", + prog, errmsg, optarg); + continue; + } + } else { + /* ids are in decimal */ + id = strtoul(optarg, NULL, 10); + } + + result = ((c == 'q') ? msgctl(id, IPC_RMID, NULL) : + (c == 'm') ? shmctl(id, IPC_RMID, NULL) : + semctl(id, 0, IPC_RMID, arg)); + + if (result < 0) { + char *errmsg; + error++; + switch(errno) { + case EACCES: + case EPERM: + errmsg = iskey + ? _("permission denied for key") + : _("permission denied for id"); + break; + case EINVAL: + errmsg = iskey + ? _("invalid key") + : _("invalid id"); + break; + case EIDRM: + errmsg = iskey + ? _("already removed key") + : _("already removed id"); + break; + default: + errmsg = iskey + ? _("unknown error in key") + : _("unknown error in id"); + break; + } + fprintf(stderr, _("%s: %s (%s)\n"), + prog, errmsg, optarg); + continue; + } + } + + /* print usage if we still have some arguments left over */ + if (optind != argc) { + fprintf(stderr, _("%s: unknown argument: %s\n"), + prog, argv[optind]); + usage(prog); + } + + /* exit value reflects the number of errors encountered */ + return error; +} diff --git a/sys-utils/readprofile.c b/sys-utils/readprofile.c index 398ebb4ce..052954f95 100644 --- a/sys-utils/readprofile.c +++ b/sys-utils/readprofile.c @@ -29,6 +29,8 @@ * - byte order auto-detection and -n option * 2001-11-09 Werner Almesberger <wa@almesberger.net> * - skip step size (index 0) + * 2002-03-09 John Levon <moz@compsoc.man.ac.uk> + * - make maplineno do something */ #include <errno.h> @@ -234,16 +236,17 @@ main (int argc, char **argv) { exit(1); } - while(fgets(mapline,S_LEN,map)) { - if (sscanf(mapline,"%lx %s %s",&fn_add,mode,fn_name)!=3) { + while (fgets(mapline,S_LEN,map)) { + if (sscanf(mapline,"%lx %s %s",&fn_add,mode,fn_name) != 3) { fprintf(stderr,_("%s: %s(%i): wrong map line\n"), - prgname,mapFile, maplineno); + prgname, mapFile, maplineno); exit(1); } if (!strcmp(fn_name,"_stext")) /* only elf works like this */ { - add0=fn_add; + add0 = fn_add; break; } + maplineno++; } if (!add0) { @@ -255,7 +258,7 @@ main (int argc, char **argv) { /* * Main loop. */ - while(fgets(mapline,S_LEN,map)) { + while (fgets(mapline,S_LEN,map)) { unsigned int this=0; if (sscanf(mapline,"%lx %s %s",&next_add,mode,next_name)!=3) { @@ -289,6 +292,8 @@ main (int argc, char **argv) { this,fn_name,this/(double)fn_len); } fn_add=next_add; strcpy(fn_name,next_name); + + maplineno++; } /* trailer */ if (optVerbose) |