|
|
6de7cf |
From 354efb96f1e4574f458e994163bbe31c76769573 Mon Sep 17 00:00:00 2001
|
|
|
6de7cf |
From: Chet Ramey <chet.ramey@case.edu>
|
|
|
6de7cf |
Date: Fri, 1 Jun 2018 10:19:56 -0400
|
|
|
6de7cf |
Subject: [PATCH] saved background process status hash table loop fixes
|
|
|
6de7cf |
|
|
|
6de7cf |
---
|
|
|
6de7cf |
jobs.c | 62 +++++++++++++++++++++++++++++++++++++++++-----------
|
|
|
6de7cf |
patchlevel.h | 2 +-
|
|
|
6de7cf |
2 files changed, 50 insertions(+), 14 deletions(-)
|
|
|
6de7cf |
|
|
|
6de7cf |
diff --git a/jobs.c b/jobs.c
|
|
|
6de7cf |
index fc966036..2684632d 100644
|
|
|
6de7cf |
--- a/jobs.c
|
|
|
6de7cf |
+++ b/jobs.c
|
|
|
6de7cf |
@@ -812,8 +812,22 @@ bgp_add (pid, status)
|
|
|
6de7cf |
ps_index_t *bucket, psi;
|
|
|
6de7cf |
struct pidstat *ps;
|
|
|
6de7cf |
|
|
|
6de7cf |
- bucket = pshash_getbucket (pid);
|
|
|
6de7cf |
- psi = bgp_getindex ();
|
|
|
6de7cf |
+ /* bucket == existing chain of pids hashing to same value
|
|
|
6de7cf |
+ psi = where were going to put this pid/status */
|
|
|
6de7cf |
+
|
|
|
6de7cf |
+ bucket = pshash_getbucket (pid); /* index into pidstat_table */
|
|
|
6de7cf |
+ psi = bgp_getindex (); /* bgpids.head, index into storage */
|
|
|
6de7cf |
+
|
|
|
6de7cf |
+ /* XXX - what if psi == *bucket? */
|
|
|
6de7cf |
+ if (psi == *bucket)
|
|
|
6de7cf |
+ {
|
|
|
6de7cf |
+#ifdef DEBUG
|
|
|
6de7cf |
+ internal_warning ("hashed pid %d (pid %d) collides with bgpids.head, skipping", psi, pid);
|
|
|
6de7cf |
+#endif
|
|
|
6de7cf |
+ bgpids.storage[psi].pid = NO_PID; /* make sure */
|
|
|
6de7cf |
+ psi = bgp_getindex (); /* skip to next one */
|
|
|
6de7cf |
+ }
|
|
|
6de7cf |
+
|
|
|
6de7cf |
ps = &bgpids.storage[psi];
|
|
|
6de7cf |
|
|
|
6de7cf |
ps->pid = pid;
|
|
|
6de7cf |
@@ -841,32 +855,47 @@ pshash_delindex (psi)
|
|
|
6de7cf |
ps_index_t psi;
|
|
|
6de7cf |
{
|
|
|
6de7cf |
struct pidstat *ps;
|
|
|
6de7cf |
+ ps_index_t *bucket;
|
|
|
6de7cf |
|
|
|
6de7cf |
ps = &bgpids.storage[psi];
|
|
|
6de7cf |
if (ps->pid == NO_PID)
|
|
|
6de7cf |
return;
|
|
|
6de7cf |
|
|
|
6de7cf |
- if (ps->bucket_next != NO_PID)
|
|
|
6de7cf |
+ if (ps->bucket_next != NO_PIDSTAT)
|
|
|
6de7cf |
bgpids.storage[ps->bucket_next].bucket_prev = ps->bucket_prev;
|
|
|
6de7cf |
- if (ps->bucket_prev != NO_PID)
|
|
|
6de7cf |
+ if (ps->bucket_prev != NO_PIDSTAT)
|
|
|
6de7cf |
bgpids.storage[ps->bucket_prev].bucket_next = ps->bucket_next;
|
|
|
6de7cf |
else
|
|
|
6de7cf |
- *(pshash_getbucket (ps->pid)) = ps->bucket_next;
|
|
|
6de7cf |
+ {
|
|
|
6de7cf |
+ bucket = pshash_getbucket (ps->pid);
|
|
|
6de7cf |
+ *bucket = ps->bucket_next; /* deleting chain head in hash table */
|
|
|
6de7cf |
+ }
|
|
|
6de7cf |
+
|
|
|
6de7cf |
+ /* clear out this cell, just in case */
|
|
|
6de7cf |
+ ps->pid = NO_PID;
|
|
|
6de7cf |
+ ps->bucket_next = ps->bucket_prev = NO_PIDSTAT;
|
|
|
6de7cf |
}
|
|
|
6de7cf |
|
|
|
6de7cf |
static int
|
|
|
6de7cf |
bgp_delete (pid)
|
|
|
6de7cf |
pid_t pid;
|
|
|
6de7cf |
{
|
|
|
6de7cf |
- ps_index_t psi;
|
|
|
6de7cf |
+ ps_index_t psi, orig_psi;
|
|
|
6de7cf |
|
|
|
6de7cf |
if (bgpids.storage == 0 || bgpids.nalloc == 0 || bgpids.npid == 0)
|
|
|
6de7cf |
return 0;
|
|
|
6de7cf |
|
|
|
6de7cf |
/* Search chain using hash to find bucket in pidstat_table */
|
|
|
6de7cf |
- for (psi = *(pshash_getbucket (pid)); psi != NO_PIDSTAT; psi = bgpids.storage[psi].bucket_next)
|
|
|
6de7cf |
- if (bgpids.storage[psi].pid == pid)
|
|
|
6de7cf |
- break;
|
|
|
6de7cf |
+ for (orig_psi = psi = *(pshash_getbucket (pid)); psi != NO_PIDSTAT; psi = bgpids.storage[psi].bucket_next)
|
|
|
6de7cf |
+ {
|
|
|
6de7cf |
+ if (bgpids.storage[psi].pid == pid)
|
|
|
6de7cf |
+ break;
|
|
|
6de7cf |
+ if (orig_psi == bgpids.storage[psi].bucket_next) /* catch reported bug */
|
|
|
6de7cf |
+ {
|
|
|
6de7cf |
+ internal_warning ("bgp_delete: LOOP: psi (%d) == storage[psi].bucket_next", psi);
|
|
|
6de7cf |
+ return 0;
|
|
|
6de7cf |
+ }
|
|
|
6de7cf |
+ }
|
|
|
6de7cf |
|
|
|
6de7cf |
if (psi == NO_PIDSTAT)
|
|
|
6de7cf |
return 0; /* not found */
|
|
|
6de7cf |
@@ -904,15 +933,22 @@ static int
|
|
|
6de7cf |
bgp_search (pid)
|
|
|
6de7cf |
pid_t pid;
|
|
|
6de7cf |
{
|
|
|
6de7cf |
- ps_index_t psi;
|
|
|
6de7cf |
+ ps_index_t psi, orig_psi;
|
|
|
6de7cf |
|
|
|
6de7cf |
if (bgpids.storage == 0 || bgpids.nalloc == 0 || bgpids.npid == 0)
|
|
|
6de7cf |
return -1;
|
|
|
6de7cf |
|
|
|
6de7cf |
/* Search chain using hash to find bucket in pidstat_table */
|
|
|
6de7cf |
- for (psi = *(pshash_getbucket (pid)); psi != NO_PIDSTAT; psi = bgpids.storage[psi].bucket_next)
|
|
|
6de7cf |
- if (bgpids.storage[psi].pid == pid)
|
|
|
6de7cf |
- return (bgpids.storage[psi].status);
|
|
|
6de7cf |
+ for (orig_psi = psi = *(pshash_getbucket (pid)); psi != NO_PIDSTAT; psi = bgpids.storage[psi].bucket_next)
|
|
|
6de7cf |
+ {
|
|
|
6de7cf |
+ if (bgpids.storage[psi].pid == pid)
|
|
|
6de7cf |
+ return (bgpids.storage[psi].status);
|
|
|
6de7cf |
+ if (orig_psi == bgpids.storage[psi].bucket_next) /* catch reported bug */
|
|
|
6de7cf |
+ {
|
|
|
6de7cf |
+ internal_warning ("bgp_search: LOOP: psi (%d) == storage[psi].bucket_next", psi);
|
|
|
6de7cf |
+ return -1;
|
|
|
6de7cf |
+ }
|
|
|
6de7cf |
+ }
|
|
|
6de7cf |
|
|
|
6de7cf |
return -1;
|
|
|
6de7cf |
}
|
|
|
6de7cf |
diff --git a/patchlevel.h b/patchlevel.h
|
|
|
6de7cf |
index a711c495..4a65dc0f 100644
|
|
|
6de7cf |
--- a/patchlevel.h
|
|
|
6de7cf |
+++ b/patchlevel.h
|
|
|
6de7cf |
@@ -25,6 +25,6 @@
|
|
|
6de7cf |
regexp `^#define[ ]*PATCHLEVEL', since that's what support/mkversion.sh
|
|
|
6de7cf |
looks for to find the patch level (for the sccs version string). */
|
|
|
6de7cf |
|
|
|
6de7cf |
-#define PATCHLEVEL 19
|
|
|
6de7cf |
+#define PATCHLEVEL 20
|
|
|
6de7cf |
|
|
|
6de7cf |
#endif /* _PATCHLEVEL_H_ */
|
|
|
6de7cf |
--
|
|
|
6de7cf |
2.29.2
|
|
|
6de7cf |
|