Changeset 40c6657
- Timestamp:
- Dec 17, 2008, 5:13:47 PM (16 years ago)
- Branches:
- master, debian, release-1.10, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
- Children:
- df7f364
- Parents:
- cf0cc64
- git-author:
- Nelson Elhage <nelhage@mit.edu> (12/17/08 17:01:28)
- git-committer:
- Nelson Elhage <nelhage@mit.edu> (12/17/08 17:13:47)
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
owl.h
r1895c29 r40c6657 380 380 } owl_popwin; 381 381 382 typedef struct _owl_popexec {383 int refcount;384 owl_viewwin *vwin;385 int winactive;386 int pid; /* or 0 if it has terminated */387 int rfd;388 } owl_popexec;389 390 382 typedef struct _owl_messagelist { 391 383 owl_list list; … … 532 524 void *data; 533 525 } owl_dispatch; 526 527 typedef struct _owl_popexec { 528 int refcount; 529 owl_viewwin *vwin; 530 int winactive; 531 int pid; /* or 0 if it has terminated */ 532 owl_dispatch dispatch; 533 } owl_popexec; 534 534 535 535 typedef struct _owl_global { -
popexec.c
r49a8434 r40c6657 51 51 return NULL; 52 52 } else if (pid != 0) { 53 close(child_write_fd); 53 54 /* still in owl */ 54 int muxhandle;55 55 pe->pid=pid; 56 56 pe->winactive=1; 57 pe-> rfd = parent_read_fd;58 close(child_write_fd);59 muxhandle = owl_muxevents_add(owl_global_get_muxevents(&g),60 parent_read_fd, OWL_MUX_READ|OWL_MUX_EXCEPT,61 owl_popexec_inputhandler, (void*)pe);57 pe->dispatch.fd = parent_read_fd; 58 pe->dispatch.cfunc = owl_popexec_inputhandler; 59 pe->dispatch.destroy = owl_popexec_free_dispatch; 60 pe->dispatch.data = pe; 61 owl_select_add_dispatch(&pe->dispatch); 62 62 pe->refcount++; 63 63 } else { … … 85 85 } 86 86 87 void owl_popexec_inputhandler( int handle, int fd, int eventmask, void *data)87 void owl_popexec_inputhandler(owl_dispatch *d) 88 88 { 89 owl_popexec *pe = (owl_popexec*)data;89 owl_popexec *pe = d->data; 90 90 int navail, bread, rv_navail; 91 91 char *buf; … … 96 96 /* If pe->winactive is 0 then the vwin has closed. 97 97 * If pe->pid is 0 then the child has already been reaped. 98 * if pe->rfd is -1 then the fd has been closed out.98 * if d->fd is -1 then the fd has been closed out. 99 99 * Under these cases we want to get to a state where: 100 100 * - data read until end if child running … … 105 105 106 106 /* the viewwin has closed */ 107 if (pe->rfd<0 && !pe->pid && !pe->winactive) { 108 owl_muxevents_remove(owl_global_get_muxevents(&g), handle); 109 owl_function_debugmsg("unref of %p from input handler at A", pe); 110 owl_popexec_unref(pe); 107 if (!pe->pid && !pe->winactive) { 108 owl_select_remove_dispatch(d->fd); 111 109 return; 112 110 } 113 111 114 if (0 != (rv_navail = ioctl( fd, FIONREAD, (void*)&navail))) {112 if (0 != (rv_navail = ioctl(d->fd, FIONREAD, (void*)&navail))) { 115 113 owl_function_debugmsg("ioctl error"); 116 114 } … … 125 123 owl_viewwin_redisplay(pe->vwin, 1); 126 124 } 127 if (pe->rfd>0) { 128 close(pe->rfd); 129 pe->rfd = -1; 130 } 131 owl_muxevents_remove(owl_global_get_muxevents(&g), handle); 132 owl_function_debugmsg("unref of %p from input handler at B", pe); 133 owl_popexec_unref(pe); 125 owl_select_remove_dispatch(d->fd); 134 126 return; 135 127 } 136 128 137 if ( pe->rfd<0 || !pe->pid || !pe->winactive || rv_navail) {129 if (d->fd<0 || !pe->pid || !pe->winactive || rv_navail) { 138 130 owl_function_error("popexec should not have reached this point"); 139 131 return; … … 143 135 if (navail>1024) { navail = 1024; } 144 136 buf = owl_malloc(navail+1); 145 owl_function_debugmsg("about to read %d \n", navail);146 bread = read( fd, buf, navail);137 owl_function_debugmsg("about to read %d", navail); 138 bread = read(d->fd, buf, navail); 147 139 if (bread<0) { 148 140 perror("read"); … … 152 144 buf[navail] = '\0'; 153 145 } 154 owl_function_debugmsg("got data: <%s> \n", buf);146 owl_function_debugmsg("got data: <%s>", buf); 155 147 if (pe->winactive) { 156 148 owl_viewwin_append_text(pe->vwin, buf); … … 161 153 } 162 154 155 void owl_popexec_free_dispatch(owl_dispatch *d) 156 { 157 owl_popexec *pe = d->data; 158 close(d->fd); 159 owl_popexec_unref(pe); 160 } 161 163 162 void owl_popexec_viewwin_onclose(owl_viewwin *vwin, void *data) 164 163 { … … 167 166 168 167 pe->winactive = 0; 169 if (pe->rfd>0) { 170 close(pe->rfd); 171 pe->rfd = -1; 168 if (pe->dispatch.fd>0) { 169 owl_select_remove_dispatch(pe->dispatch.fd); 172 170 } 173 171 if (pe->pid) {
Note: See TracChangeset
for help on using the changeset viewer.