os.c revision 0956e3d6074b197eb6aeadd6aa985e60e0dbd15d
c3c6770e537ea916265c78d0294ad108233e17c1Michael Sawyer/*
c3c6770e537ea916265c78d0294ad108233e17c1Michael Sawyer * Copyright (C) 1999-2001 Internet Software Consortium.
93ca8abdf86dfe69d40c0bc5389151e0672780afTinderbox User *
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews * Permission to use, copy, modify, and distribute this software for any
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * purpose with or without fee is hereby granted, provided that the above
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * copyright notice and this permission notice appear in all copies.
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews *
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
1d32b1df372d6be6bac6450739b9e5ea23819995Evan Hunt * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
c3c6770e537ea916265c78d0294ad108233e17c1Michael Sawyer * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
c3c6770e537ea916265c78d0294ad108233e17c1Michael Sawyer * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
c3c6770e537ea916265c78d0294ad108233e17c1Michael Sawyer * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
c3c6770e537ea916265c78d0294ad108233e17c1Michael Sawyer * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
c3c6770e537ea916265c78d0294ad108233e17c1Michael Sawyer * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
c3c6770e537ea916265c78d0294ad108233e17c1Michael Sawyer */
30a60d2aff0ec1810262a8b8efc532e28b32bd57Evan Hunt
30a60d2aff0ec1810262a8b8efc532e28b32bd57Evan Hunt/* $Id: os.c,v 1.17 2002/08/03 01:31:48 mayer Exp $ */
30a60d2aff0ec1810262a8b8efc532e28b32bd57Evan Hunt
30a60d2aff0ec1810262a8b8efc532e28b32bd57Evan Hunt#include <config.h>
30a60d2aff0ec1810262a8b8efc532e28b32bd57Evan Hunt#include <stdarg.h>
30a60d2aff0ec1810262a8b8efc532e28b32bd57Evan Hunt
30a60d2aff0ec1810262a8b8efc532e28b32bd57Evan Hunt#include <sys/stat.h>
30a60d2aff0ec1810262a8b8efc532e28b32bd57Evan Hunt
ac31adc3b76a3acf61c711d1cd49480a288b1317Mukund Sivaraman#include <ctype.h>
30a60d2aff0ec1810262a8b8efc532e28b32bd57Evan Hunt#include <errno.h>
30a60d2aff0ec1810262a8b8efc532e28b32bd57Evan Hunt#include <io.h>
30a60d2aff0ec1810262a8b8efc532e28b32bd57Evan Hunt#include <process.h>
30a60d2aff0ec1810262a8b8efc532e28b32bd57Evan Hunt#include <fcntl.h>
30a60d2aff0ec1810262a8b8efc532e28b32bd57Evan Hunt#include <stdio.h>
30a60d2aff0ec1810262a8b8efc532e28b32bd57Evan Hunt#include <stdlib.h>
30a60d2aff0ec1810262a8b8efc532e28b32bd57Evan Hunt#include <syslog.h>
30a60d2aff0ec1810262a8b8efc532e28b32bd57Evan Hunt
30a60d2aff0ec1810262a8b8efc532e28b32bd57Evan Hunt#include <isc/print.h>
222d38735f97f771054e223b03f84c5858252332Evan Hunt#include <isc/result.h>
c634c94d673f1bab17e7f65d332f989b683e712cDavid Lawrence#include <isc/strerror.h>
c3c6770e537ea916265c78d0294ad108233e17c1Michael Sawyer#include <isc/string.h>
222d38735f97f771054e223b03f84c5858252332Evan Hunt#include <isc/ntpaths.h>
222d38735f97f771054e223b03f84c5858252332Evan Hunt#include <isc/util.h>
c3c6770e537ea916265c78d0294ad108233e17c1Michael Sawyer#include <isc/win32os.h>
222d38735f97f771054e223b03f84c5858252332Evan Hunt
c634c94d673f1bab17e7f65d332f989b683e712cDavid Lawrence#include <named/main.h>
c3c6770e537ea916265c78d0294ad108233e17c1Michael Sawyer#include <named/log.h>
222d38735f97f771054e223b03f84c5858252332Evan Hunt#include <named/os.h>
222d38735f97f771054e223b03f84c5858252332Evan Hunt#include <named/globals.h>
c3c6770e537ea916265c78d0294ad108233e17c1Michael Sawyer#include <named/ntservice.h>
222d38735f97f771054e223b03f84c5858252332Evan Hunt
c634c94d673f1bab17e7f65d332f989b683e712cDavid Lawrence
222d38735f97f771054e223b03f84c5858252332Evan Huntstatic char *pidfile = NULL;
222d38735f97f771054e223b03f84c5858252332Evan Hunt
222d38735f97f771054e223b03f84c5858252332Evan Huntstatic BOOL Initialized = FALSE;
c3c6770e537ea916265c78d0294ad108233e17c1Michael Sawyer
222d38735f97f771054e223b03f84c5858252332Evan Huntstatic char *version_error =
c634c94d673f1bab17e7f65d332f989b683e712cDavid Lawrence "named requires Windows 2000 Service Pack 2 or later to run correctly";
fdebae839745f79a7550aeb49d15a930523ec483David Lawrence
222d38735f97f771054e223b03f84c5858252332Evan Huntvoid
28002bd7cb4baa0eab9f47e1e51069c5ea7ea5d4Andreas Gustafssonns_paths_init() {
28002bd7cb4baa0eab9f47e1e51069c5ea7ea5d4Andreas Gustafsson if (!Initialized)
1d32b1df372d6be6bac6450739b9e5ea23819995Evan Hunt isc_ntpaths_init();
1d32b1df372d6be6bac6450739b9e5ea23819995Evan Hunt
28002bd7cb4baa0eab9f47e1e51069c5ea7ea5d4Andreas Gustafsson ns_g_conffile = isc_ntpaths_get(NAMED_CONF_PATH);
28002bd7cb4baa0eab9f47e1e51069c5ea7ea5d4Andreas Gustafsson lwresd_g_conffile = isc_ntpaths_get(LWRES_CONF_PATH);
222d38735f97f771054e223b03f84c5858252332Evan Hunt lwresd_g_resolvconffile = isc_ntpaths_get(RESOLV_CONF_PATH);
222d38735f97f771054e223b03f84c5858252332Evan Hunt ns_g_conffile = isc_ntpaths_get(NAMED_CONF_PATH);
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt ns_g_defaultpidfile = isc_ntpaths_get(NAMED_PID_PATH);
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt lwresd_g_defaultpidfile = isc_ntpaths_get(LWRESD_PID_PATH);
c3c6770e537ea916265c78d0294ad108233e17c1Michael Sawyer ns_g_keyfile = isc_ntpaths_get(RNDC_KEY_PATH);
222d38735f97f771054e223b03f84c5858252332Evan Hunt
c634c94d673f1bab17e7f65d332f989b683e712cDavid Lawrence Initialized = TRUE;
c3c6770e537ea916265c78d0294ad108233e17c1Michael Sawyer}
222d38735f97f771054e223b03f84c5858252332Evan Hunt
222d38735f97f771054e223b03f84c5858252332Evan Hunt/*
c3c6770e537ea916265c78d0294ad108233e17c1Michael Sawyer * Due to Knowledge base article Q263823 we need to make sure that
222d38735f97f771054e223b03f84c5858252332Evan Hunt * Windows 2000 systems have Service Pack 2 or later installed and
c634c94d673f1bab17e7f65d332f989b683e712cDavid Lawrence * warn when it isn't.
c3c6770e537ea916265c78d0294ad108233e17c1Michael Sawyer */
222d38735f97f771054e223b03f84c5858252332Evan Huntstatic void
222d38735f97f771054e223b03f84c5858252332Evan Huntversion_check(const char *progname) {
c3c6770e537ea916265c78d0294ad108233e17c1Michael Sawyer
222d38735f97f771054e223b03f84c5858252332Evan Hunt if(isc_win32os_majorversion() < 5)
c634c94d673f1bab17e7f65d332f989b683e712cDavid Lawrence return; /* No problem with Version 4.0 */
222d38735f97f771054e223b03f84c5858252332Evan Hunt if(isc_win32os_versioncheck(5, 0, 2, 0) < 0)
222d38735f97f771054e223b03f84c5858252332Evan Hunt if (ntservice_isservice())
222d38735f97f771054e223b03f84c5858252332Evan Hunt NTReportError(progname, version_error);
c3c6770e537ea916265c78d0294ad108233e17c1Michael Sawyer else
222d38735f97f771054e223b03f84c5858252332Evan Hunt fprintf(stderr, "%s\n", version_error);
9069215eac23e32f4ef1c8e44ad7ff2865cfcdacEvan Hunt}
222d38735f97f771054e223b03f84c5858252332Evan Hunt
222d38735f97f771054e223b03f84c5858252332Evan Huntstatic void
222d38735f97f771054e223b03f84c5858252332Evan Huntsetup_syslog(const char *progname) {
9069215eac23e32f4ef1c8e44ad7ff2865cfcdacEvan Hunt int options;
222d38735f97f771054e223b03f84c5858252332Evan Hunt
9069215eac23e32f4ef1c8e44ad7ff2865cfcdacEvan Hunt options = LOG_PID;
9069215eac23e32f4ef1c8e44ad7ff2865cfcdacEvan Hunt#ifdef LOG_NDELAY
222d38735f97f771054e223b03f84c5858252332Evan Hunt options |= LOG_NDELAY;
9069215eac23e32f4ef1c8e44ad7ff2865cfcdacEvan Hunt#endif
9069215eac23e32f4ef1c8e44ad7ff2865cfcdacEvan Hunt
9069215eac23e32f4ef1c8e44ad7ff2865cfcdacEvan Hunt openlog(progname, options, LOG_DAEMON);
9069215eac23e32f4ef1c8e44ad7ff2865cfcdacEvan Hunt}
222d38735f97f771054e223b03f84c5858252332Evan Hunt
9069215eac23e32f4ef1c8e44ad7ff2865cfcdacEvan Huntvoid
9069215eac23e32f4ef1c8e44ad7ff2865cfcdacEvan Huntns_os_init(const char *progname) {
9069215eac23e32f4ef1c8e44ad7ff2865cfcdacEvan Hunt ns_paths_init();
9069215eac23e32f4ef1c8e44ad7ff2865cfcdacEvan Hunt setup_syslog(progname);
222d38735f97f771054e223b03f84c5858252332Evan Hunt ntservice_init();
9069215eac23e32f4ef1c8e44ad7ff2865cfcdacEvan Hunt version_check(progname);
222d38735f97f771054e223b03f84c5858252332Evan Hunt}
222d38735f97f771054e223b03f84c5858252332Evan Hunt
222d38735f97f771054e223b03f84c5858252332Evan Huntvoid
9069215eac23e32f4ef1c8e44ad7ff2865cfcdacEvan Huntns_os_daemonize(void) {
222d38735f97f771054e223b03f84c5858252332Evan Hunt int fd;
9069215eac23e32f4ef1c8e44ad7ff2865cfcdacEvan Hunt
222d38735f97f771054e223b03f84c5858252332Evan Hunt /*
222d38735f97f771054e223b03f84c5858252332Evan Hunt * Try to set stdin, stdout, and stderr to /dev/null, but press
9069215eac23e32f4ef1c8e44ad7ff2865cfcdacEvan Hunt * on even if it fails.
222d38735f97f771054e223b03f84c5858252332Evan Hunt *
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt * XXXMLG The close() calls here are unneeded on all but NetBSD, but
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt * are harmless to include everywhere. dup2() is supposed to close
222d38735f97f771054e223b03f84c5858252332Evan Hunt * the FD if it is in use, but unproven-pthreads-0.16 is broken
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt * and will end up closing the wrong FD. This will be fixed eventually,
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt * and these calls will be removed.
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt */
222d38735f97f771054e223b03f84c5858252332Evan Hunt fd = open("NUL", O_RDWR, 0);
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt if (fd != -1) {
222d38735f97f771054e223b03f84c5858252332Evan Hunt close(_fileno(stdin));
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt (void)_dup2(fd, _fileno(stdin));
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt close(_fileno(stdout));
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt (void)_dup2(fd, _fileno(stdout));
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt close(_fileno(stderr));
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt (void)_dup2(fd, _fileno(stderr));
222d38735f97f771054e223b03f84c5858252332Evan Hunt if (fd != _fileno(stdin) &&
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt fd != _fileno(stdout) &&
222d38735f97f771054e223b03f84c5858252332Evan Hunt fd != _fileno(stderr))
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt (void)close(fd);
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt }
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt}
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Huntvoid
222d38735f97f771054e223b03f84c5858252332Evan Huntns_os_chroot(const char *root) {
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt}
222d38735f97f771054e223b03f84c5858252332Evan Hunt
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Huntvoid
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Huntns_os_inituserinfo(const char *username) {
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt}
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt
222d38735f97f771054e223b03f84c5858252332Evan Huntvoid
222d38735f97f771054e223b03f84c5858252332Evan Huntns_os_changeuser(void) {
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt}
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Huntvoid
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Huntns_os_minprivs(void) {
222d38735f97f771054e223b03f84c5858252332Evan Hunt}
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt
222d38735f97f771054e223b03f84c5858252332Evan Huntstatic int
222d38735f97f771054e223b03f84c5858252332Evan Huntsafe_open(const char *filename, isc_boolean_t append) {
222d38735f97f771054e223b03f84c5858252332Evan Hunt int fd;
222d38735f97f771054e223b03f84c5858252332Evan Hunt struct stat sb;
222d38735f97f771054e223b03f84c5858252332Evan Hunt
222d38735f97f771054e223b03f84c5858252332Evan Hunt if (stat(filename, &sb) == -1) {
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt if (errno != ENOENT)
47e70d820ed07895a25e5b3520adf953114ac01eEvan Hunt return (-1);
47e70d820ed07895a25e5b3520adf953114ac01eEvan Hunt } else if ((sb.st_mode & S_IFREG) == 0)
d58e33bfabfee19a035031dac633d36659738d56Evan Hunt return (-1);
47e70d820ed07895a25e5b3520adf953114ac01eEvan Hunt
222d38735f97f771054e223b03f84c5858252332Evan Hunt if (append)
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt fd = open(filename, O_WRONLY|O_CREAT|O_APPEND,
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH);
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt else {
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt (void)unlink(filename);
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt fd = open(filename, O_WRONLY|O_CREAT|O_EXCL,
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH);
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt }
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt return (fd);
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt}
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt
222d38735f97f771054e223b03f84c5858252332Evan Huntstatic void
222d38735f97f771054e223b03f84c5858252332Evan Huntcleanup_pidfile(void) {
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt if (pidfile != NULL) {
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt (void)unlink(pidfile);
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt free(pidfile);
2a6d60615cf07b164533dbb6bb1dce84ed2d037dEvan Hunt }
2a6d60615cf07b164533dbb6bb1dce84ed2d037dEvan Hunt pidfile = NULL;
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt}
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Huntvoid
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Huntns_os_writepidfile(const char *filename, isc_boolean_t first_time) {
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt int fd;
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt FILE *lockfile;
222d38735f97f771054e223b03f84c5858252332Evan Hunt size_t len;
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt pid_t pid;
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt char strbuf[ISC_STRERRORSIZE];
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt void (*report)(const char *, ...);
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt /*
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt * The caller must ensure any required synchronization.
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt */
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt
222d38735f97f771054e223b03f84c5858252332Evan Hunt report = first_time ? ns_main_earlyfatal : ns_main_earlywarning;
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt cleanup_pidfile();
a60831febfad9d3c9cabeb22a399238748f69ae6Mark Andrews
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt if (strcmp(filename, "none") == 0)
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt return;
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt len = strlen(filename);
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt pidfile = malloc(len + 1);
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt if (pidfile == NULL) {
222d38735f97f771054e223b03f84c5858252332Evan Hunt isc__strerror(errno, strbuf, sizeof(strbuf));
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt (*report)("couldn't malloc '%s': %s", filename, strbuf);
cba23be7ba724b527f6a60c14caaeca9502fbc79Evan Hunt return;
a60831febfad9d3c9cabeb22a399238748f69ae6Mark Andrews }
cba23be7ba724b527f6a60c14caaeca9502fbc79Evan Hunt /* This is safe. */
cba23be7ba724b527f6a60c14caaeca9502fbc79Evan Hunt strcpy(pidfile, filename);
cba23be7ba724b527f6a60c14caaeca9502fbc79Evan Hunt
cba23be7ba724b527f6a60c14caaeca9502fbc79Evan Hunt fd = safe_open(filename, ISC_FALSE);
cba23be7ba724b527f6a60c14caaeca9502fbc79Evan Hunt if (fd < 0) {
222d38735f97f771054e223b03f84c5858252332Evan Hunt isc__strerror(errno, strbuf, sizeof(strbuf));
cba23be7ba724b527f6a60c14caaeca9502fbc79Evan Hunt (*report)("couldn't open pid file '%s': %s", filename, strbuf);
ffff5d67926821d3db8df63bdd84a9cb1ce56739Evan Hunt free(pidfile);
a60831febfad9d3c9cabeb22a399238748f69ae6Mark Andrews pidfile = NULL;
ffff5d67926821d3db8df63bdd84a9cb1ce56739Evan Hunt return;
ffff5d67926821d3db8df63bdd84a9cb1ce56739Evan Hunt }
ffff5d67926821d3db8df63bdd84a9cb1ce56739Evan Hunt lockfile = fdopen(fd, "w");
ffff5d67926821d3db8df63bdd84a9cb1ce56739Evan Hunt if (lockfile == NULL) {
ffff5d67926821d3db8df63bdd84a9cb1ce56739Evan Hunt isc__strerror(errno, strbuf, sizeof(strbuf));
ffff5d67926821d3db8df63bdd84a9cb1ce56739Evan Hunt (*report)("could not fdopen() pid file '%s': %s",
ffff5d67926821d3db8df63bdd84a9cb1ce56739Evan Hunt filename, strbuf);
ffff5d67926821d3db8df63bdd84a9cb1ce56739Evan Hunt (void)close(fd);
ffff5d67926821d3db8df63bdd84a9cb1ce56739Evan Hunt cleanup_pidfile();
ffff5d67926821d3db8df63bdd84a9cb1ce56739Evan Hunt return;
a69070d8fab55dbc63ba9f96c9d3e34f0ea9119aMark Andrews }
a60831febfad9d3c9cabeb22a399238748f69ae6Mark Andrews
a69070d8fab55dbc63ba9f96c9d3e34f0ea9119aMark Andrews pid = getpid();
a69070d8fab55dbc63ba9f96c9d3e34f0ea9119aMark Andrews
a69070d8fab55dbc63ba9f96c9d3e34f0ea9119aMark Andrews if (fprintf(lockfile, "%ld\n", (long)pid) < 0) {
a69070d8fab55dbc63ba9f96c9d3e34f0ea9119aMark Andrews (*report)("fprintf() to pid file '%s' failed", filename);
a69070d8fab55dbc63ba9f96c9d3e34f0ea9119aMark Andrews (void)fclose(lockfile);
a69070d8fab55dbc63ba9f96c9d3e34f0ea9119aMark Andrews cleanup_pidfile();
a69070d8fab55dbc63ba9f96c9d3e34f0ea9119aMark Andrews return;
a69070d8fab55dbc63ba9f96c9d3e34f0ea9119aMark Andrews }
a69070d8fab55dbc63ba9f96c9d3e34f0ea9119aMark Andrews if (fflush(lockfile) == EOF) {
a69070d8fab55dbc63ba9f96c9d3e34f0ea9119aMark Andrews (*report)("fflush() to pid file '%s' failed", filename);
a69070d8fab55dbc63ba9f96c9d3e34f0ea9119aMark Andrews (void)fclose(lockfile);
a69070d8fab55dbc63ba9f96c9d3e34f0ea9119aMark Andrews cleanup_pidfile();
a69070d8fab55dbc63ba9f96c9d3e34f0ea9119aMark Andrews return;
a69070d8fab55dbc63ba9f96c9d3e34f0ea9119aMark Andrews }
a69070d8fab55dbc63ba9f96c9d3e34f0ea9119aMark Andrews (void)fclose(lockfile);
222d38735f97f771054e223b03f84c5858252332Evan Hunt}
a69070d8fab55dbc63ba9f96c9d3e34f0ea9119aMark Andrews
c5272fb3303425f794dab68f734f6a2a45dce01eMichael Sawyervoid
c5272fb3303425f794dab68f734f6a2a45dce01eMichael Sawyerns_os_shutdown(void) {
c5272fb3303425f794dab68f734f6a2a45dce01eMichael Sawyer closelog();
c5272fb3303425f794dab68f734f6a2a45dce01eMichael Sawyer cleanup_pidfile();
c5272fb3303425f794dab68f734f6a2a45dce01eMichael Sawyer ntservice_shutdown(); /* This MUST be the last thing done */
c5272fb3303425f794dab68f734f6a2a45dce01eMichael Sawyer}
c5272fb3303425f794dab68f734f6a2a45dce01eMichael Sawyer
c5272fb3303425f794dab68f734f6a2a45dce01eMichael Sawyerisc_result_t
222d38735f97f771054e223b03f84c5858252332Evan Huntns_os_gethostname(char *buf, size_t len) {
6b9c29ec578de7fda057bd3b893ccda176378b1bMichael Sawyer int n;
6b9c29ec578de7fda057bd3b893ccda176378b1bMichael Sawyer
222d38735f97f771054e223b03f84c5858252332Evan Hunt n = gethostname(buf, len);
222d38735f97f771054e223b03f84c5858252332Evan Hunt return ((n == 0) ? ISC_R_SUCCESS : ISC_R_FAILURE);
6b9c29ec578de7fda057bd3b893ccda176378b1bMichael Sawyer}
a60831febfad9d3c9cabeb22a399238748f69ae6Mark Andrews
6b9c29ec578de7fda057bd3b893ccda176378b1bMichael Sawyervoid
6b9c29ec578de7fda057bd3b893ccda176378b1bMichael Sawyerns_os_shutdownmsg(char *command, isc_buffer_t *text) {
222d38735f97f771054e223b03f84c5858252332Evan Hunt UNUSED(command);
222d38735f97f771054e223b03f84c5858252332Evan Hunt UNUSED(text);
6b9c29ec578de7fda057bd3b893ccda176378b1bMichael Sawyer}
222d38735f97f771054e223b03f84c5858252332Evan Hunt