int InitializeTooltalk(void) { char * procid; Tt_status status; int fd; procid = tt_default_procid(); status = tt_ptr_error(procid); if ((status == TT_ERR_NOMP) || (status == TT_ERR_PROCID)) { /* * We need to try to establish a connection */ procid = tt_open(); status = tt_ptr_error(procid); if (status != TT_OK) { ToolTalkError("Could not connect to ToolTalk:\n%s\n", status); return (False); } tt_free(procid); /* * Determine the Tooltalk fildes. */ fd = tt_fd(); status = tt_int_error(fd); if (status != TT_OK) { ToolTalkError("Could not connect to ToolTalk:\n%s\n", status); tt_close(); ttfdG = -1; return(False); } else { ttfdG = fd; } #ifdef DtActUseXtOverSelect /* * Add the ToolTalk file descriptor to the set monitored by Xt */ XtAddInput(fd, (XtPointer)XtInputReadMask, input_handler, 0); #endif /* DtActUseXtOverSelect */ } return (True); }
static void OpenConsole(void) { input = 0; if (app_resources.file) { if (!strcmp (app_resources.file, "console")) { /* must be owner and have read/write permission */ #if !defined(__NetBSD__) && !defined(__OpenBSD__) struct stat sbuf; # if !defined (linux) if (!stat("/dev/console", &sbuf) && (sbuf.st_uid == getuid()) && !access("/dev/console", R_OK|W_OK)) # endif #endif { #ifdef USE_FILE # ifdef linux if (!stat(FILE_NAME, &sbuf)) # endif input = fopen (FILE_NAME, "r"); #endif #ifdef USE_PTY if (!input && get_pty (&pty_fd, &tty_fd, ttydev, ptydev) == 0) { # ifdef TIOCCONS int on = 1; # ifdef USE_PRIVSEP if (priv_set_console(tty_fd) != -1) input = fdopen (pty_fd, "r"); # else if (ioctl (tty_fd, TIOCCONS, (char *) &on) != -1) input = fdopen (pty_fd, "r"); # endif # else int consfd = open("/dev/console", O_RDONLY); if (consfd >= 0) { if (ioctl(consfd, SRIOCSREDIR, tty_fd) != -1) input = fdopen (pty_fd, "r"); close(consfd); } # endif } #endif /* USE_PTY */ } #ifdef USE_OSM /* Don't have to be owner of /dev/console when using /dev/osm. */ if (!input) input = osm_pipe(); #endif if (input && app_resources.verbose) { char *hostname; TextAppend (text, "Console log for ", 16); hostname = mit_console_name + MIT_CONSOLE_LEN; TextAppend (text, hostname, strlen (hostname)); TextAppend (text, "\n", 1); } } else { regularFile = FALSE; if (access(app_resources.file, R_OK) == 0) { int fd = open (app_resources.file, O_RDONLY | O_NONBLOCK | O_NOCTTY); if (fd != -1) { input = fdopen (fd, "r"); if (input) { struct stat sbuf; if ((fstat(fd, &sbuf) == 0) && S_ISREG(sbuf.st_mode)) regularFile = TRUE; } else close(fd); } } } if (!input) { if (app_resources.exitOnFail) exit(0); TextAppend (text, "Couldn't open ", 14); TextAppend (text, app_resources.file, strlen (app_resources.file)); TextAppend (text, "\n", 1); } } else input = stdin; if (input) { input_id = XtAddInput (fileno (input), (XtPointer) XtInputReadMask, inputReady, (XtPointer) text); } }
static OpenConsole () { input = 0; if (app_resources.file) { if (!strcmp (app_resources.file, "console")) { struct stat sbuf; /* must be owner and have read/write permission */ #if !defined(__NetBSD__) && !defined(__OpenBSD__) && !defined(Lynx) && !defined(__EMX__) if (!stat("/dev/console", &sbuf) && (sbuf.st_uid == getuid()) && !access("/dev/console", R_OK|W_OK)) #endif { #ifdef USE_FILE input = fopen (FILE_NAME, "r"); #ifdef __EMX__ if (input) { ULONG arg = 1,arglen; APIRET rc; if ((rc=DosDevIOCtl(fileno(input), 0x76,0x4d, &arg, sizeof(arg), &arglen, NULL, 0, NULL)) != 0) { fclose(input); input = 0; } } #endif #endif #ifdef USE_PTY if (get_pty (&pty_fd, &tty_fd, ttydev, ptydev) == 0) { #ifdef TIOCCONS int on = 1; if (ioctl (tty_fd, TIOCCONS, (char *) &on) != -1) input = fdopen (pty_fd, "r"); #else #ifndef Lynx int consfd = open("/dev/console", O_RDONLY); if (consfd >= 0) { if (ioctl(consfd, SRIOCSREDIR, tty_fd) != -1) input = fdopen (pty_fd, "r"); close(consfd); } #else if (newconsole(tty_fd) < 0) perror("newconsole"); else { input = fdopen (pty_fd, "r"); atexit(RestoreConsole); } #endif #endif } #endif } #ifdef USE_OSM /* Don't have to be owner of /dev/console when using /dev/osm. */ if (!input) input = osm_pipe(); #endif if (input && app_resources.verbose) { char *hostname; TextAppend (text, "Console log for ", 16); hostname = mit_console_name + MIT_CONSOLE_LEN; TextAppend (text, hostname, strlen (hostname)); TextAppend (text, "\n", 1); } } else { struct stat sbuf; regularFile = FALSE; if (access(app_resources.file, R_OK) == 0) { input = fopen (app_resources.file, "r"); if (input) if (!stat(app_resources.file, &sbuf) && (sbuf.st_mode & S_IFMT) == S_IFREG) { regularFile = TRUE; fseek(input, 0, SEEK_END); } } } if (!input) { if (app_resources.exitOnFail) exit(0); TextAppend (text, "Couldn't open ", 14); TextAppend (text, app_resources.file, strlen (app_resources.file)); TextAppend (text, "\n", 1); } } else input = stdin; if (input) { #ifdef MINIX fcntl(fileno (input), F_SETFD, fcntl(fileno (input), F_GETFD) | FD_ASYNCHIO); nbio_register(fileno (input)); #endif input_id = XtAddInput (fileno (input), (XtPointer) XtInputReadMask, inputReady, (XtPointer) text); } }