Example #1
0
int pipe_exec_fg(char const **argv, int in, int out) {
	int pid;

	pid = fork();
	if (pid < 0) {

		ropen(0, fd_rp(in), STAT_READER);
		ropen(1, fd_rp(out), STAT_WRITER);

		if (execv(argv[0], argv)) {
			if (errno == ENOENT) {
				fprintf(stderr, "%s: %s: command not found\n", getname_s(), argv[0]);
			}
			else {
				perror(argv[0]);
			}
			
			abort();
		}
	}
	close(in);
	close(out);
	mwait(PORT_CHILD, pid);

	return 0;
}
Example #2
0
int fish_exec_fg(int argc, char **argv, FILE *in, FILE *out, FILE *err) {
	char const **_argv;
	int pid;

	pid = fork();
	if (pid == 0) {
		if (in)  stdin  = in;
		if (out) stdout = out;
		if (err) stderr = err;

		_argv = malloc(sizeof(char*) * (argc + 1));
		memcpy(_argv, argv, sizeof(char*) * argc);
		_argv[argc] = NULL;

		if (execvp(_argv[0], _argv)) {
			if (errno == ENOENT) {
				fprintf(stderr, "%s: %s: command not found\n", getname_s(), argv[0]);
			}
			else {
				perror(argv[0]);
			}
			
			abort();
		}
	}
	frcall(stdout->fd, AC_WRITE, "set_fgjob %d", pid);
	waitpid(pid, NULL, 0);
	frcall(stdout->fd, AC_WRITE, "set_fgjob %d", 0);
	
	return 0;
}
Example #3
0
static void _sigpanic(const char *message) {

	_stop(-1);

	fprintf(stderr,
		"%s (pid %d \"%s\" terminated)\n", message, getpid(), getname_s());

	abort();
}
Example #4
0
int fish_cd(int argc, char **argv) {
	char *path;

	if (argc < 2) {
		setenv("PWD", "/");
		return 0;
	}

	path = path_simplify(argv[1]);

	if (path && fs_find(path)) {
		setenv("PWD", path);
	}
	else {
		fprintf(stderr, "%s: %s: no such directory\n", getname_s(), argv[1]);
		free(path);
		return 1;
	}

	free(path);
	return 0;
}
Example #5
0
int pipe_list_exec(struct pipe_list *list, int in, int out) {
	int pipefd[2];

	if (!list) {
		return 0;
	}

	while (list->next) {
		if (pipe(pipefd)) {
			fprintf(stderr, "%s: error: could not open pipe\n", getname_s());
			abort();
		}

		pipe_exec_bg(list->argv, in, pipefd[1]);
		in = pipefd[0];

		list = list->next;
	}

	pipe_exec_fg(list->argv, in, out);

	return 0;
}