--- freem/src/jobtab.c 2025/03/24 02:57:49 1.5
+++ freem/src/jobtab.c 2025/05/01 21:02:31 1.9
@@ -1,5 +1,5 @@
/*
- * $Id: jobtab.c,v 1.5 2025/03/24 02:57:49 snw Exp $
+ * $Id: jobtab.c,v 1.9 2025/05/01 21:02:31 snw Exp $
* job table implementation
*
*
@@ -24,6 +24,18 @@
* along with FreeM. If not, see .
*
* $Log: jobtab.c,v $
+ * Revision 1.9 2025/05/01 21:02:31 snw
+ * Documentation updates
+ *
+ * Revision 1.8 2025/04/30 20:03:09 snw
+ * Work on entryref parser
+ *
+ * Revision 1.7 2025/04/17 00:34:04 snw
+ * More logging improvements
+ *
+ * Revision 1.6 2025/04/10 01:24:38 snw
+ * Remove C++ style comments
+ *
* Revision 1.5 2025/03/24 02:57:49 snw
* Shared memory compatibility fixes for OS/2
*
@@ -38,10 +50,12 @@
#include
#include
#include
+#include
#include "mpsdef.h"
#include "shmmgr.h"
#include "jobtab.h"
+#include "log.h"
#if !defined(__OpenBSD__) && !defined(__APPLE__) && !defined(__OS2__)
union semun {
@@ -66,20 +80,18 @@ void jobtab_init(void)
semid_jobtab = semget (jt_sk, 1, 0666 | IPC_CREAT);
if (semid_jobtab == -1) {
- fprintf (stderr, "jobtab_init: failed to create job table semaphore\r\n");
- exit (1);
+ logprintf (FM_LOG_FATAL, "jobtab_init: failed to create job table semaphore (error code %d [%s])", errno, strerror (errno));
}
else {
- fprintf (stderr, "jobtab_init: job table semaphore created with semid %d\r\n", semid_jobtab);
+ logprintf (FM_LOG_INFO, "jobtab_init: job table semaphore created with semid %d", semid_jobtab);
}
arg.val = 1;
if (semctl (semid_jobtab, 0, SETVAL, arg) == -1) {
- fprintf (stderr, "jobtab_init: failed to initialize job table semaphore\r\n");
- exit (1);
+ logprintf (FM_LOG_FATAL, "jobtab_init: failed to initialize job table semaphore (error code %d [%s])", errno, strerror (errno));
}
else {
- fprintf (stderr, "jobtab_init: job table semaphore initialized\r\n");
+ logprintf (FM_LOG_INFO, "jobtab_init: job table semaphore initialized");
}
}
@@ -87,8 +99,10 @@ void jobtab_init(void)
semid_jobtab = semget (jt_sk, 1, 0);
if (semid_jobtab == -1) {
- fprintf (stderr, "jobtab_init: could not attach to job table semaphore\r\n");
- exit (1);
+ logprintf (FM_LOG_FATAL, "jobtab_init: could not attach to job table semaphore (error code %d [%s])", errno, strerror (errno));
+ }
+ else {
+ logprintf (FM_LOG_INFO, "jobtab_init: attached to job table semaphore (semid %d)", semid_jobtab);
}
}
@@ -102,7 +116,6 @@ short jobtab_get_sem(void)
struct sembuf s = {0, -1, IPC_NOWAIT};
if (have_jobtab_sem) {
-// fprintf (stderr, "jobtab_get_sem: this process already owns the job table semaphore\r\n");
return TRUE;
}
@@ -113,12 +126,11 @@ short jobtab_get_sem(void)
return TRUE;
}
- /* fprintf (stderr, "jobtab_get_sem: sleeping for retry [tries = %d]\r\n", tries); */
-
+ logprintf (FM_LOG_INFO, "jobtab_get_sem: sleeping for retry [tries = %d]", tries);
sleep (1);
}
- fprintf (stderr, "jobtab_get_sem: fail\r\n");
+ logprintf (FM_LOG_ERROR, "jobtab_get_sem: failed to acquire job table semaphore");
have_jobtab_sem = FALSE;
return FALSE;
@@ -140,8 +152,7 @@ job_slot_t *job_init(short is_fmadm)
job_slot_t *s;
if (jobtab_get_sem () == FALSE) {
- fprintf (stderr, "job_init: failed to get job table semaphore\r\n");
- exit (1);
+ logprintf (FM_LOG_FATAL, "job_init: failed to get job table semaphore");
}
for (s = shm_config->hdr->jobtab_head; s != NULL; s = s->next) {
@@ -191,8 +202,8 @@ void job_remove(const pid_t pid)
job_slot_t *t = shm_config->hdr->jobtab_head;
job_slot_t *p = NULL;
- if (jobtab_get_sem() == FALSE) {
- fprintf (stderr, "job_remove: failed to get job table semaphore\r\n");
+ if (jobtab_get_sem () == FALSE) {
+ logprintf (FM_LOG_FATAL, "job_remove: failed to get job table semaphore");
exit (1);
}
@@ -222,6 +233,7 @@ void job_remove(const pid_t pid)
jobtab_release_sem ();
+ locktab_unlock_all_by_pid (pid);
}
void job_request_stop(const pid_t target_pid)
@@ -230,8 +242,7 @@ void job_request_stop(const pid_t target
job_slot_t *s;
if (jobtab_get_sem() == FALSE) {
- fprintf (stderr, "job_request_stop: failed to get job table semaphore\r\n");
- exit (1);
+ logprintf (FM_LOG_FATAL, "job_request_stop: failed to get job table semaphore");
}
for (s = shm_config->hdr->jobtab_head; s != NULL; s = s->next) {
@@ -256,9 +267,8 @@ void job_set_ecode(const pid_t target_pi
job_slot_t *s;
- if (jobtab_get_sem() == FALSE) {
- fprintf (stderr, "job_set_ecode: failed to get job table semaphore\r\n");
- exit (1);
+ if (jobtab_get_sem () == FALSE) {
+ 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) {
@@ -279,7 +289,6 @@ pid_t job_stop_requested (const pid_t ta
{
job_slot_t *s;
-
for (s = shm_config->hdr->jobtab_head; s != NULL; s = s->next) {
if (s->pid == target_pid) {
@@ -347,9 +356,8 @@ job_slot_t *job_set_status(const pid_t t
job_slot_t *s;
- if (jobtab_get_sem() == FALSE) {
- fprintf (stderr, "job_set_status: failed to get job table semaphore\r\n");
- exit (1);
+ if (jobtab_get_sem () == FALSE) {
+ 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) {
@@ -372,31 +380,43 @@ void job_gc_mark(void)
{
job_slot_t *s;
+ int jobstat;
if (jobtab_get_sem () == FALSE) {
- fprintf (stderr, "job_gc_mark: failed to get job table semaphore\r\n");
- exit (1);
+ 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) {
- if (kill (s->pid, 0) != 0) {
- fprintf (stderr, "job_gc_mark: marking pid %ld DEFUNCT\r\n", (long) s->pid);
- s->flags = JFLG_DEFUNCT;
+ if ((jobstat = kill (s->pid, 0)) != 0) {
+
+ switch (jobstat) {
+
+ case EPERM:
+ logprintf (FM_LOG_WARNING, "job_gc_mark: environment daemon lacks permissions to pid %ld", (long) s->pid);
+ break;
+
+ case ESRCH:
+ logprintf (FM_LOG_INFO, "job_gc_mark: marking pid %ld DEFUNCT", (long) s->pid);
+ s->flags = JFLG_DEFUNCT;
+ break;
+
+ }
+
}
if ((s->flags & JFLG_NEW) == JFLG_NEW) {
if ((s->flags & JFLG_DAEMON) == JFLG_DAEMON) {
- fprintf (stderr, "job_gc_mark: registering new daemon %ld\r\n", (long) s->pid);
+ logprintf (FM_LOG_INFO, "job_gc_mark: registering new daemon %ld", (long) s->pid);
s->flags = JFLG_ALIVE | JFLG_DAEMON;
}
else {
if ((s->flags & JFLG_FMADM) == JFLG_FMADM) {
- fprintf (stderr, "job_gc_mark: registering new fmadm process %ld\r\n", (long) s->pid);
+ logprintf (FM_LOG_INFO, "job_gc_mark: registering new fmadm process %ld", (long) s->pid);
s->flags = JFLG_ALIVE | JFLG_FMADM;
}
else {
- fprintf (stderr, "job_gc_mark: registering new interpreter process %ld\r\n", (long) s->pid);
+ logprintf (FM_LOG_INFO, "job_gc_mark: registering new interpreter process %ld", (long) s->pid);
s->flags = JFLG_ALIVE;
}
}
@@ -416,8 +436,7 @@ void job_gc_sweep(void)
NULLPTRCHK(k_buf,"job_gc_sweep");
if (jobtab_get_sem () == FALSE) {
- fprintf (stderr, "job_gc_sweep: failed to get job table semaphore\r\n");
- exit (1);
+ logprintf (FM_LOG_FATAL, "job_gc_sweep: failed to get job table semaphore");
}
@@ -425,7 +444,7 @@ void job_gc_sweep(void)
if ((s->flags & JFLG_DEFUNCT) == JFLG_DEFUNCT) {
- fprintf (stderr, "job_gc_sweep: sweeping DEFUNCT pid %ld\r\n", (long) s->pid);
+ logprintf (FM_LOG_INFO, "job_gc_sweep: sweeping DEFUNCT pid %ld", (long) s->pid);
snprintf (k_buf, STRLEN - 1, "^$JOB\202%d\201", s->pid);
@@ -456,9 +475,8 @@ ipc_slot_t *job_send_ipc(const pid_t rec
ipc_slot_t *s = (ipc_slot_t *) shm_alloc (sizeof (ipc_slot_t));
NULLPTRCHK(s,"job_send_ipc");
- if (jobtab_get_sem() == FALSE) {
- fprintf (stderr, "job_send_ipc: failed to get job table semaphore\r\n");
- exit (1);
+ if (jobtab_get_sem () == FALSE) {
+ logprintf (FM_LOG_FATAL, "job_send_ipc: failed to get job table semaphore");
}