Changeset a6a9ddb
- Timestamp:
- Jun 22, 2011, 12:37:22 AM (13 years ago)
- Branches:
- master, release-1.10, release-1.8, release-1.9
- Children:
- 2d04312
- Parents:
- 2244836
- git-author:
- David Benjamin <davidben@mit.edu> (05/24/11 02:03:16)
- git-committer:
- David Benjamin <davidben@mit.edu> (06/22/11 00:37:22)
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
owl.h
r074bdaa ra6a9ddb 543 543 int winactive; 544 544 pid_t pid; /* or 0 if it has terminated */ 545 const owl_io_dispatch *dispatch;545 guint io_watch; 546 546 } owl_popexec; 547 547 -
popexec.c
r47e0a6a ra6a9ddb 16 16 int pipefds[2], child_write_fd, parent_read_fd; 17 17 pid_t pid; 18 GIOChannel *channel; 18 19 19 20 if (owl_global_get_popwin(&g) || owl_global_get_viewwin(&g)) { … … 54 55 pe->pid=pid; 55 56 pe->winactive=1; 56 pe->dispatch = owl_select_add_io_dispatch(parent_read_fd, OWL_IO_READ|OWL_IO_EXCEPT, &owl_popexec_inputhandler, &owl_popexec_delete_dispatch, pe); 57 channel = g_io_channel_unix_new(parent_read_fd); 58 g_io_channel_set_close_on_unref(channel, TRUE); 59 pe->io_watch = g_io_add_watch_full(channel, G_PRIORITY_DEFAULT, 60 G_IO_IN | G_IO_PRI | G_IO_ERR | G_IO_HUP, 61 owl_popexec_inputhandler, pe, 62 (GDestroyNotify)owl_popexec_unref); 63 g_io_channel_unref(channel); 57 64 pe->refcount++; 58 65 } else { … … 75 82 } 76 83 77 void owl_popexec_inputhandler(const owl_io_dispatch *d, void *data)84 gboolean owl_popexec_inputhandler(GIOChannel *source, GIOCondition condition, void *data) 78 85 { 79 86 owl_popexec *pe = data; … … 81 88 char *buf; 82 89 int status; 90 int fd = g_io_channel_unix_get_fd(source); 83 91 84 if (!pe) return; 92 /* TODO: Reading from GIOChannel may be more convenient. */ 93 94 if (!pe) return FALSE; 85 95 86 96 /* If pe->winactive is 0 then the vwin has closed. … … 96 106 /* the viewwin has closed */ 97 107 if (!pe->pid && !pe->winactive) { 98 owl_select_remove_io_dispatch(d); 99 pe->dispatch = NULL; 100 return; 108 pe->io_watch = 0; 109 return FALSE; 101 110 } 102 111 103 if (0 != (rv_navail = ioctl( d->fd, FIONREAD, &navail))) {112 if (0 != (rv_navail = ioctl(fd, FIONREAD, &navail))) { 104 113 owl_function_debugmsg("ioctl error"); 105 114 } … … 113 122 owl_viewwin_append_text(pe->vwin, "\n"); 114 123 } 115 owl_select_remove_io_dispatch(d); 116 pe->dispatch = NULL; 117 return; 124 pe->io_watch = 0; 125 return FALSE; 118 126 } 119 127 120 if ( d->fd<0 || !pe->pid || !pe->winactive || rv_navail) {128 if (fd<0 || !pe->pid || !pe->winactive || rv_navail) { 121 129 owl_function_error("popexec should not have reached this point"); 122 return ;130 return FALSE; 123 131 } 124 132 125 if (navail<=0) return ;133 if (navail<=0) return TRUE; 126 134 if (navail>1024) { navail = 1024; } 127 135 buf = g_new(char, navail+1); 128 136 owl_function_debugmsg("about to read %d", navail); 129 bread = read( d->fd, buf, navail);137 bread = read(fd, buf, navail); 130 138 if (bread<0) { 131 139 perror("read"); … … 140 148 } 141 149 g_free(buf); 142 143 } 144 145 void owl_popexec_delete_dispatch(const owl_io_dispatch *d) 146 { 147 owl_popexec *pe = d->data; 148 close(d->fd); 149 owl_popexec_unref(pe); 150 return TRUE; 150 151 } 151 152 … … 156 157 157 158 pe->winactive = 0; 158 if (pe-> dispatch) {159 owl_select_remove_io_dispatch(pe->dispatch);160 pe-> dispatch = NULL;159 if (pe->io_watch) { 160 g_source_remove(pe->io_watch); 161 pe->io_watch = 0; 161 162 } 162 163 if (pe->pid) {
Note: See TracChangeset
for help on using the changeset viewer.