From owner-freebsd-questions Wed May 17 12: 8:41 2000 Delivered-To: freebsd-questions@freebsd.org Received: from scientia.demon.co.uk (scientia.demon.co.uk [212.228.14.13]) by hub.freebsd.org (Postfix) with ESMTP id 7A4C937BCA1 for ; Wed, 17 May 2000 12:08:33 -0700 (PDT) (envelope-from ben@scientia.demon.co.uk) Received: from strontium.scientia.demon.co.uk ([192.168.91.36] ident=exim) by scientia.demon.co.uk with esmtp (Exim 3.12 #1) id 12s8p5-0008F7-00; Wed, 17 May 2000 19:45:35 +0100 Received: (from ben) by strontium.scientia.demon.co.uk (Exim 3.12 #7) id 12s8p5-000EiS-00; Wed, 17 May 2000 19:45:35 +0100 Date: Wed, 17 May 2000 19:45:34 +0100 From: Ben Smithurst To: Sys Admin 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> References: <3922C8EA.11CBC702@chemcomp.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="45Z9DzgjV8m4Oswq" X-Mailer: Mutt 1.0i In-Reply-To: <3922C8EA.11CBC702@chemcomp.com> Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG --45Z9DzgjV8m4Oswq Content-Type: text/plain; charset=us-ascii 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 --45Z9DzgjV8m4Oswq Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="runontty.c" static const char rcsid[] = "$Id: runontty.c,v 1.3 2000/03/04 00:04:52 ben Exp $"; #include #include #include #include #include #include #include #include /* * 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]); } --45Z9DzgjV8m4Oswq-- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message