Skip to content

Commit 8e5eb75

Browse files
committed
Enable to remove coproc variables
1 parent df0537e commit 8e5eb75

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

src/core/builtins/job_commands.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,8 +292,20 @@ fn print(core: &mut ShellCore, args: &[String]) {
292292
}
293293
}
294294

295+
fn remove_coproc(core: &mut ShellCore, pos: usize) {
296+
core.job_table[pos].coproc_fds
297+
.iter()
298+
.for_each(|fd| {core.fds.close(*fd);});
299+
300+
if let Some(name) = &core.job_table[pos].coproc_name {
301+
let _ = core.db.unset(&name, None);
302+
let _ = core.db.unset(&(name.to_owned() + "_PID"), None);
303+
}
304+
}
305+
295306
fn remove(core: &mut ShellCore, pos: usize) {
296307
let job_id = core.job_table[pos].id;
308+
remove_coproc(core, pos);
297309
core.job_table.remove(pos);
298310
core.job_table_priority.retain(|id| *id != job_id);
299311
}
@@ -570,6 +582,7 @@ pub fn disown(core: &mut ShellCore, args: &[String]) -> i32 {
570582
let ids = jobspec_to_array_poss(core, "%%");
571583

572584
if ids.len() == 1 {
585+
remove_coproc(core, ids[0]);
573586
core.job_table.remove(ids[0]);
574587
core.job_table_priority.remove(0);
575588
return 0;

src/core/jobtable.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,11 +243,15 @@ impl ShellCore {
243243
stopped.push(i);
244244
}
245245

246-
if table.display_status == "Done"
247-
|| table.display_status == "Killed" {
246+
if table.coproc_name.is_some()
247+
&& (table.display_status == "Done" || table.display_status == "Killed") {
248248
table.coproc_fds
249249
.iter()
250250
.for_each(|fd| {self.fds.close(*fd);});
251+
252+
let name = table.coproc_name.clone().unwrap();
253+
let _ = self.db.unset(&name, None);
254+
let _ = self.db.unset(&(name + "_PID"), None);
251255
}
252256
}
253257

src/elements/command/coproc.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,10 @@ impl Command for Coprocess {
5858

5959
let _ = core.db.set_param("!", &pid.to_string(), None);
6060
let new_job_id = core.generate_new_job_id();
61-
eprintln!("[{}] {}", &new_job_id, &pid);
61+
62+
if core.db.flags.contains('i') {
63+
eprintln!("[{}] {}", &new_job_id, &pid);
64+
}
6265
core.job_table_priority.insert(0, new_job_id);
6366
let mut entry = JobEntry::new(
6467
vec![Some(pid)],

0 commit comments

Comments
 (0)