Beispiel #1
0
char*
qmail(char **argv, char *buf, int n, Biobuf *cout)
{
    Waitmsg *status;
    int i, pid, pipefd[2];
    char path[512];
    Biobuf *bp;

    pid = 0;
    if(tflag == 0) {
        if(pipe(pipefd) < 0)
            exits("pipe");
        pid = fork();
        if(pid == 0) {
            dup(pipefd[0], 0);
            for(i = sysfiles(); i >= 3; i--)
                close(i);
            snprint(path, sizeof(path), "%s/qer", UPASBIN);
            *argv=path;
            exec(path, argv);
            exits("exec");
        }
        Binit(&bout, pipefd[1], OWRITE);
        bp = &bout;
    } else
        bp = Bopen("/dev/null", OWRITE);

    while(n > 0) {
        Bwrite(bp, buf, n);
        if(cout)
            Bwrite(cout, buf, n);
        n = Bread(&bin, buf, sizeof(buf)-1);
    }
    Bterm(bp);
    if(cout)
        Bterm(cout);
    if(tflag)
        return 0;

    close(pipefd[1]);
    close(pipefd[0]);
    for(;;) {
        status = wait();
        if(status == nil || status->pid == pid)
            break;
        free(status);
    }
    if(status == nil)
        strcpy(buf, "wait failed");
    else {
        strcpy(buf, status->msg);
        free(status);
    }
    return buf;
}
Beispiel #2
0
/* start a new process */
extern process *
noshell_proc_start(char **av, stream *inp, stream *outp, stream *errp, int newpg, char *who)
{
	process *pp;
	int i, n;

	if ((pp = (process *)malloc(sizeof(process))) == 0) {
		if (inp != 0)
			stream_free(inp);
		if (outp != 0)
			stream_free(outp);
		if (errp != 0)
			stream_free(errp);
		return 0;
	}
	pp->std[0] = inp;
	pp->std[1] = outp;
	pp->std[2] = errp;
	switch (pp->pid = fork()) {
	case -1:
		proc_free(pp);
		return 0;
	case 0:
		if(newpg)
			sysdetach();
		for (i=0; i<3; i++)
			if (pp->std[i] != 0){
				close(Bfildes(pp->std[i]->fp));
				while(pp->std[i]->fd < 3)
					pp->std[i]->fd = dup(pp->std[i]->fd, -1);
			}
		for (i=0; i<3; i++)
			if (pp->std[i] != 0)
				dup(pp->std[i]->fd, i);
		for (n = sysfiles(); i < n; i++)
			close(i);
		if(who)
			become(av, who);
		exec(av[0], av);
		perror("proc_start");
		exits("proc_start");
	default:
		for (i=0; i<3; i++)
			if (pp->std[i] != 0) {
				close(pp->std[i]->fd);
				pp->std[i]->fd = -1;
			}
		return pp;
	}
}
Beispiel #3
0
/*
	Function to initialize with default files
*/
initsys()
{
	get_path();			/* For GOG own use...		*/
	strcpy(setp.ftdrs,drsf);	/* FonT DResS : dress1.drs	*/
	strcpy(setp.edict,dicf);	/* Exc. DICTionary : basic.dic	*/
	strcpy(setp.kblyt,kbdf);	/* KeyBoard LaYouT : 501.lyt	*/
	setp.omod	= 5;		/* Ouptut device : Atari laser	*/
	setp.hylg	= 1;		/* HYphenation LanGuage : ENG	*/

	IFerr		= 4;		/* no previous cache setup...	*/

        gltext.slvlist	= (struct slvll *)0L;
        gltext.attr	= &gltxtattr;

	char_MFDB.fd_stand	= 0;	/* setup IFont char MFDB	*/
	char_MFDB.fd_nplanes	= 1;

	H_MARGIN = 0;			/* 0 pica  invisible margin	*/
	V_MARGIN = 0;			/* 0 point invisible margin	*/
	init_Tpos();			/* setup Text Window vars	*/
	read_GOG();			/* Read in GOG defaults, if any */
	sysfiles();			/* load default files...	*/
	clear_tags();			/* start with no text tags	*/
}