]> git.sesse.net Git - rdpsrv/blob - Xserver/programs/Xserver/os/osinit.c
12f40b850f5b63002c333ab3b128e8a665f46549
[rdpsrv] / Xserver / programs / Xserver / os / osinit.c
1 /***********************************************************
2
3 Copyright (c) 1987  X Consortium
4
5 Permission is hereby granted, free of charge, to any person obtaining a copy
6 of this software and associated documentation files (the "Software"), to deal
7 in the Software without restriction, including without limitation the rights
8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 copies of the Software, and to permit persons to whom the Software is
10 furnished to do so, subject to the following conditions:
11
12 The above copyright notice and this permission notice shall be included in
13 all copies or substantial portions of the Software.
14
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 X CONSORTIUM 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.
21
22 Except as contained in this notice, the name of the X Consortium 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 X Consortium.
25
26
27 Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
28
29                         All Rights Reserved
30
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.  
38
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
45 SOFTWARE.
46
47 ******************************************************************/
48 /* $XConsortium: osinit.c /main/45 1996/12/02 10:23:13 lehors $ */
49 /* $XFree86: xc/programs/Xserver/os/osinit.c,v 3.12 1997/01/18 06:58:02 dawes Exp $ */
50
51 #include <stdio.h>
52 #include "X.h"
53 #include "os.h"
54 #include "osdep.h"
55 #include "Xos.h"
56
57 #ifndef PATH_MAX
58 #ifdef MAXPATHLEN
59 #define PATH_MAX MAXPATHLEN
60 #else
61 #define PATH_MAX 1024
62 #endif
63 #endif
64
65 #if !defined(SYSV) && !defined(AMOEBA) && !defined(_MINIX) && !defined(WIN32) && !defined(Lynx) || defined(hpux) || defined(AIXV4)
66 #include <sys/resource.h>
67 #endif
68
69 #ifndef ADMPATH
70 #define ADMPATH "/usr/adm/X%smsgs"
71 #endif
72
73 extern char *display;
74 #ifdef RLIMIT_DATA
75 int limitDataSpace = -1;
76 #endif
77 #ifdef RLIMIT_STACK
78 int limitStackSpace = -1;
79 #endif
80 #ifdef RLIMIT_NOFILE
81 int limitNoFile = -1;
82 #endif
83
84 Bool OsDelayInitColors = FALSE;
85
86 void
87 OsInit()
88 {
89 #ifndef AMOEBA
90     static Bool been_here = FALSE;
91     char fname[PATH_MAX];
92
93 #ifdef macII
94     set42sig();
95 #endif
96
97     if (!been_here) {
98 #if !defined(MINIX) && !defined(SCO)
99         fclose(stdin);
100         fclose(stdout);
101 #endif
102         /* hack test to decide where to log errors */
103         if (write (2, fname, 0)) 
104         {
105             FILE *err;
106             sprintf (fname, ADMPATH, display);
107             /*
108              * uses stdio to avoid os dependencies here,
109              * a real os would use
110              *  open (fname, O_WRONLY|O_APPEND|O_CREAT, 0666)
111              */
112             if (!(err = fopen (fname, "a+")))
113                 err = fopen ("/dev/null", "w");
114             if (err && (fileno(err) != 2)) {
115                 dup2 (fileno (err), 2);
116                 fclose (err);
117             }
118 #if defined(SYSV) || defined(SVR4) || defined(MINIX) || defined(__EMX__) || defined(WIN32)
119             {
120             static char buf[BUFSIZ];
121             setvbuf (stderr, buf, _IOLBF, BUFSIZ);
122             }
123 #else
124             setlinebuf(stderr);
125 #endif
126         }
127
128 #ifndef X_NOT_POSIX
129         if (getpgrp () == 0)
130             setpgid (0, 0);
131 #else
132 #if !defined(SYSV) && !defined(WIN32)
133         if (getpgrp (0) == 0)
134             setpgrp (0, getpid ());
135 #endif
136 #endif
137
138 #ifdef RLIMIT_DATA
139         if (limitDataSpace >= 0)
140         {
141             struct rlimit       rlim;
142
143             if (!getrlimit(RLIMIT_DATA, &rlim))
144             {
145                 if ((limitDataSpace > 0) && (limitDataSpace < rlim.rlim_max))
146                     rlim.rlim_cur = limitDataSpace;
147                 else
148                     rlim.rlim_cur = rlim.rlim_max;
149                 (void)setrlimit(RLIMIT_DATA, &rlim);
150             }
151         }
152 #endif
153 #ifdef RLIMIT_STACK
154         if (limitStackSpace >= 0)
155         {
156             struct rlimit       rlim;
157
158             if (!getrlimit(RLIMIT_STACK, &rlim))
159             {
160                 if ((limitStackSpace > 0) && (limitStackSpace < rlim.rlim_max))
161                     rlim.rlim_cur = limitStackSpace;
162                 else
163                     rlim.rlim_cur = rlim.rlim_max;
164                 (void)setrlimit(RLIMIT_STACK, &rlim);
165             }
166         }
167 #endif
168 #ifdef RLIMIT_NOFILE
169         if (limitNoFile >= 0)
170         {
171             struct rlimit       rlim;
172
173             if (!getrlimit(RLIMIT_NOFILE, &rlim))
174             {
175                 if ((limitNoFile > 0) && (limitNoFile < rlim.rlim_max))
176                     rlim.rlim_cur = limitNoFile;
177                 else
178                     rlim.rlim_cur = rlim.rlim_max;
179                 if (rlim.rlim_cur > MAXSOCKS)
180                     rlim.rlim_cur = MAXSOCKS;
181                 (void)setrlimit(RLIMIT_NOFILE, &rlim);
182             }
183         }
184 #endif
185 #ifdef SERVER_LOCK
186         LockServer();
187 #endif
188         been_here = TRUE;
189     }
190 #endif /* AMOEBA */
191     TimerInit();
192 #ifdef DDXOSINIT
193     OsVendorInit();
194 #endif
195     OsInitAllocator();
196     if (!OsDelayInitColors) OsInitColors();
197 }
198
199 void
200 OsCleanup()
201 {
202 #ifdef SERVER_LOCK
203     UnlockServer();
204 #endif
205 }