void threadmain(int argc, char *argv[]) { char *errmsg; int ac; char *ap, *av[256]; Cmd *cp; int32_t status; if (argc > 3) { print("usage: cifscmd [to [share]]\n"); exits("args"); } smbglobalsguess(1); errmsg = nil; if (Binit(&bin, 0, OREAD) == Beof || Binit(&bout, 1, OWRITE) == Beof) { fprint(2, "%s: can't init bio: %r\n", argv0); threadexits("Binit"); } if (argc > 1) { c = smbconnect(argv[1], argc == 3 ? argv[2] : nil, &errmsg); if (c == nil) fprint(2, "failed to connect: %s\n", errmsg); } while (ap = Brdline(&bin, '\n')) { ap[Blinelen(&bin) - 1] = 0; switch (ac = parse(ap, av, nelem(av))) { default: for (cp = cmd; cp->name; cp++) { if (strcmp(cp->name, av[0]) == 0) break; } if (cp->name == 0) { Bprint(&bout, "eh?\n"); break; } if (c == 0 && cp->connected) { Bprint(&bout, "not currently connected\n"); break; } if ((status = (*cp->f)(c, ac - 1, &av[1])) != -1) { if(verbose) Bprint(&bout, "ok %ld/%ld\n", status >> 16, status & 0xffff); break; } break; case -1: Bprint(&bout, "eh?\n"); break; case 0: break; } Bflush(&bout); } threadexits(0); }
void volumeproc(void *arg) { int fd, n, nf, nnf, i, nlines; static char buf[1024]; char *lines[32]; char *fields[8]; char *subfields[8]; Channel *ctl; int volume, minvolume, maxvolume, nvolume; ctl = arg; threadsetname("volumeproc"); fd = open(volumefile, OREAD); if(fd < 0){ fprint(2, "%s: %r\n", volumefile); threadexits(nil); } for(;;){ n = read(fd, buf, sizeof buf -1); if(n == 0) continue; if(n < 0){ fprint(2, "volumeproc: read: %r\n"); threadexits("volumeproc"); } buf[n] = '\0'; nlines = getfields(buf, lines, nelem(lines), 1, "\n"); for(i = 0; i < nlines; i++){ nf = tokenize(lines[i], fields, nelem(fields)); if(nf == 0) continue; if(nf != 6 || strcmp(fields[0], "volume") || strcmp(fields[1], "out")) continue; minvolume = strtol(fields[3], nil, 0); maxvolume = strtol(fields[4], nil, 0); if(minvolume >= maxvolume) continue; nnf = tokenize(fields[2], subfields, nelem(subfields)); if(nnf <= 0 || nnf > 8){ fprint(2, "volume format error\n"); threadexits(nil); } volume = 0; nvolume = 0; for(i = 0; i < nnf; i++){ volume += strtol(subfields[i], nil, 0); nvolume++; } volume /= nvolume; volume = 100*(volume - minvolume)/(maxvolume-minvolume); chanprint(ctl, "volume value %d", volume); } } }
void decexec(void *a) { char buf[256]; Playfd *pfd; Pacbuf *pb; threadsetname("decexec"); pfd = a; close(pfd->cfd); /* read fd */ if(pfd->fd != 1){ dup(pfd->fd, 1); close(pfd->fd); } close(0); open("/dev/null", OREAD); close(2); open("/dev/null", OWRITE); strncpy(buf, pfd->filename, sizeof(buf)-1); buf[sizeof(buf)-1] = 0; free(pfd->filename); free(pfd); procexecl(nil, "/bin/play", "play", "-o", "/fd/1", buf, nil); if((pb = nbrecvp(spare)) == nil) pb = malloc(sizeof(Pacbuf)); pb->cmd = Error; pb->off = 0; pb->len = snprint(pb->data, sizeof(pb->data), "startplay: exec play failed"); sendp(full, pb); threadexits("exec"); }
void hostproc(void *arg) { Channel *c; int i, n, which; c = arg; i = 0; for(;;){ i = 1-i; /* toggle */ n = read(hostfd[0], hostbuf[i].data, sizeof hostbuf[i].data); if(0) fprint(2, "hostproc %d\n", n); if(n <= 0){ if(n == 0){ if(exiting) threadexits(nil); werrstr("unexpected eof"); } fprint(2, "samterm: host read error: %r\n"); threadexitsall("host"); } hostbuf[i].n = n; which = i; if(0) fprint(2, "hostproc send %d\n", which); send(c, &which); } }
void extproc(void *argv) { Channel *c; int i, n, which, fd; void **arg; arg = argv; c = arg[0]; fd = (int)(uintptr)arg[1]; i = 0; for(;;){ i = 1-i; /* toggle */ n = read(fd, plumbbuf[i].data, sizeof plumbbuf[i].data); if(0) fprint(2, "ext %d\n", n); if(n <= 0){ fprint(2, "samterm: extern read error: %r\n"); threadexits("extern"); /* not a fatal error */ } plumbbuf[i].n = n; which = i; send(c, &which); } }
void _schedexecwait(void) { int pid; Channel *c; Proc *p; Thread *t; Waitmsg *w; p = _threadgetproc(); t = p->thread; pid = t->ret; _threaddebug(DBGEXEC, "_schedexecwait %d", t->ret); rfork(RFCFDG); for(;;){ w = wait(); if(w == nil) break; if(w->pid == pid) break; free(w); } if(w != nil){ if((c = _threadwaitchan) != nil) sendp(c, w); else free(w); } threadexits("procexec"); }
void spawnmonitor(void *cp) { char buf[4096]; char *xbuf; int fd; int n; int out; int first; recv(cp, &fd); out = open("/dev/tty", OWRITE); if(out < 0) out = 2; xbuf = buf; /* for ease of acid */ first = 1; while((n = read(fd, xbuf, sizeof buf)) > 0){ if(first){ first = 0; fprint(2, "Ghostscript Error:\n"); } write(out, xbuf, n); alarm(500); } threadexits(0); }
void threadmain(int argc, char* argv[]) { char* mnt; char* srv; int mflag; Biobuf* b; char* user; srv = nil; mnt = nil; mflag = MREPL|MCREATE; ARGBEGIN{ case 'a': mflag = MAFTER|MCREATE; break; case 'b': mflag = MBEFORE|MCREATE; break; case 'c': mflag = MREPL|MCREATE; break; case 's': srv = EARGF(usage()); break; case 'm': mnt = EARGF(usage()); break; case 'D': debug = 1; chatty9p++; break; default: usage(); }ARGEND; if(argc != 1) usage(); tfname = argv[0]; ttfname = smprint("%s.new", tfname); b = Bopen(tfname, OREAD); if(b == nil) sysfatal("%s: %r", tfname); trie = rdtrie(b); Bterm(b); if(trie == nil) sysfatal("%s: %r", tfname); if(srv == nil && mnt == nil){ mnt = "/mnt/tags"; srv = srvname(tfname); } if(!chatty9p) rfork(RFNOTEG); sfs.tree = alloctree(nil, nil, DMDIR|0777, nil); user = getuser(); ctlf = createfile(sfs.tree->root, "ctl", user, 0666, nil); threadpostmountsrv(&sfs, srv, mnt, mflag); threadexits(nil); }
void plumbproc(void *argv) { Channel *c; int i, n, which, *fdp; void **arg; arg = argv; c = arg[0]; fdp = arg[1]; i = 0; for(;;){ i = 1-i; /* toggle */ n = read(*fdp, plumbbuf[i].data, READBUFSIZE); if(n <= 0){ fprint(2, "samterm: plumb read error: %r\n"); threadexits("plumb"); /* not a fatal error */ } plumbbuf[i].n = n; if(plumbformat(i)){ which = i; send(c, &which); } } }
void threadmain(int argc, char **argv) { char *net; //extern long _threaddebuglevel; //_threaddebuglevel = 1<<20; /* DBGNOTE */ rfork(RFNOTEG); ARGBEGIN{ case 'D': chatty9p++; break; case 'n': setexecname(EARGF(usage())); break; }ARGEND switch(argc){ default: usage(); case 0: net = "/net"; break; case 1: net = argv[0]; break; } quotefmtinstall(); initfs(); threadpostmountsrv(&fs, nil, net, MBEFORE); threadexits(nil); }
void playvolproc(void*a) { int fd, n, nf, volume, nvolume, i; static char buf[256+1]; static errors; char *fields[3], *subfields[9]; Channel *chan; threadsetname("playvolproc"); chan = a; fd = open(playvolfile, OREAD); if(fd < 0) sysfatal("%s: %r", playvolfile); for(;;){ n = read(fd, buf, sizeof buf -1); if(n == 0) continue; if(n < 0){ fprint(2, "%s: %r\n", playvolfile); threadexits("playvolproc"); } buf[n] = '\0'; if(debug) fprint(2, "volumestring: %s\n", buf); nf = tokenize(buf, fields, nelem(fields)); if(nf == 0) continue; if(nf != 2 || strcmp(fields[0], "volume")){ fprint(2, "playvolproc: [%d]: %s\n", nf, fields[0]); if(errors++ > 32) threadexits("playvolproc"); continue; } nvolume = tokenize(fields[1], subfields, nelem(subfields)); if(nvolume <= 0 || nvolume > 8){ fprint(2, "volume format error\n"); if(errors++ > 32) threadexits("playvolproc"); continue; } volume = 0; for(i = 0; i < nvolume; i++) volume += strtol(subfields[i], nil, 0); volume /= nvolume; chanprint(chan, "volume value %d", volume); } }
static void mainlauncher(void *arg) { Mainarg *a; a = arg; threadmain(a->argc, a->argv); threadexits("threadmain"); }
void cwrite(int fd, char *path, char *cmd, int len) { if (write(fd, cmd, len) < len) { fprint(2, "cwrite: %s: failed %d bytes: %r\n", path, len); sendp(quit, nil); threadexits(nil); } }
void winshell(void *args) { print_func_entry(); Window *w; Channel *pidc; void **arg; char *cmd, *dir; char **argv; arg = args; w = arg[0]; pidc = arg[1]; cmd = arg[2]; argv = arg[3]; dir = arg[4]; rfork(RFNAMEG|RFFDG|RFENVG); if(filsysmount(filsys, w->id) < 0){ fprint(2, "mount failed: %r\n"); sendul(pidc, 0); threadexits("mount failed"); } close(0); if(open("/dev/cons", OREAD) < 0){ fprint(2, "can't open /dev/cons: %r\n"); sendul(pidc, 0); threadexits("/dev/cons"); } close(1); if(open("/dev/cons", OWRITE) < 0){ fprint(2, "can't open /dev/cons: %r\n"); sendul(pidc, 0); threadexits("open"); /* BUG? was terminate() */ } if(wclose(w) == 0){ /* remove extra ref hanging from creation */ notify(nil); dup(1, 2); if(dir) chdir(dir); procexec(pidc, cmd, argv); _exits("exec failed"); } print_func_exit(); }
void cwrite(int fd, char *path, char *cmd, int len) { werrstr(""); if (write(fd, cmd, len) < len) { fprint(outf, "cwrite: %s: failed writing %d bytes: %r\n", path, len); sendp(quit, nil); threadexits(nil); } }
static void plumbwebproc(void*) { Plumbmsg *m; for(;;){ m = plumbrecv(plumbwebfd); sendp(plumbchan, m); if(m == nil) threadexits(nil); } }
void plumbproc(void *) { Plumbmsg *m; threadsetname("plumbproc"); for(;;){ m = plumbrecv(plumbwebfd); if(m == nil) threadexits(nil); sendp(cplumb, m); } }
void plumbshowthread(void *v) { Plumbmsg *m; USED(v); threadsetname("plumbshowthread"); while((m = recvp(cplumbshow)) != nil){ showmesg(m->data, plumblookup(m->attr, "digest")); plumbfree(m); } threadexits(nil); }
void plumbsendthread(void *v) { Plumbmsg *m; USED(v); threadsetname("plumbsendthread"); while((m = recvp(cplumbsend)) != nil){ mkreply(nil, "Mail", m->data, m->attr, nil); plumbfree(m); } threadexits(nil); }
void plumbsendproc(void* v) { Plumbmsg *m; threadsetname("plumbsendproc"); for(;;){ m = plumbrecvfid(plumbsendmailfd); sendp(cplumbsend, m); if(m == nil) threadexits(nil); } }
static void execproc(void *v) { Execjob *e; e = v; rfork(RFFDG); dup(e->fd[0], 0); dup(e->fd[1], 1); dup(e->fd[2], 2); procexec(e->c, e->cmd, e->argv); threadexits(nil); }
void editerror(char *fmt, ...) { va_list arg; char *s; va_start(arg, fmt); s = vsmprint(fmt, arg); va_end(arg); freecmd(); allwindows(allelogterm, nil); /* truncate the edit logs */ sendp(editerrc, s); threadexits(nil); }
int wingetec(Window *w) { if(w->nbuf == 0){ w->nbuf = read(w->event, w->buf, sizeof w->buf); if(w->nbuf <= 0){ /* probably because window has exited, and only called by wineventproc, so just shut down */ threadexits(nil); } w->bufp = w->buf; } w->nbuf--; return *w->bufp++; }
static void _ioproc(void *arg) { Rune r; Keyboardctl *kc; kc = arg; threadsetname("kbdproc"); for(;;) { if(_displayrdkbd(display, &r) < 0) threadexits("read error"); send(kc->c, &r); } }
void threadmain(int argc, char **argv) { char args[Arglen]; char *as, *ae; int accel, pena, devid; int csps[] = { KbdCSP, PtrCSP, 0 }; quotefmtinstall(); pena = 1; ae = args+sizeof(args); as = seprint(args, ae, "kb"); ARGBEGIN{ case 'a': accel = strtol(EARGF(usage()), nil, 0); as = seprint(as, ae, " -a %d", accel); break; case 'd': usbdebug++; as = seprint(as, ae, " -d"); break; case 'k': as = seprint(as, ae, " -k"); pena = 0; break; case 'm': as = seprint(as, ae, " -m"); pena = 1; break; case 'N': devid = atoi(EARGF(usage())); /* ignore dev number */ USED(devid); break; case 'b': as = seprint(as, ae, " -b"); break; default: usage(); }ARGEND; rfork(RFNOTEG); fmtinstall('U', Ufmt); threadsetgrp(threadid()); if(pena == 0) csps[1] = 0; startdevs(args, argv, argc, matchdevcsp, csps, kbmain); threadexits(nil); }
void mesgthread(void *v) { Event *e; Article *m; m = v; while(!m->dead && (e = recvp(m->w->cevent))) acmeevent(m, m->w, e); //fprint(2, "msg %p exits\n", m); unlink(m); free(m->w); free(m); threadexits(nil); }
void mainproc(void *v) { int n, nn; Fcall f; USED(v); atnotify(ignorepipe, 1); fmtinstall('D', dirfmt); fmtinstall('M', dirmodefmt); fmtinstall('F', fcallfmt); fmtinstall('H', encodefmt); outq = qalloc(); inq = qalloc(); if(!versioned){ f.type = Tversion; f.version = "9P2000"; f.msize = msize; f.tag = NOTAG; n = convS2M(&f, vbuf, sizeof vbuf); if(n <= BIT16SZ) sysfatal("convS2M conversion error"); if(verbose > 1) fprint(2, "%T * <- %F\n", &f); nn = write(1, vbuf, n); if(n != nn) sysfatal("error writing Tversion: %r\n"); n = read9pmsg(0, vbuf, sizeof vbuf); if(n < 0) sysfatal("read9pmsg failure"); if(convM2S(vbuf, n, &f) != n) sysfatal("convM2S failure"); if(f.msize < msize) msize = f.msize; if(verbose > 1) fprint(2, "%T * -> %F\n", &f); } threadcreate(inputthread, nil, STACK); threadcreate(outputthread, nil, STACK); /* if(rootfid) */ /* dorootstat(); */ threadcreate(listenthread, nil, STACK); threadexits(0); }
void threadmain(int argc, char *argv[]) { char buf[512]; int fd; progname = "plumber"; ARGBEGIN{ case 'd': debug = 1; break; case 'p': plumbfile = ARGF(); break; }ARGEND user = getuser(); home = getenv("HOME"); if(user==nil || home==nil) error("can't initialize $user or $home: %r"); if(plumbfile == nil){ sprint(buf, "%s/lib/plumbing", home); if(access(buf, 0) >= 0) plumbfile = estrdup(buf); else plumbfile = unsharp("#9/plumb/initial.plumbing"); } fd = open(plumbfile, OREAD); if(fd < 0) error("can't open rules file %s: %r", plumbfile); if(setjmp(parsejmp)) error("parse error"); rules = readrules(plumbfile, fd); close(fd); /* * Start all processes and threads from other proc * so we (main pid) can return to user. */ printerrors = 0; makeports(rules); startfsys(); threadexits(nil); }
static void _ioproc(void *arg) { int n, nerr, one; char buf[1+5*12]; Mouse m; Mousectl *mc; mc = arg; threadsetname("mouseproc"); one = 1; memset(&m, 0, sizeof m); mc->pid = getpid(); nerr = 0; for(;;){ n = read(mc->mfd, buf, sizeof buf); if(n != 1+4*12){ yield(); /* if error is due to exiting, we'll exit here */ fprint(2, "mouse: bad count %d not 49: %r\n", n); if(n<0 || ++nerr>10) threadexits("read error"); continue; } nerr = 0; switch(buf[0]){ case 'r': send(mc->resizec, &one); /* fall through */ case 'm': m.xy.x = atoi(buf+1+0*12); m.xy.y = atoi(buf+1+1*12); m.buttons = atoi(buf+1+2*12); m.msec = atoi(buf+1+3*12); send(mc->c, &m); /* * mc->Mouse is updated after send so it doesn't have wrong value if we block during send. * This means that programs should receive into mc->Mouse (see readmouse() above) if * they want full synchrony. mc->Mouse = m; */ *(Mouse *)mc = m; break; } } }
static void plumbwebthread(void*) { char *base; Plumbmsg *m; for(;;){ m = recvp(plumbchan); if(m == nil) threadexits(nil); base = plumblookup(m->attr, "baseurl"); if(base == nil) base = m->wdir; plumburl(m->data, base); plumbfree(m); } }