/* * * commands for variables * */ void do_esay(COMMAND_ARGS) { /* * on_msg checks CAXS + CARGS */ char output[MSGLEN]; char c,*chp; int i,n; ec_end = output + MSGLEN - 20; ec_src = rest; rest = STREND(rest); ec_dest = output; c = 0; chp = NULL; while(*ec_src) { if (*ec_src != '$') { *(ec_dest++) = *(ec_src++); continue; } for(i=0;ecmd[i].len;i++) { if ((rest - ec_src) >= ecmd[i].len) { chp = ec_src + ecmd[i].len; c = *chp; *chp = 0; } n = Strcasecmp(ecmd[i].name,ec_src); if (c) { *chp = c; c = 0; } if (!n) { ec_src += ecmd[i].len; ecmd[i].func(from,to); break; } } if (!ecmd[i].len) { *(ec_dest++) = *(ec_src++); } } *ec_dest = 0; to_user_q(from,FMT_PLAIN,output); }
/* help:CPUINFO:(no arguments) See also: hostinfo, meminfo */ void do_cpuinfo(COMMAND_ARGS) { char bogostr[64],cpustr[64]; char *a1,*a2,*a3,*dst; int fd,n; #ifdef DEVELOPING a1 = chop(&rest); if (a1) sprintf(bogostr,"/home/git/cpuinfo/%s",a1); else stringcpy(bogostr,"/proc/cpuinfo"); if ((fd = open(bogostr,O_RDONLY)) < 0) // if ((fd = open("/home/git/cpuinfo/mips3",O_RDONLY)) < 0) // if ((fd = open("/home/git/cpuinfo/mips2",O_RDONLY)) < 0) // if ((fd = open("/home/git/cpuinfo/mips1",O_RDONLY)) < 0) // if ((fd = open("/home/git/cpuinfo/intel1",O_RDONLY)) < 0) // if ((fd = open("/home/git/cpuinfo/cosmiccow",O_RDONLY)) < 0) #endif if ((fd = open("/proc/cpuinfo",O_RDONLY)) < 0) #ifdef DEBUG { debug("(do_cpuinfo) /proc/cpuinfo: %s\n",strerror(errno)); return; } #else return; #endif global_from = from; havemodel = bogo = siblings = procct = cpus = cores = physid = 0; omni[1] = 0; readline(fd,&parse_proc_cpuinfo); // readline closes fd if ((fd = open("/proc/loadavg",O_RDONLY)) < 0) #ifdef DEBUG { debug("(do_cpuinfo) /proc/loadavg: %s\n",strerror(errno)); return; } #else return; #endif n = read(fd,globaldata,MSGLEN-2); globaldata[n] = 0; close(fd); rest = globaldata; a1 = chop(&rest); a2 = chop(&rest); a3 = chop(&rest); if (!a3 || !*a3) return; #ifdef DEBUG debug("(do_cpuinfo) procct %i, physid %i, cores %i, bogo %i\n",procct,physid,cores,bogo); #endif if (cores == 0) cores = bogo; if (cores && physid && (physid % cores) == 0) cpus = (physid / cores)-1; if (cores && (cpus == 0 || physid == cores)) cpus = 1; *bogostr = 0; *cpustr = 0; if (bogo) sprintf(bogostr,", %s BogoMips",vmlib); if (cpus > 1 || (cores > cpus)) { sprintf(cpustr,", %i physical cpu%s",cpus,(cpus == 1) ? "" : "s"); if (cores) sprintf(STREND(cpustr),", %i core%s",cores,(cores == 1) ? "" : "s"); } to_user_q(from,"%s%s%s, loadavg: %s(1m) %s(5m) %s(15m)", omni+1,bogostr,cpustr,a1,a2,a3); }