Beispiel #1
0
bool it_reload_image(arg_t a) {
	if (mode == MODE_IMAGE) {
		load_image(fileidx);
	} else {
		win_set_cursor(&win, CURSOR_WATCH);
		if (!tns_load(&tns, tns.sel, &files[tns.sel], true, false)) {
			remove_file(tns.sel, false);
			tns.dirty = true;
			if (tns.sel >= tns.cnt)
				tns.sel = tns.cnt - 1;
		}
	}
	return true;
}
Beispiel #2
0
bool it_shell_cmd(arg_t a)
{
    int n, status;
    const char *cmdline = (const char*) a;
    pid_t pid;

    if (cmdline == NULL || *cmdline == '\0')
        return false;

    n = mode == MODE_IMAGE ? fileidx : tns.sel;

    if (setenv("SXIV_IMG", files[n].path, 1) < 0) {
        warn("could not set env.-variable: SXIV_IMG. command line was: %s",
             cmdline);
        return false;
    }

    if ((pid = fork()) == 0) {
        execl("/bin/sh", "/bin/sh", "-c", cmdline, NULL);
        warn("could not exec: /bin/sh. command line was: %s", cmdline);
        exit(EXIT_FAILURE);
    } else if (pid < 0) {
        warn("could not fork. command line was: %s", cmdline);
        return false;
    }

    win_set_cursor(&win, CURSOR_WATCH);

    waitpid(pid, &status, 0);
    if (WIFEXITED(status) == 0 || WEXITSTATUS(status) != 0)
        warn("child exited with non-zero return value: %d. command line was: %s",
             WEXITSTATUS(status), cmdline);

    if (mode == MODE_IMAGE) {
        img_close(&img, true);
        load_image(fileidx);
    }
    if (!tns_load(&tns, n, &files[n], true, mode == MODE_IMAGE) &&
            mode == MODE_THUMB)
    {
        remove_file(tns.sel, false);
        tns.dirty = true;
        if (tns.sel >= tns.cnt)
            tns.sel = tns.cnt - 1;
    }
    return true;
}