Date: Wed, 13 Jun 2012 19:54:16 GMT From: Brooks Davis <brooks@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 212771 for review Message-ID: <201206131954.q5DJsGh7022966@skunkworks.freebsd.org>
next in thread | raw e-mail | index | archive | help
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 <sys/types.h> +#include <sys/stat.h> #include <stdio.h> #include <stdlib.h> -#include <sys/types.h> -#include <sys/stat.h> +#include <syslog.h> +#include <stdarg.h> #include <fcntl.h> #include <unistd.h> #include <errno.h> @@ -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);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201206131954.q5DJsGh7022966>