diff options
Diffstat (limited to 'hw/xfree86/os-support/solaris/sun_init.c')
-rw-r--r-- | hw/xfree86/os-support/solaris/sun_init.c | 502 |
1 files changed, 242 insertions, 260 deletions
diff --git a/hw/xfree86/os-support/solaris/sun_init.c b/hw/xfree86/os-support/solaris/sun_init.c index 800fc1c3d..4b75a98ac 100644 --- a/hw/xfree86/os-support/solaris/sun_init.c +++ b/hw/xfree86/os-support/solaris/sun_init.c @@ -30,7 +30,7 @@ #include "xf86Priv.h" #include "xf86_OSlib.h" #ifdef HAVE_SYS_KD_H -# include <sys/kd.h> +#include <sys/kd.h> #endif /* @@ -48,6 +48,7 @@ static Bool KeepTty = FALSE; static Bool Protect0 = FALSE; static Bool UseConsole = FALSE; + #ifdef HAS_USL_VTS static int VTnum = -1; static int xf86StartVT = -1; @@ -71,18 +72,19 @@ switch_to(int vt, const char *from) SYSCALL(ret = ioctl(xf86Info.consoleFd, VT_ACTIVATE, vt)); if (ret != 0) xf86Msg(X_WARNING, "%s: VT_ACTIVATE failed: %s\n", - from, strerror(errno)); + from, strerror(errno)); SYSCALL(ret = ioctl(xf86Info.consoleFd, VT_WAITACTIVE, vt)); if (ret != 0) xf86Msg(X_WARNING, "%s: VT_WAITACTIVE failed: %s\n", - from, strerror(errno)); + from, strerror(errno)); } void xf86OpenConsole(void) { int i; + #ifdef HAS_USL_VTS int fd; struct vt_mode VT; @@ -90,209 +92,192 @@ xf86OpenConsole(void) MessageType from = X_PROBED; #endif - if (serverGeneration == 1) - { - /* Check if we're run with euid==0 */ - if (geteuid() != 0) - FatalError("xf86OpenConsole: Server must be suid root\n"); - - /* Protect page 0 to help find NULL dereferencing */ - /* mprotect() doesn't seem to work */ - if (Protect0) - { - int fd = -1; - - if ((fd = open("/dev/zero", O_RDONLY, 0)) < 0) - { - xf86Msg(X_WARNING, - "xf86OpenConsole: cannot open /dev/zero (%s)\n", - strerror(errno)); - } - else - { - if (mmap(0, 0x1000, PROT_NONE, - MAP_FIXED | MAP_SHARED, fd, 0) == MAP_FAILED) - xf86Msg(X_WARNING, - "xf86OpenConsole: failed to protect page 0 (%s)\n", - strerror(errno)); - - close(fd); - } - } + if (serverGeneration == 1) { + /* Check if we're run with euid==0 */ + if (geteuid() != 0) + FatalError("xf86OpenConsole: Server must be suid root\n"); + + /* Protect page 0 to help find NULL dereferencing */ + /* mprotect() doesn't seem to work */ + if (Protect0) { + int fd = -1; + + if ((fd = open("/dev/zero", O_RDONLY, 0)) < 0) { + xf86Msg(X_WARNING, + "xf86OpenConsole: cannot open /dev/zero (%s)\n", + strerror(errno)); + } + else { + if (mmap(0, 0x1000, PROT_NONE, + MAP_FIXED | MAP_SHARED, fd, 0) == MAP_FAILED) + xf86Msg(X_WARNING, + "xf86OpenConsole: failed to protect page 0 (%s)\n", + strerror(errno)); + + close(fd); + } + } #ifdef HAS_USL_VTS - /* - * Setup the virtual terminal manager - */ - if ((fd = open("/dev/vt/0",O_RDWR,0)) == -1) - { - xf86ErrorF("xf86OpenConsole: Cannot open /dev/vt/0 (%s)\n", - strerror(errno)); - vtEnabled = 0; - } - else - { - if (ioctl(fd, VT_ENABLED, &vtEnabled) < 0) - { - xf86ErrorF("xf86OpenConsole: VT_ENABLED failed (%s)\n", - strerror(errno)); - vtEnabled = 0; - } - } -#endif /* HAS_USL_VTS */ - - if (UseConsole) - { - strlcpy(consoleDev, SOL_CONSOLE_DEV, sizeof(consoleDev)); + /* + * Setup the virtual terminal manager + */ + if ((fd = open("/dev/vt/0", O_RDWR, 0)) == -1) { + xf86ErrorF("xf86OpenConsole: Cannot open /dev/vt/0 (%s)\n", + strerror(errno)); + vtEnabled = 0; + } + else { + if (ioctl(fd, VT_ENABLED, &vtEnabled) < 0) { + xf86ErrorF("xf86OpenConsole: VT_ENABLED failed (%s)\n", + strerror(errno)); + vtEnabled = 0; + } + } +#endif /* HAS_USL_VTS */ + + if (UseConsole) { + strlcpy(consoleDev, SOL_CONSOLE_DEV, sizeof(consoleDev)); #ifdef HAS_USL_VTS - xf86Info.vtno = CONSOLE_VTNO; - - if (vtEnabled == 0) - { - xf86StartVT = 0; - } - else - { - if (ioctl(fd, VT_GETSTATE, &vtinfo) < 0) - FatalError("xf86OpenConsole: Cannot determine current VT\n"); - xf86StartVT = vtinfo.v_active; - } -#endif /* HAS_USL_VTS */ - goto OPENCONSOLE; - } + xf86Info.vtno = CONSOLE_VTNO; + + if (vtEnabled == 0) { + xf86StartVT = 0; + } + else { + if (ioctl(fd, VT_GETSTATE, &vtinfo) < 0) + FatalError + ("xf86OpenConsole: Cannot determine current VT\n"); + xf86StartVT = vtinfo.v_active; + } +#endif /* HAS_USL_VTS */ + goto OPENCONSOLE; + } #ifdef HAS_USL_VTS - if (vtEnabled == 0) - { - /* VT not enabled - kernel too old or Sparc platforms - without visual_io support */ - xf86Msg(from, "VT infrastructure is not available\n"); - - xf86StartVT = 0; - xf86Info.vtno = 0; - strlcpy(consoleDev, xf86SolarisFbDev, sizeof(consoleDev)); - goto OPENCONSOLE; - } - - if (ioctl(fd, VT_GETSTATE, &vtinfo) < 0) - FatalError("xf86OpenConsole: Cannot determine current VT\n"); - - xf86StartVT = vtinfo.v_active; - - if (VTnum != -1) - { - xf86Info.vtno = VTnum; - from = X_CMDLINE; - } - else if (xf86Info.ShareVTs) - { - xf86Info.vtno = vtinfo.v_active; - from = X_CMDLINE; - } - else - { - if ((ioctl(fd, VT_OPENQRY, &xf86Info.vtno) < 0) || - (xf86Info.vtno == -1)) - { - FatalError("xf86OpenConsole: Cannot find a free VT\n"); - } - } - - xf86Msg(from, "using VT number %d\n\n", xf86Info.vtno); - snprintf(consoleDev, PATH_MAX, "/dev/vt/%d", xf86Info.vtno); - - if (fd != -1) - { - close(fd); - } - -#endif /* HAS_USL_VTS */ - -OPENCONSOLE: - if (!KeepTty) - setpgrp(); - - if (((xf86Info.consoleFd = open(consoleDev, O_RDWR | O_NDELAY, 0)) < 0)) - FatalError("xf86OpenConsole: Cannot open %s (%s)\n", - consoleDev, strerror(errno)); - - /* Change ownership of the vt or console */ - chown(consoleDev, getuid(), getgid()); + if (vtEnabled == 0) { + /* VT not enabled - kernel too old or Sparc platforms + without visual_io support */ + xf86Msg(from, "VT infrastructure is not available\n"); + + xf86StartVT = 0; + xf86Info.vtno = 0; + strlcpy(consoleDev, xf86SolarisFbDev, sizeof(consoleDev)); + goto OPENCONSOLE; + } + + if (ioctl(fd, VT_GETSTATE, &vtinfo) < 0) + FatalError("xf86OpenConsole: Cannot determine current VT\n"); + + xf86StartVT = vtinfo.v_active; + + if (VTnum != -1) { + xf86Info.vtno = VTnum; + from = X_CMDLINE; + } + else if (xf86Info.ShareVTs) { + xf86Info.vtno = vtinfo.v_active; + from = X_CMDLINE; + } + else { + if ((ioctl(fd, VT_OPENQRY, &xf86Info.vtno) < 0) || + (xf86Info.vtno == -1)) { + FatalError("xf86OpenConsole: Cannot find a free VT\n"); + } + } + + xf86Msg(from, "using VT number %d\n\n", xf86Info.vtno); + snprintf(consoleDev, PATH_MAX, "/dev/vt/%d", xf86Info.vtno); + + if (fd != -1) { + close(fd); + } + +#endif /* HAS_USL_VTS */ + + OPENCONSOLE: + if (!KeepTty) + setpgrp(); + + if (((xf86Info.consoleFd = open(consoleDev, O_RDWR | O_NDELAY, 0)) < 0)) + FatalError("xf86OpenConsole: Cannot open %s (%s)\n", + consoleDev, strerror(errno)); + + /* Change ownership of the vt or console */ + chown(consoleDev, getuid(), getgid()); #ifdef HAS_USL_VTS - if (xf86Info.ShareVTs) - return; - - if (vtEnabled) - { - /* - * Now get the VT - */ - switch_to(xf86Info.vtno, "xf86OpenConsole"); - -#ifdef VT_SET_CONSUSER /* added in snv_139 */ - if (strcmp(display, "0") == 0) - if (ioctl(xf86Info.consoleFd, VT_SET_CONSUSER) != 0) - xf86Msg(X_WARNING, - "xf86OpenConsole: VT_SET_CONSUSER failed\n"); + if (xf86Info.ShareVTs) + return; + + if (vtEnabled) { + /* + * Now get the VT + */ + switch_to(xf86Info.vtno, "xf86OpenConsole"); + +#ifdef VT_SET_CONSUSER /* added in snv_139 */ + if (strcmp(display, "0") == 0) + if (ioctl(xf86Info.consoleFd, VT_SET_CONSUSER) != 0) + xf86Msg(X_WARNING, + "xf86OpenConsole: VT_SET_CONSUSER failed\n"); #endif - if (ioctl(xf86Info.consoleFd, VT_GETMODE, &VT) < 0) - FatalError("xf86OpenConsole: VT_GETMODE failed\n"); + if (ioctl(xf86Info.consoleFd, VT_GETMODE, &VT) < 0) + FatalError("xf86OpenConsole: VT_GETMODE failed\n"); - OsSignal(SIGUSR1, xf86VTAcquire); - OsSignal(SIGUSR2, xf86VTRelease); + OsSignal(SIGUSR1, xf86VTAcquire); + OsSignal(SIGUSR2, xf86VTRelease); - VT.mode = VT_PROCESS; - VT.acqsig = SIGUSR1; - VT.relsig = SIGUSR2; + VT.mode = VT_PROCESS; + VT.acqsig = SIGUSR1; + VT.relsig = SIGUSR2; - if (ioctl(xf86Info.consoleFd, VT_SETMODE, &VT) < 0) - FatalError("xf86OpenConsole: VT_SETMODE VT_PROCESS failed\n"); + if (ioctl(xf86Info.consoleFd, VT_SETMODE, &VT) < 0) + FatalError("xf86OpenConsole: VT_SETMODE VT_PROCESS failed\n"); - if (ioctl(xf86Info.consoleFd, VT_SETDISPINFO, atoi(display)) < 0) - xf86Msg(X_WARNING, "xf86OpenConsole: VT_SETDISPINFO failed\n"); - } + if (ioctl(xf86Info.consoleFd, VT_SETDISPINFO, atoi(display)) < 0) + xf86Msg(X_WARNING, "xf86OpenConsole: VT_SETDISPINFO failed\n"); + } #endif #ifdef KDSETMODE - SYSCALL(i = ioctl(xf86Info.consoleFd, KDSETMODE, KD_GRAPHICS)); - if (i < 0) { - xf86Msg(X_WARNING, - "xf86OpenConsole: KDSETMODE KD_GRAPHICS failed on %s (%s)\n", - consoleDev, strerror(errno)); - } + SYSCALL(i = ioctl(xf86Info.consoleFd, KDSETMODE, KD_GRAPHICS)); + if (i < 0) { + xf86Msg(X_WARNING, + "xf86OpenConsole: KDSETMODE KD_GRAPHICS failed on %s (%s)\n", + consoleDev, strerror(errno)); + } #endif } - else /* serverGeneration != 1 */ - { + else { /* serverGeneration != 1 */ + #ifdef HAS_USL_VTS - if (vtEnabled && !xf86Info.ShareVTs) - { - /* - * Now re-get the VT - */ - if (xf86Info.autoVTSwitch) - switch_to(xf86Info.vtno, "xf86OpenConsole"); - -#ifdef VT_SET_CONSUSER /* added in snv_139 */ - if (strcmp(display, "0") == 0) - if (ioctl(xf86Info.consoleFd, VT_SET_CONSUSER) != 0) - xf86Msg(X_WARNING, - "xf86OpenConsole: VT_SET_CONSUSER failed\n"); + if (vtEnabled && !xf86Info.ShareVTs) { + /* + * Now re-get the VT + */ + if (xf86Info.autoVTSwitch) + switch_to(xf86Info.vtno, "xf86OpenConsole"); + +#ifdef VT_SET_CONSUSER /* added in snv_139 */ + if (strcmp(display, "0") == 0) + if (ioctl(xf86Info.consoleFd, VT_SET_CONSUSER) != 0) + xf86Msg(X_WARNING, + "xf86OpenConsole: VT_SET_CONSUSER failed\n"); #endif - /* - * If the server doesn't have the VT when the reset occurs, - * this is to make sure we don't continue until the activate - * signal is received. - */ - if (!xf86Screens[0]->vtSema) - sleep(5); - } -#endif /* HAS_USL_VTS */ + /* + * If the server doesn't have the VT when the reset occurs, + * this is to make sure we don't continue until the activate + * signal is received. + */ + if (!xf86Screens[0]->vtSema) + sleep(5); + } +#endif /* HAS_USL_VTS */ } } @@ -307,44 +292,47 @@ xf86CloseConsole(void) #if !defined(__i386__) && !defined(__i386) && !defined(__x86) if (!xf86DoConfigure) { - int fd; - - /* - * Wipe out framebuffer just like the non-SI Xsun server does. This - * could be improved by saving framebuffer contents in - * xf86OpenConsole() above and restoring them here. Also, it's unclear - * at this point whether this should be done for all framebuffers in - * the system, rather than only the console. - */ - if ((fd = open(xf86SolarisFbDev, O_RDWR, 0)) < 0) { - xf86Msg(X_WARNING, - "xf86CloseConsole(): unable to open framebuffer (%s)\n", - strerror(errno)); - } else { - struct fbgattr fbattr; - - if ((ioctl(fd, FBIOGATTR, &fbattr) < 0) && - (ioctl(fd, FBIOGTYPE, &fbattr.fbtype) < 0)) { - xf86Msg(X_WARNING, - "xf86CloseConsole(): unable to retrieve framebuffer" - " attributes (%s)\n", strerror(errno)); - } else { - pointer fbdata; - - fbdata = mmap(NULL, fbattr.fbtype.fb_size, - PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); - if (fbdata == MAP_FAILED) { - xf86Msg(X_WARNING, - "xf86CloseConsole(): unable to mmap framebuffer" - " (%s)\n", strerror(errno)); - } else { - memset(fbdata, 0, fbattr.fbtype.fb_size); - munmap(fbdata, fbattr.fbtype.fb_size); - } - } - - close(fd); - } + int fd; + + /* + * Wipe out framebuffer just like the non-SI Xsun server does. This + * could be improved by saving framebuffer contents in + * xf86OpenConsole() above and restoring them here. Also, it's unclear + * at this point whether this should be done for all framebuffers in + * the system, rather than only the console. + */ + if ((fd = open(xf86SolarisFbDev, O_RDWR, 0)) < 0) { + xf86Msg(X_WARNING, + "xf86CloseConsole(): unable to open framebuffer (%s)\n", + strerror(errno)); + } + else { + struct fbgattr fbattr; + + if ((ioctl(fd, FBIOGATTR, &fbattr) < 0) && + (ioctl(fd, FBIOGTYPE, &fbattr.fbtype) < 0)) { + xf86Msg(X_WARNING, + "xf86CloseConsole(): unable to retrieve framebuffer" + " attributes (%s)\n", strerror(errno)); + } + else { + pointer fbdata; + + fbdata = mmap(NULL, fbattr.fbtype.fb_size, + PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); + if (fbdata == MAP_FAILED) { + xf86Msg(X_WARNING, + "xf86CloseConsole(): unable to mmap framebuffer" + " (%s)\n", strerror(errno)); + } + else { + memset(fbdata, 0, fbattr.fbtype.fb_size); + munmap(fbdata, fbattr.fbtype.fb_size); + } + } + + close(fd); + } } #endif @@ -355,19 +343,17 @@ xf86CloseConsole(void) #endif #ifdef HAS_USL_VTS - if (vtEnabled) - { - if (ioctl(xf86Info.consoleFd, VT_GETMODE, &VT) != -1) - { - VT.mode = VT_AUTO; /* Set default vt handling */ - ioctl(xf86Info.consoleFd, VT_SETMODE, &VT); - } - - /* Activate the VT that X was started on */ - if (xf86Info.autoVTSwitch) - switch_to(xf86StartVT, "xf86CloseConsole"); + if (vtEnabled) { + if (ioctl(xf86Info.consoleFd, VT_GETMODE, &VT) != -1) { + VT.mode = VT_AUTO; /* Set default vt handling */ + ioctl(xf86Info.consoleFd, VT_SETMODE, &VT); + } + + /* Activate the VT that X was started on */ + if (xf86Info.autoVTSwitch) + switch_to(xf86StartVT, "xf86CloseConsole"); } -#endif /* HAS_USL_VTS */ +#endif /* HAS_USL_VTS */ close(xf86Info.consoleFd); } @@ -379,58 +365,54 @@ xf86ProcessArgument(int argc, char **argv, int i) * Keep server from detaching from controlling tty. This is useful when * debugging, so the server can receive keyboard signals. */ - if (!strcmp(argv[i], "-keeptty")) - { - KeepTty = TRUE; - return 1; + if (!strcmp(argv[i], "-keeptty")) { + KeepTty = TRUE; + return 1; } /* * Undocumented flag to protect page 0 from read/write to help catch NULL * pointer dereferences. This is purely a debugging flag. */ - if (!strcmp(argv[i], "-protect0")) - { - Protect0 = TRUE; - return 1; + if (!strcmp(argv[i], "-protect0")) { + Protect0 = TRUE; + return 1; } /* * Use /dev/console as the console device. */ - if (!strcmp(argv[i], "-C")) - { - UseConsole = TRUE; - return 1; + if (!strcmp(argv[i], "-C")) { + UseConsole = TRUE; + return 1; } #ifdef HAS_USL_VTS - if ((argv[i][0] == 'v') && (argv[i][1] == 't')) - { - if (sscanf(argv[i], "vt%d", &VTnum) == 0) - { - UseMsg(); - VTnum = -1; - return 0; - } + if ((argv[i][0] == 'v') && (argv[i][1] == 't')) { + if (sscanf(argv[i], "vt%d", &VTnum) == 0) { + UseMsg(); + VTnum = -1; + return 0; + } - return 1; + return 1; } -#endif /* HAS_USL_VTS */ +#endif /* HAS_USL_VTS */ if ((i + 1) < argc) { - if (!strcmp(argv[i], "-dev")) { - strlcpy(xf86SolarisFbDev, argv[i+1], sizeof(xf86SolarisFbDev)); - return 2; - } + if (!strcmp(argv[i], "-dev")) { + strlcpy(xf86SolarisFbDev, argv[i + 1], sizeof(xf86SolarisFbDev)); + return 2; + } } return 0; } -void xf86UseMsg(void) +void +xf86UseMsg(void) { #ifdef HAS_USL_VTS ErrorF("vtX Use the specified VT number\n"); |