~ubuntu-branches/ubuntu/intrepid/xserver-xgl/intrepid

« back to all changes in this revision

Viewing changes to os/osinit.c

  • Committer: Bazaar Package Importer
  • Author(s): Matthew Garrett
  • Date: 2006-02-13 14:21:43 UTC
  • Revision ID: james.westby@ubuntu.com-20060213142143-mad6z9xzem7hzxz9
Tags: upstream-7.0.0
ImportĀ upstreamĀ versionĀ 7.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $XFree86: xc/programs/Xserver/os/osinit.c,v 3.29 2003/09/09 03:20:41 dawes Exp $ */
 
2
/***********************************************************
 
3
 
 
4
Copyright 1987, 1998  The Open Group
 
5
 
 
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
 
10
documentation.
 
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
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.
 
21
 
 
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.
 
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
/* $Xorg: osinit.c,v 1.4 2001/02/09 02:05:23 xorgcvs Exp $ */
 
49
 
 
50
#ifdef HAVE_DIX_CONFIG_H
 
51
#include <dix-config.h>
 
52
#endif
 
53
 
 
54
#include <stdio.h>
 
55
#include <X11/X.h>
 
56
#include "os.h"
 
57
#include "osdep.h"
 
58
#include <X11/Xos.h>
 
59
 
 
60
#ifdef SMART_SCHEDULE
 
61
#include "dixstruct.h"
 
62
#endif
 
63
 
 
64
#ifndef PATH_MAX
 
65
#ifdef MAXPATHLEN
 
66
#define PATH_MAX MAXPATHLEN
 
67
#else
 
68
#define PATH_MAX 1024
 
69
#endif
 
70
#endif
 
71
 
 
72
#if defined(Lynx) || defined(__SCO__)
 
73
#include <sys/wait.h>
 
74
#endif
 
75
 
 
76
#if !defined(SYSV) && !defined(WIN32) && !defined(Lynx) && !defined(QNX4)
 
77
#include <sys/resource.h>
 
78
#endif
 
79
 
 
80
#ifndef ADMPATH
 
81
#define ADMPATH "/usr/adm/X%smsgs"
 
82
#endif
 
83
 
 
84
extern char *display;
 
85
#ifdef RLIMIT_DATA
 
86
int limitDataSpace = -1;
 
87
#endif
 
88
#ifdef RLIMIT_STACK
 
89
int limitStackSpace = -1;
 
90
#endif
 
91
#ifdef RLIMIT_NOFILE
 
92
int limitNoFile = -1;
 
93
#endif
 
94
 
 
95
Bool OsDelayInitColors = FALSE;
 
96
 
 
97
#ifdef XFree86LOADER
 
98
extern void xf86WrapperInit(void);
 
99
#endif
 
100
 
 
101
void
 
102
OsInit(void)
 
103
{
 
104
    static Bool been_here = FALSE;
 
105
    static char* admpath = ADMPATH;
 
106
    static char* devnull = "/dev/null";
 
107
    char fname[PATH_MAX];
 
108
 
 
109
#ifdef macII
 
110
    set42sig();
 
111
#endif
 
112
 
 
113
    if (!been_here) {
 
114
#ifdef XFree86LOADER
 
115
        xf86WrapperInit();
 
116
#endif
 
117
#if !defined(__SCO__) && !defined(__CYGWIN__) && !defined(__UNIXWARE__)
 
118
        fclose(stdin);
 
119
        fclose(stdout);
 
120
#endif
 
121
        /* 
 
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.)
 
125
         */
 
126
        if (write (2, fname, 0) == -1) 
 
127
        {
 
128
            FILE *err;
 
129
 
 
130
            if (strlen (display) + strlen (admpath) + 1 < sizeof fname)
 
131
                sprintf (fname, admpath, display);
 
132
            else
 
133
                strcpy (fname, devnull);
 
134
            /*
 
135
             * uses stdio to avoid os dependencies here,
 
136
             * a real os would use
 
137
             *  open (fname, O_WRONLY|O_APPEND|O_CREAT, 0666)
 
138
             */
 
139
            if (!(err = fopen (fname, "a+")))
 
140
                err = fopen (devnull, "w");
 
141
            if (err && (fileno(err) != 2)) {
 
142
                dup2 (fileno (err), 2);
 
143
                fclose (err);
 
144
            }
 
145
#if defined(SYSV) || defined(SVR4) || defined(__UNIXOS2__) || defined(WIN32) || defined(__CYGWIN__)
 
146
            {
 
147
            static char buf[BUFSIZ];
 
148
            setvbuf (stderr, buf, _IOLBF, BUFSIZ);
 
149
            }
 
150
#else
 
151
            setlinebuf(stderr);
 
152
#endif
 
153
        }
 
154
 
 
155
#ifndef X_NOT_POSIX
 
156
        if (getpgrp () == 0)
 
157
            setpgid (0, 0);
 
158
#else
 
159
#if !defined(SYSV) && !defined(WIN32)
 
160
        if (getpgrp (0) == 0)
 
161
            setpgrp (0, getpid ());
 
162
#endif
 
163
#endif
 
164
 
 
165
#ifdef RLIMIT_DATA
 
166
        if (limitDataSpace >= 0)
 
167
        {
 
168
            struct rlimit       rlim;
 
169
 
 
170
            if (!getrlimit(RLIMIT_DATA, &rlim))
 
171
            {
 
172
                if ((limitDataSpace > 0) && (limitDataSpace < rlim.rlim_max))
 
173
                    rlim.rlim_cur = limitDataSpace;
 
174
                else
 
175
                    rlim.rlim_cur = rlim.rlim_max;
 
176
                (void)setrlimit(RLIMIT_DATA, &rlim);
 
177
            }
 
178
        }
 
179
#endif
 
180
#ifdef RLIMIT_STACK
 
181
        if (limitStackSpace >= 0)
 
182
        {
 
183
            struct rlimit       rlim;
 
184
 
 
185
            if (!getrlimit(RLIMIT_STACK, &rlim))
 
186
            {
 
187
                if ((limitStackSpace > 0) && (limitStackSpace < rlim.rlim_max))
 
188
                    rlim.rlim_cur = limitStackSpace;
 
189
                else
 
190
                    rlim.rlim_cur = rlim.rlim_max;
 
191
                (void)setrlimit(RLIMIT_STACK, &rlim);
 
192
            }
 
193
        }
 
194
#endif
 
195
#ifdef RLIMIT_NOFILE
 
196
        if (limitNoFile >= 0)
 
197
        {
 
198
            struct rlimit       rlim;
 
199
 
 
200
            if (!getrlimit(RLIMIT_NOFILE, &rlim))
 
201
            {
 
202
                if ((limitNoFile > 0) && (limitNoFile < rlim.rlim_max))
 
203
                    rlim.rlim_cur = limitNoFile;
 
204
                else
 
205
                    rlim.rlim_cur = rlim.rlim_max;
 
206
#if 0
 
207
                if (rlim.rlim_cur > MAXSOCKS)
 
208
                    rlim.rlim_cur = MAXSOCKS;
 
209
#endif
 
210
                (void)setrlimit(RLIMIT_NOFILE, &rlim);
 
211
            }
 
212
        }
 
213
#endif
 
214
#ifdef SERVER_LOCK
 
215
        LockServer();
 
216
#endif
 
217
        been_here = TRUE;
 
218
    }
 
219
    TimerInit();
 
220
#ifdef DDXOSINIT
 
221
    OsVendorInit();
 
222
#endif
 
223
    /*
 
224
     * No log file by default.  OsVendorInit() should call LogInit() with the
 
225
     * log file name if logging to a file is desired.
 
226
     */
 
227
    LogInit(NULL, NULL);
 
228
#ifdef SMART_SCHEDULE
 
229
    if (!SmartScheduleDisable)
 
230
        if (!SmartScheduleInit ())
 
231
            SmartScheduleDisable = TRUE;
 
232
#endif
 
233
    OsInitAllocator();
 
234
    if (!OsDelayInitColors) OsInitColors();
 
235
}
 
236
 
 
237
void
 
238
OsCleanup(Bool terminating)
 
239
{
 
240
#ifdef SERVER_LOCK
 
241
    if (terminating)
 
242
    {
 
243
        UnlockServer();
 
244
    }
 
245
#endif
 
246
}