diff options
author | Matthieu Herrb <matthieu@cvs.openbsd.org> | 2010-12-05 15:36:12 +0000 |
---|---|---|
committer | Matthieu Herrb <matthieu@cvs.openbsd.org> | 2010-12-05 15:36:12 +0000 |
commit | a90ee792d96752ad1b71b9ada922fa6afe478c99 (patch) | |
tree | 6143b00f7646951d23dfe2a4fe2992ca40b77069 /xserver/os/utils.c | |
parent | bc97d4ecc0aa9e1b823565b07282f848700bd11a (diff) |
Upgrade to xorg-server 1.9.2.
Tested by ajacoutot@, krw@, shadchin@ and jasper@ on various configurations
including multihead with both zaphod and xrandr.
Diffstat (limited to 'xserver/os/utils.c')
-rw-r--r-- | xserver/os/utils.c | 237 |
1 files changed, 61 insertions, 176 deletions
diff --git a/xserver/os/utils.c b/xserver/os/utils.c index a635c0528..c1836ac84 100644 --- a/xserver/os/utils.c +++ b/xserver/os/utils.c @@ -120,9 +120,7 @@ __stdcall unsigned long GetTickCount(void); #include "xkbsrv.h" -#ifdef RENDER #include "picture.h" -#endif Bool noTestExtensions; #ifdef COMPOSITE @@ -148,15 +146,10 @@ Bool noScreenSaverExtension = FALSE; #ifdef MITSHM Bool noMITShmExtension = FALSE; #endif -#ifdef MULTIBUFFER -Bool noMultibufferExtension = FALSE; -#endif #ifdef RANDR Bool noRRExtension = FALSE; #endif -#ifdef RENDER Bool noRenderExtension = FALSE; -#endif #ifdef XCSECURITY Bool noSecurityExtension = FALSE; #endif @@ -212,8 +205,6 @@ int auditTrailLevel = 1; #define HAS_SAVED_IDS_AND_SETEUID #endif -static char *dev_tty_from_init = NULL; /* since we need to parse it anyway */ - OsSigHandlerPtr OsSignal(int sig, OsSigHandlerPtr handler) { @@ -535,9 +526,7 @@ void UseMsg(void) ErrorF("-nopn reject failure to listen on all ports\n"); ErrorF("-r turns off auto-repeat\n"); ErrorF("r turns on auto-repeat \n"); -#ifdef RENDER ErrorF("-render [default|mono|gray|color] set render color alloc policy\n"); -#endif #ifndef __OpenBSD__ ErrorF("-retro start with classic stipple and cursor\n"); #else @@ -579,12 +568,12 @@ void UseMsg(void) 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!!! */ - return( 1 ); + 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; } /* @@ -915,8 +904,7 @@ ProcessCommandLine(int argc, char *argv[]) } else if (strncmp (argv[i], "tty", 3) == 0) { - /* just in case any body is interested */ - dev_tty_from_init = argv[i]; + /* init supplies us with this useless information */ } #ifdef XDMCP else if ((skip = XdmcpOptions(argc, argv, i)) != i) @@ -947,7 +935,6 @@ ProcessCommandLine(int argc, char *argv[]) else UseMsg(); } -#ifdef RENDER else if ( strcmp( argv[i], "-render" ) == 0) { if (++i < argc) @@ -962,7 +949,6 @@ ProcessCommandLine(int argc, char *argv[]) else UseMsg (); } -#endif else if ( strcmp( argv[i], "+extension") == 0) { if (++i < argc) @@ -1017,7 +1003,7 @@ set_font_authorizations(char **authorizations, int *authlen, pointer client) gethostname(hname, 1024); #if defined(IPv6) && defined(AF_INET6) - bzero(&hints, sizeof(hints)); + memset(&hints, 0, sizeof(hints)); hints.ai_flags = AI_CANONNAME; if (getaddrinfo(hname, NULL, &hints, &ai) == 0) { hnameptr = ai->ai_canonname; @@ -1033,7 +1019,7 @@ set_font_authorizations(char **authorizations, int *authlen, pointer client) #endif len = strlen(hnameptr) + 1; - result = xalloc(len + sizeof(AUTHORIZATION_NAME) + 4); + result = malloc(len + sizeof(AUTHORIZATION_NAME) + 4); p = result; *p++ = sizeof(AUTHORIZATION_NAME) >> 8; @@ -1062,150 +1048,99 @@ set_font_authorizations(char **authorizations, int *authlen, pointer client) void * Xalloc(unsigned long amount) { - void *ptr; + /* + * Xalloc used to return NULL when large amount of memory is requested. In + * order to catch the buggy callers this warning has been added, slated to + * removal by anyone who touches this code (or just looks at it) in 2011. + * + * -- Mikhail Gusarov + */ + if ((long)amount <= 0) + ErrorF("Warning: Xalloc: " + "requesting unpleasantly large amount of memory: %lu bytes.\n", + amount); - if ((long)amount <= 0) { - return NULL; - } - /* aligned extra on long word boundary */ - amount = (amount + (sizeof(long) - 1)) & ~(sizeof(long) - 1); - ptr = malloc(amount); - return ptr; + return malloc(amount); } -/***************** - * XNFalloc - * "no failure" realloc - *****************/ - void * XNFalloc(unsigned long amount) { - void *ptr; - - if ((long)amount <= 0) - return NULL; - /* aligned extra on long word boundary */ - amount = (amount + (sizeof(long) - 1)) & ~(sizeof(long) - 1); - ptr = malloc(amount); + void *ptr = malloc(amount); if (!ptr) FatalError("Out of memory"); return ptr; } -/***************** - * Xcalloc - *****************/ - void * Xcalloc(unsigned long amount) { - void *ret; - - ret = Xalloc (amount); - if (ret) - bzero (ret, (int) amount); - return ret; + return calloc(1, amount); } -/***************** - * XNFcalloc - *****************/ - void * XNFcalloc(unsigned long amount) { - void *ret; - - ret = Xalloc (amount); - if (ret) - bzero (ret, (int) amount); - else if ((long)amount > 0) - FatalError("Out of memory"); + void *ret = calloc(1, amount); + if (!ret) + FatalError("XNFcalloc: Out of memory"); return ret; } -/***************** - * Xrealloc - *****************/ - void * -Xrealloc(pointer ptr, unsigned long amount) +Xrealloc(void *ptr, unsigned long amount) { + /* + * Xrealloc used to return NULL when large amount of memory is requested. In + * order to catch the buggy callers this warning has been added, slated to + * removal by anyone who touches this code (or just looks at it) in 2011. + * + * -- Mikhail Gusarov + */ if ((long)amount <= 0) - { - if (ptr && !amount) - free(ptr); - return NULL; - } - amount = (amount + (sizeof(long) - 1)) & ~(sizeof(long) - 1); - if (ptr) - ptr = realloc(ptr, amount); - else - ptr = malloc(amount); + ErrorF("Warning: Xrealloc: " + "requesting unpleasantly large amount of memory: %lu bytes.\n", + amount); - return ptr; + return realloc(ptr, amount); } - -/***************** - * XNFrealloc - * "no failure" realloc - *****************/ void * -XNFrealloc(pointer ptr, unsigned long amount) +XNFrealloc(void *ptr, unsigned long amount) { - if ((ptr = Xrealloc(ptr, amount)) == NULL) - { - if ((long)amount > 0) - FatalError( "Out of memory" ); - } - return ptr; + void *ret = realloc(ptr, amount); + if (!ret) + FatalError("XNFrealloc: Out of memory"); + return ret; } -/***************** - * Xfree - * calls free - *****************/ - void -Xfree(pointer ptr) +Xfree(void *ptr) { - if (ptr) - free(ptr); + free(ptr); } char * Xstrdup(const char *s) { - char *sd; - size_t len; - if (s == NULL) return NULL; - - len = strlen(s) + 1; - sd = (char *)Xalloc(len); - if (sd != NULL) - strlcpy(sd, s, len); - return sd; + return strdup(s); } - char * XNFstrdup(const char *s) { - char *sd; - size_t len; + char *ret; if (s == NULL) return NULL; - - len = strlen(s) + 1; - sd = (char *)XNFalloc(len); - strlcpy(sd, s, len); - return sd; + + ret = strdup(s); + if (!ret) + FatalError("XNFstrdup: Out of memory"); + return ret; } @@ -1267,7 +1202,7 @@ SmartScheduleInit (void) if (SmartScheduleDisable) return TRUE; - bzero ((char *) &act, sizeof(struct sigaction)); + memset((char *) &act, 0, sizeof(struct sigaction)); /* Set up the timer signal function */ act.sa_handler = SmartScheduleTimer; @@ -1373,7 +1308,7 @@ System(char *command) int status; if (!command) - return(1); + return 1; #ifdef SIGCHLD csig = signal(SIGCHLD, SIG_DFL); @@ -1435,11 +1370,11 @@ Popen(char *command, char *type) if ((*type != 'r' && *type != 'w') || type[1]) return NULL; - if ((cur = xalloc(sizeof(struct pid))) == NULL) + if ((cur = malloc(sizeof(struct pid))) == NULL) return NULL; if (pipe(pdes) < 0) { - xfree(cur); + free(cur); return NULL; } @@ -1454,7 +1389,7 @@ Popen(char *command, char *type) case -1: /* error */ close(pdes[0]); close(pdes[1]); - xfree(cur); + free(cur); if (OsSignal(SIGALRM, old_alarm) == SIG_ERR) perror("signal"); return NULL; @@ -1521,11 +1456,11 @@ Fopen(char *file, char *type) if ((*type != 'r' && *type != 'w') || type[1]) return NULL; - if ((cur = xalloc(sizeof(struct pid))) == NULL) + if ((cur = malloc(sizeof(struct pid))) == NULL) return NULL; if (pipe(pdes) < 0) { - xfree(cur); + free(cur); return NULL; } @@ -1533,7 +1468,7 @@ Fopen(char *file, char *type) case -1: /* error */ close(pdes[0]); close(pdes[1]); - xfree(cur); + free(cur); return NULL; case 0: /* child */ if (setgid(getgid()) == -1) @@ -1627,7 +1562,7 @@ Pclose(pointer iop) pidlist = cur->next; else last->next = cur->next; - xfree(cur); + free(cur); /* allow EINTR again */ OsReleaseSignals (); @@ -1947,53 +1882,3 @@ error: free(list); return NULL; } - -#ifdef __SCO__ -#include <fcntl.h> - -static void -lockit (int fd, short what) -{ - struct flock lck; - - lck.l_whence = 0; - lck.l_start = 0; - lck.l_len = 1; - lck.l_type = what; - - (void)fcntl (fd, F_SETLKW, &lck); -} - -/* SCO OpenServer 5 lacks pread/pwrite. Emulate them. */ -ssize_t -pread (int fd, void *buf, size_t nbytes, off_t offset) -{ - off_t saved; - ssize_t ret; - - lockit (fd, F_RDLCK); - saved = lseek (fd, 0, SEEK_CUR); - lseek (fd, offset, SEEK_SET); - ret = read (fd, buf, nbytes); - lseek (fd, saved, SEEK_SET); - lockit (fd, F_UNLCK); - - return ret; -} - -ssize_t -pwrite (int fd, const void *buf, size_t nbytes, off_t offset) -{ - off_t saved; - ssize_t ret; - - lockit (fd, F_WRLCK); - saved = lseek (fd, 0, SEEK_CUR); - lseek (fd, offset, SEEK_SET); - ret = write (fd, buf, nbytes); - lseek (fd, saved, SEEK_SET); - lockit (fd, F_UNLCK); - - return ret; -} -#endif /* __SCO__ */ |