示例#1
0
int
main (int argc, char **argv)
{
    int	oldpid;
    mode_t oldumask;
    char cmdbuf[1024];

    /* make sure at least world write access is disabled */
    if (((oldumask = umask(022)) & 002) == 002)
	(void) umask (oldumask);
#ifndef NOXDMTITLE
    Title = argv[0];
    TitleLen = (argv[argc - 1] + strlen(argv[argc - 1])) - Title;
#endif

#ifdef USESECUREWARE
    set_auth_parameters (argc, argv);
#endif

    /*
     * Step 1 - load configuration parameters
     */
    InitResources (argc, argv);
    SetConfigFileTime ();
    LoadDMResources ();
    /*
     * Only allow root to run in non-debug mode to avoid problems
     */
    if (debugLevel == 0 && getuid() != 0)
    {
	fprintf (stderr, "Only root wants to run %s\n", argv[0]);
	exit (1);
    }
    if (debugLevel == 0 && daemonMode)
	BecomeDaemon ();
    if (debugLevel == 0)
	InitErrorLog ();
    if (debugLevel >= 10)
	nofork_session = 1;
    /* SUPPRESS 560 */
    if ((oldpid = StorePid ()))
    {
	if (oldpid == -1)
	    LogError ("Can't create/lock pid file %s\n", pidFile);
	else
	    LogError ("Can't lock pid file %s, another xdm is running (pid %d)\n",
		 pidFile, oldpid);
	exit (1);
    }

    LogInfo ("Starting\n");

    if (atexit (RemovePid))
	LogError ("could not register RemovePid() with atexit()\n");

    if (nofork_session == 0) {
	/* Clean up any old Authorization files */
	/* AUD: all good? */
	snprintf(cmdbuf, sizeof(cmdbuf), "/bin/rm -f %s/authdir/authfiles/A*", authDir);
	system(cmdbuf);
    }
#if!defined(HAVE_ARC4RANDOM) && !defined(DEV_RANDOM)
    AddOtherEntropy ();
#endif
#ifdef XDMCP
    init_session_id ();
    CreateWellKnownSockets ();
#else
    Debug ("xdm: not compiled for XDMCP\n");
#endif
    parent_pid = getpid ();
    (void) Signal (SIGTERM, StopAll);
    (void) Signal (SIGINT, StopAll);
    /*
     * Step 2 - Read /etc/Xservers and set up
     *	    the socket.
     *
     *	    Keep a sub-daemon running
     *	    for each entry
     */
    SetAccessFileTime ();
#ifdef XDMCP
    ScanAccessDatabase ();
    UpdateListenSockets ();
#endif
    ScanServers ();
    StartDisplays ();
#if !defined(HAVE_ARC4RANDOM) && !defined(DEV_RANDOM)
    AddOtherEntropy();
#endif
    (void) Signal (SIGHUP, RescanNotify);
#ifndef UNRELIABLE_SIGNALS
    (void) Signal (SIGCHLD, ChildNotify);
#endif
    Debug ("startup successful; entering main loop\n");
    while (
#ifdef XDMCP
	   AnyWellKnownSockets() ||
#endif
	   AnyDisplaysLeft ())
    {
	if (Rescan)
	{
	    RescanServers ();
	    Rescan = 0;
	}
#if defined(UNRELIABLE_SIGNALS) || !defined(XDMCP)
	WaitForChild ();
#else
	WaitForSomething ();
#endif
    }
    Debug ("Nothing left to do, exiting\n");
    LogInfo ("Exiting\n");
    exit(0);
    /*NOTREACHED*/
}
示例#2
0
文件: dm.c 项目: bbidulock/wdm
int main(int argc, char **argv)
{
	int oldpid, oldumask;
	char cmdbuf[1024];
	int debugMode = 0;

	/* make sure at least world write access is disabled */
	if (((oldumask = umask(022)) & 002) == 002)
		(void)umask(oldumask);
#ifndef NOXDMTITLE
	Title = argv[0];
	TitleLen = (argv[argc - 1] + strlen(argv[argc - 1])) - Title;
#endif

	/*
	 * Step 1 - load configuration parameters
	 */
	InitResources(argc, argv);
	SetConfigFileTime();
	LoadDMResources();
	/*
	 * Only allow root to run in non-debug mode to avoid problems
	 */
	debugMode = (debugLevel.i > WDM_LEVEL_WARNING);
	if (!debugMode && getuid() != 0) {
		fprintf(stderr, "Only root wants to run %s\n", argv[0]);
		exit(1);
	}
	if (!debugMode && daemonMode.i) {
		BecomeOrphan();
		BecomeDaemon();
	}
	/* SUPPRESS 560 */
	if ((oldpid = StorePid())) {
		if (oldpid == -1)
			WDMError("Can't create/lock pid file %s\n", pidFile);
		else
			WDMError("Can't lock pid file %s, another wdm is running " "(pid %d)\n", pidFile, oldpid);
		exit(1);
	}
	WDMLogLevel(debugLevel.i);
	if (useSyslog.i) {
		WDMUseSysLog("wdm", WDMStringToFacility(syslogFacility));
	} else if (errorLogFile && *errorLogFile) {
		int f;
		if ((f = open(errorLogFile, O_CREAT | O_WRONLY | O_APPEND, 0600)) == -1)
			WDMError("cannot open errorLogFile %s\n", errorLogFile);
		else
			WDMLogStream(fdopen(f, "w"));
	}
	/* redirect any messages for stderr into standard logging functions. */
	WDMRedirectStderr(WDM_LEVEL_ERROR);

	/* Clean up any old Authorization files */
	sprintf(cmdbuf, "/bin/rm -f %s/authdir/authfiles/A*", authDir);
	system(cmdbuf);

#ifdef XDMCP
	init_session_id();
	CreateWellKnownSockets();
#else
	WDMDebug("wdm: not compiled for XDMCP\n");
#endif
	parent_pid = getpid();
	(void)Signal(SIGTERM, StopAll);
	(void)Signal(SIGINT, StopAll);
	/*
	 * Step 2 - Read /etc/Xservers and set up
	 *      the socket.
	 *
	 *      Keep a sub-daemon running
	 *      for each entry
	 */
	SetAccessFileTime();
#ifdef XDMCP
	ScanAccessDatabase();
#endif
	ScanServers();
	StartDisplays();
	(void)Signal(SIGHUP, RescanNotify);
	(void)Signal(SIGCHLD, ChildNotify);
	while (
#ifdef XDMCP
			  AnyWellKnownSockets() ||
#endif
			  AnyDisplaysLeft()) {
		if (Rescan) {
			RescanServers();
			Rescan = 0;
		}
		WaitForSomething();
	}
	WDMDebug("Nothing left to do, exiting\n");
	exit(0);
 /*NOTREACHED*/}
示例#3
0
Dispatch()
{
    int         nready,
                result;
    int        *clientReady;
    ClientPtr   client;
    int		op;

    nextFreeClientID = MINCLIENT;
    nClients = 0;

    clientReady = (int *) ALLOCATE_LOCAL(sizeof(int) * MaxClients);
    if (!clientReady)
	return;

    while (1) {
	/* wait for something */
	nready = WaitForSomething(clientReady);

	while (!dispatchException && (--nready >= 0)) {
	    client = currentClient = clients[clientReady[nready]];

	    /* Client can be NULL if CloseDownClient() is called during
	       this dispatchException loop. */
	    if (client == (ClientPtr)NULL) continue;

	    isItTimeToYield = FALSE;

	    while (!isItTimeToYield) {
		result = ReadRequest(client);
		if (result <= 0) {
		    if (result < 0)
			CloseDownClient(client);
		    break;
		}
		client->sequence++;

		if (result > (MAX_REQUEST_SIZE << 2))
		    result = FSBadLength;
		else
		{
		    op = MAJOROP;
		    if (op >= NUM_PROC_VECTORS)
			result = ProcBadRequest (client);
		    else
			result = (*client->requestVector[op]) (client);
		}
		if (result != FSSuccess) {
		    if (client->noClientException != FSSuccess)
			CloseDownClient(client);
		    break;
		}
	    }
	    FlushAllOutput ();
	}
	/* reset if server is a drone and has run out of clients */
	if (drone_server && nClients == 0) {
	    dispatchException |= DE_RESET;
	}
	if (dispatchException) {
	    /* re-read the config file */
	    if (dispatchException & DE_RECONFIG) {
		NoticeF("Re-reading config file\n");
		if (ReadConfigFile(configfilename) != FSSuccess)
		    ErrorF("couldn't parse config file\n");
		SetConfigValues();
		dispatchException &= ~DE_RECONFIG;
	    }
	    /* flush all the caches */
	    if (dispatchException & DE_FLUSH) {
		NoticeF("flushing all caches\n");
		CacheReset();
		dispatchException &= ~DE_FLUSH;
	    }
	    /* reset */
	    if (dispatchException & DE_RESET) {
		NoticeF("resetting\n");
		break;
	    }
	    /* die *now* */
	    if (dispatchException & DE_TERMINATE) {
		NoticeF("terminating\n");
		kill_all_clients();
		exit(0);
		break;
	    }
	}
    }
    kill_all_clients();
    dispatchException = 0;
}