2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
10 #include <afsconfig.h>
11 #include <afs/param.h>
27 #include <rx/rx_prototypes.h>
28 #include <WINNT/afsreg.h>
33 long cm_daemonCheckDownInterval = 180;
34 long cm_daemonCheckUpInterval = 240;
35 long cm_daemonCheckVolInterval = 3600;
36 long cm_daemonCheckCBInterval = 60;
37 long cm_daemonCheckVolCBInterval = 0;
38 long cm_daemonCheckLockInterval = 2;
39 long cm_daemonTokenCheckInterval = 180;
40 long cm_daemonCheckOfflineVolInterval = 600;
41 long cm_daemonPerformanceTuningInterval = 0;
42 long cm_daemonRankServerInterval = 600;
44 osi_rwlock_t cm_daemonLock;
46 long cm_bkgQueueCount; /* # of queued requests */
48 int cm_bkgWaitingForCount; /* true if someone's waiting for cm_bkgQueueCount to drop */
50 cm_bkgRequest_t *cm_bkgListp; /* first elt in the list of requests */
51 cm_bkgRequest_t *cm_bkgListEndp; /* last elt in the list of requests */
53 extern int powerStateSuspended;
54 int daemon_ShutdownFlag = 0;
55 static int cm_nDaemons = 0;
56 static time_t lastIPAddrChange = 0;
58 static EVENT_HANDLE cm_Daemon_ShutdownEvent = NULL;
59 static EVENT_HANDLE cm_LockDaemon_ShutdownEvent = NULL;
60 static EVENT_HANDLE cm_IPAddrDaemon_ShutdownEvent = NULL;
61 static EVENT_HANDLE cm_BkgDaemon_ShutdownEvent[CM_MAX_DAEMONS] =
62 {NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL};
64 void cm_IpAddrDaemon(long parm)
66 extern void smb_CheckVCs(void);
67 char * name = "cm_IPAddrDaemon_ShutdownEvent";
69 cm_IPAddrDaemon_ShutdownEvent = thrd_CreateEvent(NULL, FALSE, FALSE, name);
70 if ( GetLastError() == ERROR_ALREADY_EXISTS )
71 afsi_log("Event Object Already Exists: %s", name);
73 rx_StartClientThread();
75 while (daemon_ShutdownFlag == 0) {
78 thrd_SetEvent(cm_IPAddrDaemon_ShutdownEvent);
79 Result = NotifyAddrChange(NULL,NULL);
80 if (Result == NO_ERROR && daemon_ShutdownFlag == 0) {
81 lastIPAddrChange = osi_Time();
83 smb_SetLanAdapterChangeDetected();
84 cm_SetLanAdapterChangeDetected();
85 thrd_ResetEvent(cm_IPAddrDaemon_ShutdownEvent);
89 thrd_SetEvent(cm_IPAddrDaemon_ShutdownEvent);
92 void cm_BkgDaemon(void * parm)
97 long daemonID = (long)(LONG_PTR)parm;
99 snprintf(name, sizeof(name), "cm_BkgDaemon_ShutdownEvent%u", daemonID);
101 cm_BkgDaemon_ShutdownEvent[daemonID] = thrd_CreateEvent(NULL, FALSE, FALSE, name);
102 if ( GetLastError() == ERROR_ALREADY_EXISTS )
103 afsi_log("Event Object Already Exists: %s", name);
105 rx_StartClientThread();
107 lock_ObtainWrite(&cm_daemonLock);
108 while (daemon_ShutdownFlag == 0) {
109 if (powerStateSuspended) {
113 if (!cm_bkgListEndp) {
114 osi_SleepW((LONG_PTR)&cm_bkgListp, &cm_daemonLock);
115 lock_ObtainWrite(&cm_daemonLock);
119 /* we found a request */
120 for (rp = cm_bkgListEndp; rp; rp = (cm_bkgRequest_t *) osi_QPrev(&rp->q))
122 if (cm_ServerAvailable(&rp->scp->fid, rp->userp) ||
123 rp->scp->flags & CM_SCACHEFLAG_DELETED)
127 /* we couldn't find a request that we could process at the current time */
128 lock_ReleaseWrite(&cm_daemonLock);
130 lock_ObtainWrite(&cm_daemonLock);
134 osi_QRemoveHT((osi_queue_t **) &cm_bkgListp, (osi_queue_t **) &cm_bkgListEndp, &rp->q);
135 osi_assertx(cm_bkgQueueCount-- > 0, "cm_bkgQueueCount 0");
136 lock_ReleaseWrite(&cm_daemonLock);
138 osi_Log1(afsd_logp,"cm_BkgDaemon processing request 0x%p", rp);
140 if (rp->scp->flags & CM_SCACHEFLAG_DELETED) {
141 osi_Log1(afsd_logp,"cm_BkgDaemon DELETED scp 0x%x",rp->scp);
142 code = CM_ERROR_BADFD;
144 #ifdef DEBUG_REFCOUNT
145 osi_Log2(afsd_logp,"cm_BkgDaemon (before) scp 0x%x ref %d",rp->scp, rp->scp->refCount);
147 code = (*rp->procp)(rp->scp, rp->p1, rp->p2, rp->p3, rp->p4, rp->userp, &rp->req);
148 #ifdef DEBUG_REFCOUNT
149 osi_Log2(afsd_logp,"cm_BkgDaemon (after) scp 0x%x ref %d",rp->scp, rp->scp->refCount);
154 * Keep the following list synchronized with the
155 * error code list in cm_BkgStore.
156 * cm_SyncOpDone(CM_SCACHESYNC_ASYNCSTORE) will be called there unless
157 * one of these errors has occurred.
160 case CM_ERROR_TIMEDOUT: /* or server restarting */
162 case CM_ERROR_WOULDBLOCK:
163 case CM_ERROR_ALLBUSY:
164 case CM_ERROR_ALLDOWN:
165 case CM_ERROR_ALLOFFLINE:
166 case CM_ERROR_PARTIALWRITE:
167 if (rp->procp == cm_BkgStore) {
169 "cm_BkgDaemon re-queueing failed request 0x%p code 0x%x",
171 lock_ObtainWrite(&cm_daemonLock);
173 osi_QAddT((osi_queue_t **) &cm_bkgListp, (osi_queue_t **)&cm_bkgListEndp, &rp->q);
175 } /* otherwise fall through */
176 case 0: /* success */
177 default: /* other error */
179 osi_Log1(afsd_logp,"cm_BkgDaemon SUCCESS: request 0x%p", rp);
181 osi_Log2(afsd_logp,"cm_BkgDaemon FAILED: request dropped 0x%p code 0x%x",
184 cm_ReleaseUser(rp->userp);
185 cm_ReleaseSCache(rp->scp);
187 lock_ObtainWrite(&cm_daemonLock);
190 lock_ReleaseWrite(&cm_daemonLock);
191 thrd_SetEvent(cm_BkgDaemon_ShutdownEvent[daemonID]);
194 void cm_QueueBKGRequest(cm_scache_t *scp, cm_bkgProc_t *procp, afs_uint32 p1, afs_uint32 p2, afs_uint32 p3, afs_uint32 p4,
195 cm_user_t *userp, cm_req_t *reqp)
199 rp = malloc(sizeof(*rp));
200 memset(rp, 0, sizeof(*rp));
213 lock_ObtainWrite(&cm_daemonLock);
215 osi_QAdd((osi_queue_t **) &cm_bkgListp, &rp->q);
218 lock_ReleaseWrite(&cm_daemonLock);
220 osi_Wakeup((LONG_PTR) &cm_bkgListp);
224 IsWindowsFirewallPresent(void)
229 BOOLEAN result = FALSE;
230 LPQUERY_SERVICE_CONFIG pConfig = NULL;
234 /* Open services manager */
235 scm = OpenSCManager(NULL, NULL, GENERIC_READ);
236 if (!scm) return FALSE;
238 /* Open Windows Firewall service */
239 svc = OpenService(scm, "MpsSvc", SERVICE_QUERY_CONFIG);
241 afsi_log("MpsSvc Service could not be opened for query: 0x%x", GetLastError());
242 svc = OpenService(scm, "SharedAccess", SERVICE_QUERY_CONFIG);
244 afsi_log("SharedAccess Service could not be opened for query: 0x%x", GetLastError());
249 /* Query Windows Firewall service config, first just to get buffer size */
250 /* Expected to fail, so don't test return value */
251 (void) QueryServiceConfig(svc, NULL, 0, &BufSize);
252 status = GetLastError();
253 if (status != ERROR_INSUFFICIENT_BUFFER)
256 /* Allocate buffer */
257 pConfig = (LPQUERY_SERVICE_CONFIG)GlobalAlloc(GMEM_FIXED,BufSize);
261 /* Query Windows Firewall service config, this time for real */
262 flag = QueryServiceConfig(svc, pConfig, BufSize, &BufSize);
264 afsi_log("QueryServiceConfig failed: 0x%x", GetLastError());
268 /* Is it autostart? */
269 afsi_log("AutoStart 0x%x", pConfig->dwStartType);
270 if (pConfig->dwStartType < SERVICE_DEMAND_START)
276 CloseServiceHandle(svc);
278 CloseServiceHandle(scm);
284 cm_DaemonCheckInit(void)
291 code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSREG_CLT_SVC_PARAM_SUBKEY,
292 0, KEY_QUERY_VALUE, &parmKey);
296 dummyLen = sizeof(DWORD);
297 code = RegQueryValueEx(parmKey, "daemonCheckDownInterval", NULL, NULL,
298 (BYTE *) &dummy, &dummyLen);
299 if (code == ERROR_SUCCESS && dummy)
300 cm_daemonCheckDownInterval = dummy;
301 afsi_log("daemonCheckDownInterval is %d", cm_daemonCheckDownInterval);
303 dummyLen = sizeof(DWORD);
304 code = RegQueryValueEx(parmKey, "daemonCheckUpInterval", NULL, NULL,
305 (BYTE *) &dummy, &dummyLen);
306 if (code == ERROR_SUCCESS && dummy)
307 cm_daemonCheckUpInterval = dummy;
308 afsi_log("daemonCheckUpInterval is %d", cm_daemonCheckUpInterval);
310 dummyLen = sizeof(DWORD);
311 code = RegQueryValueEx(parmKey, "daemonCheckVolInterval", NULL, NULL,
312 (BYTE *) &dummy, &dummyLen);
313 if (code == ERROR_SUCCESS && dummy)
314 cm_daemonCheckVolInterval = dummy;
315 afsi_log("daemonCheckVolInterval is %d", cm_daemonCheckVolInterval);
317 dummyLen = sizeof(DWORD);
318 code = RegQueryValueEx(parmKey, "daemonCheckCBInterval", NULL, NULL,
319 (BYTE *) &dummy, &dummyLen);
320 if (code == ERROR_SUCCESS && dummy)
321 cm_daemonCheckCBInterval = dummy;
322 afsi_log("daemonCheckCBInterval is %d", cm_daemonCheckCBInterval);
324 dummyLen = sizeof(DWORD);
325 code = RegQueryValueEx(parmKey, "daemonCheckVolCBInterval", NULL, NULL,
326 (BYTE *) &dummy, &dummyLen);
327 if (code == ERROR_SUCCESS && dummy)
328 cm_daemonCheckVolCBInterval = dummy;
329 afsi_log("daemonCheckVolCBInterval is %d", cm_daemonCheckVolCBInterval);
331 dummyLen = sizeof(DWORD);
332 code = RegQueryValueEx(parmKey, "daemonCheckLockInterval", NULL, NULL,
333 (BYTE *) &dummy, &dummyLen);
334 if (code == ERROR_SUCCESS && dummy)
335 cm_daemonCheckLockInterval = dummy;
336 afsi_log("daemonCheckLockInterval is %d", cm_daemonCheckLockInterval);
338 dummyLen = sizeof(DWORD);
339 code = RegQueryValueEx(parmKey, "daemonCheckTokenInterval", NULL, NULL,
340 (BYTE *) &dummy, &dummyLen);
341 if (code == ERROR_SUCCESS && dummy)
342 cm_daemonTokenCheckInterval = dummy;
343 afsi_log("daemonCheckTokenInterval is %d", cm_daemonTokenCheckInterval);
345 dummyLen = sizeof(DWORD);
346 code = RegQueryValueEx(parmKey, "daemonCheckOfflineVolInterval", NULL, NULL,
347 (BYTE *) &dummy, &dummyLen);
348 if (code == ERROR_SUCCESS && dummy)
349 cm_daemonCheckOfflineVolInterval = dummy;
350 afsi_log("daemonCheckOfflineVolInterval is %d", cm_daemonCheckOfflineVolInterval);
352 dummyLen = sizeof(DWORD);
353 code = RegQueryValueEx(parmKey, "daemonPerformanceTuningInterval", NULL, NULL,
354 (BYTE *) &dummy, &dummyLen);
355 if (code == ERROR_SUCCESS)
356 cm_daemonPerformanceTuningInterval = dummy;
357 afsi_log("daemonPerformanceTuningInterval is %d", cm_daemonPerformanceTuningInterval);
359 dummyLen = sizeof(DWORD);
360 code = RegQueryValueEx(parmKey, "daemonRankServerInterval", NULL, NULL,
361 (BYTE *) &dummy, &dummyLen);
362 if (code == ERROR_SUCCESS && dummy)
363 cm_daemonRankServerInterval = dummy;
364 afsi_log("daemonRankServerInterval is %d", cm_daemonRankServerInterval);
366 RegCloseKey(parmKey);
368 if (cm_daemonPerformanceTuningInterval)
369 cm_PerformanceTuningInit();
372 /* periodic lock check daemon */
373 void cm_LockDaemon(long parm)
376 time_t lastLockCheck;
377 char * name = "cm_LockDaemon_ShutdownEvent";
379 cm_LockDaemon_ShutdownEvent = thrd_CreateEvent(NULL, FALSE, FALSE, name);
380 if ( GetLastError() == ERROR_ALREADY_EXISTS )
381 afsi_log("Event Object Already Exists: %s", name);
384 lastLockCheck = now - cm_daemonCheckLockInterval/2 + (rand() % cm_daemonCheckLockInterval);
386 while (daemon_ShutdownFlag == 0) {
387 if (powerStateSuspended) {
394 if (now > lastLockCheck + cm_daemonCheckLockInterval &&
395 daemon_ShutdownFlag == 0 &&
396 powerStateSuspended == 0) {
399 if (daemon_ShutdownFlag == 1)
403 thrd_Sleep(1000); /* sleep 1 second */
405 thrd_SetEvent(cm_LockDaemon_ShutdownEvent);
408 /* periodic check daemon */
409 void cm_Daemon(long parm)
413 time_t lastCBExpirationCheck;
414 time_t lastVolCBRenewalCheck;
415 time_t lastDownServerCheck;
416 time_t lastUpServerCheck;
417 time_t lastTokenCacheCheck;
418 time_t lastBusyVolCheck;
419 time_t lastPerformanceCheck;
420 time_t lastServerRankCheck;
425 char * name = "cm_Daemon_ShutdownEvent";
426 int configureFirewall = IsWindowsFirewallPresent();
427 int bAddrChangeCheck = 0;
429 cm_Daemon_ShutdownEvent = thrd_CreateEvent(NULL, FALSE, FALSE, name);
430 if ( GetLastError() == ERROR_ALREADY_EXISTS )
431 afsi_log("Event Object Already Exists: %s", name);
433 if (!configureFirewall) {
434 afsi_log("No Windows Firewall detected");
437 if (cm_freelanceEnabled && cm_freelanceImportCellServDB)
438 cm_FreelanceImportCellServDB();
440 /* ping all file servers, up or down, with unauthenticated connection,
441 * to find out whether we have all our callbacks from the server still.
442 * Also, ping down VLDBs.
445 * Seed the random number generator with our own address, so that
446 * clients starting at the same time don't all do vol checks at the
449 gethostname(thostName, sizeof(thostName));
450 thp = gethostbyname(thostName);
451 if (thp == NULL) /* In djgpp, gethostname returns the netbios
452 name of the machine. gethostbyname will fail
453 looking this up if it differs from DNS name. */
456 memcpy(&code, thp->h_addr_list[0], 4);
460 cm_DaemonCheckInit();
463 lastVolCheck = now - cm_daemonCheckVolInterval/2 + (rand() % cm_daemonCheckVolInterval);
464 lastCBExpirationCheck = now - cm_daemonCheckCBInterval/2 + (rand() % cm_daemonCheckCBInterval);
465 if (cm_daemonCheckVolCBInterval)
466 lastVolCBRenewalCheck = now - cm_daemonCheckVolCBInterval/2 + (rand() % cm_daemonCheckVolCBInterval);
467 lastDownServerCheck = now - cm_daemonCheckDownInterval/2 + (rand() % cm_daemonCheckDownInterval);
468 lastUpServerCheck = now - cm_daemonCheckUpInterval/2 + (rand() % cm_daemonCheckUpInterval);
469 lastTokenCacheCheck = now - cm_daemonTokenCheckInterval/2 + (rand() % cm_daemonTokenCheckInterval);
470 if (cm_daemonCheckOfflineVolInterval)
471 lastBusyVolCheck = now - cm_daemonCheckOfflineVolInterval/2 * (rand() % cm_daemonCheckOfflineVolInterval);
472 if (cm_daemonPerformanceTuningInterval)
473 lastPerformanceCheck = now - cm_daemonPerformanceTuningInterval/2 * (rand() % cm_daemonPerformanceTuningInterval);
474 lastServerRankCheck = now - cm_daemonRankServerInterval/2 * (rand() % cm_daemonRankServerInterval);
476 while (daemon_ShutdownFlag == 0) {
477 if (powerStateSuspended) {
481 /* check to see if the listener threads halted due to network
482 * disconnect or other issues. If so, attempt to restart them.
484 smb_RestartListeners(0);
486 if (daemon_ShutdownFlag == 1)
489 if (configureFirewall) {
490 /* Open Microsoft Firewall to allow in port 7001 */
491 switch (icf_CheckAndAddAFSPorts(AFS_PORTSET_CLIENT)) {
493 afsi_log("Windows Firewall Configuration succeeded");
494 configureFirewall = 0;
497 afsi_log("Invalid Windows Firewall Port Set");
500 afsi_log("Unable to open Windows Firewall Profile");
503 afsi_log("Unable to create/modify Windows Firewall Port entries");
506 afsi_log("Unknown Windows Firewall Configuration error");
510 /* find out what time it is */
513 /* Determine whether an address change took place that we need to respond to */
514 if (bAddrChangeCheck)
515 bAddrChangeCheck = 0;
517 if (lastIPAddrChange != 0 && lastIPAddrChange + 2500 < now) {
518 bAddrChangeCheck = 1;
519 lastIPAddrChange = 0;
522 /* check down servers */
523 if ((bAddrChangeCheck || now > lastDownServerCheck + cm_daemonCheckDownInterval) &&
524 daemon_ShutdownFlag == 0 &&
525 powerStateSuspended == 0) {
526 lastDownServerCheck = now;
527 osi_Log0(afsd_logp, "cm_Daemon CheckDownServers");
528 cm_CheckServers(CM_FLAG_CHECKDOWNSERVERS, NULL);
529 if (daemon_ShutdownFlag == 1)
534 if (bAddrChangeCheck &&
535 daemon_ShutdownFlag == 0 &&
536 powerStateSuspended == 0) {
537 cm_ForceNewConnectionsAllServers();
540 /* check up servers */
541 if ((bAddrChangeCheck || now > lastUpServerCheck + cm_daemonCheckUpInterval) &&
542 daemon_ShutdownFlag == 0 &&
543 powerStateSuspended == 0) {
544 lastUpServerCheck = now;
545 osi_Log0(afsd_logp, "cm_Daemon CheckUpServers");
546 cm_CheckServers(CM_FLAG_CHECKUPSERVERS, NULL);
547 if (daemon_ShutdownFlag == 1)
552 if (bAddrChangeCheck &&
553 daemon_ShutdownFlag == 0 &&
554 powerStateSuspended == 0) {
556 cm_VolStatus_Network_Addr_Change();
560 * Once every five minutes inspect the volume list and enforce
561 * the volume location expiration time.
563 if (now > lastVolCheck + 300 &&
564 daemon_ShutdownFlag == 0 &&
565 powerStateSuspended == 0) {
567 cm_RefreshVolumes(cm_daemonCheckVolInterval);
568 if (daemon_ShutdownFlag == 1)
573 /* Rank all up servers */
574 if ((now > lastServerRankCheck + cm_daemonRankServerInterval) &&
575 daemon_ShutdownFlag == 0 &&
576 powerStateSuspended == 0) {
577 lastServerRankCheck = now;
578 osi_Log0(afsd_logp, "cm_Daemon RankServer");
580 if(daemon_ShutdownFlag == 1)
585 if (cm_daemonCheckVolCBInterval &&
586 now > lastVolCBRenewalCheck + cm_daemonCheckVolCBInterval &&
587 daemon_ShutdownFlag == 0 &&
588 powerStateSuspended == 0) {
589 lastVolCBRenewalCheck = now;
590 cm_VolumeRenewROCallbacks();
591 if (daemon_ShutdownFlag == 1)
596 if ((bAddrChangeCheck || (cm_daemonCheckOfflineVolInterval &&
597 now > lastBusyVolCheck + cm_daemonCheckOfflineVolInterval)) &&
598 daemon_ShutdownFlag == 0 &&
599 powerStateSuspended == 0) {
600 lastBusyVolCheck = now;
601 cm_CheckOfflineVolumes();
602 if (daemon_ShutdownFlag == 1)
607 if (now > lastCBExpirationCheck + cm_daemonCheckCBInterval &&
608 daemon_ShutdownFlag == 0 &&
609 powerStateSuspended == 0) {
610 lastCBExpirationCheck = now;
611 cm_CheckCBExpiration();
612 if (daemon_ShutdownFlag == 1)
617 if (now > lastTokenCacheCheck + cm_daemonTokenCheckInterval &&
618 daemon_ShutdownFlag == 0 &&
619 powerStateSuspended == 0) {
620 lastTokenCacheCheck = now;
621 cm_CheckTokenCache(now);
622 if (daemon_ShutdownFlag == 1)
627 /* allow an exit to be called prior to stopping the service */
628 hHookDll = cm_LoadAfsdHookLib();
632 AfsdDaemonHook daemonHook = ( AfsdDaemonHook ) GetProcAddress(hHookDll, AFSD_DAEMON_HOOK);
635 hookRc = daemonHook();
637 FreeLibrary(hHookDll);
642 SetEvent(WaitToTerminate);
645 if (daemon_ShutdownFlag == 1) {
651 if (cm_daemonPerformanceTuningInterval &&
652 now > lastPerformanceCheck + cm_daemonPerformanceTuningInterval &&
653 daemon_ShutdownFlag == 0 &&
654 powerStateSuspended == 0) {
655 lastPerformanceCheck = now;
656 cm_PerformanceTuningCheck();
657 if (daemon_ShutdownFlag == 1)
663 * sleep .5 seconds. if the thread blocks for a long time
664 * we risk not being able to close the cache before Windows
665 * kills our process during system shutdown.
670 thrd_SetEvent(cm_Daemon_ShutdownEvent);
673 void cm_DaemonShutdown(void)
678 daemon_ShutdownFlag = 1;
679 osi_Wakeup((LONG_PTR) &cm_bkgListp);
681 /* wait for shutdown */
682 for ( i=0; i<cm_nDaemons; i++) {
683 if (cm_BkgDaemon_ShutdownEvent[i])
684 code = thrd_WaitForSingleObject_Event(cm_BkgDaemon_ShutdownEvent[i], INFINITE);
687 if (cm_Daemon_ShutdownEvent)
688 code = thrd_WaitForSingleObject_Event(cm_Daemon_ShutdownEvent, INFINITE);
690 if (cm_LockDaemon_ShutdownEvent)
691 code = thrd_WaitForSingleObject_Event(cm_LockDaemon_ShutdownEvent, INFINITE);
695 * Do not waste precious time waiting for the ipaddr daemon to shutdown.
696 * When it does it means we have lost our network connection and we need
697 * it during cache shutdown in order to notify the file servers that this
698 * client is giving up all callbacks.
700 if (cm_IPAddrDaemon_ShutdownEvent)
701 code = thrd_WaitForSingleObject_Event(cm_IPAddrDaemon_ShutdownEvent, INFINITE);
705 void cm_InitDaemon(int nDaemons)
707 static osi_once_t once;
712 cm_nDaemons = (nDaemons > CM_MAX_DAEMONS) ? CM_MAX_DAEMONS : nDaemons;
714 if (osi_Once(&once)) {
715 lock_InitializeRWLock(&cm_daemonLock, "cm_daemonLock",
716 LOCK_HIERARCHY_DAEMON_GLOBAL);
719 /* creating IP Address Change monitor daemon */
720 phandle = thrd_Create((SecurityAttrib) 0, 0,
721 (ThreadFunc) cm_IpAddrDaemon, 0, 0, &pid, "cm_IpAddrDaemon");
722 osi_assertx(phandle != NULL, "cm_IpAddrDaemon thread creation failure");
723 thrd_CloseHandle(phandle);
725 /* creating pinging daemon */
726 phandle = thrd_Create((SecurityAttrib) 0, 0,
727 (ThreadFunc) cm_Daemon, 0, 0, &pid, "cm_Daemon");
728 osi_assertx(phandle != NULL, "cm_Daemon thread creation failure");
729 thrd_CloseHandle(phandle);
731 phandle = thrd_Create((SecurityAttrib) 0, 0,
732 (ThreadFunc) cm_LockDaemon, 0, 0, &pid, "cm_LockDaemon");
733 osi_assertx(phandle != NULL, "cm_LockDaemon thread creation failure");
734 thrd_CloseHandle(phandle);
736 for(i=0; i < cm_nDaemons; i++) {
737 phandle = thrd_Create((SecurityAttrib) 0, 0,
738 (ThreadFunc) cm_BkgDaemon, (LPVOID)(LONG_PTR)i, 0, &pid,
740 osi_assertx(phandle != NULL, "cm_BkgDaemon thread creation failure");
741 thrd_CloseHandle(phandle);