PERFORCE change 219823 for review
Brooks Davis
brooks at FreeBSD.org
Wed Nov 21 00:12:04 UTC 2012
http://p4web.freebsd.org/@@219823?ac=10
Change 219823 by brooks at 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();
More information about the p4-projects
mailing list