diff options
author | Lee Chang Yeon <cyeon.lee@samsung.com> | 2014-04-08 21:04:30 +0900 |
---|---|---|
committer | Lee Chang Yeon <cyeon.lee@samsung.com> | 2014-04-08 21:04:30 +0900 |
commit | a9333f203e872f350b8bfb16dce0150e812cc5bb (patch) | |
tree | 3cc370fb3bd164b919f00349b8af665c09e59057 /xconsole.c | |
parent | 0fca8ad0ccb61173440d5db8fed8dc68e83223af (diff) | |
download | xconsole-a9333f203e872f350b8bfb16dce0150e812cc5bb.tar.gz xconsole-a9333f203e872f350b8bfb16dce0150e812cc5bb.tar.bz2 xconsole-a9333f203e872f350b8bfb16dce0150e812cc5bb.zip |
Imported Upstream version 1.0.6upstream/1.0.6upstream
Diffstat (limited to 'xconsole.c')
-rw-r--r-- | xconsole.c | 145 |
1 files changed, 29 insertions, 116 deletions
@@ -1,5 +1,4 @@ /* - * $Xorg: xconsole.c,v 1.5 2001/02/09 02:05:40 xorgcvs Exp $ * Copyright 1990, 1998 The Open Group @@ -26,12 +25,13 @@ in this Software without prior written authorization from The Open Group. * Author: Keith Packard, MIT X Consortium */ -/* $XFree86: xc/programs/xconsole/xconsole.c,v 3.31tsi Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" #endif +#include <X11/Xfuncproto.h> + #include <X11/Intrinsic.h> #include <X11/StringDefs.h> #include <X11/Xatom.h> @@ -69,16 +69,14 @@ extern char *_XawTextGetSTRING(TextWidget ctx, XawTextPosition left, # ifdef HAVE_UTIL_H # include <util.h> # endif +# ifdef HAVE_LIBUTIL_H +# include <libutil.h> +# endif # ifdef HAVE_PTY_H # include <pty.h> # endif #endif -/* Fix ISC brain damage. When using gcc fdopen isn't declared in <stdio.h>. */ -#if defined(ISC) && __STDC__ && !defined(ISC30) -extern FILE *fdopen(int, char const *); -#endif - static void inputReady(XtPointer w, int *source, XtInputId *id); static long TextLength(Widget w); static void TextReplace(Widget w, int start, int end, XawTextBlock *block); @@ -145,18 +143,6 @@ static XrmOptionDescRec options[] = { {"-saveLines", "*saveLines", XrmoptionSepArg, NULL}, }; -#ifdef ultrix -#define USE_FILE -#define FILE_NAME "/dev/xcons" -#endif - -#ifdef __UNIXOS2__ -#define USE_FILE -#define FILE_NAME "/dev/console$" -#define INCL_DOSFILEMGR -#define INCL_DOSDEVIOCTL -#include <os2.h> -#endif #ifdef linux #define USE_FILE @@ -167,7 +153,7 @@ static XrmOptionDescRec options[] = { * devpts. This is the fallback if open file FILE_NAME fails. * <werner@suse.de> */ -# define USE_PTS +# define USE_PTS # endif #endif @@ -189,7 +175,7 @@ static XrmOptionDescRec options[] = { # include <sys/strredir.h> # endif # endif -# if defined(TIOCCONS) || defined(SRIOCSREDIR) || defined(Lynx) +# if defined(TIOCCONS) || defined(SRIOCSREDIR) # define USE_PTY static int tty_fd, pty_fd; static char ttydev[64], ptydev[64]; @@ -215,11 +201,7 @@ static int child_pid; #ifdef __hpux #define PTYCHAR1 "zyxwvutsrqp" #else /* !__hpux */ -#ifdef __UNIXOS2__ -#define PTYCHAR1 "pq" -#else #define PTYCHAR1 "pqrstuvwxyzPQRSTUVWXYZ" -#endif /* !__UNIXOS2__ */ #endif /* !__hpux */ #endif /* !PTYCHAR1 */ @@ -235,16 +217,6 @@ static int child_pid; #endif /* !__hpux */ #endif /* !PTYCHAR2 */ -#ifdef Lynx -static void -RestoreConsole(void) -{ - int fd; - if ((fd = open("/dev/con", O_RDONLY)) >= 0) - newconsole(fd); -} -#endif - static void OpenConsole(void) { @@ -254,7 +226,7 @@ OpenConsole(void) if (!strcmp (app_resources.file, "console")) { /* must be owner and have read/write permission */ -#if !defined(__NetBSD__) && !defined(__OpenBSD__) && !defined(Lynx) && !defined(__UNIXOS2__) +#if !defined(__NetBSD__) && !defined(__OpenBSD__) struct stat sbuf; # if !defined (linux) if (!stat("/dev/console", &sbuf) && @@ -267,23 +239,9 @@ OpenConsole(void) # ifdef linux if (!stat(FILE_NAME, &sbuf)) # endif - input = fopen (FILE_NAME, "r"); -# ifdef __UNIXOS2__ - 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 + input = fopen (FILE_NAME, "r"); #endif - + #ifdef USE_PTY if (!input && get_pty (&pty_fd, &tty_fd, ttydev, ptydev) == 0) { @@ -292,7 +250,6 @@ OpenConsole(void) 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) { @@ -300,15 +257,6 @@ OpenConsole(void) 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 /* USE_PTY */ @@ -329,16 +277,23 @@ OpenConsole(void) } 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) && - S_ISREG( sbuf.st_mode ) ) - regularFile = TRUE; + 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) @@ -384,7 +339,7 @@ KillChild(int sig) #endif /*ARGSUSED*/ -static void +static void _X_NORETURN Quit(Widget widget, XEvent *event, String *params, Cardinal *num_params) { #ifdef USE_OSM @@ -434,7 +389,7 @@ Deiconified(Widget widget, XEvent *event, String *params, Cardinal *num_params) Arg arglist[1]; char *oldName; char *newName; - int oldlen; + size_t oldlen; iconified = False; if (!app_resources.notify || !notified) @@ -538,7 +493,7 @@ inputReady(XtPointer w, int *source, XtInputId *id) stripNonprint (buffer); n = strlen (buffer); } - + TextAppend ((Widget) text, buffer, n); } } @@ -636,7 +591,7 @@ ConvertSelection(Widget w, Atom *selection, Atom *target, Atom *type, return False; } -static void +static void _X_NORETURN LoseSelection(Widget w, Atom *selection) { Quit (w, (XEvent*)NULL, (String*)NULL, (Cardinal*)NULL); @@ -868,42 +823,6 @@ get_pty(int *pty, int *tty, char *ttydev, char *ptydev) #else static int devindex, letter = 0; -#if defined(umips) && defined (SYSTYPE_SYSV) - struct stat fstat_buf; - - *pty = open ("/dev/ptc", O_RDWR); - if (*pty < 0 || (fstat (*pty, &fstat_buf)) < 0) - { - return(1); - } - sprintf (ttydev, "/dev/ttyq%d", minor(fstat_buf.st_rdev)); - sprintf (ptydev, "/dev/ptyq%d", minor(fstat_buf.st_rdev)); - if ((*tty = open (ttydev, O_RDWR)) >= 0) - { - /* got one! */ - return(0); - } - close (*pty); -#else /* not (umips && SYSTYPE_SYSV) */ -#ifdef CRAY - for (; devindex < 256; devindex++) { - sprintf (ttydev, "/dev/ttyp%03d", devindex); - sprintf (ptydev, "/dev/pty/%03d", devindex); - - if ((*pty = open (ptydev, O_RDWR)) >= 0 && - (*tty = open (ttydev, O_RDWR)) >= 0) - { - /* - * We need to set things up for our next entry - * into this function! - */ - (void) devindex++; - return(0); - } - if (*pty >= 0) - close (*pty); - } -#else /* !CRAY */ #ifdef sgi { char *slave; @@ -939,8 +858,6 @@ get_pty(int *pty, int *tty, char *ttydev, char *ptydev) (void) letter++; } #endif /* sgi else not sgi */ -#endif /* CRAY else not CRAY */ -#endif /* umips && SYSTYPE_SYSV */ #endif /* USE_GET_PSEUDOTTY */ #endif /* SVR4 */ /* @@ -970,10 +887,6 @@ get_pty(int *pty, int *tty, char *ttydev, char *ptydev) #endif #endif -#ifdef ISC -#define NO_READAHEAD -#endif - static FILE * osm_pipe(void) { @@ -984,7 +897,7 @@ osm_pipe(void) return NULL; #if defined (_AIX) if ((tty = open("/dev/ptc", O_RDWR)) < 0) -#else +#else if ((tty = open("/dev/ptmx", O_RDWR)) < 0) #endif return NULL; |