⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 utils.c

📁 远程桌面连接工具
💻 C
📖 第 1 页 / 共 3 页
字号:
/* $TOG: utils.c /main/128 1997/06/01 13:50:39 sekhar $ *//*Copyright (c) 1987  X ConsortiumPermission is hereby granted, free of charge, to any person obtaininga copy of this software and associated documentation files (the"Software"), to deal in the Software without restriction, includingwithout limitation the rights to use, copy, modify, merge, publish,distribute, sublicense, and/or sell copies of the Software, and topermit persons to whom the Software is furnished to do so, subject tothe following conditions:The above copyright notice and this permission notice shall be includedin all copies or substantial portions of the Software.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESSOR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OFMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OROTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OROTHER DEALINGS IN THE SOFTWARE.Except as contained in this notice, the name of the X Consortium shallnot be used in advertising or otherwise to promote the sale, use orother dealings in this Software without prior written authorizationfrom the X Consortium.Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts,Copyright 1994 Quarterdeck Office Systems.                        All Rights ReservedPermission to use, copy, modify, and distribute this software and itsdocumentation for any purpose and without fee is hereby granted,provided that the above copyright notice appear in all copies and thatboth that copyright notice and this permission notice appear insupporting documentation, and that the names of Digital andQuarterdeck not be used in advertising or publicity pertaining todistribution of the software without specific, written priorpermission.DIGITAL AND QUARTERDECK DISCLAIM ALL WARRANTIES WITH REGARD TO THISSOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY ANDFITNESS, IN NO EVENT SHALL DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECTOR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSSOF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCEOR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USEOR PERFORMANCE OF THIS SOFTWARE.*//* $XFree86: xc/programs/Xserver/os/utils.c,v 3.27.2.6 1998/02/20 15:13:58 robin Exp $ */#ifdef WIN32#include <X11/Xwinsock.h>#endif#include "Xos.h"#include <stdio.h>#include "misc.h"#include "X.h"#include "input.h"#include "opaque.h"#ifdef X_POSIX_C_SOURCE#define _POSIX_C_SOURCE X_POSIX_C_SOURCE#include <signal.h>#undef _POSIX_C_SOURCE#else#if defined(X_NOT_POSIX) || defined(_POSIX_SOURCE)#include <signal.h>#else#define _POSIX_SOURCE#include <signal.h>#undef _POSIX_SOURCE#endif#endif#if !defined(SYSV) && !defined(AMOEBA) && !defined(_MINIX) && !defined(WIN32) && !defined(Lynx)#include <sys/resource.h>#endif#if defined(AIXV3) || defined(HPUX_10)# include <sys/resource.h>#endif#include <time.h>#include <sys/stat.h>#include <ctype.h>    /* for isspace */#if NeedVarargsPrototypes#include <stdarg.h>#endif#ifdef AMOEBA#include "osdep.h"#include <amoeba.h>#include <module/mutex.h>static mutex print_lock;#endif#if defined(__STDC__) || defined(AMOEBA)/* DHD: SVR4.0 has a prototype for abs() in stdlib.h *//* DHD: might be better to move this include higher up? */#ifdef abs#undef abs#endif#ifndef NOSTDHDRS#include <stdlib.h>	/* for malloc() */#endif#endifextern char *display;extern CARD32 defaultScreenSaverTime;	/* for parsing command line */extern CARD32 defaultScreenSaverInterval;extern int defaultScreenSaverBlanking;extern int defaultBackingStore;extern Bool disableBackingStore;extern Bool disableSaveUnders;extern Bool PartialNetwork;#ifndef NOLOGOHACKextern int logoScreenSaver;#endif#ifdef RLIMIT_DATAextern int limitDataSpace;#endif#ifdef RLIMIT_STACKextern int limitStackSpace;#endif#ifdef RLIMIT_NOFILEextern int limitNoFile;#endifextern int defaultColorVisualClass;extern Bool permitOldBugs;extern int monitorResolution;extern Bool defeatAccessControl;#ifdef SERVER_LOCKstatic Bool nolock = FALSE;#endifextern char* protNoListen;Bool CoreDump;Bool noTestExtensions;int auditTrailLevel = 1;void ddxUseMsg();#if NeedVarargsPrototypesvoid VErrorF(char*, va_list);#endif#ifdef DEBUG#ifndef SPECIAL_MALLOC#define MEMBUG#endif#endif#ifdef MEMBUG#define MEM_FAIL_SCALE 100000long Memory_fail = 0;#ifdef linux#include <stdlib.h>  /* for random() */#endif#endif#ifdef sgiint userdefinedfontpath = 0;#endif /* sgi */Bool Must_have_memory = FALSE;char *dev_tty_from_init = NULL;		/* since we need to parse it anyway */OsSigHandlerPtrOsSignal(sig, handler)    int sig;    OsSigHandlerPtr handler;{#ifdef X_NOT_POSIX    return signal(sig, handler);#else    struct sigaction act, oact;    sigemptyset(&act.sa_mask);    if (handler != SIG_IGN)	sigaddset(&act.sa_mask, sig);    act.sa_flags = 0;    act.sa_handler = handler;    sigaction(sig, &act, &oact);    return oact.sa_handler;#endif}#include <errno.h>extern int errno;#ifdef SERVER_LOCK/* * Explicit support for a server lock file like the ones used for UUCP. * For architectures with virtual terminals that can run more than one * server at a time.  This keeps the servers from stomping on each other * if the user forgets to give them different display numbers. */#ifndef __EMX__#define LOCK_DIR "/tmp"#define LOCK_TMP_PREFIX "/.tX"#define LOCK_PREFIX "/.X"#define LOCK_SUFFIX "-lock"#else#define LOCK_TMP_PREFIX "/xf86$"#define LOCK_PREFIX "/xf86_"#define LOCK_SUFFIX ".lck"#endif#ifdef _MINIX#include <limits.h>	/* For PATH_MAX */#endif#ifdef __EMX__#define link rename#endif#ifndef PATH_MAX#ifndef Lynx#include <sys/param.h>#else#include <param.h>#endif#ifndef PATH_MAX#ifdef MAXPATHLEN#define PATH_MAX MAXPATHLEN#else#define PATH_MAX 1024#endif#endif#endifstatic Bool StillLocking = FALSE;static char LockFile[PATH_MAX];/* * LockServer -- *      Check if the server lock file exists.  If so, check if the PID *      contained inside is valid.  If so, then die.  Otherwise, create *      the lock file containing the PID. */voidLockServer(){#ifndef AMOEBA  char tmp[PATH_MAX], pid_str[12];  int lfd, i, haslock, l_pid, t;  char *tmppath = NULL;  int len;  if (nolock) return;  /*   * Path names   */#ifndef __EMX__  tmppath = LOCK_DIR;#else  /* OS/2 uses TMP directory, must also prepare for 8.3 names */  tmppath = getenv("TMP");  if (!tmppath)    FatalError("No TMP dir found\n");#endif  len = strlen(LOCK_PREFIX) > strlen(LOCK_TMP_PREFIX) ? strlen(LOCK_PREFIX) :						strlen(LOCK_TMP_PREFIX);  len += strlen(tmppath) + strlen(display) + strlen(LOCK_SUFFIX) + 1;  if (len > sizeof(LockFile))    FatalError("Display name `%s' is too long\n");  (void)sprintf(tmp, "%s" LOCK_TMP_PREFIX "%s" LOCK_SUFFIX, tmppath, display);  (void)sprintf(LockFile, "%s" LOCK_PREFIX "%s" LOCK_SUFFIX, tmppath, display);  /*   * 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);    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)    FatalError("Could not create lock file in %s\n", tmp);  (void) sprintf(pid_str, "%10d\n", getpid());  (void) write(lfd, pid_str, 11);#ifndef __EMX__#ifndef USE_CHMOD  (void) fchmod(lfd, 0444);#else  (void) chmod(tmp, 0444);#endif#endif  (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);      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",		   display, "\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 /* !AMOEBA */}/* * UnlockServer -- *      Remove the server lock file. */voidUnlockServer(){#ifndef AMOEBA  if (nolock) return;  if (!StillLocking){#ifdef __EMX__  (void) chmod(LockFile,S_IREAD|S_IWRITE);#endif /* __EMX__ */  (void) unlink(LockFile);  }#endif}#endif /* SERVER_LOCK *//* Force connections to close on SIGHUP from init *//*ARGSUSED*/SIGVALAutoResetServer (sig)    int sig;{    dispatchException |= DE_RESET;    isItTimeToYield = TRUE;#ifdef GPROF    chdir ("/tmp");    exit (0);#endif#if defined(SYSV) && defined(X_NOT_POSIX)    OsSignal (SIGHUP, AutoResetServer);#endif#ifdef AMOEBA    WakeUpMainThread();#endif}/* Force connections to close and then exit on SIGTERM, SIGINT *//*ARGSUSED*/SIGVALGiveUp(sig)    int sig;{    dispatchException |= DE_TERMINATE;    isItTimeToYield = TRUE;#if defined(SYSV) && defined(X_NOT_POSIX)    if (sig)	OsSignal(sig, SIG_IGN);#endif#ifdef AMOEBA    WakeUpMainThread();#endif}#if __GNUC__static void AbortServer() __attribute__((noreturn));#endifstatic voidAbortServer(){    extern void AbortDDX();    OsCleanup();    AbortDDX();    fflush(stderr);#ifdef AMOEBA    IOPCleanUp();#endif    if (CoreDump)	abort();    exit (1);}voidError(str)    char *str;{#ifdef AMOEBA    mu_lock(&print_lock);#endif    perror(str);#ifdef AMOEBA    mu_unlock(&print_lock);#endif}#ifndef DDXTIMECARD32GetTimeInMillis(){#ifndef AMOEBA    struct timeval  tp;    X_GETTIMEOFDAY(&tp);    return(tp.tv_sec * 1000) + (tp.tv_usec / 1000);#else    return sys_milli();#endif}#endifAdjustWaitForDelay (waitTime, newdelay)    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;    }    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(){#if !defined(AIXrt) && !defined(AIX386)#ifndef AMOEBA    ErrorF("use: X [:<display>] [option]\n");#else

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -