bgjobs.free = bgjobs.entries;
}
-int fullbg(void) {
+int bgfull(void) {
return !bgjobs.free;
}
int pushbg(struct bgjob job) {
struct bglink *p;
- if (fullbg()) return 0;
+ if (bgfull()) return 0;
(p = bgjobs.free)->job = job;
bgjobs.free = p->next;
return 1;
}
+int pushbgid(pid_t id) {
+ return pushbg((struct bgjob){.id = id, .config = canonical});
+}
+
int peekbg(struct bgjob *job) {
if (bgjobs.active && job) *job = bgjobs.active->job;
return 0;
}
-int pushid(pid_t id) {
- return pushbg((struct bgjob){.id = id, .config = canonical});
-}
-
-void removeid(pid_t id) {
+void removebg(pid_t id) {
struct bglink *p, *prev;
for (prev = NULL, p = bgjobs.active; p; prev = p, p = p->next)
if (id == -1) {
id = p->job.id;
p = p->next;
- removeid(id);
+ removebg(id);
} else p = p->next;
}
errno = e;
note("Unable to wake up suspended job %d", job.id);
return EXIT_FAILURE;
}
- removeid(job.id);
+ removebg(job.id);
job.suspended = 0;
pushbg(job);
};
void initbg(void);
-
-int fullbg(void);
+int bgfull(void);
int pushbg(struct bgjob job);
+int pushbgid(pid_t id);
int peekbg(struct bgjob *job);
int searchbg(pid_t id, struct bgjob *job);
-
-int pushid(pid_t id);
-void removeid(pid_t id);
-
+void removebg(pid_t id);
void waitbg(int sig);
-
void deinitbg(void);
note("Unable to wake up job %d", id);
return 0;
}
- removeid(id);
+ removebg(id);
/* SIGCHLD handler is really the function that reaps the foreground process,
* the waitpid() below is just to block the current thread of execution until
islist = c->prev.term > BG || c->current.term > BG;
if (c->t) {
- if (c->current.term == BG && fullbg()) {
+ if (c->current.term == BG && bgfull()) {
note("Unable to place job in background, too many background jobs");
return quit(c);
}
return quit(c);
}
if (ispipestart || c->current.term == BG) {
- pushid(jobid);
+ pushbgid(jobid);
return 1;
}
if (c->current.term != PIPE && !runfg(jobid)) return quit(c);