diff options
author | Joseph Hunkeler <jhunkeler@gmail.com> | 2023-10-31 12:02:57 -0400 |
---|---|---|
committer | Joseph Hunkeler <jhunkeler@gmail.com> | 2023-10-31 12:02:57 -0400 |
commit | 8a2e123abe5bbfc8787035e5b8f77fbccdec113b (patch) | |
tree | 9d9d517c07b20248322364cf6e02b73f31df606f /src | |
parent | dafe7639674f3bfc66d3a116ec836c269c08f473 (diff) | |
download | stasis-8a2e123abe5bbfc8787035e5b8f77fbccdec113b.tar.gz |
Close dangling file descriptor
* Only remove temporary script file if it exists
Diffstat (limited to 'src')
-rw-r--r-- | src/system.c | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/src/system.c b/src/system.c index ad89682..8cd7303 100644 --- a/src/system.c +++ b/src/system.c @@ -96,6 +96,7 @@ int shell2(struct Process *proc, char *args) { fprintf(tp, "#!/bin/bash\n%s\n", args); fflush(tp); fclose(tp); + close(fd); chmod(t_name, 0755); pid = fork(); @@ -123,6 +124,10 @@ int shell2(struct Process *proc, char *args) { } retval = execl("/bin/bash", "bash", "-c", t_name, (char *) NULL); + if (!access(t_name, F_OK)) { + remove(t_name); + } + if (proc != NULL && strlen(proc->stdout)) { if (fp_out != NULL) { fflush(fp_out); @@ -154,7 +159,9 @@ int shell2(struct Process *proc, char *args) { } } - remove(t_name); + if (!access(t_name, F_OK)) { + remove(t_name); + } if (proc != NULL) { proc->returncode = status; |