Date: Tue, 29 Apr 2008 16:12:54 +0100 From: "Bruce M. Simpson" <bms@FreeBSD.org> To: FreeBSD Current <freebsd-current@freebsd.org> Subject: Re: [PATCH] cu/tip leaves tty in exclusive mode Message-ID: <48173AF6.5090609@FreeBSD.org> In-Reply-To: <48167B72.1000207@incunabulum.net> References: <48167B72.1000207@incunabulum.net>
next in thread | previous in thread | raw e-mail | index | archive | help
This is a multi-part message in MIME format.
--------------050309060208090502030102
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Bruce M Simpson wrote:
> Hi,
>
> I think I saw a bug. I have an app which creates ptys on its own. I
> connect to them manually with cu -l.
>
> It appears that cu doesn't clean up after itself... this is a quick fix
Here's another way of fixing it. Perhaps this should go in tools for now?
Only the superuser can clear the TS_XCLUDE bit according to kern/tty.c.
There doesn't seem to be any way of resetting the TIONXCL flag on a tty
without rebooting -- there's no sysctl or anything else, stty doesn't
know about it, and it does not have a TERMIOS flag.
cheers
BMS
--------------050309060208090502030102
Content-Type: text/plain;
name="tionxcl.c"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="tionxcl.c"
#include <fcntl.h>
#include <sys/ioctl.h>
#include <errno.h>
#include <err.h>
#include <libgen.h>
#include <sysexits.h>
#include <unistd.h>
#define DEVPATHNAME "/dev"
int
main(int argc, char *argv[])
{
char *progname;
char *ttyname;
int fd;
int dofree;
dofree = 0;
progname = basename(argv[0]);
if (argc != 2)
errx(EX_USAGE, "usage: %s <ttyname>\n", progname);
if (geteuid() != 0)
errx(EX_NOPERM, "Sorry\n");
if (argv[1][0] == '/') {
ttyname = argv[1];
} else {
size_t len, maxpath, result;
len = strlen(argv[1]) + sizeof(DEVPATHNAME) + 1;
maxpath = pathconf(DEVPATHNAME, _PC_PATH_MAX);
if (len > maxpath) {
warnc(ENAMETOOLONG, ttyname);
exit(EX_DATAERR);
}
ttyname = malloc(len);
if (ttyname == NULL) {
warnc(ENOMEM, "malloc");
exit(EX_OSERR);
}
dofree = 1;
result = snprintf(ttyname, len, "%s/%s", DEVPATHNAME, argv[1]);
if (result >= len)
warnc(ENOMEM, "snprintf");
}
fd = open(ttyname, O_RDWR);
if (fd == -1) {
warnc(errno, "open %s", ttyname);
if (dofree)
free(ttyname);
exit(EX_OSERR);
}
if (0 != ioctl(fd, TIOCNXCL, 0))
warnc(errno, "ioctl TIOCNXCL %s", ttyname);
if (dofree)
free(ttyname);
exit(0);
}
--------------050309060208090502030102--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?48173AF6.5090609>
