os.c revision 76786c2904942b708d8a7a4659df74da5dc9446e
d4ef65050feac78554addf6e16a06c6e2e0bd331Brian Wellington * Copyright (C) 2004, 2005, 2007-2009 Internet Systems Consortium, Inc. ("ISC")
d4ef65050feac78554addf6e16a06c6e2e0bd331Brian Wellington * Copyright (C) 1999-2002 Internet Software Consortium.
d4ef65050feac78554addf6e16a06c6e2e0bd331Brian Wellington * Permission to use, copy, modify, and/or distribute this software for any
d4ef65050feac78554addf6e16a06c6e2e0bd331Brian Wellington * purpose with or without fee is hereby granted, provided that the above
d4ef65050feac78554addf6e16a06c6e2e0bd331Brian Wellington * copyright notice and this permission notice appear in all copies.
d4ef65050feac78554addf6e16a06c6e2e0bd331Brian Wellington * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
d4ef65050feac78554addf6e16a06c6e2e0bd331Brian Wellington * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
d4ef65050feac78554addf6e16a06c6e2e0bd331Brian Wellington * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
d4ef65050feac78554addf6e16a06c6e2e0bd331Brian Wellington * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
d4ef65050feac78554addf6e16a06c6e2e0bd331Brian Wellington * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
d4ef65050feac78554addf6e16a06c6e2e0bd331Brian Wellington * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
d4ef65050feac78554addf6e16a06c6e2e0bd331Brian Wellington * PERFORMANCE OF THIS SOFTWARE.
326bcfa0e2a6b924cb829a0bcc3bf9590ce21ad6Mark Andrews/* $Id: os.c,v 1.34 2009/06/12 02:33:21 each Exp $ */
1b4e6163bed546ca7f8ad186f3eabfebacc36bc1Brian Wellington "named requires Windows 2000 Service Pack 2 or later to run correctly";
1b4e6163bed546ca7f8ad186f3eabfebacc36bc1Brian Wellington ns_g_conffile = isc_ntpaths_get(NAMED_CONF_PATH);
1b4e6163bed546ca7f8ad186f3eabfebacc36bc1Brian Wellington lwresd_g_conffile = isc_ntpaths_get(LWRES_CONF_PATH);
1b4e6163bed546ca7f8ad186f3eabfebacc36bc1Brian Wellington lwresd_g_resolvconffile = isc_ntpaths_get(RESOLV_CONF_PATH);
1b4e6163bed546ca7f8ad186f3eabfebacc36bc1Brian Wellington ns_g_conffile = isc_ntpaths_get(NAMED_CONF_PATH);
1b4e6163bed546ca7f8ad186f3eabfebacc36bc1Brian Wellington ns_g_defaultpidfile = isc_ntpaths_get(NAMED_PID_PATH);
1b4e6163bed546ca7f8ad186f3eabfebacc36bc1Brian Wellington lwresd_g_defaultpidfile = isc_ntpaths_get(LWRESD_PID_PATH);
1b4e6163bed546ca7f8ad186f3eabfebacc36bc1Brian Wellington ns_g_keyfile = isc_ntpaths_get(RNDC_KEY_PATH);
1b4e6163bed546ca7f8ad186f3eabfebacc36bc1Brian Wellington ns_g_defaultddnskeyfile = isc_ntpaths_get(DDNS_KEY_PATH);
1b4e6163bed546ca7f8ad186f3eabfebacc36bc1Brian Wellington * Due to Knowledge base article Q263823 we need to make sure that
1b4e6163bed546ca7f8ad186f3eabfebacc36bc1Brian Wellington * Windows 2000 systems have Service Pack 2 or later installed and
1b4e6163bed546ca7f8ad186f3eabfebacc36bc1Brian Wellington * warn when it isn't.
1b4e6163bed546ca7f8ad186f3eabfebacc36bc1Brian Wellington return; /* No problem with Version 4.0 */
1b4e6163bed546ca7f8ad186f3eabfebacc36bc1Brian Wellington if(isc_win32os_versioncheck(5, 0, 2, 0) < 0)
1b4e6163bed546ca7f8ad186f3eabfebacc36bc1Brian Wellington * XXXMPA. We may need to split ntservice_init() in two and
091329e690b20755aa80b86cc7389d25c5d32c9bBrian Wellington * just mark as running in ns_os_started(). If we do that
1b4e6163bed546ca7f8ad186f3eabfebacc36bc1Brian Wellington * this is where the first part of ntservice_init() should be
1b4e6163bed546ca7f8ad186f3eabfebacc36bc1Brian Wellington * called from.
1b4e6163bed546ca7f8ad186f3eabfebacc36bc1Brian Wellington * XXX970 Remove comment if no problems by 9.7.0.
1b4e6163bed546ca7f8ad186f3eabfebacc36bc1Brian Wellington * ntservice_init();
1b4e6163bed546ca7f8ad186f3eabfebacc36bc1Brian Wellington * Try to set stdin, stdout, and stderr to /dev/null, but press
1b4e6163bed546ca7f8ad186f3eabfebacc36bc1Brian Wellington * on even if it fails.
1b4e6163bed546ca7f8ad186f3eabfebacc36bc1Brian Wellington ns_main_earlyfatal("chroot(): isn't supported by Win32 API");
ed3418751ebdf7de397df76753dae97851d2bdf9Brian Wellingtonsafe_open(const char *filename, isc_boolean_t append) {
1b4e6163bed546ca7f8ad186f3eabfebacc36bc1Brian Wellington fd = open(filename, O_WRONLY|O_CREAT|O_APPEND,
1b4e6163bed546ca7f8ad186f3eabfebacc36bc1Brian Wellington fd = open(filename, O_WRONLY|O_CREAT|O_EXCL,
1b4e6163bed546ca7f8ad186f3eabfebacc36bc1Brian Wellingtonns_os_writepidfile(const char *filename, isc_boolean_t first_time) {
1b4e6163bed546ca7f8ad186f3eabfebacc36bc1Brian Wellington void (*report)(const char *, ...);
1b4e6163bed546ca7f8ad186f3eabfebacc36bc1Brian Wellington * The caller must ensure any required synchronization.
1b4e6163bed546ca7f8ad186f3eabfebacc36bc1Brian Wellington report = first_time ? ns_main_earlyfatal : ns_main_earlywarning;
1b4e6163bed546ca7f8ad186f3eabfebacc36bc1Brian Wellington isc__strerror(errno, strbuf, sizeof(strbuf));
1b4e6163bed546ca7f8ad186f3eabfebacc36bc1Brian Wellington (*report)("couldn't malloc '%s': %s", filename, strbuf);
1b4e6163bed546ca7f8ad186f3eabfebacc36bc1Brian Wellington /* This is safe. */
1b4e6163bed546ca7f8ad186f3eabfebacc36bc1Brian Wellington isc__strerror(errno, strbuf, sizeof(strbuf));
1b4e6163bed546ca7f8ad186f3eabfebacc36bc1Brian Wellington (*report)("couldn't open pid file '%s': %s", filename, strbuf);
1b4e6163bed546ca7f8ad186f3eabfebacc36bc1Brian Wellington isc__strerror(errno, strbuf, sizeof(strbuf));
1b4e6163bed546ca7f8ad186f3eabfebacc36bc1Brian Wellington (*report)("could not fdopen() pid file '%s': %s",
1b4e6163bed546ca7f8ad186f3eabfebacc36bc1Brian Wellington if (fprintf(lockfile, "%ld\n", (long)pid) < 0) {
1b4e6163bed546ca7f8ad186f3eabfebacc36bc1Brian Wellington (*report)("fprintf() to pid file '%s' failed", filename);
1b4e6163bed546ca7f8ad186f3eabfebacc36bc1Brian Wellington (*report)("fflush() to pid file '%s' failed", filename);
1b4e6163bed546ca7f8ad186f3eabfebacc36bc1Brian Wellington ntservice_shutdown(); /* This MUST be the last thing done */
1b4e6163bed546ca7f8ad186f3eabfebacc36bc1Brian Wellington return ((n == 0) ? ISC_R_SUCCESS : ISC_R_FAILURE);