Example #1
0
void init_system(int action)
{
	int index=0;
	char tmpbuf[100];	

	system("echo 0 > /proc/gpio"); //mark_issue , disable gpio anytime ?
    //kill daemon
    kill_daemons();	
	
	//mark_mac , now , we dont support lan reopen
	//bring_down_lan();	
	
	bring_down_wlan();	
	
	// init wlan driver
	if ((action & INIT_WLAN_PHY))
	{
		for(index=0; index<get_vap_num()+1; index++)
			initWlan(index,fecth_wlanmib(index),fecth_hwmib());

		if( get_sys_mode() == REPEATER_AP_MODE ) //mark_issue , to do Client mode??
			initWlan(WLAN_VXD_INDEX,fecth_wlanmib(WLAN_VXD_INDEX),fecth_hwmib());		
	}		
	//-----------------------------------------------
	init_vlan(); 	

	bring_up_wlan();

	sprintf(tmpbuf, "%s %s hw ether %s ", IFCONFG, IF_BR,INBAND_MAC); 
	system(tmpbuf);

#ifdef RTK_WPS_BRIDGE_HACK
	init_host_info();
#endif

	active_daemons();
}
Example #2
0
void
read_apache_stats(struct module *mod)
{
    int fd, n, m, sockfd, send, pos;
    char buf[LEN_4096] = {0}, request[LEN_4096], line[LEN_4096],
         buff[LEN_4096];
    memset(buf, 0, LEN_4096);
    struct sockaddr_in servaddr;
    FILE *stream = NULL;
    /* FIX me */
    char *cmd = "server-status?auto";
    struct stats_apache st_apache;
    memset(&st_apache, 0, sizeof(struct stats_apache));
    struct hostinfo hinfo;

    if ((fd = open(APACHERT, O_RDONLY , 0644)) < 0 ){
        return;
    }
    sockfd = socket(AF_INET, SOCK_STREAM, 0);
    if (sockfd < 0) {
        goto last;
    }
    if ((n = read(fd, buff, 16)) != 16) {
        goto last;
    }
    st_apache.query = * (unsigned long long *)buff;
    st_apache.response_time = * (unsigned long long *)&buff[8];
    /*fullfil another member int the structure*/
    init_host_info(&hinfo);
    bzero(&servaddr, sizeof(servaddr));
    servaddr.sin_family = AF_INET;
    servaddr.sin_port = htons(hinfo.port);
    inet_pton(AF_INET, hinfo.host, &servaddr.sin_addr);
    sprintf(request,
            "GET /%s HTTP/1.0\r\n"
            "User-Agent: Wget/1.9\r\n"
            "Host: %s\r\n"
            "Accept:*/*\r\n"
            "Connection: Close\r\n\r\n",
            cmd, hinfo.host);

    if ((m = connect(sockfd, (struct sockaddr *) &servaddr,
                    sizeof(servaddr))) == -1 ) {
        goto writebuf;
    }

    if ((send = write(sockfd, request, strlen(request))) == -1) {
        goto writebuf;
    }
    stream = fdopen(sockfd, "r");
    if (!stream) {
        goto last;
    }
    while(fgets(line, LEN_4096, stream) != NULL) {
        if(!strncmp(line, "Total kBytes:", 13)) {
            sscanf(line + 14, "%llu", &st_apache.kBytes_sent);

        } else if (!strncmp(line, "BusyWorkers:", 12)) {
            sscanf(line + 13, "%d", &st_apache.busy_proc);

        } else if (!strncmp(line, "IdleWorkers:", 12)) {
            sscanf(line + 13, "%d", &st_apache.idle_proc);

        } else {
            ;
        }
        memset(line, 0, LEN_4096);
    }
writebuf:
    pos = sprintf(buf, "%lld,%lld,%lld,%d,%d",
            st_apache.query,
            st_apache.response_time / 1000,
            st_apache.kBytes_sent,
            st_apache.busy_proc,
            st_apache.idle_proc);
    buf[pos] = '\0';
    if (stream) {
        if (fclose(stream) < 0) {
            goto last;
        }
    }
    set_mod_record(mod, buf);
last:
    close(fd);
    if (sockfd) {
        close(sockfd);
    }
    free(hinfo.host);
}