/* -*- Mode: C; tab-width: 4 -*-
*
* Copyright (c) 2003-2004 Apple Computer, Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
File: daemon.c
Contains: main & associated Application layer for mDNSResponder on Linux.
*/
#if __APPLE__
// In Mac OS X 10.5 and later trying to use the daemon function gives a “‘daemon’ is deprecated”
// error, which prevents compilation because we build with "-Werror".
// Since this is supposed to be portable cross-platform code, we don't care that daemon is
// deprecated on Mac OS X 10.5, so we use this preprocessor trick to eliminate the error message.
#endif
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <signal.h>
#include <errno.h>
#include <fcntl.h>
#include <pwd.h>
#if __APPLE__
extern int daemon(int, int);
#endif
#include "mDNSEmbeddedAPI.h"
#include "mDNSPosix.h"
#include "mDNSUNP.h" // For daemon()
#include "uds_daemon.h"
#include "PlatformCommon.h"
#ifndef MDNSD_USER
#endif
{
(void)m; // Unused
if (result == mStatus_NoError)
{
// On successful registration of dot-local mDNS host name, daemon may want to check if
// any name conflict and automatic renaming took place, and if so, record the newly negotiated
// name in persistent storage for next time. It should also inform the user of the name change.
// On Mac OS X we store the current dot-local mDNS host name in the SCPreferences store,
// and notify the user with a CFUserNotification.
}
else if (result == mStatus_ConfigChanged)
{
}
else if (result == mStatus_GrowCache)
{
// Allocate another chunk of cache storage
}
}
// %%% Reconfigure() probably belongs in the platform support layer (mDNSPosix.c), not the daemon cde
// -- all client layers running on top of mDNSPosix.c need to handle network configuration changes,
// not only the Unix Domain Socket Daemon
{
if (ParseDNSServers(m, uDNS_SERVERS_FILE) < 0)
LogMsg("Unable to parse DNS server list. Unicast DNS-SD unavailable");
}
// Do appropriate things at startup with command line arguments. Calls exit() if unhappy.
{
if (argc > 1)
{
}
if (!mDNS_DebugMode)
{
#if __APPLE__
LogMsg("The POSIX mdnsd should only be used on OS X for testing - exiting");
exit(-1);
#endif
}
}
{
}
{
}
// Dump a little log of what we've been up to.
{
LogMsg("---- BEGIN STATE LOG ----");
udsserver_info(m);
LogMsg("---- END STATE LOG ----");
}
{
for (; ;)
{
// Work out how long we expect to sleep before the next scheduled task
// Only idle if we didn't find any data the last time around
if (!gotData)
{
}
else // otherwise call EventLoop again with 0 timemout
ticks = 0;
// SIGPIPE happens when we try to write to a dead client; death should be detected soon in request_callback() and cleaned up.
}
return EINTR;
}
{
err = mDNS_Init(&mDNSStorage, &PlatformStorage, gRRCache, RR_CACHE_SIZE, mDNS_Init_AdvertiseLocalAddresses,
if (mStatus_NoError == err)
// Now that we're finished with anything privileged, switch over to running as "nobody"
if (mStatus_NoError == err)
{
else
#ifdef MDNSD_NOROOT
{
}
#else
#endif
}
if (mStatus_NoError == err)
if (udsserver_exit() < 0)
LogMsg("ExitCallback: udsserver_exit failed");
#if MDNS_DEBUGMSGS > 0
#endif
return err;
}
// uds_daemon support ////////////////////////////////////////////////////////////
mStatus udsSupportAddFDToEventLoop(int fd, udsEventCallback callback, void *context, void **platform_data)
/* Support routine for uds_daemon.c */
{
// Depends on the fact that udsEventCallback == mDNSPosixEventCallback
(void) platform_data;
}
{
(void) platform_data;
}
mStatus udsSupportRemoveFDFromEventLoop(int fd, void *platform_data) // Note: This also CLOSES the file descriptor
{
(void) platform_data;
return err;
}
{
(void)m;
(void)delay;
// No-op, for now
}
// If the process crashes, then this string will be magically included in the automatically-generated crash log
asm (".desc ___crashreporter_info__, 0x10");
#endif
// For convenience when using the "strings" command, this is the last thing in the file
#if mDNSResponderVersion > 1
mDNSexport const char mDNSResponderVersionString_SCCS[] = "@(#) mDNSResponder-" STRINGIFY(mDNSResponderVersion) " (" __DATE__ " " __TIME__ ")";
#else
mDNSexport const char mDNSResponderVersionString_SCCS[] = "@(#) mDNSResponder (Engineering Build) (" __DATE__ " " __TIME__ ")";
#endif