Date: Wed, 17 May 2000 19:45:34 +0100 From: Ben Smithurst <ben@scientia.demon.co.uk> To: Sys Admin <abeaupre@chemcomp.com> Cc: freebsd-questions@freebsd.org, beaupran@iro.umontreal.ca Subject: Re: Display the time on ttyv7 Message-ID: <20000517194534.D21557@strontium.scientia.demon.co.uk> In-Reply-To: <3922C8EA.11CBC702@chemcomp.com> References: <3922C8EA.11CBC702@chemcomp.com>
next in thread | previous in thread | raw e-mail | index | archive | help
[-- Attachment #1 --]
Sys Admin wrote:
> In a rather naive attempt, I tried to make a handy clock always
> available on ttyv7. I've put the following line in /etc/ttys:
>
> ttyv7 "/usr/gamges/grdc" cons25 on secure
^^^^^^
> It did not work. The tty was simply not accessible, giving me a nice
> -beep!- when I tried Alt-F8.
If that typo was present in /etc/ttys I'm not surprised. :-) OTOH, I've
just tried it myself and it looks as if the terminal isn't being opened
on FDs 0, 1 and 2. I think getty does that itself. (You did send
SIGHUP to init, didn't you? I don't think it would work anyway.)
If you can't get it to work, try the attached program, which can
run a specified program on a specified tty (e.g. 'runontty ttyv7
/usr/games/grdc' could go in /etc/rc.local). This has the disadvantage
that the clock won't get restarted if it dies, as it would with
/etc/ttys, but you can't have everything. You could always run a
cronjob to restart it if it dies, but I don't see why it would die
anyway. Another method would be to write a wrapper around grdc which
opened the TTY appropriately.
--
Ben Smithurst / ben@scientia.demon.co.uk / PGP: 0x99392F7D
[-- Attachment #2 --]
static const char rcsid[] =
"$Id: runontty.c,v 1.3 2000/03/04 00:04:52 ben Exp $";
#include <sys/param.h>
#include <sys/ioctl.h>
#include <err.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
/*
* usage: runontty tty command ...
* run "command ..." attached to "tty"
*/
int
main(int argc, char *argv[]) {
int fd;
char ttyname[MAXPATHLEN];
#ifdef __FreeBSD__
int errfd;
FILE *errfp;
#endif
if (argc < 3) {
fprintf(stderr, "usage: runontty tty command [arg ...]\n");
exit(EXIT_FAILURE);
}
if (*argv[1] != '/') {
if (strncmp(argv[1], "tty", 3) == 0)
snprintf(ttyname, sizeof ttyname,
"/dev/%s", argv[1]);
else
snprintf(ttyname, sizeof ttyname,
"/dev/tty%s", argv[1]);
} else
snprintf(ttyname, sizeof ttyname, "%s", argv[1]);
fd = open(ttyname, O_RDWR);
if (fd < 0)
err(1, "%s", ttyname);
#ifdef __FreeBSD__
/* make a copy of the user's stderr before closing descriptors, and
* redirect {err,warn} output there.
*/
if ((errfd = dup(2)) < 0 || (errfp = fdopen(errfd, "w")) == NULL)
err(1, "can't open errfp stream");
fcntl(errfd, F_SETFD, 1); /* set close-on-exec */
err_set_file(errfp);
#endif
/* don't do chdir("/") since that would cause trouble if a relative
* path to a command was used.
*/
if (daemon(1, 0) < 0)
err(1, "daemon");
dup2(fd, 0);
dup2(fd, 1);
dup2(fd, 2);
if (fd > 2)
close(fd);
if (ioctl(0, TIOCSCTTY) == -1)
err(1, "ioctl TIOCSCTTY on stdin");
execvp(argv[2], &argv[2]);
err(1, "execvp %s", argv[2]);
}
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20000517194534.D21557>
