int main(int argc, char *argv[]) { size_t jf[2] = { jfield, jfield, }; FILE *fp[2]; int ret = 0, n; char *fno; ARGBEGIN { case '1': jf[0] = estrtonum(EARGF(usage()), 1, MIN(LLONG_MAX, SIZE_MAX)); break; case '2': jf[1] = estrtonum(EARGF(usage()), 1, MIN(LLONG_MAX, SIZE_MAX)); break; case 'a': fno = EARGF(usage()); if (strcmp(fno, "1") == 0) unpairsa = 1; else if (strcmp(fno, "2") == 0) unpairsb = 1; else usage(); break; case 'e': replace = EARGF(usage()); break; case 'o': oflag = 1; initolist(&output); makeolist(&output, EARGF(usage())); break; case 't': sep = EARGF(usage()); break; case 'v': pairs = 0; fno = EARGF(usage()); if (strcmp(fno, "1") == 0) unpairsa = 1; else if (strcmp(fno, "2") == 0) unpairsb = 1; else usage(); break; default: usage(); } ARGEND; if (sep) seplen = unescape(sep); if (argc != 2) usage(); for (n = 0; n < 2; n++) { if (!strcmp(argv[n], "-")) { argv[n] = "<stdin>"; fp[n] = stdin; } else if (!(fp[n] = fopen(argv[n], "r"))) { eprintf("fopen %s:", argv[n]); } } jf[0]--; jf[1]--; join(fp[0], fp[1], jf[0], jf[1]); if (oflag) freespecs(&output); if (fshut(fp[0], argv[0]) | (fp[0] != fp[1] && fshut(fp[1], argv[1])) | fshut(stdout, "<stdout>")) ret = 2; return ret; }
INT main(UINT argc, PTCHAR argv[]) { CONST PTCHAR Banner = "\t\t \t\n" "\t\t ## ## ######## ## ## ######## \t\n" "\t\t ## ## ## ## ## ## ## \t\n" "\t\t ## ## ## ## ## ## ## \t\n" "\t\t ######### ###### ## ## ## ## \t\n" "\t\t ## ## ## ## ## ## ## \t\n" "\t\t ## ## ## ## ## ## ## \t\n" "\t\t ## ## ######## ### ######## \t\n" "\t\t \t\n" "\t\t HackSys Extreme Vulnerable Driver Exploits \t\n" "\t\t Ashfaq Ansari (@HackSysTeam) \t\n" "\t\t ashfaq[at]payatu[dot]com \t\n" "\t\t \t\n"; PTCHAR CommandToExecute = NULL; EXPLOIT_VULNERABILITY ExploitVulnerability; ClearScreen(); CenterConsoleScreen(); // Print the banner DEBUG_SUCCESS(Banner); if (argc < 3) { ShowUsage(argv[0]); } // Parse the command line arguments ARGBEGIN { case 'p': ExploitVulnerability.VulnerabilityType = PoolOverflow; break; case 'u': ExploitVulnerability.VulnerabilityType = UseAfterFree; break; case 't': ExploitVulnerability.VulnerabilityType = TypeConfusion; break; case 's': ExploitVulnerability.VulnerabilityType = StackOverflow; break; case 'i': ExploitVulnerability.VulnerabilityType = IntegerOverflow; break; case 'g': ExploitVulnerability.VulnerabilityType = StackOverflowGS; break; case 'a': ExploitVulnerability.VulnerabilityType = ArbitraryOverwrite; break; case 'h': ExploitVulnerability.VulnerabilityType = UninitializedHeapVariable; break; case 'v': ExploitVulnerability.VulnerabilityType = UninitializedStackVariable; break; case 'n': ExploitVulnerability.VulnerabilityType = NullPointerDereference; break; case 'c': ExploitVulnerability.Command = EARGF(ShowUsage(argv[0])); break; default: ShowUsage(argv[0]); } ARGEND; // Start the exploitation Exploit(&ExploitVulnerability); return EXIT_SUCCESS; }
void main(int argc, char *argv[]) { char *file; char *rcmd, *wcmd; int fd0, fd1, ifd0, ifd1, dupflag; rfork(RFNOTEG); dupflag = 0; rcmd = wcmd = nil; ARGBEGIN{ case 'd': dupflag = 1; break; case 'r': rcmd = EARGF(usage()); break; case 'w': wcmd = EARGF(usage()); break; default: usage(); }ARGEND if(argc!=1 || (rcmd==nil && wcmd==nil)) usage(); if(rcmd == nil) rcmd = "/bin/cat"; if(wcmd == nil) wcmd = "/bin/cat"; file = argv[0]; if(dupflag){ ifd0 = open(file, ORDWR); if(ifd0 < 0) sysfatal("open %s: %r", file); ifd1 = dup(ifd0, -1); }else{ ifd0 = open(file, OREAD); if(ifd0 < 0) sysfatal("open %s: %r", file); ifd1 = open(file, OWRITE); if(ifd1 < 0) sysfatal("open %s: %r", file); } if(bind("#|", TEMP, MREPL) < 0) sysfatal("bind pipe %s: %r", TEMP); if(bind(TEMP "/data", file, MREPL) < 0) sysfatal("bind %s %s: %r", TEMP "/data", file); fd0 = open(TEMP "/data1", OREAD); if(fd0 < 0) sysfatal("open %s: %r", TEMP "/data1"); connect(wcmd, fd0, ifd1); fd1 = open(TEMP "/data1", OWRITE); if(fd1 < 0) sysfatal("open %s: %r", TEMP "/data1"); connect(rcmd, ifd0, fd1); unmount(nil, TEMP); exits(nil); }
void main(int argc, char **argv) { char dat[MaxStr], buf[MaxStr], cmd[MaxStr], *p, *err; int ac, fd, ms, data; char *av[10]; quotefmtinstall(); origargs = procgetname(); /* see if we should use a larger message size */ fd = open("/dev/draw", OREAD); if(fd > 0){ ms = iounit(fd); if(msgsize < ms+IOHDRSZ) msgsize = ms+IOHDRSZ; close(fd); } user = getuser(); if(user == nil) fatal(1, "can't read user name"); ARGBEGIN{ case 'a': p = EARGF(usage()); if(setam(p) < 0) fatal(0, "unknown auth method %s", p); break; case 'e': ealgs = EARGF(usage()); if(*ealgs == 0 || strcmp(ealgs, "clear") == 0) ealgs = nil; break; case 'd': dbg++; break; case 'f': /* ignored but accepted for compatibility */ break; case 'R': /* From listen */ remoteside(); break; case 'h': system = EARGF(usage()); break; case 'c': cflag++; cmd[0] = '!'; cmd[1] = '\0'; while(p = ARGF()) { strcat(cmd, " "); strcat(cmd, p); } break; case 'k': keyspec = smprint("%s %s", keyspec, EARGF(usage())); break; case 'P': patternfile = EARGF(usage()); break; case 'u': user = EARGF(usage()); keyspec = smprint("%s user=%s", keyspec, user); break; default: usage(); }ARGEND; if(argc != 0) usage(); if(system == nil) { p = getenv("cpu"); if(p == 0) fatal(0, "set $cpu"); system = p; } if(err = rexcall(&data, system, srvname)) fatal(1, "%s: %s", err, system); procsetname("%s", origargs); /* Tell the remote side the command to execute and where our working directory is */ if(cflag) writestr(data, cmd, "command", 0); if(getwd(dat, sizeof(dat)) == 0) writestr(data, "NO", "dir", 0); else writestr(data, dat, "dir", 0); /* start up a process to pass along notes */ lclnoteproc(data); /* * Wait for the other end to execute and start our file service * of /mnt/term */ if(readstr(data, buf, sizeof(buf)) < 0) fatal(1, "waiting for FS: %r"); if(strncmp("FS", buf, 2) != 0) { print("remote cpu: %s", buf); exits(buf); } /* Begin serving the gnot namespace */ close(0); dup(data, 0); close(data); sprint(buf, "%d", msgsize); ac = 0; av[ac++] = exportfs; av[ac++] = "-m"; av[ac++] = buf; if(dbg) av[ac++] = "-d"; if(patternfile != nil){ av[ac++] = "-P"; av[ac++] = patternfile; } av[ac] = nil; exec(exportfs, av); fatal(1, "starting exportfs"); }
void main(int argc, char **argv) { char *f[10], *local, *name, *remote, *s, *t, verb; int fd, havedb, havelocal, i, k, n, nf, resolve1, skip; int checkedmatch1, checkedmatch2, checkedmatch3, checkedmatch4; ulong now; Biobuf bin; Dir dbd, ld, nd, rd; Avlwalk *w; Entry *e; membogus(argv); quotefmtinstall(); ARGBEGIN{ case 's': case 'c': i = ARGC(); addresolve(i, EARGF(usage())); break; case 'n': donothing = 1; verbose = 1; break; case 'S': safeinstall = 0; break; case 'T': timefile = EARGF(usage()); break; case 't': tempspool = 0; break; case 'u': douid = 1; break; case 'v': verbose++; break; default: usage(); }ARGEND if(argc < 3) usage(); if(timefile) readtimefile(); lroot = argv[1]; if(!isdir(lroot)) sysfatal("bad local root directory"); rroot = argv[2]; if(!isdir(rroot)) sysfatal("bad remote root directory"); match = argv+3; nmatch = argc-3; for(i=0; i<nmatch; i++) if(match[i][0] == '/') match[i]++; if((clientdb = opendb(argv[0])) == nil) sysfatal("opendb %q: %r", argv[2]); copyerr = opendb(nil); skip = 0; Binit(&bin, 0, OREAD); for(; s=Brdstr(&bin, '\n', 1); free(s)){ t = estrdup(s); nf = tokenize(s, f, nelem(f)); if(nf != 10 || strlen(f[2]) != 1){ skip = 1; fprint(2, "warning: skipping bad log entry <%s>\n", t); free(t); continue; } free(t); now = strtoul(f[0], 0, 0); n = atoi(f[1]); verb = f[2][0]; name = f[3]; if(now < maxnow || (now==maxnow && n <= maxn)) continue; local = mkname(localbuf, sizeof localbuf, lroot, name); if(strcmp(f[4], "-") == 0) f[4] = f[3]; remote = mkname(remotebuf, sizeof remotebuf, rroot, f[4]); rd.name = f[4]; rd.mode = strtoul(f[5], 0, 8); rd.uid = f[6]; rd.gid = f[7]; rd.mtime = strtoul(f[8], 0, 10); rd.length = strtoll(f[9], 0, 10); havedb = finddb(clientdb, name, &dbd)>=0; havelocal = localdirstat(local, &ld)>=0; resolve1 = resolve(name); /* * if(!ismatch(name)){ * skip = 1; * continue; * } * * This check used to be right here, but we want * the time to be able to move forward past entries * that don't match and have already been applied. * So now every path below must checked !ismatch(name) * before making any changes to the local file * system. The fake variable checkedmatch * tracks whether !ismatch(name) has been checked. * If the compiler doesn't produce any used/set * warnings, then all the paths should be okay. * Even so, we have the asserts to fall back on. */ switch(verb){ case 'd': /* delete file */ delce(local); if(!havelocal) /* doesn't exist; who cares? */ break; if(access(remote, AEXIST) >= 0) /* got recreated! */ break; if(!ismatch(name)){ skip = prstopped(skip, name); continue; } SET(checkedmatch1); if(!havedb){ if(resolve1 == 's') goto DoRemove; else if(resolve1 == 'c') goto DoRemoveDb; conflict(name, "locally created; will not remove"); skip = 1; continue; } assert(havelocal && havedb); if(dbd.mtime > rd.mtime) /* we have a newer file than what was deleted */ break; if(samecontents(local, remote) > 0){ /* going to get recreated */ chat("= %q %luo %q %q %lud\n", name, rd.mode, rd.uid, rd.gid, rd.mtime); break; } if(!(dbd.mode&DMDIR) && (dbd.mtime != ld.mtime || dbd.length != ld.length)){ /* locally modified since we downloaded it */ if(resolve1 == 's') goto DoRemove; else if(resolve1 == 'c') break; conflict(name, "locally modified; will not remove"); skip = 1; continue; } DoRemove: USED(checkedmatch1); assert(ismatch(name)); chat("d %q %luo %q %q %lud\n", name, rd.mode, rd.uid, rd.gid, rd.mtime); if(donothing) break; if(remove(local) < 0){ error("removing %q: %r", name); skip = 1; continue; } DoRemoveDb: USED(checkedmatch1); assert(ismatch(name)); removedb(clientdb, name); break; case 'a': /* add file */ if(!havedb){ if(!ismatch(name)){ skip = prstopped(skip, name); continue; } SET(checkedmatch2); if(!havelocal) goto DoCreate; if((ld.mode&DMDIR) && (rd.mode&DMDIR)) break; if(samecontents(local, remote) > 0){ chat("= %q %luo %q %q %lud\n", name, rd.mode, rd.uid, rd.gid, rd.mtime); goto DoCreateDb; } if(resolve1 == 's') goto DoCreate; else if(resolve1 == 'c') goto DoCreateDb; conflict(name, "locally created; will not overwrite"); skip = 1; continue; } assert(havedb); if(dbd.mtime >= rd.mtime) /* already created this file; ignore */ break; if(havelocal){ if((ld.mode&DMDIR) && (rd.mode&DMDIR)) break; if(!ismatch(name)){ skip = prstopped(skip, name); continue; } SET(checkedmatch2); if(samecontents(local, remote) > 0){ chat("= %q %luo %q %q %lud\n", name, rd.mode, rd.uid, rd.gid, rd.mtime); goto DoCreateDb; } if(dbd.mtime==ld.mtime && dbd.length==ld.length) goto DoCreate; if(resolve1=='s') goto DoCreate; else if(resolve1 == 'c') goto DoCreateDb; conflict(name, "locally modified; will not overwrite"); skip = 1; continue; } if(!ismatch(name)){ skip = prstopped(skip, name); continue; } SET(checkedmatch2); DoCreate: USED(checkedmatch2); assert(ismatch(name)); if(notexists(remote)){ addce(local); /* no skip=1 */ break;; } chat("a %q %luo %q %q %lud\n", name, rd.mode, rd.uid, rd.gid, rd.mtime); if(donothing) break; if(rd.mode&DMDIR){ fd = create(local, OREAD, DMDIR); if(fd < 0 && isdir(local)) fd = open(local, OREAD); if(fd < 0){ error("mkdir %q: %r", name); skip = 1; continue; } nulldir(&nd); nd.mode = rd.mode; if(dirfwstat(fd, &nd) < 0) fprint(2, "warning: cannot set mode on %q\n", local); nulldir(&nd); nd.gid = rd.gid; if(dirfwstat(fd, &nd) < 0) fprint(2, "warning: cannot set gid on %q\n", local); if(douid){ nulldir(&nd); nd.uid = rd.uid; if(dirfwstat(fd, &nd) < 0) fprint(2, "warning: cannot set uid on %q\n", local); } close(fd); rd.mtime = now; }else{ if(copyfile(local, remote, name, &rd, 1, &k) < 0){ if(k) addce(local); skip = 1; continue; } } DoCreateDb: USED(checkedmatch2); assert(ismatch(name)); insertdb(clientdb, name, &rd); break; case 'c': /* change contents */ if(!havedb){ if(notexists(remote)){ addce(local); /* no skip=1 */ break; } if(!ismatch(name)){ skip = prstopped(skip, name); continue; } SET(checkedmatch3); if(resolve1 == 's') goto DoCopy; else if(resolve1=='c') goto DoCopyDb; if(samecontents(local, remote) > 0){ chat("= %q %luo %q %q %lud\n", name, rd.mode, rd.uid, rd.gid, rd.mtime); goto DoCopyDb; } if(havelocal) conflict(name, "locally created; will not update"); else conflict(name, "not replicated; will not update"); skip = 1; continue; } if(dbd.mtime >= rd.mtime) /* already have/had this version; ignore */ break; if(!ismatch(name)){ skip = prstopped(skip, name); continue; } SET(checkedmatch3); if(!havelocal){ if(notexists(remote)){ addce(local); /* no skip=1 */ break; } if(resolve1 == 's') goto DoCopy; else if(resolve1 == 'c') break; conflict(name, "locally removed; will not update"); skip = 1; continue; } assert(havedb && havelocal); if(dbd.mtime != ld.mtime || dbd.length != ld.length){ if(notexists(remote)){ addce(local); /* no skip=1 */ break; } if(samecontents(local, remote) > 0){ chat("= %q %luo %q %q %lud\n", name, rd.mode, rd.uid, rd.gid, rd.mtime); goto DoCopyDb; } if(resolve1 == 's') goto DoCopy; else if(resolve1 == 'c') goto DoCopyDb; conflict(name, "locally modified; will not update [%llud %lud -> %llud %lud]", dbd.length, dbd.mtime, ld.length, ld.mtime); skip = 1; continue; } DoCopy: USED(checkedmatch3); assert(ismatch(name)); if(notexists(remote)){ addce(local); /* no skip=1 */ break; } chat("c %q\n", name); if(donothing) break; if(copyfile(local, remote, name, &rd, 0, &k) < 0){ if(k) addce(local); skip = 1; continue; } DoCopyDb: USED(checkedmatch3); assert(ismatch(name)); if(!havedb){ if(havelocal) dbd = ld; else dbd = rd; } dbd.mtime = rd.mtime; dbd.length = rd.length; insertdb(clientdb, name, &dbd); break; case 'm': /* change metadata */ if(!havedb){ if(notexists(remote)){ addce(local); /* no skip=1 */ break; } if(!ismatch(name)){ skip = prstopped(skip, name); continue; } SET(checkedmatch4); if(resolve1 == 's'){ USED(checkedmatch4); SET(checkedmatch2); goto DoCreate; } else if(resolve1 == 'c') goto DoMetaDb; if(havelocal) conflict(name, "locally created; will not update metadata"); else conflict(name, "not replicated; will not update metadata"); skip = 1; continue; } if(!(dbd.mode&DMDIR) && dbd.mtime > rd.mtime) /* have newer version; ignore */ break; if((dbd.mode&DMDIR) && dbd.mtime > now) break; if(havelocal && (!douid || strcmp(ld.uid, rd.uid)==0) && strcmp(ld.gid, rd.gid)==0 && ld.mode==rd.mode) break; if(!havelocal){ if(notexists(remote)){ addce(local); /* no skip=1 */ break; } if(!ismatch(name)){ skip = prstopped(skip, name); continue; } SET(checkedmatch4); if(resolve1 == 's'){ USED(checkedmatch4); SET(checkedmatch2); goto DoCreate; } else if(resolve1 == 'c') break; conflict(name, "locally removed; will not update metadata"); skip = 1; continue; } if(!(dbd.mode&DMDIR) && (dbd.mtime != ld.mtime || dbd.length != ld.length)){ /* this check might be overkill */ if(notexists(remote)){ addce(local); /* no skip=1 */ break; } if(!ismatch(name)){ skip = prstopped(skip, name); continue; } SET(checkedmatch4); if(resolve1 == 's' || samecontents(local, remote) > 0) goto DoMeta; else if(resolve1 == 'c') break; conflict(name, "contents locally modified (%s); will not update metadata to %s %s %luo", dbd.mtime != ld.mtime ? "mtime" : dbd.length != ld.length ? "length" : "unknown", rd.uid, rd.gid, rd.mode); skip = 1; continue; } if((douid && strcmp(ld.uid, dbd.uid)!=0) || strcmp(ld.gid, dbd.gid)!=0 || ld.mode!=dbd.mode){ if(notexists(remote)){ addce(local); /* no skip=1 */ break; } if(!ismatch(name)){ skip = prstopped(skip, name); continue; } SET(checkedmatch4); if(resolve1 == 's') goto DoMeta; else if(resolve1 == 'c') break; conflict(name, "metadata locally changed; will not update metadata to %s %s %luo", rd.uid, rd.gid, rd.mode); skip = 1; continue; } if(!ismatch(name)){ skip = prstopped(skip, name); continue; } SET(checkedmatch4); DoMeta: USED(checkedmatch4); assert(ismatch(name)); if(notexists(remote)){ addce(local); /* no skip=1 */ break; } chat("m %q %luo %q %q %lud\n", name, rd.mode, rd.uid, rd.gid, rd.mtime); if(donothing) break; nulldir(&nd); nd.gid = rd.gid; nd.mode = rd.mode; if(douid) nd.uid = rd.uid; if(dirwstat(local, &nd) < 0){ error("dirwstat %q: %r", name); skip = 1; continue; } DoMetaDb: USED(checkedmatch4); assert(ismatch(name)); if(!havedb){ if(havelocal) dbd = ld; else dbd = rd; } if(dbd.mode&DMDIR) dbd.mtime = now; dbd.gid = rd.gid; dbd.mode = rd.mode; if(douid) dbd.uid = rd.uid; insertdb(clientdb, name, &dbd); break; } if(!skip && !donothing){ maxnow = now; maxn = n; } } w = avlwalk(copyerr->avl); while(e = (Entry*)avlnext(w)) error("copying %q: %s\n", e->name, e->d.name); if(timefile) writetimefile(); if(nconf) exits("conflicts"); if(errors) exits("errors"); exits(nil); }
void cpumain(int argc, char **argv) { char dat[MaxStr], buf[MaxStr], cmd[MaxStr], *err, *secstoreserver, *p, *s; int fd, ms, data; /* see if we should use a larger message size */ fd = open("/dev/draw", OREAD); if(fd > 0){ ms = iounit(fd); if(msgsize < ms+IOHDRSZ) msgsize = ms+IOHDRSZ; close(fd); } user = getenv("USER"); if(user == nil) user = readcons("user", nil, 0); secstoreserver = nil; authserver = getenv("auth"); if(authserver == nil) authserver = "lookout.cs.bell-labs.com"; system = getenv("cpu"); if(system == nil) system = "anna.cs.bell-labs.com"; ARGBEGIN{ case 'o': authserver = "plan9.bell-labs.com"; system = "plan9.bell-labs.com"; break; case 'a': authserver = EARGF(usage()); break; case 'c': system = EARGF(usage()); break; case 'd': dbg++; break; case 'e': ealgs = EARGF(usage()); if(*ealgs == 0 || strcmp(ealgs, "clear") == 0) ealgs = nil; break; case 'C': cflag++; cmd[0] = '!'; cmd[1] = '\0'; while((p = ARGF()) != nil) { strcat(cmd, " "); strcat(cmd, p); } break; case 'k': keyspec = EARGF(usage()); break; case 'u': user = EARGF(usage()); break; case 's': secstoreserver = EARGF(usage()); break; default: usage(); }ARGEND; if(argc != 0) usage(); if(mountfactotum() < 0){ if(secstoreserver == nil) secstoreserver = authserver; if(havesecstore(secstoreserver, user)){ s = secstorefetch(secstoreserver, user, nil); if(s){ if(strlen(s) >= sizeof secstorebuf) sysfatal("secstore data too big"); strcpy(secstorebuf, s); } } } if((err = rexcall(&data, system, srvname))) fatal(1, "%s: %s", err, system); /* Tell the remote side the command to execute and where our working directory is */ if(cflag) writestr(data, cmd, "command", 0); if(getcwd(dat, sizeof(dat)) == 0) writestr(data, "NO", "dir", 0); else writestr(data, dat, "dir", 0); /* * Wait for the other end to execute and start our file service * of /mnt/term */ if(readstr(data, buf, sizeof(buf)) < 0) fatal(1, "waiting for FS: %r"); if(strncmp("FS", buf, 2) != 0) { print("remote cpu: %s", buf); exits(buf); } if(readstr(data, buf, sizeof buf) < 0) fatal(1, "waiting for remote export: %r"); if(strcmp(buf, "/") != 0){ print("remote cpu: %s" , buf); exits(buf); } write(data, "OK", 2); /* Begin serving the gnot namespace */ exportfs(data, msgsize); fatal(1, "starting exportfs"); }
void threadmain(int argc, char **argv) { int fd, i, nd; char *err, *mnt, *srv; Dir *d; srv = "usb"; mnt = "/dev"; ARGBEGIN{ case 'D': usbfsdebug++; break; case 'd': usbdebug++; break; case 's': srv = EARGF(usage()); break; case 'i': pollms = atoi(EARGF(usage())); break; case 'm': mnt = EARGF(usage()); break; default: usage(); }ARGEND; if(access("/dev/usb", AEXIST) < 0 && bind("#u", "/dev", MBEFORE) < 0) sysfatal("#u: %r"); args(); fmtinstall('U', Ufmt); quotefmtinstall(); rfork(RFNOTEG); portc = chancreate(sizeof(char *), 0); if(portc == nil) sysfatal("chancreate"); proccreate(work, portc, Stack); if(argc == 0){ fd = open("/dev/usb", OREAD); if(fd < 0) sysfatal("/dev/usb: %r"); nd = dirreadall(fd, &d); close(fd); if(nd < 2) sysfatal("/dev/usb: no hubs"); for(i = 0; i < nd; i++) if(strcmp(d[i].name, "ctl") != 0) sendp(portc, smprint("/dev/usb/%s", d[i].name)); free(d); }else for(i = 0; i < argc; i++) sendp(portc, strdup(argv[i])); sendp(portc, nil); err = recvp(portc); chanfree(portc); usbfsexits(0); usbfsinit(srv, mnt, &usbdirfs, MAFTER); snprint(ctlfs.name, sizeof(ctlfs.name), "usbdctl"); usbfsadd(&ctlfs); threadexits(err); }
void threadmain(int argc, char *argv[]) { Column *c; char buf[256]; int i, ncol; rfork(RFENVG|RFNAMEG); ncol = 1; ARGBEGIN{ case 'c': ncol = atoi(EARGF(usage())); if(ncol <= 0) usage(); break; case 'm': webmountpt = EARGF(usage()); break; case 'p': procstderr++; break; case 't': charset = EARGF(usage()); break; default: usage(); break; }ARGEND snprint(buf, sizeof(buf), "%s/ctl", webmountpt); webctlfd = open(buf, ORDWR); if(webctlfd < 0) sysfatal("can't initialize webfs: %r"); snarffd = open("/dev/snarf", OREAD|OCEXEC); if(initdraw(derror, fontnames[0], "abaco") < 0) sysfatal("can't open display: %r"); memimageinit(); iconinit(); timerinit(); initfontpaths(); cexit = chancreate(sizeof(int), 0); crefresh = chancreate(sizeof(Page *), 0); if(cexit==nil || crefresh==nil) sysfatal("can't create initial channels: %r"); mousectl = initmouse(nil, screen); if(mousectl == nil) sysfatal("can't initialize mouse: %r"); mouse = mousectl; keyboardctl = initkeyboard(nil); if(keyboardctl == nil) sysfatal("can't initialize keyboard: %r"); mainpid = getpid(); plumbwebfd = plumbopen("web", OREAD|OCEXEC); if(plumbwebfd >= 0){ cplumb = chancreate(sizeof(Plumbmsg*), 0); proccreate(plumbproc, nil, STACK); } plumbsendfd = plumbopen("send", OWRITE|OCEXEC); rowinit(&row, screen->clipr); for(i=0; i<ncol; i++){ c = rowadd(&row, nil, -1); if(c==nil && i==0) error("initializing columns"); } c = row.col[row.ncol-1]; for(i=0; i<argc; i++) if(i/WPERCOL >= row.ncol) readpage(c, argv[i]); else readpage(row.col[i/WPERCOL], argv[i]); flushimage(display, 1); threadcreate(keyboardthread, nil, STACK); threadcreate(mousethread, nil, STACK); threadnotify(shutdown, 1); recvul(cexit); threadexitsall(nil); }
void threadmain(int argc, char *argv[]) { int i, printstats; char *host; VacFile *f; fmtinstall('H', encodefmt); fmtinstall('V', vtscorefmt); fmtinstall('F', vtfcallfmt); fmtinstall('t', mtimefmt); fmtinstall('M', dirmodefmt); host = nil; printstats = 0; ARGBEGIN{ case 'T': settimes = 1; break; case 'V': chattyventi = 1; break; case 'c': tostdout++; break; case 'd': diff++; break; case 'h': host = EARGF(usage()); break; case 's': printstats++; break; case 't': table++; break; case 'v': chatty++; break; default: usage(); }ARGEND if(argc < 1) usage(); if(tostdout && diff){ fprint(2, "cannot use -c with -d\n"); usage(); } conn = vtdial(host); if(conn == nil) sysfatal("could not connect to server: %r"); if(vtconnect(conn) < 0) sysfatal("vtconnect: %r"); fs = vacfsopen(conn, argv[0], VtOREAD, 128); if(fs == nil) sysfatal("vacfsopen: %r"); nwant = argc-1; want = argv+1; found = vtmallocz(nwant*sizeof found[0]); if((f = vacfsgetroot(fs)) == nil) sysfatal("vacfsgetroot: %r"); unvac(f, nil, nil); for(i=0; i<nwant; i++){ if(want[i] && !found[i]){ fprint(2, "warning: didn't find %s\n", want[i]); errors++; } } if(errors) threadexitsall("errors"); if(printstats) fprint(2, "%lld bytes read, %lld bytes skipped\n", stats.data, stats.skipdata); threadexitsall(0); }
void main(int argc, char **argv) { char *netdir; char buf[1024]; netdir = nil; quotefmtinstall(); fmtinstall('I', eipfmt); starttime = time(0); ARGBEGIN{ case 'a': authenticate = 1; break; case 'c': tlscert = EARGF(usage()); break; case 'D': Dflag++; break; case 'd': debug++; break; case 'f': /* disallow relaying */ fflag = 1; break; case 'g': gflag = 1; break; case 'h': /* default domain name */ dom = EARGF(usage()); break; case 'k': /* prohibited ip address */ addbadguy(EARGF(usage())); break; case 'm': /* set mail command */ mailer = mailerpath(EARGF(usage())); break; case 'n': /* log peer ip address */ netdir = EARGF(usage()); break; case 'p': passwordinclear = 1; break; case 'r': rflag = 1; /* verify sender's domain */ break; case 's': /* save blocked messages */ sflag = 1; break; case 't': fprint(2, "%s: the -t option is no longer supported, see -c\n", argv0); tlscert = "/sys/lib/ssl/smtpd-cert.pem"; break; default: usage(); }ARGEND; nci = getnetconninfo(netdir, 0); if(nci == nil) sysfatal("can't get remote system's address: %r"); parseip(rsysip, nci->rsys); if(mailer == nil) mailer = mailerpath("send"); if(debug){ snprint(buf, sizeof buf, "%s/smtpdb/%ld", UPASLOG, time(0)); close(2); if (create(buf, OWRITE | OEXCL, 0662) >= 0) { seek(2, 0, 2); fprint(2, "%d smtpd %s\n", getpid(), thedate()); } else debug = 0; } getconf(); if (isbadguy()) exits("banned"); Binit(&bin, 0, OREAD); if (chdir(UPASLOG) < 0) syslog(0, "smtpd", "no %s: %r", UPASLOG); me = sysname_read(); if(dom == 0 || dom[0] == 0) dom = domainname_read(); if(dom == 0 || dom[0] == 0) dom = me; sayhi(); parseinit(); /* allow 45 minutes to parse the header */ atnotify(catchalarm, 1); alarm(45*60*1000); zzparse(); exits(0); }
void threadmain(int argc, char *argv[]) { char *mtpt, *s; char *secstorepw; char err[ERRMAX]; Dir d; rfork(RFNOTEG); mtpt = "/mnt"; extrafactotumdir = 1; secstorepw = nil; quotefmtinstall(); fmtinstall('A', attrfmt); fmtinstall('H', encodefmt); fmtinstall('N', attrnamefmt); if(argc == 3 && strcmp(argv[1], "-g") == 0){ gflag(argv[2]); threadexitsall(nil); } ARGBEGIN{ default: usage(); case 'D': chatty9p++; break; case 'S': /* server: read nvram, no prompting for keys */ askforkeys = 0; trysecstore = 0; sflag = 1; break; case 'a': authaddr = EARGF(usage()); break; case 'd': debug = 1; doprivate = 0; break; case 'g': usage(); case 'k': /* reinitialize nvram */ kflag = 1; break; case 'm': mtpt = EARGF(usage()); break; case 'n': trysecstore = 0; break; case 'p': doprivate = 0; break; case 's': service = EARGF(usage()); break; case 'u': /* user: set hostowner */ uflag = 1; break; case 'x': extrafactotumdir = 0; break; }ARGEND if(argc != 0) usage(); if(doprivate) private(); initcap(); if(sflag){ s = getnvramkey(kflag ? NVwrite : NVwriteonerr, &secstorepw); if(s == nil) fprint(2, "factotum warning: cannot read nvram: %r\n"); else if(ctlwrite(s) < 0) fprint(2, "factotum warning: cannot add nvram key: %r\n"); if(secstorepw != nil) trysecstore = 1; if (s != nil) { memset(s, 0, strlen(s)); free(s); } } else if(uflag) promptforhostowner(); owner = getuser(); if(trysecstore && havesecstore()){ while(secstorefetch(secstorepw) < 0){ rerrstr(err, sizeof err); if(strcmp(err, "cancel") == 0) break; fprint(2, "secstorefetch: %r\n"); fprint(2, "Enter an empty password to quit.\n"); free(secstorepw); secstorepw = nil; /* just try nvram pw once */ } } fsinit0(); threadpostmountsrv(&fs, service, mtpt, MBEFORE); if(service){ nulldir(&d); d.mode = 0666; s = emalloc(10+strlen(service)); strcpy(s, "/srv/"); strcat(s, service); if(dirwstat(s, &d) < 0) fprint(2, "factotum warning: cannot chmod 666 %s: %r\n", s); free(s); } threadexits(nil); }
void main(int argc, char **argv) { char *mntpt, *srvpost, srvfile[64]; int backwards = 0, fd, mntflags, oldserver; quotefmtinstall(); srvpost = nil; oldserver = 0; mntflags = MREPL; ARGBEGIN{ case 'A': doauth = 0; break; case 'a': mntflags = MAFTER; break; case 'b': mntflags = MBEFORE; break; case 'c': mntflags |= MCREATE; break; case 'C': mntflags |= MCACHE; break; case 'd': debug++; break; case 'f': /* ignored but allowed for compatibility */ break; case 'O': case 'o': oldserver = 1; break; case 'E': if ((encproto = lookup(EARGF(usage()), encprotos)) < 0) usage(); break; case 'e': ealgs = EARGF(usage()); if(*ealgs == 0 || strcmp(ealgs, "clear") == 0) ealgs = nil; break; case 'k': keyspec = EARGF(usage()); break; case 'p': filterp = aan; break; case 'n': anstring = EARGF(usage()); break; case 's': srvpost = EARGF(usage()); break; case 'B': backwards = 1; break; case 'z': skiptree = 1; break; default: usage(); }ARGEND; mntpt = 0; /* to shut up compiler */ if(backwards){ switch(argc) { default: mntpt = argv[0]; break; case 0: usage(); } } else { switch(argc) { case 2: mntpt = argv[1]; break; case 3: mntpt = argv[2]; break; default: usage(); } } if (encproto == Enctls) sysfatal("%s: tls has not yet been implemented", argv[0]); notify(catcher); alarm(60*1000); if (backwards) fd = passive(); else fd = connect(argv[0], argv[1], oldserver); if (!oldserver) fprint(fd, "impo %s %s\n", filterp? "aan": "nofilter", encprotos[encproto]); if (encproto != Encnone && ealgs && ai) { uchar key[16], digest[SHA1dlen]; char fromclientsecret[21]; char fromserversecret[21]; int i; assert(ai->nsecret <= sizeof(key)-4); memmove(key+4, ai->secret, ai->nsecret); /* exchange random numbers */ srand(truerand()); for(i = 0; i < 4; i++) key[i] = rand(); if(write(fd, key, 4) != 4) sysfatal("can't write key part: %r"); if(readn(fd, key+12, 4) != 4) sysfatal("can't read key part: %r"); /* scramble into two secrets */ sha1(key, sizeof(key), digest, nil); mksecret(fromclientsecret, digest); mksecret(fromserversecret, digest+10); if (filterp) fd = filter(fd, filterp, backwards ? nil : argv[0]); /* set up encryption */ procsetname("pushssl"); fd = pushssl(fd, ealgs, fromclientsecret, fromserversecret, nil); if(fd < 0) sysfatal("can't establish ssl connection: %r"); } else if (filterp) fd = filter(fd, filterp, backwards ? nil : argv[0]); if(ai) auth_freeAI(ai); if(srvpost){ snprint(srvfile, sizeof(srvfile), "/srv/%s", srvpost); remove(srvfile); post(srvfile, srvpost, fd); } procsetname("mount on %s", mntpt); if(mount(fd, -1, mntpt, mntflags, "") < 0) sysfatal("can't mount %s: %r", argv[1]); alarm(0); if(backwards && argc > 1){ exec(argv[1], &argv[1]); sysfatal("exec: %r"); } exits(0); }
void main(int argc, char **argv) { int fd, i, n; char buf[10485760]; ARGBEGIN{ case 'd': verbose = 1; break; case 's': replacesame = atoi(EARGF(usage())); break; case 'm': mindist = atoi(EARGF(usage())); break; case 'n': win = atoi(EARGF(usage())); minrun = win; break; default: usage(); }ARGEND switch(argc){ default: usage(); case 0: fd = 0; break; case 1: if((fd = open(argv[0], OREAD)) < 0) sysfatal("open %s: %r", argv[0]); break; } while((n = readn(fd, buf, sizeof buf)) > 0){ data = realloc(data, length+n); if(data == nil) sysfatal("realloc: %r"); memmove(data+length, buf, n); length += n; if(n < sizeof buf) break; } odat = malloc(length); if(odat == nil) sysfatal("malloc: %r"); Binit(&bout, 1, OWRITE); Bprint(&bout, "BLZ\n"); Bputint(&bout, length); outn = 1; for(i=0; i<win; i++) outn = (outn * 256) % Prime; if(verbose) fprint(2, "256^%d = %.6lux\n", win, outn); outn = Prime - outn; if(verbose) fprint(2, "outn = %.6lux\n", outn); compress(); Bwrite(&bout, odat, nodat); Bterm(&bout); fprint(2, "brk %p\n", sbrk(1)); fprint(2, "%d nodes used; %d of %d hash slots used\n", nalloc, nnew, nhash); exits(nil); }
void main(int argc, char **argv) { int fd, xsize, ysize; Memimage *im, *nim; ulong ochan, tchan; xsize = ysize = 0; ARGBEGIN{ case 'a': xsize = ysize = getsize(EARGF(usage())); break; case 'x': xsize = getsize(EARGF(usage())); break; case 'y': ysize = getsize(EARGF(usage())); break; default: usage(); }ARGEND fd = 0; if(*argv){ fd = open(*argv, OREAD); if(fd < 0) sysfatal("open: %r"); } memimageinit(); if((im = readmemimage(fd)) == nil) sysfatal("readmemimage: %r"); if(xsize & PERCENT) xsize = ((xsize & ~PERCENT) * Dx(im->r)) / 100; if(ysize & PERCENT) ysize = ((ysize & ~PERCENT) * Dy(im->r)) / 100; if(xsize || ysize){ if(ysize == 0) ysize = (xsize * Dy(im->r)) / Dx(im->r); if(xsize == 0) xsize = (ysize * Dx(im->r)) / Dy(im->r); ochan = im->chan; switch(ochan){ default: for(tchan = ochan; tchan; tchan >>= 8) if(TYPE(tchan) == CAlpha){ tchan = RGBA32; break; } if(tchan == 0) tchan = RGB24; break; case GREY8: case RGB24: case RGBA32: case ARGB32: case XRGB32: tchan = ochan; break; case GREY1: case GREY2: case GREY4: tchan = GREY8; break; } if(tchan != ochan){ if((nim = allocmemimage(im->r, tchan)) == nil) sysfatal("allocimage: %r"); memimagedraw(nim, nim->r, im, im->r.min, nil, ZP, S); freememimage(im); im = nim; } if((nim = allocmemimage( Rect(im->r.min.x, im->r.min.y, im->r.min.x+xsize, im->r.min.y+ysize), tchan)) == nil) sysfatal("allocmemimage: %r"); resample(nim, nim->r, im, im->r); freememimage(im); im = nim; if(tchan != ochan){ if((im = allocmemimage(nim->r, ochan)) == nil) sysfatal("allocimage: %r"); memimagedraw(im, im->r, nim, nim->r.min, nil, ZP, S); freememimage(nim); } } if(writememimage(1, im) < 0) sysfatal("writememimage: %r"); exits(0); }
void threadmain(int argc, char *argv[]) { int n; uchar score[VtScoreSize]; uchar *buf; char *host, *type; vlong off; VtEntry e; VtRoot root; VtCache *c; VtConn *z; VtFile *f; quotefmtinstall(); fmtinstall('F', vtfcallfmt); fmtinstall('V', vtscorefmt); host = nil; ARGBEGIN{ case 'V': chattyventi++; break; case 'h': host = EARGF(usage()); break; case 'v': chatty++; break; default: usage(); break; }ARGEND if(argc != 1) usage(); type = nil; if(vtparsescore(argv[0], &type, score) < 0) sysfatal("could not parse score '%s': %r", argv[0]); if(type == nil || strcmp(type, "file") != 0) sysfatal("bad score - not file:..."); buf = vtmallocz(VtMaxLumpSize); z = vtdial(host); if(z == nil) sysfatal("could not connect to server: %r"); if(vtconnect(z) < 0) sysfatal("vtconnect: %r"); // root block ... n = vtread(z, score, VtRootType, buf, VtMaxLumpSize); if(n < 0) sysfatal("could not read root %V: %r", score); if(n != VtRootSize) sysfatal("root block %V is wrong size %d != %d", score, n, VtRootSize); if(vtrootunpack(&root, buf) < 0) sysfatal("unpacking root block %V: %r", score); if(strcmp(root.type, "file") != 0) sysfatal("bad root type %q (not 'file')", root.type); if(chatty) fprint(2, "%V: %q %q %V %d %V\n", score, root.name, root.type, root.score, root.blocksize, root.prev); // ... points at entry block n = vtread(z, root.score, VtDirType, buf, VtMaxLumpSize); if(n < 0) sysfatal("could not read entry %V: %r", root.score); if(n != VtEntrySize) sysfatal("dir block %V is wrong size %d != %d", root.score, n, VtEntrySize); if(vtentryunpack(&e, buf, 0) < 0) sysfatal("unpacking dir block %V: %r", root.score); if((e.type&VtTypeBaseMask) != VtDataType) sysfatal("not a single file"); // open and read file c = vtcachealloc(z, root.blocksize*32); if(c == nil) sysfatal("vtcachealloc: %r"); f = vtfileopenroot(c, &e); if(f == nil) sysfatal("vtfileopenroot: %r"); off = 0; vtfilelock(f, VtOREAD); while((n = vtfileread(f, buf, VtMaxLumpSize, off)) > 0){ write(1, buf, n); off += n; } threadexitsall(0); }
static int xls(int argc, char *argv[]) { MIXP_MESSAGE m; MIXP_STAT *stat; MIXP_CFID *fid; char *file, *buf; int lflag, dflag, count, nstat, mstat, i; lflag = dflag = 0; ARGBEGIN{ case 'l': lflag++; break; case 'd': dflag++; break; default: usage(); }ARGEND; file = EARGF(usage()); stat = mixp_stat(client, file); if(stat == NULL) fatal("cannot stat file '%s': %s\n", file, mixp_errbuf()); if(dflag || (stat->mode&P9_DMDIR) == 0) { print_stat(stat, lflag); mixp_stat_free(stat); return 0; } mixp_stat_free(stat); fid = mixp_open(client, file, P9_OREAD); if(fid == NULL) fatal("Can't open file '%s': %s\n", file, mixp_errbuf()); nstat = 0; mstat = 16; stat = malloc(sizeof(*stat) * mstat); buf = malloc(fid->iounit); while((count = mixp_read(fid, buf, fid->iounit)) > 0) { m = mixp_message(buf, count, MsgUnpack); while(m.pos < m.end) { if(nstat == mstat) { mstat <<= 1; stat = ixp_erealloc(stat, sizeof(*stat) * mstat); } mixp_pstat(&m, &stat[nstat++]); } } qsort(stat, nstat, sizeof(*stat), comp_stat); for(i = 0; i < nstat; i++) { print_stat(&stat[i], lflag); mixp_stat_free(&stat[i]); } free(stat); if(count == -1) fatal("cannot read directory '%s': %s\n", file, mixp_errbuf()); return 0; }
void main(int argc, char *argv[]) { int i, c; char *a; char name[LIBNAMELEN]; Binit(&bso, 1, OWRITE); cout = -1; listinit(); memset(debug, 0, sizeof(debug)); nerrors = 0; outfile = "8.out"; HEADTYPE = -1; INITTEXT = -1; INITTEXTP = -1; INITDAT = -1; INITRND = -1; INITENTRY = 0; ARGBEGIN { default: c = ARGC(); if(c >= 0 && c < sizeof(debug)) debug[c]++; break; case 'o': /* output to (next arg) */ outfile = ARGF(); break; case 'E': a = ARGF(); if(a) INITENTRY = a; break; case 'H': a = ARGF(); if(a) HEADTYPE = atolwhex(a); break; case 'L': addlibpath(EARGF(usage())); break; case 'T': a = ARGF(); if(a) INITTEXT = atolwhex(a); break; case 'P': a = ARGF(); if(a) INITTEXTP = atolwhex(a); break; case 'D': a = ARGF(); if(a) INITDAT = atolwhex(a); break; case 'R': a = ARGF(); if(a) INITRND = atolwhex(a); break; case 'x': /* produce export table */ doexp = 1; if(argv[1] != nil && argv[1][0] != '-' && !isobjfile(argv[1])){ a = ARGF(); if(strcmp(a, "*") == 0) allexport = 1; else readundefs(a, SEXPORT); } break; case 'u': /* produce dynamically loadable module */ dlm = 1; debug['l']++; if(argv[1] != nil && argv[1][0] != '-' && !isobjfile(argv[1])) readundefs(ARGF(), SIMPORT); break; } ARGEND USED(argc); if(*argv == 0) usage(); if(!debug['9'] && !debug['U'] && !debug['B']) debug[DEFAULT] = 1; a = getenv("ccroot"); if(a != nil && *a != '\0') { if(!fileexists(a)) { diag("nonexistent $ccroot: %s", a); errorexit(); } }else a = ""; snprint(name, sizeof(name), "%s/%s/lib", a, thestring); addlibpath(name); if(HEADTYPE == -1) { if(debug['U']) HEADTYPE = 1; if(debug['B']) HEADTYPE = 2; if(debug['9']) HEADTYPE = 2; } switch(HEADTYPE) { default: diag("unknown -H option"); errorexit(); case 0: /* this is garbage */ HEADR = 20L+56L; if(INITTEXT == -1) INITTEXT = 0x40004CL; if(INITDAT == -1) INITDAT = 0x10000000L; if(INITRND == -1) INITRND = 0; break; case 1: /* is unix coff */ HEADR = 0xd0L; if(INITTEXT == -1) INITTEXT = 0xd0; if(INITDAT == -1) INITDAT = 0x400000; if(INITRND == -1) INITRND = 0; break; case 2: /* plan 9 */ HEADR = 32L; if(INITTEXT == -1) INITTEXT = 4096+32; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 4096; break; case 3: /* MS-DOS .COM */ HEADR = 0; if(INITTEXT == -1) INITTEXT = 0x0100; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 4; break; case 4: /* fake MS-DOS .EXE */ HEADR = 0x200; if(INITTEXT == -1) INITTEXT = 0x0100; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 4; HEADR += (INITTEXT & 0xFFFF); if(debug['v']) Bprint(&bso, "HEADR = 0x%ld\n", HEADR); break; case 5: /* elf executable */ HEADR = rnd(Ehdr32sz+3*Phdr32sz, 16); if(INITTEXT == -1) INITTEXT = 0x80100020L; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 4096; break; } if (INITTEXTP == -1) INITTEXTP = INITTEXT; if(INITDAT != 0 && INITRND != 0) print("warning: -D0x%lux is ignored because of -R0x%lux\n", INITDAT, INITRND); if(debug['v']) Bprint(&bso, "HEADER = -H0x%ld -T0x%lux -D0x%lux -R0x%lux\n", HEADTYPE, INITTEXT, INITDAT, INITRND); Bflush(&bso); for(i=1; optab[i].as; i++) if(i != optab[i].as) { diag("phase error in optab: %d", i); errorexit(); } for(i=0; i<Ymax; i++) ycover[i*Ymax + i] = 1; ycover[Yi0*Ymax + Yi8] = 1; ycover[Yi1*Ymax + Yi8] = 1; ycover[Yi0*Ymax + Yi32] = 1; ycover[Yi1*Ymax + Yi32] = 1; ycover[Yi8*Ymax + Yi32] = 1; ycover[Yal*Ymax + Yrb] = 1; ycover[Ycl*Ymax + Yrb] = 1; ycover[Yax*Ymax + Yrb] = 1; ycover[Ycx*Ymax + Yrb] = 1; ycover[Yrx*Ymax + Yrb] = 1; ycover[Yax*Ymax + Yrx] = 1; ycover[Ycx*Ymax + Yrx] = 1; ycover[Yax*Ymax + Yrl] = 1; ycover[Ycx*Ymax + Yrl] = 1; ycover[Yrx*Ymax + Yrl] = 1; ycover[Yf0*Ymax + Yrf] = 1; ycover[Yal*Ymax + Ymb] = 1; ycover[Ycl*Ymax + Ymb] = 1; ycover[Yax*Ymax + Ymb] = 1; ycover[Ycx*Ymax + Ymb] = 1; ycover[Yrx*Ymax + Ymb] = 1; ycover[Yrb*Ymax + Ymb] = 1; ycover[Ym*Ymax + Ymb] = 1; ycover[Yax*Ymax + Yml] = 1; ycover[Ycx*Ymax + Yml] = 1; ycover[Yrx*Ymax + Yml] = 1; ycover[Yrl*Ymax + Yml] = 1; ycover[Ym*Ymax + Yml] = 1; for(i=0; i<D_NONE; i++) { reg[i] = -1; if(i >= D_AL && i <= D_BH) reg[i] = (i-D_AL) & 7; if(i >= D_AX && i <= D_DI) reg[i] = (i-D_AX) & 7; if(i >= D_F0 && i <= D_F0+7) reg[i] = (i-D_F0) & 7; } zprg.link = P; zprg.pcond = P; zprg.back = 2; zprg.as = AGOK; zprg.from.type = D_NONE; zprg.from.index = D_NONE; zprg.from.scale = 1; zprg.to = zprg.from; pcstr = "%.6lux "; nuxiinit(); histgen = 0; textp = P; datap = P; edatap = P; pc = 0; dtype = 4; cout = create(outfile, 1, 0775); if(cout < 0) { diag("cannot create %s: %r", outfile); errorexit(); } version = 0; cbp = buf.cbuf; cbc = sizeof(buf.cbuf); firstp = prg(); lastp = firstp; if(INITENTRY == 0) { INITENTRY = "_main"; if(debug['p']) INITENTRY = "_mainp"; if(!debug['l']) lookup(INITENTRY, 0)->type = SXREF; } else if(!(*INITENTRY >= '0' && *INITENTRY <= '9')) lookup(INITENTRY, 0)->type = SXREF; while(*argv) objfile(*argv++); if(!debug['l']) loadlib(); firstp = firstp->link; if(firstp == P) errorexit(); if(doexp || dlm){ EXPTAB = "_exporttab"; zerosig(EXPTAB); zerosig("etext"); zerosig("edata"); zerosig("end"); if(dlm){ import(); HEADTYPE = 2; INITTEXT = INITDAT = 0; INITRND = 8; INITENTRY = EXPTAB; } export();
void main(int argc, char **argv) { int srvfd, pipefd[2], stdio; Xfsub **xs; stdio = 0; ARGBEGIN { case '9': noplan9 = 1; break; case 'c': nclust = atoi(EARGF(usage())); if (nclust <= 0) sysfatal("nclust %d non-positive", nclust); break; case 'f': deffile = EARGF(usage()); break; case 'r': norock = 1; break; case 's': stdio = 1; break; case 'v': chatty = 1; break; case 'J': nojoliet = 1; break; default: usage(); } ARGEND switch(argc) { case 0: break; case 1: srvname = argv[0]; break; default: usage(); } iobuf_init(); for(xs=xsublist; *xs; xs++) (*(*xs)->reset)(); if(stdio) { pipefd[0] = 0; pipefd[1] = 1; } else { close(0); close(1); open("/dev/null", OREAD); open("/dev/null", OWRITE); if(pipe(pipefd) < 0) panic(1, "pipe"); sprint(srvfile, "/srv/%s", srvname); srvfd = create(srvfile, OWRITE|ORCLOSE, 0600); if(srvfd < 0) panic(1, srvfile); fprint(srvfd, "%d", pipefd[0]); close(pipefd[0]); fprint(2, "%s %d: serving %s\n", argv0, getpid(), srvfile); } srvfd = pipefd[1]; switch(rfork(RFNOWAIT|RFNOTEG|RFFDG|RFPROC)){ case -1: panic(1, "fork"); default: _exits(0); case 0: break; } io(srvfd); exits(0); }
void main(int argc, char **argv) { uchar *pkt; char *buf, *file, *p, *e; int fd, cfd; int n; Binit(&out, 1, OWRITE); fmtinstall('E', eipfmt); fmtinstall('V', eipfmt); fmtinstall('I', eipfmt); fmtinstall('H', encodefmt); fmtinstall('F', fcallfmt); pkt = malloc(Pktlen+16); pkt += 16; buf = malloc(Blen); e = buf+Blen-1; pflag = 1; Nflag = 32; sflag = 0; mkprotograph(); ARGBEGIN{ default: usage(); case '?': printusage(); printhelp(ARGF()); exits(0); break; case 'M': p = EARGF(usage()); Mflag = atoi(p); break; case 'N': p = EARGF(usage()); Nflag = atoi(p); break; case 'f': p = EARGF(usage()); yyinit(p); yyparse(); break; case 's': sflag = 1; break; case 'h': p = EARGF(usage()); root = findproto(p); if(root == nil) sysfatal("unknown protocol: %s", p); break; case 'd': toflag = 1; break; case 'D': toflag = 1; pcap = 1; break; case 't': tiflag = 1; break; case 'C': Cflag = 1; break; case 'p': pflag = 0; break; }ARGEND; if(pcap) pcaphdr(); if(argc == 0){ file = "/net/ether0"; if(root != nil) root = ðer; } else file = argv[0]; if((!tiflag) && strstr(file, "ether")){ if(root == nil) root = ðer; snprint(buf, Blen, "%s!-1", file); fd = dial(buf, 0, 0, &cfd); if(fd < 0) sysfatal("dialing %s: %r", buf); if(pflag && fprint(cfd, prom, strlen(prom)) < 0) sysfatal("setting %s", prom); } else if((!tiflag) && strstr(file, "ipifc")){ if(root == nil) root = &ip; snprint(buf, Blen, "%s/snoop", file); fd = open(buf, OREAD); if(fd < 0) sysfatal("opening %s: %r", buf); } else { if(root == nil) root = ðer; fd = open(file, OREAD); if(fd < 0) sysfatal("opening %s: %r", file); } filter = compile(filter); if(tiflag){ /* read a trace file */ for(;;){ n = read(fd, pkt, 10); if(n != 10) break; pkttime = NetL(pkt+2); pkttime = (pkttime<<32) | NetL(pkt+6); if(starttime == 0LL) starttime = pkttime; n = NetS(pkt); if(readn(fd, pkt, n) != n) break; if(filterpkt(filter, pkt, pkt+n, root, 1)) if(toflag) tracepkt(pkt, n); else printpkt(buf, e, pkt, pkt+n); } } else { /* read a real time stream */ starttime = nsec(); for(;;){ n = root->framer(fd, pkt, Pktlen); if(n <= 0) break; pkttime = nsec(); if(filterpkt(filter, pkt, pkt+n, root, 1)) if(toflag) tracepkt(pkt, n); else printpkt(buf, e, pkt, pkt+n); } } }
void main(int argc, char **argv) { int auth, x; char *mtpt, *service, *where, *user; Netbuf n; UserPasswd *up; mtpt = "/mnt/news"; service = nil; memset(&n, 0, sizeof n); user = nil; auth = 0; ARGBEGIN{ case 'D': chatty9p++; break; case 'N': netdebug = 1; break; case 'a': auth = 1; break; case 'u': user = EARGF(usage()); break; case 's': service = EARGF(usage()); break; case 'm': mtpt = EARGF(usage()); break; default: usage(); }ARGEND if(argc > 1) usage(); if(argc==0) where = "$nntp"; else where = argv[0]; now = time(0); net = &n; if(auth) { n.auth = 1; if(user) up = auth_getuserpasswd(auth_getkey, "proto=pass service=nntp server=%q user=%q", where, user); else up = auth_getuserpasswd(auth_getkey, "proto=pass service=nntp server=%q", where); if(up == nil) sysfatal("no password: %r"); n.user = up->user; n.pass = up->passwd; } n.addr = netmkaddr(where, "tcp", "nntp"); root = emalloc(sizeof *root); root->name = estrdup(""); root->parent = root; n.fd = -1; if(nntpconnect(&n) < 0) sysfatal("nntpconnect: %s", n.response); x=netdebug; netdebug=0; nntprefreshall(&n); netdebug=x; // dumpgroups(root, 0); postmountsrv(&nntpsrv, service, mtpt, MREPL); exits(nil); }
void main(int argc, char **argv) { int p[2], pid, i, j, n, off, npad, prefix; char **av, *q, *r, *tofree, *name; char nambuf[100]; Biobuf *bin, *bout; Type *t; Field *f; quotefmtinstall(); oargc = argc; oargv = argv; av = emalloc((30+argc)*sizeof av[0]); atexit(waitforgcc); n = 0; av[n++] = "gcc"; av[n++] = "-c"; av[n++] = "-fdollars-in-identifiers"; av[n++] = "-S"; // write assembly av[n++] = "-gstabs"; // include stabs info av[n++] = "-o-"; // to stdout av[n++] = "-xc"; // read C ARGBEGIN{ case 'g': lang = &go; pkg = EARGF(usage()); break; case 'c': av[0] = EARGF(usage()); break; case 'f': av[n++] = EARGF(usage()); break; default: usage(); }ARGEND if(argc == 0) av[n++] = "-"; else av[n++] = argv[0]; av[n] = nil; // Run gcc writing assembly and stabs debugging to p[1]. if(pipe(p) < 0) sysfatal("pipe: %r"); pid = fork(); if(pid < 0) sysfatal("fork: %r"); if(pid == 0) { close(p[0]); dup(p[1], 1); if(argc == 0) { exec(av[0], av); fprint(2, "exec gcc: %r\n"); exit(1); } // Some versions of gcc do not accept -S with multiple files. // Run gcc once for each file. close(0); open("/dev/null", OREAD); for(i=0; i<argc; i++) { pid = fork(); if(pid < 0) sysfatal("fork: %r"); if(pid == 0) { av[n-1] = argv[i]; exec(av[0], av); fprint(2, "exec gcc: %r\n"); exit(1); } waitpid(); } exit(0); } close(p[1]); // Read assembly, pulling out .stabs lines. bin = Bfdopen(p[0], OREAD); while((q = Brdstr(bin, '\n', 1)) != nil) { // .stabs "float:t(0,12)=r(0,1);4;0;",128,0,0,0 tofree = q; while(*q == ' ' || *q == '\t') q++; if(strncmp(q, ".stabs", 6) != 0) goto Continue; q += 6; while(*q == ' ' || *q == '\t') q++; if(*q++ != '\"') { Bad: sysfatal("cannot parse .stabs line:\n%s", tofree); } r = strchr(q, '\"'); if(r == nil) goto Bad; *r++ = '\0'; if(*r++ != ',') goto Bad; if(*r < '0' || *r > '9') goto Bad; if(atoi(r) != 128) // stabs kind = local symbol goto Continue; parsestabtype(q); Continue: free(tofree); } Bterm(bin); waitpid(); // Write defs to standard output. bout = Bfdopen(1, OWRITE); fmtinstall('T', lang->typefmt); // Echo original command line in header. Bprint(bout, "//"); for(i=0; i<oargc; i++) Bprint(bout, " %q", oargv[i]); Bprint(bout, "\n"); Bprint(bout, "\n"); Bprint(bout, "// MACHINE GENERATED - DO NOT EDIT.\n"); Bprint(bout, "\n"); if(pkg) Bprint(bout, "package %s\n\n", pkg); // Constants. Bprint(bout, "// Constants\n"); if(ncon > 0) { Bprint(bout, lang->constbegin); for(i=0; i<ncon; i++) Bprint(bout, lang->constfmt, con[i].name, con[i].value); Bprint(bout, lang->constend); } Bprint(bout, "\n"); // Types // push our names down for(i=0; i<ntyp; i++) { t = typ[i]; name = t->name; while(t && t->kind == Typedef) t = t->type; if(t) t->name = name; } Bprint(bout, "// Types\n"); // Have to turn off structure padding in Plan 9 compiler, // mainly because it is more aggressive than gcc tends to be. if(lang == &c) Bprint(bout, "#pragma pack on\n"); for(i=0; i<ntyp; i++) { Bprint(bout, "\n"); t = typ[i]; name = t->name; while(t && t->kind == Typedef) { if(name == nil && t->name != nil) { name = t->name; if(t->printed) break; } t = t->type; } if(name == nil && t->name != nil) { name = t->name; if(t->printed) continue; t->printed = 1; } if(name == nil) { fprint(2, "unknown name for %T", typ[i]); continue; } if(name[0] == '$') name++; npad = 0; off = 0; switch(t->kind) { case 0: fprint(2, "unknown type definition for %s\n", name); break; default: // numeric, array, or pointer case Array: case Ptr: Bprint(bout, "%s %lT\n", lang->typdef, name, t); break; case Union: // In Go, print union as struct with only first element, // padded the rest of the way. Bprint(bout, lang->unionbegin, name, name, name); goto StructBody; case Struct: Bprint(bout, lang->structbegin, name, name, name); StructBody: prefix = 0; if(lang == &go) prefix = prefixlen(t); for(j=0; j<t->nf; j++) { f = &t->f[j]; // padding if(t->kind == Struct || lang == &go) { if(f->offset%8 != 0 || f->size%8 != 0) { fprint(2, "ignoring bitfield %s.%s\n", t->name, f->name); continue; } if(f->offset < off) sysfatal("%s: struct fields went backward", t->name); if(off < f->offset) { Bprint(bout, lang->structpadfmt, npad++, (f->offset - off) / 8); off = f->offset; } off += f->size; } name = f->name; if(cutprefix(name)) name += prefix; if(strcmp(name, "") == 0) { snprint(nambuf, sizeof nambuf, "Pad%d", npad++); name = nambuf; } Bprint(bout, "\t%#lT;\n", name, f->type); if(t->kind == Union && lang == &go) break; } // final padding if(t->kind == Struct || lang == &go) { if(off/8 < t->size) Bprint(bout, lang->structpadfmt, npad++, t->size - off/8); } Bprint(bout, lang->structend); } } if(lang == &c) Bprint(bout, "#pragma pack off\n"); Bterm(bout); exit(0); }
void threadmain(int argc, char *argv[]) { int vers; ArenaPart *ap; Part *part; Arena *arena; u64int addr, limit, asize, apsize; char *file, *name, aname[ANameSize]; int i, n, blocksize, tabsize, zero; ventifmtinstall(); statsinit(); blocksize = 8 * 1024; asize = 512 * 1024 *1024; tabsize = 512 * 1024; /* BUG: should be determine from number of arenas */ zero = -1; vers = ArenaVersion5; ARGBEGIN{ case 'D': settrace(EARGF(usage())); break; case 'a': asize = unittoull(EARGF(usage())); if(asize == TWID64) usage(); break; case 'b': blocksize = unittoull(EARGF(usage())); if(blocksize == ~0) usage(); if(blocksize > MaxDiskBlock) { fprint(2, "block size too large, max %d\n", MaxDiskBlock); threadexitsall("usage"); } break; case '4': vers = ArenaVersion4; break; case 'Z': zero = 0; break; default: usage(); break; } ARGEND if(zero == -1) { if(vers == ArenaVersion4) zero = 1; else zero = 0; } if(argc != 2) usage(); name = argv[0]; file = argv[1]; if(nameok(name) < 0) sysfatal("illegal name template %s", name); part = initpart(file, ORDWR|ODIRECT); if(part == nil) sysfatal("can't open partition %s: %r", file); if(zero) zeropart(part, blocksize); maxblocksize = blocksize; initdcache(20*blocksize); ap = newarenapart(part, blocksize, tabsize); if(ap == nil) sysfatal("can't initialize arena: %r"); apsize = ap->size - ap->arenabase; n = apsize / asize; if(apsize - (n * asize) >= MinArenaSize) n++; fprint(2, "fmtarenas %s: %,d arenas, %,lld bytes storage, %,d bytes for index map\n", file, n, apsize, ap->tabsize); ap->narenas = n; ap->map = MKNZ(AMap, n); ap->arenas = MKNZ(Arena*, n); addr = ap->arenabase; for(i = 0; i < n; i++) { limit = addr + asize; if(limit >= ap->size || ap->size - limit < MinArenaSize) { limit = ap->size; if(limit - addr < MinArenaSize) sysfatal("bad arena set math: runt arena at %lld,%lld %lld", addr, limit, ap->size); } snprint(aname, ANameSize, "%s%d", name, i); if(0) fprint(2, "adding arena %s at [%lld,%lld)\n", aname, addr, limit); arena = newarena(part, vers, aname, addr, limit - addr, blocksize); if(!arena) fprint(2, "can't make new arena %s: %r", aname); freearena(arena); ap->map[i].start = addr; ap->map[i].stop = limit; namecp(ap->map[i].name, aname); addr = limit; } if(wbarenapart(ap) < 0) fprint(2, "can't write back arena partition header for %s: %r\n", file); flushdcache(); threadexitsall(0); }
void main(int argc, char **argv) { int fix; ulong block, newnull, cblock; vlong maxsize; uvlong length, clength; char buf[256], *dumpname, *proto, *s, *src, *status; Cdimg *cd; Cdinfo info; XDir dir; Direc *iconform, idumproot, iroot, *jconform, jdumproot, jroot, *r; Dump *dump; fix = 0; status = nil; memset(&info, 0, sizeof info); proto = "/sys/lib/sysconfig/proto/allproto"; src = "./"; info.volumename = atom("9CD"); info.volumeset = atom("9VolumeSet"); info.publisher = atom("9Publisher"); info.preparer = atom("dump9660"); info.application = atom("dump9660"); info.flags = CDdump; maxsize = 0; mk9660 = 0; fmtinstall('H', encodefmt); ARGBEGIN{ case 'D': chatty++; break; case 'M': mk9660 = 1; argv0 = "disk/mk9660"; info.flags &= ~CDdump; break; case '9': info.flags |= CDplan9; break; case ':': docolon = 1; break; case 'a': doabort = 1; break; case 'B': info.flags |= CDbootnoemu; /* fall through */ case 'b': if(!mk9660) usage(); info.flags |= CDbootable; info.bootimage = EARGF(usage()); break; case 'c': info.flags |= CDconform; break; case 'f': fix = 1; break; case 'j': info.flags |= CDjoliet; break; case 'n': now = atoi(EARGF(usage())); break; case 'm': maxsize = strtoull(EARGF(usage()), 0, 0); break; case 'o': dataoffset = atoll(EARGF(usage())); blocksize = atoi(EARGF(usage())); if(blocksize%Blocksize) sysfatal("bad block size %d -- must be multiple of 2048", blocksize); blocksize /= Blocksize; break; case 'p': proto = EARGF(usage()); break; case 'r': info.flags |= CDrockridge; break; case 's': src = EARGF(usage()); break; case 'v': info.volumename = atom(EARGF(usage())); break; case 'x': info.flags |= CDpbs; info.loader = EARGF(usage()); break; default: usage(); }ARGEND if(info.flags & CDpbs && !(info.flags & CDbootnoemu)) usage(); if(mk9660 && (fix || now || maxsize)) usage(); if(argc != 1) usage(); if(now == 0) now = (ulong)time(0); if(mk9660){ if((cd = createcd(argv[0], info)) == nil) sysfatal("cannot create '%s': %r", argv[0]); }else{ if((cd = opencd(argv[0], info)) == nil) sysfatal("cannot open '%s': %r", argv[0]); if(!(cd->flags & CDdump)) sysfatal("not a dump cd"); } /* create ISO9660/Plan 9 tree in memory */ memset(&dir, 0, sizeof dir); dir.name = atom(""); dir.uid = atom("sys"); dir.gid = atom("sys"); dir.uidno = 0; dir.gidno = 0; dir.mode = DMDIR | 0755; dir.mtime = now; dir.atime = now; dir.ctime = now; mkdirec(&iroot, &dir); iroot.srcfile = src; /* * Read new files into memory */ if(rdproto(proto, src, addprotofile, nil, &iroot) < 0) sysfatal("rdproto: %r"); if(mk9660){ dump = emalloc(sizeof *dump); dumpname = nil; }else{ /* * Read current dump tree and _conform.map. */ idumproot = readdumpdirs(cd, &dir, isostring); readdumpconform(cd); if(cd->flags & CDjoliet) jdumproot = readdumpdirs(cd, &dir, jolietstring); if(fix){ dumpname = nil; cd->nextblock = cd->nulldump+1; cd->nulldump = 0; Cwseek(cd, (vlong)cd->nextblock * Blocksize); goto Dofix; } dumpname = adddumpdir(&idumproot, now, &dir); /* note that we assume all names are conforming and thus sorted */ if(cd->flags & CDjoliet) { s = adddumpdir(&jdumproot, now, &dir); if(s != dumpname) sysfatal("dumpnames don't match %s %s", dumpname, s); } dump = dumpcd(cd, &idumproot); cd->nextblock = cd->nulldump+1; } /* * Write new files, starting where the dump tree was. * Must be done before creation of the Joliet tree so that * blocks and lengths are correct. */ if(dataoffset > (vlong)cd->nextblock * Blocksize) cd->nextblock = (dataoffset+Blocksize-1)/Blocksize; Cwseek(cd, (vlong)cd->nextblock * Blocksize); writefiles(dump, cd, &iroot); if(cd->bootimage){ findbootimage(cd, &iroot); if(cd->loader) findloader(cd, &iroot); Cupdatebootcat(cd); } /* create Joliet tree */ if(cd->flags & CDjoliet) copydirec(&jroot, &iroot); if(info.flags & CDconform) { checknames(&iroot, isbadiso9660); convertnames(&iroot, struprcpy); } else convertnames(&iroot, (void *) strcpy); // isoabstract = findconform(&iroot, abstract); // isobiblio = findconform(&iroot, biblio); // isonotice = findconform(&iroot, notice); dsort(&iroot, isocmp); if(cd->flags & CDjoliet) { // jabstract = findconform(&jroot, abstract); // jbiblio = findconform(&jroot, biblio); // jnotice = findconform(&jroot, notice); checknames(&jroot, isbadjoliet); convertnames(&jroot, (void *) strcpy); dsort(&jroot, jolietcmp); } /* * Write directories. */ writedirs(cd, &iroot, Cputisodir); if(cd->flags & CDjoliet) writedirs(cd, &jroot, Cputjolietdir); if(mk9660){ cblock = 0; clength = 0; newnull = 0; }else{ /* * Write incremental _conform.map block. */ wrconform(cd, cd->nconform, &cblock, &clength); /* jump here if we're just fixing up the cd */ Dofix: /* * Write null dump header block; everything after this will be * overwritten at the next dump. Because of this, it needs to be * reconstructable. We reconstruct the _conform.map and dump trees * from the header blocks in dump.c, and we reconstruct the path * tables by walking the cd. */ newnull = Cputdumpblock(cd); } if(info.flags & CDpbs) Cfillpbs(cd); /* * Write _conform.map. */ dir.mode = 0444; if(cd->flags & (CDconform|CDjoliet)) { if(!mk9660 && cd->nconform == 0){ block = cblock; length = clength; }else wrconform(cd, 0, &block, &length); if(mk9660) { idumproot = iroot; jdumproot = jroot; } if(length) { /* The ISO9660 name will get turned into uppercase when written. */ if((iconform = walkdirec(&idumproot, "_conform.map")) == nil) iconform = adddirec(&idumproot, "_conform.map", &dir); jconform = nil; if(cd->flags & CDjoliet) { if((jconform = walkdirec(&jdumproot, "_conform.map")) == nil) jconform = adddirec(&jdumproot, "_conform.map", &dir); } iconform->block = block; iconform->length = length; if(cd->flags & CDjoliet) { jconform->block = block; jconform->length = length; } } if(mk9660) { iroot = idumproot; jroot = jdumproot; } } if(mk9660){ /* * Patch in root directories. */ setroot(cd, cd->iso9660pvd, iroot.block, iroot.length); setvolsize(cd, cd->iso9660pvd, cd->nextblock); if(cd->flags & CDjoliet){ setroot(cd, cd->jolietsvd, jroot.block, jroot.length); setvolsize(cd, cd->jolietsvd, cd->nextblock); } }else{ /* * Write dump tree at end. We assume the name characters * are all conforming, so everything is already sorted properly. */ convertnames(&idumproot, (info.flags & CDconform) ? (void *) struprcpy : (void *) strcpy); if(cd->nulldump) { r = walkdirec(&idumproot, dumpname); assert(r != nil); copybutname(r, &iroot); } if(cd->flags & CDjoliet) { convertnames(&jdumproot, (void *) strcpy); if(cd->nulldump) { r = walkdirec(&jdumproot, dumpname); assert(r != nil); copybutname(r, &jroot); } } writedumpdirs(cd, &idumproot, Cputisodir); if(cd->flags & CDjoliet) writedumpdirs(cd, &jdumproot, Cputjolietdir); /* * Patch in new root directory entry. */ setroot(cd, cd->iso9660pvd, idumproot.block, idumproot.length); setvolsize(cd, cd->iso9660pvd, cd->nextblock); if(cd->flags & CDjoliet){ setroot(cd, cd->jolietsvd, jdumproot.block, jdumproot.length); setvolsize(cd, cd->jolietsvd, cd->nextblock); } } writepathtables(cd); if(!mk9660){ /* * If we've gotten too big, truncate back to what we started with, * fix up the cd, and exit with a non-zero status. */ Cwflush(cd); if(cd->nulldump && maxsize && Cwoffset(cd) > maxsize){ fprint(2, "too big; writing old tree back\n"); status = "cd too big; aborted"; rmdumpdir(&idumproot, dumpname); rmdumpdir(&jdumproot, dumpname); cd->nextblock = cd->nulldump+1; cd->nulldump = 0; Cwseek(cd, (vlong)cd->nextblock * Blocksize); goto Dofix; } /* * Write old null header block; this commits all our changes. */ if(cd->nulldump){ Cwseek(cd, (vlong)cd->nulldump * Blocksize); sprint(buf, "plan 9 dump cd\n"); sprint(buf+strlen(buf), "%s %lud %lud %lud %llud %lud %lud", dumpname, now, newnull, cblock, clength, iroot.block, iroot.length); if(cd->flags & CDjoliet) sprint(buf+strlen(buf), " %lud %lud", jroot.block, jroot.length); strcat(buf, "\n"); Cwrite(cd, buf, strlen(buf)); Cpadblock(cd); Cwflush(cd); } } fdtruncate(cd->fd, (vlong)cd->nextblock * Blocksize); exits(status); }
void threadmain(int argc, char **argv) { char *devdir; int i; long value[8], volume[8]; Audiocontrol *c; char *p; extern int attachok; Ep *ep; int csps[] = { Audiocsp, 0}; devdir = nil; volume[0] = Undef; for(i = 0; i<8; i++) value[i] = 0; fmtinstall('A', Aconv); fmtinstall('U', Ufmt); quotefmtinstall(); ARGBEGIN{ case 'N': p = EARGF(usage()); /* ignore dev nb */ break; case 'd': usbdebug++; verbose++; break; case 'm': mntpt = EARGF(usage()); break; case 'p': attachok++; break; case 's': srvpost = EARGF(usage()); break; case 'v': volume[0] = strtol(EARGF(usage()), &p, 0); for(i = 1; i < 8; i++) volume[i] = volume[0]; break; case 'V': verbose++; break; default: usage(); }ARGEND switch(argc){ case 0: break; case 1: devdir = argv[0]; break; default: usage(); } if(devdir == nil) if(finddevs(matchdevcsp, csps, &devdir, 1) < 1){ fprint(2, "No usb audio\n"); threadexitsall("usbaudio not found"); } ad = opendev(devdir); if(ad == nil) sysfatal("opendev: %r"); if(configdev(ad) < 0) sysfatal("configdev: %r"); for(i = 0; i < nelem(ad->usb->ddesc); i++) if(ad->usb->ddesc[i] != nil) switch(ad->usb->ddesc[i]->data.bDescriptorType){ case AUDIO_INTERFACE: audio_interface(ad, ad->usb->ddesc[i]); break; case AUDIO_ENDPOINT: audio_endpoint(ad, ad->usb->ddesc[i]); break; } controlchan = chancreate(sizeof(char*), 8); for(i = 0; i < nelem(ad->usb->ep); i++) if((ep = ad->usb->ep[i]) != nil){ if(ep->iface->csp == CSP(Claudio, 2, 0) && ep->dir == Eout) endpt[0] = ep->id; if(ep->iface->csp == CSP(Claudio, 2, 0) && ep->dir == Ein) endpt[1] = ep->id; if(buttonendpt<0 && Class(ep->iface->csp) == Clhid) buttonendpt = ep->id; } if(endpt[0] != -1){ if(verbose) fprint(2, "usb/audio: playback on ep %d\n", endpt[0]); interface[0] = ad->usb->ep[endpt[0]]->iface->id; } if(endpt[1] != -1){ if(verbose) fprint(2, "usb/audio: record on ep %d\n", endpt[0]); interface[1] = ad->usb->ep[endpt[1]]->iface->id; } if(verbose && buttonendpt >= 0) fprint(2, "usb/audio: buttons on ep %d\n", buttonendpt); if(endpt[Play] >= 0){ if(verbose) fprint(2, "Setting default play parameters: %d Hz, %d channels at %d bits\n", defaultspeed[Play], 2, 16); if(findalt(Play, 2, 16, defaultspeed[Play]) < 0){ if(findalt(Play, 2, 16, 48000) < 0) sysfatal("Can't configure playout for %d or %d Hz", defaultspeed[Play], 48000); fprint(2, "Warning, can't configure playout for %d Hz, configuring for %d Hz instead\n", defaultspeed[Play], 48000); defaultspeed[Play] = 48000; } value[0] = 2; if(setcontrol(Play, "channels", value) == Undef) sysfatal("Can't set play channels"); value[0] = 16; if(setcontrol(Play, "resolution", value) == Undef) sysfatal("Can't set play resolution"); } if(endpt[Record] >= 0){ setrec = 1; if(verbose) fprint(2, "Setting default record parameters: " "%d Hz, %d channels at %d bits\n", defaultspeed[Record], 2, 16); i = 2; while(findalt(Record, i, 16, defaultspeed[Record]) < 0) if(i == 2 && controls[Record][Channel_control].max == 1){ fprint(2, "Warning, can't configure stereo " "recording, configuring mono instead\n"); i = 1; }else break; if(findalt(Record, i, 16, 48000) < 0){ endpt[Record] = -1; /* disable recording */ setrec = 0; fprint(2, "Warning, can't configure record for %d Hz or %d Hz\n", defaultspeed[Record], 48000); }else fprint(2, "Warning, can't configure record for %d Hz, " "configuring for %d Hz instead\n", defaultspeed[Record], 48000); defaultspeed[Record] = 48000; if(setrec){ value[0] = i; if(setcontrol(Record, "channels", value) == Undef) sysfatal("Can't set record channels"); value[0] = 16; if(setcontrol(Record, "resolution", value) == Undef) sysfatal("Can't set record resolution"); } } getcontrols(); /* Get the initial value of all controls */ value[0] = defaultspeed[Play]; if(endpt[Play] >= 0 && setcontrol(Play, "speed", value) < 0) sysfatal("can't set play speed"); value[0] = defaultspeed[Record]; if(endpt[Record] >= 0 && setcontrol(Record, "speed", value) < 0) fprint(2, "%s: can't set record speed\n", argv0); value[0] = 0; setcontrol(Play, "mute", value); if(volume[0] != Undef){ c = &controls[Play][Volume_control]; if(*p == '%' && c->min != Undef) for(i = 0; i < 8; i++) volume[i] = (volume[i]*c->max + (100-volume[i])*c->min)/100; if(c->settable) setcontrol(Play, "volume", volume); c = &controls[Record][Volume_control]; if(c->settable && setrec) setcontrol(Record, "volume", volume); } if(buttonendpt > 0){ buttondev = openep(ad, buttonendpt); if(buttondev == nil) sysfatal("openep: buttons: %r"); if(opendevdata(buttondev, OREAD) < 0) sysfatal("open buttons fd: %r"); proccreate(buttonproc, nil, STACKSIZE); } proccreate(controlproc, nil, STACKSIZE); proccreate(serve, nil, STACKSIZE); threadexits(nil); }
void optparse(Server *s, char **argv) { int64 ms; char *arg, c, *tmp; # define EARGF(x) (*arg ? (tmp=arg,arg="",tmp) : *argv ? *argv++ : (x)) while ((arg = *argv++) && *arg++ == '-' && *arg) { while ((c = *arg++)) { switch (c) { case 'p': s->port = EARGF(flagusage("-p")); warn_systemd_ignored_option("-p", s->port); break; case 'l': s->addr = EARGF(flagusage("-l")); warn_systemd_ignored_option("-l", s->addr); break; case 'L': s->path = EARGF(flagusage("-L")); warn_systemd_ignored_option("-L", s->path); if (strlen(s->path) > 100) { warnx("local socket path is longer than 100 bytes"); exit(1); } break; case 'z': job_data_size_limit = parse_size_t(EARGF(flagusage("-z"))); break; case 's': s->wal.filesize = parse_size_t(EARGF(flagusage("-s"))); break; case 'c': s->wal.nocomp = 0; break; case 'n': s->wal.nocomp = 1; break; case 'f': ms = (int64)parse_size_t(EARGF(flagusage("-f"))); s->wal.syncrate = ms * 1000000; s->wal.wantsync = 1; break; case 'F': s->wal.wantsync = 0; break; case 'u': s->user = EARGF(flagusage("-u")); break; case 'b': s->wal.dir = EARGF(flagusage("-b")); s->wal.use = 1; break; case 'h': usage(0); case 'v': printf("beanstalkd %s\n", version); exit(0); case 'V': verbose++; break; default: warnx("unknown flag: %s", arg-2); usage(5); } } } if (arg) { warnx("unknown argument: %s", arg-1); usage(5); } }
void main(int argc, char *argv[]) { int c, i; char *p; Binit(&bso, 1, OWRITE); cout = -1; listinit(); nerrors = 0; outfile = "5.out"; HEADTYPE = -1; INITTEXT = -1; INITDAT = -1; INITRND = -1; INITENTRY = 0; p = getenv("GOARM"); if(p != nil && strcmp(p, "5") == 0) debug['F'] = 1; ARGBEGIN { default: c = ARGC(); if(c == 'l') usage(); if(c >= 0 && c < sizeof(debug)) debug[c]++; break; case 'o': outfile = EARGF(usage()); break; case 'E': INITENTRY = EARGF(usage()); break; case 'I': interpreter = EARGF(usage()); break; case 'L': Lflag(EARGF(usage())); break; case 'T': INITTEXT = atolwhex(EARGF(usage())); break; case 'D': INITDAT = atolwhex(EARGF(usage())); break; case 'R': INITRND = atolwhex(EARGF(usage())); break; case 'r': rpath = EARGF(usage()); break; case 'H': HEADTYPE = headtype(EARGF(usage())); /* do something about setting INITTEXT */ break; case 'V': print("%cl version %s\n", thechar, getgoversion()); errorexit(); } ARGEND USED(argc); if(argc != 1) usage(); libinit(); if(!debug['9'] && !debug['U'] && !debug['B']) debug[DEFAULT] = 1; if(HEADTYPE == -1) { if(debug['U']) HEADTYPE = Hnoheader; if(debug['B']) HEADTYPE = Hrisc; if(debug['9']) HEADTYPE = Hplan9x32; HEADTYPE = Hlinux; } switch(HEADTYPE) { default: diag("unknown -H option"); errorexit(); case Hnoheader: /* no header */ HEADR = 0L; if(INITTEXT == -1) INITTEXT = 0; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 4; break; case Hrisc: /* aif for risc os */ HEADR = 128L; if(INITTEXT == -1) INITTEXT = 0x10005000 + HEADR; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 4; break; case Hplan9x32: /* plan 9 */ HEADR = 32L; if(INITTEXT == -1) INITTEXT = 4128; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 4096; break; case Hnetbsd: /* boot for NetBSD */ HEADR = 32L; if(INITTEXT == -1) INITTEXT = 0xF0000020L; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 4096; break; case Hixp1200: /* boot for IXP1200 */ HEADR = 0L; if(INITTEXT == -1) INITTEXT = 0x0; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 4; break; case Hipaq: /* boot for ipaq */ HEADR = 16L; if(INITTEXT == -1) INITTEXT = 0xC0008010; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 1024; break; case Hlinux: /* arm elf */ debug['d'] = 1; // no dynamic linking elfinit(); HEADR = ELFRESERVE; if(INITTEXT == -1) INITTEXT = 0x10000 + HEADR; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 4096; break; } if(INITDAT != 0 && INITRND != 0) print("warning: -D0x%ux is ignored because of -R0x%ux\n", INITDAT, INITRND); if(debug['v']) Bprint(&bso, "HEADER = -H0x%d -T0x%ux -D0x%ux -R0x%ux\n", HEADTYPE, INITTEXT, INITDAT, INITRND); Bflush(&bso); zprg.as = AGOK; zprg.scond = 14; zprg.reg = NREG; zprg.from.name = D_NONE; zprg.from.type = D_NONE; zprg.from.reg = NREG; zprg.to = zprg.from; buildop(); histgen = 0; pc = 0; dtype = 4; nuxiinit(); version = 0; cbp = buf.cbuf; cbc = sizeof(buf.cbuf); addlibpath("command line", "command line", argv[0], "main"); loadlib(); // mark some functions that are only referenced after linker code editing // TODO(kaib): this doesn't work, the prog can't be found in runtime for(i=0; i<nelem(linkername); i++) mark(lookup(linkername[i], 0)); deadcode(); if(textp == nil) { diag("no code"); errorexit(); } patch(); if(debug['p']) if(debug['1']) doprof1(); else doprof2(); doelf(); follow(); softfloat(); noops(); dostkcheck(); span(); pclntab(); symtab(); dodata(); address(); doweak(); reloc(); asmb(); undef(); if(debug['c']) print("ARM size = %d\n", armsize); if(debug['v']) { Bprint(&bso, "%5.2f cpu time\n", cputime()); Bprint(&bso, "%d sizeof adr\n", sizeof(Adr)); Bprint(&bso, "%d sizeof prog\n", sizeof(Prog)); } Bflush(&bso); errorexit(); }
void threadmain(int argc, char *argv[]) { char *defsrv, *srvname; int p[2], fd; int stdio; char *host = nil; long ncache; stdio = 0; ncache = 256; fmtinstall('H', encodefmt); fmtinstall('V', vtscorefmt); fmtinstall('F', vtfcallfmt); defmnt = nil; defsrv = nil; ARGBEGIN{ case 'd': fmtinstall('F', fcallfmt); dflag = 1; break; case 'c': ncache = atoi(EARGF(usage())); break; case 'i': defmnt = nil; stdio = 1; mfd[0] = 0; mfd[1] = 1; break; case 'h': host = EARGF(usage()); break; case 'S': defsrv = EARGF(usage()); break; case 's': defsrv = "vacfs"; break; case 'm': defmnt = EARGF(usage()); break; case 'p': noperm = 1; break; case 'V': chattyventi = 1; break; default: usage(); }ARGEND if(argc != 1) usage(); if(defsrv == nil && defmnt == nil && !stdio) defmnt = "/n/vac"; if(stdio && defmnt) sysfatal("cannot use -m with -i"); initfcalls(); notify(notifyf); user = getuser(); conn = vtdial(host); if(conn == nil) sysfatal("could not connect to server: %r"); if(vtconnect(conn) < 0) sysfatal("vtconnect: %r"); fs = vacfsopen(conn, argv[0], VtOREAD, ncache); if(fs == nil) sysfatal("vacfsopen: %r"); if(!stdio){ if(pipe(p) < 0) sysfatal("pipe failed: %r"); mfd[0] = p[0]; mfd[1] = p[0]; srvfd = p[1]; if(defsrv){ srvname = smprint("/srv/%s", defsrv); fd = create(srvname, OWRITE|ORCLOSE, 0666); if(fd < 0) sysfatal("create %s: %r", srvname); if(fprint(fd, "%d", srvfd) < 0) sysfatal("write %s: %r", srvname); free(srvname); } } procrfork(srv, 0, Stacksize, RFFDG|RFNAMEG|RFNOTEG); if(!stdio){ close(p[0]); if(defmnt){ if(mount(srvfd, -1, defmnt, MREPL|MCREATE, "") < 0) sysfatal("mount %s: %r", defmnt); } } threadexits(0); }
void main(int argc, char *argv[]) { int c; char *a; char name[LIBNAMELEN]; Binit(&bso, 1, OWRITE); cout = -1; listinit(); outfile = 0; nerrors = 0; curtext = P; HEADTYPE = -1; INITTEXT = -1; INITTEXTP = -1; INITDAT = -1; INITRND = -1; INITENTRY = 0; ARGBEGIN { default: c = ARGC(); if(c >= 0 && c < sizeof(debug)) debug[c]++; break; case 'o': outfile = ARGF(); break; case 'E': a = ARGF(); if(a) INITENTRY = a; break; case 'L': addlibpath(EARGF(usage())); break; case 'T': a = ARGF(); if(a) INITTEXT = atolwhex(a); break; case 'P': a = ARGF(); if(a) INITTEXTP = atolwhex(a); break; case 'D': a = ARGF(); if(a) INITDAT = atolwhex(a); break; case 'R': a = ARGF(); if(a) INITRND = atolwhex(a); break; case 'H': a = ARGF(); if(a) HEADTYPE = atolwhex(a); break; case 'x': /* produce export table */ doexp = 1; if(argv[1] != nil && argv[1][0] != '-' && !isobjfile(argv[1])) readundefs(ARGF(), SEXPORT); break; case 'u': /* produce dynamically loadable module */ dlm = 1; if(argv[1] != nil && argv[1][0] != '-' && !isobjfile(argv[1])) readundefs(ARGF(), SIMPORT); break; } ARGEND USED(argc); if(*argv == 0) usage(); if(!debug['9'] && !debug['U'] && !debug['B']) debug[DEFAULT] = 1; a = getenv("ccroot"); if(a != nil && *a != '\0') { if(!fileexists(a)) { diag("nonexistent $ccroot: %s", a); errorexit(); } }else a = ""; snprint(name, sizeof(name), "%s/%s/lib", a, thestring); addlibpath(name); r0iszero = debug['0'] == 0; if(HEADTYPE == -1) { if(debug['U']) HEADTYPE = 0; if(debug['B']) HEADTYPE = 1; if(debug['9']) HEADTYPE = 2; } switch(HEADTYPE) { default: diag("unknown -H option"); errorexit(); case 0: /* boot */ HEADR = 32L; if(INITTEXT == -1) INITTEXT = 0x200000L; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 4096L; break; case 1: /* plan 9 q.out */ HEADR = 32L; if(INITTEXT == -1) INITTEXT = 4128; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 4096; break; case 2: /* plan 9 */ HEADR = 32L+8L; if(INITTEXT == -1) INITTEXT = 0x100000+HEADR; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 0x100000; break; case 3: /* raw */ HEADR = 0; if(INITTEXT == -1) INITTEXT = 4128; if(INITDAT == -1) { INITDAT = 0; INITRND = 4; } if(INITRND == -1) INITRND = 0; break; case 5: /* elf executable */ HEADR = rnd(Ehdr32sz+3*Phdr32sz, 16); if(INITTEXT == -1) INITTEXT = 0x00400000L+HEADR; if(INITDAT == -1) INITDAT = 0x10000000; if(INITRND == -1) INITRND = 0; break; case 9: /* ELF64 executable */ case 10: HEADR = rnd(Ehdr64sz+3*Phdr64sz, 16); if(INITTEXT == -1) INITTEXT = 0x100000+HEADR; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 0x100000; break; } if (INITTEXTP == -1) INITTEXTP = INITTEXT; if(INITDAT != 0 && INITRND != 0) print("warning: -D0x%llux is ignored because of -R0x%lux\n", INITDAT, INITRND); if(debug['v']) Bprint(&bso, "HEADER = -H0x%x -T0x%llux -D0x%llux -R0x%lux\n", HEADTYPE, INITTEXT, INITDAT, INITRND); Bflush(&bso); zprg.as = AGOK; zprg.reg = NREG; zprg.from.name = D_NONE; zprg.from.type = D_NONE; zprg.from.reg = NREG; zprg.from3 = zprg.from; zprg.to = zprg.from; buildop(); histgen = 0; textp = P; datap = P; pc = 0; dtype = 4; if(outfile == 0) outfile = "9.out"; cout = create(outfile, 1, 0775); if(cout < 0) { diag("cannot create %s: %r", outfile); errorexit(); } nuxiinit(); version = 0; cbp = buf.cbuf; cbc = sizeof(buf.cbuf); firstp = prg(); lastp = firstp; if(INITENTRY == 0) { INITENTRY = "_main"; if(debug['p']) INITENTRY = "_mainp"; if(!debug['l']) lookup(INITENTRY, 0)->type = SXREF; } else { /* * It's possibly a number handed in by -En (this is * the test made by entryvalue() when creating the appropriate * header). Calling lookup() on that will create the symbol 'n' * printing an undef() diagnostic later. */ a = INITENTRY; if(!(*a >= '0' && *a <= '9')) lookup(INITENTRY, 0)->type = SXREF; } while(*argv) objfile(*argv++); if(!debug['l']) loadlib(); firstp = firstp->link; if(firstp == P) goto out; if(doexp || dlm){ EXPTAB = "_exporttab"; zerosig(EXPTAB); zerosig("etext"); zerosig("edata"); zerosig("end"); if(dlm){ import(); HEADTYPE = 2; INITTEXT = 0; INITDAT = 0; INITRND = 8; INITENTRY = EXPTAB; } export();
int ethermain(Dev *dev, int argc, char **argv) { int epin, epout, i, devid; Ether *e; uint8_t ea[Eaddrlen]; devid = dev->id; memset(ea, 0, Eaddrlen); ARGBEGIN{ case 'a': if(parseaddr(ea, EARGF(usage())) < 0) return usage(); break; case 'd': if(etherdebug == 0) fprint(2, "ether debug on\n"); etherdebug++; break; case 'N': devid = atoi(EARGF(usage())); break; default: return usage(); }ARGEND if(argc != 0) { return usage(); } e = dev->aux = emallocz(sizeof(Ether), 1); e->dev = dev; dev->free = etherdevfree; memmove(e->addr, ea, Eaddrlen); e->Etherops.name = "cdc"; for(i = 0; i < nelem(ethers); i++) if(ethers[i](e) == 0) break; if(i == nelem(ethers)) return -1; if(e->Etherops.init == nil) e->Etherops.init = etherinit; if(e->Etherops.init(e, &epin, &epout) < 0) return -1; if(e->Etherops.bwrite == nil) e->Etherops.bwrite = etherbwrite; if(e->Etherops.bread == nil) e->Etherops.bread = etherbread; if(e->Etherops.bufsize == 0) e->Etherops.bufsize = Maxpkt; if(openeps(e, epin, epout) < 0) return -1; if(kernelproxy(e) == 0) return 0; e->fs = etherfs; snprint(e->fs.name, sizeof(e->fs.name), "etherU%d", devid); e->fs.dev = dev; e->fs.aux = e; e->bc = chancreate(sizeof(Buf*), Nbufs); e->rc = chancreate(sizeof(Buf*), Nconns/2); e->wc = chancreate(sizeof(Buf*), Nconns*2); incref(&e->dev->Ref); proccreate(etherwriteproc, e, 16*1024); incref(&e->dev->Ref); proccreate(etherreadproc, e, 16*1024); deprint(2, "%s: dev ref %ld\n", argv0, dev->Ref.ref); incref(&e->dev->Ref); usbfsadd(&e->fs); return 0; }
int main(int argc, char *argv[]) { DIR *dp; struct dirent *entry; pid_t pid; struct procstat ps; char cmdline[BUFSIZ], *cmd, *cmdbase = NULL, *p, *arg = NULL; int i, found = 0; int sflag = 0, oflag = 0; struct pidentry *pe; ARGBEGIN { case 's': sflag = 1; break; case 'o': oflag = 1; arg = EARGF(usage()); break; default: usage(); } ARGEND; if (!argc) return 1; SLIST_INIT(&omitpid_head); for (p = strtok(arg, ","); p; p = strtok(NULL, ",")) { pe = emalloc(sizeof(*pe)); if (strcmp(p, "%PPID") == 0) pe->pid = getppid(); else pe->pid = estrtol(p, 10); SLIST_INSERT_HEAD(&omitpid_head, pe, entry); } if (!(dp = opendir("/proc"))) eprintf("opendir /proc:"); while ((entry = readdir(dp))) { if (!pidfile(entry->d_name)) continue; pid = estrtol(entry->d_name, 10); if (oflag) { SLIST_FOREACH(pe, &omitpid_head, entry) if (pe->pid == pid) break; if (pe) continue; } if (parsestat(pid, &ps) < 0) continue; if (parsecmdline(ps.pid, cmdline, sizeof(cmdline)) < 0) { cmd = ps.comm; cmdbase = cmd; } else { if ((p = strchr(cmdline, ' '))) *p = '\0'; cmd = cmdline; cmdbase = basename(cmdline); } /* Workaround for login shells */ if (cmd[0] == '-') cmd++; for (i = 0; i < argc; i++) { if (strcmp(cmd, argv[i]) == 0 || strcmp(cmdbase, argv[i]) == 0) { putword(entry->d_name); found++; if (sflag) goto out; } } } out: if (found) putchar('\n'); closedir(dp); return 0; }