/// Delete the file located at path. /// If "retry" is set, do retries for 5 sec in case some /// other program (e.g. virus checker) has the file locked. /// Don't do this if deleting directories - it can lock up the Manager. /// /// \param[in] path The path name of the file that should be deleted. /// \param[in] retry If true this function will try to delete the file /// multiple times if the first attempt failed. /// \return Zero on success, ERR_UNLINK on error. int delete_project_owned_file(const char* path, bool retry) { int retval = 0; if (!boinc_file_or_symlink_exists(path)) { return 0; } retval = delete_project_owned_file_aux(path); if (retval && retry) { double start = dtime(); do { boinc_sleep(drand() * 2.0); // avoid lockstep retval = delete_project_owned_file_aux(path); if (!retval) break; } while (dtime() < start + FILE_RETRY_INTERVAL); } if (retval) { safe_strcpy(boinc_failed_file, path); return ERR_UNLINK; } return 0; }
// Delete the file located at path. // If "retry" is set, do retries for 5 sec in case some // other program (e.g. virus checker) has the file locked. // Don't do this if deleting directories - it can lock up the Manager. // int delete_project_owned_file(const char* path, bool retry) { int retval = 0; if (!boinc_file_or_symlink_exists(path)) { return 0; } retval = delete_project_owned_file_aux(path); if (retval && retry) { double start = dtime(); do { boinc_sleep(drand()*2); // avoid lockstep retval = delete_project_owned_file_aux(path); if (!retval) break; } while (dtime() < start + FILE_RETRY_INTERVAL); } if (retval) { safe_strcpy(boinc_failed_file, path); return ERR_UNLINK; } if (log_flags.slot_debug) { msg_printf(0, MSG_INFO, "[slot] removed file %s", path); } return 0; }
bool CSensorMacUSBONavi::detect() { // first see if the port actually exists (the device is a "file" at /dev/tty.xrusbmodemNNN, given in STR_USB_ONAVI01 and now STR_USB_ONAVI02 since they seem to have changed the device name // use glob to match names, if count is > 0, we found a match glob_t gt; memset(>, 0x00, sizeof(glob_t)); if (glob(STR_USB_ONAVI01, GLOB_NOCHECK, NULL, >) || !gt.gl_matchc) { // either glob failed or no match // device string failed, but try the new string onavi (really Exar USB driver) may be using if (glob(STR_USB_ONAVI02, GLOB_NOCHECK, NULL, >) || !gt.gl_matchc) { // either glob failed or no match globfree(>); return false; } } char* strDevice = new char[_MAX_PATH]; memset(strDevice, 0x00, sizeof(char) * _MAX_PATH); strncpy(strDevice, gt.gl_pathv[0], _MAX_PATH); globfree(>); // can get rid of gt now if (!boinc_file_or_symlink_exists(strDevice)) { delete [] strDevice; strDevice = NULL; return false; } m_fd = open(strDevice, O_RDWR); // | O_NOCTTY | O_NONBLOCK); delete [] strDevice; // don't need strDevice after this call strDevice = NULL; if (m_fd == -1) { //failure return false; } // if here we opened the port, now set comm params struct termios tty; if (tcgetattr(m_fd, &tty) == -1) { // get current terminal state closePort(); return false; } cfmakeraw(&tty); // get raw tty settings // set terminal speed 115.2K if (cfsetspeed(&tty, B115200) == -1) { closePort(); return false; } // flow contol tty.c_iflag = 0; tty.c_oflag = 0; tty.c_cflag = CS8 | CREAD | CLOCAL; if (tcsetattr(m_fd, TCSANOW, &tty) == -1 || tcsendbreak(m_fd, 10) == -1 ) { // tcflow(m_fd, TCION) == -1) { // || tcflush(m_fd, TCIOFLUSH) == -1) { closePort(); return false; } setPort(m_fd); setSingleSampleDT(true); // onavi samples itself // try to read a value and get the sensor bit-type (& hence sensor type) float x,y,z; m_usBitSensor = 0; if (read_xyz(x,y,z) && m_usBitSensor > 0) { // exists, so setPort & Type switch(m_usBitSensor) { case 12: setType(SENSOR_USB_ONAVI_A_12); break; case 16: setType(SENSOR_USB_ONAVI_B_16); break; case 24: setType(SENSOR_USB_ONAVI_C_24); break; default: // error! closePort(); return false; } } else { closePort(); return false; } return true; }