static void mpoverride(uchar** newp, uchar** e) { int size, i, j; char buf[20]; uchar* p; char* s; size = atoi(getconf("*mp")); if(size == 0) panic("mpoverride: invalid size in *mp"); *newp = p = xalloc(size); if(p == nil) panic("mpoverride: can't allocate memory"); *e = p + size; for(i = 0; ; i++){ snprint(buf, sizeof buf, "*mp%d", i); s = getconf(buf); if(s == nil) break; while(*s){ j = strtol(s, &s, 16); if(*s && *s != ' ' || j < 0 || j > 0xff) panic("mpoverride: invalid entry in %s", buf); if(p >= *e) panic("mpoverride: overflow in %s", buf); *p++ = j; } } if(p != *e) panic("mpoverride: size doesn't match"); }
static int identify(void) { char *cp; _MP_ *_mp_; if((cp = getconf("*nomp")) != nil && strcmp(cp, "0") != 0) return 1; /* * Search for an MP configuration table. For now, * don't accept the default configurations (physaddr == 0). * Check for correct signature, calculate the checksum and, * if correct, check the version. * To do: check extended table checksum. */ if((_mp_ = sigsearch("_MP_")) == 0 || checksum(_mp_, _MP_sz) || (_mp_->physaddr == 0)) return 1; pcmp = KADDR(_mp_->physaddr); if(memcmp(pcmp, "PCMP", 4) || checksum(pcmp, pcmp->length) || (pcmp->version != 1 && pcmp->version != 4)) { pcmp = nil; return 1; } if(m->havetsc && getconf("*notsc") == nil) archmp.fastclock = tscticks; return 0; }
void okay(int on) { static int first; static int okled, polarity; char *p; if(!first++){ p = getconf("bcm2709.disk_led_gpio"); if(p == nil) p = getconf("bcm2708.disk_led_gpio"); if(p != nil) okled = strtol(p, 0, 0); else okled = 'v'; p = getconf("bcm2709.disk_led_active_low"); if(p == nil) p = getconf("bcm2708.disk_led_active_low"); polarity = (p == nil || *p == '1'); if(okled != 'v') gpiofuncset(okled, Output); } if(okled == 'v') vgpset(0, on); else if(okled != 0) gpioout(okled, on^polarity); }
int main() { print_header(); #ifdef DEBIAN_BINARY getconf = getenvdeb; #else getconf = getenv; #endif char* envval; if (envval = getconf("PROTOCOL")) { if (strcmp(envval, "raw") == 0) { return tunmain_raw(); } else if (strcmp(envval, "nacl0") == 0) { return tunmain_nacl0(); } else if (strcmp(envval, "nacltai") == 0) { return tunmain_nacltai(); } else { fprintf(stderr, "Unknown protocol specified: %s\n", envval); return -1; } } else if (getconf("PRIVATE_KEY")) { return tunmain_nacl0(); } else { return tunmain_raw(); } }
void savedatabases(void *p) { int userdb, chandb; chandb = savechandb(getconf("chanfile", "ircbot.chanfile")); userdb = saveuserdb(getconf("userfile", "ircbot.userfile")); printlog("-- Saved %d channels and %d users", chandb, userdb); }
static int init_udp(struct qtsession* session) { char* envval; fprintf(stderr, "Initializing UDP socket...\n"); struct addrinfo *ai_local = NULL, *ai_remote = NULL; unsigned short af = 0; int ret; if (envval = getconf("LOCAL_ADDRESS")) { if (ret = getaddrinfo(envval, NULL, NULL, &ai_local)) return errorexit2("getaddrinfo(LOCAL_ADDRESS)", gai_strerror(ret)); if (!ai_local) return errorexit("LOCAL_ADDRESS lookup failed"); if (ai_local->ai_addrlen > sizeof(sockaddr_any)) return errorexit("Resolved LOCAL_ADDRESS is too big"); af = ai_local->ai_family; } if (envval = getconf("REMOTE_ADDRESS")) { if (ret = getaddrinfo(envval, NULL, NULL, &ai_remote)) return errorexit2("getaddrinfo(REMOTE_ADDRESS)", gai_strerror(ret)); if (!ai_remote) return errorexit("REMOTE_ADDRESS lookup failed"); if (ai_remote->ai_addrlen > sizeof(sockaddr_any)) return errorexit("Resolved REMOTE_ADDRESS is too big"); if (af && af != ai_remote->ai_family) return errorexit("Address families do not match"); af = ai_remote->ai_family; } if (!af) af = AF_INET; int sfd = socket(af, SOCK_DGRAM, IPPROTO_UDP); if (sfd < 0) return errorexitp("Could not create UDP socket"); sockaddr_any udpaddr; memset(&udpaddr, 0, sizeof(udpaddr)); udpaddr.any.sa_family = af; if (ai_local) memcpy(&udpaddr, ai_local->ai_addr, ai_local->ai_addrlen); int port = 2998; if (envval = getconf("LOCAL_PORT")) port = atoi(envval); if (sockaddr_set_port(&udpaddr, port)) return -1; if (bind(sfd, (struct sockaddr*)&udpaddr, sizeof(udpaddr))) return errorexitp("Could not bind socket"); memset(&udpaddr, 0, sizeof(udpaddr)); udpaddr.any.sa_family = af; if (ai_remote) memcpy(&udpaddr, ai_remote->ai_addr, ai_remote->ai_addrlen); if (!ai_remote || sockaddr_is_zero_address(&udpaddr)) { session->remote_float = 1; } else { session->remote_float = getconf("REMOTE_FLOAT") ? 1 : 0; port = 2998; if (envval = getconf("REMOTE_PORT")) port = atoi(envval); if (sockaddr_set_port(&udpaddr, port)) return -1; session->remote_addr = udpaddr; if (session->remote_float) { session->remote_float = 2; } else { if (connect(sfd, (struct sockaddr*)&udpaddr, sizeof(udpaddr))) return errorexitp("Could not connect socket"); } } if (ai_local) freeaddrinfo(ai_local); if (ai_remote) freeaddrinfo(ai_remote); session->fd_socket = sfd; return sfd; }
static void umbexclude(void) { int size; ulong addr; char *op, *p, *rptr; if((p = getconf("umbexclude")) == nil) return; while(p && *p != '\0' && *p != '\n'){ op = p; addr = strtoul(p, &rptr, 0); if(rptr == nil || rptr == p || *rptr != '-'){ print("umbexclude: invalid argument <%s>\n", op); break; } p = rptr+1; size = strtoul(p, &rptr, 0) - addr + 1; if(size <= 0){ print("umbexclude: bad range <%s>\n", op); break; } if(rptr != nil && *rptr == ',') *rptr++ = '\0'; p = rptr; mapalloc(&rmapumb, addr, size, 0); } }
void exit(int ispanic) { canlock(&active); active.machs &= ~(1<<m->machno); active.exiting = 1; unlock(&active); spllo(); print("cpu %d exiting\n", m->machno); do delay(100); while(consactive()); splhi(); delay(1000); /* give serial fifo time to finish flushing */ if (getconf("*debug") != nil) { USED(ispanic); delay(60*1000); /* give us time to read the screen */ } if(arch->coredetach) arch->coredetach(); setupboot(1); // set up to halt for (; ; ) firmware(); // on PC is just: //if (0) { // shutdown(ispanic); // arch->reset(); //} }
void uartconsinit(void) { Uart *uart; int n; char *p, *cmd; if((p = getconf("console")) == nil) return; n = strtoul(p, &cmd, 0); if(p == cmd) return; switch(n){ default: return; case 0: uart = &miniuart; break; } if(!uart->enabled) (*uart->phys->enable)(uart, 0); uartctl(uart, "b9600 l8 pn s1"); if(*cmd != '\0') uartctl(uart, cmd); consuart = uart; uart->console = 1; }
void confinit(void) { char *p; int pcnt; if(p = getconf("*kernelpercent")) pcnt = 100 - strtol(p, 0, 0); else pcnt = 0; conf.nscc = 4; conf.smcuarts = 1<<0; /* SMC1 (usual console) */ conf.sccuarts = 1<<1; /* SCC2 available by default */ archconfinit(); conf.npage = conf.npage0 + conf.npage1; if(pcnt < 10) pcnt = 70; conf.ialloc = (((conf.npage*(100-pcnt))/100)/2)*BY2PG; conf.nproc = 100 + ((conf.npage*BY2PG)/MB)*5; conf.nmach = MAXMACH; }
void i8250console(void) { Uart *uart; int n; char *cmd, *p; if((p = getconf("console")) == nil) return; n = strtoul(p, &cmd, 0); if(p == cmd) return; switch(n){ default: return; case 0: uart = &i8250uart[0]; break; case 1: uart = &i8250uart[1]; break; } uartctl(uart, "b9600 l8 pn s1"); if(*cmd != '\0') uartctl(uart, cmd); (*uart->phys->enable)(uart, 0); consuart = uart; uart->console = 1; }
static SDev* pnp(void) { int i, id; char *p; SDev *h, *t, *s; if((p = getconf("loopdev")) == 0) return 0; nprobe = tokenize(p, probef, nelem(probef)); h = t = 0; for(i = 0; i < nprobe; i++){ id = pnpprobeid(probef[i]); if(id == 0) continue; s = malloc(sizeof *s); if(s == nil) break; s->ctlr = 0; s->idno = id; s->ifc = &sdloopifc; s->nunit = 1; if(h) t->next = s; else h = s; t = s; } return h; }
static int drop_privileges() { char* envval; struct passwd *pw = NULL; if (envval = getconf("SETUID")) { pw = getpwnam(envval); if (!pw) return errorexitp("getpwnam"); } if (envval = getconf("CHROOT")) { if (chroot(envval)) return errorexitp("chroot"); if (chdir("/")) return errorexitp("chdir /"); } if (pw) { if (setgroups(0, NULL) == -1) return errorexitp("setgroups"); if (setgid(pw->pw_gid) == -1) return errorexitp("setgid"); if (setuid(pw->pw_uid) == -1) return errorexitp("setuid"); } }
static int sdinitpart(SDunit* unit) { int nf; uvlong start, end; char *f[4], *p, *q, buf[10]; if(unit->sectors > 0){ unit->sectors = unit->secsize = 0; sdincvers(unit); } /* device must be connected or not; other values are trouble */ if(unit->inquiry[0] & 0xC0) /* see SDinq0periphqual */ return 0; switch(unit->inquiry[0] & SDinq0periphtype){ case SDperdisk: case SDperworm: case SDpercd: case SDpermo: break; default: return 0; } if(unit->dev->ifc->online) unit->dev->ifc->online(unit); if(unit->sectors){ sdincvers(unit); sdaddpart(unit, "data", 0, unit->sectors); /* * Use partitions passed from boot program, * e.g. * sdC0part=dos 63 123123/plan9 123123 456456 * This happens before /boot sets hostname so the * partitions will have the null-string for user. * The gen functions patch it up. */ snprint(buf, sizeof buf, "%spart", unit->name); for(p = getconf(buf); p != nil; p = q){ if(q = strchr(p, '/')) *q++ = '\0'; nf = tokenize(p, f, nelem(f)); if(nf < 3) continue; start = strtoull(f[1], 0, 0); end = strtoull(f[2], 0, 0); if(!waserror()){ sdaddpart(unit, f[0], start, end); poperror(); } } } return 1; }
static int sdinitpart(SDunit* unit) { int nf; uvlong start, end; char *f[4], *p, *q, buf[10]; if(unit->sectors > 0){ unit->sectors = unit->secsize = 0; sdincvers(unit); } if(unit->inquiry[0] & 0xC0) return 0; switch(unit->inquiry[0] & 0x1F){ case 0x00: /* DA */ case 0x04: /* WORM */ case 0x05: /* CD-ROM */ case 0x07: /* MO */ break; default: return 0; } if(unit->dev->ifc->online) unit->dev->ifc->online(unit); if(unit->sectors){ sdincvers(unit); sdaddpart(unit, "data", 0, unit->sectors); /* * Use partitions passed from boot program, * e.g. * sdC0part=dos 63 123123/plan9 123123 456456 * This happens before /boot sets hostname so the * partitions will have the null-string for user. * The gen functions patch it up. */ snprint(buf, sizeof buf, "%spart", unit->name); for(p = getconf(buf); p != nil; p = q){ if(q = strchr(p, '/')) *q++ = '\0'; nf = tokenize(p, f, nelem(f)); if(nf < 3) continue; start = strtoull(f[1], 0, 0); end = strtoull(f[2], 0, 0); if(!waserror()){ sdaddpart(unit, f[0], start, end); poperror(); } } } return 1; }
void meminit(void) { int i; Map *mp; Confmem *cm; ulong pa, *pte; ulong maxmem, lost; char *p; if(p = getconf("*maxmem")) maxmem = strtoul(p, 0, 0); else maxmem = 0; /* * Set special attributes for memory between 640KB and 1MB: * VGA memory is writethrough; * BIOS ROM's/UMB's are uncached; * then scan for useful memory. */ for(pa = 0xA0000; pa < 0xC0000; pa += BY2PG){ pte = mmuwalk(m->pdb, (ulong)KADDR(pa), 2, 0); *pte |= PTEWT; } for(pa = 0xC0000; pa < 0x100000; pa += BY2PG){ pte = mmuwalk(m->pdb, (ulong)KADDR(pa), 2, 0); *pte |= PTEUNCACHED; } mmuflushtlb(PADDR(m->pdb)); umbscan(); lowraminit(); if(e820scan() < 0) ramscan(maxmem); /* * Set the conf entries describing banks of allocatable memory. */ for(i=0; i<nelem(mapram) && i<nelem(conf.mem); i++){ mp = &rmapram.map[i]; cm = &conf.mem[i]; cm->base = mp->addr; cm->npage = mp->size/BY2PG; } lost = 0; for(; i<nelem(mapram); i++) lost += rmapram.map[i].size; if(lost) print("meminit - lost %lud bytes\n", lost); if(MEMDEBUG) memdebug(); }
Uart* i8250console(char* cfg) { int i; Uart *uart; Ctlr *ctlr; char *cmd, *p; /* * Before i8250pnp() is run can only set the console * to 0 or 1 because those are the only uart structs which * will be the same before and after that. */ if((p = getconf("console")) == nil && (p = cfg) == nil) return nil; i = strtoul(p, &cmd, 0); if(p == cmd) return nil; if((uart = uartconsole(i, cmd)) != nil){ consuart = uart; return uart; } switch(i){ default: return nil; case 0: uart = &i8250uart[0]; break; case 1: uart = &i8250uart[1]; break; } /* * Does it exist? * Should be able to write/read * the Scratch Pad. */ ctlr = uart->regs; csr8o(ctlr, Scr, 0x55); if(csr8r(ctlr, Scr) != 0x55) return nil; (*uart->phys->enable)(uart, 0); uartctl(uart, "b9600 l8 pn s1 i1"); if(*cmd != '\0') uartctl(uart, cmd); consuart = uart; uart->console = 1; return uart; }
static void serialconsole(void) { char *p; int port, baud; p = getconf("console"); if(p == nil) p = "0"; if(p != nil && !remotedebug){ port = strtol(p, nil, 0); baud = 9600; p = getconf("baud"); if(p != nil){ baud = strtol(p, nil, 0); if(baud < 9600) baud = 9600; } uartspecial(port, baud, &kbdq, &printq, kbdcr2nl); } }
// resolve host name and return addrinfo with data_port filled in struct addrinfo *resolve(char *data_host) { if (data_host == NULL) return NULL; struct addrinfo *ainfo; struct addrinfo hints; bzero(&hints, sizeof(hints)); if (strspn(data_host, "0123456789.") == strlen(data_host)) hints.ai_flags = AI_NUMERICHOST; // get ip address if (getaddrinfo(data_host, getconf("data_port"), &hints, &ainfo)) return NULL; return ainfo; }
void okay(int on) { static int first; static int okled, polarity; char *p; if(!first++){ p = getconf("bcm2709.disk_led_gpio"); if(p == nil) p = getconf("bcm2708.disk_led_gpio"); if(p != nil) okled = strtol(p, 0, 0); else okled = OkLed; p = getconf("bcm2709.disk_led_active_low"); if(p == nil) p = getconf("bcm2708.disk_led_active_low"); polarity = (p == nil || *p == '1'); gpiosel(okled, Output); } gpioout(okled, on^polarity); }
static SDev* aoepnp(void) { int i, id; char *p; SDev *h, *t, *s; if((p = getconf("aoedev")) == 0) return 0; kstrdup(&probebuf, p); nprobe = tokenize(probebuf, probef, nelem(probef)); h = t = 0; for(i = 0; i < nprobe; i++) { p = probef[i]; if(strlen(p) < 2) continue; id = 'e'; if(p[1] == '!') { id = p[0]; p += 2; } /* * shorthand for: id!lun -> id!#æ/aoe/lun * because we cannot type æ in the bootloader console. */ if(strchr(p, '/') == nil) { char tmp[64]; snprint(tmp, sizeof(tmp), "%c!#æ/aoe/%s", (char)id, p); probef[i] = nil; kstrdup(&probef[i], tmp); } s = malloc(sizeof *s); if(s == nil) break; s->ctlr = 0; s->idno = id; s->ifc = &sdaoeifc; s->nunit = 1; if(h) t->next = s; else h = s; t = s; } return h; }
static void rwrite(Fcall *f) { Fid *fidp; int n; char *err, *argv[10]; fidp = newfid(f->fid); if(fidp->node->d.mode & DMDIR) { reply(f, "directories are not writable"); return; } if(fidp->open == 0) { reply(f, "file not open"); return; } if (!permitted(fidp, fidp->node, AWRITE)) { reply(f, "permission denied"); return; } f->data[f->count] = 0; /* the extra byte in rbuf leaves room */ n = tokenize(f->data, argv, 10); err = 0; switch(findkey(argv[0], cmds)) { case RELOAD: getconf(); reload(); break; case RDEBUG: if(n > 1) { debugfd = create(argv[1], OWRITE, 0666); if(debugfd < 0) err = "create failed"; } else debugfd = 2; break; case RNODEBUG: if(debugfd >= 0) close(debugfd); debugfd = -1; break; default: err = "unknown command"; break; } reply(f, err); }
int eaccess(register const char *name, register int mode) { struct stat statb; if (stat(name, &statb) == 0) { if(euserid == 0) { if(!S_ISREG(statb.st_mode) || mode != 1) return(0); /* root needs execute permission for someone */ mode = (S_IXUSR|S_IXGRP|S_IXOTH); } else if(euserid == statb.st_uid) mode <<= 6; else if(egroupid == statb.st_gid) mode <<= 3; #ifdef _lib_getgroups /* on some systems you can be in several groups */ else { static int maxgroups; gid_t *groups=0; register int n; if(maxgroups==0) { /* first time */ if((maxgroups=getgroups(0,groups)) < 0) { /* pre-POSIX system */ maxgroups=getconf("NGROUPS_MAX"); } } groups = (gid_t*)malloc((maxgroups+1)*sizeof(gid_t)); n = getgroups(maxgroups,groups); while(--n >= 0) { if(groups[n] == statb.st_gid) { mode <<= 3; break; } } } #endif /* _lib_getgroups */ if(statb.st_mode & mode) return(0); } return(-1); }
/* int getconf_long(const char *configfile, const char *key, long *lvalue) description: gets the long value associated with a key in a config file arguments: configfile: path of config file key: section/key to look for return values: returns 0 for OK or error code defined in conf.h lvalue: the long integer associated with key in section */ int getconf_long(const char *configfile, const char *key, long *lvalue) { char svalue[CONF_MAX_LINE_LEN]; /* tempory storage for string value */ int result; /* result of called functions */ if (!lvalue) /* NULL pointer was passed */ return CONF_ERR_ARGUMENT; if ((result = getconf(configfile, key, svalue, sizeof(svalue)))) /* get string value from config file */ return result; *lvalue = strtol(svalue,0,0); /* convert to long */ return CONF_SUCCESS; } /* getconf_long() */
int establish_connection() { /* For connecting */ char *hostname, *port; /* For introduction purposes */ char *nickname, *username, *realname; hostname = getconf("server", NULL); port = getconf("port", "6667"); nickname = getconf("nickname", NULL); username = getconf("username", NULL); realname = getconf("realname", NULL); if (!hostname || !nickname || !username || !realname) { printlog("You are missing some variables from the configuration file, " "please check the configuration file for the missing values of: %s%s%s%s%s%s%s", !hostname ? "server" : "", !hostname ? " " : "", !nickname ? "nickname" : "", !nickname ? " " : "", !username ? "username" : "", !username ? " " : "", !realname ? "realname" : ""); exit(1); } if (irc_connect(hostname, atoi(port))) { /* If we connected, lets introduce ourselves to the server */ /* Only copy the nickname until we use USERHOST on the server to find out our real host */ bi.botuser = addtouser(NULL, nickname, NULL, NULL); irc_write(QUEUE_SERVER, "USER %s 127.0.0.1 localhost :%s", username, realname); irc_write(QUEUE_SERVER, "NICK %s", nickname); return 1; } return 0; }
static int screensize(void) { char *p; char *f[3]; int width, height, depth; p = getconf("vgasize"); if(p == nil || getfields(p, f, nelem(f), 0, "x") != nelem(f) || (width = atoi(f[0])) < 16 || (height = atoi(f[1])) <= 0 || (depth = atoi(f[2])) <= 0) return -1; xgscreen.r.max = Pt(width, height); xgscreen.depth = depth; return 0; }
static int fbdefault(int *width, int *height, int *depth) { u32int buf[3]; char *p; if(vcreq(TagGetres, &buf[0], 0, 2*4) != 2*4 || vcreq(TagGetdepth, &buf[2], 0, 4) != 4) return -1; *width = buf[0]; *height = buf[1]; if((p = getconf("bcm2708_fb.fbdepth")) != nil) *depth = atoi(p); else *depth = buf[2]; return 0; }
int main(int argc, char **argv) { char c; char *flags=0; optind = 0; while ((c = getopt(argc, argv, "vi:x:Mp:")) !=EOF) { switch (c) { case 'i': cfile = optarg; insert = 1; break; case 'x': extract = 1; cfile = optarg; break; case 'M': makemagic = 1; break; case 'v': view = 1; break; case 'p': setflags = 1; flags = optarg; break; default: usage(); } } dexefile = argv[optind]; if (!dexefile) usage(); if ((insert || extract) && !cfile) usage(); if (insert) { putconf(); if (setflags) changeflags(flags); } else if (view) viewconf(); else if (setflags) changeflags(flags); else if (extract) getconf(); else usage(); return 0; }
void archconfinit(void) { char *p; ulong hz; assert(m != nil); m->cpuhz = 1000 * Mhz; /* trimslice speed */ p = getconf("*cpumhz"); if (p) { hz = atoi(p) * Mhz; if (hz >= 100*Mhz && hz <= 3600UL*Mhz) m->cpuhz = hz; } m->delayloop = m->cpuhz/2000; /* initial estimate */ errata(); }
static void shutdown(int ispanic) { int ms, once; lock(&active); if(ispanic) active.ispanic = ispanic; else if(m->machno == 0 && (active.machs & (1<<m->machno)) == 0) active.ispanic = 0; once = active.machs & (1<<m->machno); /* * setting exiting will make hzclock() on each processor call exit(0), * which calls shutdown(0) and arch->reset(), which on mp systems is * mpshutdown, which idles non-bootstrap cpus and returns on bootstrap * processors (to permit a reboot). clearing our bit in machs avoids * calling exit(0) from hzclock() on this processor. */ active.machs &= ~(1<<m->machno); active.exiting = 1; unlock(&active); if(once) iprint("cpu%d: exiting\n", m->machno); /* wait for any other processors to shutdown */ spllo(); for(ms = 5*1000; ms > 0; ms -= TK2MS(2)){ delay(TK2MS(2)); if(active.machs == 0 && consactive() == 0) break; } if(active.ispanic){ if(!cpuserver) for(;;) halt(); if(getconf("*debug")) delay(5*60*1000); else delay(10000); }else delay(1000); }