--- freem/src/transact.c 2025/04/13 04:22:43 1.9 +++ freem/src/transact.c 2025/04/15 16:49:36 1.10 @@ -1,5 +1,5 @@ /* - * $Id: transact.c,v 1.9 2025/04/13 04:22:43 snw Exp $ + * $Id: transact.c,v 1.10 2025/04/15 16:49:36 snw Exp $ * FreeM transaction processing support * * @@ -24,6 +24,9 @@ * along with FreeM. If not, see . * * $Log: transact.c,v $ + * Revision 1.10 2025/04/15 16:49:36 snw + * Make use of logprintf throughout codebase + * * Revision 1.9 2025/04/13 04:22:43 snw * Fix snprintf calls * @@ -61,6 +64,7 @@ #include "shmmgr.h" #include "mref.h" #include "tp_check.h" +#include "log.h" #define FALSE 0 #define TRUE 1 @@ -75,8 +79,6 @@ union semun { }; #endif -void m_log (int, const char *); - int semid_tp; int tp_committing = FALSE; int tp_level = 0; @@ -94,14 +96,12 @@ void tp_init(void) semid_tp = semget (tp_sk, 1, 0666 | IPC_CREAT); if (semid_tp == -1) { - fprintf (stderr, "tp_init: failed to create transaction processing semaphore [errno %d]\r\n", errno); - exit (1); + logprintf (FM_LOG_FATAL, "tp_init: failed to create transaction processing semaphore [%s]", strerror (errno)); } arg.val = 1; if (semctl (semid_tp, 0, SETVAL, arg) == -1) { - fprintf (stderr, "tp_init: failed to initialize transaction processing semaphore\r\n"); - exit (1); + logprintf (FM_LOG_FATAL, "tp_init: failed to initialize transaction processing semaphore [%s]", strerror (errno)); } } @@ -109,8 +109,7 @@ void tp_init(void) semid_tp = semget (tp_sk, 1, 0); if (semid_tp == -1) { - fprintf (stderr, "tp_init: could not attach to transaction processing semaphore [errno %d]\r\n", errno); - exit (1); + logprintf (FM_LOG_FATAL, "tp_init: could not attach to transaction processing semaphore [%s]", strerror (errno)); } } @@ -126,19 +125,17 @@ short tp_get_sem(void) char msgbuf[100]; - snprintf (msgbuf, sizeof (msgbuf) - 1, "tp_get_sem: process %d attempting to acquire transaction processing semaphore", pid); - m_log (1, msgbuf); + logprintf (FM_LOG_INFO, "tp_get_sem: process %d attempting to acquire transaction processing semaphore", pid); /* our process already owns the semaphore */ if (shm_config->hdr->tp_owner == pid) { - snprintf (msgbuf, sizeof (msgbuf) - 1, "tp_get_sem: process %d increments transaction processing semaphore counter", pid); - m_log (1, msgbuf); + logprintf (FM_LOG_INFO, "tp_get_sem: process %ld increments transaction processing semaphore counter", pid); if (first_process == TRUE) { - fprintf (stderr, "tp_get_sem: daemon process increments critical section counter\r\n"); + logprintf (FM_LOG_INFO, "tp_get_sem: daemon process increments critical section counter"); } @@ -148,7 +145,7 @@ short tp_get_sem(void) } if (first_process == TRUE) { - fprintf (stderr, "tp_get_sem: daemon process enters critical section\r\n"); + logprintf (FM_LOG_INFO, "tp_get_sem: daemon process enters critical section"); } @@ -158,20 +155,16 @@ short tp_get_sem(void) shm_config->hdr->tp_owner = pid; shm_config->hdr->tp_semctr = 1; - snprintf (msgbuf, sizeof (msgbuf) - 1, "tp_get_sem: process %d takes transaction processing semaphore", pid); - m_log (1, msgbuf); - + logprintf (FM_LOG_INFO, "tp_get_sem: process %ld takes transaction processing semaphore", pid); if (first_process == TRUE) { - fprintf (stderr, "tp_get_sem: daemon process takes transaction processing semaphore\r\n"); + logprintf (FM_LOG_INFO, "tp_get_sem: daemon process takes transaction processing semaphore"); } return TRUE; } - snprintf (msgbuf, sizeof (msgbuf) - 1, "tp_get_sem: process %d attempting to acquire transaction processing semaphore (tries = %d)", pid, tries); - m_log (1, msgbuf); - + logprintf (FM_LOG_WARNING, "tp_get_sem: process %ld retries attempting to acquire transaction processing semaphore (tries = %d)", pid, tries); sleep (1); @@ -191,7 +184,7 @@ void tp_release_sem(void) struct sembuf s = {0, 1, 0}; if (first_process == TRUE) { - fprintf (stderr, "tp_release_sem: daemon process leaves critical section\r\n"); + logprintf (FM_LOG_INFO, "tp_release_sem: daemon process leaves critical section"); } @@ -199,13 +192,11 @@ void tp_release_sem(void) shm_config->hdr->tp_owner = 0; if (first_process == TRUE) { - fprintf (stderr, "tp_release_sem: daemon process relinquishes transaction processing semaphore\r\n"); + logprintf (FM_LOG_INFO, "tp_release_sem: daemon process relinquishes transaction processing semaphore"); } - snprintf (msgbuf, sizeof (msgbuf) - 1, "tp_get_sem: process %d releases transaction processing semaphore", pid); - m_log (1, msgbuf); - + logprintf (FM_LOG_INFO, "tp_get_sem: process %ld releases transaction processing semaphore", pid); semop (semid_tp, &s, 1); @@ -213,11 +204,10 @@ void tp_release_sem(void) else { if (first_process == TRUE) { - fprintf (stderr, "tp_release_sem: daemon process decrements critical section counter\r\n"); + logprintf (FM_LOG_INFO, "tp_release_sem: daemon process decrements critical section counter"); } - snprintf (msgbuf, sizeof (msgbuf) - 1, "tp_get_sem: process %d decrements transaction processing semaphore counter", pid); - m_log (1, msgbuf); + logprintf (FM_LOG_INFO, "tp_get_sem: process %d decrements transaction processing semaphore counter", pid); shm_config->hdr->tp_semctr--; } @@ -230,8 +220,7 @@ int tp_tstart(char *tp_id, short serial, if (tp_level == TP_MAX_NEST) { char m[256]; - snprintf (m, sizeof (m) - 1, "Attempt to exceed TP_MAX_NEST. Transaction aborted.\r\n\201"); - write_m (m); + logprintf (FM_LOG_ERROR, "Attempt to exceed TP_MAX_NEST. Transaction aborted."); return FALSE; } @@ -254,8 +243,7 @@ int tp_tstart(char *tp_id, short serial, } else { - fprintf (stderr, "tp_tstart: could not get transaction processing semaphore\r\n"); - exit (1); + logprintf (FM_LOG_FATAL, "tp_tstart: could not get transaction processing semaphore"); } @@ -275,8 +263,7 @@ int tp_add_op(short islock, short action if (transactions[tp_level].opcount == TP_MAX_OPS) { char m[256]; - snprintf (m, sizeof (m) - 1, "Attempt to exceed TP_MAX_OPS at transaction level %d. Rolling back.\r\n\201", tp_level); - write_m (m); + logprintf (FM_LOG_ERROR, "attempt to exceed TP_MAX_OPS at transaction level %d; rolling back", tp_level); free (gr);