From owner-p4-projects@FreeBSD.ORG Wed Jun 13 19:54:17 2012 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 5EA211065672; Wed, 13 Jun 2012 19:54:17 +0000 (UTC) Delivered-To: perforce@freebsd.org Received: from mx1.freebsd.org (unknown [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id EE3DB106566B for ; Wed, 13 Jun 2012 19:54:16 +0000 (UTC) (envelope-from brooks@freebsd.org) Received: from skunkworks.freebsd.org (skunkworks.freebsd.org [69.147.83.45]) by mx1.freebsd.org (Postfix) with ESMTP id CEDD48FC0C for ; Wed, 13 Jun 2012 19:54:16 +0000 (UTC) Received: from skunkworks.freebsd.org (localhost [127.0.0.1]) by skunkworks.freebsd.org (8.14.4/8.14.4) with ESMTP id q5DJsGww022969 for ; Wed, 13 Jun 2012 19:54:16 GMT (envelope-from brooks@freebsd.org) Received: (from perforce@localhost) by skunkworks.freebsd.org (8.14.4/8.14.4/Submit) id q5DJsGh7022966 for perforce@freebsd.org; Wed, 13 Jun 2012 19:54:16 GMT (envelope-from brooks@freebsd.org) Date: Wed, 13 Jun 2012 19:54:16 GMT Message-Id: <201206131954.q5DJsGh7022966@skunkworks.freebsd.org> X-Authentication-Warning: skunkworks.freebsd.org: perforce set sender to brooks@freebsd.org using -f From: Brooks Davis To: Perforce Change Reviews Precedence: bulk Cc: Subject: PERFORCE change 212771 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 13 Jun 2012 19:54:17 -0000 http://p4web.freebsd.org/@@212771?ac=10 Change 212771 by brooks@brooks_ecr_current on 2012/06/13 19:53:39 Checkpoint simple support for running pictview directly from init via and entry in /etc/ttys. The code is incomplete in that it does not allocate a pty and thus lacks things like ECHO support which makes typing in the swapped /bin/sh quite difficult. I don't need that for the demo so I'm not going to spend further time on it. The original behavior suitable for use with a manual invocation and watch should be preserved. Affected files ... .. //depot/projects/ctsrd/beribsd/src/ctsrd/pictview/pictview.c#2 edit Differences ... ==== //depot/projects/ctsrd/beribsd/src/ctsrd/pictview/pictview.c#2 (text+ko) ==== @@ -28,10 +28,12 @@ * SUCH DAMAGE. */ +#include +#include #include #include -#include -#include +#include +#include #include #include #include @@ -62,6 +64,9 @@ // number of lines in the line pattern static const int num_lines_pattern = 600; +// send keyboard output to stdout by default +static int kbdfd = 0; + /***************************************************************************** * hack around endian issue @@ -702,8 +707,9 @@ } if(ic < 0x80) { // printf("key = \"%c\" = 0x%02x\n", c, ic); - putchar(c); - fflush(stdout); + /* XXX: should handle full buffers */ + if (write(kbdfd, &c, 1) == -1) + err(1, "write"); // cancel shift and ctrl modes after character sent if((keymode==1) || (keymode==3)) keymode=0; @@ -1012,6 +1018,10 @@ int main(int argc, char *argv[]) { + int ofd, pipefds[2]; + pid_t pid; + char *devpath; + // initialise framebuffers and mtl control for mmap access fb_init(); fb_text_cursor(255, 255); @@ -1023,6 +1033,40 @@ // pen_drawing(); // line_pattern(); + if (argc > 2) + errx(1, "usage: pictview [tty]"); + if (argc == 2) { + if (pipe(pipefds) == -1) + err(1, "pipe()"); + pid = fork(); + if (pid < 0) + return (pid); + else if (pid > 0) { + /* XXX: should probably wait a bit and see if the child fails quickly */ + kbdfd=pipefds[0]; + } else { + if (dup2(pipefds[1], 0) == -1) + err(1, "dup2(%d, 0)", pipefds[1]); + if (argv[1][0] != '/') + asprintf(&devpath, "/dev/%s", argv[1]); + else + devpath = argv[1]; + ofd = open(devpath, O_WRONLY); + if (ofd < 0) + err(1, "open(%s)", argv[1]); + if (dup2(ofd, 1) == -1) { + syslog(LOG_ALERT, "redir: dup2(%d, 1) failed with %d", ofd, errno); + exit(1); + } + if (dup2(ofd, 2) == -1) { + syslog(LOG_ALERT, "redir: dup2(%d, 2) failed with %d", ofd, errno); + exit(1); + } + execl("/bin/sh", "sh", "-i", NULL); + err(1, "execl()"); + } + } + pictview(); close(ctrlfd);