=================================================================== RCS file: /home/cvs/OpenXM_contrib/gnuplot/term/Attic/linux.trm,v retrieving revision 1.1 retrieving revision 1.1.1.3 diff -u -p -r1.1 -r1.1.1.3 --- OpenXM_contrib/gnuplot/term/Attic/linux.trm 2000/01/09 17:01:14 1.1 +++ OpenXM_contrib/gnuplot/term/Attic/linux.trm 2003/09/15 07:09:37 1.1.1.3 @@ -1,5 +1,5 @@ /* - * $Id: linux.trm,v 1.1 2000/01/09 17:01:14 maekawa Exp $ + * $Id: linux.trm,v 1.1.1.3 2003/09/15 07:09:37 ohara Exp $ * */ @@ -80,7 +80,7 @@ TERM_PUBLIC void LINUX_linetype __PROTO((int linetype) TERM_PUBLIC void LINUX_move __PROTO((unsigned int x, unsigned int y)); TERM_PUBLIC void LINUX_vector __PROTO((unsigned int x, unsigned int y)); TERM_PUBLIC int LINUX_text_angle __PROTO((int ang)); -TERM_PUBLIC void LINUX_put_text __PROTO((unsigned int x, unsigned int y, char *str)); +TERM_PUBLIC void LINUX_put_text __PROTO((unsigned int x, unsigned int y, const char *str)); TERM_PUBLIC void LINUX_suspend __PROTO((void)); TERM_PUBLIC void LINUX_resume __PROTO((void)); @@ -94,22 +94,25 @@ TERM_PUBLIC void LINUX_resume __PROTO((void)); static int linux_vmode = G1024x768x256; /* default mode */ static int vgacolor[] = { 7, 8, 2, 3, 4, 5, 9, 14, 12, 15, 13, 10, 11, 1, 6 }; static int graphics_on = FALSE; -vga_modeinfo *modeinfo; +static vga_modeinfo *modeinfo; static int linux_startx, linux_starty, linux_lasty; static int linux_angle; -int LINUX_graphics_allowed; +int LINUX_graphics_allowed; /* also used in vgagl.trm */ +extern void drop_privilege(); +extern void take_privilege(); -typedef (*linux_line_func_ptr) __PROTO((int x1, int y1, int x2, int y2)); +typedef int (*linux_line_func_ptr) __PROTO((int x1, int y1, int x2, int y2)); static void LINUX_putc __PROTO((unsigned int x, unsigned int y, int c, int ang, linux_line_func_ptr line_func)); /* this function is called at the very beginning of main() to initialize * the vgalib and to revoke suid privileges. - * /dev/console and /dev/tty\d are considered graphic terminals, all other + * /dev/console and /dev/tty\d and /dev/vc/\d are considered graphic terminals, all other * don't support the linux terminal */ -void LINUX_setup(void) +void +LINUX_setup(void) { char line[256]; FILE *pipe; @@ -124,12 +127,31 @@ void LINUX_setup(void) fgets(line, 256, pipe); pclose(pipe); line[strlen(line) - 1] = '\0'; - if (strcmp(line, "/dev/console") == 0 || - (strncmp(line, "/dev/tty", 8) == 0 && isdigit(line[8]))) + if ( + strcmp(line, "/dev/console") == 0 || + + ( ( strncmp(line, "/dev/tty", 8) == 0 || strncmp(line, "/dev/vc/", 8) == 0 ) + && isdigit((unsigned char) line[8])) + + ) { LINUX_graphics_allowed = TRUE; + } else { + /* check for socket name as set for example by `screen' */ + char* sty = getenv("STY"); + if (sty) { + int n1, n2; + if (3 == sscanf(sty, "%d.tty%d.%s", &n1, &n2, line)) { + /* we could check here, if host is the + * same as gethostname() returns. */ + LINUX_graphics_allowed = TRUE; + } + } + } } if (LINUX_graphics_allowed) { + take_privilege(); vga_init(); + drop_privilege(); } else { /* err - shouldn't we give up root uid whatever happens ? * or perhaps vga_init() does it ? @@ -138,7 +160,8 @@ void LINUX_setup(void) } } -TERM_PUBLIC void LINUX_options() +TERM_PUBLIC +void LINUX_options() { if (!LINUX_graphics_allowed) { int_error("Linux terminal driver not available", NO_CARET); @@ -146,7 +169,8 @@ TERM_PUBLIC void LINUX_options() fprintf(stderr, "%s\n", vga_getmodename(linux_vmode)); } -TERM_PUBLIC void LINUX_init() +TERM_PUBLIC +void LINUX_init() { /* vga_init () has been moved to immediately after main () for security */ if (vga_getdefaultmode() != -1) @@ -165,7 +189,8 @@ TERM_PUBLIC void LINUX_init() linux_lasty = modeinfo->height - 1; } -TERM_PUBLIC void LINUX_reset() +TERM_PUBLIC void +LINUX_reset() { if (graphics_on) { vga_setmode(TEXT); @@ -173,7 +198,8 @@ TERM_PUBLIC void LINUX_reset() } } -TERM_PUBLIC void LINUX_text() +TERM_PUBLIC void +LINUX_text() { if (graphics_on) { vga_getch(); @@ -182,7 +208,8 @@ TERM_PUBLIC void LINUX_text() } } -TERM_PUBLIC void LINUX_graphics() +TERM_PUBLIC void +LINUX_graphics() { if (!graphics_on) { vga_setmode(linux_vmode); @@ -190,17 +217,20 @@ TERM_PUBLIC void LINUX_graphics() } } -TERM_PUBLIC void LINUX_suspend() +TERM_PUBLIC void +LINUX_suspend() { vga_flip(); } -TERM_PUBLIC void LINUX_resume() +TERM_PUBLIC void +LINUX_resume() { vga_flip(); } -TERM_PUBLIC void LINUX_linetype(linetype) +TERM_PUBLIC void +LINUX_linetype(linetype) int linetype; { if (linetype >= 13) @@ -208,7 +238,8 @@ int linetype; vga_setcolor(vgacolor[linetype + 2]); } -TERM_PUBLIC void LINUX_move(x, y) +TERM_PUBLIC void +LINUX_move(x, y) unsigned int x; unsigned int y; { @@ -216,7 +247,8 @@ unsigned int y; linux_starty = y; } -TERM_PUBLIC void LINUX_vector(x, y) +TERM_PUBLIC void +LINUX_vector(x, y) unsigned int x; unsigned int y; { @@ -225,14 +257,16 @@ unsigned int y; linux_starty = y; } -TERM_PUBLIC int LINUX_text_angle(ang) +TERM_PUBLIC int +LINUX_text_angle(ang) int ang; { linux_angle = ang; return TRUE; } -static void LINUX_putc(x, y, c, ang, line_func) +static void +LINUX_putc(x, y, c, ang, line_func) unsigned int x, y; int c; int ang; @@ -258,9 +292,10 @@ linux_line_func_ptr line_func; } } -TERM_PUBLIC void LINUX_put_text(x, y, str) +TERM_PUBLIC void +LINUX_put_text(x, y, str) unsigned int x, y; -char *str; +const char *str; { int i; switch (linux_angle) {