From owner-p4-projects@FreeBSD.ORG Wed Nov 21 00:12:04 2012 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 4E8A4199; Wed, 21 Nov 2012 00:12:04 +0000 (UTC) Delivered-To: perforce@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id EBFBB197 for ; Wed, 21 Nov 2012 00:12:03 +0000 (UTC) (envelope-from brooks@freebsd.org) Received: from skunkworks.freebsd.org (skunkworks.freebsd.org [IPv6:2001:4f8:fff6::2d]) by mx1.freebsd.org (Postfix) with ESMTP id D29FE8FC16 for ; Wed, 21 Nov 2012 00:12:03 +0000 (UTC) Received: from skunkworks.freebsd.org (localhost [127.0.0.1]) by skunkworks.freebsd.org (8.14.5/8.14.5) with ESMTP id qAL0C3ag052348 for ; Wed, 21 Nov 2012 00:12:03 GMT (envelope-from brooks@freebsd.org) Received: (from perforce@localhost) by skunkworks.freebsd.org (8.14.5/8.14.5/Submit) id qAL0C3e6052345 for perforce@freebsd.org; Wed, 21 Nov 2012 00:12:03 GMT (envelope-from brooks@freebsd.org) Date: Wed, 21 Nov 2012 00:12:03 GMT Message-Id: <201211210012.qAL0C3e6052345@skunkworks.freebsd.org> X-Authentication-Warning: skunkworks.freebsd.org: perforce set sender to brooks@freebsd.org using -f From: Brooks Davis Subject: PERFORCE change 219823 for review To: Perforce Change Reviews Precedence: bulk X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.14 List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 21 Nov 2012 00:12:04 -0000 http://p4web.freebsd.org/@@219823?ac=10 Change 219823 by brooks@brooks_zenith on 2012/11/21 00:11:40 Treat directories ending .cpt as CheriPoint presentations and launch cheripoint when they are selected. An appropriate icon is still required. Affected files ... .. //depot/projects/ctsrd/cheribsd/src/ctsrd/browser/browser.c#5 edit Differences ... ==== //depot/projects/ctsrd/cheribsd/src/ctsrd/browser/browser.c#5 (text+ko) ==== @@ -265,7 +265,6 @@ int pmaster, pslave, status; ssize_t rlen; pid_t pid; - struct sigaction act; struct pollfd pfd[1]; char buf[1024]; u_int32_t *image; @@ -287,12 +286,6 @@ return; } - memset (&act, 0, sizeof(act)); - act.sa_handler = handle_sigchld; - - if (sigaction(SIGCHLD, &act, 0)) - err(1, "sigacation"); - close(pslave); /* * We poll for data from the child's pty. Don't bother looking for @@ -549,7 +542,10 @@ desc = "special/character"; break; case DT_DIR: - desc = "directory"; + if (fnmatch("*.cpt", entry->d_name, 0) == 0) + desc = "x-application/cheripoint"; + else + desc = "directory"; break; case DT_BLK: desc = "special/block"; @@ -797,6 +793,84 @@ } static int +invoke_cheripoint(int dfd, const char *name) +{ + static int pmaster; + int pslave, n, status; + char buf[1024]; + ssize_t rlen; + pid_t child_pid; + struct pollfd pfd[1]; + + if (openpty(&pmaster, &pslave, NULL, NULL, NULL) == -1) + err(1, "openpty"); + child_pid = fork(); + if (child_pid < 0) + err(1, "fork()"); + else if (child_pid > 0) + close(pslave); + else { + close(pmaster); + if (fchdir(dfd) == -1) { + syslog(LOG_ALERT, "fchdir failed in child: %s", + strerror(errno)); + err(1, "fchdir"); + } + if (login_tty(pslave) < 0) { + syslog(LOG_ALERT, "login_tty failed in child: %s", + strerror(errno)); + err(1, "tty_login"); + } + execl("/usr/bin/cheripoint", "cheripoint", "-f", name, + NULL); + syslog(LOG_ALERT, "exec of /usr/bin/browser failed: %s", + strerror(errno)); + err(1, "execl()"); + } + + for(;;) { + /* + * If the child has exited, reset the state and return to the + * main screen. + */ + if (zombies_waiting) { + wait4(child_pid, &status, 0, NULL); + /* XXX: ideally we'd check the status */ + close(pmaster); + zombies_waiting = 0; + break; + } + + /* Check for output from the child and post it if needed */ + pfd[0].fd = pmaster; + pfd[0].events = POLLIN; + n = poll(pfd, 1, INFTIM); + if (n == 0) + continue; + else if (n < 0) { + if (errno == EINTR) + continue; + err(1, "poll"); + } + if (n < 0) { + syslog(LOG_ALERT, "poll failed with %s", + strerror(errno)); + err(1, "poll"); + } + if (pfd[0].revents & POLLIN) { + rlen = read(pfd[0].fd, buf, sizeof(buf)); + if (rlen < 0) { + syslog(LOG_ALERT, "read failed: %s", + strerror(errno)); + err(1, "read"); + } else if (rlen > 0) + writeall(0, buf, rlen); + } + } + return (0); +} + +static int dentcmp(const void *v1, const void *v2) { const struct dent *d1, *d2; @@ -914,6 +988,12 @@ show_text_file(dfd, dents[topslot + action].entry.d_name); goto render; + } else if (strcmp("x-application/cheripoint", + dents[topslot + action].desc) == 0) { + invoke_cheripoint(dfd, dents[topslot + + action].entry.d_name); + fb_post(bgimage); /* Restore background */ + goto render; } else { if (verbose) printf("opening non-directory not " @@ -939,6 +1019,7 @@ { int ch, dfd; int ttyflag = 1, forkflag = 0; + struct sigaction act; while ((ch = getopt(argc, argv, "fTv")) != -1) { switch (ch) { @@ -975,6 +1056,12 @@ fb_load_syscons_font(NULL, "/usr/share/syscons/fonts/iso-8x16.fnt"); busy_indicator(); + memset (&act, 0, sizeof(act)); + act.sa_handler = handle_sigchld; + + if (sigaction(SIGCHLD, &act, 0)) + err(1, "sigacation"); + if (forkflag) fork_child(); busy_indicator();