STATUS usrRamDiskInit () { BLK_DEV *pBlkDev; DOS_VOL_DESC *pVolDesc; /* create a ram disk */ pBlkDev=ramDevCreate(0, 512, 400, 200000, 0); if(pBlkDev==NULL){ printf("ran disk create error!!\n"); printErrno(); return ERROR; } /* Create Ram Disk Device */ /*if(dosFsDevCreate("/ram0", pBlkDev, 4, NULL)==NULL){ printf("create ramdisk error!!!\n"); printErrno(); return ERROR; }*/ /* Format dosFs */ /*if(dosFsVolFormat(pBlkDev, DOS_OPT_BLANK | DOS_OPT_QUIET | DOS_OPT_FAT32, NULL)==NULL){ printf("Format dosFs error!!!\n"); printErrno(); return ERROR; }*/ pVolDesc=dosFsMkfs("/ram0",pBlkDev); return OK; }
/** * Handles errors generated by task related code. */ bool Task::HandleError(STATUS results) { if (results != ERROR) return true; switch(errnoGet()) { case S_objLib_OBJ_ID_ERROR: wpi_setWPIErrorWithContext(TaskIDError, m_taskName); break; case S_objLib_OBJ_DELETED: wpi_setWPIErrorWithContext(TaskDeletedError, m_taskName); break; case S_taskLib_ILLEGAL_OPTIONS: wpi_setWPIErrorWithContext(TaskOptionsError, m_taskName); break; case S_memLib_NOT_ENOUGH_MEMORY: wpi_setWPIErrorWithContext(TaskMemoryError, m_taskName); break; case S_taskLib_ILLEGAL_PRIORITY: wpi_setWPIErrorWithContext(TaskPriorityError, m_taskName); break; default: printErrno(errnoGet()); wpi_setWPIErrorWithContext(TaskError, m_taskName); } return false; }
void nfsd_debugno() { if (!nfsd_debug_on) return; printErrno(errnoGet()); }
bool normalizedSleepers() { char value[256] = {0,}; if (readStringFromFile(kSchedFeatures, value, sizeof(value)) == -1) { printErrno(kDebugfsWarningMsg, kSchedFeatures); return false; } return strstr(value, "NO_NEW_FAIR_SLEEPERS") == NULL; }
bool Editor::executeCommand() { bool ret(false); if(_cmd == ":q") { std::lock_guard<std::recursive_mutex> lock(_mutex); ret = true; _mode = EXIT; } else if(_cmd == ":w") { std::lock_guard<std::recursive_mutex> lock(_mutex); ret = true; saveFile(); _mode = EXIT; } else if(_cmd == ":x") { std::lock_guard<std::recursive_mutex> lock(_mutex); ret = true; _mode = EXIT; } else if(_cmd.find(":exec") == 0) { refresh(); std::vector<std::string> arguments; splitString(_cmd, ' ', arguments); if(arguments[1] == "ssh") { refresh(); endwin(); std::string pass = _pBuff->lines[_y]; std::string host = _pBuff->lines[_y-1]; std::string::size_type loc = pass.find("pass: "******"ssh "); if(loc == 0) host.erase(0, 4); int ret = execlp("sshpass", "sshpass", "-p", pass.c_str(), "ssh", "-oStrictHostKeyChecking=no", host.c_str(), NULL); if(ret < 0) { std::cerr << "exec failed! returning to editor..." << std::endl; printErrno(); sleep(2); } } } // Reset command buffer _cmd.clear(); return ret; }
int Reader::Read() { fd_set readFdSet; int retval = ERROR; FD_ZERO(&readFdSet); FD_SET(m_inputStreamFd, &readFdSet); if (select(FD_SETSIZE, &readFdSet, NULL, NULL, NULL) != ERROR) { if (FD_ISSET(m_inputStreamFd, &readFdSet)) { char readbuf; retval = recv(m_inputStreamFd, &readbuf, 1, 0); m_lastByte = readbuf; if (retval != ERROR && retval > 0) { #ifdef DEBUG if (m_lastByte != kNetworkTables_PING) { char pbuf[6]; snprintf(pbuf, 6, "I:%02X\n", m_lastByte); printf(pbuf); } #endif return m_lastByte; } } } else if (!m_connection->IsConnected()) { // The error came from us closing the socket return 0; } // TODO: Should we ignore ECONNRESET errors? if (retval == ERROR) { char buf[32] = ""; int err = errnoGet(); snprintf(buf, 32, "errno=%d", err); wpi_setStaticWPIErrorWithContext(m_connection, NetworkTablesReadError, buf); printErrno(err); } m_connection->Close(); return 0; }
int testBoxing(){ #ifdef test box toFill = {5,1,0,0,42}; box done; int ret = 0; MSG_Q_ID mid_boxing_todo = msgQCreate(10,4,0); MSG_Q_ID mid_boxing_done = msgQCreate(10,4,0); MSG_Q_ID mid_received_part = msgQCreate(10,4,0); printf("Starting conditionning"); taskSpawn("testBoxing",10,0,15000,(FUNCPTR)startBoxing,0,0,0,0,0,0,0,0,0,0); printf("Asking for batch production : \n"); printf("\tBatchNumber=%d\n",toFill.batchNumber); printf("\tBoxSize=%d\n",toFill.size); printf("\tPartsType=%d\n",toFill.partsType); ret=msgQSend(mid_boxing_todo,(char*)&toFill,sizeof(toFill),WAIT_FOREVER,MSG_PRI_NORMAL); if(ret==ERROR){ printf("[FAIL],"); printErrno(errnoGet()); printf("\n"); return; } printf("[OK]\n"); printf("Starting part type 1 generation..."); if (partProdTid!=0){ printf("[FAIL], Production already started.\n"); return; } partProdTid=taskSpawn("partProd1",5,0,10000,(FUNCPTR)startPartProd,1,0,0,0,0,0,0,0,0,0); printf("[OK]\n"); for(;;){ printf("Waiting for boxes done...\n"); if (msgQReceive(mid_boxing_done,(char*)&done,sizeof(done),5)==-1){ return 1; } printf("Received :\n"); printf("\t Box size : %d\n",done.size); printf("\t Part type : %d\n",done.partsType); } #else printf("You must compile the application with 'test' defined to use this functionality!\n"); #endif return 0; }
bool waitForChildrenAndSignal(int mProcessNb, int readfd, int writefd) { if (readfd > writefd) { fprintf(stderr, "Called with args in wrong order!!\n"); return false; } bool error; int attempts; size_t size; for (int p = 0; p < mProcessNb; ++p) { bool eof = false; pid_t pid; char *end = reinterpret_cast<char *>(&pid); error = false; attempts = 0; size = sizeof(pid); while (size > 0 && !error && !eof && attempts < kMaxAttempts) { ssize_t s; s = read(readfd, end, size); if (s < 0) { error = EAGAIN != errno && EINTR != errno; if (error) { printErrno("Failed to read", "child"); } } else if (0 == s) { eof = true; } else { end += s; size -= s; } ++attempts; } if (error || 0 != size) { return false; } } for (int p = 0; p < mProcessNb; ++p) { char dummy; error = false; attempts = 0; size = sizeof(dummy); while (size > 0 && !error && attempts < kMaxAttempts) { ssize_t s = write(writefd, &dummy, size); if (s < 0) { error = EAGAIN != errno && EINTR != errno; if (error) { printErrno("Failed to write", "child"); } } else { size -= s; } ++attempts; } if (error || 0 != size) { return false; } } return true; }
// IPC bool writePidAndWaitForReply(int writefd, int readfd) { if (writefd > readfd) { fprintf(stderr, "Called with args in wrong order!!\n"); return false; } pid_t pid = getpid(); char *start = reinterpret_cast<char *>(&pid); size_t size = sizeof(pid); bool error = false; int attempts = 0; while (size > 0 && !error && attempts < kMaxAttempts) { ssize_t s = write(writefd, start, size); if (s < 0) { error = EAGAIN != errno && EINTR != errno; if (error) { printErrno("Failed to write", "parent"); } } else { start += s; size -= s; } ++attempts; } if (error || 0 != size) { return false; } bool eof = false; char dummy; size = sizeof(dummy); error = false; attempts = 0; while (size > 0 && !error && !eof && attempts < kMaxAttempts) { ssize_t s; s = read(readfd, &dummy, size); if (s < 0) { error = EAGAIN != errno && EINTR != errno; if (error) { printErrno("Failed to read", "parent"); } } else if (0 == s) { eof = true; } else { size -= s; } ++attempts; } if (error || 0 != size) { return false; } return true; }