Пример #1
0
static index_word_extractor_t* new_bigram_generator(int id)
{
	index_word_extractor_t *extractor = NULL;
	bigram_t *handle = NULL;

	if (id != MY_EXTRACTOR_ID)
		return (index_word_extractor_t*)MINUS_DECLINE;

	extractor = sb_calloc(1, sizeof(index_word_extractor_t));
	if (extractor == NULL) {
		crit("cannot allocate index word extractor object");
		return NULL;
	}
	
	handle = new_bigram(); 
	if (handle == NULL) {
		crit("cannot allocate bigram handle");
		sb_free(extractor);
		return NULL;
	}
	extractor->handle = handle;
	extractor->id = id;

	if (extractor == (index_word_extractor_t*)MINUS_DECLINE) {
		crit("extractor pointer is %d (same as the decline value for this api",
								MINUS_DECLINE);
	}

	return extractor;
}
Пример #2
0
static index_word_extractor_t* new_kor2chn_translator(int id)
{
	index_word_extractor_t *extractor = NULL;
	kor2chn_translator_handle_t *handle=NULL;

	if (id != 2)
		return (index_word_extractor_t*)MINUS_DECLINE;

	extractor = sb_calloc(1, sizeof(index_word_extractor_t));
	if (extractor == NULL) {
		crit("cannot allocate index word extractor object");
		return NULL;
	}

	handle = sb_calloc(1, sizeof(kor2chn_translator_handle_t));
	if (handle == NULL) {
		crit("failed to malloc kor2chn_translator_handle");
		sb_free(extractor);
		return NULL;
	}

	handle->tokenizer = sb_run_new_tokenizer();
	handle->token_array = NULL;

	extractor->handle = handle;
	extractor->id = id;

	if (extractor == (index_word_extractor_t*)MINUS_DECLINE) {
		crit("extractor pointer is -99 (same as the MINUS_DECLINE)");
	}

	return extractor;
}
Пример #3
0
int lookup_init(const char *mapfmt, int argc, const char *const *argv, void **context)
{
	struct lookup_context *ctxt;

	if (!(*context = ctxt = malloc(sizeof(struct lookup_context)))) {
		crit(MODPREFIX "malloc: %m");
		return 1;
	}

	if (argc < 1) {
		crit(MODPREFIX "No map name");
		return 1;
	}
	ctxt->mapname = argv[0];

	if (ctxt->mapname[0] != '/') {
		crit(MODPREFIX "program map %s is not an absolute pathname",
		       ctxt->mapname);
		return 1;
	}

	if (access(ctxt->mapname, X_OK)) {
		crit(MODPREFIX "program map %s missing or not executable",
		       ctxt->mapname);
		return 1;
	}

	if (!mapfmt)
		mapfmt = MAPFMT_DEFAULT;

	return !(ctxt->parse = open_parse(mapfmt, MODPREFIX, argc - 1, argv + 1));
}
Пример #4
0
int lookup_init(const char *mapfmt, int argc, const char *const *argv, void **context)
{
    struct lookup_context *ctxt;

    if (!(*context = ctxt = malloc(sizeof(struct lookup_context)))) {
        crit(MODPREFIX "%m");
        return 1;
    }

    if (argc < 1) {
        crit(MODPREFIX "No map name");
        return 1;
    }
    ctxt->mapname = argv[0];

    /*
     * nis_local_directory () returns a pointer to a static buffer.
     * We don't need to copy or free it.
     */
    ctxt->domainname = nis_local_directory();

    if (!mapfmt)
        mapfmt = MAPFMT_DEFAULT;

    return !(ctxt->parse = open_parse(mapfmt, MODPREFIX, argc - 1, argv + 1));
}
Пример #5
0
Файл: mail.c Проект: nhanh0/hah
void setupXAPini()
{
	xapInitFromINI("mail","dbzoo","Mail","00E1",interfaceName, inifile);
        ini_gets("mail","server","",smtp_server,sizeof(smtp_server),inifile);
        ini_gets("mail","from","",smtp_username,sizeof(smtp_username),inifile);
        ini_gets("mail","fullname","",fullname,sizeof(fullname),inifile);
	smtp_password = getINIPassword("mail","password", (char *)inifile);

	int err = 0;
	if (strlen(smtp_server) == 0) {
	  crit("%s : [mail] server=  <- not defined", inifile);
	  err = 1;
	}
	if (strlen(smtp_username) == 0) {
	  crit("%s : [mail] from=  <- not defined", inifile);
	  err = 1;
	}
	if (strlen(fullname) == 0) {
	  crit("%s : [mail] fullname=  <- not defined", inifile);
	  err = 1;
	}
	if (smtp_password == NULL || strlen(smtp_password) == 0) {
	  crit("%s : [mail] password=  <- not defined", inifile);
	  err = 1;
	}
	if(err)
	  exit(1);
}
Пример #6
0
/**
 * @returns #hipSuccess #hipErrorMemoryAllocation
 */
hipError_t hipMalloc(void** ptr, size_t sizeBytes)
{
    HIP_INIT_API(ptr, sizeBytes);

    hipError_t  hip_status = hipSuccess;

	auto device = ihipGetTlsDefaultDevice();

    if (device) {
        const unsigned am_flags = 0;
        *ptr = hc::am_alloc(sizeBytes, device->_acc, am_flags);

        if (sizeBytes && (*ptr == NULL)) {
            hip_status = hipErrorMemoryAllocation;
        } else {
            hc::am_memtracker_update(*ptr, device->_device_index, 0);
            {
                LockedAccessor_DeviceCrit_t crit(device->criticalData());
                if (crit->peerCnt()) {
                    hsa_amd_agents_allow_access(crit->peerCnt(), crit->peerAgents(), NULL, *ptr);
                }
            }
        }
    } else {
        hip_status = hipErrorMemoryAllocation;
    }

    return ihipLogStatus(hip_status);
}
const ff::SharedResourceValue &ff::AutoResourceValue::UpdateValue()
{
	if (!_value)
	{
		static ff::SharedResourceValue s_null;
		if (!s_null)
		{
			LockMutex crit(GCS_RESOURCE_VALUE);
			if (!s_null)
			{
				ff::ValuePtr nullValue;
				ff::Value::CreateNull(&nullValue);
				s_null = std::make_shared<ff::ResourceValue>(nullValue, ff::GetEmptyString());

				ff::SharedResourceValue *p_null = &s_null;
				ff::AtProgramShutdown([p_null]()
				{
					p_null->reset();
				});
			}
		}

		return s_null;
	}

	if (!_value->IsValid())
	{
		_value = _value->GetNewValue();
	}

	return _value;
}
Пример #8
0
hipError_t hipHostMalloc(void** ptr, size_t sizeBytes, unsigned int flags)
{
    HIP_INIT_API(ptr, sizeBytes, flags);

    hipError_t hip_status = hipSuccess;

    auto device = ihipGetTlsDefaultDevice();

    if(device){
        if(flags == hipHostMallocDefault){
            *ptr = hc::am_alloc(sizeBytes, device->_acc, amHostPinned);
            if(sizeBytes < 1 && (*ptr == NULL)){
                hip_status = hipErrorMemoryAllocation;
            }else{
                hc::am_memtracker_update(*ptr, device->_device_index, amHostPinned);
            }
            tprintf(DB_MEM, " %s: pinned ptr=%p\n", __func__, *ptr);
        } else if(flags & hipHostMallocMapped){
            *ptr = hc::am_alloc(sizeBytes, device->_acc, amHostPinned);
            if(sizeBytes && (*ptr == NULL)){
                hip_status = hipErrorMemoryAllocation;
            }else{
                hc::am_memtracker_update(*ptr, device->_device_index, flags);
                {
                    LockedAccessor_DeviceCrit_t crit(device->criticalData());
                    if (crit->peerCnt()) {
                        hsa_amd_agents_allow_access(crit->peerCnt(), crit->peerAgents(), NULL, *ptr);
                    }
                }
            }
            tprintf(DB_MEM, " %s: pinned ptr=%p\n", __func__, *ptr);
        }
    }
    return ihipLogStatus(hip_status);
}
int gcomm::AsioUdpSocket::send(const Datagram& dg)
{
    Critical<AsioProtonet> crit(net_);
    boost::array<asio::const_buffer, 3> cbs;
    NetHeader hdr(dg.len(), net_.version_);

    if (net_.checksum_ != NetHeader::CS_NONE)
    {
        hdr.set_crc32(crc32(net_.checksum_, dg), net_.checksum_);
    }

    gu::byte_t buf[NetHeader::serial_size_];
    serialize(hdr, buf, sizeof(buf), 0);
    cbs[0] = asio::const_buffer(buf, sizeof(buf));
    cbs[1] = asio::const_buffer(dg.header() + dg.header_offset(),
                          dg.header_len());
    cbs[2] = asio::const_buffer(&dg.payload()[0], dg.payload().size());
    try
    {
        socket_.send_to(cbs, target_ep_);
    }
    catch (asio::system_error& err)
    {
        log_warn << "Error: " << err.what();
        return err.code().value();
    }
    return 0;
}
void ff::ComBaseEx::_TrackLeak()
{
#ifdef COUNT_COM_OBJECTS
	LockMutex crit(GCS_COM_BASE);
	GetGlobalComObjectList().SetKey(this, InterlockedIncrement(&s_nComObjects));
#endif
}
Пример #11
0
static void alloc_shm_for_scoreboard(int size)
{
	g_scoreboard_shm.type = IPC_TYPE_SHM;
	g_scoreboard_shm.pathname = NULL;
	/* guarantee no shm collision with client.
	 * NULL pathname means key IPC_PRIVATE.
	 * see ipc.c->alloc_shm() */
	g_scoreboard_shm.pid = SYS5_SCOREBOARD;
	g_scoreboard_shm.size = size;

	if ( size == 0 ) {
		warn("invalid scoreboard size: %d", size);
		g_scoreboard_shm.addr = NULL;
	}
	else if ( alloc_shm(&g_scoreboard_shm) != SUCCESS ) {
		// it's critical if error occured while getting shared memory.
		// so we exit.
		crit("error while allocating shm for scoreboard");
		exit(1);
	}

#ifdef DEBUG_SCOREBOARD_MEMORY
	debug("key file for shared memory:%s",gSoftBotRoot);
	debug("shared memory key:%d",g_scoreboard_shm.key);
	debug("shared memory shmid:%d",g_scoreboard_shm.id);
	debug("shared memory size:%ld",g_scoreboard_shm.size);
#endif

	/* memset(NULL) for newly created shm will be done by alloc_shm().
	 * you should not memset(NULL) if the shm is attached by another process. */
	//memset(g_scoreboard_shm.addr, 0x00, size);
}
Пример #12
0
void ff::SetTempSubDirectory(StringRef name)
{
	SettingTempPath();

	LockMutex crit(GCS_FILE_UTIL);

	s_tempSubName = CanonicalizePath(name);
}
Пример #13
0
void create_daemon_thread()
{
	int flags;

	if (pipe(daemon_pipe) == -1)
		crit("could not create pipe");

	if ((flags = fcntl(daemon_pipe[0], F_GETFL, 0)) == -1)
		flags = 0;
	fcntl(daemon_pipe[0], F_SETFL, flags | O_NONBLOCK);

	pthread_mutex_init(&mutex, NULL);

	int rc = pthread_create(&daemon_thread, NULL, daemon_main, 0);
	if (rc)
		crit("could not start thread");
}
Пример #14
0
int sb_tstat_log_init(const char* file_name) {
    if ((fp_log = fopen(file_name, "a")) == NULL) {
        crit("cannot open time log file %s: %s", file_name, strerror(errno));
        return FAIL;
    }
    setlinebuf(fp_log);

    return SUCCESS;
}
Пример #15
0
// XXX: should be extern...
bigram_t* new_bigram()
{
	bigram_t *handle=NULL;
	handle = sb_calloc(1,sizeof(bigram_t));
	if (handle == NULL) {
		crit("cannot allocate bigram handle");
		return NULL;
	}

	handle->tokenizer = sb_run_new_tokenizer();
	if (handle->tokenizer == NULL) {
		crit("cannot allocate tokenizer");
		sb_free(handle);
		return NULL;
	}

	return handle;
}
Пример #16
0
int lookup_init(const char *mapfmt, int argc, const char *const *argv, void **context)
{
	struct lookup_context *ctxt;
	struct stat st;

	if (!(*context = ctxt = malloc(sizeof(struct lookup_context)))) {
		crit(MODPREFIX "malloc: %m");
		return 1;
	}

	if (argc < 1) {
		crit(MODPREFIX "No map name");
		return 1;
	}

	ctxt->mapname = argv[0];

	if (ctxt->mapname[0] != '/') {
		crit(MODPREFIX "file map %s is not an absolute pathname",
		       ctxt->mapname);
		return 1;
	}

	if (access(ctxt->mapname, R_OK)) {
		crit(MODPREFIX "file map %s missing or not readable",
		       ctxt->mapname);
		return 1;
	}

	if (stat(ctxt->mapname, &st)) {
		crit(MODPREFIX "file map %s, could not stat",
		       ctxt->mapname);
		return 1;
	}
		
	ctxt->mtime = st.st_mtime;

	if (!mapfmt)
		mapfmt = MAPFMT_DEFAULT;

	cache_init();

	return !(ctxt->parse = open_parse(mapfmt, MODPREFIX, argc - 1, argv + 1));
}
Пример #17
0
extern jlib_decl IIdAtom * createIdAtom(const char *value, size32_t len)
{
    if (!value || !len)
        return NULL;
    char * nullTerminated = (char *)alloca(len+1);
    memcpy(nullTerminated, value, len);
    nullTerminated[len] = 0;
    CriticalBlock crit(caseAtomCrit);
    return queryGlobalCaseAtomTable()->addAtom(nullTerminated);
}
Пример #18
0
static int init()
{
	if ( sizeof(test_attr_t) != 64 ) {
		crit("sizeof(test_attr_t) (%d) != 64", (int) sizeof(test_attr_t) );
		return FAIL;
	}

	if ( sizeof(test_cond_t) >= STRING_SIZE ) {
		crit("sizeof(test_cond_t) (%d) >= STRING_SIZE(%d)", (int) sizeof(test_cond_t), STRING_SIZE);
		return FAIL;
	}

	if ( sizeof(test_mask_t) >= STRING_SIZE ) {
		crit("sizeof(test_mask_t) (%d) >= STRING_SIZE(%d)", (int) sizeof(test_mask_t), STRING_SIZE);
		return FAIL;
	}

	return SUCCESS;
}
Пример #19
0
void galera::ist::AsyncSenderMap::remove(AsyncSender* as, wsrep_seqno_t seqno)
{
    gu::Critical crit(monitor_);
    std::set<AsyncSender*>::iterator i(senders_.find(as));
    if (i == senders_.end())
    {
        throw gu::NotFound();
    }
    senders_.erase(i);
    gcs_.join(seqno);
}
void gcomm::AsioUdpSocket::async_receive()
{
    Critical<AsioProtonet> crit(net_);
    boost::array<asio::mutable_buffer, 1> mbs;
    mbs[0] = asio::mutable_buffer(&recv_buf_[0], recv_buf_.size());
    socket_.async_receive_from(mbs, source_ep_,
                               boost::bind(&AsioUdpSocket::read_handler,
                                           shared_from_this(),
                                           asio::placeholders::error,
                                           asio::placeholders::bytes_transferred));
}
void gcomm::AsioUdpSocket::read_handler(const asio::error_code& ec,
                                        size_t bytes_transferred)
{
    if (ec)
    {
        //
        return;
    }

    if (bytes_transferred >= NetHeader::serial_size_)
    {
        Critical<AsioProtonet> crit(net_);
        NetHeader hdr;
        try
        {
            unserialize(&recv_buf_[0], NetHeader::serial_size_, 0, hdr);
        }
        catch (gu::Exception& e)
        {
            log_warn << "hdr unserialize failed: " << e.get_errno();
            return;
        }
        if (NetHeader::serial_size_ + hdr.len() != bytes_transferred)
        {
            log_warn << "len " << hdr.len()
                     << " does not match to bytes transferred"
                     << bytes_transferred;
        }
        else
        {
            Datagram dg(
                gu::SharedBuffer(
                    new gu::Buffer(&recv_buf_[0] + NetHeader::serial_size_,
                                   &recv_buf_[0] + NetHeader::serial_size_
                                   + hdr.len())));
            if (net_.checksum_ == true && check_cs(hdr, dg))
            {
                log_warn << "checksum failed, hdr: len=" << hdr.len()
                         << " has_crc32="  << hdr.has_crc32()
                         << " has_crc32c=" << hdr.has_crc32c()
                         << " crc32=" << hdr.crc32();
            }
            else
            {
                net_.dispatch(id(), dg, ProtoUpMeta());
            }
        }
    }
    else
    {
        log_warn << "short read of " << bytes_transferred;
    }
    async_receive();
}
Пример #22
0
int main(int argc, char *argv[])
{
	struct sigaction sa;

	xmlrpc_env env;

	if (signal(SIGPIPE, SIG_IGN) == SIG_ERR)
		crit("could not ignore SIGPIPE");

	sa.sa_handler = sighandler;
	sa.sa_flags = 0;
	sigemptyset (&sa.sa_mask);
	sigaction (SIGHUP, &sa, NULL);
	sigaction (SIGALRM, &sa, NULL);
	sigaction (SIGCHLD, &sa, NULL);

	set_progname(argv[0]);
	parse_cmdline(argc, argv);
	logging_init();
#ifdef HAVE_LIBPCAP
	fg_pcap_init();
#endif /* HAVE_LIBPCAP */
	if (log_type == LOGTYPE_SYSLOG) {
		/* Need to call daemon() before creating the thread because
		 * it internally calls fork() which does not copy threads. */
		if (daemon(0, 0) == -1)
			crit("daemon() failed");
		logging_log(LOG_NOTICE, "flowgrindd daemonized");
	}

	if (cpu >= 0)
		set_affinity(cpu);

	create_daemon_thread();

	xmlrpc_env_init(&env);

	run_rpc_server(&env, port);

	critx("control should never reach end of main()");
}
void ff::ComBaseEx::_NoLeak()
{
#ifdef COUNT_COM_OBJECTS
	LockMutex crit(GCS_COM_BASE);
	BucketIter hp = GetGlobalComObjectList().Get(this);

	if (hp != INVALID_ITER)
	{
		GetGlobalComObjectList().DeletePos(hp);
	}
#endif
}
Пример #24
0
int common_setup(const char* pidfilename, bool unsafe, const char* runas_user,
                 const char* runas_group, bool daemonize)
{
    if (pidfile_open(pidfilename) < 0) {
        crit("unable to write pidfile %s", pidfilename);
        return EXIT_FAILURE;
    }

    if (!unsafe && drop_privileges(runas_user, runas_group) < 0) {
        crit("unable to drop privileges");
        return EXIT_FAILURE;
    }

    if (daemonize && daemon_detach() < 0) {
        crit("unable to fork");
        return EXIT_FAILURE;
    }

    pidfile_refresh();
    return EXIT_SUCCESS;
}
Пример #25
0
// Must be called before setting any of the previous static Strings
static void SettingTempPath()
{
	if (!s_initTempPathStatics)
	{
		ff::LockMutex crit(ff::GCS_FILE_UTIL);

		if (!s_initTempPathStatics)
		{
			s_initTempPathStatics = true;

			ff::AtProgramShutdown([]()
			{
				ff::LockMutex crit(ff::GCS_FILE_UTIL);
				s_tempPath.clear();
				s_oldTempSubName.clear();
				s_tempSubName.clear();
				s_initTempPathStatics = false;
			});
		}
	}
}
Пример #26
0
    virtual void run()
    {
        if(exLog->hasLogged())
            return;
       
        {
            mt::CriticalSection<sys::Mutex> crit(&counterLock);
            counter++;
        }

        exLog->log(except::Exception("Bad run"), logging::LogLevel::LOG_ERROR);
    }
void gcomm::AsioUdpSocket::close()
{
    Critical<AsioProtonet> crit(net_);
    if (state() != S_CLOSED)
    {
        if (is_multicast(target_ep_) == true)
        {
            leave_group(socket_, target_ep_);
        }
        socket_.close();
    }
    state_ = S_CLOSED;
}
Пример #28
0
char *String::dup(const char *cp)
{
    char *mem;

    if(!cp)
        return NULL;

    size_t len = strlen(cp) + 1;
    mem = (char *)malloc(len);
    crit(mem != NULL, "string dup allocation error");
    String::set(mem, len, cp);
    return mem;
}
Пример #29
0
extern jlib_decl IAtom * createLowerCaseAtom(const char *value, size32_t len)
{
    if (!value || !len)
        return NULL;

    const byte * src = (const byte *)value;
    char * lower = (char *)alloca(len+1);
    for (unsigned i=0; i < len; i++)
        lower[i] = tolower(src[i]);
    lower[len] = 0;

    CriticalBlock crit(atomCrit);
    return queryGlobalAtomTable()->addAtom(lower);
}
Пример #30
0
static int pushStarredWord(void* word_db, StateObj *state, QueryNode *input_qnode)
{
	if (input_qnode->opParam == STAR_BEGIN) {
		return pushRightEndBigram(word_db, state, input_qnode);
	}
	else if (input_qnode->opParam == STAR_END) {
		return pushLeftEndBigram(word_db, state, input_qnode);
	}
	else {
		crit("opParam[%d] is not STAR_BEGIN[%d] and not STAR_END[%d] .. then what???",
				input_qnode->opParam, STAR_BEGIN, STAR_END);
		return FAIL;
	}
}