int main (int argc, char **argv) { mode_t oldumask; char cmdbuf[1024]; /* make sure at least world write access is disabled */ if (((oldumask = umask(022)) & 002) == 002) (void) umask (oldumask); /* * 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) { if (daemon (0, 0) < 0) { /* error */ LogError("daemon() failed, %s\n", _SysErrorMsg (errno)); exit(1); } } if (debugLevel == 0) InitErrorLog (); if (debugLevel >= 10) nofork_session = 1; LogInfo ("Starting\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); } parent_pid = getpid (); (void) signal (SIGTERM, StopAll); (void) signal (SIGINT, StopAll); /* * Step 2 - Read Xservers and set up * the socket. * * Keep a sub-daemon running * for each entry */ ScanServers (); StartDisplays (); (void) signal (SIGHUP, RescanNotify); (void) signal (SIGCHLD, ChildNotify); Debug ("startup successful; entering main loop\n"); while (AnyDisplaysLeft ()) { if (Rescan) { RescanServers (); Rescan = 0; } WaitForChild (); } Debug ("Nothing left to do, exiting\n"); LogInfo ("Exiting\n"); return 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*/ }