Forwarding to the list. Comments & suggestions? My suggestion is: s/ipccreate/ipccrt/. Karel On Mon, Mar 24, 2008 at 08:26:25AM -0400, Hayden James wrote: > I was trying to get a new utility added to util-linux-ng, but it doesn't > appear as if my e-mail is getting to the mailing list, so I'm sending the > patch to you because you're listed as the maintainer. > > From: Hayden James <hayden.james@xxxxxxxxx> > Date: Mon, Mar 24, 2008 at 8:13 AM > Subject: [PATCH] Added "ipc create" utility > To: util-linux-ng@xxxxxxxxxxxxxxx > > Small patch to create an application that can easily create ad-hoc ipc > resources, along with man page. > > diff -urN util-linux-ng.orig/sys-utils/ipccreat.1 util-linux-ng.new > /sys-utils/ipccreat.1 > --- util-linux-ng.orig/sys-utils/ipccreat.1 1969-12-31 19:00: > 00.000000000 -0500 > +++ util-linux-ng.new/sys-utils/ipccreat.1 2008-03-21 18:59: > 30.000000000 -0400 > @@ -0,0 +1,39 @@ > +.\" Copyright 2008 Hayden A. James (hayden.james@xxxxxxxxx) > +.\" May be distributed under the GNU General Public License > +.TH "IPCCREAT" "1" "21 March 2008" "ipccreat" "Linux Programmer's Manual" > +.SH "NAME" > +ipccreate \- create various ipc resources > +.SH "SYNOPSIS" > +.B ipccreat [ \-M \fIsize\fR ] [ \-p \fImode\fR ] > +.br > +.B ipccreat [ \-S \fInsems\fR ] [ \-p \fImode\fR ] > +.br > +.B ipccreat [ \-Q ] [ \-p \fImode\fR ] > +.SH "DESCRIPTION" > +.B ipccreat > +allows you to create shared memory segments, message queues or semaphore > arrays. > +.SH "OPTIONS" > +Resources may be specified as follows: > +.TP > +.BI \-M " size" > +shared memory segment of size \fB\fIsize\fR\fR > +.TP > +.BI \-S " nsems" > +semaphore array with \fB\fInsems\fR\fR elements > +.TP > +.BI \-Q > +message queue > +.TP > +Other options > +.TP > +.BI \-p " mode" > +permission for the resource (default is 0644) > +.PP > +.SH "SEE ALSO" > +.BR ipcrm (1), > +.BR ipcs (1) > +.SH "AUTHOR" > +Hayden A. James (hayden.james@xxxxxxxxx) > +.SH "AVAILABILITY" > +The ipccreat command is part of the util\-linux\-ng package and is > available from > +ftp://ftp.kernel.org/pub/linux/utils/util\-linux\-ng/. > diff -urN util-linux-ng.orig/sys-utils/ipccreat.c util-linux-ng.new > /sys-utils/ipccreat.c > --- util-linux-ng.orig/sys-utils/ipccreat.c 1969-12-31 19:00: > 00.000000000 -0500 > +++ util-linux-ng.new/sys-utils/ipccreat.c 2008-03-21 18:59: > 30.000000000 -0400 > @@ -0,0 +1,145 @@ > +/* > + * ipccreat.c - used to create ad-hoc IPC segments > + * > + * Copyright (C) 2008 Hayden A. James (hayden.james@xxxxxxxxx) > + * > + * This program is free software; you can redistribute it and/or modify > + * it under the terms of the GNU General Public License as published by > + * the Free Software Foundation; either version 2 of the License, or > + * (at your option) any later version. > + * > + * This program is distributed in the hope that it will be useful, > + * but WITHOUT ANY WARRANTY; without even the implied warranty of > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > + * GNU General Public License for more details. > + * > + * You should have received a copy of the GNU General Public License > + * along with this program; if not, write to the Free Software > + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. > + */ > + > +#include <stdlib.h> > +#include <stdio.h> > +#include <string.h> > +#include <errno.h> > +#include <time.h> > + > +#include <unistd.h> > +#include <sys/types.h> > +#include <sys/ipc.h> > +#include <sys/shm.h> > +#include <sys/sem.h> > +#include <sys/msg.h> > + > +key_t createKey(void) > +{ > + srandom( time( NULL ) ); > + return random(); > +} > + > +int createShm(size_t size, int permission) > +{ > + int result = -1; > + int shmid; > + key_t key = createKey(); > + > + if (-1 != (shmid = shmget(key, size, permission | IPC_CREAT))) > + result = shmid; > + > + return result; > +} > + > +int createMsg(int permission) > +{ > + int result = -1; > + int msgid; > + key_t key = createKey(); > + > + if (-1 != (msgid = msgget(key, permission | IPC_CREAT))) > + result = msgid; > + > + return result; > +} > + > +int createSem(int nsems, int permission) > +{ > + int result = -1; > + int semid; > + key_t key = createKey(); > + > + if (-1 != (semid = semget(key, nsems, permission | IPC_CREAT))) > + result = semid; > + > + return result; > +} > + > +void usage(char *progname) > +{ > + fprintf(stderr, "usage: %s [-M size] [-S nsems] [-Q] [-p > permission]\n", progname); > +} > + > +int main(int argc, char **argv) > +{ > + int permission = 0644; > + int opt; > + size_t size = 0; > + int nsems = 0; > + > + int doShm = 0, doMsg = 0, doSem = 0; > + > + while((opt = getopt(argc, argv, "M:QS:p:")) != -1) > + { > + switch(opt) > + { > + case 'M': > + size = atoi(optarg); > + doShm = 1; > + break; > + case 'Q': > + doMsg = 1; > + break; > + case 'S': > + nsems = atoi(optarg); > + doSem = 1; > + break; > + case 'p': > + permission = strtoul(optarg, NULL, 8); > + break; > + default: > + doShm = doMsg = doSem = 0; > + break; > + } > + } > + > + if (doShm) > + { > + int shmid; > + if (-1 == (shmid = createShm(size, permission))) > + fprintf(stderr, "%s\n", strerror(errno)); > + else > + fprintf(stdout, "%s%d\n", "Shared memory id: ", shmid); > + } > + > + if (doMsg) > + { > + int msgid; > + if (-1 == (msgid = createMsg(permission))) > + fprintf(stderr, "%s\n", strerror(errno)); > + else > + fprintf(stdout, "%s%d\n", "Message queue id: ", msgid); > + } > + > + if (doSem) > + { > + int semid; > + if (-1 == (semid = createSem(nsems, permission))) > + fprintf(stderr, "%s\n", strerror(errno)); > + else > + fprintf(stdout, "%s%d\n", "Semaphore id: ", semid); > + } > + > + if(!doShm && !doMsg && !doSem) > + usage(argv[0]); > + > + return 0; > +} > diff -urN util-linux-ng.orig/sys-utils/ipcrm.1 util-linux-ng.new > /sys-utils/ipcrm.1 > --- util-linux-ng.orig/sys-utils/ipcrm.1 2008-03-21 18:54: > 46.000000000 -0400 > +++ util-linux-ng.new/sys-utils/ipcrm.1 2008-03-21 18:59:52.000000000 -0400 > @@ -114,6 +114,7 @@ > .SH SEE ALSO > .nh > .BR ipcs (1), > +.BR ipccreat (1), > .BR msgctl (2), > .BR msgget (2), > .BR semctl (2), > diff -urN util-linux-ng.orig/sys-utils/ipcrm.c util-linux-ng.new > /sys-utils/ipcrm.c > --- util-linux-ng.orig/sys-utils/ipcrm.c 2008-03-21 18:54: > 46.000000000 -0400 > +++ util-linux-ng.new/sys-utils/ipcrm.c 2008-03-21 18:59:52.000000000 -0400 > @@ -137,7 +137,7 @@ > usage(char *progname) > { > fprintf(stderr, > - _("usage: %s [ [-q msqid] [-m shmid] [-s semid]\n" > + _("usage: %s [ [-q msgid] [-m shmid] [-s semid]\n" > " [-Q msgkey] [-M shmkey] [-S semkey] ... ]\n"), > progname); > } > diff -urN util-linux-ng.orig/sys-utils/ipcs.1 util-linux-ng.new > /sys-utils/ipcs.1 > --- util-linux-ng.orig/sys-utils/ipcs.1 2008-03-21 18:54:46.000000000 -0400 > +++ util-linux-ng.new/sys-utils/ipcs.1 2008-03-21 18:59:52.000000000 -0400 > @@ -53,7 +53,8 @@ > .B \-u > summary > .SH SEE ALSO > -.BR ipcrm (1) > +.BR ipcrm (1), > +.BR ipccreat (1) > .SH CONFORMING TO > The Linux ipcs utility is not fully compatible to the POSIX ipcs utility. > The Linux version does not support the > diff -urN util-linux-ng.orig/sys-utils/Makefile.am util-linux-ng.new > /sys-utils/Makefile.am > --- util-linux-ng.orig/sys-utils/Makefile.am 2008-03-21 18:54: > 46.000000000 -0400 > +++ util-linux-ng.new/sys-utils/Makefile.am 2008-03-21 18:59: > 52.000000000 -0400 > @@ -5,7 +5,7 @@ > bin_PROGRAMS += dmesg > endif > > -usrbinexec_PROGRAMS = flock ipcrm ipcs renice setsid > +usrbinexec_PROGRAMS = flock ipcrm ipcs ipccreat renice setsid > if LINUX > usrbinexec_PROGRAMS += cytune setarch > endif > @@ -24,7 +24,7 @@ > tunelp_SOURCES = tunelp.c lp.h > > dist_man_MANS = flock.1 readprofile.1 \ > - ctrlaltdel.8 cytune.8 dmesg.1 ipcrm.1 ipcs.1 ldattach.8 renice.1 \ > + ctrlaltdel.8 cytune.8 dmesg.1 ipcrm.1 ipcs.1 ipccreat.1 ldattach.8 > renice.1 \ > setsid.1 tunelp.8 setarch.8 rtcwake.8 > > info_TEXINFOS = ipc.tex -- Karel Zak <kzak@xxxxxxxxxx> -- To unsubscribe from this list: send the line "unsubscribe util-linux-ng" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html