version 1.10, 2025/05/12 18:18:00
|
version 1.12, 2025/05/14 15:28:55
|
Line 24
|
Line 24
|
* along with FreeM. If not, see <https://www.gnu.org/licenses/>. |
* along with FreeM. If not, see <https://www.gnu.org/licenses/>. |
* |
* |
* $Log$ |
* $Log$ |
|
* Revision 1.12 2025/05/14 15:28:55 snw |
|
* Get basic job table and lock table functionality working with new shared memory architecture |
|
* |
|
* Revision 1.11 2025/05/14 12:22:04 snw |
|
* Further work on shared memory |
|
* |
* Revision 1.10 2025/05/12 18:18:00 snw |
* Revision 1.10 2025/05/12 18:18:00 snw |
* Further work on shared memory |
* Further work on shared memory |
* |
* |
Line 118 short jobtab_get_sem(void)
|
Line 124 short jobtab_get_sem(void)
|
int tries; |
int tries; |
struct sembuf s = {0, -1, IPC_NOWAIT}; |
struct sembuf s = {0, -1, IPC_NOWAIT}; |
|
|
|
logprintf (FM_LOG_DEBUG, "jobtab_get_sem: attempting to acquire job table semaphore"); |
|
|
if (have_jobtab_sem) { |
if (have_jobtab_sem) { |
|
logprintf (FM_LOG_DEBUG, "jobtab_get_sem: acquired semaphore by virtue of already owning it"); |
return TRUE; |
return TRUE; |
} |
} |
|
|
for (tries = 0; tries < 5; tries++) { |
for (tries = 0; tries < 5; tries++) { |
|
|
if (semop (semid_jobtab, &s, 1) != -1) { |
if (semop (semid_jobtab, &s, 1) != -1) { |
|
logprintf (FM_LOG_DEBUG, "jobtab_get_sem: acquired semaphore by virtue of calling semop on it"); |
have_jobtab_sem = TRUE; |
have_jobtab_sem = TRUE; |
return TRUE; |
return TRUE; |
} |
} |
|
|
logprintf (FM_LOG_INFO, "jobtab_get_sem: sleeping for retry [tries = %d]", tries); |
logprintf (FM_LOG_INFO, "jobtab_get_sem: sleeping for retry [tries = %d; errno = %d; error = %s]", tries, errno, strerror (errno)); |
sleep (1); |
sleep (1); |
|
|
} |
} |
logprintf (FM_LOG_ERROR, "jobtab_get_sem: failed to acquire job table semaphore"); |
logprintf (FM_LOG_ERROR, "jobtab_get_sem: failed to acquire job table semaphore"); |
|
|
have_jobtab_sem = FALSE; |
have_jobtab_sem = FALSE; |
return FALSE; |
return FALSE; |
} |
} |
Line 143 void jobtab_release_sem(void)
|
Line 153 void jobtab_release_sem(void)
|
{ |
{ |
struct sembuf s = {0, 1, 0}; |
struct sembuf s = {0, 1, 0}; |
|
|
semop (semid_jobtab, &s, 1); |
logprintf (FM_LOG_DEBUG, "jobtab_release_sem: trying to release job table semaphore"); |
|
if (semop (semid_jobtab, &s, 1) != -1) { |
have_jobtab_sem = FALSE; |
logprintf (FM_LOG_DEBUG, "jobtab_release_sem: released job table semaphore by means of semop"); |
|
have_jobtab_sem = FALSE; |
|
} |
|
else { |
|
logprintf (FM_LOG_FATAL, "jobtab_release_sem: failed to release job table semaphore (error code %d [%s])", errno, strerror (errno)); |
|
} |
} |
} |
|
|
|
|
Line 190 skip_alloc:
|
Line 205 skip_alloc:
|
} |
} |
} |
} |
|
|
s->next = SBM(shm_config->hdr->jobtab_head); |
s->next = SBM(SOA(shm_config->hdr->jobtab_head)); |
shm_config->hdr->jobtab_head = SBM(s); |
shm_config->hdr->jobtab_head = SBM(s); |
|
|
jobtab_release_sem (); |
jobtab_release_sem (); |
Line 211 void job_remove(const pid_t pid)
|
Line 226 void job_remove(const pid_t pid)
|
|
|
if ((t != (job_slot_t *) NULL) && (t->pid == pid)) { |
if ((t != (job_slot_t *) NULL) && (t->pid == pid)) { |
|
|
shm_config->hdr->jobtab_head = SBM(t->next); |
shm_config->hdr->jobtab_head = SBM(SOA(t->next)); |
shm_free (t); |
shm_free (t); |
|
|
jobtab_release_sem (); |
jobtab_release_sem (); |
Line 222 void job_remove(const pid_t pid)
|
Line 237 void job_remove(const pid_t pid)
|
|
|
while ((t != NULL) && (t->pid != pid)) { |
while ((t != NULL) && (t->pid != pid)) { |
p = t; |
p = t; |
t = SBA(t->next); |
t = SOA(t->next); |
} |
} |
|
|
if (t == NULL) { |
if (t == NULL) { |
Line 273 void job_set_ecode(const pid_t target_pi
|
Line 288 void job_set_ecode(const pid_t target_pi
|
logprintf (FM_LOG_FATAL, "job_set_ecode: failed to get job table semaphore"); |
logprintf (FM_LOG_FATAL, "job_set_ecode: failed to get job table semaphore"); |
} |
} |
|
|
for (s = shm_config->hdr->jobtab_head; s != NULL; s = s->next) { |
for (s = SOA(shm_config->hdr->jobtab_head); s != NULL; s = SOA(s->next)) { |
|
|
if (s->pid == target_pid) { |
if (s->pid == target_pid) { |
strncpy (s->last_ecode, ecode, 20); |
strncpy (s->last_ecode, ecode, 20); |
Line 292 pid_t job_stop_requested (const pid_t ta
|
Line 307 pid_t job_stop_requested (const pid_t ta
|
|
|
job_slot_t *s; |
job_slot_t *s; |
|
|
for (s = shm_config->hdr->jobtab_head; s != NULL; s = s->next) { |
for (s = SOA(shm_config->hdr->jobtab_head); s != NULL; s = SOA(s->next)) { |
if (s->pid == target_pid) { |
if (s->pid == target_pid) { |
return s->stop_requested; |
return s->stop_requested; |
} |
} |
Line 308 void job_request_all_stop(void)
|
Line 323 void job_request_all_stop(void)
|
job_slot_t *s; |
job_slot_t *s; |
|
|
|
|
for (s = shm_config->hdr->jobtab_head; s != NULL; s = s->next) { |
for (s = SOA(shm_config->hdr->jobtab_head); s != NULL; s = SOA(s->next)) { |
|
|
if ((s->flags & JFLG_DAEMON) != JFLG_DAEMON) { |
if ((s->flags & JFLG_DAEMON) != JFLG_DAEMON) { |
job_request_stop (s->pid); |
job_request_stop (s->pid); |
Line 324 void job_signal_all(const int sig)
|
Line 339 void job_signal_all(const int sig)
|
|
|
job_slot_t *s; |
job_slot_t *s; |
|
|
for (s = shm_config->hdr->jobtab_head; s != NULL; s = s->next) { |
for (s = SOA(shm_config->hdr->jobtab_head); s != NULL; s = SOA(s->next)) { |
|
|
if ((s->flags & JFLG_DAEMON) != JFLG_DAEMON) { |
if ((s->flags & JFLG_DAEMON) != JFLG_DAEMON) { |
kill (s->pid, sig); |
kill (s->pid, sig); |
Line 341 int job_count(void)
|
Line 356 int job_count(void)
|
job_slot_t *s; |
job_slot_t *s; |
int ct = 0; |
int ct = 0; |
|
|
for (s = shm_config->hdr->jobtab_head; s != NULL; s = s->next) { |
for (s = SOA(shm_config->hdr->jobtab_head); s != NULL; s = SOA(s->next)) { |
|
|
if ((s->flags & JFLG_DEFUNCT) != JFLG_DEFUNCT) { |
if ((s->flags & JFLG_DEFUNCT) != JFLG_DEFUNCT) { |
ct++; |
ct++; |
Line 362 job_slot_t *job_set_status(const pid_t t
|
Line 377 job_slot_t *job_set_status(const pid_t t
|
logprintf (FM_LOG_FATAL, "job_set_status: failed to get job table semaphore"); |
logprintf (FM_LOG_FATAL, "job_set_status: failed to get job table semaphore"); |
} |
} |
|
|
for (s = shm_config->hdr->jobtab_head; s != NULL; s = s->next) { |
for (s = SOA(shm_config->hdr->jobtab_head); s != NULL; s = SOA(s->next)) { |
|
|
if (s->pid == target_pid) { |
if (s->pid == target_pid) { |
s->status = status; |
s->status = status; |
Line 388 void job_gc_mark(void)
|
Line 403 void job_gc_mark(void)
|
logprintf (FM_LOG_FATAL, "job_gc_mark: failed to get job table semaphore"); |
logprintf (FM_LOG_FATAL, "job_gc_mark: failed to get job table semaphore"); |
} |
} |
|
|
for (s = shm_config->hdr->jobtab_head; s != NULL; s = s->next) { |
for (s = SOA(shm_config->hdr->jobtab_head); s != NULL; s = SOA(s->next)) { |
|
logprintf (FM_LOG_WARNING, "job_gc_mark looking at pid %ld", s->pid); |
if ((jobstat = kill (s->pid, 0)) != 0) { |
if ((jobstat = kill (s->pid, 0)) != 0) { |
|
|
switch (jobstat) { |
switch (jobstat) { |
Line 442 void job_gc_sweep(void)
|
Line 457 void job_gc_sweep(void)
|
} |
} |
|
|
|
|
for (s = shm_config->hdr->jobtab_head; s != NULL; s = s->next) { |
for (s = SOA(shm_config->hdr->jobtab_head); s != NULL; s = SOA(s->next)) { |
|
|
if ((s->flags & JFLG_DEFUNCT) == JFLG_DEFUNCT) { |
if ((s->flags & JFLG_DEFUNCT) == JFLG_DEFUNCT) { |
|
|
Line 482 ipc_slot_t *job_send_ipc(const pid_t rec
|
Line 497 ipc_slot_t *job_send_ipc(const pid_t rec
|
} |
} |
|
|
|
|
for (j = shm_config->hdr->jobtab_head; j != NULL; j = j->next) { |
for (j = SOA(shm_config->hdr->jobtab_head); j != NULL; j = SOA(j->next)) { |
|
|
if (j->pid == receiver_pid) { |
if (j->pid == receiver_pid) { |
|
|
Line 514 job_slot_t *job_get(const pid_t target_p
|
Line 529 job_slot_t *job_get(const pid_t target_p
|
|
|
job_slot_t *s; |
job_slot_t *s; |
|
|
for (s = shm_config->hdr->jobtab_head; s != NULL; s = s->next) { |
for (s = SOA(shm_config->hdr->jobtab_head); s != NULL; s = SOA(s->next)) { |
if (s->pid == target_pid) return s; |
if (s->pid == target_pid) return s; |
} |
} |
|
|
Line 536 void job_dump(void)
|
Line 551 void job_dump(void)
|
printf ("%-10s%-15s%-20s%-22s%s\r\n", "PID", "STATUS", "LAST ECODE", "STARTED", "FLAGS"); |
printf ("%-10s%-15s%-20s%-22s%s\r\n", "PID", "STATUS", "LAST ECODE", "STARTED", "FLAGS"); |
printf ("%-10s%-15s%-20s%-22s%s\r\n", "---", "------", "----------", "-------", "-----"); |
printf ("%-10s%-15s%-20s%-22s%s\r\n", "---", "------", "----------", "-------", "-----"); |
|
|
for (s = shm_config->hdr->jobtab_head; s != NULL; s = s->next) { |
for (s = SOA(shm_config->hdr->jobtab_head); s != NULL; s = SOA(s->next)) { |
|
|
strftime (time_buf, 20, "%Y-%m-%d %H:%M:%S", localtime (&(s->start_time))); |
strftime (time_buf, 20, "%Y-%m-%d %H:%M:%S", localtime (&(s->start_time))); |
|
|