]> Trent Huber's Code - thus.git/commitdiff
Slight refactoring to bg.c
authorTrent Huber <trentmhuber@gmail.com>
Sat, 6 Sep 2025 06:56:40 +0000 (02:56 -0400)
committerTrent Huber <trentmhuber@gmail.com>
Sat, 6 Sep 2025 06:56:40 +0000 (02:56 -0400)
src/builtins/bg.c
src/builtins/bg.h
src/builtins/fg.c
src/run.c

index 6c50e1cbb26d1c7985e8aba67ef94083095600a0..2f78950521a3e119326d7582ee0569b8f4df2282 100644 (file)
@@ -29,14 +29,14 @@ void initbg(void) {
    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;
@@ -46,6 +46,10 @@ int pushbg(struct bgjob job) {
    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;
 
@@ -63,11 +67,7 @@ int searchbg(pid_t id, struct bgjob *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)
@@ -96,7 +96,7 @@ void waitbg(int sig) {
        if (id == -1) {
            id = p->job.id;
            p = p->next;
-           removeid(id);
+           removebg(id);
        } else p = p->next;
    }
    errno = e;
@@ -147,7 +147,7 @@ BUILTIN(bg) {
        note("Unable to wake up suspended job %d", job.id);
        return EXIT_FAILURE;
    }
-   removeid(job.id);
+   removebg(job.id);
    job.suspended = 0;
    pushbg(job);
 
index 6b6c135fefc400d8c920da6337822b9b69c2049e..b933134340e56549490fff6487b7209f19f4f0a8 100644 (file)
@@ -5,15 +5,11 @@ struct bgjob {
 };
 
 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);
index 70fe125e7af7328a884dfbc10b49f02f33dc9ec5..6da9a07e95632f359e43a023cad3e92d6bec6423 100644 (file)
@@ -77,7 +77,7 @@ int runfg(pid_t id) {
        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
index c8960621b9f6ab3ebeb437fb162c1fa986515a23..a0452e26e5b40b1f1780d0dbab53c91ba093d3b1 100644 (file)
--- a/src/run.c
+++ b/src/run.c
@@ -77,7 +77,7 @@ int run(struct context *c) {
 
    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);
        }
@@ -135,7 +135,7 @@ int run(struct context *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);