Exemple #1
0
Card16E1::Card16E1(std::string& name, CBaseSlot* slot) : CBaseCard(name, slot),
                                        cpld(slot), chipE1(slot), chipE1Map(slot, 0x8000, mode_MAP) {

//    if(GeneralLogic::instance().ifColdStart()){
    Chip_INIT_RESULT rst = chipE1.ChipInit();
        if( rst == failed ) {
            throw SysError("!!!Card 16E1 E1Logic init error!!!");
        }
        else if( rst == succeed ) {
            if( chipE1Map.ChipInit() == failed ) {
                throw SysError("!!!Card 16E1 RC7883 init error!!!");
            }
        }
        else {
            std::cout << chipE1.itsName() << " have been running!" << std::endl;
        }
//    }
    if( !fetchConfig() ) {
        throw SysError("!!!Card 16E1 config data error!!!");
    }
    ST_E1 info;
    info.slot = slot->GetSn();
    for (int i = 0; i < E1_Port_Num; ++i) {
        info.E1 = i;
        uint32 uid = UID::makeUID(&info);
        PairRscSDHChannel* mapLink = getConnectedSDHChannel(uid);
        e1port_obj[i] = new PortE1(uid, mapLink, this, chipE1Map, &ConfigData.port[i]);
    }

    cardversionInfo = cpld.GetVerInfo();

    AM = new E1Card16AlarmModule(this);
    AM->initModule();

}
Exemple #2
0
/*
 * Allocates memory for a 2-dimensional array of chars and returns a pointer
 * thereto.  Each line is formed from a set of char arrays, with an index
 * (i.e., the ScrnBuf type).  The first pointer in the index is reserved for
 * per-line flags, and does not point to data.
 *
 * After the per-line flags, we have a series of pointers to char arrays:  The
 * first one is the actual character array, the second one is the attributes,
 * the third is the foreground and background colors, and the fourth denotes
 * the character set.
 *
 * We store it all as pointers, because of alignment considerations, together
 * with the intention of being able to change the total number of pointers per
 * row according to whether the user wants color or not.
 */
ScrnBuf
Allocate(int nrow, int ncol, Char ** addr)
{
    ScrnBuf base;
    Char *tmp;
    int i, j, k;
    size_t entries = MAX_PTRS * nrow;
    size_t length = BUF_PTRS * nrow * ncol;

    if ((base = (ScrnBuf) calloc(entries, sizeof(char *))) == 0)
	  SysError(ERROR_SCALLOC);

    if ((tmp = (Char *) calloc(length, sizeof(Char))) == 0)
	SysError(ERROR_SCALLOC2);

    *addr = tmp;
    for (i = k = 0; i < nrow; i++) {
	base[k] = 0;		/* per-line flags */
	k += BUF_HEAD;
	for (j = BUF_HEAD; j < MAX_PTRS; j++) {
	    base[k++] = tmp;
	    tmp += ncol;
	}
    }

    return (base);
}
Exemple #3
0
static void wi_start(unsigned count)
{
	unsigned i;
	struct listen *curr;
	int e;

	for (curr = listen_head; curr; curr = curr->next) {
		wi_grow(count);
		for (i = 0; i < count; i++) {
			struct work_info *wi;

			wi = calloc(1, sizeof(*wi));
			wi->active = true;
			wi->li = curr;
			e = pthread_create(&wi->thr, NULL, worker_loop, wi);
			if (e) {
				SysError();
				free(wi);
				break;
			}
			e = pthread_detach(wi->thr);
			if (e) {
				SysError();
				/* TODO: handle this error */
			}
			wi = NULL;
			work[work_cur++] = wi;
		}
	}
	Info("thread count at %d\n", work_cur);
}
QString F520xmlserializer::query(F520Status *f520, QString day, QString month, SysError &sysErr) {
    QXmlQuery query;
    QString res;
    QFile xml(f520->getXmlPath());
    if ( ! xml.exists()) {
        xml.setFileName(f520->getXmlPath());
        if ( ! xml.exists()) {
            sysErr = SysError(SysError::F520_CAN_NOT_OPEN_FILE, "F520 Rasource file not exist");
            return "";
        }
    }

    if (!xml.open(QIODevice::ReadOnly | QIODevice::Text)) {
        sysErr = SysError(SysError::F520_RESOUCES_NOT_EXIST, "F520 can not open xml resource file");
        return "";
    }

    QString queryStr = CARICO + "/" + DAYS + "/" + DAY + "[@" + DAY_VALUE + "='" + day + "'][@" + MONTH_VALUE + "='" + month + "']";
    qDebug() << "F520xmlserializer::query: " << queryStr;

    query.setFocus(&xml);
    query.setQuery(queryStr);
    if ( ! query.isValid()) {
        qDebug() << "F520xmlserializer::query query not valid";
        sysErr = SysError(SysError::F520_QUERY_ERROR, "F520 Query is invalid: " + queryStr);
        return "";
    }

    query.evaluateTo(&res);

    if (!(res.length() > 1)) {
        queryStr = CARICO + "/" + DAYS + "/" + DAY + "[@" + NAME + "='" + DEFAULT_DAY + "']";
        qDebug() << "F520xmlserializer::query: " << queryStr;
        query.setQuery(queryStr);
        if (!query.isValid()) {
            qDebug() << "F520xmlserializer::query query not valid";
            sysErr = SysError(SysError::F520_QUERY_ERROR, "F520 Query is invalid: " + queryStr);
            return "";
        }
        query.evaluateTo(&res);
    }

    xml.close();

    qDebug() << "F520xmlserializer::query " << res;

    QDomDocument watt;
    watt.setContent("" + res + "");
    QDomNodeList entryNodes = watt.elementsByTagName(DAY);

    QString rtn;
    for (int i = 0; i < entryNodes.count(); i++) {
        QDomElement node = entryNodes.at(i).toElement();
        rtn = node.attribute(WATT);
        break;
    }
    qDebug() << "F520xmlserializer::query " << rtn;
    return rtn;
}
Exemple #5
0
static void registerSegment( orl_sec_handle o_shnd )
//**************************************************
{
    orl_sec_flags               sec_flags;
    orl_sec_handle              reloc_section;
    orl_sec_alignment           alignment;
    char *                      content;
    int                         ctr;
    segment                     *seg;

    seg = NewSegment();
    seg->name = ORLSecGetName( o_shnd );
    seg->size = ORLSecGetSize( o_shnd );
    seg->start = 0;
    seg->use_32 = 1;            // only 32-bit object files use ORL
    seg->attr = ( 2 << 2 );     // (?) combine public
    alignment = ORLSecGetAlignment( o_shnd );
    // FIXME: Need better alignment translation.
    switch( alignment ) {
    case 0:
        seg->attr |= ( 1 << 5 ); break;
    case 1:
        seg->attr |= ( 2 << 5 ); break;
    case 3:
    case 4:
        seg->attr |= ( 3 << 5 ); break;
    case 8:
        seg->attr |= ( 4 << 5 ); break;
    case 2:
        seg->attr |= ( 5 << 5 ); break;
    case 12:
        seg->attr |= ( 6 << 5 ); break;
    default:
        // fprintf( stderr, "NOTE! 'Strange' alignment (%d) found. Using byte alignment.\n", alignment );
        seg->attr |= ( 1 << 5 ); break;
    }
    sec_flags = ORLSecGetFlags( o_shnd );
    if( !( sec_flags & ORL_SEC_FLAG_EXEC ) ) {
        seg->data_seg = true;
    }
    if( seg->size > 0 && ORLSecGetContents( o_shnd, &content ) == ORL_OKAY ) {
        Segment = seg;
        // Putting contents into segment struct.
        for( ctr = 0; ctr < seg->size; ctr++ ) {
            PutSegByte( ctr, content[ctr] );
        }
    }
    if( !HashTableInsert( SectionToSegmentTable, (hash_value)o_shnd, (hash_data)seg ) ) {
        SysError( ERR_OUT_OF_MEM, false );
    }
    reloc_section = ORLSecGetRelocTable( o_shnd );
    if( reloc_section ) {
        if( !addRelocSection( reloc_section ) ) {
            SysError( ERR_OUT_OF_MEM, false );
        }
    }
}
Exemple #6
0
static int GlobalErrorHandler(int eType, const char* buffer)
{
	static thread_local bool inError = false;

	trace("GlobalError: %s\n", buffer);

	if (inError)
	{
		static thread_local bool inRecursiveError = false;

		if (inRecursiveError)
		{
			return SysError("RECURSIVE RECURSIVE ERROR");
		}

		inRecursiveError = true;
		return SysError(va("Recursive error: %s", buffer));
	}

	inError = true;

	if (eType == ERR_NORMAL)
	{
#if !defined(COMPILING_LAUNCH) && !defined(COMPILING_CONSOLE) && !defined(IS_FXSERVER)
		ICoreGameInit* gameInit = Instance<ICoreGameInit>::Get();
		bool handled = false;

		if (gameInit && gameInit->TriggerError(buffer))
		{
			handled = true;
		}
		
		if (gameInit && gameInit->GetGameLoaded())
		{
			gameInit->KillNetwork(ToWide(buffer).c_str());

			handled = true;
		}
		
		if (!handled)
#endif
		{
			return SysError(buffer);
		}
	}
	else
	{
		return SysError(buffer);
	}

	inError = false;

	return 0;
}
Exemple #7
0
bool InitORL( void )
//******************
// Try and see if we will use ORL. Returns true if we'll use it.
{
    orl_file_flags      o_flags;
    orl_file_format     o_format;
    orl_machine_type    o_machine_type;

    ORLFileHnd = NULL;
    oFuncs.alloc = AllocMem;
    oFuncs.free = FreeMem;
    oFuncs.read = (void * (*) ( void *, int ))buffRead;
    oFuncs.seek = (long int (*) ( void *, long int, int ))buffSeek;
    ORLHnd = ORLInit( &oFuncs );
    if( !ORLHnd ) {
        SysError( ERR_OUT_OF_MEM, false );
    }

    initBuffer( &fileBuff, ObjFile );
    o_format = ORLFileIdentify( ORLHnd, &fileBuff );
    if( o_format != ORL_ELF && o_format != ORL_COFF ) {
        ORLFini( ORLHnd );
        finiBuffer( &fileBuff );
        ORLHnd = NULL;
        return( false );        // Will use ParseObjectOMF
    }

    ORLFileHnd = ORLFileInit( ORLHnd, &fileBuff, o_format );
    if( !ORLFileHnd ) {
        ORLFini( ORLHnd );
        finiBuffer( &fileBuff );
        SysError( ERR_OUT_OF_MEM, false );
    }
    o_machine_type = ORLFileGetMachineType( ORLFileHnd );
    if( o_machine_type != ORL_MACHINE_TYPE_I386 ) {
        FiniORL();
        Error( ERR_ORL_INV_MACHINE_TYPE, true );
        exit( 1 );
    }
    o_flags = ORLFileGetFlags( ORLFileHnd );
    if( !(o_flags & ORL_FILE_FLAG_LITTLE_ENDIAN) ) {
        FiniORL();
        Error( ERR_ORL_INV_BYTE_ORDER, true );
        exit( 1 );
    }
    UseORL = true;
    createHashTables();
    return( true );     // Success: will use ORL
}
Exemple #8
0
    void setInherit(void *handle, bool inherit) {
      if (handle == INVALID_HANDLE_VALUE) THROW("Invalid handle");

      DWORD flags = inherit ? HANDLE_FLAG_INHERIT : 0;
      if (!SetHandleInformation(handle, HANDLE_FLAG_INHERIT, flags))
        THROWS("Failed to clear pipe inherit flag: " << SysError());
    }
void SetSoftRlimitErr(int resource, rlim_t limit, char* desc)
{
   char* ldesc ="";
   char message[200];
   RLimResult res;

   if(desc)
   {
      assert(strlen(desc)<=100);
      ldesc = desc;
   }
   res = SetSoftRlimit(resource, limit);

   switch(res)
   {
   case RLimFailed:
         sprintf(message, "Could not set limit %s", ldesc);
         TmpErrno = errno;
         SysError(message, SYS_ERROR);
         break;
   case RLimReduced:
         sprintf(message, "Had to reduce limit %s", ldesc);
         Warning(message);
         break;
   case RLimSuccess:
         /* Nothing to do */
         break;
   default:
         assert(false && "Out of bounds return from SetSoftRlimit()");
         break;
   }   
}
void GEN_xmlserializer::serialize(QString deviceID, QString currBUS, QString sourceFile, QDomDocument &xml, SysError &sysErr)
{
    qDebug() << "SERIALIZE";
    QDomElement device = xml.createElement(DEVICE);
    device.setAttribute(ID, deviceID);
    device.setAttribute(TYPE, BtGEN_dev::className());
    xml.appendChild(device);

    QDomElement xmlAttributeDIR = xml.createElement(DEVATTRIBUTE);
    xmlAttributeDIR.setAttribute(NAME, SRCFILE);
    xmlAttributeDIR.setAttribute(VALUE, sourceFile);
    xmlAttributeDIR.setAttribute(TYPE, FL);
    xmlAttributeDIR.setAttribute(EXTFILE, XML_FILE);
    device.appendChild(xmlAttributeDIR);

    QDomElement xmlAttributeBus = xml.createElement(DEVATTRIBUTE);
    xmlAttributeBus.setAttribute(NAME, BUS);
    xmlAttributeBus.setAttribute(VALUE, currBUS);
    xmlAttributeBus.setAttribute(TYPE, COMBO);
    xmlAttributeBus.setAttribute(VALUES, PlantMgr::getInstance().getBuses());
    device.appendChild(xmlAttributeBus);

    qDebug() << "SERIALIZE";


    sysErr = SysError();
}
Exemple #11
0
void CBrowseDlg::OnEndlabeleditDirs(NMHDR* pNMHDR, LRESULT* pResult) {
	TV_DISPINFO* pTVDispInfo = (TV_DISPINFO*)pNMHDR;

	if (pTVDispInfo->item.pszText != NULL &&
		lstrlen(pTVDispInfo->item.pszText) > 0) {

		m_ctlDirs.SetItemText(pTVDispInfo->item.hItem, pTVDispInfo->item.pszText);
		CString strPath = GetFullPath(pTVDispInfo->item.hItem);

		if (CreateDirectory(strPath, NULL)) {
			m_ctlDirs.SelectItem(pTVDispInfo->item.hItem);
			*pResult = TRUE;
		}
		else {
			SysError(IDS_DIRECTORY_NOT_CREATED, GetLastError(), FALSE);
			m_ctlDirs.DeleteItem(pTVDispInfo->item.hItem);
			*pResult = FALSE;
		}

	}
	else {
		m_ctlDirs.DeleteItem(pTVDispInfo->item.hItem);
		*pResult = FALSE;
	}

	m_ctlDirs.ModifyStyle(TVS_EDITLABELS, 0);
}
Exemple #12
0
static struct module *mo_load(const char *name, const char *dll_path, const char *args)
{
	struct module *mo;

	mo = mo_find(name);
	if (mo) {
		Error("module '%s' is already loaded\n", name);
		return NULL;
	}

	mo = calloc(1, sizeof(*mo));
	if (!mo) {
		SysError();
		return NULL;
	}

	if (dll_open(&mo->mh, dll_path, args))
		goto error;
	mo->name = strdup(name);
	mo->next = module_head;
	module_head = mo;

	Info("MODULE:%s\n", name);
	return mo;
error:
	free(mo);
	return NULL;
}
Exemple #13
0
static bool pcl_run_prover(char* command, char*success)
{
   bool   res=false;
   char   line[180],*l;
   FILE*  ppipe;

   if(OutputLevel>1)
   {
      fprintf(GlobalOut, "# Running %s\n", command);
   }
   ppipe=popen(command, "r");
   if(!ppipe)
   {
      TmpErrno = errno;
      SysError("Cannot open pipe", SYS_ERROR);
   }
   while((l=fgets(line, 180, ppipe)))
   {
      if(strstr(line,success))
      {
	 res = true;
      }
      if(OutputLevel >= 3)
      {
	 fprintf(GlobalOut, "#> %s", line);
      }
   }
   pclose(ppipe);

   return res;
}
Exemple #14
0
static void createHashTables( void )
//**********************************
{
    SymbolToTargetTable = HashTableCreate( SYMBOL_TO_TARGET_TABLE_SIZE, HASH_NUMBER, numberCmp );
    if( !SymbolToTargetTable ) {
        SysError( ERR_OUT_OF_MEM, false );
    }
    SymbolToExportTable = HashTableCreate( SYMBOL_TO_EXPORT_TABLE_SIZE, HASH_NUMBER, numberCmp );
    if( !SymbolToExportTable ) {
        SysError( ERR_OUT_OF_MEM, false );
    }
    SectionToSegmentTable = HashTableCreate( SECTION_TO_SEGMENT_TABLE_SIZE, HASH_NUMBER, numberCmp );
    if( !SectionToSegmentTable ) {
        SysError( ERR_OUT_OF_MEM, false );
    }
}
// Multicast data in a memory buffer, given the specific start sequence number
void FMTPSender::DoMemoryTransfer(void* data, size_t dataLen, u_int32_t start_seq_num) {
	char 	     buffer[FMTP_HLEN ];
	FmtpHeader* header = (FmtpHeader*) buffer;

	// TODO: replace this with packing of `buffer` IN NETWORK FORM
	header->session_id = cur_session_id;
	header->seq_number = start_seq_num;
	header->flags = FMTP_DATA;

	size_t remained_size = dataLen;
	size_t offset = 0;
	while (remained_size > 0) {
		uint data_size = remained_size < FMTP_DATA_LEN ? remained_size
				: FMTP_DATA_LEN;
		// TODO: replace this with packing of `buffer` IN NETWORK FORM
		header->seq_number = offset + start_seq_num;
		header->data_len = data_size;

		//Get tokens from the rate controller
		rate_shaper.RetrieveTokens(22 + FMTP_HLEN + data_size);
		if (ptr_multicast_comm->SendData(buffer, FMTP_HLEN, data,
		        dataLen) < 0) {
			SysError("FMTPSender::DoMemoryTransfer()::SendPacket() error");
		}

		remained_size -= data_size;
		offset += data_size;

		// Update statistics
		send_stats.total_sent_packets++;
		send_stats.total_sent_bytes += data_size;
		send_stats.session_sent_packets++;
		send_stats.session_sent_bytes += data_size;
	}
}
Exemple #16
0
void utilCreateDir(folly::StringPiece path) {
  try {
    boost::filesystem::create_directories(path.str());
  } catch (...) {
    throw SysError(errno, "failed to create directory \"", path, "\"");
  }
}
Exemple #17
0
uint8_t I2cDevice::readByte(int offset) {
  auto data = i2c_smbus_read_byte_data(file_, offset);
  if (data < 0) {
    throw SysError(-data, "Error reading word data: ", i2cBus_);
  }
  return data;
}
Exemple #18
0
static void GlobalErrorHandler(int eType, const char* buffer)
{
	static bool inError = false;

	trace("GlobalError: %s\n", buffer);

	if (inError)
	{
		static bool inRecursiveError = false;

		if (inRecursiveError)
		{
			SysError("RECURSIVE RECURSIVE ERROR");
		}

		inRecursiveError = true;
		SysError(va("Recursive error: %s", buffer));
	}

	inError = true;

	if (eType == ERR_NORMAL)
	{
	#if !defined(COMPILING_LAUNCH) && !defined(COMPILING_CONSOLE)
			// TODO: UI killer for pre-connected state
			ICoreGameInit* gameInit = Instance<ICoreGameInit>::Get();

			if (gameInit && gameInit->GetGameLoaded())
			{
				static wchar_t wbuffer[BUFFER_LENGTH];
				mbstowcs(wbuffer, buffer, _countof(wbuffer));

				gameInit->KillNetwork(wbuffer);
			}
			else
	#endif
		{
			SysError(buffer);
		}
	}
	else
	{
		SysError(buffer);
	}

	inError = false;
}
Exemple #19
0
int I2cDevice::readBlock(int offset, uint8_t fieldValue[]) {
  auto rc = i2c_smbus_read_i2c_block_data(file_, offset, I2C_BLOCK_SIZE,
                                          fieldValue);
  if (rc < 0) {
    throw SysError(-rc, "Error reading i2c bus block data i2c bus: ", i2cBus_);
  }
  return rc;
}
Exemple #20
0
MulticastComm::MulticastComm() {
	if ( (sock_fd = socket(PF_INET, SOCK_DGRAM, 0)) < 0) {
		SysError("Cannot create new socket.");
	}

	//int x=fcntl(sock_fd,F_GETFL,0);
	//if (fcntl(sock_fd,F_SETFL,x | O_NONBLOCK) < 0)
	//	SysError("MulticastComm()::Cannot set socket to non-blocking mode.");
}
CParseObj* CParseObjList::Get(int i)
{
  if (i > Length() || i <= 0) 
  {
    SysError("CParseObjList_Get");
    return (*parseObjList)[1];
  }
  return (*parseObjList)[i];
}
Exemple #22
0
bool MountTable::ReadFromFile(const char* path)
////////////////////////////////////////////////////////////////////////
// ReadFromFile reads the mount points from the configuration file
//   and fills in the mount table
/////////////////////////////////////////////////////////////////////////
{
    // Open the file
    //   TODO: If there are errors, we will abort, although we really should close the file
    FILE *f = fopen(path, "r");
    if (f == NULL) return SysError("Can't open source table %s\n", path);

    // Read it a line at a time.
    // Each line is of the form:   mountpoint; password; STR data
    while (!feof(f)) {
        byte line[MaxSTR+MaxName+MaxPassword+25]; // TODO: get it out of stack
        if (ReadLine(f, line, sizeof(line)) != OK)
            return SysError("Trouble reading from source table file %s\n", path);

       // Get the mount point name. 
       Parse token(line, strlen((char*)line));
       char name[MaxName+1];
       token.Next(";");
       if (token == "") return Error("Empty mount point not valid\n");
       token.GetToken(name, sizeof(name));

       // Get the password
       char password[MaxPassword+1];
       token.Next(";");
       token.GetToken(password, sizeof(password));

       // Get the Stream Record entry (STR) - all entries up to end of line.
       char str[MaxSTR+1];
       token.Next("\r\n");
       token.GetToken(str, sizeof(str));

       // Create a new entry with the password and STR data
       MountPoint* mnt = CreateMount(name);
       if (mnt == NULL || mnt->SetPassword(password) != OK | mnt->SetSTR(str) != OK)
           return Error("Problem creating new mountpoint %s\n", name);
    }

    fclose(f);
    return OK;
}
Exemple #23
0
static  void  openFiles( void )
/*****************************/

{
/*  C.L. May 22, 91 */
    char        sp_buf[ _MAX_PATH2 ];
    char        *ext;
    size_t      len;

    _splitpath2( objName, sp_buf, NULL, NULL, &rootName, &ext );
    len = strlen( rootName ) + 1;
    rootName = memcpy( AllocMem( len ), rootName, len );
    if( ext[ 0 ] == '\0' ) {
        /* search with '.obj' or '.o' extension first */
        ObjFile = OpenBinRead( MakeFileName( objName, objExt ) );
        if( ObjFile == NULL ) {
            /* try without extension */
            ObjFile = OpenBinRead( objName );
        }
    } else {
        /* extension specified */
        ObjFile = OpenBinRead( objName );
    }
/**/
    if( ObjFile == NULL ) {
//        ObjFile = OpenBinRead( MakeFileName( objName, objExt ) );
//        if( ObjFile == NULL ) {
            SysError( ERR_NOT_OPEN_OBJ, true );
//        }
    }
    if( lstReqd ) {
        if( lstName == NULL ) {
            Output = OpenTxtWrite( MakeFileName( rootName, "lst" ) );
        } else {
            Output = OpenTxtWrite( lstName );
        }
        if( Output == NULL ) {
            CloseBin( ObjFile );
            SysError( ERR_NOT_OPEN_LIST, true );
        }
    }
}
Exemple #24
0
void BcmWarmBootHelper::setCanWarmBoot() {
  auto wbFlag = warmBootFlag();
  auto updateFd = creat(wbFlag.c_str(),
                        S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
  if (updateFd < 0) {
    throw SysError(errno, "Unable to create ", wbFlag);
  }
  close(updateFd);

  VLOG(1) << "Wrote can warm boot flag: " << wbFlag;
}
Exemple #25
0
I2cDevice::I2cDevice(int i2cBus, uint32_t address, bool slaveForce) {
  /* set the i2c bus name */
  i2cBus_ = i2cBus;
  /* Open the i2c Bus file */
  char filename[15];
  snprintf(filename, sizeof(filename), "/dev/i2c/%d", i2cBus_);
  file_ = open(filename, O_RDWR);
  if (file_ < 0 && errno == ENOENT) {
    snprintf(filename, sizeof(filename), "/dev/i2c-%d", i2cBus_);
    file_ = open(filename, O_RDWR);
  }
  if (file_ < 0) {
    throw SysError(errno, "Error opening i2c device: ", i2cBus_);
  }
  /* Set the slave address */
  if (ioctl(file_, slaveForce ? I2C_SLAVE_FORCE : I2C_SLAVE, address) < 0) {
    close(file_);
    throw SysError(errno, "Error setting slave address: ", address);
  }
}
Exemple #26
0
static int se_add(struct domain *dom, const char *prefix, const char *module)
{
	struct service *se;
	struct module *mo;

	assert(dom != NULL);
	mo = mo_find(module);
	if (!mo) {
		Error("module '%s' unknown for service %s:%s\n",
			module, dom->name, prefix);
		return -1;
	}

	se = se_find_exact(dom, prefix);
	if (se) {
		Error("service path '%s' for domain '%s' matches existing entry\n",
			prefix, dom->name);
		return -1;
	}

	se = calloc(1, sizeof(*se));
	if (!se) {
		SysError();
		return -1;
	}

	se->prefix = strdup(prefix);
	if (!se->prefix) {
		SysError();
		free(se);
		return -1;
	}
	se->module = mo_find(module); /* TODO: check for failures */
	se->next = dom->service_head;
	dom->service_head = se;

	Info("SERVICE:dom=\"%s\" path=\"%s\" module=\"%s\"\n",
		dom->name, prefix, module);

	return 0;
}
Exemple #27
0
void TempFileRemove(char* name)
{
   bool res;

   if(unlink(name)!=0)
   {
      TmpErrno = errno;
      SysError("Could not remove temporary file", SYS_ERROR);
   }
   res = StrTreeDeleteEntry(&temp_file_store, name);
   assert(res);
}
Exemple #28
0
FILE* SecureFOpen(char* name, char* mode)
{
   FILE* res;

   res = fopen(name, mode);
   if(!res)
   {
      TmpErrno = errno;
      SysError("Cannot open file %s",FILE_ERROR,name);
   }
   return res;
}
Exemple #29
0
/* create a hosting domain, if it does not already exist */
static struct domain *dom_create(const char *name)
{
	struct domain *dom;

	assert(name != NULL);
	dom = dom_find(name);
	if (dom)
		return dom;
	dom = calloc(1, sizeof(*dom));
	if (!dom) {
		SysError();
		return NULL;
	}
	dom->name = strdup(name);
	if (!dom->name) {
		SysError();
		free(dom);
		return NULL;
	}
	dom->service_head = NULL;
	return dom;
}
Exemple #30
0
static int ha_add(struct domain *dom, const char *alias)
{
	struct host_alias *ha;

	ha = calloc(1, sizeof(*ha));
	if (!ha) {
		SysError();
		return -1;
	}

	ha->host = strdup(alias);
	if (!ha->host) {
		SysError();
		free(ha);
		return -1;
	}
	ha->next = host_alias_head;
	ha->domain = dom;
	host_alias_head = ha;

	return 0;
}