Пример #1
0
static int
refresh_net_dev_sysfs(char *name, net_interface_t *netip, int *need_refresh)
{
    char path[MAXPATHLEN];
    char line[64];
    char *value;

    if (need_refresh[REFRESH_NET_SPEED]) {
	snprintf(path, sizeof(path), "%s/sys/class/net/%s/speed",
		linux_statspath, name);
	path[sizeof(path)-1] = '\0';
	value = read_oneline(path, line);
	if (value == NULL)
	    return PM_ERR_AGAIN;	/* no sysfs, try ioctl */
	netip->ioc.speed = atoi(value);
    }
    if (need_refresh[REFRESH_NET_MTU]) {
	snprintf(path, sizeof(path), "%s/sys/class/net/%s/mtu",
		linux_statspath, name);
	path[sizeof(path)-1] = '\0';
	value = read_oneline(path, line);
	if (value == NULL)
	    return PM_ERR_AGAIN;	/* no sysfs, try ioctl */
	netip->ioc.mtu = atoi(value);
    }
    if (need_refresh[REFRESH_NET_LINKUP] ||
	need_refresh[REFRESH_NET_RUNNING]) {
	snprintf(path, sizeof(path), "%s/sys/class/net/%s/flags",
		linux_statspath, name);
	path[sizeof(path)-1] = '\0';
	value = read_oneline(path, line);
	if (value == NULL)
	    return PM_ERR_AGAIN;	/* no sysfs, try ioctl */
	else {
	    unsigned long flags = strtoul(value, &value, 16);
	    netip->ioc.linkup = !!(flags & IFF_UP);
	    netip->ioc.running = !!(flags & IFF_RUNNING);
	}
    }
    if (need_refresh[REFRESH_NET_DUPLEX]) {
	snprintf(path, sizeof(path), "%s/sys/class/net/%s/duplex",
		linux_statspath, name);
	path[sizeof(path)-1] = '\0';
	value = read_oneline(path, line);
	if (value == NULL)
	    netip->ioc.duplex = 0;
	else if (strcmp(value, "half") == 0)
	    netip->ioc.duplex = 1;
	else if (strcmp(value, "full") == 0)
	    netip->ioc.duplex = 2;
    }
    return 0;
}
Пример #2
0
static int check_prog(void) {
        DIR *dir;
        struct dirent *entry;
        char *name;
        char *status_tail;
        int pid;
        struct stat sb;
        int n;
        char status[32];
        char buf[1023];
        char cmd[16], scmd[16];
	char str[1024];
	if((dir = opendir("/proc")) == NULL) return(1);
        for(;;) {
                if((entry = readdir(dir)) == NULL) {
                        closedir(dir);
                        return(0);
                }
                name = entry->d_name;
                if (!(*name >= '0' && *name <= '9')) continue;
                pid = atoi(name);
                status_tail = status + sprintf(status, "/proc/%d", pid);
                if(stat(status, &sb)) continue;
                strcpy(status_tail, "/stat");
                n = read_oneline(status, buf);
                if(n < 0) continue;
                sscanf(buf, "%*s (%15c)", cmd);
		splitc(scmd,cmd,')');
		sprintf(str,"%s ",scmd);
                strcpy(status_tail, "/cmdline");
		n = read_oneline(status, buf);
                if(n > 0) {
                        if(buf[n-1]=='\n')  buf[--n] = 0;
                        name = buf;
                        while(n) {
                                if(((unsigned char)*name) < ' ') *name = ' ';
                                name++;
                                n--;
                        }
                        *name = 0;
                        if(buf[0]) sprintf(str,"%s %s ",str, strdup(buf));
                }
		trim(str);
		if(strstr(str,"taskq-check")) {
			taskq=1;
			continue;
		} 
		set_check(str);
        }
        return(0);
}
Пример #3
0
static int check_config(void) {
        DIR *dir;
        struct dirent *entry;
        char *name;
        int n;
        struct stat sb;
        char status[32];
        char buf[1023];
	listcnt=0;
        if((dir = opendir(DIRCHECK)) == NULL) return(1);
        for(;;) {
                if((entry = readdir(dir)) == NULL) {
                        closedir(dir);
                        return(1);
                }
                name = entry->d_name;
                if(!strcmp(name,".") || !strcmp(name,"..")) continue;
                sprintf(status, "%s/%s", DIRCHECK, name);
                if(stat(status, &sb)) continue;
                if(read_oneline(status, buf) < 0) continue;
                trim(buf);trim(name);
                set_config(name,buf,listcnt);
                listcnt++;
        }
        return(0);
}
Пример #4
0
static void
refresh_net_hw_addr(char *name, net_addr_t *netip)
{
    char path[MAXPATHLEN];
    char line[64];
    char *value;

    snprintf(path, sizeof(path), "%s/sys/class/net/%s/address",
		linux_statspath, name);
    path[sizeof(path)-1] = '\0';
    value = read_oneline(path, line);
    if (value) {
	netip->has_hw = 1;
	strncpy(netip->hw_addr, value, sizeof(netip->hw_addr));
	netip->hw_addr[sizeof(netip->hw_addr)-1] = '\0';
    } else {
	netip->hw_addr[0] = '\0';
    }
}
Пример #5
0
static void read_cmdline(void) {
	char buf[550], name[150];
	char **xchargv;
	int n, k;
	read_oneline("/proc/cmdline",buf);
	trim(buf);
	if(split_array(buf," ",&chargv) > 0) {
		k=numtokens;
		for(n=0;n < k; n++) {
			memset(name,0x0,sizeof(name));
			snprintf(name,sizeof(name),"%s",chargv[n]);
			if(split_array(name,"=",&xchargv) > 0) {
				if(xchargv[0]!=NULL && xchargv[1]!=NULL) {
					if(!strcmp(xchargv[0],"dev_boot")) {
						splitc(BOOT_DEV,xchargv[1],':');
						strcpy(BOOT_FS,xchargv[1]);
					} else if(!strcmp(xchargv[0],"dev_strg")) {
						splitc(STRG_DEV,xchargv[1],':');
						strcpy(STRG_FS,xchargv[1]);
					} else if(!strcmp(xchargv[0],"dev_swap")) {
						splitc(SWAP_DEV,xchargv[1],':');
					} else if(!strcmp(xchargv[0],"keymap")) {
						strcpy(KEY_MAP,xchargv[1]);
					} else if(!strcmp(xchargv[0],"dev_lcd")) {
						strcpy(LCD_DEV,xchargv[1]);
						trim(LCD_DEV);
					} else if(!strcmp(xchargv[0],"lcdprog")) {
						LCD_PROG=atoi(xchargv[1]);						
					} else if(!strcmp(xchargv[0],"numnet")) {
						NUM_NET=atoi(xchargv[1]);
					}
				}
			}
		}
	}
}
Пример #6
0
procps_status_t * procps_scan(int dotask) {
	static DIR *dir;
	struct dirent *entry;
	static procps_status_t ret_status;
	char *name;
	int n;
	char status[32];
	char *status_tail;
	char buf[1024];
	procps_status_t curstatus;
	int pid;
	long tasknice;
	struct stat sb;

	if(!dir) {
                dir=opendir("/proc");
        }
	for(;;) {
		if((entry = readdir(dir)) == NULL) {
			closedir(dir);
			dir = 0;
			return 0;
		}
		name = entry->d_name;
		if(!(*name >= '0' && *name <= '9')) continue;

		memset(&curstatus, 0, sizeof(procps_status_t));
		pid = atoi(name);
		curstatus.pid = pid;

		status_tail = status + sprintf(status, "/proc/%d", pid);
		if(stat(status, &sb)) continue;
		strcpy(status_tail, "/stat");
		n = read_oneline(status, buf);
		if(n < 0) continue;
		name = strrchr(buf, ')');
		if(name == 0 || name[1] != ' ') continue;
		*name = 0;
		sscanf(buf, "%*s (%15c", curstatus.short_cmd);
		n = sscanf(name+2,
		"%c %d "
		"%*s %*s %*s %*s "     /* pgrp, session, tty, tpgid */
		"%*s %*s %*s %*s %*s " /* flags, min_flt, cmin_flt, maj_flt, cmaj_flt */
		"%lu %lu "             /* utime, stime */
		"%*s %*s %*s "         /* cutime, cstime, priority */
		"%ld "                 /* nice */
		"%*s %*s %*s "         /* timeout, it_real_value, start_time */
		"%*s "                 /* vsize */
		"%ld",                 /* rss */
		curstatus.state, &curstatus.ppid,
		&curstatus.utime, &curstatus.stime,
		&tasknice,
                &curstatus.rss);

		if(n != 6)
			continue;

		// paging (not valid since the 2.6.xx kernel)
		//if (curstatus.rss == 0 && curstatus.state[0] != 'Z')
		//	curstatus.state[1] = 'W';
		//else
		//curstatus.state[1] = '';
		if (tasknice < 0) {
			curstatus.state[1] = '<';
		} else if(tasknice > 0) {
			curstatus.state[1] = 'N';
		} else {
			curstatus.state[1] = ' ';
		}
		curstatus.state[2]=' ';
		curstatus.state[3]=' ';
		curstatus.rss *= (getpagesize() >> 10);     /* 2**10 = 1kb */

		if(dotask==1) {
			strcpy(status_tail, "/cmdline");
			n = read_oneline(status, buf);
			if(n > 0) {
				if(buf[n-1]=='\n')
					buf[--n] = 0;
				name = buf;
				while(n) {
					if(((unsigned char)*name) < ' ')
						*name = ' ';
					name++;
					n--;
				}
				*name = 0;
				if(buf[0])
					curstatus.cmd = strdup(buf);
				/* if NULL it work true also */
			}
		}
		return memcpy(&ret_status, &curstatus, sizeof(procps_status_t));
	}
}