proper forking of spawned processes
This commit is contained in:
15
config.h
15
config.h
@@ -4,6 +4,7 @@
|
||||
#define SETTINGS_CURSES_TIMEOUT 100 /* read: inopts(3NCURSES), blocking time between user inputs */
|
||||
#define SETTINGS_COMMAND_REPLACE_STR "^" /* if a command in any cmd inside this fle contains this string, it will be replaced with the hovered/selected file name
|
||||
* as of right now, this character cannot be escaped; i.e ``command\^ --arg`` will parse into ``command\path_of_hovered_file --arg``*/
|
||||
#define SETTINGS_COMMAND_FORK '@' /* commands starting with this character will be forked into a new non blokcing detached process */
|
||||
|
||||
/* {{{ */
|
||||
#ifndef CONFIG_GUARD
|
||||
@@ -22,20 +23,20 @@ static const mimetype mimetype_default_cmd[] = {
|
||||
* gives us "image/gif", thusly if we want to open gif in mpv rather than feh,
|
||||
* we need to define "gif" before "image" */
|
||||
{ "text", "$EDITOR" },
|
||||
{ "avif", "nohup mpv ^ >/dev/null 2>&1 &" },
|
||||
{ "gif", "nohup mpv --loop-file=\"inf\" ^ >/dev/null 2>&1 &" },
|
||||
{ "image", "feh ^ >/dev/null 2>&1 &" },
|
||||
{ "video", "nohup mpv ^ >/dev/null 2>&1 &" },
|
||||
{ "avif", "@ mpv" },
|
||||
{ "gif", "@ mpv --loop-file=\"inf\"" },
|
||||
{ "image", "@ feh" },
|
||||
{ "video", "@ mpv" },
|
||||
{ "audio", "mpv" },
|
||||
{ "pdf", "zathura" },
|
||||
{ "pdf", "@ zathura" },
|
||||
};
|
||||
static const extension file_extension_default_cmd[] = {
|
||||
/* extension shell command
|
||||
* similar to mimetype_default_cmd, however it searches for exact string matches
|
||||
* and is checked before mimetype_default_cmd */
|
||||
{ ".exe", "wine"},
|
||||
{ ".cbz", "mcomix ^ &"},
|
||||
{ ".cbr", "mcomix ^ &"},
|
||||
{ ".cbz", "@ mcomix"},
|
||||
{ ".cbr", "@ mcomix"},
|
||||
{ ".json", "$EDITOR"},
|
||||
{ ".csv", "$EDITOR"},
|
||||
{ ".blend", "blender-bin-5.0.0"}, /* version number in bin in main repo? yea idc */
|
||||
|
||||
@@ -226,9 +226,19 @@ void move_right(){
|
||||
if (extension <= mid_dir.current_file->file_name + strlen(mid_dir.current_file->file_name)) {
|
||||
for (i = 0; i < file_extension_default_count; i++) {
|
||||
if (strcmp(extension, file_extension_default_cmd[i].file_extension) == 0) {
|
||||
if (file_extension_default_cmd[i].command[0] == SETTINGS_COMMAND_FORK) {
|
||||
cmd = parse_cmd(file_extension_default_cmd[i].command + 1, mid_dir.current_file);
|
||||
pid_t pid = fork();
|
||||
if (pid == 0 && setsid()) {
|
||||
system(cmd);
|
||||
status = STATUS_QUIT_PROGRAM;
|
||||
exit(1);
|
||||
}
|
||||
} else {
|
||||
cmd = parse_cmd(file_extension_default_cmd[i].command, mid_dir.current_file);
|
||||
if (system(cmd)) {
|
||||
}
|
||||
}
|
||||
status |= STATUS_MOVE_RIGHT_MATCH;
|
||||
update();
|
||||
break;
|
||||
@@ -238,9 +248,20 @@ void move_right(){
|
||||
if (!(status & STATUS_MOVE_RIGHT_MATCH)) {
|
||||
for (i = 0; i < mimetype_default_count; i++) {
|
||||
if (strstr(mime, mimetype_default_cmd[i].mimetype)) {
|
||||
if (mimetype_default_cmd[i].command[0] == SETTINGS_COMMAND_FORK) {
|
||||
cmd = parse_cmd(mimetype_default_cmd[i].command + 1, mid_dir.current_file);
|
||||
pid_t pid = fork();
|
||||
if (pid == 0 && setsid()) {
|
||||
system(cmd);
|
||||
status = STATUS_QUIT_PROGRAM;
|
||||
exit(1);
|
||||
}
|
||||
} else {
|
||||
cmd = parse_cmd(mimetype_default_cmd[i].command, mid_dir.current_file);
|
||||
if (system(cmd)) {
|
||||
}
|
||||
}
|
||||
status |= STATUS_MOVE_RIGHT_MATCH;
|
||||
update();
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user