1 /***********************************************************
3 Copyright 1987, 1998 The Open Group
5 Permission to use, copy, modify, distribute, and sell this software and its
6 documentation for any purpose is hereby granted without fee, provided that
7 the above copyright notice appear in all copies and that both that
8 copyright notice and this permission notice appear in supporting
11 The above copyright notice and this permission notice shall be included in
12 all copies or substantial portions of the Software.
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 Except as contained in this notice, the name of The Open Group shall not be
22 used in advertising or otherwise to promote the sale, use or other dealings
23 in this Software without prior written authorization from The Open Group.
26 Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
30 Permission to use, copy, modify, and distribute this software and its
31 documentation for any purpose and without fee is hereby granted,
32 provided that the above copyright notice appear in all copies and that
33 both that copyright notice and this permission notice appear in
34 supporting documentation, and that the name of Digital not be
35 used in advertising or publicity pertaining to distribution of the
36 software without specific, written prior permission.
38 DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
39 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
40 DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
41 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
42 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
43 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
46 ******************************************************************/
48 #ifdef HAVE_DIX_CONFIG_H
49 #include <dix-config.h>
59 #include "dixstruct.h"
64 #define PATH_MAX MAXPATHLEN
70 #if defined(Lynx) || defined(__SCO__)
74 #if !defined(SYSV) && !defined(WIN32) && !defined(Lynx) && !defined(QNX4)
75 #include <sys/resource.h>
79 #define ADMPATH "/usr/adm/X%smsgs"
84 int limitDataSpace
= -1;
87 int limitStackSpace
= -1;
93 Bool OsDelayInitColors
= FALSE
;
98 static Bool been_here
= FALSE
;
99 static char* admpath
= ADMPATH
;
100 static char* devnull
= "/dev/null";
101 char fname
[PATH_MAX
];
108 #if !defined(__SCO__) && !defined(__CYGWIN__) && !defined(__UNIXWARE__)
113 * If a write of zero bytes to stderr returns non-zero, i.e. -1,
114 * then writing to stderr failed, and we'll write somewhere else
115 * instead. (Apparently this never happens in the Real World.)
117 if (write (2, fname
, 0) == -1)
121 if (strlen (display
) + strlen (admpath
) + 1 < sizeof fname
)
122 sprintf (fname
, admpath
, display
);
124 strcpy (fname
, devnull
);
126 * uses stdio to avoid os dependencies here,
127 * a real os would use
128 * open (fname, O_WRONLY|O_APPEND|O_CREAT, 0666)
130 if (!(err
= fopen (fname
, "a+")))
131 err
= fopen (devnull
, "w");
132 if (err
&& (fileno(err
) != 2)) {
133 dup2 (fileno (err
), 2);
136 #if defined(SYSV) || defined(SVR4) || defined(WIN32) || defined(__CYGWIN__)
138 static char buf
[BUFSIZ
];
139 setvbuf (stderr
, buf
, _IOLBF
, BUFSIZ
);
150 #if !defined(SYSV) && !defined(WIN32)
151 if (getpgrp (0) == 0)
152 setpgrp (0, getpid ());
157 if (limitDataSpace
>= 0)
161 if (!getrlimit(RLIMIT_DATA
, &rlim
))
163 if ((limitDataSpace
> 0) && (limitDataSpace
< rlim
.rlim_max
))
164 rlim
.rlim_cur
= limitDataSpace
;
166 rlim
.rlim_cur
= rlim
.rlim_max
;
167 (void)setrlimit(RLIMIT_DATA
, &rlim
);
172 if (limitStackSpace
>= 0)
176 if (!getrlimit(RLIMIT_STACK
, &rlim
))
178 if ((limitStackSpace
> 0) && (limitStackSpace
< rlim
.rlim_max
))
179 rlim
.rlim_cur
= limitStackSpace
;
181 rlim
.rlim_cur
= rlim
.rlim_max
;
182 (void)setrlimit(RLIMIT_STACK
, &rlim
);
187 if (limitNoFile
>= 0)
191 if (!getrlimit(RLIMIT_NOFILE
, &rlim
))
193 if ((limitNoFile
> 0) && (limitNoFile
< rlim
.rlim_max
))
194 rlim
.rlim_cur
= limitNoFile
;
196 rlim
.rlim_cur
= rlim
.rlim_max
;
198 if (rlim
.rlim_cur
> MAXSOCKS
)
199 rlim
.rlim_cur
= MAXSOCKS
;
201 (void)setrlimit(RLIMIT_NOFILE
, &rlim
);
215 * No log file by default. OsVendorInit() should call LogInit() with the
216 * log file name if logging to a file is desired.
219 #ifdef SMART_SCHEDULE
220 if (!SmartScheduleDisable
)
221 if (!SmartScheduleInit ())
222 SmartScheduleDisable
= TRUE
;
225 if (!OsDelayInitColors
) OsInitColors();
229 OsCleanup(Bool terminating
)