コード例 #1
0
ファイル: netinfo.c プロジェクト: UVP-Tools/UVP-Tools
/*****************************************************************************
Function   : Ipv6PrintInfo
Description: print Ipv4/6 info
Input       : None
Output     : None
Return     : 
*****************************************************************************/
void Ipv6PrintInfo(void * handle)
{
    unsigned int i = 0;
    char vif_path[NETINFO_PATH_LEN] = {0};
    /*xenstore print info*/
    for (i = 0; i < XENSTORE_COUNT; i++)
    {

        memset_s(vif_path,NETINFO_PATH_LEN,0,NETINFO_PATH_LEN);
        /*assemble xenstore path*/
        if(i == 0)
        {
            (void)snprintf_s(vif_path, NETINFO_PATH_LEN, NETINFO_PATH_LEN, "%s", IPV6_VIF_DATA_PATH);
        }
        else
        {
            (void)snprintf_s(vif_path, NETINFO_PATH_LEN, NETINFO_PATH_LEN, "%s_%u", IPV6_VIF_DATA_PATH, i);
        }

        if(xb_write_first_flag == 0)
        {
            (void)write_to_xenstore(handle, vif_path, ArrRetNet[i]);
        }
        else
        {
            (void)write_weak_to_xenstore(handle, vif_path, ArrRetNet[i]);
        }
    }
}
コード例 #2
0
ファイル: conf.c プロジェクト: azuwis/xreader
static char *cycleToString(char *str, int size, t_conf_cycle cycle)
{
	if (str == NULL || size == 0)
		return NULL;

	switch (cycle) {
		case conf_cycle_single:
			snprintf_s(str, size, "single");
			break;
		case conf_cycle_repeat:
			snprintf_s(str, size, "repeat");
			break;
		case conf_cycle_repeat_one:
			snprintf_s(str, size, "repeat_one");
			break;
		case conf_cycle_random:
			snprintf_s(str, size, "random");
			break;
		default:
			snprintf_s(str, size, "");
			break;
	}

	return str;
}
コード例 #3
0
ファイル: conf.c プロジェクト: azuwis/xreader
static char *vertreadToString(char *str, int size, t_conf_vertread vertread)
{
	if (str == NULL || size == 0)
		return NULL;

	switch (vertread) {
		case conf_vertread_horz:
			snprintf_s(str, size, "horz");
			break;
		case conf_vertread_rvert:
			snprintf_s(str, size, "rvert");
			break;
		case conf_vertread_lvert:
			snprintf_s(str, size, "lvert");
			break;
		case conf_vertread_reversal:
			snprintf_s(str, size, "reversal");
			break;
		default:
			snprintf_s(str, size, "");
			break;
	}

	return str;
}
コード例 #4
0
ファイル: conf.c プロジェクト: azuwis/xreader
static char *rotateToString(char *str, int size, t_conf_rotate rotate)
{
	if (str == NULL || size == 0)
		return NULL;

	switch (rotate) {
		case conf_rotate_0:
			snprintf_s(str, size, "0");
			break;
		case conf_rotate_90:
			snprintf_s(str, size, "90");
			break;
		case conf_rotate_180:
			snprintf_s(str, size, "180");
			break;
		case conf_rotate_270:
			snprintf_s(str, size, "270");
			break;
		default:
			snprintf_s(str, size, "");
			break;
	}

	return str;
}
コード例 #5
0
/*****************************************************************************
* 函 数 名  : bsp_gpio_init
*
* 功能描述  : GPIO初始化接口
*
* 输入参数  : 无
*
* 返 回 值  : 无
*
* 修改记录  : 2012年11月27日
*****************************************************************************/
s32 bsp_gpio_init(void)
{
    u32  i = 0;
    int  ret = 0;
    char gpio_clk_name[40]       = "";
	char node_name[NAME_LENTH]   = "";
	char *base_addr              = NULL;	
    struct clk         *gpio_clk = NULL;
	struct device_node *dev_node = NULL;

    if (GPIO_DEF_RUNNING == g_u32GpioRunning)
    {
        return GPIO_OK;
    }

    spin_lock_init(&g_gpio_spinlock);

    for(i = 0; i < GPIO_MAX_BANK_NUM; i++)
    {
		(void)snprintf_s(node_name,NAME_LENTH,NAME_LENTH,"hisilicon,gpio%d",i);
		dev_node = of_find_compatible_node(NULL,NULL,node_name);
		if(!dev_node)
		{
			gpio_print_error("get gpio%d node failed!\n",i);
			return ERROR;
		}
		
		/* 内存映射,获得基址 */
		base_addr = (char *)of_iomap(dev_node, 0);
		if (NULL == base_addr)
		{
			gpio_print_error("gpio%d iomap fail\n",i);
			return ERROR;
		}
		s_u32GpioBaseAddr[i] = (u32)base_addr;
        (void)memset_s(gpio_clk_name, 40, 0 , 40);
        (void)snprintf_s(gpio_clk_name, 40, 40, "gpio%d_clk", i); /*lint !e119*/
        gpio_clk = (struct clk *)clk_get(NULL, gpio_clk_name);
    	if(IS_ERR(gpio_clk))
        {
    		gpio_print_error("gpio%d clk cannot get, 0x%x.\n", i, gpio_clk);
			return ERROR;
    	}

        ret = clk_enable(gpio_clk);

    }

    gpio_print_info("gpio init ok.\n");
    g_u32GpioRunning = GPIO_DEF_RUNNING;

    return ret;

}
コード例 #6
0
ファイル: netinfo.c プロジェクト: UVP-Tools/UVP-Tools
/*****************************************************************************
Function   : GetIpv6VifMac
Description: get Ipv4/6 mac address
Input       : None
Output     : None
Return     : 
*****************************************************************************/
void GetIpv6VifMac(int skt, const char *ifname)
{
    struct ifreq ifrequest;

    if (NULL == ifname)
    {
        return ;
    }

    strncpy_s(ifrequest.ifr_name, IFNAMSIZ, ifname, IFNAMSIZ-1);
    ifrequest.ifr_name[IFNAMSIZ - 1] = '\0';

    if ( ! (ioctl(skt, SIOCGIFHWADDR, (char *) &ifrequest) ) )
    {
        (void)snprintf_s(gtNicIpv6Info.info[gtNicIpv6Info.count].mac, 
                        sizeof(gtNicIpv6Info.info[gtNicIpv6Info.count].mac), 
                        sizeof(gtNicIpv6Info.info[gtNicIpv6Info.count].mac), 
                        "%02x:%02x:%02x:%02x:%02x:%02x",
                       (unsigned char)ifrequest.ifr_hwaddr.sa_data[0],
                       (unsigned char)ifrequest.ifr_hwaddr.sa_data[1],
                       (unsigned char)ifrequest.ifr_hwaddr.sa_data[2],
                       (unsigned char)ifrequest.ifr_hwaddr.sa_data[3],
                       (unsigned char)ifrequest.ifr_hwaddr.sa_data[4],
                       (unsigned char)ifrequest.ifr_hwaddr.sa_data[5]);

    }
    return ;

}
コード例 #7
0
ファイル: healthcheck.c プロジェクト: Jinjian0609/UVP-Tools
/*****************************************************************************
 Function   : do_healthcheck
 Description: do update heatch check
 Input      : handle -- xenbus file handle
 Output     : None
 Return     : XEN_SUCC or XEN_ERROR
 *****************************************************************************/
int do_healthcheck(void * handle)
{
    int iSpaceRet = 0;           //disksize
    int iKernelRet = 0;          //UpKernel flag
    int iCommandRet = 0;     //command flag
    char resStr[MAX_PATH] = {0};

    if (NULL == handle)
    {
        return XEN_FAIL;
    }

    /*检查磁盘空间是否剩余*/
    iSpaceRet = CheckDiskspace();

    /*检查内核是否升级*/
    iKernelRet = CheckUpKernel();

    /*检查系统命令是否存在*/
    iCommandRet = CheckCommand();

    (void)snprintf_s(resStr, MAX_PATH, MAX_PATH, "%d:%d:%d", iSpaceRet, iKernelRet, iCommandRet);

    if(xb_write_first_flag == 0)
    {
        /*如果返回成功,写入磁盘利用率信息*/
        write_to_xenstore(handle, HEALTH_CHECK_RESULT_PATH, resStr);
    }
    else
    {
        write_weak_to_xenstore(handle, HEALTH_CHECK_RESULT_PATH, resStr);
    }
    return XEN_SUCC;
}
コード例 #8
0
ファイル: netinfo.c プロジェクト: UVP-Tools/UVP-Tools
/*****************************************************************************
Function   : GetIpv4VifIp
Description: get Ipv4 ip info
Input       : None
Output     : None
Return     : 
*****************************************************************************/
int GetIpv4VifIp(int skt, int num, char *ifname)
{
    struct ifaddrs *ifaddr, *ifa;
    int ret;
    char address[IPV6_ADDR_LEN];

    if (getifaddrs(&ifaddr) == -1)
    {
        ERR_LOG("Call getifaddrs failed, errno=%d", errno);
        return ERROR;
    }

    for (ifa = ifaddr; ifa; ifa = ifa->ifa_next)
    {
        if (NULL == ifa->ifa_addr)
            continue;
        if( AF_INET != ifa->ifa_addr->sa_family)
            continue;

        ret = getnameinfo(ifa->ifa_addr,sizeof(struct sockaddr_in),address, IPV6_ADDR_LEN, NULL, 0, NI_NUMERICHOST);
        if (0 != ret)
        {
            ERR_LOG("Call getnameinfo for nic %s failed: %s.", ifname, gai_strerror(ret));
            continue;
        }

        if((NULL != ifa->ifa_name) && (strcmp(ifa->ifa_name,ifname) == 0) && (AF_INET == ifa->ifa_addr->sa_family))
        {
            snprintf_s(gtNicIpv6Info.info[gtNicIpv6Info.count].ifname, VIF_NAME_LENGTH, VIF_NAME_LENGTH, "%s", ifname);
            GetIpv6VifMac(skt,ifname);
            gtNicIpv6Info.info[gtNicIpv6Info.count].ipversionflag = 4;
            snprintf_s(gtNicIpv6Info.info[gtNicIpv6Info.count].ipaddr, IPV6_ADDR_LEN, IPV6_ADDR_LEN, "%s", address);

            GetIpv4VifGateway(skt, ifname);

            GetIpv6Flux(skt,ifname);
            GetIpv6NetFlag(skt,ifname);

            num++;
            gtNicIpv6Info.count = num;
        }
    }

    freeifaddrs(ifaddr);
    return gtNicIpv6Info.count;
}
コード例 #9
0
ファイル: conf.c プロジェクト: azuwis/xreader
static char *fitToString(char *str, int size, t_conf_fit fit)
{
	if (str == NULL || size == 0)
		return NULL;

	switch (fit) {
		case conf_fit_none:
			snprintf_s(str, size, "none");
			break;
		case conf_fit_width:
			snprintf_s(str, size, "width");
			break;
		case conf_fit_dblwidth:
			snprintf_s(str, size, "dblwidth");
			break;
		case conf_fit_height:
			snprintf_s(str, size, "height");
			break;
		case conf_fit_dblheight:
			snprintf_s(str, size, "dblheight");
			break;
		case conf_fit_custom:
			snprintf_s(str, size, "custom");
			break;
		default:
			snprintf_s(str, size, "");
			break;
	}

	return str;
}
コード例 #10
0
ファイル: conf.c プロジェクト: azuwis/xreader
static char *dwordToString(char *str, int size, dword dw)
{
	if (str == NULL || size == 0)
		return NULL;

	snprintf_s(str, size, "%lu", dw);

	return str;
}
コード例 #11
0
ファイル: conf.c プロジェクト: azuwis/xreader
static char *intToString(char *str, int size, int i)
{
	if (str == NULL || size == 0)
		return NULL;

	snprintf_s(str, size, "%ld", i);

	return str;
}
コード例 #12
0
ファイル: conf.c プロジェクト: azuwis/xreader
static char *hexToString(char *str, int size, unsigned int hex)
{
	if (str == NULL || size == 0)
		return NULL;

	snprintf_s(str, size, "0x%08x", hex);

	return str;
}
コード例 #13
0
ファイル: conf.c プロジェクト: azuwis/xreader
static char *booleanToString(char *str, int size, bool b)
{
	if (str == NULL || size == 0)
		return NULL;

	snprintf_s(str, size, "%s", b ? "true" : "false");

	return str;
}
コード例 #14
0
ファイル: conf.c プロジェクト: azuwis/xreader
static char *arrangeToString(char *str, int size, t_conf_arrange arrange)
{
	if (str == NULL || size == 0)
		return NULL;

	switch (arrange) {
		case conf_arrange_ext:
			snprintf_s(str, size, "ext");
			break;
		case conf_arrange_name:
			snprintf_s(str, size, "name");
			break;
		case conf_arrange_size:
			snprintf_s(str, size, "size");
			break;
		case conf_arrange_ctime:
			snprintf_s(str, size, "ctime");
			break;
		case conf_arrange_mtime:
			snprintf_s(str, size, "mtime");
			break;
		default:
			snprintf_s(str, size, "");
			break;
	}

	return str;
}
コード例 #15
0
ファイル: conf.c プロジェクト: azuwis/xreader
static char *imgpagingToString(char *str, int size, t_conf_imgpaging imgpaging)
{
	if (str == NULL || size == 0)
		return NULL;

	switch (imgpaging) {
		case conf_imgpaging_direct:
			snprintf_s(str, size, "direct");
			break;
		case conf_imgpaging_updown:
			snprintf_s(str, size, "updown");
			break;
		case conf_imgpaging_leftright:
			snprintf_s(str, size, "leftright");
			break;
		case conf_imgpaging_updown_smooth:
			snprintf_s(str, size, "updown_smooth");
			break;
		case conf_imgpaging_leftright_smooth:
			snprintf_s(str, size, "leftright_smooth");
			break;
		default:
			snprintf_s(str, size, "");
			break;
	}

	return str;
}
コード例 #16
0
ファイル: conf.c プロジェクト: azuwis/xreader
static char *encodeToString(char *str, int size, t_conf_encode encode)
{
	if (str == NULL || size == 0)
		return NULL;

	switch (encode) {
		case conf_encode_gbk:
			snprintf_s(str, size, "gbk");
			break;
		case conf_encode_big5:
			snprintf_s(str, size, "big5");
			break;
		case conf_encode_sjis:
			snprintf_s(str, size, "sjis");
			break;
		case conf_encode_ucs:
			snprintf_s(str, size, "ucs");
			break;
		case conf_encode_utf8:
			snprintf_s(str, size, "utf8");
			break;
		default:
			snprintf_s(str, size, "");
			break;
	}

	return str;
}
コード例 #17
0
ファイル: conf.c プロジェクト: azuwis/xreader
static char *viewposToString(char *str, int size, t_conf_viewpos viewpos)
{
	if (str == NULL || size == 0)
		return NULL;

	switch (viewpos) {
		case conf_viewpos_leftup:
			snprintf_s(str, size, "leftup");
			break;
		case conf_viewpos_midup:
			snprintf_s(str, size, "midup");
			break;
		case conf_viewpos_rightup:
			snprintf_s(str, size, "rightup");
			break;
		case conf_viewpos_leftmid:
			snprintf_s(str, size, "leftmid");
			break;
		case conf_viewpos_midmid:
			snprintf_s(str, size, "midmid");
			break;
		case conf_viewpos_rightmid:
			snprintf_s(str, size, "rightmid");
			break;
		case conf_viewpos_leftdown:
			snprintf_s(str, size, "leftdown");
			break;
		case conf_viewpos_middown:
			snprintf_s(str, size, "middown");
			break;
		case conf_viewpos_rightdown:
			snprintf_s(str, size, "rightdown");
			break;
		default:
			snprintf_s(str, size, "");
			break;
	}

	return str;
}
コード例 #18
0
ファイル: conf.c プロジェクト: azuwis/xreader
static char *alignToString(char *str, int size, t_conf_align align)
{
	if (str == NULL || size == 0)
		return NULL;

	switch (align) {
		case conf_align_left:
			snprintf_s(str, size, "left");
			break;
		case conf_align_right:
			snprintf_s(str, size, "right");
			break;
		case conf_align_center:
			snprintf_s(str, size, "center");
			break;
		default:
			snprintf_s(str, size, "");
			break;
	}

	return str;
}
コード例 #19
0
ファイル: conf.c プロジェクト: azuwis/xreader
static char *infobarToString(char *str, int size, t_conf_infobar infobar)
{
	if (str == NULL || size == 0)
		return NULL;

	switch (infobar) {
		case conf_infobar_none:
			snprintf_s(str, size, "none");
			break;
		case conf_infobar_info:
			snprintf_s(str, size, "info");
			break;
		case conf_infobar_lyric:
			snprintf_s(str, size, "lyric");
			break;
		default:
			snprintf_s(str, size, "");
			break;
	}

	return str;
}
コード例 #20
0
ファイル: conf.c プロジェクト: azuwis/xreader
static char *thumbToString(char *str, int size, t_conf_thumb thumb)
{
	if (str == NULL || size == 0)
		return NULL;

	switch (thumb) {
		case conf_thumb_none:
			snprintf_s(str, size, "none");
			break;
		case conf_thumb_scroll:
			snprintf_s(str, size, "scroll");
			break;
		case conf_thumb_always:
			snprintf_s(str, size, "always");
			break;
		default:
			snprintf_s(str, size, "");
			break;
	}

	return str;
}
コード例 #21
0
ファイル: Ex10_03.c プロジェクト: NoMan2000/c-prog
void show(double array[], size_t array_size, unsigned int field_width)
{
  char format[10] = {'\0'};                         // Holds the format string
  unsigned int places = 2;
  snprintf_s(format, sizeof(format), "%%%u.%ulf", field_width, places);

  // Output the values five to a line
  for(size_t j = 0 ; j < array_size ; ++j)
  {
    if(j%5 == 0)
      printf_s("\n");

    printf_s(format, array[j]);
  }
}
コード例 #22
0
ファイル: netinfo.c プロジェクト: UVP-Tools/UVP-Tools
int GetIpv6VifGateway(int skt, const char *ifname)
{
    char pathBuf[MAX_NICINFO_LENGTH] = {0};
    char pszGateway[VIF_NAME_LENGTH] = {0};
    char pszGatewayBuf[VIF_NAME_LENGTH] = {0};
    FILE *iRet;

    if(NULL == ifname)
    {
        return ERROR;
    }

    if(SUCC != CheckName(ifname))
    {
        return ERROR;
    }

    (void)memset_s(pathBuf, MAX_NICINFO_LENGTH, 0, MAX_NICINFO_LENGTH);
     /*exec shell command to get ipv6 route gataway info*/
    (void)snprintf_s(pathBuf, MAX_NICINFO_LENGTH, MAX_NICINFO_LENGTH,
                "route -A inet6 -n | grep -w \"%s\" | grep UG | awk '{print $2}'", ifname);
    iRet = openPipe(pathBuf, "r");
    if (NULL == iRet)
    {
       INFO_LOG("Failed to execute route shell command, pathBuf=%s.", pathBuf);
       gtNicIpv6Info.info[gtNicIpv6Info.count].gateway[0] = '\0';
       return ERROR;
    }

    /*save default gw*/
    if(NULL != fgets(pszGatewayBuf,sizeof(pszGatewayBuf),iRet))
    {
       (void)sscanf_s(pszGatewayBuf,"%s",pszGateway,sizeof(pszGateway));
    }
    trim(pszGateway);

    /*if strlen(pszGateway) < 1, then 0*/
    if(strlen(pszGateway) < 1)
    {
       pszGateway[0]='0';
       pszGateway[1]='\0';
    }
    (void)pclose(iRet);
    (void)strncpy_s(gtNicIpv6Info.info[gtNicIpv6Info.count].gateway, IPV6_ADDR_LEN, pszGateway, strlen(pszGateway));
    return SUCC;
}
コード例 #23
0
ファイル: memory.c プロジェクト: Jinjian0609/UVP-Tools
/*****************************************************************************
Function   : GetMMUseRatio
Description: 获得 memory的利用率
Input       :meminfo文件的路径
Input       :char size
Output     :按顺序保存内存总量,内存空闲量,内存使用量,内存buffer量,
            内存cache量以及swap总量,swap使用量,swap空闲量,单位KB
Return     : memory的利用率
*****************************************************************************/
int GetMMUseRatio(const char *mem_file, char *meminfo_buf, int size, char *swap_meminfo_buf)
{
    FILE *file;
    char tmp_buffer[TMP_BUFFER_SIZE + 1];
    char *start = NULL;
    char *start_swap = NULL;
    unsigned long ulMemTotal = 0L;
    unsigned long ulMemFree = 0L;
    unsigned long ulMemBuffers = 0L;
    unsigned long ulMemCached = 0L;
    unsigned long ulMemSwapCached = 0L;
    unsigned long ulMemSReclaimable = 0L;
    unsigned long ulMemNFSUnstable = 0L;
    unsigned long ulSwapTotal = 0L;
    unsigned long ulSwapFree = 0L;
    
    int iRetLen = 0;

    file = fopen(mem_file, "r");
    if (NULL == file)
    {
        //	LogPrint("Unable to open %s, errno: %d\n", PROC_MEMINFO, errno);

        (void)strncpy_s(meminfo_buf, size+1, ERR_STR, size);
        (void)strncpy_s(swap_meminfo_buf, size+1, ERR_STR, size);
        meminfo_buf[size] = '\0';
        swap_meminfo_buf[size] = '\0';

        return ERROR;
        //lint -save -e438
    }

    while (NULL != fgets(tmp_buffer, TMP_BUFFER_SIZE, file))
    {
        /*get total memory*/
        start = strstr(tmp_buffer, "MemTotal:");

        if ( NULL != start )
        {
            start = start + strlen("MemTotal:");
            /*lMemTotal = atol(start);*/
            ulMemTotal = strtoul(start, NULL, DECIMAL);
        }
        /*get free memory*/
        start = strstr(tmp_buffer, "MemFree:");
        if ( NULL != start )
        {
            start = start + strlen("MemFree:");
            /*lMemFree = atol(start);*/
            ulMemFree = strtoul(start, NULL, DECIMAL);
        }
        /*get buffers memory*/
        start = strstr(tmp_buffer, "Buffers:");
        if ( NULL != start )
        {
            start = start + strlen("Buffers:");
            ulMemBuffers = strtoul(start, NULL, DECIMAL);
        }
        /*get cached memory*/
        start = strstr(tmp_buffer, "Cached:");
        if ( NULL != start )
        {
            if(0 == strncmp(tmp_buffer, "Cached:", 7))
            {
                start = start + strlen("Cached:");
                ulMemCached = strtoul(start, NULL, DECIMAL);
            }
        }
        /*get SwapCached memory*/
        start = strstr(tmp_buffer, "SwapCached:");
        if ( NULL != start )
        {
            start = start + strlen("SwapCached:");
            ulMemSwapCached = strtoul(start, NULL, DECIMAL);
        }
        /*get swap total*/
        start = strstr(tmp_buffer, "SwapTotal:");
        if ( NULL != start )
        {
            start = start + strlen("SwapTotal:");
            ulSwapTotal = strtoul(start, NULL, DECIMAL);
        }
        /*get swap free*/
        start = strstr(tmp_buffer, "SwapFree:");
        if ( NULL != start )
        {
            start = start + strlen("SwapFree:");
            ulSwapFree = strtoul(start, NULL, DECIMAL);
        }
        /*get SReclaiable memory*/
        start = strstr(tmp_buffer, "SReclaimable:");
        if ( NULL != start )
        {
            start = start + strlen("SReclaimable:");
            ulMemSReclaimable = strtoul(start, NULL, DECIMAL);
        }      
        /*get NFSUnstable memory*/
        start = strstr(tmp_buffer, "NFS_Unstable:");
        if ( NULL != start )
        {
            start = start + strlen("NFS_Unstable:");
            ulMemNFSUnstable = strtoul(start, NULL, DECIMAL);
            break;
        }

    }

    (void)fclose(file);
    if(is_suse())
    {
        iRetLen = snprintf_s(meminfo_buf, size - 1, size - 1, "%lu:%lu:%lu:%lu:%lu", 
                    ulMemFree + ulMemBuffers + ulMemCached + ulMemSwapCached + ulMemSReclaimable + ulMemNFSUnstable,
                    ulMemTotal,
                    ulMemTotal - ulMemFree,
                    ulMemBuffers,
                    ulMemCached);
    }
    else
    {
        iRetLen = snprintf_s(meminfo_buf, size - 1, size - 1, "%lu:%lu:%lu:%lu:%lu",
                    ulMemFree + ulMemBuffers + ulMemCached,
                    ulMemTotal,
                    ulMemTotal - ulMemFree,
                    ulMemBuffers,
                    ulMemCached);
    }
    meminfo_buf[iRetLen] = '\0';

    iRetLen = snprintf_s(swap_meminfo_buf, size - 1, size - 1, "%lu:%lu:%lu",
                    ulSwapTotal,
                    ulSwapTotal - ulSwapFree,
                    ulSwapFree);
    swap_meminfo_buf[iRetLen] = '\0';
    
    return SUCC;
}
コード例 #24
0
ファイル: netinfo.c プロジェクト: UVP-Tools/UVP-Tools
/*****************************************************************************
Function   : NetinfoNetworkctlmon
Description: ip4/6 main entry
Input       : None
Output     : None
Return     : 
*****************************************************************************/
void NetinfoNetworkctlmon(void *handle)
{
   char NetworkLoss[32] = {0};
   int i = 0;
   int num = 0;
   int count = 0;
   int BuffLen = 0;
   long sumrecievedrop = 0;
   long sumsentdrop = 0;
   
   num = GetIpv6Info();
   memset_s(ArrRetNet,sizeof(ArrRetNet),0,sizeof(ArrRetNet));

   /*init ArrRetNet*/
   for(i=0;i<XENSTORE_COUNT;i++)
   {
        (void)snprintf_s(ArrRetNet[i],sizeof("0"),sizeof("0"),"%s","0");
   }
   
   if (ERROR == num)
   {
        write_to_xenstore(handle, IPV6_VIF_DATA_PATH, "error");
        DEBUG_LOG("Num is ERROR.");
        return;
   }
   
   if (0 == num)
   {
        Ipv6PrintInfo(handle);
        write_to_xenstore(handle, IPV6_VIF_DATA_PATH, "0");
        return;
   }
   
   memset_s(&gtNicIpv6InfoResult, sizeof(gtNicIpv6InfoResult), 0, sizeof(gtNicIpv6InfoResult));
   gtNicIpv6InfoResult.count = 0;

   /*IP Prioritization: if interface has ip, then put on the front of array*/
   for(i=0;i<num;i++)
   {
        if(IPADDR_LEN < strlen(gtNicIpv6Info.info[i].ipaddr))
        {
            (void)memcpy_s(&gtNicIpv6InfoResult.info[gtNicIpv6InfoResult.count],
                sizeof(IPV6_VIF_DATA),
                &gtNicIpv6Info.info[i],
                sizeof(IPV6_VIF_DATA));
            gtNicIpv6InfoResult.count++;
        }
        if(gtNicIpv6InfoResult.count >IPV6_IPNUM )
            break;
   }
   for(i=0;i<num;i++)
   {
        if(gtNicIpv6InfoResult.count >IPV6_IPNUM )
                break;
        if(IPADDR_LEN >= strlen(gtNicIpv6Info.info[i].ipaddr))
        {
                (void)memcpy_s(&gtNicIpv6InfoResult.info[gtNicIpv6InfoResult.count],
                    sizeof(IPV6_VIF_DATA),
                    &gtNicIpv6Info.info[i],
                    sizeof(IPV6_VIF_DATA));
                gtNicIpv6InfoResult.count++;
        }
        
   }
   
   /*assemble array*/
   for(i=0;i<gtNicIpv6InfoResult.count;i++)
    {
        /*The total number of packet loss statistics*/
        if(g_exinfo_flag_value & EXINFO_FLAG_NET_LOSS)
        {
          sumsentdrop += gtNicIpv6InfoResult.info[i].sentdrop;
          sumrecievedrop += gtNicIpv6InfoResult.info[i].recievedrop;
        }

        /*6 xenstore info*/
        count = i/XENSTORE_COUNT;
        if(i%XENSTORE_COUNT == 0)
            BuffLen = 0;
        else
            BuffLen = strlen(ArrRetNet[count]);

        if(0!=strlen(gtNicIpv6InfoResult.info[i].ipaddr))
        {
            (void)snprintf_s(ArrRetNet[count] + BuffLen, 
                sizeof(ArrRetNet[count]) - BuffLen,
                sizeof(ArrRetNet[count]) - BuffLen,
                "[%s-%d-%s-%s-<%s>-<%s>]",
                gtNicIpv6InfoResult.info[i].mac,
                gtNicIpv6InfoResult.info[i].netstatusflag,
                gtNicIpv6InfoResult.info[i].ipaddr,
                trim(gtNicIpv6InfoResult.info[i].gateway),
                gtNicIpv6InfoResult.info[i].tp,
                gtNicIpv6InfoResult.info[i].packs);
        }
        else
        {
           (void)snprintf_s(ArrRetNet[count] + BuffLen, 
                sizeof(ArrRetNet[count]) - BuffLen,
                sizeof(ArrRetNet[count]) - BuffLen,
                "[%s-%d]",
                gtNicIpv6InfoResult.info[i].mac,
                gtNicIpv6InfoResult.info[i].netstatusflag);
        }
    }
    
   Ipv6PrintInfo(handle);
   
   if(g_exinfo_flag_value & EXINFO_FLAG_NET_LOSS)
   {
        (void)snprintf_s(NetworkLoss, sizeof(NetworkLoss), sizeof(NetworkLoss), "%ld:%ld",sumrecievedrop, sumsentdrop);
   }
   
   if(xb_write_first_flag == 0)
   {
        if(g_exinfo_flag_value & EXINFO_FLAG_NET_LOSS)
        {
           write_to_xenstore(handle, VIF_DROP_PATH, NetworkLoss);
        }
   }
   else
   {
        if(g_exinfo_flag_value & EXINFO_FLAG_NET_LOSS)
        {
           write_weak_to_xenstore(handle, VIF_DROP_PATH, NetworkLoss);
        }
   }
   return ;
}
コード例 #25
0
ファイル: netinfo.c プロジェクト: UVP-Tools/UVP-Tools
/*****************************************************************************
Function   : GetIpv6NetFlag
Description: get interface flag 
Input       : None
Output     : None
Return     : 
*****************************************************************************/
void GetIpv6NetFlag(int skt,char *vifname)
{

    char *vlan_path = "/proc/net/vlan/config";
    char bond_path[BONDBRIDGE_PATH_LEN] = {0};
    char bridge_path[BONDBRIDGE_PATH_LEN] = {0};
    char namebuf[VIF_NAME_LENGTH] = {0};
    char *vifnamebuf = NULL;
    int vlan_flag = 0;
    int vlanfile_flag = 1;
    int bond_flag = 0;
    int bridge_flag = 0;
    int vifnamelen = 0;
    FILE *file = NULL;
    char *begin = NULL;
    char pline[128] = {0};
    int i = 0;


    if (NULL == vifname)
    {
        return ;
    }
    vifnamebuf = vifname;
    
    (void)memset_s(namebuf,VIF_NAME_LENGTH,0,VIF_NAME_LENGTH);
    /*if has bond0:0 br0:0  muti ip Etc,you should get bond0 br0 name*/
    if(NULL != strstr(vifname, ":"))
    {
        while(*vifname != ':')
        {
            namebuf[i++] = *vifname;
            vifname++;
        }
        namebuf[i] = '\0';
        vifnamebuf = namebuf;
    }
    
    /*vlan*/
    if(!access(vlan_path,0))
    {
        if(NULL == (file = opendevfile(vlan_path)))
        {
            DEBUG_LOG("Failed to open /proc/net/vlan/config.");
            vlanfile_flag = 0;
        }

        vifnamelen = strlen(vifnamebuf);
        if(1 == vlanfile_flag)
        {
            /*if has vlan, then query /proc/net/vlan/config to get interface name*/
			/*lint -e668 */ 
            while (fgets(pline, 128, file))
            {
                begin = pline;
                /*skip blank*/
                while (' ' == *begin)  begin++;
                /*if find matched name,then vlan_flag = 1 and break*/
                if (0 == strncmp(begin, vifnamebuf, vifnamelen))
                {
                    if (' ' == *(begin + vifnamelen)  )
                    {
                        vlan_flag = 1;
                        break;
                    }
                }
                /*init pline 0*/
                memset_s(pline, 128, 0, 128);
            }
			/*lint +e668 */ 
            fclose(file);
        }
    }

    /*assemble bond path*/
    snprintf_s(bond_path,BONDBRIDGE_PATH_LEN,BONDBRIDGE_PATH_LEN,"/proc/net/bonding/%s",vifnamebuf);
    if(!access(bond_path,0))
    {
        bond_flag = 1;
    }

    /*assemble bridge path*/
    snprintf_s(bridge_path,BONDBRIDGE_PATH_LEN,BONDBRIDGE_PATH_LEN,"/sys/class/net/%s/bridge",vifnamebuf);
    if(!access(bridge_path,0))
    {
        bridge_flag = 1;
    }
    
    /*if has vlan and status is down, then vlan_flag=2*/
    if(vlan_flag == 1 && DOWNFLAG == GetVifFlag(skt, vifnamebuf))
    {
        vlan_flag = 2;
    }
    

    if(UPFLAG == GetVifFlag(skt, vifnamebuf))
    {
        /*status:  bond upflag:2, vlan upflag:3, normal NIC upflag:1,bridge upflag:4*/
        if(1 == bond_flag)
        {
                gtNicIpv6Info.info[gtNicIpv6Info.count].netstatusflag = 2;
        }
        else if(1 == vlan_flag)
        {
                gtNicIpv6Info.info[gtNicIpv6Info.count].netstatusflag = 3;
        }
        else if(1 == bridge_flag)
        {
                gtNicIpv6Info.info[gtNicIpv6Info.count].netstatusflag = 4;
        }
        else
        {
                gtNicIpv6Info.info[gtNicIpv6Info.count].netstatusflag = 1;
        }
    }
    else
    {
        /*status:  bond/vlan/bridge downflag:9, normal NIC downflag:0*/
        if(1 == bond_flag || vlan_flag == 2 || 1 == bridge_flag)
        {
            gtNicIpv6Info.info[gtNicIpv6Info.count].netstatusflag = 9;
        }
        else
        {
            gtNicIpv6Info.info[gtNicIpv6Info.count].netstatusflag = 0;
        }
    }
}
コード例 #26
0
ファイル: netinfo.c プロジェクト: UVP-Tools/UVP-Tools
/*****************************************************************************
Function   : GetIpv6Flux
Description: get Ipv4/6 Flux
Input       : None
Output     : None
Return     : 
*****************************************************************************/
int GetIpv6Flux(int skt,char *ifname)
{
    char Sent[PACKAGE_LENGTH] = {0};
    char Recived[PACKAGE_LENGTH] = {0};
    char SentPkt[PACKAGE_LENGTH] = {0};
    char RecivedPkt[PACKAGE_LENGTH] = {0};
    char SentPktDrop[PACKAGE_LENGTH] = {0};
    char RecivedPktDrop[PACKAGE_LENGTH] = {0};
    char *ptmp = NULL;
    /*get flux info line*/
    char fluxline[255] = {0};
    /* get vifname info line*/
    char *vifline = NULL;
    size_t linelen = 0;
    char *foundStr = NULL;
    FILE *file;
    char *path="/proc/net/dev";
    char *namebuf = NULL;
    char *p = NULL;
    int ifnamelen = 0;

    
    if(NULL == (file = opendevfile(path)))
    {
        DEBUG_LOG("Failed to open /proc/net/dev.");
        return ERROR;
    }
    if (NULL == ifname)//for pclint warning
    {
        DEBUG_LOG("ifname is NULL.");
        fclose(file);
        return ERROR;
    }
    
    /*multi ip: such as eth0:0, you should match eth0 flux*/
    if (getline(&vifline, &linelen, file) == -1 /* eat line */
        || getline(&vifline, &linelen, file) == -1) {}
    while (getline(&vifline, &linelen, file) != -1)
    {
        (void)GetVifName(&namebuf, vifline);
        ifnamelen = strlen(namebuf);
        /*consider this scene: such as ifname = "eth10:0" namebuf="eth1"  and ifname = "eth1:0" namebuf="eth1"*/
        if(NULL != strstr(ifname,namebuf) && NULL != strstr(ifname,":"))
         {
                p = ifname + ifnamelen;
                if(':' == *p)
                {
                    ifname = namebuf;
                    break;
                }
         }
         
    } 
    
    /*get flux line*/
    if (ERROR == getFluxinfoLine(ifname, fluxline))
    {
        strncpy_s(gtNicIpv6Info.info[gtNicIpv6Info.count].tp, IPV6_FLUX_LEN, ERR_STR, strlen(ERR_STR));
        gtNicIpv6Info.info[gtNicIpv6Info.count].tp[strlen(ERR_STR)] = '\0';
        DEBUG_LOG("getFluxinfoLine failed, ifname=%s.", ifname);
        fclose(file);
        return ERROR;
    }

    if(0 == strlen(fluxline))
    {
        DEBUG_LOG("Line is NULL.");
        fclose(file);
        return ERROR;
    }

    foundStr = strstr(fluxline, ifname);
    if (NULL == foundStr)
    {
        DEBUG_LOG("foundStr is NULL, fluxline=%s, ifname=%s.", fluxline, ifname);
        fclose(file);
        return ERROR;
    }
    /*get first data*/
    ptmp = foundStr + strlen(ifname) + 1;


    if (NULL == ptmp)
    {
        DEBUG_LOG("ptmp is NULL.");
        fclose(file);
        return ERROR;
    }

    /*get each column data info*/
    if(ERROR == getVifData(ptmp, 1, Recived)
            || ERROR ==  getVifData(ptmp, 2, RecivedPkt)
        || ERROR == getVifData(ptmp, 4, RecivedPktDrop)
            || ERROR == getVifData(ptmp, 9, Sent)
            || ERROR == getVifData(ptmp, 10, SentPkt)
            || ERROR == getVifData(ptmp, 12, SentPktDrop))
    {
        DEBUG_LOG("getVifData is ERROR.");
        fclose(file);
        return ERROR;
    }

    (void)snprintf_s(gtNicIpv6Info.info[gtNicIpv6Info.count].tp, 
                    sizeof(gtNicIpv6Info.info[gtNicIpv6Info.count].tp), 
                    sizeof(gtNicIpv6Info.info[gtNicIpv6Info.count].tp), 
                    "%s:%s", 
                    Sent, Recived);
    gtNicIpv6Info.info[gtNicIpv6Info.count].tp[strlen(Sent) + strlen(Recived) + 1] = '\0';

    (void)snprintf_s(gtNicIpv6Info.info[gtNicIpv6Info.count].packs, 
                    sizeof(gtNicIpv6Info.info[gtNicIpv6Info.count].packs), 
                    sizeof(gtNicIpv6Info.info[gtNicIpv6Info.count].packs), 
                    "%s:%s",
                    SentPkt, RecivedPkt);
    gtNicIpv6Info.info[gtNicIpv6Info.count].packs[strlen(SentPkt) + strlen(RecivedPkt) + 1] = '\0';
    
    /*networkloss*/
    (void)sscanf_s(SentPktDrop,"%ld", &gtNicIpv6Info.info[gtNicIpv6Info.count].sentdrop);
    (void)sscanf_s(RecivedPktDrop,"%ld",&gtNicIpv6Info.info[gtNicIpv6Info.count].recievedrop);
    fclose(file);
    free(vifline);
    return SUCC;
}
コード例 #27
0
ファイル: netinfo.c プロジェクト: UVP-Tools/UVP-Tools
/*****************************************************************************
Function   : GetIpv6VifIp
Description: get Ipv6 ip info
Input       : None
Output     : None
Return     : 
*****************************************************************************/
int GetIpv6VifIp(int skt,int num, char *vifname)
{
   char *path="/proc/net/if_inet6";
   FILE *file;
   char addr6p[8][5] = {0};
   char devname[20] = {0};
   char *line = NULL;
   char addr6[40] = {0};
   size_t linelen = 0;
   int plen, scope, dad_status, if_idx;
   struct sockaddr_in6 sap;
   char *abbreviationIpv6 = NULL;


   if(NULL == vifname)
   {
           return ERROR;
   }

   /*if no support ipv6, return error*/
   if(0 != access(path,F_OK))
   {
        return ERROR;
   }
	
   if(NULL == (file = opendevfile(path)))
   {
        DEBUG_LOG("Failed to open /proc/net/if_inet6.");
        return ERROR;
   }

   
   /*query /proc/net/if_inet6 to get ipv6 info*/
   while(getline(&line, &linelen, file) != -1)
   {
        (void)memset_s(devname,20,0,20);
        sscanf_s(line, "%4s%4s%4s%4s%4s%4s%4s%4s %02x %02x %02x %02x %20s\n",
                      addr6p[0], sizeof(addr6p[0]), addr6p[1], sizeof(addr6p[1]),
                      addr6p[2], sizeof(addr6p[2]), addr6p[3], sizeof(addr6p[3]),
                      addr6p[4], sizeof(addr6p[4]), addr6p[5], sizeof(addr6p[5]),
                      addr6p[6], sizeof(addr6p[6]), addr6p[7], sizeof(addr6p[7]),
                      &if_idx, &plen, &scope, &dad_status, devname, sizeof(devname));
        /*do not modify strcmp -> strncmp*/
        if(0 == strcmp(devname,vifname) && (scope == 0 || scope == IPV6_ADDR_LINKLOCAL || scope == IPV6_ADDR_SITELOCAL || scope == IPV6_ADDR_COMPATv4))
        {
            snprintf_s(gtNicIpv6Info.info[gtNicIpv6Info.count].ifname, VIF_NAME_LENGTH, VIF_NAME_LENGTH, "%s", vifname);
            snprintf_s(addr6, IPV6_ADDR_LEN, IPV6_ADDR_LEN, "%s:%s:%s:%s:%s:%s:%s:%s",
                            addr6p[0], addr6p[1], addr6p[2], addr6p[3],
                            addr6p[4], addr6p[5], addr6p[6], addr6p[7]);
            /*abbreviation Ipv6 info*/
            Inet6Input(1, addr6, (struct sockaddr *) &sap);
            abbreviationIpv6 = Inet6Sprint((struct sockaddr *) &sap, 1);
            snprintf_s(gtNicIpv6Info.info[gtNicIpv6Info.count].ipaddr, IPV6_ADDR_LEN, IPV6_ADDR_LEN,
                        "%s", abbreviationIpv6);
            
            GetIpv6VifMac(skt,vifname);

            /*gw info has switch function*/
            if(g_exinfo_flag_value & EXINFO_FLAG_GATEWAY)
            {
                GetIpv6VifGateway(skt,vifname);
            }
            else
            {
                (void)strncpy_s(gtNicIpv6Info.info[gtNicIpv6Info.count].gateway,
                    IPV6_ADDR_LEN,
                    "0", 
                    strlen("0"));
            }
            gtNicIpv6Info.info[gtNicIpv6Info.count].ipversionflag = 6;
            GetIpv6Flux(skt,vifname);
            GetIpv6NetFlag(skt,vifname);
            num++;
            gtNicIpv6Info.count = num;
        }
    }
   fclose(file);
   free(line);
   return gtNicIpv6Info.count;
}
コード例 #28
0
ファイル: netinfo.c プロジェクト: UVP-Tools/UVP-Tools
/*****************************************************************************
Function   : GetIpv6Info
Description: get Ipv4/6 info
Input       : None
Output     : None
Return     : 
*****************************************************************************/
int GetIpv6Info()
{
    struct ifconf ifconfigure;
    struct ifreq *ifreqIdx;
    struct ifreq *ifreq;
    char *path="/proc/net/dev";
    FILE *file;
    char *line = NULL;
    size_t linelen = 0;
    char namebuf[16] = {0};
    char buf[4096] = {0};
    int uNICCount = 0;
    int num = 0;
    int i = 0;
    int novifnameFlag = 0;
    int lastcount = 0;
    int getipv6flag = 0;
    int vifnameLen = 0;
    int skt;

    
    ifconfigure.ifc_len = 4096;
    ifconfigure.ifc_buf = buf;
    
    skt = openNetSocket(); 
    if (ERROR == skt)
    {
        DEBUG_LOG("Failed to openNetSocket.");
        return ERROR;
    }
    memset_s(&gtNicIpv6Info, sizeof(gtNicIpv6Info), 0, sizeof(gtNicIpv6Info)); 


    /*ioctl interface: interface has ipv4 and its status is up*/
    if(!ioctl(skt, SIOCGIFCONF, (char *) &ifconfigure))
    {
        ifreq = (struct ifreq *)buf;
        uNICCount = ifconfigure.ifc_len / (int)sizeof(struct ifreq);
        for(i=0; i<uNICCount; i++)
        {
            int nicRepeatFlag = 0;
            int j = 0;
            ifreqIdx = ifreq + i;
            memset_s(namebuf, 16, 0, 16);
            (void)snprintf_s(namebuf, sizeof(namebuf), sizeof(namebuf), "%s", ifreqIdx->ifr_name);

            for(j = 0; num > 0 && j < num; j++)
            {
                /*do not modify strcmp -> strncmp*/
                if(0 == strcmp(namebuf, gtNicIpv6Info.info[j].ifname))
                {
                    nicRepeatFlag = 1;
                    break;
                }
            }

            vifnameLen = strlen(namebuf);
            if(nicRepeatFlag || 0 == strncmp(namebuf,"lo",vifnameLen) || 0 == strncmp(namebuf,"sit0",vifnameLen))
            {
                continue;
            }

            /*get ipv4 info */
            if(UPFLAG == GetVifFlag(skt, namebuf))
            {
                getipv6flag = GetIpv4VifIp(skt,num,namebuf);
                if(ERROR != getipv6flag)
                {
                    num = getipv6flag;
                }

                if(num >= IPV6_NIC_MAX)
                    break;
            }

            /*get ipv6 info, /proc/net/if_inet6: the interface status is up */
            getipv6flag = GetIpv6VifIp(skt,num,namebuf);
            if(ERROR != getipv6flag)
            {
               num = getipv6flag;
            }

            if(num >= IPV6_NIC_MAX)
                  break;

        }
    }
    
    /*patch interface by query /proc/net/dev*/ 
   if(NULL == (file = opendevfile(path)))
    {
        NetworkDestroy(skt);
        DEBUG_LOG("Failed to open /proc/net/dev.");
        return ERROR;
    }
    
   if(getline(&line, &linelen, file) == -1 /* eat line */
        || getline(&line, &linelen, file) == -1) {}
   while (getline(&line, &linelen, file) != -1)
    {
        novifnameFlag = 0;
        char *vifname;
        (void)GetVifName(&vifname, line);
        vifnameLen = strlen(vifname);
        if(0 == strncmp(vifname,"lo",vifnameLen) || 0== strncmp(vifname,"sit0",vifnameLen))
        {
           continue;
        }
        
        for(i=0;i<num;i++)
        {
           /*do not modify strcmp -> strncmp*/
           if(0 == strcmp(vifname,gtNicIpv6Info.info[i].ifname))
           {
                   /*has exist vifname*/
                novifnameFlag = 1;
           }
        }
        if(num >= IPV6_NIC_MAX)
                  break;
          /*new vifname*/
        if(novifnameFlag == 0)
        {
            /*if interface status is down, then xenstore info only has mac and its status*/
            if(DOWNFLAG == GetVifFlag(skt,vifname))
            {
                num++;
                GetIpv6VifMac(skt, vifname);
                GetIpv6NetFlag(skt,vifname);
                gtNicIpv6Info.count=num;

            }
            else
            {
                /*if interface status is up and no ip, then xenstore info has mac,staus,ip(none),gw,flux*/
                /*if interface status is up and has ipv6 info,then xenstore info has mac,staus,ip6,gw,flux*/
                lastcount = gtNicIpv6Info.count;
                getipv6flag = GetIpv6VifIp(skt,num,vifname);
                if(ERROR != getipv6flag)
                {
                    num = getipv6flag;
                }
                if(num == lastcount)
                {
                    num++;
                    GetIpv6VifMac(skt, vifname);
                    gtNicIpv6Info.info[gtNicIpv6Info.count].gateway[0] = '\0';
                    (void)strncpy_s(gtNicIpv6Info.info[gtNicIpv6Info.count].ipaddr,
                        IPV6_ADDR_LEN, 
                        "none", 
                        strlen("none"));
                    gtNicIpv6Info.info[gtNicIpv6Info.count].ipaddr[sizeof(gtNicIpv6Info.info[gtNicIpv6Info.count].ipaddr)-1]='\0';
                    GetIpv6Flux(skt,vifname);

                    if(g_exinfo_flag_value & EXINFO_FLAG_GATEWAY)
                    {
                        GetIpv4VifGateway(skt,vifname);
                    }
                    else
                    {
                        (void)strncpy_s(gtNicIpv6Info.info[gtNicIpv6Info.count].gateway, 
                            IPV6_ADDR_LEN, 
                            "0", 
                            strlen("0"));
                    }
                    GetIpv6NetFlag(skt,vifname);
                    gtNicIpv6Info.count =num;
                }
                else
                {
                    gtNicIpv6Info.count =num;
                }
            }

        }
    }
   fclose(file);
   free(line);
   NetworkDestroy(skt);
   return gtNicIpv6Info.count; 
}
コード例 #29
0
ファイル: cpu_hotplug.c プロジェクト: UVP-Tools/UVP-Tools
/*****************************************************************************
 Function   : do_cpu_online
 Description: update cpu to online and wrtie state into xenstore
 Input      : handle -- xenbus file handle
 Output     : None
 Return     : XEN_SUCC or XEN_ERROR
 *****************************************************************************/
int DoCpuHotplug(void * phandle)
{
    char pszBuff[1024] = {0};
    char pszCommand[1024] = {0};
    int  i = 0;
    int  cpu_enable_num = 0;
    int  cpu_nr = 0;
    char *cpu_online = NULL;
    int  idelay = 0;
    int  ret = -1;
    int  rc = -1;

    cpu_nr = GetSupportMaxnumCpu();
    if (cpu_nr <= 0)
    {
        INFO_LOG("This OS has unexpectable cpus: %d.", cpu_nr);
        goto out;
    }

    INFO_LOG("This OS has cpu hotplug and less than %d.", cpu_nr);

    /* obtain cpu numbers */
    for(i = 0; i <= cpu_nr - 1; i++)
    {
        (void)snprintf_s(pszCommand, 1024, 1024, "cpu/%d/availability", i);
        cpu_online = read_from_xenstore(phandle, pszCommand);
        if((NULL != cpu_online) && (0 == strcmp(cpu_online, "online")))
        {
            cpu_enable_num ++;
        }
        free(cpu_online);
        cpu_online = NULL;
    }

    i = 1;

    /* loop for upgrade cpu online */
    while (i < cpu_enable_num )
    {
        if (idelay >= 300)
        {
            i ++;
            idelay = 0;
            continue;
        }

        (void)memset_s(pszCommand, 1024, 0, 1024);
        (void)memset_s(pszBuff, 1024, 0, 1024);
        (void)snprintf_s(pszCommand, 1024, 1024,
            "if [ -d \"/sys/devices/system/cpu/cpu%d\" ]; then \n  printf \"online\" \nfi", i);

        ret = uvpPopen(pszCommand, pszBuff, 1024);

        if (0 != ret)
        {
            ERR_LOG("Failed to call uvpPopen, ret=%d.", ret);
            idelay++;
            uvp_sleep();
            continue;
        }

        if (0 != strcmp("online", pszBuff))
        {
            idelay++;
            uvp_sleep();
            continue;
        }

        /*  判断cpu当前是否online */
        (void)memset_s(pszCommand, 1024, 0, 1024);
        (void)memset_s(pszBuff, 1024, 0, 1024);
        (void)snprintf_s(pszCommand, 1024, 1024, "cat /sys/devices/system/cpu/cpu%d/online", i);
        ret = uvpPopen(pszCommand, pszBuff, 1024);

        if (0 != ret)
        {
            ERR_LOG("Failed to call uvpPopen, ret=%d.", ret);
            idelay++;
            uvp_sleep();
            continue;
        }

        if ('1' == pszBuff[0])
        {
            INFO_LOG("Cpu%d is always online.", i);
            i++;
            idelay = 0;
            continue;
        }
        (void)memset_s(pszCommand, 1024, 0, 1024);
        (void)memset_s(pszBuff, 1024, 0, 1024);
        (void)snprintf_s(pszCommand, 1024, 1024, "echo 1 > /sys/devices/system/cpu/cpu%d/online", i);

        ret = uvpPopen(pszCommand, pszBuff, 1024);
        if (0 != ret)
        {
            ERR_LOG("Failed to call uvpPopen, ret=%d.", ret);
            idelay++;
            uvp_sleep();
            continue;
        }

        idelay = 0;
        i++;
    }

    rc = XEN_SUCC;

out:
    (void)write_to_xenstore(phandle, CPU_HOTPLUG_STATE, "0");
    (void)write_to_xenstore(phandle, CPU_HOTPLUG_SIGNAL, "0");
    return rc;
}