Ejemplo n.º 1
0
int main(int argc, char* args[])
{
    printf("[ibin/init] Init process started... :) Thats so good!\n");
    printf("[ibin/init] Switching into TTY to VGA mode.\nIf you see this something probably went wrong.\n");

    HANDLE cntrl = fmkfifo("/var/cntrl/init");

    texec("/ibin/ttytovga", 0);
    waitResp(cntrl);

    setstdout("/dev/tty0");
    setstdin ("/dev/keyboard");
    setstderr("/dev/tty0");

    printf("[init] now working on tty0\n");

    print_memstat();

    printf("[init] executing virtual file drivers\n");
    texec("/ibin/urnd_prov", 0);
    waitResp(cntrl);

    printf("[init] switching to shell\n");

    char* testparams[] = {
        "test1",
        "test2",
        0
    };

    texec("/ibin/csh", 0);

    while(1);

    return 0;
}
Ejemplo n.º 2
0
void execline(programlist *pgl, path *pth)
{
	/*printf("\n\n\n====\n\n\n"); */
	int i;

	/* set up pipes/filters */
	/*int filterfd[2]; */
	int **filterfds;
	int pipecnt = pgl->count - 1;
	if (pipecnt > 0) {
		filterfds = (int **)malloc(sizeof(int *) * pipecnt);
		if (filterfds == NULL) {
			/*printf("failed to malloc filterfds\n"); */
			exit(1);
		}

		for (i = 0; i < pipecnt; i++) {
			filterfds[i] = (int *)malloc(sizeof(int) * 2);
			if (filterfds[i] == NULL) {
				/*printf("failed to malloc pipe\n"); */
				exit(1);
			}
			if (pipe(filterfds[i]) == -1) {
				/*printf("failed to create pipe. i = %d, err= %d\n", i, errno); */
			}
			/*printf("in = %d, out = %d\n", filterfds[i][0], filterfds[i][1]); */

		}
	}

	/*set up standard in/out */
	int infd, outfd, errfd;
	if (pgl->in != NULL) {
		//infd = setstd(pgl->in, 0, stdin);
		infd = setstdin(pgl->in);
	}
	if (pgl->out != NULL) {
		/*printf("setting out\n=====\n"); */
		outfd = setstd(pgl->out, 1, stdout);
	}
	if (pgl->err != NULL) {
		errfd = setstd(pgl->err, 2, stderr);
	}

	/*set up commands */
	program **programs;
	programs = (program **)malloc(sizeof(program *) * pgl->count);
	if (programs == NULL) {
		exit(1);
	}
	program *crntprg;
	crntprg = pgl->tail;
	for (i = 0; i < pgl->count; i++) {
		programs[i] = (program *)malloc(sizeof(program));
		if (programs[i] == NULL) {
			fprintf(stderr, "failed to malloc\n");
			exit(1);
		}
		programs[i] = crntprg;
		crntprg = crntprg->prev;
	}

	char ***execs;
	execs = (char ***)malloc(sizeof(char **) * pgl->count);
	if (execs == NULL) {
		fprintf(stderr, "Failed to mallocs execs");
		exit(1);
	}
	memset(execs, 0, pgl->count);
	//printf("pgl count = %d\n", pgl->count);
	for (i = 0; i < pgl->count; i++) {
		execs[i] = createcmd(programs[i], pth);
		//printf("exec[i] = %s\n", execs[i][0]);
		if (execs[i] == NULL) {
			printf("Failed to find cmd: %s\n", programs[i]->cmd);
			exit(1);
		}
	}
	free(programs);

	for (i = 0; i < pgl->count; i++) {
		/* Set in for the command as a pipe. */
		pid_t child;
		child = fork();
		if (child == 0) {
			/*printf("My parent is %d\n", getppid()); */
			if (i == 0 && pgl->filtered == 1) {
				//printf("setting pipe1\n");
				/*last in list, don't set stdout, only in */
				dup2(filterfds[i][0], STDIN_FILENO);
			} else if (i == pgl->count - 1 && pgl->filtered == 1) {
				//printf("setting pipe2\n");
				/*first in list dont set in, only out */
				dup2(filterfds[i - 1][1], STDOUT_FILENO);
			} else if (pgl->filtered == 1) {
				//printf("setting pipe3\n");
				dup2(filterfds[i - 1][1], STDOUT_FILENO);
				dup2(filterfds[i][0], STDIN_FILENO);
			}
			if (closepipes(filterfds, pipecnt) == -1) {
				/*printf("Failed to close pipe\n"); */
				exit(1);
			}

			if (execv(execs[i][0], execs[i]) == -1) {
				/*printf("Failed to execute\n"); */
				exit(1);
			}

			exit(0);
		} else {
			continue;
		}
	}
	if (closepipes(filterfds, pipecnt) == -1) {
		/*printf("parent failed to close pipes\n"); */
		exit(1);
	}
	int status;
	for (i = 0; i < pgl->count; i++) {
		wait(&status);
		/*printf("\ti = %d, wait = %d\n", pgl->count, wait(&status)); */
	}

	if (pgl->in != NULL && infd != -1) {
		infd = resetstd(infd, 0, stdin);
	}
	if (pgl->out != NULL && outfd != -1) {
		outfd = resetstd(outfd, 1, stdout);
	}
	if (pgl->err != NULL && errfd != -1) {
		errfd = resetstd(errfd, 2, stderr);
	}

	//clean up pipes
	cleanuppipes(filterfds, pipecnt);
	//clean up execs
	cleanupexecs(execs, pgl);
	

	exit(0);
}