Exemple #1
0
int execl(const char *path, const char *arg, ...) {
    va_list args;
    va_start(args, arg);
    char const **argv = bear_strings_build(arg, &args);
    va_end(args);

    bear_report_call(__func__, (char const *const *)argv);
    int const result = call_execve(path, (char *const *)argv, environ);

    bear_strings_release(argv);
    return result;
}
Exemple #2
0
int main(int argc, char *const argv[]) {
    if (argc != 2)
        exit(EXIT_FAILURE);

    expected_out_open(argv[1]);
#ifdef HAVE_EXECV
    call_execv();
#endif
#ifdef HAVE_EXECVE
    call_execve();
#endif
#ifdef HAVE_EXECVP
    call_execvp();
#endif
#ifdef HAVE_EXECVP2
    call_execvP();
#endif
#ifdef HAVE_EXECVPE
    call_execvpe();
#endif
#ifdef HAVE_EXECL
    call_execl();
#endif
#ifdef HAVE_EXECLP
    call_execlp();
#endif
#ifdef HAVE_EXECLE
    call_execle();
#endif
#ifdef HAVE_POSIX_SPAWN
    call_posix_spawn();
#endif
#ifdef HAVE_POSIX_SPAWNP
    call_posix_spawnp();
#endif
    expected_out_close();
    return 0;
}
Exemple #3
0
void read_input(int mode, char *batch_path) {

	char c;
	int current_length = (BUFFER_SIZE + 1);
	line = (char *) malloc(sizeof(char) * (BUFFER_SIZE + 1));
	char *path = (char *) malloc(sizeof(char) * (BUFFER_SIZE + 1));
	fflush(stderr);
	printf("\n[SHELL ] ");
	fflush(stdout);
	int run = 1, len = 0;
	if (mode == BATCH) {
		if (open(batch_path, O_RDONLY) > 0) {
			batch_file = fopen(batch_path, "r");
		} else {
			fprintf(stderr, "cann't open or read the file\n");
			return;
		}
	}
	while (c != EOF && run) {

		if (mode == INTERACTIVE)
			c = getchar();
		else {
			c = fgetc(batch_file);
			if (feof(stdin)) {
				run = 0;
				break;
			}
		}
		switch (c) {
		case '\n':
			if (line[0] == '\0') {
				len = 0;
				free_args();
				bzero(line, current_length);
				fflush(stderr);
				printf("\n[SHELL ] ");
				fflush(stdout);
			} else {

				if (mode == BATCH) {
					printf("%s\n", line);
				}
				if (len >= BUFFER_SIZE) {
					fprintf(stderr, "buffer limit excited\n");
					bzero(line, current_length);
					len = 0;
					continue;
				}
				add_to_history(line);
				free_args();
				fill_argv(line);
				if (is_comment(line) == 0) {
					if (strchr(line, '=') != NULL
							&& strcmp(args[0], "echo") != 0) {
						assign_var(line);
					} else {
//						free_args();
//						fill_argv(line);
						if (strcmp(args[0], "echo") != 0) {
							int i;
							for (i = 0; args[i] != NULL; i++) {
								append_home_dir(args[i]);
								fix_echo_line(args[i]);
							}
						} else {
							int i;
							for (i = 1; args[i] != NULL; i++) {
								fix_echo_line(args[i]);
							}
						}

						if (strcmp("exit", line) == 0) {
							run = 0;
							break;
						} else if (strcmp("history", args[0]) == 0) {
							execute_history();
						} else if (strcmp("cd", args[0]) == 0)
							cd();
						else {
							strcpy(path, args[0]);
							if (strchr(path, '/') != NULL) {
								int fd;
								if ((fd = open(path, O_RDONLY)) > 0) {
									close(fd);
									call_execve(path);
								} else {
									fprintf(stderr,
											"%s: No such file or directory\n",
											args[0]);
								}
							} else {
								if (!is_command(path)) {
									fprintf(stderr, "%s: command not found\n",
											args[0]);
								} else {
									call_execve(path);
								}
							}

						}
					}
				}
				free_args();
				fflush(stderr);
				printf("\n[SHELL ] ");
				fflush(stdout);
				bzero(line, BUFFER_SIZE);
				len = 0;
			}
			bzero(line, BUFFER_SIZE);
			break;
		default:
			len++;
			if (len < BUFFER_SIZE) {
				strncat(line, &c, 1);
			}
			break;
		}
	}
	if (mode == BATCH)
		fclose(batch_file);
}
Exemple #4
0
int execv(const char *path, char *const argv[]) {
    bear_report_call(__func__, (char const *const *)argv);
    return call_execve(path, argv, environ);
}