proper forking of spawned processes

This commit is contained in:
nova
2026-05-21 01:11:56 +02:00
parent 41af25e0b1
commit 9f7ed73885
2 changed files with 35 additions and 13 deletions

View File

@@ -4,6 +4,7 @@
#define SETTINGS_CURSES_TIMEOUT 100 /* read: inopts(3NCURSES), blocking time between user inputs */ #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 #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``*/ * 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 #ifndef CONFIG_GUARD
@@ -21,21 +22,21 @@ static const mimetype mimetype_default_cmd[] = {
* file --mime-type -b ./image.gif * file --mime-type -b ./image.gif
* gives us "image/gif", thusly if we want to open gif in mpv rather than feh, * gives us "image/gif", thusly if we want to open gif in mpv rather than feh,
* we need to define "gif" before "image" */ * we need to define "gif" before "image" */
{ "text", "$EDITOR" }, { "text", "$EDITOR" },
{ "avif", "nohup mpv ^ >/dev/null 2>&1 &" }, { "avif", "@ mpv" },
{ "gif", "nohup mpv --loop-file=\"inf\" ^ >/dev/null 2>&1 &" }, { "gif", "@ mpv --loop-file=\"inf\"" },
{ "image", "feh ^ >/dev/null 2>&1 &" }, { "image", "@ feh" },
{ "video", "nohup mpv ^ >/dev/null 2>&1 &" }, { "video", "@ mpv" },
{ "audio", "mpv" }, { "audio", "mpv" },
{ "pdf", "zathura" }, { "pdf", "@ zathura" },
}; };
static const extension file_extension_default_cmd[] = { static const extension file_extension_default_cmd[] = {
/* extension shell command /* extension shell command
* similar to mimetype_default_cmd, however it searches for exact string matches * similar to mimetype_default_cmd, however it searches for exact string matches
* and is checked before mimetype_default_cmd */ * and is checked before mimetype_default_cmd */
{ ".exe", "wine"}, { ".exe", "wine"},
{ ".cbz", "mcomix ^ &"}, { ".cbz", "@ mcomix"},
{ ".cbr", "mcomix ^ &"}, { ".cbr", "@ mcomix"},
{ ".json", "$EDITOR"}, { ".json", "$EDITOR"},
{ ".csv", "$EDITOR"}, { ".csv", "$EDITOR"},
{ ".blend", "blender-bin-5.0.0"}, /* version number in bin in main repo? yea idc */ { ".blend", "blender-bin-5.0.0"}, /* version number in bin in main repo? yea idc */

View File

@@ -226,8 +226,18 @@ void move_right(){
if (extension <= mid_dir.current_file->file_name + strlen(mid_dir.current_file->file_name)) { if (extension <= mid_dir.current_file->file_name + strlen(mid_dir.current_file->file_name)) {
for (i = 0; i < file_extension_default_count; i++) { for (i = 0; i < file_extension_default_count; i++) {
if (strcmp(extension, file_extension_default_cmd[i].file_extension) == 0) { if (strcmp(extension, file_extension_default_cmd[i].file_extension) == 0) {
cmd = parse_cmd(file_extension_default_cmd[i].command, mid_dir.current_file); if (file_extension_default_cmd[i].command[0] == SETTINGS_COMMAND_FORK) {
if (system(cmd)) { 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; status |= STATUS_MOVE_RIGHT_MATCH;
update(); update();
@@ -238,9 +248,20 @@ void move_right(){
if (!(status & STATUS_MOVE_RIGHT_MATCH)) { if (!(status & STATUS_MOVE_RIGHT_MATCH)) {
for (i = 0; i < mimetype_default_count; i++) { for (i = 0; i < mimetype_default_count; i++) {
if (strstr(mime, mimetype_default_cmd[i].mimetype)) { if (strstr(mime, mimetype_default_cmd[i].mimetype)) {
cmd = parse_cmd(mimetype_default_cmd[i].command, mid_dir.current_file); if (mimetype_default_cmd[i].command[0] == SETTINGS_COMMAND_FORK) {
if (system(cmd)) { 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(); update();
break; break;
} }