Bug Summary

File:d/nsmain.c
Warning:line 535, column 63
No call of chdir("/") immediately after chroot

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-unknown-linux-gnu -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name nsmain.c -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -fhalf-no-semantic-interposition -mframe-pointer=none -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fcoverage-compilation-dir=/home/isvv/naviserver/nsd -resource-dir /usr/local/lib/clang/15.0.0 -D _FORTIFY_SOURCE=2 -D NDEBUG -D SYSTEM_MALLOC -I ../include -I /usr/include/tcl8.6 -D HAVE_CONFIG_H -internal-isystem /usr/local/lib/clang/15.0.0/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/11/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O2 -std=c99 -fdebug-compilation-dir=/home/isvv/naviserver/nsd -ferror-limit 19 -stack-protector 2 -fgnuc-version=4.2.1 -vectorize-loops -vectorize-slp -analyzer-checker alpha -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/scan-build-2022-07-23-130959-11103-1 -x c nsmain.c
1/*
2 * The contents of this file are subject to the Mozilla Public License
3 * Version 1.1 (the "License"); you may not use this file except in
4 * compliance with the License. You may obtain a copy of the License at
5 * http://mozilla.org/.
6 *
7 * Software distributed under the License is distributed on an "AS IS"
8 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
9 * the License for the specific language governing rights and limitations
10 * under the License.
11 *
12 * The Original Code is AOLserver Code and related documentation
13 * distributed by AOL.
14 *
15 * The Initial Developer of the Original Code is America Online,
16 * Inc. Portions created by AOL are Copyright (C) 1999 America Online,
17 * Inc. All Rights Reserved.
18 *
19 * Alternatively, the contents of this file may be used under the terms
20 * of the GNU General Public License (the "GPL"), in which case the
21 * provisions of GPL are applicable instead of those above. If you wish
22 * to allow use of your version of this file only under the terms of the
23 * GPL and not to allow others to use your version of this file under the
24 * License, indicate your decision by deleting the provisions above and
25 * replace them with the notice and other provisions required by the GPL.
26 * If you do not delete the provisions above, a recipient may use your
27 * version of this file under either the License or the GPL.
28 */
29
30/*
31 * nsmain.c --
32 *
33 * NaviServer Ns_Main() startup routine.
34 */
35
36#include "nsd.h"
37
38/*
39 * The following structure is used to pass command line args to
40 * the command interpreter thread.
41 */
42
43typedef struct Args {
44 char **argv;
45 int argc;
46} Args;
47
48/*
49 * This one is used to better track run state
50 * when looking at the code
51 */
52
53typedef enum {
54 starting_state, /* == 0 */
55 running_state, /* == 1 */
56 stopping_state, /* == 2 */
57 exiting_state /* == 3 */
58} runState;
59
60/*
61 * Local functions defined in this file.
62 */
63
64static Ns_ThreadProc CmdThread;
65
66static void UsageError(const char *msg, ...) NS_GNUC_NONNULL(1)__attribute__((__nonnull__(1))) NS_GNUC_PRINTF(1, 2)__attribute__((__format__ (__printf__, 1, 2))) __attribute__(
(__nonnull__(1)))
NS_GNUC_NORETURN__attribute__((__noreturn__));
67static void UsageMsg(int exitCode) NS_GNUC_NORETURN__attribute__((__noreturn__));
68static void StatusMsg(runState state);
69static void LogTclVersion(void);
70static const char *MakePath(const char *file) NS_GNUC_NONNULL(1)__attribute__((__nonnull__(1)));
71static const char *SetCwd(const char *path) NS_GNUC_NONNULL(1)__attribute__((__nonnull__(1)));
72
73#if defined(STATIC_BUILD) && (STATIC_BUILD == 1)
74extern void NsthreadsInit();
75extern void NsdInit();
76#endif
77
78const char *NS_EMPTY_STRING = "";
79
80
81/*
82 *----------------------------------------------------------------------
83 *
84 * Ns_Main --
85 *
86 * The NaviServer startup routine called from main(). Startup is
87 * somewhat complicated to ensure certain things happen in the
88 * correct order.
89 *
90 * Results:
91 * Returns 0 to main() on final exit.
92 *
93 * Side effects:
94 * Many - read comments below.
95 *
96 *----------------------------------------------------------------------
97 */
98
99int
100Ns_Main(int argc, char *const* argv, Ns_ServerInitProc *initProc)
101{
102 Args cmd;
103 int sig, optionIndex;
104 Ns_Time timeout;
105 Ns_Set *set;
106 bool_Bool testMode = NS_FALSE0;
107 const char *configFileContent = NULL((void*)0);
108#ifndef _WIN32
109 bool_Bool debug = NS_FALSE0;
110 bool_Bool forked = NS_FALSE0;
111 char mode = '\0';
112 const char *root = NULL((void*)0), *garg = NULL((void*)0), *uarg = NULL((void*)0), *server = NULL((void*)0);
113 const char *bindargs = NULL((void*)0), *bindfile = NULL((void*)0);
114 Ns_Set *servers;
115 Ns_ReturnCode status;
116#else
117 /*
118 * The following variables are declared static so they
119 * preserve their values when Ns_Main is re-entered by
120 * the Win32 service control manager.
121 */
122 static char mode = '\0', *procname, *server = NULL((void*)0);
123 static Ns_Set *servers;
124#endif
125
126 /*
127 * Before doing anything else, initialize the Tcl API
128 * as we rely heavily on it, even for the most basic
129 * functions like memory allocation.
130 */
131
132 Tcl_FindExecutable(argv[0]);
133
134 /*
135 * Initialize the Nsd library.
136 */
137
138 Nsd_LibInit();
139
140 /*
141 * Mark the server stopped until initialization is complete.
142 */
143
144 Ns_MutexLock(&nsconf.state.lock);
145 nsconf.state.started = NS_FALSE0;
146 Ns_MutexUnlock(&nsconf.state.lock);
147
148 /*
149 * When run as a Win32 service, Ns_Main will be re-entered
150 * in the service main thread. In this case, jump past the
151 * point where the initial thread blocked when connected to
152 * the service control manager.
153 */
154
155#ifdef _WIN32
156 if (mode == 'S') {
157 Ns_ThreadSetName("-service-");
158 goto contservice;
159 }
160#endif
161
162 nsconf.argv0 = argv[0];
163
164 /*
165 * Parse the command line arguments.
166 */
167
168 for (optionIndex = 1; optionIndex < argc; optionIndex++) {
1
Assuming 'optionIndex' is < 'argc'
2
Loop condition is true. Entering loop body
9
Assuming 'optionIndex' is >= 'argc'
10
Loop condition is false. Execution continues on line 270
169 if (argv[optionIndex][0] != '-') {
3
Assuming the condition is false
4
Taking false branch
170 break;
171 }
172 switch (argv[optionIndex][1]) {
5
Control jumps to 'case 114:' at line 241
173 case 'h':
174 UsageMsg(0);
175
176 case 'c': NS_FALL_THROUGH((void)0); /* fall through */
177 case 'f': NS_FALL_THROUGH((void)0); /* fall through */
178#ifdef _WIN32
179 case 'I': NS_FALL_THROUGH((void)0); /* fall through */
180 case 'R': NS_FALL_THROUGH((void)0); /* fall through */
181 case 'S': NS_FALL_THROUGH((void)0); /* fall through */
182#else
183 case 'i': NS_FALL_THROUGH((void)0); /* fall through */
184 case 'w': NS_FALL_THROUGH((void)0); /* fall through */
185#endif
186 case 'V':
187 if (mode != '\0') {
188#ifdef _WIN32
189 UsageError("only one of the options -c, -f, -I, -R, -S or -V"
190 " may be specified");
191#else
192 UsageError("only one of the options -c, -f, -i, -w or -V"
193 " may be specified");
194#endif
195 }
196 mode = argv[optionIndex][1];
197 break;
198 case 's':
199 if (server != NULL((void*)0)) {
200 UsageError("multiple -s <server> options");
201 }
202 if (optionIndex + 1 < argc) {
203 server = argv[++optionIndex];
204 } else {
205 UsageError("no parameter for -s option");
206 }
207 break;
208 case 't':
209 if (nsconf.configFile != NULL((void*)0)) {
210 UsageError("multiple -t <file> options");
211 }
212 if (optionIndex + 1 < argc) {
213 nsconf.configFile = argv[++optionIndex];
214 } else {
215 UsageError("no parameter for -t option");
216 }
217 break;
218 case 'T':
219 testMode = NS_TRUE1;
220 break;
221
222 case 'p':
223 case 'z':
224 /* NB: Ignored. */
225 break;
226#ifndef _WIN32
227 case 'b':
228 if (optionIndex + 1 < argc) {
229 bindargs = argv[++optionIndex];
230 } else {
231 UsageError("no parameter for -b option");
232 }
233 break;
234 case 'B':
235 if (optionIndex + 1 < argc) {
236 bindfile = argv[++optionIndex];
237 } else {
238 UsageError("no parameter for -B option");
239 }
240 break;
241 case 'r':
242 if (optionIndex + 1 < argc) {
6
Assuming the condition is true
7
Taking true branch
243 root = argv[++optionIndex];
244 } else {
245 UsageError("no parameter for -r option");
246 }
247 break;
8
Execution continues on line 168
248 case 'd':
249 debug = NS_TRUE1;
250 break;
251 case 'g':
252 if (optionIndex + 1 < argc) {
253 garg = argv[++optionIndex];
254 } else {
255 UsageError("no parameter for -g option");
256 }
257 break;
258 case 'u':
259 if (optionIndex + 1 < argc) {
260 uarg = argv[++optionIndex];
261 } else {
262 UsageError("no parameter for -u option");
263 }
264 break;
265#endif
266 default:
267 UsageError("invalid option: -%c", argv[optionIndex][1]);
268 }
269 }
270 if (mode == 'V') {
11
Taking false branch
271 printf("%s/%s\n", PACKAGE_NAME, PACKAGE_VERSION)__printf_chk (2 - 1, "%s/%s\n", "NaviServer", "4.99.24");
272 printf(" Tag: %s\n", Ns_InfoTag())__printf_chk (2 - 1, " Tag: %s\n", Ns_InfoTag()
)
;
273 printf(" Built: %s\n", Ns_InfoBuildDate())__printf_chk (2 - 1, " Built: %s\n", Ns_InfoBuildDate
())
;
274 printf(" Tcl version: %s\n", nsconf.tcl.version)__printf_chk (2 - 1, " Tcl version: %s\n", nsconf.tcl.version
)
;
275 printf(" Platform: %s\n", Ns_InfoPlatform())__printf_chk (2 - 1, " Platform: %s\n", Ns_InfoPlatform
())
;
276 return 0;
277 }
278
279 if (testMode
11.1
'testMode' is false
) {
12
Taking false branch
280 const char *fileContent;
281
282 if (nsconf.configFile == NULL((void*)0)) {
283 UsageError("option -t <file> must be provided, when -T is used");
284 }
285 fileContent = NsConfigRead(nsconf.configFile);
286 if (fileContent != NULL((void*)0)) {
287
288 /*
289 * Evaluate the configuration file.
290 */
291 NsConfigEval(fileContent, nsconf.configFile, argc, argv, optionIndex);
292
293 printf("%s/%s: configuration file %s looks OK\n",__printf_chk (2 - 1, "%s/%s: configuration file %s looks OK\n"
, "NaviServer", "4.99.24", nsconf.configFile)
294 PACKAGE_NAME, PACKAGE_VERSION, nsconf.configFile)__printf_chk (2 - 1, "%s/%s: configuration file %s looks OK\n"
, "NaviServer", "4.99.24", nsconf.configFile)
;
295
296 ns_free((char *)fileContent);
297 }
298 return 0;
299 }
300
301 if (mode == 'c') {
13
Taking false branch
302 int i;
303
304 cmd.argv = ns_calloc(((size_t)argc - (size_t)optionIndex) + 2u, sizeof(char *));
305 cmd.argc = 0;
306 cmd.argv[cmd.argc++] = argv[0];
307 for (i = optionIndex; i < argc; i++) {
308 cmd.argv[cmd.argc++] = argv[i];
309 }
310 Ns_ThreadCreate(CmdThread, &cmd, 0, NULL((void*)0));
311 }
312
313#ifndef _WIN32
314
315 /*
316 * If running as privileged user (root) check given user/group
317 * information and bail-out if any of them not really known.
318 */
319
320 if (getuid() == 0) {
14
Assuming the condition is false
321
322 /*
323 * OK, so the caller is running as root. In such cases
324 * he/she should have used "-u" to give the actual user
325 * to run as (may be root as well) and optionally "-g"
326 * to set the process group.
327 */
328
329 if (uarg == NULL((void*)0)) {
330 Ns_Fatal("nsmain: will not run without valid user; "
331 "must specify '-u username' parameter");
332 }
333 }
334
335 /*
336 * Fork into the background
337 */
338
339 if (mode
14.1
'mode' is equal to 0
== 0 || mode == 'w') {
340#ifdef HAVE_COREFOUNDATION
341 Ns_Fatal("nsmain: Tcl compiled with Core Foundation support does not support forking modes; "
342 "use e.g. the '-i' mode parameter in the command line.\n");
343#else
344 int i;
345
346 if (mode != 'w') {
15
Taking true branch
347 /*
348 * Unless we are in watchdog mode, setup pipe for realizing
349 * nonzero return codes in case setup fails.
350 *
351 * Background: The pipe is used for communicating problems during
352 * startup from the child process to return nonzero return codes
353 * in case the server does not start up. However, the watchdog
354 * mode restarts the child if necessary, so the pipe to the child
355 * can't be used.
356 */
357 ns_pipe(nsconf.state.pipefd);
358 }
359
360 i = ns_fork();
361 if (i == -1) {
16
Assuming the condition is false
17
Taking false branch
362 Ns_Fatal("nsmain: fork() failed: '%s'", strerror(errno(*__errno_location ())));
363 }
364 if (i > 0) {
18
Assuming 'i' is <= 0
19
Taking false branch
365 /*
366 * We are in the parent process.
367 */
368 int exit_code;
369
370 /*
371 * Pipe communication between parent and child communication is
372 * NOT established in watchdog mode.
373 */
374 if (mode != 'w') {
375 char buf = '\0';
376 ssize_t nread;
377
378 /*
379 * Close the write-end of the pipe, we do not use it
380 */
381 ns_closeclose(nsconf.state.pipefd[1]);
382 nsconf.state.pipefd[1] = 0;
383
384 Ns_Log(Debug, "nsmain: wait for feedback from forked child, read from fd %d",
385 nsconf.state.pipefd[0]);
386
387 /*
388 * Read the status from the child process. We expect as result
389 * either 'O' (when initialization went OK) or 'F' (for Fatal).
390 */
391 nread = ns_readread(nsconf.state.pipefd[0], &buf, 1);
392 if (nread < 0) {
393 /*
394 * Do nothing, even when the read fails
395 */
396 ;
397 Ns_Log(Warning, "nsmain: received no feedback from child process, error: %s", strerror(errno(*__errno_location ())));
398 }
399 Ns_Log(Debug, "nsmain: received from child %" PRIdz"zd" " bytes", nread);
400 ns_closeclose(nsconf.state.pipefd[0]);
401 nsconf.state.pipefd[0] = 0;
402 exit_code = (buf == 'O') ? 0 : 1;
403
404 } else {
405 /*
406 * If we are not in watchdog mode, the parent will return
407 * after a successful for always with 0.
408 */
409 exit_code = 0;
410 }
411
412 return exit_code;
413 }
414 /*
415 * We are in the child process.
416 */
417 if (mode != 'w') {
20
Taking true branch
418 /*
419 * Unless we are in the watchdog mode, close the read-end of the
420 * pipe, we do not use it.
421 */
422 ns_closeclose(nsconf.state.pipefd[0]);
423 nsconf.state.pipefd[0] = 0;
424 }
425
426 forked = NS_TRUE1;
427 setsid(); /* Detach from the controlling terminal device */
428#endif
429 }
430
431 /*
432 * For watchdog mode, start the watchdog/server process pair.
433 * The watchdog will monitor and restart the server unless the
434 * server exits gracefully, either by calling exit(0) or get
435 * signaled by the SIGTERM signal.
436 * The watchdog itself will exit when the server exits gracefully,
437 * or, when get signaled by the SIGTERM signal. In the latter
438 * case, watchdog will pass the SIGTERM to the server, so both of
439 * them will gracefully exit.
440 */
441
442 if (mode == 'w') {
21
Taking false branch
443 if (NsForkWatchedProcess() == 0) {
444 /*
445 * Watchdog exiting. We're done.
446 */
447 return 0;
448 }
449
450 /*
451 * Continue as watched server process.
452 */
453 forked = NS_TRUE1;
454 }
455
456 /*
457 * Keep up the C-compatibility with Tcl 8.4.
458 */
459
460 if (forked
21.1
'forked' is true
) {
22
Taking true branch
461 int major, minor;
462
463 Tcl_GetVersion(&major, &minor, NULL((void*)0), NULL((void*)0));
464 if (major == 8 && minor <= 4) {
23
Assuming 'major' is not equal to 8
465
466 /*
467 * For Tcl versions up to (and including the) Tcl 8.4
468 * we need to re-init the notifier after the fork.
469 * Failing to do so will make Tcl_ThreadAlert (et.al.)
470 * unusable since the notifier subsystem may not be
471 * initialized. The problematic behavior may be exibited
472 * for any loadable module that creates threads using the
473 * Tcl API but never calls directly into Tcl_CreateInterp
474 * that handles the notifier initialization indirectly.
475 */
476
477 Tcl_InitNotifier();
478 }
479 }
480
481 nsconf.pid = getpid();
482
483 /*
484 * Block all signals for the duration of startup to ensure any new
485 * threads inherit the blocked state.
486 */
487
488 NsBlockSignals(debug);
489
490#endif /* ! _WIN32 */
491
492 nsconf.nsd = ns_strdup(Tcl_GetNameOfExecutable());
493
494 /*
495 * Find and read configuration file, if given at the command line, just use it,
496 * if not specified, try to figure out by looking in the current dir for
497 * nsd.tcl and for ../conf/nsd.tcl
498 */
499
500 if (nsconf.configFile == NULL((void*)0)) {
24
Assuming field 'configFile' is not equal to NULL
25
Taking false branch
501 nsconf.configFile = MakePath("nsd.tcl");
502 if (nsconf.configFile == NULL((void*)0)) {
503 nsconf.configFile = MakePath("conf/nsd.tcl");
504 }
505 }
506
507 /*
508 * In case chroot has to be performed, we might not be able anymore to
509 * read the configuration file. So, we have to read it before issuing the
510 * chroot() command.
511 */
512 if (nsconf.configFile
25.1
Field 'configFile' is not equal to NULL
!= NULL((void*)0)) {
26
Taking true branch
513 configFileContent = NsConfigRead(nsconf.configFile);
514 }
515
516#ifndef _WIN32
517
518 if (bindargs
26.1
'bindargs' is equal to NULL
!= NULL((void*)0) || bindfile
26.2
'bindfile' is equal to NULL
!= NULL((void*)0)) {
27
Taking false branch
519 /*
520 * Pre-bind any sockets now, before a possible setuid from root
521 * or chroot which may hide /etc/resolv.conf required to resolve
522 * name-based addresses.
523 */
524 status = NsPreBind(bindargs, bindfile);
525 if (status != NS_OK) {
526 Ns_Fatal("nsmain: prebind failed");
527 }
528 }
529
530 /*
531 * Chroot() if requested before setuid from root.
532 */
533 if (root != NULL((void*)0)) {
28
Assuming 'root' is not equal to NULL
29
Taking true branch
534 if (chroot(root) != 0) {
30
Assuming the condition is true
31
Taking true branch
535 Ns_Fatal("nsmain: chroot(%s) failed: '%s'", root, strerror(errno(*__errno_location ())));
32
No call of chdir("/") immediately after chroot
536 }
537 nsconf.home = SetCwd("/");
538 }
539
540 /*
541 * If caller is running as the privileged user, change
542 * to the run time (given) user and/or group now.
543 */
544
545 if (getuid() == 0) {
546
547 /*
548 * Set or clear supplementary groups.
549 */
550
551 if (Ns_SetGroup(garg) == NS_ERROR) {
552 Ns_Fatal("nsmain: failed to switch to group %s", garg);
553 }
554
555 /*
556 * Before setuid, fork the background binder process to
557 * listen on ports which were not pre-bound above.
558 */
559 if (bindargs != NULL((void*)0) || bindfile != NULL((void*)0)) {
560 NsForkBinder();
561 }
562
563 if (Ns_SetUser(uarg) == NS_ERROR) {
564 Ns_Fatal("nsmain: failed to switch to user %s", uarg);
565 }
566 }
567
568#ifdef __linux1
569
570 /*
571 * On Linux, once a process changes uid/gid, the dumpable flag
572 * is cleared, preventing a core file from being written. On
573 * Linux 2.4+, it can be set again using prctl() so that we can
574 * get core files.
575 */
576
577 if (prctl(PR_SET_DUMPABLE4, 1, 0, 0, 0) < 0) {
578 Ns_Fatal("nsmain: prctl(PR_SET_DUMPABLE) failed: '%s'",
579 strerror(errno(*__errno_location ())));
580 }
581
582#endif /* __linux */
583
584#endif /* ! _WIN32 */
585
586 if (configFileContent != NULL((void*)0)) {
587 /*
588 * Evaluate the configuration file.
589 */
590 NsConfigEval(configFileContent, nsconf.configFile, argc, argv, optionIndex);
591 ns_free((char *)configFileContent);
592 }
593
594 /*
595 * This is the first place, where we can use values from the configuration file.
596 *
597 * Turn on logging of long mutex calls if desired. For whatever reason, we
598 * can't access NS_mutexlocktrace from here (unknown external symbol),
599 * although it is defined exactly like NS_finalshutdown;
600 */
601
602 /*
603 * Internationalized programs must call setlocale() to initiate specific
604 * language operations.
605 */
606 {
607 char *localeString = getenv("LC_ALL");
608 const char *source = "unknown source", *response;
609
610 if (localeString == NULL((void*)0)) {
611 source = "environment variable LC_COLLATE";
612 localeString = getenv("LC_COLLATE");
613 }
614 if (localeString == NULL((void*)0)) {
615 source = "environment variable LANG";
616 localeString = getenv("LANG");
617 }
618 if (localeString == NULL((void*)0)) {
619 source = "system-wide default locale";
620 localeString = setlocale(LC_COLLATE3, NULL((void*)0));
621 }
622
623 response = setlocale(LC_COLLATE3, localeString);
624 if (response != NULL((void*)0)) {
625#ifdef _WIN32
626 nsconf.locale = _create_locale(LC_COLLATE3, localeString);
627#else
628 nsconf.locale = newlocale(LC_COLLATE_MASK(1 << 3), localeString, (locale_t)0);
629#endif
630 }
631 if (nsconf.locale == 0) {
632 Ns_Fatal("nsmain: system configuration mismatch.\n"
633 "The provided locale '%s' based on the %s is not installed on this system.\n"
634 "On unix-like systems you can check the available locales with the command 'locale -a' .\n",
635 localeString, source);
636 }
637 Ns_Log(Notice, "initialized locale %s from %s", localeString, source);
638 }
639
640
641#ifndef _WIN32
642 NS_mutexlocktrace = Ns_ConfigBool(NS_GLOBAL_CONFIG_PARAMETERS"ns/parameters", "mutexlocktrace", NS_FALSE0);
643#endif
644
645 nsconf.formFallbackCharset = Ns_ConfigString(NS_GLOBAL_CONFIG_PARAMETERS"ns/parameters", "FormFallbackCharset", NULL((void*)0));
646 if (nsconf.formFallbackCharset != NULL((void*)0)
647 && *nsconf.formFallbackCharset == '\0') {
648 nsconf.formFallbackCharset = NULL((void*)0);
649 }
650
651 /*
652 * If no servers were defined, autocreate server "default"
653 * so all default config values will be used for that server
654 */
655
656 servers = Ns_ConfigGetSection("ns/servers");
657 if (servers == NULL((void*)0)) {
658 servers = Ns_ConfigCreateSection("ns/servers");
659 }
660 if (Ns_SetSize(servers)((servers)->size) == 0u) {
661 (void)Ns_SetPutSz(servers, "default", 7, "Default NaviServer", 18);
662 }
663
664 /*
665 * If a single server was specified, ensure it exists
666 * and update the pointer to the config string (the
667 * config server strings are considered the unique
668 * server "handles").
669 */
670
671 if (server != NULL((void*)0)) {
672 int i = Ns_SetFind(servers, server);
673 if (i < 0) {
674 Ns_Log(Error, "nsmain: no such server '%s' in configuration file '%s'",
675 server, nsconf.configFile);
676 Ns_Log(Warning, "nsmain: Writing the server names we DO have to stderr now:");
677 Ns_SetPrint(servers);
678 Ns_Fatal("nsmain: no such server '%s'", server);
679 }
680 server = Ns_SetKey(servers, i)((servers)->fields[(i)].name);
681 }
682
683 /*
684 * Verify and change to the home directory.
685 */
686
687 nsconf.home = Ns_ConfigGetValue(NS_GLOBAL_CONFIG_PARAMETERS"ns/parameters", "home");
688 if (nsconf.home == NULL((void*)0) && mode != 'c') {
689
690 /*
691 * We will try to figure out our installation directory from
692 * executable binary. Check if nsd is in bin/ subdirectory according
693 * to our make install, if true make our home one level up, otherwise
694 * make home directory where executable binary resides. All custom
695 * installation will require "home" config parameter to be specified
696 * in the nsd.tcl
697 */
698
699 nsconf.home = MakePath("");
700 if (nsconf.home == NULL((void*)0)) {
701 Ns_Fatal("nsmain: missing: [%s]home", NS_GLOBAL_CONFIG_PARAMETERS"ns/parameters");
702 }
703 } else if (nsconf.home == NULL((void*)0) /* && mode == 'c' */) {
704 /*
705 * Try to get HOME from environment variable NAVISERVER. If
706 * this is not defined, take the value from the path. Using
707 * NAVISERVER makes especially sense when testing or running
708 * nsd from the source directory.
709 */
710 nsconf.home = getenv("NAVISERVER");
711 if (nsconf.home == NULL((void*)0)) {
712 /*
713 * There is no such environment variable. Try, if we can get the
714 * home from the binary. In such cases, we expect to find
715 * "bin/init.tcl" under home.
716 */
717 const char *path = MakePath("bin/init.tcl");
718 if (path != NULL((void*)0)) {
719 /*
720 * Yep, we found it, use its parent directory.
721 */
722 nsconf.home = MakePath("");
723 } else {
724 /*
725 * Desperate fallback. Use the name of the configured install
726 * directory.
727 */
728 nsconf.home = NS_NAVISERVER"/usr/local/ns";
729 }
730 }
731 assert(nsconf.home != NULL)((void) (0));
732 }
733 nsconf.home = SetCwd(nsconf.home);
734 nsconf.reject_already_closed_connection =
735 Ns_ConfigBool(NS_GLOBAL_CONFIG_PARAMETERS"ns/parameters", "rejectalreadyclosedconn", NS_TRUE1);
736 nsconf.sanitize_logfiles =
737 Ns_ConfigIntRange(NS_GLOBAL_CONFIG_PARAMETERS"ns/parameters", "sanitizelogfiles", 2, 0, 2);
738 nsconf.reverseproxymode =
739 Ns_ConfigBool(NS_GLOBAL_CONFIG_PARAMETERS"ns/parameters", "reverseproxymode", NS_FALSE0);
740
741 {
742 /*
743 * Allow values like "none", or abbreviated to "no"), but be open for
744 * future enhancements like e.g. "cluster".
745 */
746 const char *cacheConfig = Ns_ConfigGetValue(NS_GLOBAL_CONFIG_PARAMETERS"ns/parameters", "cachingmode");
747 if (cacheConfig == NULL((void*)0)) {
748 nsconf.nocache = NS_FALSE0;
749 } else {
750 nsconf.nocache = (strncmp(cacheConfig, "no", 2) == 0);
751 }
752 }
753
754 /*
755 * Make the result queryable.
756 */
757
758 set = Ns_ConfigCreateSection(NS_GLOBAL_CONFIG_PARAMETERS"ns/parameters");
759 Ns_SetUpdateSz(set, "home", 4, nsconf.home, -1);
760
761 /*
762 * Update core config values.
763 */
764
765 NsConfUpdate();
766
767 nsconf.tmpDir = Ns_ConfigGetValue(NS_GLOBAL_CONFIG_PARAMETERS"ns/parameters", "tmpdir");
768 if (nsconf.tmpDir == NULL((void*)0)) {
769 nsconf.tmpDir = getenv("TMPDIR");
770 if (nsconf.tmpDir == NULL((void*)0)) {
771 nsconf.tmpDir = P_tmpdir"/tmp";
772 }
773 Ns_SetUpdateSz(set, "tmpdir", 6, nsconf.tmpDir, -1);
774 }
775
776#ifdef _WIN32
777
778 /*
779 * Set the procname used for the pid file.
780 */
781
782 procname = ((server != NULL((void*)0)) ? server : Ns_SetKey(servers, 0)((servers)->fields[(0)].name));
783
784 /*
785 * Connect to the service control manager if running
786 * as a service (see service comment above).
787 */
788
789 if (mode == 'I' || mode == 'R' || mode == 'S') {
790 Ns_ReturnCode status = NS_OK;
791
792 Ns_ThreadSetName("-service-");
793
794 switch (mode) {
795 case 'I':
796 status = NsInstallService(procname);
797 break;
798 case 'R':
799 status = NsRemoveService(procname);
800 break;
801 case 'S':
802 status = NsConnectService();
803 break;
804 default:
805 /* cannot happen */
806 assert(0)((void) (0));
807 break;
808 }
809 return (status == NS_OK ? 0 : 1);
810 }
811
812 contservice:
813
814#endif
815
816 /*
817 * Open the log file now that the home directory and run time
818 * user id have been set.
819 */
820
821 if (mode != 'c' && mode != 'f') {
822 NsLogOpen();
823 }
824
825 /*
826 * Log the first startup message which should be the first
827 * output to the open log file unless the config script
828 * generated some messages.
829 */
830
831 StatusMsg(starting_state);
832 LogTclVersion();
833
834#ifndef _WIN32
835 {
836 struct rlimit rl;
837
838 /*
839 * Log the current open file limit.
840 */
841 memset(&rl, 0, sizeof(rl));
842
843 if (getrlimit(RLIMIT_NOFILERLIMIT_NOFILE, &rl) != 0) {
844 Ns_Log(Warning, "nsmain: "
845 "getrlimit(RLIMIT_NOFILE) failed: '%s'", strerror(errno(*__errno_location ())));
846 } else {
847 char curBuffer[TCL_INTEGER_SPACE24], maxBuffer[TCL_INTEGER_SPACE24];
848
849 snprintf(curBuffer, sizeof(curBuffer), "%" PRIuMAX, (uintmax_t)rl.rlim_cur)__builtin___snprintf_chk (curBuffer, sizeof(curBuffer), 2 - 1
, __builtin_object_size (curBuffer, 2 > 1), "%" "l" "u", (
uintmax_t)rl.rlim_cur)
;
850 snprintf(maxBuffer, sizeof(maxBuffer), "%" PRIuMAX, (uintmax_t)rl.rlim_max)__builtin___snprintf_chk (maxBuffer, sizeof(maxBuffer), 2 - 1
, __builtin_object_size (maxBuffer, 2 > 1), "%" "l" "u", (
uintmax_t)rl.rlim_max)
;
851 Ns_Log(Notice, "nsmain: "
852 "max files: soft limit %s, hard limit %s",
853 (rl.rlim_cur == RLIM_INFINITY((__rlim_t) -1) ? "infinity" : curBuffer),
854 (rl.rlim_max == RLIM_INFINITY((__rlim_t) -1) ? "infinity" : maxBuffer)
855 );
856 if (rl.rlim_cur == RLIM_INFINITY((__rlim_t) -1)
857 || rl.rlim_cur > FD_SETSIZE1024) {
858 Ns_Log(Warning, "nsmain: current limit "
859 "of maximum number of files > FD_SETSIZE (%d), "
860 "select() calls should not be used",
861 FD_SETSIZE1024);
862 }
863 }
864 }
865#endif
866
867 /*
868 * Create the pid file.
869 */
870
871 NsCreatePidFile();
872
873 /*
874 * Initialize the virtual servers.
875 */
876
877 if (server != NULL((void*)0)) {
878 NsInitServer(server, initProc);
879 } else {
880 size_t i;
881
882 for (i = 0u; i < Ns_SetSize(servers)((servers)->size); ++i) {
883 server = Ns_SetKey(servers, i)((servers)->fields[(i)].name);
884 NsInitServer(server, initProc);
885
886 }
887 /*
888 * Make the first server the default server.
889 */
890 server = Ns_SetKey(servers, 0)((servers)->fields[(0)].name);
891 }
892 nsconf.defaultServer = server;
893
894 /*
895 * Initialize non-server static modules.
896 */
897
898 NsInitStaticModules(NULL((void*)0));
899
900 /*
901 * Run pre-startup procs
902 */
903
904 NsRunPreStartupProcs();
905
906 /*
907 * Map virtual servers. This requires that all servers and all drivers are
908 * initialized (can be found via global data structures). Drivers are
909 * created via NsRunPreStartupProcs().
910 */
911
912 NsDriverMapVirtualServers();
913
914 /*
915 * Start the servers and drivers.
916 */
917
918 NsStartServers();
919 NsStartDrivers();
920
921 /*
922 * Signal startup is complete.
923 */
924
925 StatusMsg(running_state);
926
927 Ns_MutexLock(&nsconf.state.lock);
928 nsconf.state.started = NS_TRUE1;
929 Ns_CondBroadcast(&nsconf.state.cond);
930 Ns_MutexUnlock(&nsconf.state.lock);
931
932 if (mode != 'w' && nsconf.state.pipefd[1] != 0) {
933 ssize_t nwrite;
934
935 /*
936 * Tell the parent process, that initialization went OK.
937 */
938 nwrite = ns_writewrite(nsconf.state.pipefd[1], "O", 1);
939 if (nwrite < 1) {
940 Ns_Fatal("nsmain: can't communicate with parent process, nwrite %" PRIdz"zd"
941 ", error: %s (parent process was probably killed)",
942 nwrite, strerror(errno(*__errno_location ())));
943 }
944 (void)ns_closeclose(nsconf.state.pipefd[1]);
945 nsconf.state.pipefd[1] = 0;
946 }
947
948 /*
949 * Run any post-startup procs.
950 */
951
952 NsRunStartupProcs();
953
954 /*
955 * Start the drivers now that the server appears ready
956 * and then close any remaining pre-bound sockets.
957 */
958
959#ifndef _WIN32
960 NsClosePreBound();
961 NsStopBinder();
962#endif
963
964 /*
965 * Once the drivers listen thread is started, this thread will just
966 * endlessly wait for Unix signals, calling NsRunSignalProcs()
967 * whenever SIGHUP arrives.
968 */
969
970 sig = NsHandleSignals();
971
972 /*
973 * Print a "server shutting down" status message, set
974 * the nsconf.stopping flag for any threads calling
975 * Ns_InfoShutdownPending(), and set the absolute
976 * timeout for all systems to complete shutdown.
977 * If SIGQUIT signal was sent, make immediate shutdown
978 * without waiting for all subsystems to exit gracefully
979 */
980
981 StatusMsg(stopping_state);
982
983 Ns_MutexLock(&nsconf.state.lock);
984 nsconf.state.stopping = NS_TRUE1;
985 if (sig == NS_SIGQUIT(3)) {
986 nsconf.shutdowntimeout.sec = 0;
987 nsconf.shutdowntimeout.usec = 0;
988 }
989 Ns_GetTime(&timeout);
990 Ns_IncrTime(&timeout, nsconf.shutdowntimeout.sec, nsconf.shutdowntimeout.usec);
991 Ns_MutexUnlock(&nsconf.state.lock);
992
993 /*
994 * First, stop the drivers and servers threads.
995 */
996
997 NsStopDrivers();
998 NsStopServers(&timeout);
999 NsStopSpoolers();
1000
1001 /*
1002 * Next, start simultaneous shutdown in other systems and wait
1003 * for them to complete.
1004 */
1005
1006 NsStartSchedShutdown();
1007 NsStartSockShutdown();
1008 NsStartTaskQueueShutdown();
1009 NsStartJobsShutdown();
1010 NsStartShutdownProcs();
1011
1012 NsWaitSchedShutdown(&timeout);
1013 NsWaitSockShutdown(&timeout);
1014 NsWaitTaskQueueShutdown(&timeout);
1015 NsWaitJobsShutdown(&timeout);
1016 NsWaitDriversShutdown(&timeout);
1017 NsWaitShutdownProcs(&timeout);
1018
1019 /*
1020 * Finally, execute the exit procs directly. Note that
1021 * there is not timeout check for the exit procs so they
1022 * should be well behaved.
1023 */
1024
1025 NsRunAtExitProcs();
1026
1027 /*
1028 * Remove the pid maker file, print a final "server exiting"
1029 * status message and return to main.
1030 */
1031
1032 NsRemovePidFile();
1033 StatusMsg(exiting_state);
1034
1035 /*
1036 * The main thread exits gracefully on NS_SIGTERM.
1037 * All other signals are propagated to the caller.
1038 */
1039
1040 return (sig == NS_SIGTERM(15)) ? 0 : sig;
1041}
1042
1043
1044/*
1045 *----------------------------------------------------------------------
1046 *
1047 * Ns_WaitForStartup --
1048 *
1049 * Blocks thread until the server has completed loading modules,
1050 * sourcing Tcl, and is ready to begin normal operation.
1051 *
1052 * Results:
1053 * NS_OK
1054 *
1055 * Side effects:
1056 * None.
1057 *
1058 *----------------------------------------------------------------------
1059 */
1060
1061Ns_ReturnCode
1062Ns_WaitForStartup(void)
1063{
1064 /*
1065 * This dirty-read is worth the effort.
1066 */
1067
1068 if (unlikely(!nsconf.state.started)(__builtin_expect((!nsconf.state.started), 0))) {
1069 Ns_MutexLock(&nsconf.state.lock);
1070 while (nsconf.state.started == NS_FALSE0) {
1071 Ns_CondWait(&nsconf.state.cond, &nsconf.state.lock);
1072 }
1073 Ns_MutexUnlock(&nsconf.state.lock);
1074 }
1075 return NS_OK;
1076}
1077
1078
1079/*
1080 *----------------------------------------------------------------------
1081 *
1082 * Ns_StopServer --
1083 *
1084 * Shutdown a server.
1085 *
1086 * Results:
1087 * None.
1088 *
1089 * Side effects:
1090 * Server will begin shutdown process.
1091 *
1092 *----------------------------------------------------------------------
1093 */
1094
1095void
1096Ns_StopServer(char *server)
1097{
1098 Ns_Log(Warning, "nsmain: immediate shutdown of server %s requested", server);
1099 NsSendSignal(NS_SIGTERM(15));
1100}
1101
1102
1103/*
1104 *----------------------------------------------------------------------
1105 *
1106 * NsTclShutdownObjCmd --
1107 *
1108 * Implements "ns_shutdown". Shutdown the server, waiting at most timeout
1109 * seconds for threads to exit cleanly before giving up.
1110 *
1111 * Results:
1112 * Tcl result.
1113 *
1114 * Side effects:
1115 * If -restart was specified and watchdog is active, server
1116 * will be restarted.
1117 *
1118 *----------------------------------------------------------------------
1119 */
1120
1121int
1122NsTclShutdownObjCmd(ClientData UNUSED(clientData)UNUSED_clientData __attribute__((__unused__)), Tcl_Interp *interp, int objc, Tcl_Obj *const* objv)
1123{
1124 int sig = NS_SIGTERM(15), result = TCL_OK0;
1125 Ns_Time *timeoutPtr = NULL((void*)0);
1126 Ns_ObjvSpec opts[] = {
1127 {"-restart", Ns_ObjvBool, &sig, INT2PTR(NS_SIGINT)((void *)(intptr_t)((2)))},
1128 {"--", Ns_ObjvBreak, NULL((void*)0), NULL((void*)0)},
1129 {NULL((void*)0), NULL((void*)0), NULL((void*)0), NULL((void*)0)}
1130 };
1131 Ns_ObjvSpec args[] = {
1132 {"?timeout", Ns_ObjvTime, &timeoutPtr, NULL((void*)0)},
1133 {NULL((void*)0), NULL((void*)0), NULL((void*)0), NULL((void*)0)}
1134 };
1135
1136 if (Ns_ParseObjv(opts, args, interp, 1, objc, objv) != NS_OK) {
1137 result = TCL_ERROR1;
1138
1139 } else if (timeoutPtr != NULL((void*)0) && timeoutPtr->sec < 0) {
1140 Ns_TclPrintfResult(interp, "timeout must be >= 0");
1141 result = TCL_ERROR1;
1142
1143 } else {
1144
1145 Ns_MutexLock(&nsconf.state.lock);
1146 if (timeoutPtr != NULL((void*)0)) {
1147 nsconf.shutdowntimeout.sec = timeoutPtr->sec;
1148 nsconf.shutdowntimeout.usec = timeoutPtr->usec;
1149 } else {
1150 timeoutPtr = &nsconf.shutdowntimeout;
1151 }
1152 Ns_MutexUnlock(&nsconf.state.lock);
1153
1154 NsSendSignal(sig);
1155 Tcl_SetObjResult(interp, Ns_TclNewTimeObj(timeoutPtr));
1156 }
1157 return result;
1158}
1159
1160
1161/*
1162 *----------------------------------------------------------------------
1163 *
1164 * StatusMsg --
1165 *
1166 * Print a status message to the log file. Initial messages log
1167 * security status to ensure setuid()/setgid() works as expected.
1168 *
1169 * Results:
1170 * None.
1171 *
1172 * Side effects:
1173 * None.
1174 *
1175 *----------------------------------------------------------------------
1176 */
1177
1178static void
1179StatusMsg(runState state)
1180{
1181 const char *what = ""; /* Just to make compiler silent, we have a complete enumeration of switch values */
1182
1183 switch (state) {
1184
1185 case starting_state:
1186 what = "starting";
1187 break;
1188
1189 case running_state:
1190 what = "running";
1191 break;
1192
1193 case stopping_state:
1194 what = "stopping";
1195 break;
1196
1197 case exiting_state:
1198 what = "exiting";
1199 break;
1200 }
1201 Ns_Log(Notice, "nsmain: %s/%s (%s) %s",
1202 Ns_InfoServerName(), Ns_InfoServerVersion(), Ns_InfoTag(), what);
1203#ifndef _WIN32
1204 if (state == starting_state || state == running_state) {
1205 Ns_Log(Notice, "nsmain: security info: uid=%d, euid=%d, gid=%d, egid=%d",
1206 (int)getuid(), (int)geteuid(), (int)getgid(), (int)getegid());
1207 }
1208#endif
1209}
1210
1211
1212/*
1213 *----------------------------------------------------------------------
1214 *
1215 * LogTclVersion --
1216 *
1217 * Emit Tcl library version to server log.
1218 *
1219 * Results:
1220 * None.
1221 *
1222 * Side effects:
1223 * None.
1224 *
1225 *----------------------------------------------------------------------
1226 */
1227
1228static void
1229LogTclVersion(void)
1230{
1231 int major, minor, patch;
1232
1233 Tcl_GetVersion(&major, &minor, &patch, NULL((void*)0));
1234 Ns_Log(Notice, "nsmain: Tcl version: %d.%d.%d", major, minor, patch);
1235
1236 return;
1237}
1238
1239
1240/*
1241 *----------------------------------------------------------------------
1242 *
1243 * UsageError --
1244 *
1245 * Print a command line usage error message and exit.
1246 *
1247 * Results:
1248 * None.
1249 *
1250 * Side effects:
1251 * Server exits.
1252 *
1253 *----------------------------------------------------------------------
1254 */
1255
1256static void
1257UsageError(const char *msg, ...)
1258{
1259 va_list ap;
1260
1261 va_start(ap, msg)__builtin_va_start(ap, msg);
1262 fprintf(stderr, "\nError: ")__fprintf_chk (stderr, 2 - 1, "\nError: ");
1263 vfprintf(stderrstderr, msg, ap);
1264 fprintf(stderr, "\n")__fprintf_chk (stderr, 2 - 1, "\n");
1265 va_end(ap)__builtin_va_end(ap);
1266
1267 UsageMsg(1);
1268}
1269
1270static void
1271UsageMsg(int exitCode)
1272{
1273 fprintf(stderr, "\n"__fprintf_chk (stderr, 2 - 1, "\n"ifdef _WIN32 "Usage: %s [-h|V] [-c|f|I|R|S] "
else "Usage: %s [-h|V] [-c|f|i|w] " "[-u <user>] [-g <group>] [-r <path>] [-b <address:port>|-B <file>] "
endif "[-s <server>] [-t <file>]\n" "\n" " -h help (this message)\n"
" -V version and release information\n" " -c command (interactive) mode\n"
" -f foreground mode\n"ifdef _WIN32 " -I install Win32 service\n"
" -R remove Win32 service\n" " -S start Win32 service\n"
else " -i inittab mode\n" " -w watchdog mode (restart a failed server)\n"
" -d debugger-friendly mode (ignore SIGINT)\n" " -u run as <user>\n"
" -g run as <group>\n" " -r chroot to <path>\n"
" -b bind <address:port> (Example: 192.168.0.1:80,[::1]:80)\n"
" -B bind address:port list from <file>\n"endif " -s use server named <server> in configuration file\n"
" -t read configuration file from <file>\n" " -T just check configuration file (without starting server)\n"
"\n", nsconf.argv0)
1274#ifdef _WIN32__fprintf_chk (stderr, 2 - 1, "\n"ifdef _WIN32 "Usage: %s [-h|V] [-c|f|I|R|S] "
else "Usage: %s [-h|V] [-c|f|i|w] " "[-u <user>] [-g <group>] [-r <path>] [-b <address:port>|-B <file>] "
endif "[-s <server>] [-t <file>]\n" "\n" " -h help (this message)\n"
" -V version and release information\n" " -c command (interactive) mode\n"
" -f foreground mode\n"ifdef _WIN32 " -I install Win32 service\n"
" -R remove Win32 service\n" " -S start Win32 service\n"
else " -i inittab mode\n" " -w watchdog mode (restart a failed server)\n"
" -d debugger-friendly mode (ignore SIGINT)\n" " -u run as <user>\n"
" -g run as <group>\n" " -r chroot to <path>\n"
" -b bind <address:port> (Example: 192.168.0.1:80,[::1]:80)\n"
" -B bind address:port list from <file>\n"endif " -s use server named <server> in configuration file\n"
" -t read configuration file from <file>\n" " -T just check configuration file (without starting server)\n"
"\n", nsconf.argv0)
1275 "Usage: %s [-h|V] [-c|f|I|R|S] "__fprintf_chk (stderr, 2 - 1, "\n"ifdef _WIN32 "Usage: %s [-h|V] [-c|f|I|R|S] "
else "Usage: %s [-h|V] [-c|f|i|w] " "[-u <user>] [-g <group>] [-r <path>] [-b <address:port>|-B <file>] "
endif "[-s <server>] [-t <file>]\n" "\n" " -h help (this message)\n"
" -V version and release information\n" " -c command (interactive) mode\n"
" -f foreground mode\n"ifdef _WIN32 " -I install Win32 service\n"
" -R remove Win32 service\n" " -S start Win32 service\n"
else " -i inittab mode\n" " -w watchdog mode (restart a failed server)\n"
" -d debugger-friendly mode (ignore SIGINT)\n" " -u run as <user>\n"
" -g run as <group>\n" " -r chroot to <path>\n"
" -b bind <address:port> (Example: 192.168.0.1:80,[::1]:80)\n"
" -B bind address:port list from <file>\n"endif " -s use server named <server> in configuration file\n"
" -t read configuration file from <file>\n" " -T just check configuration file (without starting server)\n"
"\n", nsconf.argv0)
1276#else__fprintf_chk (stderr, 2 - 1, "\n"ifdef _WIN32 "Usage: %s [-h|V] [-c|f|I|R|S] "
else "Usage: %s [-h|V] [-c|f|i|w] " "[-u <user>] [-g <group>] [-r <path>] [-b <address:port>|-B <file>] "
endif "[-s <server>] [-t <file>]\n" "\n" " -h help (this message)\n"
" -V version and release information\n" " -c command (interactive) mode\n"
" -f foreground mode\n"ifdef _WIN32 " -I install Win32 service\n"
" -R remove Win32 service\n" " -S start Win32 service\n"
else " -i inittab mode\n" " -w watchdog mode (restart a failed server)\n"
" -d debugger-friendly mode (ignore SIGINT)\n" " -u run as <user>\n"
" -g run as <group>\n" " -r chroot to <path>\n"
" -b bind <address:port> (Example: 192.168.0.1:80,[::1]:80)\n"
" -B bind address:port list from <file>\n"endif " -s use server named <server> in configuration file\n"
" -t read configuration file from <file>\n" " -T just check configuration file (without starting server)\n"
"\n", nsconf.argv0)
1277 "Usage: %s [-h|V] [-c|f|i|w] "__fprintf_chk (stderr, 2 - 1, "\n"ifdef _WIN32 "Usage: %s [-h|V] [-c|f|I|R|S] "
else "Usage: %s [-h|V] [-c|f|i|w] " "[-u <user>] [-g <group>] [-r <path>] [-b <address:port>|-B <file>] "
endif "[-s <server>] [-t <file>]\n" "\n" " -h help (this message)\n"
" -V version and release information\n" " -c command (interactive) mode\n"
" -f foreground mode\n"ifdef _WIN32 " -I install Win32 service\n"
" -R remove Win32 service\n" " -S start Win32 service\n"
else " -i inittab mode\n" " -w watchdog mode (restart a failed server)\n"
" -d debugger-friendly mode (ignore SIGINT)\n" " -u run as <user>\n"
" -g run as <group>\n" " -r chroot to <path>\n"
" -b bind <address:port> (Example: 192.168.0.1:80,[::1]:80)\n"
" -B bind address:port list from <file>\n"endif " -s use server named <server> in configuration file\n"
" -t read configuration file from <file>\n" " -T just check configuration file (without starting server)\n"
"\n", nsconf.argv0)
1278 "[-u <user>] [-g <group>] [-r <path>] [-b <address:port>|-B <file>] "__fprintf_chk (stderr, 2 - 1, "\n"ifdef _WIN32 "Usage: %s [-h|V] [-c|f|I|R|S] "
else "Usage: %s [-h|V] [-c|f|i|w] " "[-u <user>] [-g <group>] [-r <path>] [-b <address:port>|-B <file>] "
endif "[-s <server>] [-t <file>]\n" "\n" " -h help (this message)\n"
" -V version and release information\n" " -c command (interactive) mode\n"
" -f foreground mode\n"ifdef _WIN32 " -I install Win32 service\n"
" -R remove Win32 service\n" " -S start Win32 service\n"
else " -i inittab mode\n" " -w watchdog mode (restart a failed server)\n"
" -d debugger-friendly mode (ignore SIGINT)\n" " -u run as <user>\n"
" -g run as <group>\n" " -r chroot to <path>\n"
" -b bind <address:port> (Example: 192.168.0.1:80,[::1]:80)\n"
" -B bind address:port list from <file>\n"endif " -s use server named <server> in configuration file\n"
" -t read configuration file from <file>\n" " -T just check configuration file (without starting server)\n"
"\n", nsconf.argv0)
1279#endif__fprintf_chk (stderr, 2 - 1, "\n"ifdef _WIN32 "Usage: %s [-h|V] [-c|f|I|R|S] "
else "Usage: %s [-h|V] [-c|f|i|w] " "[-u <user>] [-g <group>] [-r <path>] [-b <address:port>|-B <file>] "
endif "[-s <server>] [-t <file>]\n" "\n" " -h help (this message)\n"
" -V version and release information\n" " -c command (interactive) mode\n"
" -f foreground mode\n"ifdef _WIN32 " -I install Win32 service\n"
" -R remove Win32 service\n" " -S start Win32 service\n"
else " -i inittab mode\n" " -w watchdog mode (restart a failed server)\n"
" -d debugger-friendly mode (ignore SIGINT)\n" " -u run as <user>\n"
" -g run as <group>\n" " -r chroot to <path>\n"
" -b bind <address:port> (Example: 192.168.0.1:80,[::1]:80)\n"
" -B bind address:port list from <file>\n"endif " -s use server named <server> in configuration file\n"
" -t read configuration file from <file>\n" " -T just check configuration file (without starting server)\n"
"\n", nsconf.argv0)
1280 "[-s <server>] [-t <file>]\n"__fprintf_chk (stderr, 2 - 1, "\n"ifdef _WIN32 "Usage: %s [-h|V] [-c|f|I|R|S] "
else "Usage: %s [-h|V] [-c|f|i|w] " "[-u <user>] [-g <group>] [-r <path>] [-b <address:port>|-B <file>] "
endif "[-s <server>] [-t <file>]\n" "\n" " -h help (this message)\n"
" -V version and release information\n" " -c command (interactive) mode\n"
" -f foreground mode\n"ifdef _WIN32 " -I install Win32 service\n"
" -R remove Win32 service\n" " -S start Win32 service\n"
else " -i inittab mode\n" " -w watchdog mode (restart a failed server)\n"
" -d debugger-friendly mode (ignore SIGINT)\n" " -u run as <user>\n"
" -g run as <group>\n" " -r chroot to <path>\n"
" -b bind <address:port> (Example: 192.168.0.1:80,[::1]:80)\n"
" -B bind address:port list from <file>\n"endif " -s use server named <server> in configuration file\n"
" -t read configuration file from <file>\n" " -T just check configuration file (without starting server)\n"
"\n", nsconf.argv0)
1281 "\n"__fprintf_chk (stderr, 2 - 1, "\n"ifdef _WIN32 "Usage: %s [-h|V] [-c|f|I|R|S] "
else "Usage: %s [-h|V] [-c|f|i|w] " "[-u <user>] [-g <group>] [-r <path>] [-b <address:port>|-B <file>] "
endif "[-s <server>] [-t <file>]\n" "\n" " -h help (this message)\n"
" -V version and release information\n" " -c command (interactive) mode\n"
" -f foreground mode\n"ifdef _WIN32 " -I install Win32 service\n"
" -R remove Win32 service\n" " -S start Win32 service\n"
else " -i inittab mode\n" " -w watchdog mode (restart a failed server)\n"
" -d debugger-friendly mode (ignore SIGINT)\n" " -u run as <user>\n"
" -g run as <group>\n" " -r chroot to <path>\n"
" -b bind <address:port> (Example: 192.168.0.1:80,[::1]:80)\n"
" -B bind address:port list from <file>\n"endif " -s use server named <server> in configuration file\n"
" -t read configuration file from <file>\n" " -T just check configuration file (without starting server)\n"
"\n", nsconf.argv0)
1282 " -h help (this message)\n"__fprintf_chk (stderr, 2 - 1, "\n"ifdef _WIN32 "Usage: %s [-h|V] [-c|f|I|R|S] "
else "Usage: %s [-h|V] [-c|f|i|w] " "[-u <user>] [-g <group>] [-r <path>] [-b <address:port>|-B <file>] "
endif "[-s <server>] [-t <file>]\n" "\n" " -h help (this message)\n"
" -V version and release information\n" " -c command (interactive) mode\n"
" -f foreground mode\n"ifdef _WIN32 " -I install Win32 service\n"
" -R remove Win32 service\n" " -S start Win32 service\n"
else " -i inittab mode\n" " -w watchdog mode (restart a failed server)\n"
" -d debugger-friendly mode (ignore SIGINT)\n" " -u run as <user>\n"
" -g run as <group>\n" " -r chroot to <path>\n"
" -b bind <address:port> (Example: 192.168.0.1:80,[::1]:80)\n"
" -B bind address:port list from <file>\n"endif " -s use server named <server> in configuration file\n"
" -t read configuration file from <file>\n" " -T just check configuration file (without starting server)\n"
"\n", nsconf.argv0)
1283 " -V version and release information\n"__fprintf_chk (stderr, 2 - 1, "\n"ifdef _WIN32 "Usage: %s [-h|V] [-c|f|I|R|S] "
else "Usage: %s [-h|V] [-c|f|i|w] " "[-u <user>] [-g <group>] [-r <path>] [-b <address:port>|-B <file>] "
endif "[-s <server>] [-t <file>]\n" "\n" " -h help (this message)\n"
" -V version and release information\n" " -c command (interactive) mode\n"
" -f foreground mode\n"ifdef _WIN32 " -I install Win32 service\n"
" -R remove Win32 service\n" " -S start Win32 service\n"
else " -i inittab mode\n" " -w watchdog mode (restart a failed server)\n"
" -d debugger-friendly mode (ignore SIGINT)\n" " -u run as <user>\n"
" -g run as <group>\n" " -r chroot to <path>\n"
" -b bind <address:port> (Example: 192.168.0.1:80,[::1]:80)\n"
" -B bind address:port list from <file>\n"endif " -s use server named <server> in configuration file\n"
" -t read configuration file from <file>\n" " -T just check configuration file (without starting server)\n"
"\n", nsconf.argv0)
1284 " -c command (interactive) mode\n"__fprintf_chk (stderr, 2 - 1, "\n"ifdef _WIN32 "Usage: %s [-h|V] [-c|f|I|R|S] "
else "Usage: %s [-h|V] [-c|f|i|w] " "[-u <user>] [-g <group>] [-r <path>] [-b <address:port>|-B <file>] "
endif "[-s <server>] [-t <file>]\n" "\n" " -h help (this message)\n"
" -V version and release information\n" " -c command (interactive) mode\n"
" -f foreground mode\n"ifdef _WIN32 " -I install Win32 service\n"
" -R remove Win32 service\n" " -S start Win32 service\n"
else " -i inittab mode\n" " -w watchdog mode (restart a failed server)\n"
" -d debugger-friendly mode (ignore SIGINT)\n" " -u run as <user>\n"
" -g run as <group>\n" " -r chroot to <path>\n"
" -b bind <address:port> (Example: 192.168.0.1:80,[::1]:80)\n"
" -B bind address:port list from <file>\n"endif " -s use server named <server> in configuration file\n"
" -t read configuration file from <file>\n" " -T just check configuration file (without starting server)\n"
"\n", nsconf.argv0)
1285 " -f foreground mode\n"__fprintf_chk (stderr, 2 - 1, "\n"ifdef _WIN32 "Usage: %s [-h|V] [-c|f|I|R|S] "
else "Usage: %s [-h|V] [-c|f|i|w] " "[-u <user>] [-g <group>] [-r <path>] [-b <address:port>|-B <file>] "
endif "[-s <server>] [-t <file>]\n" "\n" " -h help (this message)\n"
" -V version and release information\n" " -c command (interactive) mode\n"
" -f foreground mode\n"ifdef _WIN32 " -I install Win32 service\n"
" -R remove Win32 service\n" " -S start Win32 service\n"
else " -i inittab mode\n" " -w watchdog mode (restart a failed server)\n"
" -d debugger-friendly mode (ignore SIGINT)\n" " -u run as <user>\n"
" -g run as <group>\n" " -r chroot to <path>\n"
" -b bind <address:port> (Example: 192.168.0.1:80,[::1]:80)\n"
" -B bind address:port list from <file>\n"endif " -s use server named <server> in configuration file\n"
" -t read configuration file from <file>\n" " -T just check configuration file (without starting server)\n"
"\n", nsconf.argv0)
1286#ifdef _WIN32__fprintf_chk (stderr, 2 - 1, "\n"ifdef _WIN32 "Usage: %s [-h|V] [-c|f|I|R|S] "
else "Usage: %s [-h|V] [-c|f|i|w] " "[-u <user>] [-g <group>] [-r <path>] [-b <address:port>|-B <file>] "
endif "[-s <server>] [-t <file>]\n" "\n" " -h help (this message)\n"
" -V version and release information\n" " -c command (interactive) mode\n"
" -f foreground mode\n"ifdef _WIN32 " -I install Win32 service\n"
" -R remove Win32 service\n" " -S start Win32 service\n"
else " -i inittab mode\n" " -w watchdog mode (restart a failed server)\n"
" -d debugger-friendly mode (ignore SIGINT)\n" " -u run as <user>\n"
" -g run as <group>\n" " -r chroot to <path>\n"
" -b bind <address:port> (Example: 192.168.0.1:80,[::1]:80)\n"
" -B bind address:port list from <file>\n"endif " -s use server named <server> in configuration file\n"
" -t read configuration file from <file>\n" " -T just check configuration file (without starting server)\n"
"\n", nsconf.argv0)
1287 " -I install Win32 service\n"__fprintf_chk (stderr, 2 - 1, "\n"ifdef _WIN32 "Usage: %s [-h|V] [-c|f|I|R|S] "
else "Usage: %s [-h|V] [-c|f|i|w] " "[-u <user>] [-g <group>] [-r <path>] [-b <address:port>|-B <file>] "
endif "[-s <server>] [-t <file>]\n" "\n" " -h help (this message)\n"
" -V version and release information\n" " -c command (interactive) mode\n"
" -f foreground mode\n"ifdef _WIN32 " -I install Win32 service\n"
" -R remove Win32 service\n" " -S start Win32 service\n"
else " -i inittab mode\n" " -w watchdog mode (restart a failed server)\n"
" -d debugger-friendly mode (ignore SIGINT)\n" " -u run as <user>\n"
" -g run as <group>\n" " -r chroot to <path>\n"
" -b bind <address:port> (Example: 192.168.0.1:80,[::1]:80)\n"
" -B bind address:port list from <file>\n"endif " -s use server named <server> in configuration file\n"
" -t read configuration file from <file>\n" " -T just check configuration file (without starting server)\n"
"\n", nsconf.argv0)
1288 " -R remove Win32 service\n"__fprintf_chk (stderr, 2 - 1, "\n"ifdef _WIN32 "Usage: %s [-h|V] [-c|f|I|R|S] "
else "Usage: %s [-h|V] [-c|f|i|w] " "[-u <user>] [-g <group>] [-r <path>] [-b <address:port>|-B <file>] "
endif "[-s <server>] [-t <file>]\n" "\n" " -h help (this message)\n"
" -V version and release information\n" " -c command (interactive) mode\n"
" -f foreground mode\n"ifdef _WIN32 " -I install Win32 service\n"
" -R remove Win32 service\n" " -S start Win32 service\n"
else " -i inittab mode\n" " -w watchdog mode (restart a failed server)\n"
" -d debugger-friendly mode (ignore SIGINT)\n" " -u run as <user>\n"
" -g run as <group>\n" " -r chroot to <path>\n"
" -b bind <address:port> (Example: 192.168.0.1:80,[::1]:80)\n"
" -B bind address:port list from <file>\n"endif " -s use server named <server> in configuration file\n"
" -t read configuration file from <file>\n" " -T just check configuration file (without starting server)\n"
"\n", nsconf.argv0)
1289 " -S start Win32 service\n"__fprintf_chk (stderr, 2 - 1, "\n"ifdef _WIN32 "Usage: %s [-h|V] [-c|f|I|R|S] "
else "Usage: %s [-h|V] [-c|f|i|w] " "[-u <user>] [-g <group>] [-r <path>] [-b <address:port>|-B <file>] "
endif "[-s <server>] [-t <file>]\n" "\n" " -h help (this message)\n"
" -V version and release information\n" " -c command (interactive) mode\n"
" -f foreground mode\n"ifdef _WIN32 " -I install Win32 service\n"
" -R remove Win32 service\n" " -S start Win32 service\n"
else " -i inittab mode\n" " -w watchdog mode (restart a failed server)\n"
" -d debugger-friendly mode (ignore SIGINT)\n" " -u run as <user>\n"
" -g run as <group>\n" " -r chroot to <path>\n"
" -b bind <address:port> (Example: 192.168.0.1:80,[::1]:80)\n"
" -B bind address:port list from <file>\n"endif " -s use server named <server> in configuration file\n"
" -t read configuration file from <file>\n" " -T just check configuration file (without starting server)\n"
"\n", nsconf.argv0)
1290#else__fprintf_chk (stderr, 2 - 1, "\n"ifdef _WIN32 "Usage: %s [-h|V] [-c|f|I|R|S] "
else "Usage: %s [-h|V] [-c|f|i|w] " "[-u <user>] [-g <group>] [-r <path>] [-b <address:port>|-B <file>] "
endif "[-s <server>] [-t <file>]\n" "\n" " -h help (this message)\n"
" -V version and release information\n" " -c command (interactive) mode\n"
" -f foreground mode\n"ifdef _WIN32 " -I install Win32 service\n"
" -R remove Win32 service\n" " -S start Win32 service\n"
else " -i inittab mode\n" " -w watchdog mode (restart a failed server)\n"
" -d debugger-friendly mode (ignore SIGINT)\n" " -u run as <user>\n"
" -g run as <group>\n" " -r chroot to <path>\n"
" -b bind <address:port> (Example: 192.168.0.1:80,[::1]:80)\n"
" -B bind address:port list from <file>\n"endif " -s use server named <server> in configuration file\n"
" -t read configuration file from <file>\n" " -T just check configuration file (without starting server)\n"
"\n", nsconf.argv0)
1291 " -i inittab mode\n"__fprintf_chk (stderr, 2 - 1, "\n"ifdef _WIN32 "Usage: %s [-h|V] [-c|f|I|R|S] "
else "Usage: %s [-h|V] [-c|f|i|w] " "[-u <user>] [-g <group>] [-r <path>] [-b <address:port>|-B <file>] "
endif "[-s <server>] [-t <file>]\n" "\n" " -h help (this message)\n"
" -V version and release information\n" " -c command (interactive) mode\n"
" -f foreground mode\n"ifdef _WIN32 " -I install Win32 service\n"
" -R remove Win32 service\n" " -S start Win32 service\n"
else " -i inittab mode\n" " -w watchdog mode (restart a failed server)\n"
" -d debugger-friendly mode (ignore SIGINT)\n" " -u run as <user>\n"
" -g run as <group>\n" " -r chroot to <path>\n"
" -b bind <address:port> (Example: 192.168.0.1:80,[::1]:80)\n"
" -B bind address:port list from <file>\n"endif " -s use server named <server> in configuration file\n"
" -t read configuration file from <file>\n" " -T just check configuration file (without starting server)\n"
"\n", nsconf.argv0)
1292 " -w watchdog mode (restart a failed server)\n"__fprintf_chk (stderr, 2 - 1, "\n"ifdef _WIN32 "Usage: %s [-h|V] [-c|f|I|R|S] "
else "Usage: %s [-h|V] [-c|f|i|w] " "[-u <user>] [-g <group>] [-r <path>] [-b <address:port>|-B <file>] "
endif "[-s <server>] [-t <file>]\n" "\n" " -h help (this message)\n"
" -V version and release information\n" " -c command (interactive) mode\n"
" -f foreground mode\n"ifdef _WIN32 " -I install Win32 service\n"
" -R remove Win32 service\n" " -S start Win32 service\n"
else " -i inittab mode\n" " -w watchdog mode (restart a failed server)\n"
" -d debugger-friendly mode (ignore SIGINT)\n" " -u run as <user>\n"
" -g run as <group>\n" " -r chroot to <path>\n"
" -b bind <address:port> (Example: 192.168.0.1:80,[::1]:80)\n"
" -B bind address:port list from <file>\n"endif " -s use server named <server> in configuration file\n"
" -t read configuration file from <file>\n" " -T just check configuration file (without starting server)\n"
"\n", nsconf.argv0)
1293 " -d debugger-friendly mode (ignore SIGINT)\n"__fprintf_chk (stderr, 2 - 1, "\n"ifdef _WIN32 "Usage: %s [-h|V] [-c|f|I|R|S] "
else "Usage: %s [-h|V] [-c|f|i|w] " "[-u <user>] [-g <group>] [-r <path>] [-b <address:port>|-B <file>] "
endif "[-s <server>] [-t <file>]\n" "\n" " -h help (this message)\n"
" -V version and release information\n" " -c command (interactive) mode\n"
" -f foreground mode\n"ifdef _WIN32 " -I install Win32 service\n"
" -R remove Win32 service\n" " -S start Win32 service\n"
else " -i inittab mode\n" " -w watchdog mode (restart a failed server)\n"
" -d debugger-friendly mode (ignore SIGINT)\n" " -u run as <user>\n"
" -g run as <group>\n" " -r chroot to <path>\n"
" -b bind <address:port> (Example: 192.168.0.1:80,[::1]:80)\n"
" -B bind address:port list from <file>\n"endif " -s use server named <server> in configuration file\n"
" -t read configuration file from <file>\n" " -T just check configuration file (without starting server)\n"
"\n", nsconf.argv0)
1294 " -u run as <user>\n"__fprintf_chk (stderr, 2 - 1, "\n"ifdef _WIN32 "Usage: %s [-h|V] [-c|f|I|R|S] "
else "Usage: %s [-h|V] [-c|f|i|w] " "[-u <user>] [-g <group>] [-r <path>] [-b <address:port>|-B <file>] "
endif "[-s <server>] [-t <file>]\n" "\n" " -h help (this message)\n"
" -V version and release information\n" " -c command (interactive) mode\n"
" -f foreground mode\n"ifdef _WIN32 " -I install Win32 service\n"
" -R remove Win32 service\n" " -S start Win32 service\n"
else " -i inittab mode\n" " -w watchdog mode (restart a failed server)\n"
" -d debugger-friendly mode (ignore SIGINT)\n" " -u run as <user>\n"
" -g run as <group>\n" " -r chroot to <path>\n"
" -b bind <address:port> (Example: 192.168.0.1:80,[::1]:80)\n"
" -B bind address:port list from <file>\n"endif " -s use server named <server> in configuration file\n"
" -t read configuration file from <file>\n" " -T just check configuration file (without starting server)\n"
"\n", nsconf.argv0)
1295 " -g run as <group>\n"__fprintf_chk (stderr, 2 - 1, "\n"ifdef _WIN32 "Usage: %s [-h|V] [-c|f|I|R|S] "
else "Usage: %s [-h|V] [-c|f|i|w] " "[-u <user>] [-g <group>] [-r <path>] [-b <address:port>|-B <file>] "
endif "[-s <server>] [-t <file>]\n" "\n" " -h help (this message)\n"
" -V version and release information\n" " -c command (interactive) mode\n"
" -f foreground mode\n"ifdef _WIN32 " -I install Win32 service\n"
" -R remove Win32 service\n" " -S start Win32 service\n"
else " -i inittab mode\n" " -w watchdog mode (restart a failed server)\n"
" -d debugger-friendly mode (ignore SIGINT)\n" " -u run as <user>\n"
" -g run as <group>\n" " -r chroot to <path>\n"
" -b bind <address:port> (Example: 192.168.0.1:80,[::1]:80)\n"
" -B bind address:port list from <file>\n"endif " -s use server named <server> in configuration file\n"
" -t read configuration file from <file>\n" " -T just check configuration file (without starting server)\n"
"\n", nsconf.argv0)
1296 " -r chroot to <path>\n"__fprintf_chk (stderr, 2 - 1, "\n"ifdef _WIN32 "Usage: %s [-h|V] [-c|f|I|R|S] "
else "Usage: %s [-h|V] [-c|f|i|w] " "[-u <user>] [-g <group>] [-r <path>] [-b <address:port>|-B <file>] "
endif "[-s <server>] [-t <file>]\n" "\n" " -h help (this message)\n"
" -V version and release information\n" " -c command (interactive) mode\n"
" -f foreground mode\n"ifdef _WIN32 " -I install Win32 service\n"
" -R remove Win32 service\n" " -S start Win32 service\n"
else " -i inittab mode\n" " -w watchdog mode (restart a failed server)\n"
" -d debugger-friendly mode (ignore SIGINT)\n" " -u run as <user>\n"
" -g run as <group>\n" " -r chroot to <path>\n"
" -b bind <address:port> (Example: 192.168.0.1:80,[::1]:80)\n"
" -B bind address:port list from <file>\n"endif " -s use server named <server> in configuration file\n"
" -t read configuration file from <file>\n" " -T just check configuration file (without starting server)\n"
"\n", nsconf.argv0)
1297 " -b bind <address:port> (Example: 192.168.0.1:80,[::1]:80)\n"__fprintf_chk (stderr, 2 - 1, "\n"ifdef _WIN32 "Usage: %s [-h|V] [-c|f|I|R|S] "
else "Usage: %s [-h|V] [-c|f|i|w] " "[-u <user>] [-g <group>] [-r <path>] [-b <address:port>|-B <file>] "
endif "[-s <server>] [-t <file>]\n" "\n" " -h help (this message)\n"
" -V version and release information\n" " -c command (interactive) mode\n"
" -f foreground mode\n"ifdef _WIN32 " -I install Win32 service\n"
" -R remove Win32 service\n" " -S start Win32 service\n"
else " -i inittab mode\n" " -w watchdog mode (restart a failed server)\n"
" -d debugger-friendly mode (ignore SIGINT)\n" " -u run as <user>\n"
" -g run as <group>\n" " -r chroot to <path>\n"
" -b bind <address:port> (Example: 192.168.0.1:80,[::1]:80)\n"
" -B bind address:port list from <file>\n"endif " -s use server named <server> in configuration file\n"
" -t read configuration file from <file>\n" " -T just check configuration file (without starting server)\n"
"\n", nsconf.argv0)
1298 " -B bind address:port list from <file>\n"__fprintf_chk (stderr, 2 - 1, "\n"ifdef _WIN32 "Usage: %s [-h|V] [-c|f|I|R|S] "
else "Usage: %s [-h|V] [-c|f|i|w] " "[-u <user>] [-g <group>] [-r <path>] [-b <address:port>|-B <file>] "
endif "[-s <server>] [-t <file>]\n" "\n" " -h help (this message)\n"
" -V version and release information\n" " -c command (interactive) mode\n"
" -f foreground mode\n"ifdef _WIN32 " -I install Win32 service\n"
" -R remove Win32 service\n" " -S start Win32 service\n"
else " -i inittab mode\n" " -w watchdog mode (restart a failed server)\n"
" -d debugger-friendly mode (ignore SIGINT)\n" " -u run as <user>\n"
" -g run as <group>\n" " -r chroot to <path>\n"
" -b bind <address:port> (Example: 192.168.0.1:80,[::1]:80)\n"
" -B bind address:port list from <file>\n"endif " -s use server named <server> in configuration file\n"
" -t read configuration file from <file>\n" " -T just check configuration file (without starting server)\n"
"\n", nsconf.argv0)
1299#endif__fprintf_chk (stderr, 2 - 1, "\n"ifdef _WIN32 "Usage: %s [-h|V] [-c|f|I|R|S] "
else "Usage: %s [-h|V] [-c|f|i|w] " "[-u <user>] [-g <group>] [-r <path>] [-b <address:port>|-B <file>] "
endif "[-s <server>] [-t <file>]\n" "\n" " -h help (this message)\n"
" -V version and release information\n" " -c command (interactive) mode\n"
" -f foreground mode\n"ifdef _WIN32 " -I install Win32 service\n"
" -R remove Win32 service\n" " -S start Win32 service\n"
else " -i inittab mode\n" " -w watchdog mode (restart a failed server)\n"
" -d debugger-friendly mode (ignore SIGINT)\n" " -u run as <user>\n"
" -g run as <group>\n" " -r chroot to <path>\n"
" -b bind <address:port> (Example: 192.168.0.1:80,[::1]:80)\n"
" -B bind address:port list from <file>\n"endif " -s use server named <server> in configuration file\n"
" -t read configuration file from <file>\n" " -T just check configuration file (without starting server)\n"
"\n", nsconf.argv0)
1300 " -s use server named <server> in configuration file\n"__fprintf_chk (stderr, 2 - 1, "\n"ifdef _WIN32 "Usage: %s [-h|V] [-c|f|I|R|S] "
else "Usage: %s [-h|V] [-c|f|i|w] " "[-u <user>] [-g <group>] [-r <path>] [-b <address:port>|-B <file>] "
endif "[-s <server>] [-t <file>]\n" "\n" " -h help (this message)\n"
" -V version and release information\n" " -c command (interactive) mode\n"
" -f foreground mode\n"ifdef _WIN32 " -I install Win32 service\n"
" -R remove Win32 service\n" " -S start Win32 service\n"
else " -i inittab mode\n" " -w watchdog mode (restart a failed server)\n"
" -d debugger-friendly mode (ignore SIGINT)\n" " -u run as <user>\n"
" -g run as <group>\n" " -r chroot to <path>\n"
" -b bind <address:port> (Example: 192.168.0.1:80,[::1]:80)\n"
" -B bind address:port list from <file>\n"endif " -s use server named <server> in configuration file\n"
" -t read configuration file from <file>\n" " -T just check configuration file (without starting server)\n"
"\n", nsconf.argv0)
1301 " -t read configuration file from <file>\n"__fprintf_chk (stderr, 2 - 1, "\n"ifdef _WIN32 "Usage: %s [-h|V] [-c|f|I|R|S] "
else "Usage: %s [-h|V] [-c|f|i|w] " "[-u <user>] [-g <group>] [-r <path>] [-b <address:port>|-B <file>] "
endif "[-s <server>] [-t <file>]\n" "\n" " -h help (this message)\n"
" -V version and release information\n" " -c command (interactive) mode\n"
" -f foreground mode\n"ifdef _WIN32 " -I install Win32 service\n"
" -R remove Win32 service\n" " -S start Win32 service\n"
else " -i inittab mode\n" " -w watchdog mode (restart a failed server)\n"
" -d debugger-friendly mode (ignore SIGINT)\n" " -u run as <user>\n"
" -g run as <group>\n" " -r chroot to <path>\n"
" -b bind <address:port> (Example: 192.168.0.1:80,[::1]:80)\n"
" -B bind address:port list from <file>\n"endif " -s use server named <server> in configuration file\n"
" -t read configuration file from <file>\n" " -T just check configuration file (without starting server)\n"
"\n", nsconf.argv0)
1302 " -T just check configuration file (without starting server)\n"__fprintf_chk (stderr, 2 - 1, "\n"ifdef _WIN32 "Usage: %s [-h|V] [-c|f|I|R|S] "
else "Usage: %s [-h|V] [-c|f|i|w] " "[-u <user>] [-g <group>] [-r <path>] [-b <address:port>|-B <file>] "
endif "[-s <server>] [-t <file>]\n" "\n" " -h help (this message)\n"
" -V version and release information\n" " -c command (interactive) mode\n"
" -f foreground mode\n"ifdef _WIN32 " -I install Win32 service\n"
" -R remove Win32 service\n" " -S start Win32 service\n"
else " -i inittab mode\n" " -w watchdog mode (restart a failed server)\n"
" -d debugger-friendly mode (ignore SIGINT)\n" " -u run as <user>\n"
" -g run as <group>\n" " -r chroot to <path>\n"
" -b bind <address:port> (Example: 192.168.0.1:80,[::1]:80)\n"
" -B bind address:port list from <file>\n"endif " -s use server named <server> in configuration file\n"
" -t read configuration file from <file>\n" " -T just check configuration file (without starting server)\n"
"\n", nsconf.argv0)
1303 "\n", nsconf.argv0)__fprintf_chk (stderr, 2 - 1, "\n"ifdef _WIN32 "Usage: %s [-h|V] [-c|f|I|R|S] "
else "Usage: %s [-h|V] [-c|f|i|w] " "[-u <user>] [-g <group>] [-r <path>] [-b <address:port>|-B <file>] "
endif "[-s <server>] [-t <file>]\n" "\n" " -h help (this message)\n"
" -V version and release information\n" " -c command (interactive) mode\n"
" -f foreground mode\n"ifdef _WIN32 " -I install Win32 service\n"
" -R remove Win32 service\n" " -S start Win32 service\n"
else " -i inittab mode\n" " -w watchdog mode (restart a failed server)\n"
" -d debugger-friendly mode (ignore SIGINT)\n" " -u run as <user>\n"
" -g run as <group>\n" " -r chroot to <path>\n"
" -b bind <address:port> (Example: 192.168.0.1:80,[::1]:80)\n"
" -B bind address:port list from <file>\n"endif " -s use server named <server> in configuration file\n"
" -t read configuration file from <file>\n" " -T just check configuration file (without starting server)\n"
"\n", nsconf.argv0)
;
1304 exit(exitCode);
1305}
1306
1307
1308/*
1309 *----------------------------------------------------------------------
1310 *
1311 * MakePath --
1312 *
1313 * Returns full path to the file relative to the base dir
1314 *
1315 * Results:
1316 * Allocated full path or NULL
1317 *
1318 * Side effects:
1319 * None.
1320 *
1321 *----------------------------------------------------------------------
1322 */
1323
1324static const char *
1325MakePath(const char *file)
1326{
1327 const char *result = NULL((void*)0);
1328
1329 NS_NONNULL_ASSERT(file != NULL)((void) (0));
1330
1331 if (Ns_PathIsAbsolute(nsconf.nsd) == NS_TRUE1) {
1332 const char *str = strstr(nsconf.nsd, "/bin/");
1333
1334 if (str == NULL((void*)0)) {
1335 str = strrchr(nsconf.nsd, INTCHAR('/')((int)((unsigned char)(('/')))));
1336 }
1337 if (str != NULL((void*)0)) {
1338 const char *path = NULL((void*)0);
1339 Tcl_Obj *obj;
1340
1341 /*
1342 * Make sure we have valid path on all platforms
1343 */
1344 obj = Tcl_NewStringObj(nsconf.nsd, (int)(str - nsconf.nsd));
1345 Tcl_AppendStringsToObj(obj, "/", file, (char *)0L);
1346
1347 Tcl_IncrRefCount(obj)++(obj)->refCount;
1348 if (Tcl_FSGetNormalizedPath(NULL((void*)0), obj) != NULL((void*)0)) {
1349 path = Tcl_FSGetTranslatedStringPath(NULL((void*)0), obj);
1350 }
1351 Tcl_DecrRefCount(obj)do { Tcl_Obj *_objPtr = (obj); if (_objPtr->refCount-- <=
1) { TclFreeObj(_objPtr); } } while(0)
;
1352
1353 /*
1354 * If filename was given, check if the file exists
1355 */
1356 if (path != NULL((void*)0) && *file != '\0' && access(path, F_OK0) != 0) {
1357 ckfree((void *)path)Tcl_Free((char *)((void *)path));
1358 path = NULL((void*)0);
1359 }
1360 result = path;
1361 }
1362 }
1363 return result;
1364}
1365
1366
1367/*
1368 *----------------------------------------------------------------------
1369 *
1370 * SetCwd --
1371 *
1372 * Changes the current working directory to the passed path.
1373 *
1374 * Results:
1375 * Tcl_Alloc'ated string with the normalized path of the
1376 * current working directory.
1377 *
1378 * Side effects:
1379 * Kills server if unable to change to given directory
1380 * or if the absolute normalized path of the directory
1381 * could not be resolved.
1382 *
1383 *----------------------------------------------------------------------
1384 */
1385
1386static const char *
1387SetCwd(const char *path)
1388{
1389 Tcl_Obj *pathObj;
1390
1391 NS_NONNULL_ASSERT(path != NULL)((void) (0));
1392
1393 pathObj = Tcl_NewStringObj(path, -1);
1394 Tcl_IncrRefCount(pathObj)++(pathObj)->refCount;
1395 if (Tcl_FSChdir(pathObj) == -1) {
1396 Ns_Fatal("nsmain: chdir(%s) failed: '%s'", path, strerror(Tcl_GetErrno()));
1397 }
1398 Tcl_DecrRefCount(pathObj)do { Tcl_Obj *_objPtr = (pathObj); if (_objPtr->refCount--
<= 1) { TclFreeObj(_objPtr); } } while(0)
;
1399 pathObj = Tcl_FSGetCwd(NULL((void*)0));
1400 if (pathObj == NULL((void*)0)) {
1401 Ns_Fatal("nsmain: can't resolve home directory path");
1402 }
1403
1404 return Tcl_FSGetTranslatedStringPath(NULL((void*)0), pathObj);
1405}
1406
1407
1408/*
1409 *----------------------------------------------------------------------
1410 *
1411 * CmdThread --
1412 *
1413 * Run a command shell accepting commands on standard input.
1414 *
1415 * Results:
1416 * None.
1417 *
1418 * Side effects:
1419 * None.
1420 *
1421 *----------------------------------------------------------------------
1422 */
1423
1424static void
1425CmdThread(void *arg)
1426{
1427 const Args *cmd = arg;
1428
1429 Ns_ThreadSetName("-command-");
1430
1431 (void)Ns_WaitForStartup();
1432
1433 NsRestoreSignals();
1434 NsBlockSignal(NS_SIGPIPE(13));
1435
1436#if defined(__APPLE__) && defined(__MACH__)
1437 signal(SIGPIPE13, SIG_IGN((__sighandler_t) 1));
1438#endif
1439
1440 Tcl_Main(cmd->argc, cmd->argv, NsTclAppInit)Tcl_MainEx(cmd->argc, cmd->argv, NsTclAppInit, ((Tcl_CreateInterp
)()))
;
1441}
1442
1443/*
1444 * Local Variables:
1445 * mode: c
1446 * c-basic-offset: 4
1447 * fill-column: 78
1448 * indent-tabs-mode: nil
1449 * End:
1450 */