示例#1
0
static int	SYSTEM_SWAP_PUSED(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
	AGENT_RESULT	result_tmp;
	zbx_uint64_t	tot_val = 0;
	zbx_uint64_t	free_val = 0;

        init_result(&result_tmp);

	if(SYSTEM_SWAP_TOTAL(cmd, param, flags, &result_tmp) != SYSINFO_RET_OK || !(result_tmp.type & AR_UINT64))
		return SYSINFO_RET_FAIL;
	tot_val = result_tmp.ui64;

	/* Check for division by zero */
	if(tot_val == 0)
	{
		free_result(&result_tmp);
		return SYSINFO_RET_FAIL;
	}

	if(SYSTEM_SWAP_FREE(cmd, param, flags, &result_tmp) != SYSINFO_RET_OK || !(result_tmp.type & AR_UINT64))
		return SYSINFO_RET_FAIL;
	free_val = result_tmp.ui64;

	free_result(&result_tmp);

	SET_DBL_RESULT(result, 100.0 - (100.0 * (double)free_val) / (double)tot_val);

        return SYSINFO_RET_OK;
}
示例#2
0
文件: swap.c 项目: HupuInc/zabbix
static int	SYSTEM_SWAP_PFREE(AGENT_RESULT *result)
{
	AGENT_RESULT	result_tmp;
	zbx_uint64_t	tot_val = 0;
	zbx_uint64_t	free_val = 0;

        init_result(&result_tmp);

	if (SYSINFO_RET_OK != SYSTEM_SWAP_TOTAL(cmd, param, flags, &result_tmp) || !(result_tmp.type & AR_UINT64))
		return SYSINFO_RET_FAIL;
	tot_val = result_tmp.ui64;

	/* Check for division by zero */
	if (0 == tot_val)
	{
		free_result(&result_tmp);
		return SYSINFO_RET_FAIL;
	}

	if (SYSINFO_RET_OK != SYSTEM_SWAP_FREE(cmd, param, flags, &result_tmp) || !(result_tmp.type & AR_UINT64))
		return SYSINFO_RET_FAIL;
	free_val = result_tmp.ui64;

	free_result(&result_tmp);

	SET_DBL_RESULT(result, (100.0 * (double)free_val) / (double)tot_val);

	return SYSINFO_RET_OK;
}
示例#3
0
文件: dbase.c 项目: OPSF/uClinux
int db_free_query(db_con_t* _h, db_res_t* _r)
{
	free_query(_h);
	free_result(_r);

	return 0;
}
示例#4
0
bool db_pgsql::sql_update(const char* sql)
{
	free_result();

	PGresult* res = (PGresult *) sane_pgsql_query(sql);
	if (res == NULL)
		return false;

	if (__dbresult_status(res) != PGRES_COMMAND_OK)
	{
		logger_error("db(%s), sql(%s) error(%s)",
			dbname_, sql, __dberror_message(conn_));
		__dbclear(res);
		return false;
	}

	const char* ptr = __dbcmd_tuples(res);
	if (ptr == NULL || *ptr == 0)
	{
		__dbclear(res);
		return true;
	}

	affect_count_ = atoi(ptr);
	__dbclear(res);
	return true;
}
示例#5
0
static void	process_listener(zbx_sock_t *s)
{
	AGENT_RESULT	result;
	char		*command;
	char		**value = NULL;
	int		ret;

	if (SUCCEED == (ret = zbx_tcp_recv_to(s, &command, CONFIG_TIMEOUT)))
	{
		zbx_rtrim(command, "\r\n");

		zabbix_log(LOG_LEVEL_DEBUG, "Requested [%s]", command);

		init_result(&result);
		process(command, 0, &result);

		if (NULL == (value = GET_TEXT_RESULT(&result)))
			value = GET_MSG_RESULT(&result);

		if (NULL != value)
		{
			zabbix_log(LOG_LEVEL_DEBUG, "Sending back [%s]", *value);
			ret = zbx_tcp_send_to(s, *value, CONFIG_TIMEOUT);
		}

		free_result(&result);
	}

	if (FAIL == ret)
		zabbix_log(LOG_LEVEL_DEBUG, "Process listener error: %s", zbx_tcp_strerror());
}
示例#6
0
bool db_pgsql::sql_select(const char* sql, db_rows* result /* = NULL */)
{
	// 优先调用基类方法释放上次的查询结果
	free_result();

	PGresult* res = (PGresult *) sane_pgsql_query(sql);
	if (res == NULL)
		return false;

	if (__dbresult_status(res) != PGRES_TUPLES_OK)
	{
		logger_error("db(%s), sql(%s) error(%s)",
			dbname_, sql, __dberror_message(conn_));
		__dbclear(res);
		return false;
	}

	if (__dbntuples(res) <= 0)
	{
		__dbclear(res);
		result_ = NULL;
		return true;
	}

	if (result != NULL)
		pgsql_rows_save(res, *result);
	else
	{
		result_ = NEW db_rows();
		pgsql_rows_save(res, *result_);
	}

	return true;
}
示例#7
0
/**
 * 获取当天操作纪录信息
 */
int
get_cur_history() {

	char sql[MAX_BUF_SIZE];
    memset(sql, 0, sizeof(sql));

	time_t cur_time = time(NULL);		//获取系统当前时间并格式化

	struct tm *timeinfo;
	timeinfo = localtime(&cur_time);

	char date[MAX_BUF_SIZE];
	memset(date, 0, sizeof(date));

	strftime (date, sizeof(date), "history_%Y%m%d", timeinfo);



	sprintf(sql, "SELECT * FROM `%s`", date);


	if (mysql_query(g_conn, sql)){
    	 print_mysql_error(NULL);
    	 return EXIT_FAILURE;
    }

    g_res = mysql_store_result(g_conn); //从服务器传送结果集至本地,mysql_use_result直接使用服务器上的记录集

	print_result();		//打印
	free_result();		//释放结果集

    return EXIT_SUCCESS;

}
示例#8
0
static int	zbx_execute_script_on_agent(DC_HOST *host, const char *command, char **result,
		char *error, size_t max_error_len)
{
	const char	*__function_name = "zbx_execute_script_on_agent";
	int		ret;
	AGENT_RESULT	agent_result;
	char		*param, *port = NULL;
	DC_ITEM		item;

	zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __function_name);

	*error = '\0';
	memset(&item, 0, sizeof(item));
	memcpy(&item.host, host, sizeof(item.host));

	if (SUCCEED != (ret = DCconfig_get_interface_by_type(&item.interface, host->hostid, INTERFACE_TYPE_AGENT)))
	{
		zbx_snprintf(error, max_error_len, "Whatap agent interface is not defined for host [%s]", host->host);
		goto fail;
	}

	port = zbx_strdup(port, item.interface.port_orig);
	substitute_simple_macros(NULL, NULL, NULL, NULL, &host->hostid, NULL, NULL, &port, MACRO_TYPE_COMMON, NULL, 0);

	if (SUCCEED != (ret = is_ushort(port, &item.interface.port)))
	{
		zbx_snprintf(error, max_error_len, "Invalid port number [%s]", item.interface.port_orig);
		goto fail;
	}

	param = zbx_dyn_escape_string(command, "\"");
	item.key = zbx_dsprintf(item.key, "system.run[\"%s\",\"%s\"]", param, NULL == result ? "nowait" : "wait");
	item.value_type = ITEM_VALUE_TYPE_TEXT;
	zbx_free(param);

	init_result(&agent_result);

	alarm(CONFIG_TIMEOUT);

	if (SUCCEED != (ret = get_value_agent(&item, &agent_result)))
	{
		if (ISSET_MSG(&agent_result))
			zbx_strlcpy(error, agent_result.msg, max_error_len);
		ret = FAIL;
	}
	else if (NULL != result && ISSET_TEXT(&agent_result))
		*result = zbx_strdup(*result, agent_result.text);

	alarm(0);

	free_result(&agent_result);

	zbx_free(item.key);
fail:
	zbx_free(port);

	zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __function_name, zbx_result_string(ret));

	return ret;
}
示例#9
0
文件: Query.cpp 项目: lindianyin/sgbj
MYSQL_RES *Query::get_result(const std::string& sql)
{	// query, result
	if (odb && res)
	{
		free_result();	// add by wlj 2011-11-15
		//GetDatabase().error(*this, "get_result: query busy");
	}
	if (odb && !res)
	{
		if (execute(sql))
		{
			res = mysql_store_result(&odb -> mysql);
			if (res)
			{
				MYSQL_FIELD *f = mysql_fetch_field(res);
				int i = 1;
				while (f)
				{
					if (f -> name)
						m_nmap[f -> name] = i;
					f = mysql_fetch_field(res);
					i++;
				}
				m_num_cols = i - 1;
			}
		}
	}
	return res;
}
/**
 * query_location(char *start_ra, char *end_ra, char *start_dec, char *end_dec)
 * 参数:起止位置坐标
 * 返回值:无
 * 功能描述:根据位置查询文件信息
 */
void
query_location_curr(char* diskName,char* dirId,char *start_ra, char *end_ra, char *start_dec, char *end_dec){

	query_file_by_curr_location(diskName,dirId,start_ra, end_ra, start_dec, end_dec);	//根据位置查询文件信息
	//print_result();		  //打印结果
	free_result();        //释放结果集
}
/**
 * query_location(char *start_ra, char *end_ra, char *start_dec, char *end_dec)
 * 参数:起止位置坐标
 * 返回值:无
 * 功能描述:根据位置查询文件信息
 */
void
query_location(char *start_ra, char *end_ra, char *start_dec, char *end_dec){

	query_file_by_location(start_ra, end_ra, start_dec, end_dec);	//根据位置查询文件信息
	print_result();		  //打印结果
	free_result();        //释放结果集
}
示例#12
0
文件: memory.c 项目: phedders/zabbix
static int      VM_MEMORY_AVAILABLE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
	AGENT_RESULT	result_tmp;
	zbx_uint64_t	sum = 0;

	assert(result);

	init_result(result);

	init_result(&result_tmp);
	if(VM_MEMORY_FREE(cmd, param, flags, &result_tmp) != SYSINFO_RET_OK ||
		!(result_tmp.type & AR_UINT64))
			return  SYSINFO_RET_FAIL;
	sum += result_tmp.ui64;

	if(VM_MEMORY_BUFFERS(cmd, param, flags, &result_tmp) != SYSINFO_RET_OK ||
		!(result_tmp.type & AR_UINT64))
			return  SYSINFO_RET_FAIL;
	sum += result_tmp.ui64;

	if(VM_MEMORY_CACHED(cmd, param, flags, &result_tmp) != SYSINFO_RET_OK ||
		!(result_tmp.type & AR_UINT64))
			return  SYSINFO_RET_FAIL;
	sum += result_tmp.ui64;

	free_result(&result_tmp);

	SET_UI64_RESULT(result, sum);

	return SYSINFO_RET_OK;
}
示例#13
0
文件: history.c 项目: fujii/ebview
void save_result_history(RESULT *rp)
{

	RESULT *result;

	GList *next;

	LOG(LOG_DEBUG, "IN : save_history()");

	g_assert(rp != NULL);

	// 現在表示内容がヒストリの最後でない場合には
	// 以降を削除する
	if(current_in_history){
		next = g_list_next(current_in_history);
		while(next){
			result = (RESULT *)(next->data);
			history_list = g_list_remove(history_list, next->data);
			free_result(result);
			next = g_list_next(current_in_history);
		}
	}

	result = duplicate_result(rp);

	history_list = g_list_append(history_list, result);
	current_in_history = g_list_last(history_list);

	LOG(LOG_DEBUG, "OUT : save_history()");
}
示例#14
0
int PlatDbAccess::free_result(vector<MYSQL_RES*>& result_set_vec)
{
    for(int i=0; i<result_set_vec.size(); i++)
    {
        free_result(result_set_vec[i]);
    }
    return 0;
}
示例#15
0
文件: listener.c 项目: zabbix/zabbix
static void	process_listener(zbx_socket_t *s)
{
	AGENT_RESULT	result;
	char		**value = NULL;
	int		ret;

	if (SUCCEED == (ret = zbx_tcp_recv_to(s, CONFIG_TIMEOUT)))
	{
		zbx_rtrim(s->buffer, "\r\n");

		zabbix_log(LOG_LEVEL_DEBUG, "Requested [%s]", s->buffer);

		init_result(&result);

		if (SUCCEED == process(s->buffer, PROCESS_WITH_ALIAS, &result))
		{
			if (NULL != (value = GET_TEXT_RESULT(&result)))
			{
				zabbix_log(LOG_LEVEL_DEBUG, "Sending back [%s]", *value);
				ret = zbx_tcp_send_to(s, *value, CONFIG_TIMEOUT);
			}
		}
		else
		{
			value = GET_MSG_RESULT(&result);

			if (NULL != value)
			{
				static char	*buffer = NULL;
				static size_t	buffer_alloc = 256;
				size_t		buffer_offset = 0;

				zabbix_log(LOG_LEVEL_DEBUG, "Sending back [" ZBX_NOTSUPPORTED ": %s]", *value);

				if (NULL == buffer)
					buffer = (char *)zbx_malloc(buffer, buffer_alloc);

				zbx_strncpy_alloc(&buffer, &buffer_alloc, &buffer_offset,
						ZBX_NOTSUPPORTED, ZBX_CONST_STRLEN(ZBX_NOTSUPPORTED));
				buffer_offset++;
				zbx_strcpy_alloc(&buffer, &buffer_alloc, &buffer_offset, *value);

				ret = zbx_tcp_send_bytes_to(s, buffer, buffer_offset, CONFIG_TIMEOUT);
			}
			else
			{
				zabbix_log(LOG_LEVEL_DEBUG, "Sending back [" ZBX_NOTSUPPORTED "]");

				ret = zbx_tcp_send_to(s, ZBX_NOTSUPPORTED, CONFIG_TIMEOUT);
			}
		}

		free_result(&result);
	}

	if (FAIL == ret)
		zabbix_log(LOG_LEVEL_DEBUG, "Process listener error: %s", zbx_socket_strerror());
}
示例#16
0
long Query::get_count(const std::string& sql)
{
	long l = 0;
	if (get_result(sql))
	{
		if (fetch_row())
			l = getval();
		free_result();
	}
	return l;
}
示例#17
0
文件: db_mysql.cpp 项目: iYefeng/acl
bool db_mysql::sql_update(const char* sql)
{
	free_result();

	if (sane_mysql_query(sql) == false)
		return false;
	int ret = (int) __mysql_affected_rows(conn_);
	if (ret == -1)
		return false;
	return true;
}
int sql_query_c::execute(char *sql)
{
    free_result();

    if (odb && mysql_query(&odb->mysql, sql) == 0)
    {
        res = mysql_store_result(&odb->mysql);
    }       

    return (int)res;
} 
/*
 * execute_list_all(char* diskName):执行list操作
 * 参数:char* diskName
 * 返回值:无
 * 功能描述:列出指定磁盘下的目录信息
 */
void excute_list_all_directory(char* diskName,char* dirId){

	query_disks_all_info(diskName,dirId);  //查询目录信息
	print_result();              //打印结果
	//printf("%d",print_result());
	/*if((print_result())!=11)
	{
		printf("%s\n","There are no directories in the disk");
	}*/
	free_result();               //释放结果集

}
示例#20
0
文件: dbase.c 项目: OPSF/uClinux
/*
 * Retrieve result set
 */
int get_result(db_con_t* _h, db_res_t** _r)
{
	*_r = new_result_pg(CON_SQLURL(_h));

	if (!CON_RESULT(_h)) {
		LOG(L_ERR, "get_result(): error");
		free_result(*_r);
		*_r = 0;
		return -3;
	}

        if (convert_result(_h, *_r) < 0) {
		LOG(L_ERR, "get_result(): Error while converting result\n");
		free_result(*_r);
		*_r = 0;

		return -4;
	}

	return 0;
}
/*
 * execute_time(char *start_time, char *end_time):执行query操作
 * 参数:无
 * 返回值:无
 * 功能描述:显示当前工作目录
 */
void query_time_from_home(char *start_time,  char *end_time){

	query_file_by_time(start_time, end_time);//根据时间查询文件信息
	print_result();		  //打印结果
	//printf("%d",print_result());
	/*if((print_result())!=13)
	{
		printf("%s\n","No file was retrieved");
	}*/
	free_result();        //释放结果集

}
示例#22
0
文件: struct.c 项目: m3dh/onlinejudge
int free_submit(struct submit *sbp) {
	if(sbp) {
		if(sbp->code) {
			free(sbp->code);
		}
		if(sbp->r_ptr) {
			free_result(sbp->r_ptr);
		}
		free(sbp);
	}
	return _SUCCEED_;
}
/*
 * execute_show_all():执行show操作
 * 参数:无
 * 返回值:无
 * 功能描述:列出所有磁盘详细信息
 */
void excute_show_all(){

	query_all_disks();     //查询所有磁盘信息
	print_result();    //打印结果
	//printf("%d",print_result());
	/*if((print_result())!=13)
	{
		printf("%s\n","There is no disk information");
	}*/
	free_result();     //释放结果集

}
示例#24
0
    /// Ctor
    explicit
    NumberCompressor() : m_result(0)
    {
        m_Allocator   = malloc;  // using C memory allocators
        m_DeAllocator = free;

        // no compression is the default
        setCompressor( COMPRESSOR_DEFAULT_ID, 0 );
        
        clear_data();
        free_result();
    }
示例#25
0
static void test_free_result(void)
{
    char* data = malloc(32);
    sprintf(data, "some entity data");

    free_called_with = 0;

    free_result(success_result((void*)data, &free_data, 0, 0));
    CU_ASSERT_PTR_EQUAL(free_called_with, data);

    free(data);
}
示例#26
0
static void test_success_with_cookie(void)
{
    struct cookie cookie;
    struct result* result = 0;

    result = success_result(0, 0, 0, &cookie);

    CU_ASSERT_PTR_NOT_NULL_FATAL(result);
    CU_ASSERT_PTR_EQUAL(result->cookies, &cookie);

    free_result(result);
}
/*
 * execute_ls_all(char* dirName, char* diskName):执行ls
 * 参数:char* parameter
 * 返回值:无
 * 功能描述:在终端显示当前目录详细信息
 */
void excute_list_all_file(char* diskName, char* dirId){

	query_directory_all_info(diskName, dirId);//查询当前目录内文件和目录详细信息
	print_result();       //打印结果
	//printf("%d",print_result());
	/*if((print_result())!=13)
	{
		printf("%s\n","There are no files in the directory");
	}*/
	free_result();        //释放结果集

}
示例#28
0
static void	process_test_data(zbx_uint64_t httptestid, ZBX_HTTPSTAT *stat)
{
	const char	*__function_name = "process_test_data";

	DB_RESULT	result;
	DB_ROW		row;
	DB_HTTPTESTITEM	httptestitem;

	AGENT_RESULT    value;

	zabbix_log(LOG_LEVEL_DEBUG, "In %s() httptestid:" ZBX_FS_UI64 " total_time:" ZBX_FS_DBL " last_step:%d",
			__function_name, httptestid, stat->test_total_time, stat->test_last_step);

	result = DBselect("select httptestitemid,httptestid,itemid,type"
				" from httptestitem"
				" where httptestid=" ZBX_FS_UI64,
				httptestid);

	while (NULL != (row = DBfetch(result)))
	{
		ZBX_STR2UINT64(httptestitem.httptestitemid, row[0]);
		ZBX_STR2UINT64(httptestitem.httptestid, row[1]);
		ZBX_STR2UINT64(httptestitem.itemid, row[2]);
		httptestitem.type = atoi(row[3]);

		init_result(&value);

		switch (httptestitem.type)
		{
			case ZBX_HTTPITEM_TYPE_TIME:
				SET_DBL_RESULT(&value, stat->test_total_time);
				process_value(httptestitem.itemid, &value);
				break;
			case ZBX_HTTPITEM_TYPE_LASTSTEP:
				SET_UI64_RESULT(&value, stat->test_last_step);
				process_value(httptestitem.itemid, &value);
				break;
			case ZBX_HTTPITEM_TYPE_SPEED:
				SET_UI64_RESULT(&value, stat->speed_download);
				process_value(httptestitem.itemid, &value);
				break;
			default:
				break;
		}

		free_result(&value);
	}

	DBfree_result(result);

	zabbix_log(LOG_LEVEL_DEBUG, "End of %s()", __function_name);
}
示例#29
0
bool sqlinc::fetch_row()
{
	if ((row = mysql_fetch_row(result)))
	{
		return true; // something in the row
	}
	else
	{
		// end of the array
		free_result();
		return false;
	}
}
示例#30
0
static void test_entity_without_free(void)
{
    char data[] = "some entity data";
    struct result* result = 0;

    free_called_with = 0;

    result = success_result((void*)data, 0, 0, 0);
    CU_ASSERT_PTR_NOT_NULL_FATAL(result);

    free_result(result);
    CU_ASSERT_PTR_NULL(free_called_with);
}