summaryrefslogtreecommitdiff
path: root/app/xfs/os
diff options
context:
space:
mode:
Diffstat (limited to 'app/xfs/os')
-rw-r--r--app/xfs/os/access.c53
-rw-r--r--app/xfs/os/config.c23
-rw-r--r--app/xfs/os/config.h3
-rw-r--r--app/xfs/os/configstr.h4
-rw-r--r--app/xfs/os/connection.c45
-rw-r--r--app/xfs/os/daemon.c106
-rw-r--r--app/xfs/os/error.c51
-rw-r--r--app/xfs/os/io.c22
-rw-r--r--app/xfs/os/osdep.h61
-rw-r--r--app/xfs/os/osglue.c28
-rw-r--r--app/xfs/os/osinit.c9
-rw-r--r--app/xfs/os/utils.c151
-rw-r--r--app/xfs/os/waitfor.c61
-rw-r--r--app/xfs/os/xfstrans.c79
14 files changed, 290 insertions, 406 deletions
diff --git a/app/xfs/os/access.c b/app/xfs/os/access.c
index c50072848..36c459cf3 100644
--- a/app/xfs/os/access.c
+++ b/app/xfs/os/access.c
@@ -1,4 +1,3 @@
-/* $Xorg: access.c,v 1.4 2001/02/09 02:05:44 xorgcvs Exp $ */
/*
Copyright 1990, 1991, 1998 The Open Group
@@ -43,68 +42,40 @@ in this Software without prior written authorization from The Open Group.
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
* THIS SOFTWARE.
*/
-/* $XFree86: xc/programs/xfs/os/access.c,v 3.7tsi Exp $ */
+
+#include "xfs-config.h"
#include <X11/Xos.h>
-#ifndef Lynx
#include <sys/param.h>
#include <sys/socket.h>
-#else
-#include <socket.h>
-#endif
#include <netdb.h>
#include <netinet/in.h>
#include "clientstr.h"
#include "misc.h"
#include "site.h"
-#include "accstr.h"
#include "osdep.h"
#include "osstruct.h"
-#include "accstr.h"
+#include "globals.h"
+#include "access.h"
long MaxClients = DEFAULT_CLIENT_LIMIT;
void
AccessSetConnectionLimit(int num)
{
- num++; /* take serverClient into account */
- if (num > MAXSOCKS) {
+ int newlim = num + 8; /* allow room for serverClient, logs, etc. */
+ int maxfd = sysconf(_SC_OPEN_MAX) - 1;
+
+ if ((maxfd < 0) || (maxfd > MAXSOCKS)) {
+ maxfd = MAXSOCKS;
+ }
+ if (newlim > maxfd) {
ErrorF("Client limit of %d too high; using default of %d\n",
num, DEFAULT_CLIENT_LIMIT);
return;
}
- MaxClients = num;
-}
-
-#ifdef NOTDEF
-/*
- * XXX
- *
- * needs massive amounts of OS-dependent work (big surprise)
- * needs IPv6 support as well
- */
-int
-GetHostAddress(HostAddress *addr)
-{
- char hname[64];
- struct hostent *hp;
-
- addr->addr_len = sizeof(struct in_addr);
- addr->address = (pointer) fsalloc(addr->addr_len);
- if (!addr->address)
- return FSBadAlloc;
- addr->type = HOST_AF_INET;
- gethostname(hname, sizeof(hname));
- hp = gethostbyname(hname);
- if (hp) {
- memmove( (char *) addr->address, (char *) hp->h_addr, addr->addr_len);
- } else {
- fsfree((char *) addr->address);
- return FSBadName;
- }
- return FSSuccess;
+ MaxClients = newlim;
}
-#endif
/* ARGSUSED */
int
diff --git a/app/xfs/os/config.c b/app/xfs/os/config.c
index 1abf2afff..298dc2f30 100644
--- a/app/xfs/os/config.c
+++ b/app/xfs/os/config.c
@@ -1,4 +1,3 @@
-/* $Xorg: config.c,v 1.4 2001/02/09 02:05:44 xorgcvs Exp $ */
/*
Copyright 1987, 1998 The Open Group
@@ -44,12 +43,9 @@ in this Software without prior written authorization from The Open Group.
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
- * $NCDXorg: @(#)config.c,v 4.6 1991/07/09 14:08:09 lemke Exp $
- *
*/
-/* $XFree86: xc/programs/xfs/os/config.c,v 3.15 2002/05/31 18:46:12 dawes Exp $ */
-#include <xfs-config.h>
+#include "xfs-config.h"
#include <stdio.h>
#include <stdlib.h>
@@ -68,6 +64,9 @@ in this Software without prior written authorization from The Open Group.
#include <X11/fonts/fontutil.h>
#include "difs.h"
+/* libXfont/src/bitmap/snfstr.h */
+extern void SnfSetFormat(int bit, int byte, int glyph, int scan);
+
static const char * const default_config_files[] = {
#ifdef DEFAULT_CONFIG_FILE
DEFAULT_CONFIG_FILE,
@@ -77,8 +76,6 @@ static const char * const default_config_files[] = {
NULL
};
-extern int portFromCmdline;
-
static char *font_catalogue = NULL;
static char *config_set_int(ConfigOptionPtr parm, char *val);
@@ -114,7 +111,7 @@ static ConfigOptionRec config_options[] = {
{"snf-format", config_set_snf_format},
{"trusted-clients", config_set_list},
{"use-syslog", config_set_bool},
- {(char *) 0, 0},
+ {NULL, NULL},
};
char *ConfigErrors[] = {
@@ -195,7 +192,7 @@ match_param_name(char *name)
}
pos = ((high + low) >> 1);
}
- return 0;
+ return NULL;
}
static int
@@ -334,7 +331,7 @@ char *__XFSRedirRoot(char *fname)
int
ReadConfigFile(const char *filename)
{
- FILE *fp;
+ FILE *fp = NULL;
int ret;
int len;
int i;
@@ -359,8 +356,12 @@ ReadConfigFile(const char *filename)
#ifdef __UNIXOS2__
filename = __XFSRedirRoot(filename);
#endif
- if ((fp = fopen(filename, "r")) != NULL)
+ if ((fp = fopen(filename, "r")) != NULL) {
+ if (configfilename == NULL) {
+ configfilename = strdup(filename); /* save for clones */
+ }
break;
+ }
}
if (fp == NULL) {
for (i = 0; default_config_files[i] != NULL; i++) {
diff --git a/app/xfs/os/config.h b/app/xfs/os/config.h
index ba6db45cb..1a4de08a4 100644
--- a/app/xfs/os/config.h
+++ b/app/xfs/os/config.h
@@ -1,4 +1,3 @@
-/* $Xorg: config.h,v 1.4 2001/02/09 02:05:44 xorgcvs Exp $ */
/*
Copyright 1987, 1998 The Open Group
@@ -44,8 +43,6 @@ in this Software without prior written authorization from The Open Group.
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
- * @(#)config.h 4.1 91/05/02
- *
*/
#ifndef _CONFIG_H_
diff --git a/app/xfs/os/configstr.h b/app/xfs/os/configstr.h
index 9c1a8afa1..0d55e2325 100644
--- a/app/xfs/os/configstr.h
+++ b/app/xfs/os/configstr.h
@@ -1,4 +1,3 @@
-/* $Xorg: configstr.h,v 1.4 2001/02/09 02:05:44 xorgcvs Exp $ */
/*
Copyright 1987, 1998 The Open Group
@@ -44,10 +43,7 @@ in this Software without prior written authorization from The Open Group.
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
- * @(#)configstr.h 4.1 91/05/02
- *
*/
-/* $XFree86: xc/programs/xfs/os/configstr.h,v 1.4 2001/01/17 23:45:32 dawes Exp $ */
#ifndef _CONFIGSTR_H_
#define _CONFIGSTR_H_
#include "config.h"
diff --git a/app/xfs/os/connection.c b/app/xfs/os/connection.c
index 2035312c7..bc35a6066 100644
--- a/app/xfs/os/connection.c
+++ b/app/xfs/os/connection.c
@@ -1,4 +1,3 @@
-/* $Xorg: connection.c,v 1.5 2001/02/09 02:05:44 xorgcvs Exp $ */
/*
* handles connections
*/
@@ -67,7 +66,8 @@ in this Software without prior written authorization from The Open Group.
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
* THIS SOFTWARE.
*/
-/* $XFree86: xc/programs/xfs/os/connection.c,v 3.25tsi Exp $ */
+
+#include "xfs-config.h"
#include <stdlib.h>
#include <X11/Xtrans/Xtrans.h>
@@ -76,16 +76,11 @@ in this Software without prior written authorization from The Open Group.
#include <stdio.h>
#include <errno.h>
#include <X11/Xos.h>
-#ifndef Lynx
#include <sys/param.h>
#include <sys/socket.h>
#ifndef __UNIXOS2__
#include <sys/uio.h>
#endif
-#else
-#include <socket.h>
-#include <uio.h>
-#endif
#include <signal.h>
#include <X11/fonts/FS.h>
@@ -161,6 +156,7 @@ StopListening(void)
ListenTransFds = NULL;
ListenTransConns = NULL;
+ ListenTransCount = 0;
}
/*
@@ -172,6 +168,7 @@ void
CreateSockets(int old_listen_count, OldListenRec *old_listen)
{
int i;
+ struct sigaction act;
FD_ZERO(&AllSockets);
FD_ZERO(&AllClients);
@@ -182,20 +179,9 @@ CreateSockets(int old_listen_count, OldListenRec *old_listen)
for (i = 0; i < MAXSOCKS; i++)
ConnectionTranslation[i] = 0;
-#ifdef XNO_SYSCONF /* should only be on FreeBSD 1.x and NetBSD 0.x */
-#undef _SC_OPEN_MAX
-#endif
-#ifdef _SC_OPEN_MAX
lastfdesc = sysconf(_SC_OPEN_MAX) - 1;
-#else
-#if defined(hpux) || defined(__UNIXOS2__)
- lastfdesc = _NFILE - 1;
-#else
- lastfdesc = getdtablesize() - 1;
-#endif /* hpux */
-#endif
- if (lastfdesc > MAXSOCKS) {
+ if ((lastfdesc < 0) || (lastfdesc > MAXSOCKS)) {
lastfdesc = MAXSOCKS;
}
@@ -261,13 +247,17 @@ CreateSockets(int old_listen_count, OldListenRec *old_listen)
FatalError("cannot establish any listening sockets\n");
/* set up all the signal handlers */
- signal(SIGPIPE, SIG_IGN);
- signal(SIGHUP, AutoResetServer);
- signal(SIGINT, GiveUp);
- signal(SIGTERM, GiveUp);
- signal(SIGUSR1, ServerReconfig);
- signal(SIGUSR2, ServerCacheFlush);
- signal(SIGCHLD, CleanupChild);
+ sigemptyset(&act.sa_mask);
+ act.sa_flags = SA_RESTART;
+#define HANDLE_SIGNAL(s, h) act.sa_handler = h; sigaction(s, &act, NULL)
+
+ HANDLE_SIGNAL(SIGPIPE, SIG_IGN);
+ HANDLE_SIGNAL(SIGHUP, AutoResetServer);
+ HANDLE_SIGNAL(SIGINT, GiveUp);
+ HANDLE_SIGNAL(SIGTERM, GiveUp);
+ HANDLE_SIGNAL(SIGUSR1, ServerReconfig);
+ HANDLE_SIGNAL(SIGUSR2, ServerCacheFlush);
+ HANDLE_SIGNAL(SIGCHLD, CleanupChild);
XFD_COPYSET (&WellKnownConnections, &AllSockets);
}
@@ -480,6 +470,9 @@ CloseDownConnection(ClientPtr client)
{
OsCommPtr oc = (OsCommPtr) client->osPrivate;
+ if (oc == NULL)
+ return;
+
if (oc->output && oc->output->count)
FlushClient(client, oc, (char *) NULL, 0, 0);
ConnectionTranslation[oc->fd] = 0;
diff --git a/app/xfs/os/daemon.c b/app/xfs/os/daemon.c
index 2b23de328..e1f826ee0 100644
--- a/app/xfs/os/daemon.c
+++ b/app/xfs/os/daemon.c
@@ -27,81 +27,33 @@ other dealings in this Software without prior written authorization
from the X Consortium.
*/
-/* $XFree86: xc/programs/xfs/os/daemon.c,v 1.12 2002/10/20 21:42:50 tsi Exp $ */
+
+#include "xfs-config.h"
#include <X11/Xos.h>
#include <sys/types.h>
#include <errno.h>
#include <stdlib.h>
-#if defined(USG)
-# include <termios.h>
-#else
-# include <sys/ioctl.h>
-#endif
-#ifdef hpux
-# include <sys/ptyio.h>
-#endif
-
-#ifdef X_NOT_POSIX
-# define Pid_t int
-#else
-# define Pid_t pid_t
-#endif
-
#include "os.h"
-#if defined(__GLIBC__) || defined(CSRG_BASED)
-#define HAS_DAEMON
-#endif
-
-#ifndef X_NOT_POSIX
-#define HAS_SETSID
-#endif
-
-#ifndef HAS_SETSID
-
-#define setsid() MySetsid()
-
-static Pid_t
-MySetsid(void)
-{
-#if defined(TIOCNOTTY) || defined(TCCLRCTTY) || defined(TIOCTTY)
- int fd;
-#endif
- int stat;
-
- fd = open("/dev/tty", O_RDWR);
- if (fd >= 0) {
-#if defined(USG) && defined(TCCLRCTTY)
- int zero = 0;
- (void) ioctl (fd, TCCLRCTTY, &zero);
-#elif (defined(SYSV) || defined(SVR4)) && defined(TIOCTTY)
- int zero = 0;
- (void) ioctl (i, TIOCTTY, &zero);
-#elif defined(TIOCNOTTY)
- (void) ioctl (i, TIOCNOTTY, (char *) 0); /* detach, BSD style */
-#endif
- close(fd);
- }
-
-#if defined(SYSV) || defined(__QNXNTO__)
- return setpgrp();
-#else
- return setpgid(0, getpid());
-#endif
-}
-
-#endif /* !HAS_SETSID */
-
-
/* detach */
void
-BecomeDaemon ()
+BecomeDaemon (void)
{
/* If our C library has the daemon() function, just use it. */
-#ifdef HAS_DAEMON
- daemon (0, 0);
+#ifdef HAVE_DAEMON
+ if (daemon (0, 0) < 0) {
+ /* error */
+ FatalError("daemon() failed, %s\n", strerror(errno));
+ }
+
+ /* Open/reopen log file on stderr */
+#ifdef USE_SYSLOG
+ if (!UseSyslog)
+#endif
+ CloseErrors();
+ InitErrors();
#else
switch (fork()) {
@@ -123,6 +75,14 @@ BecomeDaemon ()
chdir("/");
+ DetachStdio();
+#endif /* HAVE_DAEMON */
+}
+
+void
+DetachStdio (void)
+{
+ int nullfd;
close (0);
close (1);
close (2);
@@ -130,9 +90,21 @@ BecomeDaemon ()
/*
* Set up the standard file descriptors.
*/
- (void) open ("/dev/null", O_RDWR);
- (void) dup2 (0, 1);
- (void) dup2 (0, 2);
+ nullfd = open ("/dev/null", O_RDWR);
+ if (nullfd != 0) {
+ dup2(nullfd, 0);
+ close(nullfd);
+ }
+ dup2 (0, 1);
+
+#ifdef USE_SYSLOG
+ if (UseSyslog) {
+ dup2 (0, 2);
+ return;
+ }
+#endif
-#endif /* HAS_DAEMON */
+ /* open/reopen log file on stderr */
+ CloseErrors();
+ InitErrors();
}
diff --git a/app/xfs/os/error.c b/app/xfs/os/error.c
index 8c72a657c..d078f640c 100644
--- a/app/xfs/os/error.c
+++ b/app/xfs/os/error.c
@@ -1,4 +1,3 @@
-/* $Xorg: error.c,v 1.4 2001/02/09 02:05:44 xorgcvs Exp $ */
/*
* error message handling
*/
@@ -44,33 +43,14 @@ in this Software without prior written authorization from The Open Group.
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
* THIS SOFTWARE.
*/
-/* $XFree86: error.c,v 1.11 2002/10/15 01:45:03 dawes Exp $ */
+
+#include "xfs-config.h"
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <X11/Xos.h>
-#ifndef X_NOT_POSIX
-#ifdef _POSIX_SOURCE
-#include <limits.h>
-#else
-#define _POSIX_SOURCE
-#include <limits.h>
-#undef _POSIX_SOURCE
-#endif
-#endif
-#ifndef PATH_MAX
-#include <sys/param.h>
-#ifndef PATH_MAX
-#ifdef MAXPATHLEN
-#define PATH_MAX MAXPATHLEN
-#else
-#define PATH_MAX 1024
-#endif
-#endif
-#endif
-
#ifdef USE_SYSLOG
#include <syslog.h>
#endif
@@ -78,13 +58,11 @@ in this Software without prior written authorization from The Open Group.
#include <errno.h>
#include "misc.h"
-
-extern char *progname;
+#include "globals.h"
+#include "osdep.h"
Bool UseSyslog;
-#ifdef USE_SYSLOG
Bool log_open = FALSE;
-#endif
char ErrorFile[PATH_MAX];
static char CurrentErrorFile[PATH_MAX];
@@ -113,11 +91,13 @@ InitErrors(void)
}
#endif
- if (ErrorFile[0] && strcmp(CurrentErrorFile, ErrorFile) != 0) {
- i = creat(ErrorFile, 0666);
+ if (ErrorFile[0] &&
+ (!log_open || (strcmp(CurrentErrorFile, ErrorFile) != 0)) ) {
+ i = open(ErrorFile, O_WRONLY | O_APPEND | O_CREAT, 0666);
if (i != -1) {
dup2(i, 2);
close(i);
+ log_open = TRUE;
} else {
ErrorF("can't open error file \"%s\"\n", ErrorFile);
}
@@ -128,13 +108,26 @@ InitErrors(void)
void
CloseErrors(void)
{
+ int nullfd;
+
+ if (!log_open)
+ return;
+
+ log_open = FALSE;
+
#ifdef USE_SYSLOG
if (UseSyslog) {
closelog();
- log_open = FALSE;
return;
}
#endif
+
+ close (2);
+ nullfd = open ("/dev/null", O_RDWR);
+ if (nullfd != 2) {
+ dup2 (nullfd, 2);
+ close(nullfd);
+ }
}
void
diff --git a/app/xfs/os/io.c b/app/xfs/os/io.c
index a5603e24f..13c7fe47e 100644
--- a/app/xfs/os/io.c
+++ b/app/xfs/os/io.c
@@ -1,4 +1,3 @@
-/* $Xorg: io.c,v 1.5 2001/02/09 02:05:44 xorgcvs Exp $ */
/*
* i/o functions
*/
@@ -46,20 +45,17 @@ in this Software without prior written authorization from The Open Group.
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
* THIS SOFTWARE.
*/
-/* $XFree86: xc/programs/xfs/os/io.c,v 3.18 2001/12/14 20:01:41 dawes Exp $ */
+
+#include "xfs-config.h"
#include <X11/Xtrans/Xtrans.h>
#include <stdio.h>
#include <errno.h>
#include <sys/types.h>
-#ifndef Lynx
#include <sys/param.h>
#ifndef __UNIXOS2__
#include <sys/uio.h>
#endif
-#else
-#include <uio.h>
-#endif
#include <X11/fonts/FSproto.h>
#include "clientstr.h"
@@ -85,18 +81,6 @@ in this Software without prior written authorization from The Open Group.
#endif
-
-extern fd_set ClientsWithInput;
-extern fd_set ClientsWriteBlocked;
-extern fd_set OutputPending;
-
-extern long OutputBufferSize;
-
-extern int ConnectionTranslation[];
-
-extern Bool AnyClientsWriteBlocked;
-extern Bool NewOutputPending;
-
static int timesThisConnection = 0;
static ConnectionInputPtr FreeInputs = (ConnectionInputPtr) NULL;
static ConnectionOutputPtr FreeOutputs = (ConnectionOutputPtr) NULL;
@@ -628,7 +612,7 @@ AllocateInputBuffer(void)
fsfree(oci);
return (ConnectionInputPtr) NULL;
}
- oci->next = 0;
+ oci->next = NULL;
oci->size = BUFSIZE;
oci->bufptr = oci->buffer;
oci->bufcnt = 0;
diff --git a/app/xfs/os/osdep.h b/app/xfs/os/osdep.h
index 4b07b283e..d8799bec3 100644
--- a/app/xfs/os/osdep.h
+++ b/app/xfs/os/osdep.h
@@ -1,4 +1,3 @@
-/* $Xorg: osdep.h,v 1.4 2001/02/09 02:05:44 xorgcvs Exp $ */
/*
Copyright 1987, 1998 The Open Group
@@ -44,10 +43,7 @@ in this Software without prior written authorization from The Open Group.
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
- * @(#)osdep.h 4.1 5/2/91
- *
*/
-/* $XFree86: xc/programs/xfs/os/osdep.h,v 3.11 2001/12/14 20:01:41 dawes Exp $ */
#ifndef _OSDEP_H_
#define _OSDEP_H_
@@ -57,53 +53,26 @@ in this Software without prior written authorization from The Open Group.
#define BUFWATERMARK 8192
#define MAXBUFSIZE (1 << 15)
-#ifndef sgi /* SGI defines OPEN_MAX in a useless way */
-#ifndef X_NOT_POSIX
#ifdef _POSIX_SOURCE
-#include <limits.h>
+# include <limits.h>
#else
-#define _POSIX_SOURCE
-#include <limits.h>
-#undef _POSIX_SOURCE
-#endif
-#endif
+# define _POSIX_SOURCE
+# include <limits.h>
+# undef _POSIX_SOURCE
#endif
-
-#ifndef OPEN_MAX
-#if defined(__UNIXOS2__) || defined(__QNX__)
-#define OPEN_MAX 256
-#else
-#ifdef SVR4
-#define OPEN_MAX 128
-#else
#include <sys/param.h>
-#ifdef __GNU__
-#define OPEN_MAX (sysconf(_SC_OPEN_MAX))
-#endif /*__GNU__*/
-#ifndef OPEN_MAX
-#ifdef SCO325
-#define OPEN_MAX (sysconf(_SC_OPEN_MAX))
-#else
-#if defined(NOFILE) && !defined(NOFILES_MAX)
-#define OPEN_MAX NOFILE
-#else
-#define OPEN_MAX NOFILES_MAX
-#endif
-#endif
-#endif
-#endif
-#endif
-#endif
-#if defined(__GNU__) || defined(SCO325)
-#define MAXSOCKS 128
-#else /*__GNU__*/
-#if OPEN_MAX <= 128 /* 128 is value of MAXCLIENTS */
-#define MAXSOCKS (OPEN_MAX - 1)
-#else
-#define MAXSOCKS 128
-#endif
-#endif /*__GNU__*/
+#ifndef PATH_MAX
+# ifndef PATH_MAX
+# ifdef MAXPATHLEN
+# define PATH_MAX MAXPATHLEN
+# else
+# define PATH_MAX 1024
+# endif
+# endif
+#endif /* PATH_MAX */
+
+#define MAXSOCKS MAXCLIENTS
#include <stddef.h>
diff --git a/app/xfs/os/osglue.c b/app/xfs/os/osglue.c
index e1e9ef239..bcfce2f1f 100644
--- a/app/xfs/os/osglue.c
+++ b/app/xfs/os/osglue.c
@@ -1,4 +1,3 @@
-/* $Xorg: osglue.c,v 1.4 2001/02/09 02:05:44 xorgcvs Exp $ */
/*
Copyright 1987, 1998 The Open Group
@@ -44,10 +43,7 @@ in this Software without prior written authorization from The Open Group.
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
- * $NCDXorg: @(#)osglue.c,v 4.6 1991/07/09 14:07:30 lemke Exp $
- *
*/
-/* $XFree86: xc/programs/xfs/os/osglue.c,v 3.18 2002/10/15 01:45:03 dawes Exp $ */
/*
* this is miscellaneous OS specific stuff.
@@ -55,6 +51,8 @@ in this Software without prior written authorization from The Open Group.
* Catalogue support, alternate servers, and cloneing
*/
+#include "xfs-config.h"
+
#include <X11/Xtrans/Xtrans.h>
#include "osstruct.h"
#include <stdio.h>
@@ -64,18 +62,14 @@ in this Software without prior written authorization from The Open Group.
#ifdef __UNIXOS2__
#define _NFILE 256
#endif
+#include "globals.h"
+#include "osdep.h"
Bool drone_server = FALSE;
-extern char *progname;
-extern char *configfilename;
static int num_alts;
static AlternateServerPtr alt_servers = (AlternateServerPtr) 0;
-extern XtransConnInfo *ListenTransConns;
-extern int *ListenTransFds;
-extern int ListenTransCount;
-
/*
* XXX
*
@@ -301,18 +295,10 @@ CloneMyself(void)
old_listen_arg[0] = '\0';
-#ifdef XNO_SYSCONF /* should only be on FreeBSD 1.x and NetBSD 0.x */
-#undef _SC_OPEN_MAX
-#endif
-#ifdef _SC_OPEN_MAX
lastfdesc = sysconf(_SC_OPEN_MAX) - 1;
-#else
-#if defined(hpux) || defined(__UNIXOS2__)
- lastfdesc = _NFILE - 1;
-#else
- lastfdesc = getdtablesize() - 1;
-#endif /* hpux */
-#endif
+ if ( (lastfdesc < 0) || (lastfdesc > MAXSOCKS)) {
+ lastfdesc = MAXSOCKS;
+ }
NoticeF("attempting clone...\n");
chdir("/");
diff --git a/app/xfs/os/osinit.c b/app/xfs/os/osinit.c
index a12bb002d..dcefe2877 100644
--- a/app/xfs/os/osinit.c
+++ b/app/xfs/os/osinit.c
@@ -1,4 +1,3 @@
-/* $Xorg: osinit.c,v 1.4 2001/02/09 02:05:45 xorgcvs Exp $ */
/*
* os init code
*/
@@ -47,14 +46,12 @@ in this Software without prior written authorization from The Open Group.
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
- * @(#)osinit.c 4.3 5/7/91
- *
*/
-/* $XFree86: xc/programs/xfs/os/osinit.c,v 1.4 2001/01/17 23:45:33 dawes Exp $ */
-#include "os.h"
+#include "xfs-config.h"
-extern long LastReapTime;
+#include "os.h"
+#include "globals.h"
void
OsInit(void)
diff --git a/app/xfs/os/utils.c b/app/xfs/os/utils.c
index 5ee8b6e94..7714e7533 100644
--- a/app/xfs/os/utils.c
+++ b/app/xfs/os/utils.c
@@ -1,4 +1,3 @@
-/* $Xorg: utils.c,v 1.4 2001/02/09 02:05:45 xorgcvs Exp $ */
/*
* misc os utilities
*/
@@ -46,7 +45,8 @@ in this Software without prior written authorization from The Open Group.
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
* THIS SOFTWARE.
*/
-/* $XFree86: xc/programs/xfs/os/utils.c,v 3.20 2002/10/15 01:45:03 dawes Exp $ */
+
+#include "xfs-config.h"
#include <stdio.h>
#include <X11/Xos.h>
@@ -54,9 +54,6 @@ in this Software without prior written authorization from The Open Group.
#include "misc.h"
#include "globals.h"
#include <signal.h>
-#ifdef MEMBUG
-#include <util/memleak/memleak.h>
-#endif
#include <sys/wait.h>
#include <unistd.h>
#include <pwd.h>
@@ -65,40 +62,19 @@ in this Software without prior written authorization from The Open Group.
#include <sys/types.h>
#include <errno.h>
#include <string.h>
-
-#ifndef X_NOT_POSIX
-#ifdef _POSIX_SOURCE
-#include <limits.h>
-#else
-#define _POSIX_SOURCE
-#include <limits.h>
-#undef _POSIX_SOURCE
-#endif
-#endif /* X_NOT_POSIX */
-#ifndef PATH_MAX
-#include <sys/param.h>
-#ifndef PATH_MAX
-#ifdef MAXPATHLEN
-#define PATH_MAX MAXPATHLEN
-#else
-#define PATH_MAX 1024
-#endif
-#endif
-#endif /* PATH_MAX */
-
-#if defined(X_NOT_POSIX) && (defined(SYSV) || defined(SVR4))
-#define SIGNALS_RESET_WHEN_CAUGHT
-#endif
+#include "osdep.h"
#include <stdlib.h>
-extern char *configfilename;
static Bool dropPriv = FALSE; /* whether or not to drop root privileges */
#ifdef DEFAULT_DAEMON
static Bool becomeDaemon = TRUE; /* whether to become a daemon or not */
#else
static Bool becomeDaemon = FALSE; /* whether to become a daemon or not */
#endif
+#ifdef XFS_INETD
+static Bool runFromInetd = FALSE; /* whether we were run from inetd or not */
+#endif
static const char *userId = NULL;
char *progname;
Bool CloneSelf;
@@ -107,11 +83,10 @@ Bool portFromCmdline = FALSE;
OldListenRec *OldListen = NULL;
int OldListenCount = 0;
-#ifdef STDERR_FILENO
-# define WRITES write(STDERR_FILENO, s, strlen(s))
-#else
-# define WRITES write(fileno(stderr), s, strlen(s))
+#ifndef STDERR_FILENO
+# define STDERR_FILENO fileno(stderr)
#endif
+#define WRITES(s) write(STDERR_FILENO, s, strlen(s))
static char *pidFile = XFSPIDDIR "/xfs.pid";
static int pidFd;
@@ -119,7 +94,7 @@ static FILE *pidFilePtr;
static int StorePid (void);
/* ARGSUSED */
-SIGVAL
+void
AutoResetServer(int n)
{
int olderrno = errno;
@@ -131,14 +106,11 @@ AutoResetServer(int n)
dispatchException |= DE_RESET;
isItTimeToYield = TRUE;
-#ifdef SIGNALS_RESET_WHEN_CAUGHT
- signal(SIGHUP, AutoResetServer);
-#endif
errno = olderrno;
}
/* ARGSUSED */
-SIGVAL
+void
GiveUp(int n)
{
int olderrno = errno;
@@ -152,7 +124,7 @@ GiveUp(int n)
}
/* ARGSUSED */
-SIGVAL
+void
ServerReconfig(int n)
{
int olderrno = errno;
@@ -164,14 +136,11 @@ ServerReconfig(int n)
dispatchException |= DE_RECONFIG;
isItTimeToYield = TRUE;
-#ifdef SIGNALS_RESET_WHEN_CAUGHT
- signal(SIGUSR1, ServerReconfig);
-#endif
errno = olderrno;
}
/* ARGSUSED */
-SIGVAL
+void
ServerCacheFlush(int n)
{
int olderrno = errno;
@@ -183,27 +152,29 @@ ServerCacheFlush(int n)
dispatchException |= DE_FLUSH;
isItTimeToYield = TRUE;
-#ifdef SIGNALS_RESET_WHEN_CAUGHT
- signal(SIGUSR2, ServerCacheFlush);
-#endif
errno = olderrno;
}
/* ARGSUSED */
-SIGVAL
+void
CleanupChild(int n)
{
int olderrno = errno;
+ pid_t child;
#ifdef DEBUG
WRITES("got a child signal\n");
#endif
- wait(NULL);
+ while ( (child = waitpid((pid_t)-1, NULL, WNOHANG)) > 0 ) {
+#ifdef DEBUG
+ char msgbuf[64];
-#ifdef SIGNALS_RESET_WHEN_CAUGHT
- signal(SIGCHLD, CleanupChild);
+ snprintf(msgbuf, sizeof(msgbuf), " child %d exited\n", child);
+ WRITES(msgbuf);
#endif
+ }
+
errno = olderrno;
}
@@ -227,9 +198,7 @@ usage(void)
void
OsInitAllocator (void)
{
-#ifdef MEMBUG
- CheckMemory ();
-#endif
+ return;
}
@@ -339,6 +308,13 @@ ProcessCmdLine(int argc, char **argv)
becomeDaemon = TRUE;
} else if (!strcmp(argv[i], "-nodaemon")) {
becomeDaemon = FALSE;
+ } else if (!strcmp(argv[i], "-inetd")) {
+#ifdef XFS_INETD
+ runFromInetd = TRUE;
+#else
+ FatalError("-inetd specified, but xfs was not built"
+ " with inetd support\n");
+#endif
} else if (!strcmp(argv[i], "-user")) {
if (argv[i + 1])
userId = argv[++i];
@@ -350,16 +326,6 @@ ProcessCmdLine(int argc, char **argv)
else
usage();
}
-#ifdef MEMBUG
- else if ( strcmp( argv[i], "-alloc") == 0)
- {
- extern unsigned long MemoryFail;
- if(++i < argc)
- MemoryFail = atoi(argv[i]);
- else
- usage ();
- }
-#endif
else
usage();
}
@@ -370,11 +336,6 @@ ProcessCmdLine(int argc, char **argv)
unsigned long Must_have_memory;
-#ifdef MEMBUG
-#define MEM_FAIL_SCALE 100000
-unsigned long MemoryFail;
-
-#endif
/* FSalloc -- FS's internal memory allocator. Why does it return unsigned
* int * instead of the more common char *? Well, if you read K&R you'll
@@ -399,16 +360,8 @@ FSalloc (unsigned long amount)
amount++;
/* aligned extra on long word boundary */
amount = (amount + 3) & ~3;
-#ifdef MEMBUG
- if (!Must_have_memory && MemoryFail &&
- ((random() % MEM_FAIL_SCALE) < MemoryFail))
- return 0;
- if (ptr = (pointer)fmalloc(amount))
- return ptr;
-#else
if ((ptr = (pointer)malloc(amount)) != 0)
return ptr;
-#endif
if (Must_have_memory)
FatalError("out of memory\n");
return 0;
@@ -436,14 +389,6 @@ FScalloc (unsigned long amount)
pointer
FSrealloc (pointer ptr, unsigned long amount)
{
-#ifdef MEMBUG
- if (!Must_have_memory && MemoryFail &&
- ((random() % MEM_FAIL_SCALE) < MemoryFail))
- return 0;
- ptr = (pointer)frealloc((char *) ptr, amount);
- if (ptr)
- return ptr;
-#else
if ((long)amount <= 0)
{
if (ptr && !amount)
@@ -457,7 +402,6 @@ FSrealloc (pointer ptr, unsigned long amount)
ptr = (pointer)malloc(amount);
if (ptr)
return ptr;
-#endif
if (Must_have_memory)
FatalError("out of memory\n");
return 0;
@@ -471,13 +415,8 @@ FSrealloc (pointer ptr, unsigned long amount)
void
FSfree(pointer ptr)
{
-#ifdef MEMBUG
- if (ptr)
- ffree((char *)ptr);
-#else
if (ptr)
free((char *)ptr);
-#endif
}
#endif /* SPECIAL_MALLOC */
@@ -525,6 +464,36 @@ SetDaemonState(void)
{
int oldpid;
+#ifdef XFS_INETD
+ if (runFromInetd) {
+ int inetdListener;
+
+ /* fd's 0, 1, & 2 are the initial listen socket provided by inetd,
+ * so dup it and then clear them so stdin/out/err aren't in use.
+ */
+ inetdListener = dup(0);
+ if (inetdListener == -1) {
+ FatalError("failed to dup inetd socket: %s\n",
+ strerror(errno));
+ }
+ DetachStdio();
+
+ /* Setup & pass the inetd socket back through the connection setup
+ * code the same way as a cloned listening port
+ */
+ OldListenCount = 1;
+ OldListen = _FontTransGetInetdListenInfo (inetdListener);
+ if (OldListen == NULL) {
+ FatalError("failed to initialize OldListen to inetd socket: %s\n",
+ strerror(errno));
+ }
+ ListenPort = OldListen[0].portnum;
+ NoticeF("accepting listener from inetd on fd %d, port %d\n",
+ inetdListener, ListenPort);
+ return;
+ }
+#endif /* XFS_INETD */
+
if (becomeDaemon) {
BecomeDaemon();
if ((oldpid = StorePid ())) {
diff --git a/app/xfs/os/waitfor.c b/app/xfs/os/waitfor.c
index 09e30c87c..1a29a974f 100644
--- a/app/xfs/os/waitfor.c
+++ b/app/xfs/os/waitfor.c
@@ -1,4 +1,3 @@
-/* $Xorg: waitfor.c,v 1.4 2001/02/09 02:05:45 xorgcvs Exp $ */
/*
* waits for input
*/
@@ -47,18 +46,15 @@ in this Software without prior written authorization from The Open Group.
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
- * $NCDXorg: @(#)waitfor.c,v 4.5 1991/06/24 11:59:20 lemke Exp $
- *
*/
-/* $XFree86: xc/programs/xfs/os/waitfor.c,v 3.15 2001/12/14 20:01:41 dawes Exp $ */
+
+#include "xfs-config.h"
#include <X11/Xos.h> /* strings, time, etc */
#include <stdio.h>
#include <errno.h>
-#if !defined(Lynx)
#include <sys/param.h>
-#endif
#include "clientstr.h"
#include "globals.h"
@@ -70,24 +66,24 @@ in this Software without prior written authorization from The Open Group.
#define select(n,r,w,x,t) os2PseudoSelect(n,r,w,x,t)
#endif
-extern WorkQueuePtr workQueue;
-
+long LastReapTime;
-extern fd_set WellKnownConnections;
-extern fd_set LastSelectMask;
-extern fd_set WriteMask;
-extern fd_set ClientsWithInput;
-extern fd_set ClientsWriteBlocked;
-extern fd_set AllSockets;
-extern fd_set AllClients;
-extern fd_set OutputPending;
+/* like ffs, but uses fd_mask instead of int as argument, so it works
+ when fd_mask is longer than an int, such as common 64-bit platforms */
+static inline int
+xfd_ffs(fd_mask mask)
+{
+ int i;
-extern Bool AnyClientsWriteBlocked;
-extern Bool NewOutputPending;
+ if (!mask) return 0;
-extern int ConnectionTranslation[];
+ for (i = 1; !(mask & 1); i++)
+ {
+ mask >>= 1;
+ }
+ return i;
+}
-long LastReapTime;
/*
* wait_for_something
@@ -198,7 +194,7 @@ WaitForSomething(int *pClientsReady)
current_time = GetTimeInMillis();
for (i = 0; i < howmany(XFD_SETSIZE, NFDBITS); i++) {
while (clientsReadable.fds_bits[i]) {
- curclient = ffs(clientsReadable.fds_bits[i]) - 1;
+ curclient = xfd_ffs(clientsReadable.fds_bits[i]) - 1;
conn = ConnectionTranslation[curclient + (i << 5)];
clientsReadable.fds_bits[i] &= ~(((fd_mask)1L) << curclient);
client = clients[conn];
@@ -207,25 +203,14 @@ WaitForSomething(int *pClientsReady)
pClientsReady[nready++] = conn;
client->last_request_time = current_time;
client->clientGone = CLIENT_ALIVE;
+
+ if (nready >= MaxClients) {
+ /* pClientsReady buffer has no more room, get the
+ rest on the next time through select() loop */
+ return nready;
+ }
}
}
}
return nready;
}
-
-#if 0
-/*
- * This is not always a macro
- */
-int
-ANYSET(long *src)
-{
- int i;
-
- for (i = 0; i < howmany(XFD_SETSIZE, NFDBITS); i++)
- if (src[i])
- return (1);
- return (0);
-}
-
-#endif
diff --git a/app/xfs/os/xfstrans.c b/app/xfs/os/xfstrans.c
index f74a23a6b..b24e7ec0a 100644
--- a/app/xfs/os/xfstrans.c
+++ b/app/xfs/os/xfstrans.c
@@ -1,5 +1,5 @@
/*
- * $Id: xfstrans.c,v 1.2 2008/06/13 21:00:36 matthieu Exp $
+ * $Id: xfstrans.c,v 1.3 2009/10/10 10:12:49 matthieu Exp $
*
* Copyright © 2003 Keith Packard
*
@@ -24,8 +24,79 @@
#include <xfs-config.h>
-#define FONT_t
-#define TRANS_REOPEN
-#define TRANS_SERVER
+#define FONT_t 1
+#define TRANS_REOPEN 1
+#define TRANS_SERVER 1
#include <X11/Xtrans/transport.c>
+
+#ifdef XFS_INETD
+/* xfs special handling for listen socket passed from inetd */
+#include "misc.h"
+
+OldListenRec *
+TRANS(GetInetdListenInfo) (int fd)
+{
+ char *port = "0";
+ XtransConnInfo inetdCI;
+ OldListenRec *old_listen;
+ int portnum;
+
+ /* Create a XtransConnInfo struct for this connection */
+ inetdCI = TRANS(ReopenCOTSServer)(TRANS_SOCKET_TCP_INDEX, fd, port);
+
+ /* Fill in correct address/portnum */
+ TRANS(SocketINETGetAddr)(inetdCI);
+#ifdef AF_INET6
+ if ( ((struct sockaddr *)(inetdCI->addr))->sa_family == AF_INET6 )
+ portnum = ntohs(((struct sockaddr_in6 *)(inetdCI->addr))->sin6_port);
+ else
+#endif
+ portnum = ntohs(((struct sockaddr_in *)(inetdCI->addr))->sin_port);
+ inetdCI->port = xalloc(6); /* Base 10 integer <= 65535 + trailing NUL */
+ snprintf(inetdCI->port, 6, "%d", portnum);
+
+ /* Do the socket setup that xtrans normally takes care of in
+ * TRANS(SocketOpen) && TRANS(SocketCreateListener)
+ */
+ {
+ /*
+ * turn off TCP coalescence for INET sockets
+ */
+
+ int tmp = 1;
+ setsockopt (fd, IPPROTO_TCP, TCP_NODELAY,
+ (char *) &tmp, sizeof (int));
+ }
+#ifdef SO_DONTLINGER
+ setsockopt (fd, SOL_SOCKET, SO_DONTLINGER, NULL, 0);
+#else
+# ifdef SO_LINGER
+ {
+ static int linger[2] = { 0, 0 };
+ setsockopt (fd, SOL_SOCKET, SO_LINGER,
+ (char *) linger, sizeof (linger));
+ }
+# endif
+#endif
+
+ if (listen (fd, BACKLOG) < 0)
+ {
+ FatalError("listen() failed on inetd socket: %s\n",
+ strerror(errno));
+ }
+
+ /* Pass the inetd socket back through the connection setup code
+ * the same way as a cloned listening port
+ */
+ old_listen = malloc (sizeof (OldListenRec));
+ if (old_listen != NULL) {
+ TRANS(GetReopenInfo)(inetdCI, &(old_listen->trans_id),
+ &(old_listen->fd), &port);
+
+ old_listen->portnum = portnum;
+ }
+
+ return old_listen;
+}
+#endif /* XFS_INETD */