Пример #1
0
static int get_client_mutex(const char*) {
    char buf[MAX_PATH] = "";
    
    // Global mutex on Win2k and later
    //
    if (IsWindows2000Compatible()) {
        strcpy(buf, "Global\\");
    }
    strcat(buf, RUN_MUTEX);

    HANDLE h = CreateMutexA(NULL, true, buf);
    if ((h==0) || (GetLastError() == ERROR_ALREADY_EXISTS)) {
        return ERR_ALREADY_RUNNING;
    }
#else
static int get_client_mutex(const char* dir) {
    char path[MAXPATHLEN];
    static FILE_LOCK file_lock;

    sprintf(path, "%s/%s", dir, LOCK_FILE_NAME);
    int retval = file_lock.lock(path);
    if (retval == ERR_FCNTL) {
        return ERR_ALREADY_RUNNING;
    } else if (retval) {
        return retval;
    }
#endif
    return 0;
}
Пример #2
0
bool CBOINCClientManager::IsBOINCCoreRunning() {
    wxLogTrace(wxT("Function Start/End"), wxT("CBOINCClientManager::IsBOINCCoreRunning - Function Begin"));
    bool running = false;

#ifdef __WXMSW__
    char buf[MAX_PATH] = "";
    
    if (is_daemon_installed()) {
        running = (FALSE != is_daemon_starting()) || (FALSE != is_daemon_running());
    } else {
        // Global mutex on Win2k and later
        //
        safe_strcpy(buf, "Global\\");
        strcat( buf, RUN_MUTEX);

        HANDLE h = CreateMutexA(NULL, true, buf);
        DWORD err = GetLastError();
        if ((h==0) || (err == ERROR_ALREADY_EXISTS)) {
            running = true;
        }
        if (h) {
            CloseHandle(h);
        }
    }
#elif defined(__WXMAC__)
    char path[1024];
    static FILE_LOCK file_lock;
    
    sprintf(path, "%s/%s", (const char *)wxGetApp().GetDataDirectory().mb_str(), LOCK_FILE_NAME);
    if (boinc_file_exists(path)) {   // If there is no lock file, core is not running
        if (file_lock.lock(path)) {
            running = true;
        } else {
            file_lock.unlock(path);
        }
    }
#else
    PROC_MAP pm;
    int retval;

    if (m_lBOINCCoreProcessId) {
        // Prevent client from being a zombie
        if (waitpid(m_lBOINCCoreProcessId, 0, WNOHANG) == m_lBOINCCoreProcessId) {
            m_lBOINCCoreProcessId = 0;
        }
    }

    // Look for BOINC Client in list of all running processes
    retval = procinfo_setup(pm);
    if (retval) return false;     // Should never happen
    
    PROC_MAP::iterator i;
    for (i=pm.begin(); i!=pm.end(); i++) {
        PROCINFO& pi = i->second;
        if (!strcmp(pi.command, "boinc")) {
            running = true;
            break;
        }
        if (!strcmp(pi.command, "boinc_client")) {
            running = true;
            break;
        }
    }
#endif
    wxLogTrace(wxT("Function Status"), wxT("CBOINCClientManager::IsBOINCCoreRunning - Returning '%d'"), (int)running);
    wxLogTrace(wxT("Function Start/End"), wxT("CBOINCClientManager::IsBOINCCoreRunning - Function End"));
    return running;
}