/* ** Called when the shell sub-process stdin stream is ready for input. Writes ** data from the "input" text string passed to issueCommand. */ static void stdinWriteProc(XtPointer clientData, int *source, XtInputId *id) { WindowInfo *window = (WindowInfo *)clientData; shellCmdInfo *cmdData = window->shellCmdData; int nWritten; nWritten = write(cmdData->stdinFD, cmdData->inPtr, cmdData->inLength); if (nWritten == -1) { if (errno == EPIPE) { /* Just shut off input to broken pipes. User is likely feeding it to a command which does not take input */ XtRemoveInput(cmdData->stdinInputID); cmdData->stdinInputID = 0; close(cmdData->stdinFD); cmdData->inPtr = NULL; } else if (errno != EWOULDBLOCK && errno != EAGAIN) { perror("NEdit: Write to shell command failed"); finishCmdExecution(window, True); } } else { cmdData->inPtr += nWritten; cmdData->inLength -= nWritten; if (cmdData->inLength <= 0) { XtRemoveInput(cmdData->stdinInputID); cmdData->stdinInputID = 0; close(cmdData->stdinFD); cmdData->inPtr = NULL; } } }
void IvyChannelRemove( Channel channel ) { if ( channel->handle_delete ) (*channel->handle_delete)( channel->data ); XtRemoveInput( channel->id_read ); XtRemoveInput( channel->id_delete ); }
void FinalizeToolTalkSession( ) { Tt_status ttRc; int i; for (i = 0; i < view_count; i++) { if (view_set[i]->msg != 0) { if (view_set[i]->pats != 0) { ttdt_file_quit( view_set[i]->pats, 0 ); view_set[i]->pats = 0; } tt_message_reply( view_set[i]->msg ); tttk_message_destroy( view_set[i]->msg ); view_set[i]->msg = 0; } } if( FileManagerToolTalkPattern && tt_ptr_error( FileManagerToolTalkPattern ) == TT_OK ) { ttRc = ttdt_session_quit( NULL, FileManagerToolTalkPattern, 1 ); if( ProcessToolTalkInputId ) XtRemoveInput( ProcessToolTalkInputId ); } ttRc = ttdt_close( NULL, NULL, sendStopped ); }
/*++++++++++++++++++++++++++++ kill_child() +++++++++++++++++++++++++++++*/ static void kill_child(Widget w) { if (cmd_pid > 0) { pid_t pid = cmd_pid; XtRemoveInput(cmd_input_id); cmd_input_id = 0L; if (kill(pid, SIGINT) == -1) { (void)fprintf(stderr, #if SIZEOF_PID_T == 4 "Failed to kill() process %d : %s (%s %d)\n", #else "Failed to kill() process %lld : %s (%s %d)\n", #endif (pri_pid_t)cmd_pid, strerror(errno), __FILE__, __LINE__); } else { catch_child(cmd_output); } } return; }
void MAPaintTabletQuit( ThreeDViewStruct *view_struct) { /* do nothing if tablet NULL */ if( !tablet ){ return; } /* stop the tablet */ TabletStop(tablet); /* remove it as an input source */ XtRemoveInput(tabletInputId); /* close it */ TabletClose(tablet); tablet = NULL; /* clear the global polyline */ if( tabletPoly ){ WlzFreePolyDmn(tabletPoly); tabletPoly = NULL; } return; }
void GSocketGUIFunctionsTableConcrete::Install_Callback(GSocket *socket, GSocketEvent event) { int *m_id = (int *)(socket->m_gui_dependent); int c; if (socket->m_fd == -1) return; switch (event) { case GSOCK_LOST: /* fall-through */ case GSOCK_INPUT: c = 0; break; case GSOCK_OUTPUT: c = 1; break; case GSOCK_CONNECTION: c = ((socket->m_server) ? 0 : 1); break; default: return; } if (m_id[c] != -1) XtRemoveInput(m_id[c]); if (c == 0) { m_id[0] = XtAppAddInput(wxGetAppContext(), socket->m_fd, (XtPointer *)XtInputReadMask, (XtInputCallbackProc) _GSocket_Motif_Input, (XtPointer) socket); } else { m_id[1] = XtAppAddInput(wxGetAppContext(), socket->m_fd, (XtPointer *)XtInputWriteMask, (XtInputCallbackProc) _GSocket_Motif_Output, (XtPointer) socket); } }
void xunregister_rti(const Input_buffer *ib) { if (gapp->gui->inwin && ib) { /* the screen has been initialized : we can remove the buffer */ XtRemoveInput((XtInputId) ib->id); } }
static void close_pipe (text_data *d) { if (d->pid) { # ifdef DEBUG fprintf (stderr, "%s: textclient: kill %d\n", progname, d->pid); # endif kill (d->pid, SIGTERM); } d->pid = 0; if (d->pipe_id) XtRemoveInput (d->pipe_id); d->pipe_id = 0; if (d->pipe) { # ifdef DEBUG fprintf (stderr, "%s: textclient: pclose\n", progname); # endif pclose (d->pipe); } d->pipe = 0; }
/* Called in the parent when the forked process dies. Runs the caller's callback, and cleans up. */ static void finalize_cb (XtPointer closure, int *fd, XtIntervalId *id) { grabclient_data *data = (grabclient_data *) closure; Display *dpy = DisplayOfScreen (data->screen); char *name; XRectangle geom = { 0, 0, 0, 0 }; XtRemoveInput (*id); name = get_name (dpy, data->window); get_geometry (dpy, data->window, &geom); data->callback (data->screen, data->window, data->drawable, name, &geom, data->closure); if (name) free (name); fclose (data->read_pipe); if (data->pid) /* reap zombies */ { int status; waitpid (data->pid, &status, 0); data->pid = 0; } memset (data, 0, sizeof (*data)); free (data); }
void _XtIceWatchProc ( IceConn ice_conn, IcePointer client_data, Bool opening, IcePointer *watch_data) { #ifdef DEBUG printf ("_XtIceWatchProc\n"); #endif /* DEBUG */ if (opening) { XtAppContext appContext = (XtAppContext) client_data; *watch_data = (IcePointer) XtAppAddInput ( appContext, IceConnectionNumber (ice_conn), (XtPointer) XtInputReadMask, _XtProcessIceMsgProc, (XtPointer) ice_conn); } else { XtRemoveInput ((XtInputId) *watch_data); } }
static void DeleteFileHandler( int fd) /* Stream id for which to remove callback * procedure. */ { FileHandler *filePtr, *prevPtr; if (!initialized) { InitNotifier(); } TclSetAppContext(NULL); /* * Find the entry for the given file (and return if there isn't one). */ for (prevPtr = NULL, filePtr = notifier.firstFileHandlerPtr; ; prevPtr = filePtr, filePtr = filePtr->nextPtr) { if (filePtr == NULL) { return; } if (filePtr->fd == fd) { break; } } /* * Clean up information in the callback record. */ if (prevPtr == NULL) { notifier.firstFileHandlerPtr = filePtr->nextPtr; } else { prevPtr->nextPtr = filePtr->nextPtr; } if (filePtr->mask & TCL_READABLE) { XtRemoveInput(filePtr->read); } if (filePtr->mask & TCL_WRITABLE) { XtRemoveInput(filePtr->write); } if (filePtr->mask & TCL_EXCEPTION) { XtRemoveInput(filePtr->except); } ckfree(filePtr); }
bool qt_set_socket_handler( int sockfd, int type, TQObject *obj, bool enable ) { if ( sockfd < 0 || type < 0 || type > 2 || obj == 0 ) { #if defined(CHECK_RANGE) tqWarning( "TQSocketNotifier: Internal error" ); #endif return FALSE; } XtPointer inpMask = 0; switch (type) { case TQSocketNotifier::Read: inpMask = (XtPointer)XtInputReadMask; break; case TQSocketNotifier::Write: inpMask = (XtPointer)XtInputWriteMask; break; case TQSocketNotifier::Exception: inpMask = (XtPointer)XtInputExceptMask; break; default: return FALSE; } if (enable) { SocketNot *sn = new SocketNot; sn->obj = obj; sn->fd = sockfd; if( _notifiers[type].isEmpty() ) { _notifiers[type].insert( 0, sn ); } else { SocketNot *p = _notifiers[type].first(); while ( p && p->fd > sockfd ) p = _notifiers[type].next(); #if defined(CHECK_STATE) if ( p && p->fd==sockfd ) { static const char *t[] = { "read", "write", "exception" }; tqWarning( "TQSocketNotifier: Multiple socket notifiers for " "same socket %d and type %s", sockfd, t[type] ); } #endif if ( p ) _notifiers[type].insert( _notifiers[type].at(), sn ); else _notifiers[type].append( sn ); } sn->id = XtAppAddInput( g_appcon, sockfd, inpMask, socketCallback, sn ); } else { SocketNot *sn = _notifiers[type].first(); while ( sn && !(sn->obj == obj && sn->fd == sockfd) ) sn = _notifiers[type].next(); if ( !sn ) // not found return FALSE; XtRemoveInput( sn->id ); _notifiers[type].remove(); } return TRUE; }
static void mcu_close(uint mcuid) { struct mcu_comm *mcu = mcu_ptr(mcuid); if( mcu->fd >= 0 ) { close(mcu->fd); mcu->fd = -1; } if( mcu->inp_id ) { XtRemoveInput(mcu->inp_id); mcu->inp_id = 0; } mcu->state = INIT; }
NPError NPP_Destroy(NPP instance, NPSavedData** save) { SqueakPlugin *plugin; DPRINT("NP: NPP_Destroy\n"); if (!instance) return NPERR_INVALID_INSTANCE_ERROR; plugin= (SqueakPlugin*) instance->pdata; if (plugin) { int i; if (plugin->sqwindow && plugin->display) { DPRINT("NP: DestroyWindow %x\n", plugin->sqwindow); XSetErrorHandler(IgnoreErrors); XSync(plugin->display,0); XKillClient(plugin->display, plugin->sqwindow); XSync(plugin->display,0); } if (plugin->pid) { DPRINT("NP: kill 0x%i\n", plugin->pid); kill(plugin->pid, SIGTERM); plugin->pid= 0; } if (plugin->input) { XtRemoveInput(plugin->input); } for (i= 0; i < 4; i++) if (plugin->pipes[i]) { close(plugin->pipes[i]); plugin->pipes[i]= 0; } if (plugin->srcUrl) { NPN_MemFree(plugin->srcUrl); plugin->srcUrl= NULL; } if (plugin->srcFilename) { NPN_MemFree(plugin->srcFilename); plugin->srcFilename= NULL; } if (plugin->failureUrl) { NPN_MemFree(plugin->failureUrl); plugin->failureUrl= NULL; } if (plugin->argv) { for (i= 0; i < plugin->argc; i++) { if (plugin->argv[i]) NPN_MemFree(plugin->argv[i]); } plugin->argc= 0; NPN_MemFree(plugin->argv); plugin->argv= NULL; } NPN_MemFree(plugin); } instance->pdata= NULL; return NPERR_NO_ERROR; }
/*--------------------------- catch_child() -----------------------------*/ static void catch_child(Widget w) { int n; char buffer[4096 + 3]; if ((n = read(cmd_fd, buffer, 4096)) > 0) { buffer[n] = '\0'; XmTextInsert(cmd_output, wpr_position, buffer); wpr_position += n; if (go_to_beginning == NO) { XmTextShowPosition(cmd_output, wpr_position); } XFlush(display); } else if (n == 0) { buffer[0] = '>'; buffer[1] = '\0'; XmTextInsert(cmd_output, wpr_position, buffer); if (go_to_beginning == NO) { XmTextShowPosition(cmd_output, wpr_position); } else { XmTextShowPosition(cmd_output, 0); } XFlush(display); if (cmd_pid > 0) { if (wait(NULL) == -1) { (void)fprintf(stderr, "wait() error : %s (%s %d)\n", strerror(errno), __FILE__, __LINE__); exit(INCORRECT); } cmd_pid = 0; } wpr_position = 0; if (cmd_input_id != 0L) { XtRemoveInput(cmd_input_id); cmd_input_id = 0L; if (close(cmd_fd) == -1) { (void)fprintf(stderr, "close() error : %s (%s %d)\n", strerror(errno), __FILE__, __LINE__); } } } return; }
void workshop_connection_closed(void) { /* * socket closed on other end */ XtRemoveInput(inputHandler); inputHandler = 0; sd = -1; }
static void xt_sln_input_cb( XtPointer p, int *n, XtInputId *id ) { TRACE(1,""); int sln = (intptr_t) p; if( sln_input_cb(sln) ) { TRACE(1,"server died" ); XtRemoveInput(*id); } }
static void glitchpeg_free (Display *dpy, Window window, void *closure) { struct state *st = (struct state *) closure; XFreeGC (dpy, st->gc); if (st->pipe_id) XtRemoveInput (st->pipe_id); if (st->pipe) fclose (st->pipe); if (st->image_data) free (st->image_data); free (st); }
/******************************************************** Callback to register file descriptors ********************************************************/ void registerCA(void *dummy, int fd, int opened) { struct FDLIST *cur,*next; int found; #ifdef WIN32 #define alhInputMask XtInputReadWinsock #else #define alhInputMask XtInputReadMask #endif /* Branch depending on whether the fd is opened or closed */ if(opened) { /* Look for a linked list structure for this fd */ cur=lastFdInList; while(cur) { if(cur->fd == fd) { errMsg("Tried to add a second callback for file descriptor %d\n",fd); return; } cur=cur->prev; } /* Allocate and fill a linked list structure for this fd */ cur=(struct FDLIST *)calloc(1,sizeof(struct FDLIST)); if(cur == NULL) { errMsg("Could not allocate space to keep track of file descriptor %d\n",fd); return; } cur->prev=lastFdInList; cur->inpid=XtAppAddInput(appContext,fd,(XtPointer)alhInputMask, alProcessCA,NULL); cur->fd=fd; lastFdInList=cur; } else { /* Find the linked list structure for this fd */ found=0; cur=next=lastFdInList; while(cur) { if(cur->fd == fd) { found=1; break; } next=cur; cur=cur->prev; } /* Remove the callback */ if(found) { XtRemoveInput(cur->inpid); if(cur == lastFdInList) lastFdInList=cur->prev; else next->prev=cur->prev; free(cur); } else { errMsg("Error removing callback for file descriptor %d\n",fd); } } }
/* Duplicated from utils/grabclient.c */ static void xscreensaver_getimage_file_cb (XtPointer closure, int *source, XtInputId *id) { /* This is not called from a signal handler, so doing stuff here is fine. */ struct state *st = (struct state *) closure; char buf[10240]; char *file = buf; FILE *fp; struct stat stat; int n; unsigned char *s; int L; *buf = 0; fgets (buf, sizeof(buf)-1, st->pipe); pclose (st->pipe); st->pipe = 0; XtRemoveInput (st->pipe_id); st->pipe_id = 0; /* strip trailing newline */ L = strlen(buf); while (L > 0 && (buf[L-1] == '\r' || buf[L-1] == '\n')) buf[--L] = 0; fp = fopen (file, "r"); if (! fp) { fprintf (stderr, "%s: unable to read %s\n", progname, file); return; } if (fstat (fileno (fp), &stat)) { fprintf (stderr, "%s: %s: stat failed\n", progname, file); return; } if (st->image_data) free (st->image_data); st->image_size = stat.st_size; st->image_data = malloc (st->image_size); s = st->image_data; do { n = fread (s, 1, st->image_data + st->image_size - s, fp); if (n > 0) s += n; } while (n > 0); fclose (fp); /* fprintf (stderr, "loaded %s (%lu)\n", file, st->image_size); */ st->start_time = time((time_t *) 0); }
/* When the subprocess has generated some output, this reads as much as it can into s->buf at s->buf_tail. */ static void drain_input (state *s) { XtAppContext app = XtDisplayToApplicationContext (s->dpy); if (! s->pipe) return; /* if (! s->input_available_p) return; */ /* s->input_available_p = False; */ if (! input_available_p (fileno (s->pipe))) return; if (s->buf_tail < sizeof(s->buf) - 2) { int target = sizeof(s->buf) - s->buf_tail - 2; int n; n = read (fileno (s->pipe), (void *) (s->buf + s->buf_tail), target); if (n > 0) { s->buf_tail += n; s->buf[s->buf_tail] = 0; } else { XtRemoveInput (s->pipe_id); s->pipe_id = 0; pclose (s->pipe); s->pipe = 0; /* If the process didn't print a terminating newline, add one. */ if (s->buf_tail > 1 && s->buf[s->buf_tail-1] != '\n') { s->buf[s->buf_tail++] = '\n'; s->buf[s->buf_tail] = 0; } /* Then add one more, to make sure there's a sentence break at EOF. */ s->buf[s->buf_tail++] = '\n'; s->buf[s->buf_tail] = 0; /* Set up a timer to re-launch the subproc in a bit. */ if (s->timer_id) abort(); s->timer_id = XtAppAddTimeOut (app, s->subproc_relaunch_delay, relaunch_generator_timer, (XtPointer) s); } } }
void ws_no_input_stream(Stream s) { XtInputId id; if ( (id = getXtInputIdStream(s)) ) { XtRemoveInput(id); setXtInputIdStream(s, 0); DEBUG(NAME_stream, Cprintf("Un-registered %s for asynchronous input\n", pp(s))); } }
static void CloseConsole (void) { if (input) { XtRemoveInput (input_id); fclose (input); } #ifdef USE_PTY close (tty_fd); #endif }
static void xt_notify_end_process(XtPointer data, int *WXUNUSED(fid), XtInputId *id) { wxEndProcessData *proc_data = (wxEndProcessData *)data; wxHandleProcessTermination(proc_data); // VZ: I think they should be the same... wxASSERT( (int)*id == proc_data->tag ); XtRemoveInput(*id); }
void child_close(int hc) { struct child_stat *child = mls(CLIST, hc); if( child->stat == CHILD_NOT_INIT ) return; child_close_handle(hc); /* get exit status */ XtRemoveInput(child->id); /* remove listener */ if(child->cb) child->cb(hc); /* tell app. */ m_free(child->line); /* free mem */ mrb_destroy(child->qin); free( child->filename ); child->stat = CHILD_NOT_INIT; m_free_strings(child->args,0); }
static void comp_err(XtPointer closure, int *fd, XtInputId *id) { MGV *m = (MGV *)closure; assert(MgvOK(m)); if(m->child_err == NULL) m->child_err = XmCreateInformationDialog(m->main, "childStderr", NULL, 0); if(!mgv_child_msg(m->child_err, *fd)) { XtRemoveInput(*id); close(*fd); } }
static void handle_input(XtPointer client_data, int *source, XtInputId *id) { if (gps_poll(gpsdata) < 0) { XtRemoveInput(gps_input); (void)gps_close(gpsdata); XtRemoveTimeOut(timeout); XmTextFieldSetString(text_10, "No GPS data available"); (void)err_dialog(toplevel, "No GPS data available.\n\n" "Check the connection to gpsd and if gpsd is running"); gps_lost = true; gps_timeout = XtAppAddTimeOut(app, 3000, handle_gps, app); } }
static CloseConsole () { if (input) { XtRemoveInput (input_id); #ifdef MINIX nbio_unregister(fileno (input)); #endif fclose (input); } #ifdef USE_PTY close (tty_fd); #endif }
void ToolTalkError( char * procName, Tt_status errId ) { if( tt_is_err( errId ) ) { switch( errId ) { case TT_ERR_NOMP: XtRemoveInput( ProcessToolTalkInputId ); break; default: break; } } }
static void Disconnect(Widget w) { int i; #ifdef DEBUG printf("Disconnect()\n"); #endif for (i = 0; i < Host_NumClients(w); i++) { close(Host_ClientList(w)[i].fd); } if (Host_ClientList(w)) { XtFree((char *)Host_ClientList(w)); Host_ClientList(w) = NULL; } Host_NumClients(w) = 0; if (Host_InputId(w)) { XtRemoveInput(Host_InputId(w)); Host_InputId(w) = 0; } if (Host_Fd(w) != -1) { XltHostCallbackStruct tmp; tmp.reason = XltCR_DISCONNECT; XtCallCallbackList(w, Host_DisconnectCallback(w), &tmp); close(Host_Fd(w)); Host_Fd(w) = -1; } if (Host_OutputId(w)) { XtRemoveTimeOut(Host_OutputId(w)); Host_OutputId(w) = 0; } if (Host_BinaryTimeOutId(w)) { XtRemoveTimeOut(Host_BinaryTimeOutId(w)); Host_BinaryTimeOutId(w) = 0; } Host_OutputSize(w) = 0; Host_InputSize(w) = 0; Host_OutputData(w)[0] = '\0'; Host_InputData(w)[0] = '\0'; Host_Mode(w) = MODE_ASCII; }