VOID RdrTree2Revive( PRDR_TREE2 pTree ) { if (pTree->pTimeout) { LwRtlCancelTask(pTree->pTimeout); LwRtlReleaseTask(&pTree->pTimeout); } }
static VOID DispatchSignal( siginfo_t* pInfo ) { RING dispatch; PRING pBase = NULL; PRING pRing = NULL; PRING pNext = NULL; PLW_SIGNAL_SUBSCRIPTION pSub = NULL; if (!gSignal.pSubscribers || pInfo->si_signo > gSignal.maxSig || pInfo->si_signo < 0) { return; } RingInit(&dispatch); pBase = &gSignal.pSubscribers[pInfo->si_signo]; for (pRing = pBase->pNext; pRing != pBase; pRing = pRing->pNext) { pSub = LW_STRUCT_FROM_FIELD(pRing, LW_SIGNAL_SUBSCRIPTION, Ring); pSub->ucRefCount++; RingInit(&pSub->DispatchRing); RingEnqueue(&dispatch, &pSub->DispatchRing); } UNLOCK_SIGNAL(); for (pRing = dispatch.pNext; pRing != &dispatch; pRing = pRing->pNext) { pSub = LW_STRUCT_FROM_FIELD(pRing, LW_SIGNAL_SUBSCRIPTION, DispatchRing); NotifyTaskUnixSignal(pSub->pTask, pInfo); } LOCK_SIGNAL(); for (pRing = dispatch.pNext; pRing != &dispatch; pRing = pNext) { pNext = pRing->pNext; pSub = LW_STRUCT_FROM_FIELD(pRing, LW_SIGNAL_SUBSCRIPTION, DispatchRing); if (--pSub->ucRefCount == 0) { RingRemove(&pSub->Ring); LwRtlReleaseTask(&pSub->pTask); LwRtlMemoryFree(pSub); } } }
static NTSTATUS RdrTree2DestroyContents( PRDR_TREE2 pTree ) { LWIO_SAFE_FREE_MEMORY(pTree->pwszPath); if (pTree->pTimeout) { LwRtlCancelTask(pTree->pTimeout); LwRtlReleaseTask(&pTree->pTimeout); } if (pTree->pDisconnectContext) { RdrFreeContext(pTree->pDisconnectContext); } return 0; }
static DWORD LwSmMain( VOID ) { DWORD dwError = 0; PLW_TASK pTask = NULL; dwError = LwNtStatusToWin32Error(LwRtlCreateTask( gpPool, &pTask, NULL, MainTask, NULL)); BAIL_ON_ERROR(dwError); LwRtlWakeTask(pTask); dwError = LwNtStatusToWin32Error(LwRtlMain()); BAIL_ON_ERROR(dwError); cleanup: if (pTask) { LwRtlCancelTask(pTask); LwRtlWaitTask(pTask); LwRtlReleaseTask(&pTask); } return dwError; error: goto cleanup; }
NTSTATUS RegisterTaskUnixSignal( LW_IN PLW_TASK pTask, LW_IN int Sig, LW_IN LW_BOOLEAN bSubscribe ) { NTSTATUS status = STATUS_SUCCESS; size_t i = 0; PRING pBase = NULL; PRING pRing = NULL; PLW_SIGNAL_SUBSCRIPTION pExisting = NULL; PLW_SIGNAL_SUBSCRIPTION pSub = NULL; struct sigaction action; #ifdef SIGRTMAX int maxSig = SIGRTMAX; #else int maxSig = SIGUSR2; #endif if (Sig == 0) { for (i = 1; i < maxSig + 1; i++) { status = RegisterTaskUnixSignal(pTask, (int) i, bSubscribe); if (status) { return status; } } return STATUS_SUCCESS; } LOCK_SIGNAL(); if (Sig > maxSig || Sig < 0) { status = STATUS_INVALID_PARAMETER; GOTO_ERROR_ON_STATUS(status); } if (!gSignal.pSubscribers) { status = LW_RTL_ALLOCATE_ARRAY_AUTO(&gSignal.pSubscribers, maxSig + 1); GOTO_ERROR_ON_STATUS(status); for (i = 0; i < maxSig + 1; i++) { RingInit(&gSignal.pSubscribers[i]); } gSignal.maxSig = maxSig; } pBase = &gSignal.pSubscribers[Sig]; for (pRing = pBase->pNext; pRing != pBase; pRing = pRing->pNext) { pSub = LW_STRUCT_FROM_FIELD(pRing, LW_SIGNAL_SUBSCRIPTION, Ring); if (pSub->pTask == pTask) { pExisting = pSub; break; } } if (bSubscribe && !pExisting) { if (Sig != SIGINT) { memset(&action, 0, sizeof(action)); /* Make sure there is a dummy handler for the signal so it is actually delivered to the process */ action.sa_handler = DummyHandler; action.sa_flags = 0; if (sigaction(Sig, &action, NULL) < 0) { status = LwErrnoToNtStatus(errno); GOTO_ERROR_ON_STATUS(status); } } status = LW_RTL_ALLOCATE_AUTO(&pSub); GOTO_ERROR_ON_STATUS(status); pSub->pTask = pTask; pSub->ucRefCount = 1; RingInit(&pSub->Ring); RingInit(&pSub->DispatchRing); RingEnqueue(pBase, &pSub->Ring); RetainTask(pTask); } else if (!bSubscribe && pExisting) { RingRemove(&pExisting->Ring); if (--pExisting->ucRefCount == 0) { LwRtlReleaseTask(&pExisting->pTask); LwRtlMemoryFree(pExisting); } } error: UNLOCK_SIGNAL(); return status; }
static DWORD LwSmCmdTapLog( int argc, char** pArgv ) { DWORD error = ERROR_SUCCESS; PLW_THREAD_POOL pPool = NULL; PLW_TASK pTask = NULL; BOOLEAN bResetLogger = FALSE; BOOLEAN bRmPipe = FALSE; LW_SM_LOGGER_TYPE oldLogger = 0; PSTR pOldTarget = NULL; LW_SM_LOG_LEVEL oldLevel = 0; LW_SM_LOG_LEVEL newLevel = 0; PSTR pFacility = NULL; LW_SERVICE_HANDLE hHandle = NULL; PWSTR pServiceName = NULL; PSTR pFifo = NULL; int FifoFd = -1; if (argc < 4) { error = LW_ERROR_INVALID_PARAMETER; BAIL_ON_ERROR(error); } if (strcmp(pArgv[1], "-")) { error = LwMbsToWc16s(pArgv[1], &pServiceName); BAIL_ON_ERROR(error); error = LwSmAcquireServiceHandle(pServiceName, &hHandle); BAIL_ON_ERROR(error); } if (strcmp(pArgv[2], "-")) { pFacility = pArgv[2]; } error = LwSmLogLevelNameToLogLevel(pArgv[3], &newLevel); BAIL_ON_ERROR(error); error = LwSmGetServiceLogState(hHandle, pFacility, &oldLogger, &pOldTarget, &oldLevel); BAIL_ON_ERROR(error); error = LwAllocateStringPrintf(&pFifo, "/tmp/.lwsm-log-tap-%lu", (unsigned long) getpid()); BAIL_ON_ERROR(error); LwRtlBlockSignals(); if (mknod(pFifo, S_IRUSR | S_IWUSR | S_IFIFO, 0) < 0) { error = LwErrnoToWin32Error(errno); BAIL_ON_ERROR(error); } bRmPipe = TRUE; if ((FifoFd = open(pFifo, O_RDONLY | O_NONBLOCK)) < 0) { error = LwErrnoToWin32Error(errno); BAIL_ON_ERROR(error); } if (fcntl(FifoFd, F_SETFL, O_NONBLOCK) < 0) { error = LwErrnoToWin32Error(errno); BAIL_ON_ERROR(error); } error = LwSmSetServiceLogTarget(hHandle, pFacility, LW_SM_LOGGER_FILE, pFifo); BAIL_ON_ERROR(error); bResetLogger = TRUE; error = LwSmSetServiceLogLevel(hHandle, pFacility, newLevel); BAIL_ON_ERROR(error); error = LwNtStatusToWin32Error(LwRtlCreateThreadPool(&pPool, NULL)); BAIL_ON_ERROR(error); error = LwNtStatusToWin32Error(LwRtlCreateTask(pPool, &pTask, NULL, LogTapper, &FifoFd)); BAIL_ON_ERROR(error); LwRtlWakeTask(pTask); error = LwNtStatusToWin32Error(LwRtlMain()); BAIL_ON_ERROR(error); error: if (pTask) { LwRtlCancelTask(pTask); LwRtlWaitTask(pTask); LwRtlReleaseTask(&pTask); } LwRtlFreeThreadPool(&pPool); if (bResetLogger) { error = LwSmSetServiceLogLevel(hHandle, pFacility, oldLevel); BAIL_ON_ERROR(error); error = LwSmSetServiceLogTarget(hHandle, pFacility, oldLogger, pOldTarget); BAIL_ON_ERROR(error); } if (pOldTarget) { LwSmFreeLogTarget(pOldTarget); } if (FifoFd >= 0) { close(FifoFd); } if (bRmPipe) { unlink(pFifo); } LW_SAFE_FREE_MEMORY(pFifo); return error; }