Ejemplo n.º 1
0
void main(int argc, char *argv[])
{
    int i;
    String *t;
    char *termargs[10], **ap;

    ap = termargs;
    *ap++ = "samterm";
    ARGBEGIN{
    case 'd':
        dflag++;
        break;
    case 'r':
        machine = EARGF(usage());
        break;
    case 'R':
        Rflag++;
        break;
    case 't':
        samterm = EARGF(usage());
        break;
    case 's':
        rsamname = EARGF(usage());
        break;
    default:
        dprint("sam: unknown flag %c\n", ARGC());
        usage();
        /* options for samterm */
    case 'a':
        *ap++ = "-a";
        break;
    } ARGEND
    *ap = nil;

    Strinit(&cmdstr);
    Strinit0(&lastpat);
    Strinit0(&lastregexp);
    Strinit0(&genstr);
    Strinit0(&rhs);
    Strinit0(&curwd);
    Strinit0(&plan9cmd);
    home = getenv(HOME);
    disk = diskinit();
    if(home == 0)
        home = "/";
    if(!dflag)
        startup(machine, Rflag, termargs, argv);
    notify(notifyf);
    getcurwd();
    if(argc>0) {
        for(i=0; i<argc; i++) {
            if(!setjmp(mainloop)) {
                t = tmpcstr(argv[i]);
                Straddc(t, '\0');
                Strduplstr(&genstr, t);
                freetmpstr(t);
                fixname(&genstr);
                logsetname(newfile(), &genstr);
            }
        }
    } else if(!downloaded)
        newfile();
    seq++;
    if(file.nused)
        current(file.filepptr[0]);
    setjmp(mainloop);
    cmdloop();
    trytoquit();	/* if we already q'ed, quitok will be TRUE */
    exits(0);
}
Ejemplo n.º 2
0
void
usage(void)
{
	fprint(2, "usage: %s address-list-file listname\n", argv0);
	exits("usage");
}
Ejemplo n.º 3
0
/* Note: §c{apisetupmainthread} §emph{never returns; it calls §c{exits} */
void
apisetupmainthread(struct gspos pos, struct api_thread_table *api_thread_table, void *api_main_thread_data, struct api_prim_table *api_prim_table, gsvalue entry)
{
    struct api_thread *mainthread, *thread;

    int threadnum;
    int suspended_runnable_thread;
    struct api_thread_stats stats;

    if (api_thread_queue)
        gsfatal("apisetupmainthread called twice")
        ;

    api_thread_queue = gs_sys_global_block_suballoc(&api_thread_queue_info, sizeof(*api_thread_queue));
    memset(api_thread_queue, 0, sizeof(*api_thread_queue));

    mainthread = api_add_thread(pos, api_thread_table, api_main_thread_data, api_prim_table, entry);
    mainthread->ismain = 1;

    api_release_thread(mainthread);

    mainthread = 0;

    stats.thread_lifetime = 0;
    stats.loops = stats.instrs = stats.loops_waiting = 0;

    for (;;) {
        suspended_runnable_thread = 0;

        if (gs_sys_should_gc()) {
            struct gsstringbuilder *err;

            gsstatprint("Before garbage collection: %dMB used\n", gs_sys_memory_allocated_size() / 0x400 / 0x400);
            err = gsreserve_string_builder();

            gs_sys_wait_for_gc();
            if (gs_sys_start_gc(err) < 0) {
                gsfinish_string_builder(err);
                api_handle_gc_failed(err);
                goto gc_done;
            }

            err = gsreserve_string_builder();
            if (api_gc_trace_thread_queue(err) < 0) {
                gsfinish_string_builder(err);
                api_handle_gc_failed(err);
                goto gc_done;
            }

            if (gs_sys_finish_gc(err) < 0) {
                gsfinish_string_builder(err);
                api_handle_gc_failed(err);
                goto gc_done;
            }

            gsstatprint("After garbage collection: %dMB used\n", gs_sys_memory_allocated_size() / 0x400 / 0x400);
        }
gc_done:

        if (gs_sys_memory_exhausted()) {
            gswarning("%s:%d: About to terminate on out of memory (%dMB used)", __FILE__, __LINE__, gs_sys_memory_allocated_size() / 0x400 / 0x400);
            api_take_thread_queue();
            for (threadnum = 0; threadnum < API_NUMTHREADS; threadnum++) {
                thread = &api_thread_queue->threads[threadnum];
                api_take_thread(thread);
                if (thread->state == api_thread_st_active)
                    api_abend(thread, UNIMPL("Terminate on out of memory"))
                    ;
                api_release_thread(thread);
            }
            api_release_thread_queue();
        }

        for (threadnum = 0; threadnum < API_NUMTHREADS; threadnum++) {
            thread = 0;
            api_take_thread_queue();
            for (; threadnum < API_NUMTHREADS && !thread; threadnum++) {
                thread = api_try_schedule_thread(&api_thread_queue->threads[threadnum]);
            }
            api_release_thread_queue();
            if (thread) {
                stats.loops++;

                switch (thread->state) {
                case api_thread_st_active: {
                    gstypecode st;
                    gsvalue instr;
                    struct api_code_segment *code;

                    code = thread->code;

                    instr = code->instrs[code->ip].instr;
                    st = GS_SLOW_EVALUATE(code->instrs[code->ip].pos, instr);

                    switch (st) {
                    case gstywhnf:
                        stats.instrs++;
                        if (api_exec_instr(thread, instr) > 0)
                            suspended_runnable_thread = 1
                                                        ;
                        break;
                    case gstyerr:
                    case gstyimplerr:
                        api_exec_err(thread, instr, st);
                        break;
                    case gstystack:
                        stats.loops_waiting++;
                        break;
                    case gstyindir:
                        code->instrs[code->ip].instr = GS_REMOVE_INDIRECTION(code->instrs[code->ip].pos, instr);
                        suspended_runnable_thread = 1;
                        break;
                    case gstyenosys:
                        api_abend(thread, "Un-implemented operation: %r");
                        break;
                    default:
                        api_abend_unimpl(thread, __FILE__, __LINE__, "API thread advancement (state = %d)", st);
                        break;
                    }
                    break;
                }
                case api_thread_st_terminating_on_done:
                case api_thread_st_terminating_on_abend: {
                    enum api_prim_execution_state st;
                    int thread_abended = thread->state == api_thread_st_terminating_on_abend;

                    if (gsflag_stat_collection && !thread->prog_term_time) {
                        thread->prog_term_time = nsec();
                        stats.thread_lifetime += thread->prog_term_time - thread->start_time;
                    }
                    st = thread->api_thread_table->thread_term_status(thread);
                    switch (st) {
                    case api_st_success: {
                        int have_other_threads;

                        api_take_thread_queue();
                        api_thread_queue->numthreads--;
                        have_other_threads = api_thread_queue->numthreads > 0;
                        api_release_thread_queue();
                        thread->state = api_thread_st_unused;

                        if (thread->ismain) {
                            if (have_other_threads) {
                                api_thread_pool_shutdown(&stats);
                                gs_sys_num_procs--;
                                gsfatal(UNIMPL("Thread is main thread and there are background threads --- fork into background.  Do not release ACE or run shutdown hooks yet."));
                            } else {
                                api_thread_pool_shutdown(&stats);
                                if (thread_abended) {
                                    fprint(2, "%s\n", thread->status->start);
                                    gs_sys_num_procs--;
                                    exits(thread->status->start);
                                } else {
                                    gs_sys_num_procs--;
                                    exits("");
                                }
                            }
                        } else { /* Thread is background thread */
                            if (have_other_threads) {
                                api_thread_pool_shutdown(&stats);
                                gs_sys_num_procs--;
                                gsfatal(UNIMPL("Thread is background thread and there are other threads --- shut down thread and keep going.  Do not release ACE or run shutdown hooks yet."));
                            } else {
                                api_thread_pool_shutdown(&stats);
                                gs_sys_num_procs--;
                                gsfatal(UNIMPL("Thread is last background thread --- shut down.  Always exits(\"\") in this case; exit status doesn't matter anyway. Complication: Need to run the stuff at the bottom of this thread, too."));
                            }
                        }
                        break;
                    }
                    case api_st_blocked:
                        break;
                    default:
                        thread->state = api_thread_st_unused;
                        api_thread_pool_shutdown(&stats);
                        gs_sys_num_procs--;
                        gsfatal(UNIMPL("Handle state %d from thread terminator next"), st);
                        break;
                    }
                    break;
                }
                default: {
                    thread->state = api_thread_st_unused;
                    api_thread_pool_shutdown(&stats);
                    gs_sys_num_procs--;
                    gsfatal(UNIMPL("Handle thread state %d next"), thread->state);
                    break;
                }
                }
                api_release_thread(thread);
            }
        }
        if (!suspended_runnable_thread)
            if (sleep(1) < 0)
                gswarning("%s:%d: sleep returned a negative number", __FILE__, __LINE__)
                ;
    }
}
Ejemplo n.º 4
0
void
usage(void)
{
	fprint(2, "usage: convkeys2 keyfile\n");
	exits("usage");
}
Ejemplo n.º 5
0
void
runtime·badsignal(void)
{
	runtime·pwrite(2, badsignal, sizeof badsignal - 1, -1LL);
	runtime·exits(badsignal);
}
Ejemplo n.º 6
0
Archivo: xd.c Proyecto: bbarker/plan9
void
main(int argc, char *argv[])
{
	int i, err;
	Arg *ap;

	Binit(&bout, 1, OWRITE);
	err = 0;
	ap = 0;
	while(argc>1 && argv[1][0]=='-' && argv[1][1]){
		--argc;
		argv++;
		argv[0]++;
		if(argv[0][0] == 'r'){
			repeats = 1;
			if(argv[0][1])
				goto Usage;
			continue;
		}
		if(argv[0][0] == 's'){
			swizzle = 1;
			if(argv[0][1])
				goto Usage;
			continue;
		}
		if(argv[0][0] == 'u'){
			flush = 1;
			if(argv[0][1])
				goto Usage;
			continue;
		}
		if(argv[0][0] == 'a'){
			argv[0]++;
			switch(argv[0][0]){
			case 'o':
				abase = 0;
				break;
			case 'd':
				abase = 1;
				break;
			case 'x':
				abase = 2;
				break;
			default:
				goto Usage;
			}
			if(argv[0][1])
				goto Usage;
			continue;
		}
		ap = &arg[narg];
		initarg();
		while(argv[0][0]){
			switch(argv[0][0]){
			case 'c':
				ap->chartype = TAscii;
				ap->loglen = 0;
				if(argv[0][1] || argv[0][-1]!='-')
					goto Usage;
				break;
			case 'R':
				ap->chartype = TRune;
				ap->loglen = 0;
				if(argv[0][1] || argv[0][-1]!='-')
					goto Usage;
				break;
			case 'o':
				ap->base = 0;
				break;
			case 'd':
				ap->base = 1;
				break;
			case 'x':
				ap->base = 2;
				break;
			case 'b':
			case '1':
				ap->loglen = 0;
				break;
			case 'w':
			case '2':
				ap->loglen = 1;
				break;
			case 'l':
			case '4':
				ap->loglen = 2;
				break;
			case 'v':
			case '8':
				ap->loglen = 3;
				break;
			default:
			Usage:
   fprint(2, "usage: xd [-u] [-r] [-s] [-a{odx}] [-c|{b1w2l4v8}{odx}] ... file ...\n");
				exits("usage");
			}
			argv[0]++;
		}
		if(ap->chartype == TRune)
			ap->fn = fmtr;
		else if(ap->chartype == TAscii)
			ap->fn = fmtc;
		else
			ap->fn = fmt[ap->loglen];
		ap->fmt = dfmt[ap->loglen][ap->base];
		ap->afmt = afmt[ap>arg][abase];
	}
	if(narg == 0)
		initarg();
	if(argc == 1)
		err = xd(0, 0);
	else if(argc == 2)
		err = xd(argv[1], 0);
	else for(i=1; i<argc; i++)
		err |= xd(argv[i], 1);
	exits(err? "error" : 0);
}
Ejemplo n.º 7
0
Archivo: main.c Proyecto: 99years/plan9
void
main(int argc, char *argv[])
{
	int i, j;
	double d;

	pi = atan(1.0)*4;
	pipi = pi*2;
	radian = pi/180;
	radsec = radian/3600;
	converge = 1.0e-14;

	fmtinstall('R', Rconv);
	fmtinstall('D', Dconv);

	per = PER;
	deld = PER/NPTS;
	init();
	args(argc, argv);
	init();

loop:
	d = day;
	pdate(d);
	if(flags['p'] || flags['e']) {
		print(" ");
		ptime(d);
		pstime(d);
	}
	print("\n");
	for(i=0; i<=NPTS+1; i++) {
		setime(d);

		for(j=0; objlst[j]; j++) {
			(*objlst[j]->obj)();
			setobj(&objlst[j]->point[i]);
			if(flags['p']) {
				if(flags['m'])
					if(strcmp(objlst[j]->name, "Comet"))
						continue;
				output(objlst[j]->name, &objlst[j]->point[i]);
			}
		}
		if(flags['e']) {
			d = dist(&eobj1->point[i], &eobj2->point[i]);
			print("dist %s to %s = %.4f\n", eobj1->name, eobj2->name, d);
		}
//		if(flags['p']) {
//			pdate(d);
//			print(" ");
//			ptime(d);
//			print("\n");
//		}
		if(flags['p'] || flags['e'])
			break;
		d += deld;
	}
	if(!(flags['p'] || flags['e']))
		search();
	day += per;
	nperiods -= 1;
	if(nperiods > 0)
		goto loop;
	exits(0);
}
Ejemplo n.º 8
0
void
usage(void)
{
	fprint(2, "usage: webget [-b baseurl] [-m mtpt] [-p postbody] url\n");
	exits("usage");
}
Ejemplo n.º 9
0
void
main(int argc, char **argv)
{
	int conn, ctlfd, fd, n;
	char buf[128], *base, *mtpt, *post, *url;

	mtpt = "/mnt/web";
	post = nil;
	base = nil;
	ARGBEGIN{
	default:
		usage();
	case 'b':
		base = EARGF(usage());
		break;
	case 'm':
		mtpt = EARGF(usage());
		break;
	case 'p':
		post = EARGF(usage());
		break;
	}ARGEND;

	if (argc != 1) 
		usage();

	url = argv[0];
 
	snprint(buf, sizeof buf, "%s/clone", mtpt);
	if((ctlfd = open(buf, ORDWR)) < 0)
		sysfatal("couldn't open %s: %r", buf);
	if((n = read(ctlfd, buf, sizeof buf-1)) < 0)
		sysfatal("reading clone: %r");
	if(n == 0)
		sysfatal("short read on clone");
	buf[n] = '\0';
	conn = atoi(buf);

	if(base)
		if(fprint(ctlfd, "baseurl %s", base) < 0)
			sysfatal("baseurl ctl write: %r");

	if(fprint(ctlfd, "url %s", url) <= 0)
		sysfatal("get ctl write: %r");

	if(post){
		snprint(buf, sizeof buf, "%s/%d/postbody", mtpt, conn);
		if((fd = open(buf, OWRITE)) < 0)
			sysfatal("open %s: %r", buf);
		if(write(fd, post, strlen(post)) < 0)
			sysfatal("post write failed: %r");
		close(fd);
	}

	snprint(buf, sizeof buf, "%s/%d/body", mtpt, conn);
	if((fd = open(buf, OREAD)) < 0)
		sysfatal("open %s: %r", buf);

	xfer(fd, 1);
	exits(nil);
}
Ejemplo n.º 10
0
static void
usage(void)
{
	fprint(2, "usage: %s [-6eq] [-m maxiosize] [[-r] /dev/sdXX]\n", argv0);
	exits("usage");
}
Ejemplo n.º 11
0
void
main(int argc, char *argv[])
{
	ScsiReq target;
	char *ap, *av[256];
	int ac, i, raw = 0;
	ScsiCmd *cp;
	long status;

	ARGBEGIN {
	case 'e':
		exabyte = 1;
		/* fallthrough */
	case '6':
		force6bytecmds = 1;
		break;
	case 'm':
		ap = ARGF();
		if(ap == nil)
			usage();
		maxiosize = atol(ap);
		if(maxiosize < 512 || maxiosize > MaxIOsize)
			sysfatal("max-xfer < 512 or > %d", MaxIOsize);
		break;
	case 'r':			/* must be last option and not bundled */
		raw++;
		break;
	case 'q':
		verbose = 0;
		break;
	default:
		usage();
	} ARGEND

	if(Binit(&bin, 0, OREAD) == Beof || Binit(&bout, 1, OWRITE) == Beof){
		fprint(2, "%s: can't init bio: %r\n", argv0);
		exits("Binit");
	}

	memset(&target, 0, sizeof target);
	if (raw) {			/* hack for -r */
		++argc;
		--argv;
	}
	if(argc && cmdopen(&target, argc, argv) == -1) {
		fprint(2, "open failed\n");
		usage();
	}
	Bflush(&bout);

	while(ap = Brdline(&bin, '\n')){
		ap[Blinelen(&bin)-1] = 0;
		switch(ac = parse(ap, av, nelem(av))){

		default:
			for(cp = scsicmds; cp->name; cp++){
				if(strcmp(cp->name, av[0]) == 0)
					break;
			}
			if(cp->name == 0){
				Bprint(&bout, "eh?\n");
				break;
			}
			if((target.flags & Fopen) == 0 && cp->open){
				Bprint(&bout, "no current target\n");
				break;
			}
			if((status = (*cp->f)(&target, ac-1, &av[1])) != -1){
				if(verbose)
					Bprint(&bout, "ok %ld\n", status);
				break;
			}
			for(i = 0; description[i].description; i++){
				if(target.status != description[i].status)
					continue;
				if(target.status == Status_SD)
					makesense(&target);
				else
					Bprint(&bout, "%s\n", description[i].description);
				break;
			}
			break;

		case -1:
			Bprint(&bout, "eh?\n");
			break;

		case 0:
			break;
		}
		Bflush(&bout);
	}
	exits(0);
}
Ejemplo n.º 12
0
static void
usage(void)
{
	fprint(2, "usage: 5e [-npbf] text [...]\n");
	exits(nil);
}
Ejemplo n.º 13
0
int32
runtime·sighandler(void *v, int8 *s, G *gp)
{
	bool crash;
	Ureg *ureg;
	uintptr *sp;
	SigTab *sig, *nsig;
	intgo len, i;

	if(!s)
		return NCONT;
			
	len = runtime·findnull((byte*)s);
	if(len <= 4 || runtime·mcmp((byte*)s, (byte*)"sys:", 4) != 0)
		return NDFLT;

	nsig = nil;
	sig = runtime·sigtab;
	for(i=0; i < NSIG; i++) {
		if(runtime·strstr((byte*)s, (byte*)sig->name)) {
			nsig = sig;
			break;
		}
		sig++;
	}

	if(nsig == nil)
		return NDFLT;

	ureg = v;
	if(nsig->flags & SigPanic) {
		if(gp == nil || m->notesig == 0)
			goto Throw;

		// Copy the error string from sigtramp's stack into m->notesig so
		// we can reliably access it from the panic routines. We can't use
		// runtime·memmove here since it will use SSE instructions for big
		// copies. The Plan 9 kernel doesn't allow floating point in note
		// handlers.
		//
		// TODO(ality): revert back to memmove when the kernel is fixed.
		if(len >= ERRMAX)
			len = ERRMAX-1;
		for(i = 0; i < len; i++)
			m->notesig[i] = s[i];
		m->notesig[i] = '\0';

		gp->sig = i;
		gp->sigpc = ureg->pc;

		// Only push runtime·sigpanic if ureg->pc != 0.
		// If ureg->pc == 0, probably panicked because of a
		// call to a nil func.  Not pushing that onto sp will
		// make the trace look like a call to runtime·sigpanic instead.
		// (Otherwise the trace will end at runtime·sigpanic and we
		// won't get to see who faulted.)
		if(ureg->pc != 0) {
			sp = (uintptr*)ureg->sp;
			*--sp = ureg->pc;
			ureg->sp = (uint32)sp;
		}
		ureg->pc = (uintptr)runtime·sigpanic;
		return NCONT;
	}

	if(!(nsig->flags & SigThrow))
		return NDFLT;

Throw:
	m->throwing = 1;
	m->caughtsig = gp;
	runtime·startpanic();

	runtime·printf("%s\n", s);
	runtime·printf("PC=%X\n", ureg->pc);
	runtime·printf("\n");

	if(runtime·gotraceback(&crash)) {
		runtime·traceback(ureg->pc, ureg->sp, 0, gp);
		runtime·tracebackothers(gp);
		runtime·dumpregs(ureg);
	}
	
	if(crash)
		runtime·crash();

	runtime·goexitsall("");
	runtime·exits(s);

	return 0;
}
Ejemplo n.º 14
0
Archivo: tarfs.c Proyecto: aahud/harvey
void
populate(char *name)
{
	int32_t chksum, linkflg;
	int64_t blkno;
	char *fname;
	Fileinf f;
	Hdr *hp;

	tapefile = open(name, OREAD);
	if (tapefile < 0)
		error("Can't open argument file");
	replete = 1;
	hp = &dblock;
	for (blkno = 0; ; blkno++) {
		seek(tapefile, Tblock*blkno, 0);
		if (readn(tapefile, hp->dummy, sizeof hp->dummy) < sizeof hp->dummy)
			break;
		fname = tarname(hp);
		if (fname[0] == '\0')
			break;

		/* crack header */
		f.addr = blkno + 1;
		f.mode = strtoul(hp->mode, 0, 8);
		f.uid  = strtoul(hp->uid, 0, 8);
		f.gid  = strtoul(hp->gid, 0, 8);
		if((uint8_t)hp->size[0] == 0x80)
			f.size = b8byte(hp->size+3);
		else
			f.size = strtoull(hp->size, 0, 8);
		f.mdate = strtoul(hp->mtime, 0, 8);
		chksum  = strtoul(hp->chksum, 0, 8);
		/* the mode test is ugly but sometimes necessary */
		if (hp->linkflag == LF_DIR || (f.mode&0170000) == 040000 ||
		    strrchr(fname, '\0')[-1] == '/'){
			f.mode |= DMDIR;
			f.size = 0;
		}
		f.mode &= DMDIR | 0777;

		/* make file name safe, canonical and free of . and .. */
		while (fname[0] == '/')		/* don't allow absolute paths */
			++fname;
		cleanname(fname);
		while (strncmp(fname, "../", 3) == 0)
			fname += 3;

		/* reject links */
		linkflg = hp->linkflag == LF_SYMLINK1 ||
			hp->linkflag == LF_SYMLINK2 || hp->linkflag == LF_LINK;
		if (chksum != checksum()){
			fprint(2, "%s: bad checksum on %.28s at offset %lld\n",
				argv0, fname, Tblock*blkno);
			exits("checksum");
		}
		if (linkflg) {
			/*fprint(2, "link %s->%s skipped\n", fname, hp->linkname);*/
			f.size = 0;
		} else {
			/* accept this file */
			f.name = fname;
			if (f.name[0] == '\0')
				fprint(2, "%s: null name skipped\n", argv0);
			else
				poppath(f, 1);
			blkno += (f.size + Tblock - 1)/Tblock;
		}
	}
}
Ejemplo n.º 15
0
static void
usage(void)
{
	fprint(2, "usage: %s [-v] [-9Jr] [-s] [-f devicefile] [srvname]\n", argv0);
	exits("usage");
}
Ejemplo n.º 16
0
int
main(int argc, char *argv[])
{
	char *p;
	int nout, nproc, status, i, c;

	thechar = '1';
	thestring = "68000";
	memset(debug, 0, sizeof(debug));
	cinit();
	outfile = 0;
	include[ninclude++] = ".";
	ARGBEGIN {
	default:
		c = ARGC();
		if(c >= 0 || c < sizeof(debug))
			debug[c] = 1;
		break;

	case 'o':
		outfile = ARGF();
		break;

	case 'D':
		p = ARGF();
		if(p)
			Dlist[nDlist++] = p;
		break;

	case 'I':
		p = ARGF();
		setinclude(p);
		break;
	} ARGEND
	if(*argv == 0) {
		print("usage: %ca [-options] file.s\n", thechar);
		errorexit();
	}
	if(argc > 1 && systemtype(Windows)){
		print("can't assemble multiple files on windows\n");
		errorexit();
	}
	if(argc > 1 && !systemtype(Windows)) {
		nproc = 1;
		if(p = getenv("NPROC"))
			nproc = atol(p);	/* */
		c = 0;
		nout = 0;
		for(;;) {
			while(nout < nproc && argc > 0) {
				i = myfork();
				if(i < 0) {
					i = mywait(&status);
					if(i < 0)
						errorexit();
					if(status)
						c++;
					nout--;
					continue;
				}
				if(i == 0) {
					print("%s:\n", *argv);
					if(assemble(*argv))
						errorexit();
					exits(0);
				}
				nout++;
				argc--;
				argv++;
			}
			i = mywait(&status);
			if(i < 0) {
				if(c)
					errorexit();
				exits(0);
			}
			if(status)
				c++;
			nout--;
		}
	}
	if(assemble(argv[0]))
		errorexit();
	exits(0);
}
Ejemplo n.º 17
0
void
main(int argc, char **argv)
{
	int srvfd, pipefd[2], stdio;
	Xfsub **xs;
	char *mtpt;

	initfcalls();
	stdio = 0;
	mtpt = nil;
	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;
	case 'm':
		mtpt = EARGF(usage());
		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");
		
		if(post9pservice(pipefd[0], srvname, mtpt) < 0)
			sysfatal("post9pservice: %r");
		close(pipefd[0]);
	}
	srvfd = pipefd[1];
	
	switch(rfork(RFNOWAIT|RFNOTEG|RFFDG|RFPROC)){
	case -1:
		panic(1, "fork");
	default:
		_exits(0);
	case 0:
		break;
	}

	io(srvfd);
	exits(0);
}
Ejemplo n.º 18
0
void
main(int argc, char *argv[])
{
	Filsys *fs;
	int ream, fsok;
	int newbufsize, nocheck;
	char buf[NAMELEN];
	int pid, ctl;

	progname = "kfs";
	procname = "init";

	/*
	 * insulate from invoker's environment and keep it from swapping
	 */
	rfork(RFNAMEG|RFNOTEG|RFREND);

	confinit();
	sfd = -1;
	ream = 0;
	newbufsize = 0;
	nocheck = 0;
	wrenfile = "/dev/sdC0/fs";

	pid = getpid();
	snprint(buf, sizeof buf, "/proc/%d/ctl", pid);
	ctl = open(buf, OWRITE);
	fprint(ctl, "noswap\n");
	close(ctl);

	buf[0] = '\0';

	ARGBEGIN{
	case 'b':
		newbufsize = atol(ARGF());
		break;
	case 'c':
		nocheck = 1;
		break;
	case 'f':
		wrenfile = ARGF();
		break;
	case 'm':
		nwren = atol(ARGF());
		break;
	case 'n':
		strncpy(buf, ARGF(), NAMELEN-1);
		buf[NAMELEN-1] = '\0';
		break;
	case 'p':
		cmdmode = atol(ARGF());
		break;
	case 'r':
		ream = 1;
		break;
	case 's':
		sfd = 0;
		rfd = dup(1, -1);
		close(1);
		if(open("/dev/cons", OWRITE) < 0)
			open("#c/cons", OWRITE);
		break;
	case 'B':
		conf.niobuf = strtoul(ARGF(), 0, 0);
		break;
	case 'C':
		chat = 1;
		break;
	default:
		usage();
	}ARGEND

	if(argc != 0)
		usage();

	cmdfd = 2;

	if (access(wrenfile, AREAD|AWRITE) == -1)
		sysfatal("%s cannot access device", wrenfile);

	formatinit();
	sublockinit();

	if(buf[0])
		sprint(service, "kfs.%s", buf);
	else
		strcpy(service, "kfs");
	chan = chaninit(service);
	consinit();
	tlocks = ialloc(NTLOCK * sizeof *tlocks);
	uid = ialloc(conf.nuid * sizeof(*uid));
	uidspace = ialloc(conf.uidspace * sizeof(*uidspace));
	gidspace = ialloc(conf.gidspace * sizeof(*gidspace));

	/*
	 * init global locks
	 */
	wlock(&mainlock); wunlock(&mainlock);

	/*
	 * init the file system, ream it if needed, and get the block sizes
	 */
	ream = fsinit(ream, newbufsize);
	iobufinit();
	for(fs=filesys; fs->name; fs++)
		if(fs->flags & FREAM){		/* set by fsinit if reamed */
			ream++;
			rootream(fs->dev, getraddr(fs->dev));
			superream(fs->dev, superaddr(fs->dev));
		}

	boottime = time(nil);

	consserve();
	fsok = superok(filesys[0].dev, superaddr(filesys[0].dev), 0);
	if(!nocheck && !ream && !fsok)
		cmd_exec("check fq");

	startproc(forkserve, "srv");
	startproc(syncproc, "sync");

	exits(0);
}
Ejemplo n.º 19
0
void
main(int argc, char *argv[])
{
	int fd, i;
	int n = 1000, m;
	int s = 1;
	double *t, t0, t1;
	unsigned char *buf;
	double a, d, max, min;

	m = OREAD;
	ARGBEGIN{
	case 'n':
		n = atoi(ARGF());
		break;
	case 's':
		s = unittoull(ARGF());
		if(s < 1 || s > 1024*1024)
			sysfatal("bad size");
		break;
	case 'r':
		m = OREAD;
		break;
	case 'w':
		m = OWRITE;
		break;
	}ARGEND

	fd = 0;
	if(argc == 1){
		fd = open(argv[0], m);
		if(fd < 0)
			sysfatal("could not open file: %s: %r", argv[0]);
	}

	buf = malloc(s);
	t = malloc(n*sizeof(double));

	t0 = nsec();
	for(i=0; i<n; i++){
		if(m == OREAD){
			if(pread(fd, buf, s, 0) < s)
				sysfatal("bad read: %r");
		}else{
			if(pwrite(fd, buf, s, 0) < s)
				sysfatal("bad write: %r");
		}
		t1 = nsec();
		t[i] = (t1 - t0)*1e-3;
		t0 = t1;
	}

	a = 0.;
	d = 0.;
	max = 0.;
	min = 1e12;

	for(i=0; i<n; i++){
		a += t[i];
		if(max < t[i])
			max = t[i];
		if(min > t[i])
			min = t[i];
	}

	a /= n;

	for(i=0; i<n; i++)
		d += (a - t[i]) * (a - t[i]);
	d /= n;
	d = sqrt(d);

	print("avg = %.0fµs min = %.0fµs max = %.0fµs dev = %.0fµs\n", a, min, max, d);

	exits(0);
}
Ejemplo n.º 20
0
void
usage(void)
{
	fprint(2, "usage: kfs [-cCr] [-b bufsize] [-s infd outfd] [-f fsfile]\n");
	exits(0);
}
Ejemplo n.º 21
0
Archivo: main.c Proyecto: 99years/plan9
void
args(int argc, char *argv[])
{
	char *p;
	long t;
	int f, i;
	Obj2 *q;

	memset(flags, 0, sizeof(flags));
	ARGBEGIN {
	default:
		fprint(2, "astro [-adeklmopst] [-c nperiod] [-C tperiod]\n");
		exits(0);

	case 'c':
		nperiods = 1;
		p = ARGF();
		if(p)
			nperiods = atol(p);
		flags['c']++;
		break;
	case 'C':
		p = ARGF();
		if(p)
			per = atof(p);
		break;
	case 'e':
		eobj1 = nil;
		eobj2 = nil;
		p = ARGF();
		if(p) {
			for(i=0; q=objlst[i]; i++) {
				if(strcmp(q->name, p) == 0)
					eobj1 = q;
				if(strcmp(q->name1, p) == 0)
					eobj1 = q;
			}
			p = ARGF();
			if(p) {
				for(i=0; q=objlst[i]; i++) {
					if(strcmp(q->name, p) == 0)
						eobj2 = q;
					if(strcmp(q->name1, p) == 0)
						eobj2 = q;
				}
			}
		}
		if(eobj1 && eobj2) {
			flags['e']++;
			break;
		}
		fprint(2, "cant recognize eclipse objects\n");
		exits("eflag");

	case 'a':
	case 'd':
	case 'j':
	case 'k':
	case 'l':
	case 'm':
	case 'o':
	case 'p':
	case 's':
	case 't':
		flags[ARGC()]++;
		break;
	} ARGEND
	if(*argv){
		fprint(2, "usage: astro [-dlpsatokm] [-c nday] [-e obj1 obj2]\n");
		exits("usage");
	}

	t = time(0);
	day = t/86400. + 25567.5;
	if(flags['d'])
		day = readate();
	if(flags['j'])
		print("jday = %.4f\n", day);
	deltat = day * .001704;
	if(deltat > 32.184)		// assume date is utc1
		deltat = 32.184;	// correct by leap sec
	if(flags['t'])
		deltat = readdt();

	if(flags['l']) {
		fprint(2, "nlat wlong elev\n");
		readlat(0);
	} else {
		f = open(herefile, OREAD);
		if(f < 0) {
			fprint(2, "%s?\n", herefile);
			/* btl mh */
			nlat = (40 + 41.06/60)*radian;
			awlong = (74 + 23.98/60)*radian;
			elev = 150 * 3.28084;
		} else {
			readlat(f);
			close(f);
		}
	}
}
Ejemplo n.º 22
0
void
main(int argc, char *argv[])
{
	char *p;
	int nout, nproc, i, c;

	thechar = '5';
	thestring = "arm";

	ensuresymb(NSYMB);
	memset(debug, 0, sizeof(debug));
	cinit();
	outfile = 0;
	setinclude(".");
	ARGBEGIN {
	default:
		c = ARGC();
		if(c >= 0 || c < sizeof(debug))
			debug[c] = 1;
		break;

	case 'o':
		outfile = ARGF();
		break;

	case 'D':
		p = ARGF();
		if(p) {
			if (nDlist%8 == 0) 
				Dlist = allocn(Dlist, nDlist*sizeof(char *), 
					8*sizeof(char *));
			Dlist[nDlist++] = p;
		}
		break;

	case 'I':
		p = ARGF();
		setinclude(p);
		break;
	case 't':
		thechar = 't';
		thestring = "thumb";
		break;
	} ARGEND
	if(*argv == 0) {
		print("usage: %ca [-options] file.s\n", thechar);
		errorexit();
	}
	if(argc > 1 && systemtype(Windows)){
		print("can't assemble multiple files on windows\n");
		errorexit();
	}
	if(argc > 1 && !systemtype(Windows)) {
		nproc = 1;
		if(p = getenv("NPROC"))
			nproc = atol(p);	/* */
		c = 0;
		nout = 0;
		for(;;) {
			Waitmsg *w;

			while(nout < nproc && argc > 0) {
				i = fork();
				if(i < 0) {
					fprint(2, "fork: %r\n");
					errorexit();
				}
				if(i == 0) {
					print("%s:\n", *argv);
					if(assemble(*argv))
						errorexit();
					exits(0);
				}
				nout++;
				argc--;
				argv++;
			}
			w = wait();
			if(w == nil) {
				if(c)
					errorexit();
				exits(0);
			}
			if(w->msg[0])
				c++;
			nout--;
		}
	}
	if(assemble(argv[0]))
		errorexit();
	exits(0);
}
Ejemplo n.º 23
0
Archivo: kbits.c Proyecto: aahud/harvey
Bitmap *
kreadbits(char *file, int n, long *chars, int size, uchar *bits, int **doneptr)
{
	Bitmap *bm;
	Biobuf *bf;
	char *p;
	long kmin, kmax;
	int i, j, byt;
	int nch;
	long c;
	uchar *b;
	int *done;
	uchar *nbits;
	static int dig[256] = {
	['0'] 0, ['1'] 1, ['2'] 2, ['3'] 3, ['4'] 4, ['5'] 5, ['6'] 6, ['7'] 7,
	['8'] 8, ['9'] 9, ['a'] 10, ['b'] 11, ['c'] 12, ['d'] 13, ['e'] 14, ['f'] 15,
	};

	bf = Bopen(file, OREAD);
	if(bf == 0){
		fprint(2, "%s: %s: %r\n", argv0, file);
		exits("bitfile open error");
	}
	done = (int *)malloc(n*sizeof(done[0]));
	if(done == 0){
		fprint(2, "%s: malloc error (%d bytes)\n", argv0, n);
		exits("malloc error");
	}
	*doneptr = done;
	memset(done, 0, n*sizeof(done[0]));
	kmin = 65536;
	kmax = 0;
	for(i = 0; i < n; i++){
		c = chars[i];
		if(kmin > c)
			kmin = c;
		if(kmax < c)
			kmax = c;
	}
	nch = 0;
	byt = size/8;
	Brdline(bf, '\n');		/* header line 1 */
	Brdline(bf, '\n');		/* header line 2 */
	while(p = (char *)Brdline(bf, '\n')){
		c = strtol(p+17, (char **)0, 10);
		if((c < kmin) || (c > kmax))
			continue;
		for(i = 0; i < n; i++)
			if(c == chars[i]){
				nch++;
				done[i] = 1;
				p += 25;
				b = bits + i*byt;
				for(i = 0; i < size; i++){	/* rows */
					for(j = 0; j < byt; j++){
						*b++ = (dig[*p]<<4) | dig[p[1]];
						p += 2;
					}
					b += (n-1)*byt;
				}
				break;
			}
	}
	nbits = (uchar *)malloc(nch*byt*size);
	if(nbits == 0){
		fprint(2, "%s: malloc error (%d bytes)\n", argv0, nch*byt);
		exits("malloc error");
	}
	c = 0;
	for(i = 0; i < n; i++)
		if(done[i]){
			for(j = 0; j < size; j++)
				memmove(nbits+c*byt+j*nch*byt, bits+i*byt+j*n*byt, byt);
			c++;
		}
	bm = balloc((Rectangle){(Point){0, 0}, (Point){nch*size, size}}, 0);
	if(bm == 0){
		fprint(2, "%s: balloc failure\n", argv0);
		exits("balloc failure");
	}
	wrbitmap(bm, 0, size, nbits);
	for(i = 0; i < n; i++)
		if(done[i] == 0){
			/*fprint(2, "char 0x%x (%d) not found\n", chars[i], chars[i]);/**/
		}
	return(bm);
}
Ejemplo n.º 24
0
Archivo: tty.c Proyecto: Requaos/harvey
void
main(int argc, char *argv[])
{
	int frchld[2];
	int tochld[2];
	int pid;
	int i, j;

	ARGBEGIN{
	case 'p':
		ctrlp++;
		break;
	}ARGEND

	pipe(frchld);
	pipe(tochld);

	switch(pid = rfork(RFPROC|RFFDG|RFNOTEG)){
	case -1:
		sysfatal("fork");
	case 0:
		close(tochld[0]);
		close(frchld[1]);

		dup(tochld[1], 0);
		dup(frchld[0], 1);
		dup(frchld[0], 2);
		close(tochld[1]);
		close(frchld[0]);

		exec(argv[0], argv);
		sysfatal("exec");
	default:
		close(tochld[1]);
		close(frchld[0]);
		break;
	}

	static char buf[512];
	static char obuf[512];
	int nfr, nto;
	int wpid;

	switch(wpid = rfork(RFPROC|RFFDG)){
	case -1:
		sysfatal("rfork");
	case 0:
		close(0);
		while((nfr = read(frchld[1], buf, sizeof buf)) > 0){
			int i, j;
			j = 0;
			for(i = 0; i < nfr; i++){
				if(buf[i] == '\n'){
					if(j > 0){
						write(1, buf, j);
						j = 0;
					}
					write(1, "\r\n", 2);
				} else {
					buf[j++] = buf[i];
				}
			}

			if(write(1, buf, j) != j)
				exits("write");
		}
		fprint(1, "aux/tty: got eof\n");
		postnote(PNPROC, getppid(), "interrupt");
		exits(nil);
	default:
		close(frchld[1]);
		j = 0;
		while((nto = read(0, buf, sizeof buf)) > 0){
			int oldj;
			oldj = j;
			for(i = 0; i < nto; i++){
				if(buf[i] == '\r' || buf[i] == '\n'){
					obuf[j++] = '\n';
					write(tochld[0], obuf, j);
					j = 0;
				} else if(ctrlp && buf[i] == '\x10'){ // ctrl-p
					if(j > 0){
						write(tochld[0], obuf, j);
						j = 0;
					}
					int fd;
					fd = open("/dev/reboot", OWRITE);
					if(fd != -1){
						fprint(1, "aux/tty: rebooting the system\n");
						sleep(2000);
						write(fd, "reboot", 6);
						close(fd);
					} else {
						fprint(1, "aux/tty: open /dev/reboot: %r\n");
					}
				} else if(buf[i] == '\003'){ // ctrl-c
					if(j > 0){
						write(tochld[0], obuf, j);
						j = 0;
					}
					fprint(1, "aux/tty: sent interrupt to %d\n", pid);
					postnote(PNGROUP, pid, "interrupt");
					continue;
				} else if(buf[i] == '\x1d' ){ // ctrl-]
					if(j > 0){
						write(tochld[0], obuf, j);
						j = 0;
					}
					fprint(1, "aux/tty: sent interrupt to %d\n", pid);
					postnote(PNGROUP, pid, "term");
					continue;
				} else {
					obuf[j++] = buf[i];
				}
			}
			if(j > 0){
				write(1, obuf+oldj, j-oldj);
			}

		}
		close(0);
		close(1);
		close(2);
		close(tochld[0]);
		postnote(PNGROUP, pid, "hangup");
		waitpid();
		waitpid();
	}
	exits(nil);
}
Ejemplo n.º 25
0
void
usage(void)
{
	fprint(2, "usage: fossil/epoch fs [new-low-epoch]\n");
	exits("usage");
}
Ejemplo n.º 26
0
Archivo: tty.c Proyecto: Requaos/harvey
void
usage(void)
{
	fprint(2, "usage: aux/tty [-p] cmd args...\n");
	exits("usage");
}
Ejemplo n.º 27
0
void
main(int argc, char **argv)
{
	String *msg;
	String *firstline;
	char *listname, *alfile;
	Waitmsg *w;
	int fd;
	char *replytoname = nil;

	ARGBEGIN{
	case 'r':
		replytoname = ARGF();
		break;
	}ARGEND;

	rfork(RFENVG|RFREND);

	if(argc < 2)
		usage();
	alfile = argv[0];
	listname = argv[1];
	if(replytoname == nil)
		replytoname = listname;

	readaddrs(alfile);

	if(Binit(&in, 0, OREAD) < 0)
		sysfatal("opening input: %r");

	msg = s_new();
	firstline = s_new();

	/* discard the 'From ' line */
	if(s_read_line(&in, firstline) == nil)
		sysfatal("reading input: %r");

	/* read up to the first 128k of the message.  more is ridiculous. 
	     Not if word documents are distributed.  Upped it to 2MB (pb) */
	if(s_read(&in, msg, 2*1024*1024) <= 0)
		sysfatal("reading input: %r");

	/* parse the header */
	yyinit(s_to_c(msg), s_len(msg));
	yyparse();

	/* get the sender */
	getaddrs();
	if(from == nil)
		from = sender;
	if(from == nil)
		sysfatal("message must contain From: or Sender:");
	if(strcmp(listname, s_to_c(from)) == 0)
		sysfatal("can't remail messages from myself");
	addaddr(s_to_c(from));

	/* start the mailer up and return a pipe to it */
	fd = startmailer(listname);

	/* send message adding our own reply-to and precedence */
	printmsg(fd, msg, replytoname, listname);
	close(fd);

	/* wait for mailer to end */
	while(w = wait()){
		if(w->msg != nil && w->msg[0])
			sysfatal("%s", w->msg);
		free(w);
	}

	/* if the mailbox exists, cat the mail to the end of it */
	appendtoarchive(listname, firstline, msg);
	exits(0);
}
Ejemplo n.º 28
0
void
main(int argc, char **argv)
{
	HConnect *c;
	Dir *dir;
	Hio *hin, *hout;
	char *s, *t, *fn;
	int n, nfn, datafd, htmlfd;

	c = init(argc, argv);

	if(dangerous(c->req.uri)){
		hfail(c, HSyntax);
		exits("failed");
	}

	if(hparseheaders(c, HSTIMEOUT) < 0)
		exits("failed");
	hout = &c->hout;
	if(c->head.expectother){
		hfail(c, HExpectFail, nil);
		exits("failed");
	}
	if(c->head.expectcont){
		hprint(hout, "100 Continue\r\n");
		hprint(hout, "\r\n");
		hflush(hout);
	}

	s = nil;
	if(strcmp(c->req.meth, "POST") == 0){
		hin = hbodypush(&c->hin, c->head.contlen, c->head.transenc);
		if(hin != nil){
			alarm(HSTIMEOUT);
			s = hreadbuf(hin, hin->pos);
			alarm(0);
		}
		if(s == nil){
			hfail(c, HBadReq, nil);
			exits("failed");
		}
		t = strchr(s, '\n');
		if(t != nil)
			*t = '\0';
	}else if(strcmp(c->req.meth, "GET") != 0 && strcmp(c->req.meth, "HEAD") != 0){
		hunallowed(c, "GET, HEAD, PUT");
		exits("unallowed");
	}else
		s = c->req.search;
	if(s == nil){
		hfail(c, HNoData, "save");
		exits("failed");
	}

	if(strlen(s) > MaxLog)
		s[MaxLog] = '\0';
	n = snprint(c->xferbuf, HBufSize, "at %ld %s\n", time(0), s);


	nfn = strlen(c->req.uri) + 64;
	fn = halloc(c, nfn);

	/*
	 * open file descriptors & write log line
	 */
	snprint(fn, nfn, "/usr/web/save/%s.html", c->req.uri);
	htmlfd = open(fn, OREAD);
	if(htmlfd < 0 || (dir = dirfstat(htmlfd)) == nil){
		hfail(c, HNotFound, c->req.uri);
		exits("failed");
		return;
	}

	snprint(fn, nfn, "/usr/web/save/%s.data", c->req.uri);
	datafd = openLocked(fn, OWRITE);
	if(datafd < 0){
		errstr(c->xferbuf, sizeof c->xferbuf);
		if(strstr(c->xferbuf, "locked") != nil)
			hfail(c, HTempFail, c->req.uri);
		else
			hfail(c, HNotFound, c->req.uri);
		exits("failed");
	}
	seek(datafd, 0, 2);
	write(datafd, c->xferbuf, n);
	close(datafd);

	sendfd(c, htmlfd, dir, hmkcontent(c, "text", "html", nil), nil);

	exits(nil);
}
Ejemplo n.º 29
0
void
main(int argc, char **argv)
{
	int isdir;
	char *file, *cname;
	Dir *dir;

	quotefmtinstall();
	time0 = time(0);

	ARGBEGIN{
	case 'D':
		chatty9p++;
		break;
	case 'd':
		sdname = EARGF(usage());
		break;
	case 'm':
		mtpt = EARGF(usage());
		break;
	case 'r':
		rdonly = 1;
		break;
	case 's':
		srvname = EARGF(usage());
		break;
	default:
		usage();
	}ARGEND

	if(argc != 1)
		usage();
	file = argv[0];
	dir = dirstat(file);
	if(!dir)
		sysfatal("%s: %r", file);
	isdir = (dir->mode & DMDIR) != 0;
	free(dir);

	if (isdir) {
		cname = smprint("%s/ctl", file);
		if ((ctlfd = open(cname, ORDWR)) < 0)
			sysfatal("open %s: %r", cname);
		file = smprint("%s/data", file);
	}
	if((fd = open(file, rdonly? OREAD: ORDWR)) < 0)
		sysfatal("open %s: %r", file);

	sectsize = 512;			/* conventional */
	dir = dirfstat(fd);
	if (dir)
		nsect = dir->length / sectsize;
	free(dir);

	inquiry = estrdup9p(inquiry);
	tab[0].inuse = 1;
	tab[0].name = estrdup9p("data");
	tab[0].mode = 0666;
	tab[0].length = nsect;

	postmountsrv(&fs, srvname, mtpt, MBEFORE);
	exits(nil);
}
Ejemplo n.º 30
0
void
usage(void)
{
    dprint("usage: sam [-d] [-t samterm] [-s sam name] -r machine\n");
    exits("usage");
}