]> git.ipfire.org Git - thirdparty/cups.git/blob - scheduler/server.c
Add missing include files.
[thirdparty/cups.git] / scheduler / server.c
1 /*
2 * "$Id: server.c,v 1.2 2001/03/28 16:55:56 mike Exp $"
3 *
4 * Server start/stop routines for the Common UNIX Printing System (CUPS).
5 *
6 * Copyright 1997-2001 by Easy Software Products, all rights reserved.
7 *
8 * These coded instructions, statements, and computer programs are the
9 * property of Easy Software Products and are protected by Federal
10 * copyright law. Distribution and use rights are outlined in the file
11 * "LICENSE.txt" which should have been included with this file. If this
12 * file is missing or damaged please contact Easy Software Products
13 * at:
14 *
15 * Attn: CUPS Licensing Information
16 * Easy Software Products
17 * 44141 Airport View Drive, Suite 204
18 * Hollywood, Maryland 20636-3111 USA
19 *
20 * Voice: (301) 373-9603
21 * EMail: cups-info@cups.org
22 * WWW: http://www.cups.org
23 *
24 * Contents:
25 *
26 * StartServer() - Start the server.
27 * StopServer() - Stop the server.
28 */
29
30 /*
31 * Include necessary headers...
32 */
33
34 #include "cupsd.h"
35
36 #include <grp.h>
37
38 #ifdef HAVE_LIBSSL
39 # include <openssl/ssl.h>
40 # include <openssl/rand.h>
41 #endif /* HAVE_LIBSSL */
42
43
44 /*
45 * 'StartServer()' - Start the server.
46 */
47
48 void
49 StartServer(void)
50 {
51 #ifdef HAVE_LIBSSL
52 int i; /* Looping var */
53 struct timeval curtime; /* Current time in microseconds */
54 unsigned char data[1024]; /* Seed data */
55 #endif /* HAVE_LIBSSL */
56
57
58 #ifdef HAVE_LIBSSL
59 /*
60 * Initialize the encryption libraries...
61 */
62
63 SSL_library_init();
64 SSL_load_error_strings();
65
66 /*
67 * Using the current time is a dubious random seed, but on some systems
68 * it is the best we can do (on others, this seed isn't even used...)
69 */
70
71 gettimeofday(&curtime, NULL);
72 srand(curtime.tv_sec + curtime.tv_usec);
73
74 for (i = 0; i < sizeof(data); i ++)
75 data[i] = rand(); /* Yes, this is a poor source of random data... */
76
77 RAND_seed(&data, sizeof(data));
78 #endif /* HAVE_LIBSSL */
79
80 /*
81 * Startup all the networking stuff...
82 */
83
84 StartListening();
85 StartBrowsing();
86 StartPolling();
87
88 /*
89 * If the administrator has configured the server to run as an unpriviledged
90 * user, change to that user now...
91 */
92
93 if (RunAsUser)
94 {
95 setgid(Group);
96 setgroups(0, NULL);
97 setuid(User);
98 }
99 }
100
101
102 /*
103 * 'StopServer()' - Stop the server.
104 */
105
106 void
107 StopServer(void)
108 {
109 /*
110 * Close all network clients and stop all jobs...
111 */
112
113 CloseAllClients();
114 StopListening();
115 StopPolling();
116 StopBrowsing();
117
118 if (Clients != NULL)
119 {
120 free(Clients);
121 Clients = NULL;
122 }
123
124 StopAllJobs();
125
126 /*
127 * Close all log files...
128 */
129
130 if (AccessFile != NULL)
131 {
132 fclose(AccessFile);
133
134 AccessFile = NULL;
135 }
136
137 if (ErrorFile != NULL)
138 {
139 fclose(ErrorFile);
140
141 ErrorFile = NULL;
142 }
143
144 if (PageFile != NULL)
145 {
146 fclose(PageFile);
147
148 PageFile = NULL;
149 }
150
151 /*
152 * Clear the input and output sets...
153 */
154
155 FD_ZERO(&InputSet);
156 FD_ZERO(&OutputSet);
157 }
158
159
160 /*
161 * End of "$Id: server.c,v 1.2 2001/03/28 16:55:56 mike Exp $".
162 */