Add arguments for ptyfs: slave tty group and mode, so we don't have to

hard-code them in the kernel.
This commit is contained in:
christos 2004-11-24 22:13:08 +00:00
parent 2a2d87d1db
commit f11900e378
3 changed files with 89 additions and 11 deletions

View File

@ -1,4 +1,4 @@
# $NetBSD: Makefile,v 1.2 2004/11/11 19:10:16 jdolecek Exp $
# $NetBSD: Makefile,v 1.3 2004/11/24 22:13:08 christos Exp $
# @(#)Makefile 8.2 (Berkeley) 3/27/94
.include <bsd.own.mk>
@ -7,6 +7,7 @@ PROG= mount_ptyfs
SRCS= mount_ptyfs.c
MAN= mount_ptyfs.8
CFLAGS+=-g
CPPFLAGS+= -I${NETBSDSRCDIR}/sys
DPADD+=${LIBUTIL}

View File

@ -1,4 +1,4 @@
.\" $NetBSD: mount_ptyfs.8,v 1.3 2004/11/11 13:42:55 christos Exp $
.\" $NetBSD: mount_ptyfs.8,v 1.4 2004/11/24 22:13:08 christos Exp $
.\"
.\"
.\" Copyright (c) 2004 The NetBSD Foundation, Inc.
@ -35,7 +35,7 @@
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
.Dd November 8, 2004
.Dd November 24, 2004
.Dt MOUNT_PTYFS 8
.Os
.Sh NAME
@ -43,6 +43,8 @@
.Nd mount the /dev/pts file system
.Sh SYNOPSIS
.Nm
.Op Fl g Ar group|gid
.Op Fl m Ar mode
.Op Fl o Ar options
.Ar ptyfs
.Ar mount_point
@ -64,10 +66,26 @@ or they are already open via traditional BSD style ptys.
.Pp
The options are as follows:
.Bl -tag -width indent
.It Fl g Ar group|gid
Specify the group ownership of the slave pseudo-tty.
.It Fl m Ar mode
Specify the default
.Ar mode
of the slave pseudo-tty.
.It Fl o
Options are specified with a
.Fl o
flag followed by a comma separated string of options.
.Pp
.Nm
specific options are
.Dv group
which corresponds to
.Fl g ,
and
.Dv mode
which corresponds to
.Fl m .
See the
.Xr mount 8
man page for possible options and their meanings.

View File

@ -1,4 +1,4 @@
/* $NetBSD: mount_ptyfs.c,v 1.1 2004/11/11 01:42:17 christos Exp $ */
/* $NetBSD: mount_ptyfs.c,v 1.2 2004/11/24 22:13:08 christos Exp $ */
/*
* Copyright (c) 1992, 1993, 1994
@ -77,29 +77,41 @@ __COPYRIGHT("@(#) Copyright (c) 1992, 1993, 1994\n\
#if 0
static char sccsid[] = "@(#)mount_ptyfs.c 8.3 (Berkeley) 5/4/95";
#else
__RCSID("$NetBSD: mount_ptyfs.c,v 1.1 2004/11/11 01:42:17 christos Exp $");
__RCSID("$NetBSD: mount_ptyfs.c,v 1.2 2004/11/24 22:13:08 christos Exp $");
#endif
#endif /* not lint */
#include <sys/param.h>
#include <sys/types.h>
#include <sys/mount.h>
#include <sys/stat.h>
#include <fs/ptyfs/ptyfs.h>
#include <err.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <grp.h>
#include <mntopts.h>
#define ALTF_GROUP 1
#define ALTF_MODE 2
static const struct mntopt mopts[] = {
MOPT_STDOPTS,
MOPT_GETARGS,
{ "group", 0, ALTF_GROUP, 1 },
{ "mode", 0, ALTF_MODE, 1 },
{ NULL }
};
int main(int, char *[]);
int mount_ptyfs(int argc, char **argv);
static gid_t getgrp(const char *name);
static void usage(void);
#ifndef MOUNT_NOMAIN
@ -110,37 +122,84 @@ main(int argc, char *argv[])
}
#endif
static gid_t
getgrp(const char *name)
{
char *ep;
struct group *grp;
long l;
if (name == NULL)
errx(1, "Missing group name");
l = strtol(name, &ep, 0);
if (name == ep || *ep)
grp = getgrnam(name);
else
grp = getgrgid((gid_t)l);
if (grp == NULL)
errx(1, "Cannot find group `%s'", name);
return grp->gr_gid;
}
int
mount_ptyfs(int argc, char *argv[])
{
int ch, mntflags = 0;
int ch, mntflags = 0, altflags = 0;
struct ptyfs_args args;
mntoptparse_t mp;
setprogname(argv[0]);
while ((ch = getopt(argc, argv, "o:")) != -1)
args.version = PTYFS_ARGSVERSION;
args.gid = getgrp("tty");
args.mode = S_IRUSR|S_IWUSR|S_IWGRP;
while ((ch = getopt(argc, argv, "g:m:o:")) != -1)
switch (ch) {
case 'o':
getmntopts(optarg, mopts, &mntflags, 0);
altflags = 0;
mp = getmntopts(optarg, mopts, &mntflags, &altflags);
if (altflags & ALTF_GROUP)
args.gid = getgrp(getmntoptstr(mp, "group"));
if (altflags & ALTF_MODE)
args.mode = (mode_t)getmntoptnum(mp, "mode");
freemntopts(mp);
break;
case 'g':
args.gid = getgrp(optarg);
break;
case 'm':
args.mode = (mode_t)strtol(optarg, NULL, 0);
break;
case '?':
default:
usage();
}
argc -= optind;
argv += optind;
if (argc != 2)
usage();
if (mount(MOUNT_PTYFS, argv[1], mntflags, NULL))
if (mount(MOUNT_PTYFS, argv[1], mntflags, &args))
err(1, "ptyfs on %s", argv[1]);
exit(0);
if (mntflags & MNT_GETARGS)
printf("version %d, gid=%lu, mode=0%o\n", args.version,
(unsigned long)args.gid, args.mode);
return 0;
}
static void
usage(void)
{
(void)fprintf(stderr,
"Usage: %s [-o options] ptyfs mountpoint\n", getprogname());
"Usage: %s [-g <group|gid>] [-m <mode>] [-o options] ptyfs mountpoint\n", getprogname());
exit(1);
}