aboutsummaryrefslogtreecommitdiff
path: root/xorg-server/os/utils.c
diff options
context:
space:
mode:
authormarha <marha@users.sourceforge.net>2012-03-26 14:23:28 +0200
committermarha <marha@users.sourceforge.net>2012-03-26 14:23:28 +0200
commit76bcc36ed305418a3ddc5752d287ede894243e1b (patch)
treebacb320c825768471ce56f058f17ce863d592376 /xorg-server/os/utils.c
parent7d894e32566b710952c44cbc71939ad1d9e2fa8d (diff)
parent0f834b91a4768673833ab4917e87d86c237bb1a6 (diff)
downloadvcxsrv-76bcc36ed305418a3ddc5752d287ede894243e1b.tar.gz
vcxsrv-76bcc36ed305418a3ddc5752d287ede894243e1b.tar.bz2
vcxsrv-76bcc36ed305418a3ddc5752d287ede894243e1b.zip
Merge remote-tracking branch 'origin/released'
Conflicts: pixman/pixman/pixman-mmx.c xorg-server/Xext/shm.c xorg-server/Xext/syncsrv.h xorg-server/Xext/xvmain.c xorg-server/Xi/exevents.c xorg-server/Xi/opendev.c xorg-server/composite/compalloc.c xorg-server/composite/compoverlay.c xorg-server/dix/colormap.c xorg-server/dix/devices.c xorg-server/dix/dispatch.c xorg-server/dix/dixfonts.c xorg-server/dix/eventconvert.c xorg-server/dix/events.c xorg-server/dix/gc.c xorg-server/dix/getevents.c xorg-server/dix/main.c xorg-server/dix/privates.c xorg-server/dix/registry.c xorg-server/dix/resource.c xorg-server/exa/exa_accel.c xorg-server/exa/exa_migration_classic.c xorg-server/exa/exa_unaccel.c xorg-server/fb/fb.h xorg-server/fb/fbcopy.c xorg-server/fb/fbpixmap.c xorg-server/glx/dispatch.h xorg-server/glx/glapi.h xorg-server/glx/glapi_gentable.c xorg-server/glx/glapitable.h xorg-server/glx/glprocs.h xorg-server/glx/glxcmds.c xorg-server/glx/glxcmdsswap.c xorg-server/glx/glxdricommon.c xorg-server/glx/glxdriswrast.c xorg-server/glx/glxext.c xorg-server/glx/indirect_dispatch.c xorg-server/glx/indirect_dispatch.h xorg-server/glx/indirect_dispatch_swap.c xorg-server/glx/indirect_size.h xorg-server/glx/indirect_size_get.h xorg-server/glx/indirect_table.c xorg-server/glx/indirect_util.c xorg-server/glx/rensize.c xorg-server/glx/single2swap.c xorg-server/glx/singlepix.c xorg-server/glx/singlepixswap.c xorg-server/glx/singlesize.c xorg-server/hw/dmx/dmxinit.c xorg-server/hw/kdrive/ephyr/ephyr.c xorg-server/hw/kdrive/ephyr/hostx.c xorg-server/hw/kdrive/ephyr/hostx.h xorg-server/hw/kdrive/src/kinput.c xorg-server/hw/xfree86/common/compiler.h xorg-server/hw/xwin/InitInput.c xorg-server/hw/xwin/InitOutput.c xorg-server/hw/xwin/ddraw.h xorg-server/hw/xwin/glx/glwrap.c xorg-server/hw/xwin/glx/indirect.c xorg-server/hw/xwin/glx/wgl_ext_api.h xorg-server/hw/xwin/glx/winpriv.c xorg-server/hw/xwin/win.h xorg-server/hw/xwin/winallpriv.c xorg-server/hw/xwin/winauth.c xorg-server/hw/xwin/winclipboard.h xorg-server/hw/xwin/winclipboardinit.c xorg-server/hw/xwin/winclipboardthread.c xorg-server/hw/xwin/winclipboardunicode.c xorg-server/hw/xwin/winclipboardwndproc.c xorg-server/hw/xwin/winclipboardwrappers.c xorg-server/hw/xwin/winclipboardxevents.c xorg-server/hw/xwin/wincmap.c xorg-server/hw/xwin/winconfig.c xorg-server/hw/xwin/wincreatewnd.c xorg-server/hw/xwin/wincursor.c xorg-server/hw/xwin/windialogs.c xorg-server/hw/xwin/winengine.c xorg-server/hw/xwin/winerror.c xorg-server/hw/xwin/wingc.c xorg-server/hw/xwin/wingetsp.c xorg-server/hw/xwin/winkeybd.c xorg-server/hw/xwin/winkeybd.h xorg-server/hw/xwin/winlayouts.h xorg-server/hw/xwin/winmisc.c xorg-server/hw/xwin/winmonitors.c xorg-server/hw/xwin/winmouse.c xorg-server/hw/xwin/winmsg.c xorg-server/hw/xwin/winmsg.h xorg-server/hw/xwin/winmultiwindowclass.c xorg-server/hw/xwin/winmultiwindowicons.c xorg-server/hw/xwin/winmultiwindowshape.c xorg-server/hw/xwin/winmultiwindowwindow.c xorg-server/hw/xwin/winmultiwindowwm.c xorg-server/hw/xwin/winmultiwindowwndproc.c xorg-server/hw/xwin/winnativegdi.c xorg-server/hw/xwin/winpfbdd.c xorg-server/hw/xwin/winpixmap.c xorg-server/hw/xwin/winpolyline.c xorg-server/hw/xwin/winprefs.c xorg-server/hw/xwin/winprocarg.c xorg-server/hw/xwin/winregistry.c xorg-server/hw/xwin/winscrinit.c xorg-server/hw/xwin/winsetsp.c xorg-server/hw/xwin/winshaddd.c xorg-server/hw/xwin/winshadddnl.c xorg-server/hw/xwin/winshadgdi.c xorg-server/hw/xwin/wintrayicon.c xorg-server/hw/xwin/winwin32rootless.c xorg-server/hw/xwin/winwin32rootlesswindow.c xorg-server/hw/xwin/winwin32rootlesswndproc.c xorg-server/hw/xwin/winwindow.c xorg-server/hw/xwin/winwindow.h xorg-server/hw/xwin/winwindowswm.c xorg-server/hw/xwin/winwndproc.c xorg-server/include/callback.h xorg-server/include/dixstruct.h xorg-server/include/misc.h xorg-server/include/os.h xorg-server/include/scrnintstr.h xorg-server/mi/micmap.c xorg-server/mi/miinitext.c xorg-server/mi/mioverlay.c xorg-server/mi/misprite.c xorg-server/mi/mivaltree.c xorg-server/mi/miwindow.c xorg-server/miext/damage/damage.c xorg-server/miext/rootless/rootlessGC.c xorg-server/miext/rootless/rootlessWindow.c xorg-server/os/WaitFor.c xorg-server/os/access.c xorg-server/os/connection.c xorg-server/os/io.c xorg-server/os/log.c xorg-server/os/osinit.c xorg-server/os/utils.c xorg-server/os/xdmcp.c xorg-server/os/xprintf.c xorg-server/os/xstrans.c xorg-server/render/mipict.c xorg-server/xkb/xkbActions.c xorg-server/xkb/xkbInit.c xorg-server/xkeyboard-config/compat/default.in
Diffstat (limited to 'xorg-server/os/utils.c')
-rw-r--r--xorg-server/os/utils.c1671
1 files changed, 819 insertions, 852 deletions
diff --git a/xorg-server/os/utils.c b/xorg-server/os/utils.c
index d7e88c708..dbed76132 100644
--- a/xorg-server/os/utils.c
+++ b/xorg-server/os/utils.c
@@ -24,7 +24,6 @@ not be used in advertising or otherwise to promote the sale, use or
other dealings in this Software without prior written authorization
from The Open Group.
-
Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts,
Copyright 1994 Quarterdeck Office Systems.
@@ -99,19 +98,19 @@ __stdcall unsigned long GetTickCount(void);
#ifndef WIN32
#include <sys/wait.h>
#endif
-#if !defined(SYSV) && !defined(WIN32)
+#if !defined(SYSV) && !defined(WIN32)
#include <sys/resource.h>
#endif
#include <sys/stat.h>
-#include <ctype.h> /* for isspace */
+#include <ctype.h> /* for isspace */
#include <stdarg.h>
-#include <stdlib.h> /* for malloc() */
+#include <stdlib.h> /* for malloc() */
#if defined(TCPCONN) || defined(STREAMSCONN)
-# ifndef WIN32
-# include <netdb.h>
-# endif
+#ifndef WIN32
+#include <netdb.h>
+#endif
#endif
#include "opaque.h"
@@ -123,6 +122,7 @@ __stdcall unsigned long GetTickCount(void);
#include "picture.h"
Bool noTestExtensions;
+
#ifdef COMPOSITE
Bool noCompositeExtension = FALSE;
#endif
@@ -150,6 +150,7 @@ Bool noMITShmExtension = FALSE;
Bool noRRExtension = FALSE;
#endif
Bool noRenderExtension = FALSE;
+
#ifdef XCSECURITY
Bool noSecurityExtension = FALSE;
#endif
@@ -222,11 +223,11 @@ OsSignal(int sig, OsSigHandlerPtr handler)
sigemptyset(&act.sa_mask);
if (handler != SIG_IGN)
- sigaddset(&act.sa_mask, sig);
+ sigaddset(&act.sa_mask, sig);
act.sa_flags = 0;
act.sa_handler = handler;
if (sigaction(sig, &act, &oact))
- perror("sigaction");
+ perror("sigaction");
return oact.sa_handler;
#endif
}
@@ -267,121 +268,123 @@ LockServer(void)
FatalError("Server is already active for display %d\n", atoi(display));
}
#else
- char tmp[PATH_MAX], pid_str[12];
- int lfd, i, haslock, l_pid, t;
- const char *tmppath = LOCK_DIR;
- int len;
- char port[20];
-
- if (nolock) return;
- /*
- * Path names
- */
- snprintf(port, sizeof(port), "%d", atoi(display));
- len = strlen(LOCK_PREFIX) > strlen(LOCK_TMP_PREFIX) ? strlen(LOCK_PREFIX) :
- strlen(LOCK_TMP_PREFIX);
- len += strlen(tmppath) + strlen(port) + strlen(LOCK_SUFFIX) + 1;
- if (len > sizeof(LockFile))
- FatalError("Display name `%s' is too long\n", port);
- (void)sprintf(tmp, "%s" LOCK_TMP_PREFIX "%s" LOCK_SUFFIX, tmppath, port);
- (void)sprintf(LockFile, "%s" LOCK_PREFIX "%s" LOCK_SUFFIX, tmppath, port);
-
- /*
- * Create a temporary file containing our PID. Attempt three times
- * to create the file.
- */
- StillLocking = TRUE;
- i = 0;
- do {
- i++;
- lfd = open(tmp, O_CREAT | O_EXCL | O_WRONLY, 0644);
- if (lfd < 0)
- sleep(2);
- else
- break;
- } while (i < 3);
- if (lfd < 0) {
- unlink(tmp);
+ char tmp[PATH_MAX], pid_str[12];
+ int lfd, i, haslock, l_pid, t;
+ const char *tmppath = LOCK_DIR;
+ int len;
+ char port[20];
+
+ if (nolock)
+ return;
+ /*
+ * Path names
+ */
+ snprintf(port, sizeof(port), "%d", atoi(display));
+ len = strlen(LOCK_PREFIX) > strlen(LOCK_TMP_PREFIX) ? strlen(LOCK_PREFIX) :
+ strlen(LOCK_TMP_PREFIX);
+ len += strlen(tmppath) + strlen(port) + strlen(LOCK_SUFFIX) + 1;
+ if (len > sizeof(LockFile))
+ FatalError("Display name `%s' is too long\n", port);
+ (void) sprintf(tmp, "%s" LOCK_TMP_PREFIX "%s" LOCK_SUFFIX, tmppath, port);
+ (void) sprintf(LockFile, "%s" LOCK_PREFIX "%s" LOCK_SUFFIX, tmppath, port);
+
+ /*
+ * Create a temporary file containing our PID. Attempt three times
+ * to create the file.
+ */
+ StillLocking = TRUE;
i = 0;
do {
- i++;
- lfd = open(tmp, O_CREAT | O_EXCL | O_WRONLY, 0644);
- if (lfd < 0)
- sleep(2);
- else
- break;
+ i++;
+ lfd = open(tmp, O_CREAT | O_EXCL | O_WRONLY, 0644);
+ if (lfd < 0)
+ sleep(2);
+ else
+ break;
} while (i < 3);
- }
- if (lfd < 0)
- FatalError("Could not create lock file in %s\n", tmp);
- snprintf(pid_str, sizeof(pid_str), "%10ld\n", (long)getpid());
- (void) write(lfd, pid_str, 11);
- (void) fchmod(lfd, 0444);
- (void) close(lfd);
-
- /*
- * OK. Now the tmp file exists. Try three times to move it in place
- * for the lock.
- */
- i = 0;
- haslock = 0;
- while ((!haslock) && (i++ < 3)) {
- haslock = (link(tmp,LockFile) == 0);
- if (haslock) {
- /*
- * We're done.
- */
- break;
- }
- else {
- /*
- * Read the pid from the existing file
- */
- lfd = open(LockFile, O_RDONLY|O_NOFOLLOW);
- if (lfd < 0) {
+ if (lfd < 0) {
unlink(tmp);
- FatalError("Can't read lock file %s\n", LockFile);
- }
- pid_str[0] = '\0';
- if (read(lfd, pid_str, 11) != 11) {
- /*
- * Bogus lock file.
- */
- unlink(LockFile);
- close(lfd);
- continue;
- }
- pid_str[11] = '\0';
- sscanf(pid_str, "%d", &l_pid);
- close(lfd);
-
- /*
- * Now try to kill the PID to see if it exists.
- */
- errno = 0;
- t = kill(l_pid, 0);
- if ((t< 0) && (errno == ESRCH)) {
- /*
- * Stale lock file.
- */
- unlink(LockFile);
- continue;
- }
- else if (((t < 0) && (errno == EPERM)) || (t == 0)) {
- /*
- * Process is still active.
- */
- unlink(tmp);
- FatalError("Server is already active for display %s\n%s %s\n%s\n",
- port, "\tIf this server is no longer running, remove",
- LockFile, "\tand start again.");
- }
+ i = 0;
+ do {
+ i++;
+ lfd = open(tmp, O_CREAT | O_EXCL | O_WRONLY, 0644);
+ if (lfd < 0)
+ sleep(2);
+ else
+ break;
+ } while (i < 3);
}
- }
- unlink(tmp);
- if (!haslock)
- FatalError("Could not create server lock file: %s\n", LockFile);
- StillLocking = FALSE;
+ if (lfd < 0)
+ FatalError("Could not create lock file in %s\n", tmp);
+ snprintf(pid_str, sizeof(pid_str), "%10ld\n", (long) getpid());
+ (void) write(lfd, pid_str, 11);
+ (void) fchmod(lfd, 0444);
+ (void) close(lfd);
+
+ /*
+ * OK. Now the tmp file exists. Try three times to move it in place
+ * for the lock.
+ */
+ i = 0;
+ haslock = 0;
+ while ((!haslock) && (i++ < 3)) {
+ haslock = (link(tmp, LockFile) == 0);
+ if (haslock) {
+ /*
+ * We're done.
+ */
+ break;
+ }
+ else {
+ /*
+ * Read the pid from the existing file
+ */
+ lfd = open(LockFile, O_RDONLY | O_NOFOLLOW);
+ if (lfd < 0) {
+ unlink(tmp);
+ FatalError("Can't read lock file %s\n", LockFile);
+ }
+ pid_str[0] = '\0';
+ if (read(lfd, pid_str, 11) != 11) {
+ /*
+ * Bogus lock file.
+ */
+ unlink(LockFile);
+ close(lfd);
+ continue;
+ }
+ pid_str[11] = '\0';
+ sscanf(pid_str, "%d", &l_pid);
+ close(lfd);
+
+ /*
+ * Now try to kill the PID to see if it exists.
+ */
+ errno = 0;
+ t = kill(l_pid, 0);
+ if ((t < 0) && (errno == ESRCH)) {
+ /*
+ * Stale lock file.
+ */
+ unlink(LockFile);
+ continue;
+ }
+ else if (((t < 0) && (errno == EPERM)) || (t == 0)) {
+ /*
+ * Process is still active.
+ */
+ unlink(tmp);
+ FatalError
+ ("Server is already active for display %s\n%s %s\n%s\n",
+ port, "\tIf this server is no longer running, remove",
+ LockFile, "\tand start again.");
+ }
+ }
+ }
+ unlink(tmp);
+ if (!haslock)
+ FatalError("Could not create server lock file: %s\n", LockFile);
+ StillLocking = FALSE;
#endif
}
@@ -392,18 +395,19 @@ LockServer(void)
void
UnlockServer(void)
{
- if (nolock) return;
+ if (nolock)
+ return;
- if (!StillLocking){
+ if (!StillLocking) {
- (void) unlink(LockFile);
- }
+ (void) unlink(LockFile);
+ }
}
/* Force connections to close on SIGHUP from init */
void
-AutoResetServer (int sig)
+AutoResetServer(int sig)
{
int olderrno = errno;
@@ -426,9 +430,9 @@ GiveUp(int sig)
#if (defined WIN32 && defined __MINGW32__) || defined(__CYGWIN__)
CARD32
-GetTimeInMillis (void)
+GetTimeInMillis(void)
{
- return GetTickCount ();
+ return GetTickCount();
}
#else
CARD32
@@ -439,6 +443,7 @@ GetTimeInMillis(void)
#ifdef MONOTONIC_CLOCK
struct timespec tp;
static clockid_t clockid;
+
if (!clockid) {
#ifdef CLOCK_MONOTONIC_COARSE
if (clock_getres(CLOCK_MONOTONIC_COARSE, &tp) == 0 &&
@@ -457,35 +462,33 @@ GetTimeInMillis(void)
#endif
X_GETTIMEOFDAY(&tv);
- return(tv.tv_sec * 1000) + (tv.tv_usec / 1000);
+ return (tv.tv_sec * 1000) + (tv.tv_usec / 1000);
}
#endif
void
-AdjustWaitForDelay (pointer waitTime, unsigned long newdelay)
+AdjustWaitForDelay(pointer waitTime, unsigned long newdelay)
{
- static struct timeval delay_val;
- struct timeval **wt = (struct timeval **) waitTime;
- unsigned long olddelay;
-
- if (*wt == NULL)
- {
- delay_val.tv_sec = newdelay / 1000;
- delay_val.tv_usec = 1000 * (newdelay % 1000);
- *wt = &delay_val;
+ static struct timeval delay_val;
+ struct timeval **wt = (struct timeval **) waitTime;
+ unsigned long olddelay;
+
+ if (*wt == NULL) {
+ delay_val.tv_sec = newdelay / 1000;
+ delay_val.tv_usec = 1000 * (newdelay % 1000);
+ *wt = &delay_val;
}
- else
- {
- olddelay = (*wt)->tv_sec * 1000 + (*wt)->tv_usec / 1000;
- if (newdelay < olddelay)
- {
- (*wt)->tv_sec = newdelay / 1000;
- (*wt)->tv_usec = 1000 * (newdelay % 1000);
- }
+ else {
+ olddelay = (*wt)->tv_sec * 1000 + (*wt)->tv_usec / 1000;
+ if (newdelay < olddelay) {
+ (*wt)->tv_sec = newdelay / 1000;
+ (*wt)->tv_usec = 1000 * (newdelay % 1000);
+ }
}
}
-void UseMsg(void)
+void
+UseMsg(void)
{
ErrorF("Usage...\nVcxsrv [:<display>] [option]\n\n");
ErrorF(":display-number\n\tVcxsrv runs as the given display-number, which defaults to 0.\n");
@@ -493,8 +496,8 @@ void UseMsg(void)
ErrorF("-a # default pointer acceleration (factor)\n");
ErrorF("-ac disable access control restrictions\n");
- ErrorF("-audit int set audit trail level\n");
- ErrorF("-auth file select authorization file\n");
+ ErrorF("-audit int set audit trail level\n");
+ ErrorF("-auth file select authorization file\n");
ErrorF("-br create root window with black background\n");
ErrorF("+bs enable any backing store support\n");
ErrorF("-bs disable any backing store support\n");
@@ -509,7 +512,8 @@ void UseMsg(void)
#ifdef DPMSExtension
ErrorF("-dpms disables VESA DPMS monitor control\n");
#endif
- ErrorF("-deferglyphs [none|all|16] defer loading of [no|all|16-bit] glyphs\n");
+ ErrorF
+ ("-deferglyphs [none|all|16] defer loading of [no|all|16-bit] glyphs\n");
ErrorF("-f # bell base (0-100)\n");
ErrorF("-fc string cursor font\n");
ErrorF("-fn string default font name\n");
@@ -547,7 +551,8 @@ void UseMsg(void)
ErrorF("+xinerama Enable XINERAMA extension\n");
ErrorF("-xinerama Disable XINERAMA extension\n");
#endif
- ErrorF("-dumbSched Disable smart scheduling, enable old behavior\n");
+ ErrorF
+ ("-dumbSched Disable smart scheduling, enable old behavior\n");
ErrorF("-schedInterval int Set scheduler interval in msec\n");
ErrorF("+extension name Enable extension\n");
ErrorF("-extension name Disable extension\n");
@@ -565,14 +570,19 @@ void UseMsg(void)
* not contain a "/" and not start with a "-".
* --kvajk
*/
-static int
+static int
VerifyDisplayName(const char *d)
{
- if ( d == (char *)0 ) return 0; /* null */
- if ( *d == '\0' ) return 0; /* empty */
- if ( *d == '-' ) return 0; /* could be confused for an option */
- if ( *d == '.' ) return 0; /* must not equal "." or ".." */
- if ( strchr(d, '/') != (char *)0 ) return 0; /* very important!!! */
+ if (d == (char *) 0)
+ return 0; /* null */
+ if (*d == '\0')
+ return 0; /* empty */
+ if (*d == '-')
+ return 0; /* could be confused for an option */
+ if (*d == '.')
+ return 0; /* must not equal "." or ".." */
+ if (strchr(d, '/') != (char *) 0)
+ return 0; /* very important!!! */
return 1;
}
@@ -594,388 +604,340 @@ ProcessCommandLine(int argc, char *argv[])
PartialNetwork = TRUE;
#endif
- for ( i = 1; i < argc; i++ )
- {
- /* call ddx first, so it can peek/override if it wants */
- if((skip = ddxProcessArgument(argc, argv, i)))
- {
- i += (skip - 1);
- }
- else if(argv[i][0] == ':')
- {
- /* initialize display */
- display = argv[i];
- display++;
- if( ! VerifyDisplayName( display ) ) {
+ for (i = 1; i < argc; i++) {
+ /* call ddx first, so it can peek/override if it wants */
+ if ((skip = ddxProcessArgument(argc, argv, i))) {
+ i += (skip - 1);
+ }
+ else if (argv[i][0] == ':') {
+ /* initialize display */
+ display = argv[i];
+ display++;
+ if (!VerifyDisplayName(display)) {
ErrorF("Bad display name: %s\n", display);
UseMsg();
- FatalError("Bad display name, exiting: %s\n", display);
+ FatalError("Bad display name, exiting: %s\n", display);
}
- }
- else if ( strcmp( argv[i], "-a") == 0)
- {
- if(++i < argc)
- defaultPointerControl.num = atoi(argv[i]);
- else
- UseMsg();
- }
- else if ( strcmp( argv[i], "-ac") == 0)
- {
- defeatAccessControl = TRUE;
- }
- else if ( strcmp( argv[i], "-audit") == 0)
- {
- if(++i < argc)
- auditTrailLevel = atoi(argv[i]);
- else
- UseMsg();
- }
- else if ( strcmp( argv[i], "-auth") == 0)
- {
- if(++i < argc)
- InitAuthorization (argv[i]);
- else
- UseMsg();
- }
- else if ( strcmp( argv[i], "-br") == 0) ; /* default */
- else if ( strcmp( argv[i], "+bs") == 0)
- enableBackingStore = TRUE;
- else if ( strcmp( argv[i], "-bs") == 0)
- disableBackingStore = TRUE;
- else if ( strcmp( argv[i], "-cc") == 0)
- {
- if(++i < argc)
- defaultColorVisualClass = atoi(argv[i]);
- else
- UseMsg();
- }
- else if ( strcmp( argv[i], "-core") == 0)
- {
+ }
+ else if (strcmp(argv[i], "-a") == 0) {
+ if (++i < argc)
+ defaultPointerControl.num = atoi(argv[i]);
+ else
+ UseMsg();
+ }
+ else if (strcmp(argv[i], "-ac") == 0) {
+ defeatAccessControl = TRUE;
+ }
+ else if (strcmp(argv[i], "-audit") == 0) {
+ if (++i < argc)
+ auditTrailLevel = atoi(argv[i]);
+ else
+ UseMsg();
+ }
+ else if (strcmp(argv[i], "-auth") == 0) {
+ if (++i < argc)
+ InitAuthorization(argv[i]);
+ else
+ UseMsg();
+ }
+ else if (strcmp(argv[i], "-br") == 0); /* default */
+ else if (strcmp(argv[i], "+bs") == 0)
+ enableBackingStore = TRUE;
+ else if (strcmp(argv[i], "-bs") == 0)
+ disableBackingStore = TRUE;
+ else if (strcmp(argv[i], "-cc") == 0) {
+ if (++i < argc)
+ defaultColorVisualClass = atoi(argv[i]);
+ else
+ UseMsg();
+ }
+ else if (strcmp(argv[i], "-core") == 0) {
#if !defined(WIN32) || !defined(__MINGW32__)
- struct rlimit core_limit;
- getrlimit (RLIMIT_CORE, &core_limit);
- core_limit.rlim_cur = core_limit.rlim_max;
- setrlimit (RLIMIT_CORE, &core_limit);
-#endif
- CoreDump = TRUE;
- }
- else if ( strcmp( argv[i], "-nocursor") == 0)
- {
+ struct rlimit core_limit;
+
+ getrlimit(RLIMIT_CORE, &core_limit);
+ core_limit.rlim_cur = core_limit.rlim_max;
+ setrlimit(RLIMIT_CORE, &core_limit);
+#endif
+ CoreDump = TRUE;
+ }
+ else if (strcmp(argv[i], "-nocursor") == 0) {
EnableCursor = FALSE;
}
- else if ( strcmp( argv[i], "-dpi") == 0)
- {
- if(++i < argc)
+ else if (strcmp(argv[i], "-dpi") == 0) {
+ if (++i < argc)
#ifdef _MSC_VER
- {
- if (strcmp(argv[i], "auto") == 0)
- {
- HDC hdc = GetDC(NULL);
- if (hdc)
- {
- int dpiY = GetDeviceCaps(hdc, LOGPIXELSY);
- monitorResolution = dpiY;
- ReleaseDC(NULL, hdc);
- }
- }
- else if (isdigit(*argv[i])) /* Naively prevent a crash if not numeric */
- monitorResolution = atoi(argv[i]);
- }
+ {
+ if (strcmp(argv[i], "auto") == 0)
+ {
+ HDC hdc = GetDC(NULL);
+ if (hdc)
+ {
+ int dpiY = GetDeviceCaps(hdc, LOGPIXELSY);
+ monitorResolution = dpiY;
+ ReleaseDC(NULL, hdc);
+ }
+ }
+ else if (isdigit(*argv[i])) /* Naively prevent a crash if not numeric */
+ monitorResolution = atoi(argv[i]);
+ }
#else
- monitorResolution = atoi(argv[i]);
+ monitorResolution = atoi(argv[i]);
#endif
- else
- UseMsg();
- }
+ else
+ UseMsg();
+ }
#ifdef DPMSExtension
- else if ( strcmp( argv[i], "dpms") == 0)
- /* ignored for compatibility */ ;
- else if ( strcmp( argv[i], "-dpms") == 0)
- DPMSDisabledSwitch = TRUE;
-#endif
- else if ( strcmp( argv[i], "-deferglyphs") == 0)
- {
- if(++i >= argc || !ParseGlyphCachingMode(argv[i]))
- UseMsg();
- }
- else if ( strcmp( argv[i], "-f") == 0)
- {
- if(++i < argc)
- defaultKeyboardControl.bell = atoi(argv[i]);
- else
- UseMsg();
- }
- else if ( strcmp( argv[i], "-fc") == 0)
- {
- if(++i < argc)
- defaultCursorFont = argv[i];
- else
- UseMsg();
- }
- else if ( strcmp( argv[i], "-fn") == 0)
- {
- if(++i < argc)
- defaultTextFont = argv[i];
- else
- UseMsg();
- }
- else if ( strcmp( argv[i], "-fp") == 0)
- {
- if(++i < argc)
- {
- defaultFontPath = argv[i];
- }
- else
- UseMsg();
- }
- else if ( strcmp( argv[i], "-help") == 0)
- {
- UseMsg();
- exit(0);
- }
- else if ( (skip=XkbProcessArguments(argc,argv,i))!=0 ) {
- if (skip>0)
- i+= skip-1;
- else UseMsg();
- }
+ else if (strcmp(argv[i], "dpms") == 0)
+ /* ignored for compatibility */ ;
+ else if (strcmp(argv[i], "-dpms") == 0)
+ DPMSDisabledSwitch = TRUE;
+#endif
+ else if (strcmp(argv[i], "-deferglyphs") == 0) {
+ if (++i >= argc || !ParseGlyphCachingMode(argv[i]))
+ UseMsg();
+ }
+ else if (strcmp(argv[i], "-f") == 0) {
+ if (++i < argc)
+ defaultKeyboardControl.bell = atoi(argv[i]);
+ else
+ UseMsg();
+ }
+ else if (strcmp(argv[i], "-fc") == 0) {
+ if (++i < argc)
+ defaultCursorFont = argv[i];
+ else
+ UseMsg();
+ }
+ else if (strcmp(argv[i], "-fn") == 0) {
+ if (++i < argc)
+ defaultTextFont = argv[i];
+ else
+ UseMsg();
+ }
+ else if (strcmp(argv[i], "-fp") == 0) {
+ if (++i < argc) {
+ defaultFontPath = argv[i];
+ }
+ else
+ UseMsg();
+ }
+ else if (strcmp(argv[i], "-help") == 0) {
+ UseMsg();
+ exit(0);
+ }
+ else if ((skip = XkbProcessArguments(argc, argv, i)) != 0) {
+ if (skip > 0)
+ i += skip - 1;
+ else
+ UseMsg();
+ }
#ifdef RLIMIT_DATA
- else if ( strcmp( argv[i], "-ld") == 0)
- {
- if(++i < argc)
- {
- limitDataSpace = atoi(argv[i]);
- if (limitDataSpace > 0)
- limitDataSpace *= 1024;
- }
- else
- UseMsg();
- }
+ else if (strcmp(argv[i], "-ld") == 0) {
+ if (++i < argc) {
+ limitDataSpace = atoi(argv[i]);
+ if (limitDataSpace > 0)
+ limitDataSpace *= 1024;
+ }
+ else
+ UseMsg();
+ }
#endif
#ifdef RLIMIT_NOFILE
- else if ( strcmp( argv[i], "-lf") == 0)
- {
- if(++i < argc)
- limitNoFile = atoi(argv[i]);
- else
- UseMsg();
- }
+ else if (strcmp(argv[i], "-lf") == 0) {
+ if (++i < argc)
+ limitNoFile = atoi(argv[i]);
+ else
+ UseMsg();
+ }
#endif
#ifdef RLIMIT_STACK
- else if ( strcmp( argv[i], "-ls") == 0)
- {
- if(++i < argc)
- {
- limitStackSpace = atoi(argv[i]);
- if (limitStackSpace > 0)
- limitStackSpace *= 1024;
- }
- else
- UseMsg();
- }
-#endif
- else if ( strcmp ( argv[i], "-nolock") == 0)
- {
+ else if (strcmp(argv[i], "-ls") == 0) {
+ if (++i < argc) {
+ limitStackSpace = atoi(argv[i]);
+ if (limitStackSpace > 0)
+ limitStackSpace *= 1024;
+ }
+ else
+ UseMsg();
+ }
+#endif
+ else if (strcmp(argv[i], "-nolock") == 0) {
#if !defined(WIN32) && !defined(__CYGWIN__)
- if (getuid() != 0)
- ErrorF("Warning: the -nolock option can only be used by root\n");
- else
-#endif
- nolock = TRUE;
- }
- else if ( strcmp( argv[i], "-nolisten") == 0)
- {
- if(++i < argc) {
- if (_XSERVTransNoListen(argv[i]))
- FatalError ("Failed to disable listen for %s transport",
- argv[i]);
- } else
- UseMsg();
- }
- else if ( strcmp( argv[i], "-noreset") == 0)
- {
- dispatchExceptionAtReset = 0;
- }
- else if ( strcmp( argv[i], "-reset") == 0)
- {
- dispatchExceptionAtReset = DE_RESET;
- }
- else if ( strcmp( argv[i], "-p") == 0)
- {
- if(++i < argc)
- defaultScreenSaverInterval = ((CARD32)atoi(argv[i])) *
- MILLI_PER_MIN;
- else
- UseMsg();
- }
- else if (strcmp(argv[i], "-pogo") == 0)
- {
- dispatchException = DE_TERMINATE;
- }
- else if ( strcmp( argv[i], "-pn") == 0)
- PartialNetwork = TRUE;
- else if ( strcmp( argv[i], "-nopn") == 0)
- PartialNetwork = FALSE;
- else if ( strcmp( argv[i], "r") == 0)
- defaultKeyboardControl.autoRepeat = TRUE;
- else if ( strcmp( argv[i], "-r") == 0)
- defaultKeyboardControl.autoRepeat = FALSE;
- else if ( strcmp( argv[i], "-retro") == 0)
- party_like_its_1989 = TRUE;
- else if ( strcmp( argv[i], "-s") == 0)
- {
- if(++i < argc)
- defaultScreenSaverTime = ((CARD32)atoi(argv[i])) *
- MILLI_PER_MIN;
- else
- UseMsg();
- }
- else if ( strcmp( argv[i], "-seat") == 0)
- {
- if(++i < argc)
- SeatId = argv[i];
- else
- UseMsg();
- }
- else if ( strcmp( argv[i], "-t") == 0)
- {
- if(++i < argc)
- defaultPointerControl.threshold = atoi(argv[i]);
- else
- UseMsg();
- }
- else if ( strcmp( argv[i], "-terminate") == 0)
- {
- dispatchExceptionAtReset = DE_TERMINATE;
- }
- else if ( strcmp( argv[i], "-to") == 0)
- {
- if(++i < argc)
- TimeOutValue = ((CARD32)atoi(argv[i])) * MILLI_PER_SECOND;
- else
- UseMsg();
- }
- else if ( strcmp( argv[i], "-tst") == 0)
- {
- noTestExtensions = TRUE;
- }
- else if ( strcmp( argv[i], "-wm") == 0)
- defaultBackingStore = WhenMapped;
- else if ( strcmp( argv[i], "-wr") == 0)
+ if (getuid() != 0)
+ ErrorF
+ ("Warning: the -nolock option can only be used by root\n");
+ else
+#endif
+ nolock = TRUE;
+ }
+ else if (strcmp(argv[i], "-nolisten") == 0) {
+ if (++i < argc) {
+ if (_XSERVTransNoListen(argv[i]))
+ FatalError("Failed to disable listen for %s transport",
+ argv[i]);
+ }
+ else
+ UseMsg();
+ }
+ else if (strcmp(argv[i], "-noreset") == 0) {
+ dispatchExceptionAtReset = 0;
+ }
+ else if (strcmp(argv[i], "-reset") == 0) {
+ dispatchExceptionAtReset = DE_RESET;
+ }
+ else if (strcmp(argv[i], "-p") == 0) {
+ if (++i < argc)
+ defaultScreenSaverInterval = ((CARD32) atoi(argv[i])) *
+ MILLI_PER_MIN;
+ else
+ UseMsg();
+ }
+ else if (strcmp(argv[i], "-pogo") == 0) {
+ dispatchException = DE_TERMINATE;
+ }
+ else if (strcmp(argv[i], "-pn") == 0)
+ PartialNetwork = TRUE;
+ else if (strcmp(argv[i], "-nopn") == 0)
+ PartialNetwork = FALSE;
+ else if (strcmp(argv[i], "r") == 0)
+ defaultKeyboardControl.autoRepeat = TRUE;
+ else if (strcmp(argv[i], "-r") == 0)
+ defaultKeyboardControl.autoRepeat = FALSE;
+ else if (strcmp(argv[i], "-retro") == 0)
+ party_like_its_1989 = TRUE;
+ else if (strcmp(argv[i], "-s") == 0) {
+ if (++i < argc)
+ defaultScreenSaverTime = ((CARD32) atoi(argv[i])) *
+ MILLI_PER_MIN;
+ else
+ UseMsg();
+ }
+ else if (strcmp(argv[i], "-seat") == 0) {
+ if (++i < argc)
+ SeatId = argv[i];
+ else
+ UseMsg();
+ }
+ else if (strcmp(argv[i], "-t") == 0) {
+ if (++i < argc)
+ defaultPointerControl.threshold = atoi(argv[i]);
+ else
+ UseMsg();
+ }
+ else if (strcmp(argv[i], "-terminate") == 0) {
+ dispatchExceptionAtReset = DE_TERMINATE;
+ }
+ else if (strcmp(argv[i], "-to") == 0) {
+ if (++i < argc)
+ TimeOutValue = ((CARD32) atoi(argv[i])) * MILLI_PER_SECOND;
+ else
+ UseMsg();
+ }
+ else if (strcmp(argv[i], "-tst") == 0) {
+ noTestExtensions = TRUE;
+ }
+ else if (strcmp(argv[i], "-wm") == 0)
+ defaultBackingStore = WhenMapped;
+ else if (strcmp(argv[i], "-wr") == 0)
whiteRoot = TRUE;
- else if ( strcmp( argv[i], "-background") == 0) {
- if(++i < argc) {
- if (!strcmp ( argv[i], "none"))
+ else if (strcmp(argv[i], "-background") == 0) {
+ if (++i < argc) {
+ if (!strcmp(argv[i], "none"))
bgNoneRoot = TRUE;
else
UseMsg();
}
}
- else if ( strcmp( argv[i], "-maxbigreqsize") == 0) {
- if(++i < argc) {
- long reqSizeArg = atol(argv[i]);
-
- /* Request size > 128MB does not make much sense... */
- if( reqSizeArg > 0L && reqSizeArg < 128L ) {
- maxBigRequestSize = (reqSizeArg * 1048576L) - 1L;
- }
- else
- {
- UseMsg();
- }
- }
- else
- {
- UseMsg();
- }
- }
+ else if (strcmp(argv[i], "-maxbigreqsize") == 0) {
+ if (++i < argc) {
+ long reqSizeArg = atol(argv[i]);
+
+ /* Request size > 128MB does not make much sense... */
+ if (reqSizeArg > 0L && reqSizeArg < 128L) {
+ maxBigRequestSize = (reqSizeArg * 1048576L) - 1L;
+ }
+ else {
+ UseMsg();
+ }
+ }
+ else {
+ UseMsg();
+ }
+ }
#ifdef PANORAMIX
- else if ( strcmp( argv[i], "+xinerama") == 0){
- noPanoramiXExtension = FALSE;
- }
- else if ( strcmp( argv[i], "-xinerama") == 0){
- noPanoramiXExtension = TRUE;
- }
- else if ( strcmp( argv[i], "-disablexineramaextension") == 0){
- PanoramiXExtensionDisabledHack = TRUE;
- }
-#endif
- else if ( strcmp( argv[i], "-I") == 0)
- {
- /* ignore all remaining arguments */
- break;
- }
- else if (strncmp (argv[i], "tty", 3) == 0)
- {
+ else if (strcmp(argv[i], "+xinerama") == 0) {
+ noPanoramiXExtension = FALSE;
+ }
+ else if (strcmp(argv[i], "-xinerama") == 0) {
+ noPanoramiXExtension = TRUE;
+ }
+ else if (strcmp(argv[i], "-disablexineramaextension") == 0) {
+ PanoramiXExtensionDisabledHack = TRUE;
+ }
+#endif
+ else if (strcmp(argv[i], "-I") == 0) {
+ /* ignore all remaining arguments */
+ break;
+ }
+ else if (strncmp(argv[i], "tty", 3) == 0) {
/* init supplies us with this useless information */
- }
+ }
#ifdef XDMCP
- else if ((skip = XdmcpOptions(argc, argv, i)) != i)
- {
- i = skip - 1;
- }
-#endif
- else if ( strcmp( argv[i], "-dumbSched") == 0)
- {
- SmartScheduleDisable = TRUE;
- }
- else if ( strcmp( argv[i], "-schedInterval") == 0)
- {
- if (++i < argc)
- {
- SmartScheduleInterval = atoi(argv[i]);
- SmartScheduleSlice = SmartScheduleInterval;
- }
- else
- UseMsg();
- }
- else if ( strcmp( argv[i], "-schedMax") == 0)
- {
- if (++i < argc)
- {
- SmartScheduleMaxSlice = atoi(argv[i]);
- }
- else
- UseMsg();
- }
- else if ( strcmp( argv[i], "-render" ) == 0)
- {
- if (++i < argc)
- {
- int policy = PictureParseCmapPolicy (argv[i]);
-
- if (policy != PictureCmapPolicyInvalid)
- PictureCmapPolicy = policy;
- else
- UseMsg ();
- }
- else
- UseMsg ();
- }
- else if ( strcmp( argv[i], "+extension") == 0)
- {
- if (++i < argc)
- {
- if (!EnableDisableExtension(argv[i], TRUE))
- EnableDisableExtensionError(argv[i], TRUE);
- }
- else
- UseMsg();
- }
- else if ( strcmp( argv[i], "-extension") == 0)
- {
- if (++i < argc)
- {
- if (!EnableDisableExtension(argv[i], FALSE))
- EnableDisableExtensionError(argv[i], FALSE);
- }
- else
- UseMsg();
- }
- else
- {
- ErrorF("Unrecognized option: %s\n", argv[i]);
- UseMsg();
- FatalError("Unrecognized option: %s\n", argv[i]);
+ else if ((skip = XdmcpOptions(argc, argv, i)) != i) {
+ i = skip - 1;
+ }
+#endif
+ else if (strcmp(argv[i], "-dumbSched") == 0) {
+ SmartScheduleDisable = TRUE;
+ }
+ else if (strcmp(argv[i], "-schedInterval") == 0) {
+ if (++i < argc) {
+ SmartScheduleInterval = atoi(argv[i]);
+ SmartScheduleSlice = SmartScheduleInterval;
+ }
+ else
+ UseMsg();
+ }
+ else if (strcmp(argv[i], "-schedMax") == 0) {
+ if (++i < argc) {
+ SmartScheduleMaxSlice = atoi(argv[i]);
+ }
+ else
+ UseMsg();
+ }
+ else if (strcmp(argv[i], "-render") == 0) {
+ if (++i < argc) {
+ int policy = PictureParseCmapPolicy(argv[i]);
+
+ if (policy != PictureCmapPolicyInvalid)
+ PictureCmapPolicy = policy;
+ else
+ UseMsg();
+ }
+ else
+ UseMsg();
+ }
+ else if (strcmp(argv[i], "+extension") == 0) {
+ if (++i < argc) {
+ if (!EnableDisableExtension(argv[i], TRUE))
+ EnableDisableExtensionError(argv[i], TRUE);
+ }
+ else
+ UseMsg();
+ }
+ else if (strcmp(argv[i], "-extension") == 0) {
+ if (++i < argc) {
+ if (!EnableDisableExtension(argv[i], FALSE))
+ EnableDisableExtensionError(argv[i], FALSE);
+ }
+ else
+ UseMsg();
+ }
+ else {
+ ErrorF("Unrecognized option: %s\n", argv[i]);
+ UseMsg();
+ FatalError("Unrecognized option: %s\n", argv[i]);
}
}
}
@@ -990,61 +952,63 @@ set_font_authorizations(char **authorizations, int *authlen, pointer client)
static char *result = NULL;
static char *p = NULL;
- if (p == NULL)
- {
- char hname[1024], *hnameptr;
- unsigned int len;
+ if (p == NULL) {
+ char hname[1024], *hnameptr;
+ unsigned int len;
+
#if defined(IPv6) && defined(AF_INET6)
- struct addrinfo hints, *ai = NULL;
+ struct addrinfo hints, *ai = NULL;
#else
- struct hostent *host;
+ struct hostent *host;
+
#ifdef XTHREADS_NEEDS_BYNAMEPARAMS
- _Xgethostbynameparams hparams;
+ _Xgethostbynameparams hparams;
#endif
#endif
- gethostname(hname, 1024);
+ gethostname(hname, 1024);
#if defined(IPv6) && defined(AF_INET6)
- memset(&hints, 0, sizeof(hints));
- hints.ai_flags = AI_CANONNAME;
- if (getaddrinfo(hname, NULL, &hints, &ai) == 0) {
- hnameptr = ai->ai_canonname;
- } else {
- hnameptr = hname;
- }
+ memset(&hints, 0, sizeof(hints));
+ hints.ai_flags = AI_CANONNAME;
+ if (getaddrinfo(hname, NULL, &hints, &ai) == 0) {
+ hnameptr = ai->ai_canonname;
+ }
+ else {
+ hnameptr = hname;
+ }
#else
- host = _XGethostbyname(hname, hparams);
- if (host == NULL)
- hnameptr = hname;
- else
- hnameptr = host->h_name;
+ host = _XGethostbyname(hname, hparams);
+ if (host == NULL)
+ hnameptr = hname;
+ else
+ hnameptr = host->h_name;
#endif
- len = strlen(hnameptr) + 1;
- result = malloc(len + sizeof(AUTHORIZATION_NAME) + 4);
+ len = strlen(hnameptr) + 1;
+ result = malloc(len + sizeof(AUTHORIZATION_NAME) + 4);
- p = result;
+ p = result;
*p++ = sizeof(AUTHORIZATION_NAME) >> 8;
*p++ = sizeof(AUTHORIZATION_NAME) & 0xff;
*p++ = (len) >> 8;
*p++ = (len & 0xff);
- memmove(p, AUTHORIZATION_NAME, sizeof(AUTHORIZATION_NAME));
- p += sizeof(AUTHORIZATION_NAME);
- memmove(p, hnameptr, len);
- p += len;
+ memmove(p, AUTHORIZATION_NAME, sizeof(AUTHORIZATION_NAME));
+ p += sizeof(AUTHORIZATION_NAME);
+ memmove(p, hnameptr, len);
+ p += len;
#if defined(IPv6) && defined(AF_INET6)
- if (ai) {
- freeaddrinfo(ai);
- }
+ if (ai) {
+ freeaddrinfo(ai);
+ }
#endif
}
*authlen = p - result;
*authorizations = result;
return 1;
-#else /* TCPCONN */
+#else /* TCPCONN */
return 0;
-#endif /* TCPCONN */
+#endif /* TCPCONN */
}
void *
@@ -1057,9 +1021,9 @@ Xalloc(unsigned long amount)
*
* -- Mikhail Gusarov
*/
- if ((long)amount <= 0)
- ErrorF("Warning: Xalloc: "
- "requesting unpleasantly large amount of memory: %lu bytes.\n",
+ if ((long) amount <= 0)
+ ErrorF("Warning: Xalloc: "
+ "requesting unpleasantly large amount of memory: %lu bytes.\n",
amount);
return malloc(amount);
@@ -1069,6 +1033,7 @@ void *
XNFalloc(unsigned long amount)
{
void *ptr = malloc(amount);
+
if (!ptr)
FatalError("Out of memory");
return ptr;
@@ -1084,6 +1049,7 @@ void *
XNFcalloc(unsigned long amount)
{
void *ret = calloc(1, amount);
+
if (!ret)
FatalError("XNFcalloc: Out of memory");
return ret;
@@ -1099,9 +1065,9 @@ Xrealloc(void *ptr, unsigned long amount)
*
* -- Mikhail Gusarov
*/
- if ((long)amount <= 0)
- ErrorF("Warning: Xrealloc: "
- "requesting unpleasantly large amount of memory: %lu bytes.\n",
+ if ((long) amount <= 0)
+ ErrorF("Warning: Xrealloc: "
+ "requesting unpleasantly large amount of memory: %lu bytes.\n",
amount);
return realloc(ptr, amount);
@@ -1111,8 +1077,9 @@ void *
XNFrealloc(void *ptr, unsigned long amount)
{
void *ret = realloc(ptr, amount);
+
if (!ret)
- FatalError("XNFrealloc: Out of memory");
+ FatalError("XNFrealloc: Out of memory");
return ret;
}
@@ -1122,12 +1089,11 @@ Xfree(void *ptr)
free(ptr);
}
-
char *
Xstrdup(const char *s)
{
if (s == NULL)
- return NULL;
+ return NULL;
return strdup(s);
}
@@ -1137,32 +1103,32 @@ XNFstrdup(const char *s)
char *ret;
if (s == NULL)
- return NULL;
+ return NULL;
ret = strdup(s);
if (!ret)
- FatalError("XNFstrdup: Out of memory");
+ FatalError("XNFstrdup: Out of memory");
return ret;
}
void
-SmartScheduleStopTimer (void)
+SmartScheduleStopTimer(void)
{
#ifdef _MSC_VER
if (SmartScheduleDisable)
- return;
+ return;
DeleteTimerQueueTimer(s_hSmartScheduleTimerQueue, s_hSmartScheduleTimer, NULL);
s_hSmartScheduleTimer=NULL;
#else
- struct itimerval timer;
-
+ struct itimerval timer;
+
if (SmartScheduleDisable)
- return;
+ return;
timer.it_interval.tv_sec = 0;
timer.it_interval.tv_usec = 0;
timer.it_value.tv_sec = 0;
timer.it_value.tv_usec = 0;
- (void) setitimer (ITIMER_REAL, &timer, 0);
+ (void) setitimer(ITIMER_REAL, &timer, 0);
#endif
}
@@ -1177,105 +1143,102 @@ static void SmartScheduleTimer (int sig)
void
-SmartScheduleStartTimer (void)
+SmartScheduleStartTimer(void)
{
#ifdef _MSC_VER
if (SmartScheduleDisable)
- return;
+ return;
if (!CreateTimerQueueTimer( &s_hSmartScheduleTimer, s_hSmartScheduleTimerQueue, SmartScheduleTimer, NULL
, SmartScheduleInterval, SmartScheduleInterval, WT_EXECUTEONLYONCE|WT_EXECUTEINPERSISTENTTHREAD))
{
DWORD Error=GetLastError();
ErrorF("Error starting timer, smart scheduling disabled: 0x%x (%d)\n",Error,Error);
- CloseHandle(s_hSmartScheduleTimer);
- SmartScheduleDisable = TRUE;
- return;
+ CloseHandle(s_hSmartScheduleTimer);
+ SmartScheduleDisable = TRUE;
+ return;
}
#else
- struct itimerval timer;
-
+ struct itimerval timer;
+
if (SmartScheduleDisable)
- return;
+ return;
timer.it_interval.tv_sec = 0;
timer.it_interval.tv_usec = SmartScheduleInterval * 1000;
timer.it_value.tv_sec = 0;
timer.it_value.tv_usec = SmartScheduleInterval * 1000;
- setitimer (ITIMER_REAL, &timer, 0);
+ setitimer(ITIMER_REAL, &timer, 0);
#endif
}
void
-SmartScheduleInit (void)
+SmartScheduleInit(void)
{
#ifdef _MSC_VER
if (SmartScheduleDisable)
- return;
+ return;
s_hSmartScheduleTimerQueue = CreateTimerQueue();
if (!s_hSmartScheduleTimerQueue)
{
DWORD Error=GetLastError();
ErrorF("Error creating timer, smart scheduling disabled: 0x%x (%d)\n",Error,Error);
- SmartScheduleDisable = TRUE;
+ SmartScheduleDisable = TRUE;
}
#else
- struct sigaction act;
+ struct sigaction act;
if (SmartScheduleDisable)
- return;
+ return;
memset((char *) &act, 0, sizeof(struct sigaction));
/* Set up the timer signal function */
act.sa_handler = SmartScheduleTimer;
- sigemptyset (&act.sa_mask);
- sigaddset (&act.sa_mask, SIGALRM);
- if (sigaction (SIGALRM, &act, 0) < 0)
- {
- perror ("sigaction for smart scheduler");
- SmartScheduleDisable = TRUE;
+ sigemptyset(&act.sa_mask);
+ sigaddset(&act.sa_mask, SIGALRM);
+ if (sigaction(SIGALRM, &act, 0) < 0) {
+ perror("sigaction for smart scheduler");
+ SmartScheduleDisable = TRUE;
}
#endif
}
#ifdef SIG_BLOCK
-static sigset_t PreviousSignalMask;
-static int BlockedSignalCount;
+static sigset_t PreviousSignalMask;
+static int BlockedSignalCount;
#endif
void
-OsBlockSignals (void)
+OsBlockSignals(void)
{
#ifdef SIG_BLOCK
- if (BlockedSignalCount++ == 0)
- {
- sigset_t set;
-
- sigemptyset (&set);
- sigaddset (&set, SIGALRM);
- sigaddset (&set, SIGVTALRM);
+ if (BlockedSignalCount++ == 0) {
+ sigset_t set;
+
+ sigemptyset(&set);
+ sigaddset(&set, SIGALRM);
+ sigaddset(&set, SIGVTALRM);
#ifdef SIGWINCH
- sigaddset (&set, SIGWINCH);
+ sigaddset(&set, SIGWINCH);
#endif
#ifdef SIGIO
- sigaddset (&set, SIGIO);
+ sigaddset(&set, SIGIO);
#endif
- sigaddset (&set, SIGTSTP);
- sigaddset (&set, SIGTTIN);
- sigaddset (&set, SIGTTOU);
- sigaddset (&set, SIGCHLD);
- sigprocmask (SIG_BLOCK, &set, &PreviousSignalMask);
+ sigaddset(&set, SIGTSTP);
+ sigaddset(&set, SIGTTIN);
+ sigaddset(&set, SIGTTOU);
+ sigaddset(&set, SIGCHLD);
+ sigprocmask(SIG_BLOCK, &set, &PreviousSignalMask);
}
#endif
}
void
-OsReleaseSignals (void)
+OsReleaseSignals(void)
{
#ifdef SIG_BLOCK
- if (--BlockedSignalCount == 0)
- {
- sigprocmask (SIG_SETMASK, &PreviousSignalMask, 0);
+ if (--BlockedSignalCount == 0) {
+ sigprocmask(SIG_SETMASK, &PreviousSignalMask, 0);
}
#endif
}
@@ -1286,7 +1249,7 @@ OsReleaseSignals (void)
*/
void
-OsAbort (void)
+OsAbort(void)
{
#ifndef __APPLE__
OsBlockSignals();
@@ -1309,39 +1272,39 @@ int
System(const char *command)
{
int pid, p;
- void (*csig)(int);
+ void (*csig) (int);
int status;
if (!command)
- return 1;
+ return 1;
csig = signal(SIGCHLD, SIG_DFL);
if (csig == SIG_ERR) {
- perror("signal");
- return -1;
+ perror("signal");
+ return -1;
}
DebugF("System: `%s'\n", command);
switch (pid = fork()) {
- case -1: /* error */
- p = -1;
- case 0: /* child */
- if (setgid(getgid()) == -1)
- _exit(127);
- if (setuid(getuid()) == -1)
- _exit(127);
- execl("/bin/sh", "sh", "-c", command, (char *)NULL);
- _exit(127);
- default: /* parent */
- do {
- p = waitpid(pid, &status, 0);
- } while (p == -1 && errno == EINTR);
-
+ case -1: /* error */
+ p = -1;
+ case 0: /* child */
+ if (setgid(getgid()) == -1)
+ _exit(127);
+ if (setuid(getuid()) == -1)
+ _exit(127);
+ execl("/bin/sh", "sh", "-c", command, (char *) NULL);
+ _exit(127);
+ default: /* parent */
+ do {
+ p = waitpid(pid, &status, 0);
+ } while (p == -1 && errno == EINTR);
+
}
if (signal(SIGCHLD, csig) == SIG_ERR) {
- perror("signal");
- return -1;
+ perror("signal");
+ return -1;
}
return p == -1 ? -1 : status;
@@ -1353,7 +1316,7 @@ static struct pid {
int pid;
} *pidlist;
-OsSigHandlerPtr old_alarm = NULL; /* XXX horrible awful hack */
+OsSigHandlerPtr old_alarm = NULL; /* XXX horrible awful hack */
pointer
Popen(const char *command, const char *type)
@@ -1363,71 +1326,73 @@ Popen(const char *command, const char *type)
int pdes[2], pid;
if (command == NULL || type == NULL)
- return NULL;
+ return NULL;
if ((*type != 'r' && *type != 'w') || type[1])
- return NULL;
+ return NULL;
if ((cur = malloc(sizeof(struct pid))) == NULL)
- return NULL;
+ return NULL;
if (pipe(pdes) < 0) {
- free(cur);
- return NULL;
+ free(cur);
+ return NULL;
}
/* Ignore the smart scheduler while this is going on */
old_alarm = OsSignal(SIGALRM, SIG_IGN);
if (old_alarm == SIG_ERR) {
- close(pdes[0]);
- close(pdes[1]);
- free(cur);
- perror("signal");
- return NULL;
+ close(pdes[0]);
+ close(pdes[1]);
+ free(cur);
+ perror("signal");
+ return NULL;
}
switch (pid = fork()) {
- case -1: /* error */
- close(pdes[0]);
- close(pdes[1]);
- free(cur);
- if (OsSignal(SIGALRM, old_alarm) == SIG_ERR)
- perror("signal");
- return NULL;
- case 0: /* child */
- if (setgid(getgid()) == -1)
- _exit(127);
- if (setuid(getuid()) == -1)
- _exit(127);
- if (*type == 'r') {
- if (pdes[1] != 1) {
- /* stdout */
- dup2(pdes[1], 1);
- close(pdes[1]);
- }
- close(pdes[0]);
- } else {
- if (pdes[0] != 0) {
- /* stdin */
- dup2(pdes[0], 0);
- close(pdes[0]);
- }
- close(pdes[1]);
- }
- execl("/bin/sh", "sh", "-c", command, (char *)NULL);
- _exit(127);
+ case -1: /* error */
+ close(pdes[0]);
+ close(pdes[1]);
+ free(cur);
+ if (OsSignal(SIGALRM, old_alarm) == SIG_ERR)
+ perror("signal");
+ return NULL;
+ case 0: /* child */
+ if (setgid(getgid()) == -1)
+ _exit(127);
+ if (setuid(getuid()) == -1)
+ _exit(127);
+ if (*type == 'r') {
+ if (pdes[1] != 1) {
+ /* stdout */
+ dup2(pdes[1], 1);
+ close(pdes[1]);
+ }
+ close(pdes[0]);
+ }
+ else {
+ if (pdes[0] != 0) {
+ /* stdin */
+ dup2(pdes[0], 0);
+ close(pdes[0]);
+ }
+ close(pdes[1]);
+ }
+ execl("/bin/sh", "sh", "-c", command, (char *) NULL);
+ _exit(127);
}
/* Avoid EINTR during stdio calls */
- OsBlockSignals ();
-
+ OsBlockSignals();
+
/* parent */
if (*type == 'r') {
- iop = fdopen(pdes[0], type);
- close(pdes[1]);
- } else {
- iop = fdopen(pdes[1], type);
- close(pdes[0]);
+ iop = fdopen(pdes[0], type);
+ close(pdes[1]);
+ }
+ else {
+ iop = fdopen(pdes[1], type);
+ close(pdes[0]);
}
cur->fp = iop;
@@ -1445,64 +1410,67 @@ pointer
Fopen(const char *file, const char *type)
{
FILE *iop;
+
#ifndef HAS_SAVED_IDS_AND_SETEUID
struct pid *cur;
int pdes[2], pid;
if (file == NULL || type == NULL)
- return NULL;
+ return NULL;
if ((*type != 'r' && *type != 'w') || type[1])
- return NULL;
+ return NULL;
if ((cur = malloc(sizeof(struct pid))) == NULL)
- return NULL;
+ return NULL;
if (pipe(pdes) < 0) {
- free(cur);
- return NULL;
+ free(cur);
+ return NULL;
}
switch (pid = fork()) {
- case -1: /* error */
- close(pdes[0]);
- close(pdes[1]);
- free(cur);
- return NULL;
- case 0: /* child */
- if (setgid(getgid()) == -1)
- _exit(127);
- if (setuid(getuid()) == -1)
- _exit(127);
- if (*type == 'r') {
- if (pdes[1] != 1) {
- /* stdout */
- dup2(pdes[1], 1);
- close(pdes[1]);
- }
- close(pdes[0]);
- } else {
- if (pdes[0] != 0) {
- /* stdin */
- dup2(pdes[0], 0);
- close(pdes[0]);
- }
- close(pdes[1]);
- }
- execl("/bin/cat", "cat", file, (char *)NULL);
- _exit(127);
+ case -1: /* error */
+ close(pdes[0]);
+ close(pdes[1]);
+ free(cur);
+ return NULL;
+ case 0: /* child */
+ if (setgid(getgid()) == -1)
+ _exit(127);
+ if (setuid(getuid()) == -1)
+ _exit(127);
+ if (*type == 'r') {
+ if (pdes[1] != 1) {
+ /* stdout */
+ dup2(pdes[1], 1);
+ close(pdes[1]);
+ }
+ close(pdes[0]);
+ }
+ else {
+ if (pdes[0] != 0) {
+ /* stdin */
+ dup2(pdes[0], 0);
+ close(pdes[0]);
+ }
+ close(pdes[1]);
+ }
+ execl("/bin/cat", "cat", file, (char *) NULL);
+ _exit(127);
}
/* Avoid EINTR during stdio calls */
- OsBlockSignals ();
-
+ OsBlockSignals();
+
/* parent */
if (*type == 'r') {
- iop = fdopen(pdes[0], type);
- close(pdes[1]);
- } else {
- iop = fdopen(pdes[1], type);
- close(pdes[0]);
+ iop = fdopen(pdes[0], type);
+ close(pdes[1]);
+ }
+ else {
+ iop = fdopen(pdes[1], type);
+ close(pdes[0]);
}
cur->fp = iop;
@@ -1518,18 +1486,18 @@ Fopen(const char *file, const char *type)
ruid = getuid();
euid = geteuid();
-
+
if (seteuid(ruid) == -1) {
- return NULL;
+ return NULL;
}
iop = fopen(file, type);
if (seteuid(euid) == -1) {
- fclose(iop);
- return NULL;
+ fclose(iop);
+ return NULL;
}
return iop;
-#endif /* HAS_SAVED_IDS_AND_SETEUID */
+#endif /* HAS_SAVED_IDS_AND_SETEUID */
}
int
@@ -1543,27 +1511,27 @@ Pclose(pointer iop)
fclose(iop);
for (last = NULL, cur = pidlist; cur; last = cur, cur = cur->next)
- if (cur->fp == iop)
- break;
+ if (cur->fp == iop)
+ break;
if (cur == NULL)
- return -1;
+ return -1;
do {
- pid = waitpid(cur->pid, &pstat, 0);
+ pid = waitpid(cur->pid, &pstat, 0);
} while (pid == -1 && errno == EINTR);
if (last == NULL)
- pidlist = cur->next;
+ pidlist = cur->next;
else
- last->next = cur->next;
+ last->next = cur->next;
free(cur);
/* allow EINTR again */
- OsReleaseSignals ();
-
+ OsReleaseSignals();
+
if (old_alarm && OsSignal(SIGALRM, old_alarm) == SIG_ERR) {
- perror("signal");
- return -1;
+ perror("signal");
+ return -1;
}
return pid == -1 ? -1 : pstat;
@@ -1579,8 +1547,7 @@ Fclose(pointer iop)
#endif
}
-#endif /* !WIN32 */
-
+#endif /* !WIN32 */
/*
* CheckUserParameters: check for long command line arguments and long
@@ -1611,7 +1578,6 @@ Fclose(pointer iop)
#define NO_OUTPUT_PIPES 0
#endif
-
/* Check args and env only if running setuid (euid == 0 && euid != uid) ? */
#ifndef CHECK_EUID
#ifndef WIN32
@@ -1631,7 +1597,7 @@ Fclose(pointer iop)
#define MAX_ARG_LENGTH 128
#define MAX_ENV_LENGTH 2048
-#define MAX_ENV_PATH_LENGTH 2048 /* Limit for *PATH and TERMCAP */
+#define MAX_ENV_PATH_LENGTH 2048 /* Limit for *PATH and TERMCAP */
#if USE_ISPRINT
#include <ctype.h>
@@ -1669,115 +1635,116 @@ CheckUserParameters(int argc, char **argv, char **envp)
if (geteuid() == 0 && getuid() != geteuid())
#endif
{
- /* Check each argv[] */
- for (i = 1; i < argc; i++) {
- if (strcmp(argv[i], "-fp") == 0)
- {
- i++; /* continue with next argument. skip the length check */
- if (i >= argc)
- break;
- } else
- {
- if (strlen(argv[i]) > MAX_ARG_LENGTH) {
- bad = ArgTooLong;
- break;
- }
- }
- a = argv[i];
- while (*a) {
- if (checkPrintable(*a) == 0) {
- bad = UnprintableArg;
- break;
- }
- a++;
- }
- if (bad)
- break;
- }
- if (!bad) {
- /* Check each envp[] */
- for (i = 0; envp[i]; i++) {
-
- /* Check for bad environment variables and values */
+ /* Check each argv[] */
+ for (i = 1; i < argc; i++) {
+ if (strcmp(argv[i], "-fp") == 0) {
+ i++; /* continue with next argument. skip the length check */
+ if (i >= argc)
+ break;
+ }
+ else {
+ if (strlen(argv[i]) > MAX_ARG_LENGTH) {
+ bad = ArgTooLong;
+ break;
+ }
+ }
+ a = argv[i];
+ while (*a) {
+ if (checkPrintable(*a) == 0) {
+ bad = UnprintableArg;
+ break;
+ }
+ a++;
+ }
+ if (bad)
+ break;
+ }
+ if (!bad) {
+ /* Check each envp[] */
+ for (i = 0; envp[i]; i++) {
+
+ /* Check for bad environment variables and values */
#if REMOVE_ENV_LD
- while (envp[i] && (strncmp(envp[i], "LD", 2) == 0)) {
- for (j = i; envp[j]; j++) {
- envp[j] = envp[j+1];
- }
- }
-#endif
- if (envp[i] && (strlen(envp[i]) > MAX_ENV_LENGTH)) {
+ while (envp[i] && (strncmp(envp[i], "LD", 2) == 0)) {
+ for (j = i; envp[j]; j++) {
+ envp[j] = envp[j + 1];
+ }
+ }
+#endif
+ if (envp[i] && (strlen(envp[i]) > MAX_ENV_LENGTH)) {
#if REMOVE_LONG_ENV
- for (j = i; envp[j]; j++) {
- envp[j] = envp[j+1];
- }
- i--;
+ for (j = i; envp[j]; j++) {
+ envp[j] = envp[j + 1];
+ }
+ i--;
#else
- char *eq;
- int len;
-
- eq = strchr(envp[i], '=');
- if (!eq)
- continue;
- len = eq - envp[i];
- e = strndup(envp[i], len);
- if (!e) {
- bad = InternalError;
- break;
- }
- if (len >= 4 &&
- (strcmp(e + len - 4, "PATH") == 0 ||
- strcmp(e, "TERMCAP") == 0)) {
- if (strlen(envp[i]) > MAX_ENV_PATH_LENGTH) {
- bad = EnvTooLong;
- break;
- } else {
- free(e);
- }
- } else {
- bad = EnvTooLong;
- break;
- }
-#endif
- }
- }
- }
+ char *eq;
+ int len;
+
+ eq = strchr(envp[i], '=');
+ if (!eq)
+ continue;
+ len = eq - envp[i];
+ e = strndup(envp[i], len);
+ if (!e) {
+ bad = InternalError;
+ break;
+ }
+ if (len >= 4 &&
+ (strcmp(e + len - 4, "PATH") == 0 ||
+ strcmp(e, "TERMCAP") == 0)) {
+ if (strlen(envp[i]) > MAX_ENV_PATH_LENGTH) {
+ bad = EnvTooLong;
+ break;
+ }
+ else {
+ free(e);
+ }
+ }
+ else {
+ bad = EnvTooLong;
+ break;
+ }
+#endif
+ }
+ }
+ }
#if NO_OUTPUT_PIPES
- if (!bad) {
- struct stat buf;
+ if (!bad) {
+ struct stat buf;
- if (fstat(fileno(stdout), &buf) == 0 && S_ISFIFO(buf.st_mode))
- bad = OutputIsPipe;
- if (fstat(fileno(stderr), &buf) == 0 && S_ISFIFO(buf.st_mode))
- bad = OutputIsPipe;
- }
+ if (fstat(fileno(stdout), &buf) == 0 && S_ISFIFO(buf.st_mode))
+ bad = OutputIsPipe;
+ if (fstat(fileno(stderr), &buf) == 0 && S_ISFIFO(buf.st_mode))
+ bad = OutputIsPipe;
+ }
#endif
}
switch (bad) {
case NotBad:
- return;
+ return;
case UnsafeArg:
- ErrorF("Command line argument number %d is unsafe\n", i);
- break;
+ ErrorF("Command line argument number %d is unsafe\n", i);
+ break;
case ArgTooLong:
- ErrorF("Command line argument number %d is too long\n", i);
- break;
+ ErrorF("Command line argument number %d is too long\n", i);
+ break;
case UnprintableArg:
- ErrorF("Command line argument number %d contains unprintable"
- " characters\n", i);
- break;
+ ErrorF("Command line argument number %d contains unprintable"
+ " characters\n", i);
+ break;
case EnvTooLong:
- ErrorF("Environment variable `%s' is too long\n", e);
- break;
+ ErrorF("Environment variable `%s' is too long\n", e);
+ break;
case OutputIsPipe:
- ErrorF("Stdout and/or stderr is a pipe\n");
- break;
+ ErrorF("Stdout and/or stderr is a pipe\n");
+ break;
case InternalError:
- ErrorF("Internal Error\n");
- break;
+ ErrorF("Internal Error\n");
+ break;
default:
- ErrorF("Unknown error\n");
- break;
+ ErrorF("Unknown error\n");
+ break;
}
FatalError("X server aborted because of unsafe environment\n");
}
@@ -1792,15 +1759,15 @@ CheckUserParameters(int argc, char **argv, char **envp)
#include <security/pam_appl.h>
#include <security/pam_misc.h>
#include <pwd.h>
-#endif /* USE_PAM */
+#endif /* USE_PAM */
void
CheckUserAuthorization(void)
{
#ifdef USE_PAM
static struct pam_conv conv = {
- misc_conv,
- NULL
+ misc_conv,
+ NULL
};
pam_handle_t *pamh = NULL;
@@ -1808,31 +1775,31 @@ CheckUserAuthorization(void)
int retval;
if (getuid() != geteuid()) {
- pw = getpwuid(getuid());
- if (pw == NULL)
- FatalError("getpwuid() failed for uid %d\n", getuid());
-
- retval = pam_start("xserver", pw->pw_name, &conv, &pamh);
- if (retval != PAM_SUCCESS)
- FatalError("pam_start() failed.\n"
- "\tMissing or mangled PAM config file or module?\n");
-
- retval = pam_authenticate(pamh, 0);
- if (retval != PAM_SUCCESS) {
- pam_end(pamh, retval);
- FatalError("PAM authentication failed, cannot start X server.\n"
- "\tPerhaps you do not have console ownership?\n");
- }
-
- retval = pam_acct_mgmt(pamh, 0);
- if (retval != PAM_SUCCESS) {
- pam_end(pamh, retval);
- FatalError("PAM authentication failed, cannot start X server.\n"
- "\tPerhaps you do not have console ownership?\n");
- }
-
- /* this is not a session, so do not do session management */
- pam_end(pamh, PAM_SUCCESS);
+ pw = getpwuid(getuid());
+ if (pw == NULL)
+ FatalError("getpwuid() failed for uid %d\n", getuid());
+
+ retval = pam_start("xserver", pw->pw_name, &conv, &pamh);
+ if (retval != PAM_SUCCESS)
+ FatalError("pam_start() failed.\n"
+ "\tMissing or mangled PAM config file or module?\n");
+
+ retval = pam_authenticate(pamh, 0);
+ if (retval != PAM_SUCCESS) {
+ pam_end(pamh, retval);
+ FatalError("PAM authentication failed, cannot start X server.\n"
+ "\tPerhaps you do not have console ownership?\n");
+ }
+
+ retval = pam_acct_mgmt(pamh, 0);
+ if (retval != PAM_SUCCESS) {
+ pam_end(pamh, retval);
+ FatalError("PAM authentication failed, cannot start X server.\n"
+ "\tPerhaps you do not have console ownership?\n");
+ }
+
+ /* this is not a session, so do not do session management */
+ pam_end(pamh, PAM_SUCCESS);
}
#endif
}
@@ -1841,7 +1808,7 @@ CheckUserAuthorization(void)
* Tokenize a string into a NULL terminated array of strings. Always returns
* an allocated array unless an error occurs.
*/
-char**
+char **
xstrtokenize(const char *str, const char *separators)
{
char **list, **nlist;
@@ -1869,7 +1836,7 @@ xstrtokenize(const char *str, const char *separators)
free(tmp);
return list;
-error:
+ error:
free(tmp);
for (n = 0; n < num; n++)
free(list[n]);