Exemplo n.º 1
0
/* Switch to command-line mode. */
static void
cmd_colon(key_info_t key_info, keys_info_t *keys_info)
{
	update_marks(view);
	set_count_vars(key_info.count);
	enter_cmdline_mode(CLS_COMMAND, "", NULL);
}
Exemplo n.º 2
0
static void
cmd_return(key_info_t key_info, keys_info_t *keys_info)
{
	update_marks(view);
	if(vle_mode_is(VISUAL_MODE))
	{
		vle_mode_set(NORMAL_MODE, VMT_PRIMARY);
	}
}
int main(int argc, char **argv)
{
    populate_device(argc, argv);
    reset_marks(TOTAL_MARKS);

    int ret;

    int pid = fork();
    if (pid == 0) {
        printv("Child sleeping for 3 seconds\n");
        sleep(3);
        printv("Child creating buffer\n");
        ret = create_buffer(1);
        printv("Child finished, exiting with status %d\n", ret);
        _exit(ret);
    } else {
        printv("Parent creating buffer\n");
        ret = create_buffer(0);
        if (ret == 0) {
            update_marks(1);
        }
        if (ret != 4) {
            device_dirty = true;
        }

        int status;
        wait(&status);
        if (WIFEXITED(status)) {
            int child_ret = WEXITSTATUS(status);
            printv("Child returned status %d\n", child_ret);
            if (child_ret == 0) {
                update_marks(1);
            }
            if (ret != 4) {
                device_dirty = true;
            }
        }
    }

    /* only the parent gets here */
    return end_marks();
}
void try_close(int fd, bool mark)
{
    /* 1 mark: close. If open() did not work, then the student gets 0 for this
     * criteria too.
     */
    if (fd < 0) {
        fprintf(stderr, "Since all opens failed, close() cannot be tested)\n");
    } else {
        if (close(fd) == 0) {
            if (mark) 
                update_marks(1);
        } else {
            printe("close()");
        }
    }
}
int main(int argc, char **argv)
{
    populate_device(argc, argv);
    reset_marks(TOTAL_MARKS);

    /* 1 mark: open. Device must be able to be opened for reading, writing and
     * reading/writing to get this mark.
     */
    int fd = open_rdrw();
    if (fd < 0) {
        try_close(fd, false);
        goto end;
    }

    fd = open_rdonly();
    if (fd < 0) {
        try_close(fd, false);
        goto end;
    }

    fd = open_wronly();
    if (fd < 0) {
        try_close(fd, false);
        goto end;
    }

    /* fork another process and try the opens again */
    char *arg0 = "./test_1a_open_close";
    printv("Now forking to run %s\n", arg0);
    int pid = fork();
    if (pid == 0) {
        /* get rid of stdout */
        int null_fd = open("/dev/null", O_WRONLY);
        if (null_fd < 0) {
            printe("open(\"/dev/null\")");
            _exit(ERR_EXEC);
        }
        if (dup2(null_fd, STDOUT_FILENO) < 0) {
            printe("dup2()");
            _exit(ERR_EXEC);
        }

        /* execute the single open/close test */
        execl(arg0, arg0, device_node, NULL);
        printe("execl()");
        _exit(ERR_EXEC);
    } else {
        int status;
        wait(&status);
        if (WIFEXITED(status)) {
            int ret = WEXITSTATUS(status);
            if (ret == 0) {
                printv("Child returned success\n");
                update_marks(1);
            } else {
                printv("Child returned non-zero status (%d)\n", ret);
            }
        }
        try_close(fd, true);
        goto end;
    }

end:
    return end_marks();
}
Exemplo n.º 6
0
/* Switch to command-line mode. */
static void
cmd_colon(key_info_t key_info, keys_info_t *keys_info)
{
	update_marks(view);
	enter_cmdline_mode(CMD_SUBMODE, L"", NULL);
}