1
/* $XFree86: xc/programs/Xserver/os/osinit.c,v 3.29 2003/09/09 03:20:41 dawes Exp $ */
2
/***********************************************************
4
Copyright 1987, 1998 The Open Group
6
Permission to use, copy, modify, distribute, and sell this software and its
7
documentation for any purpose is hereby granted without fee, provided that
8
the above copyright notice appear in all copies and that both that
9
copyright notice and this permission notice appear in supporting
12
The above copyright notice and this permission notice shall be included in
13
all copies or substantial portions of the Software.
15
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
19
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
Except as contained in this notice, the name of The Open Group shall not be
23
used in advertising or otherwise to promote the sale, use or other dealings
24
in this Software without prior written authorization from The Open Group.
27
Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
31
Permission to use, copy, modify, and distribute this software and its
32
documentation for any purpose and without fee is hereby granted,
33
provided that the above copyright notice appear in all copies and that
34
both that copyright notice and this permission notice appear in
35
supporting documentation, and that the name of Digital not be
36
used in advertising or publicity pertaining to distribution of the
37
software without specific, written prior permission.
39
DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
40
ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
41
DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
42
ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
43
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
44
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
47
******************************************************************/
48
/* $Xorg: osinit.c,v 1.4 2001/02/09 02:05:23 xorgcvs Exp $ */
50
#ifdef HAVE_DIX_CONFIG_H
51
#include <dix-config.h>
61
#include "dixstruct.h"
66
#define PATH_MAX MAXPATHLEN
72
#if defined(Lynx) || defined(__SCO__)
76
#if !defined(SYSV) && !defined(WIN32) && !defined(Lynx) && !defined(QNX4)
77
#include <sys/resource.h>
81
#define ADMPATH "/usr/adm/X%smsgs"
86
int limitDataSpace = -1;
89
int limitStackSpace = -1;
95
Bool OsDelayInitColors = FALSE;
98
extern void xf86WrapperInit(void);
104
static Bool been_here = FALSE;
105
static char* admpath = ADMPATH;
106
static char* devnull = "/dev/null";
107
char fname[PATH_MAX];
117
#if !defined(__SCO__) && !defined(__CYGWIN__) && !defined(__UNIXWARE__)
122
* If a write of zero bytes to stderr returns non-zero, i.e. -1,
123
* then writing to stderr failed, and we'll write somewhere else
124
* instead. (Apparently this never happens in the Real World.)
126
if (write (2, fname, 0) == -1)
130
if (strlen (display) + strlen (admpath) + 1 < sizeof fname)
131
sprintf (fname, admpath, display);
133
strcpy (fname, devnull);
135
* uses stdio to avoid os dependencies here,
136
* a real os would use
137
* open (fname, O_WRONLY|O_APPEND|O_CREAT, 0666)
139
if (!(err = fopen (fname, "a+")))
140
err = fopen (devnull, "w");
141
if (err && (fileno(err) != 2)) {
142
dup2 (fileno (err), 2);
145
#if defined(SYSV) || defined(SVR4) || defined(__UNIXOS2__) || defined(WIN32) || defined(__CYGWIN__)
147
static char buf[BUFSIZ];
148
setvbuf (stderr, buf, _IOLBF, BUFSIZ);
159
#if !defined(SYSV) && !defined(WIN32)
160
if (getpgrp (0) == 0)
161
setpgrp (0, getpid ());
166
if (limitDataSpace >= 0)
170
if (!getrlimit(RLIMIT_DATA, &rlim))
172
if ((limitDataSpace > 0) && (limitDataSpace < rlim.rlim_max))
173
rlim.rlim_cur = limitDataSpace;
175
rlim.rlim_cur = rlim.rlim_max;
176
(void)setrlimit(RLIMIT_DATA, &rlim);
181
if (limitStackSpace >= 0)
185
if (!getrlimit(RLIMIT_STACK, &rlim))
187
if ((limitStackSpace > 0) && (limitStackSpace < rlim.rlim_max))
188
rlim.rlim_cur = limitStackSpace;
190
rlim.rlim_cur = rlim.rlim_max;
191
(void)setrlimit(RLIMIT_STACK, &rlim);
196
if (limitNoFile >= 0)
200
if (!getrlimit(RLIMIT_NOFILE, &rlim))
202
if ((limitNoFile > 0) && (limitNoFile < rlim.rlim_max))
203
rlim.rlim_cur = limitNoFile;
205
rlim.rlim_cur = rlim.rlim_max;
207
if (rlim.rlim_cur > MAXSOCKS)
208
rlim.rlim_cur = MAXSOCKS;
210
(void)setrlimit(RLIMIT_NOFILE, &rlim);
224
* No log file by default. OsVendorInit() should call LogInit() with the
225
* log file name if logging to a file is desired.
228
#ifdef SMART_SCHEDULE
229
if (!SmartScheduleDisable)
230
if (!SmartScheduleInit ())
231
SmartScheduleDisable = TRUE;
234
if (!OsDelayInitColors) OsInitColors();
238
OsCleanup(Bool terminating)