--- freem/src/transact.c 2025/01/19 02:04:04 1.1.1.1 +++ freem/src/transact.c 2025/04/13 04:22:43 1.9 @@ -1,23 +1,11 @@ /* - * * - * * * - * * * - * *************** - * * * * * - * * MUMPS * - * * * * * - * *************** - * * * - * * * - * * - * - * transact.c + * $Id: transact.c,v 1.9 2025/04/13 04:22:43 snw Exp $ * FreeM transaction processing support * * - * Author: Serena Willis + * Author: Serena Willis * Copyright (C) 1998 MUG Deutschland - * Copyright (C) 2020 Coherent Logic Development LLC + * Copyright (C) 2020, 2025 Coherent Logic Development LLC * * * This file is part of FreeM. @@ -35,6 +23,28 @@ * You should have received a copy of the GNU Affero Public License * along with FreeM. If not, see . * + * $Log: transact.c,v $ + * Revision 1.9 2025/04/13 04:22:43 snw + * Fix snprintf calls + * + * Revision 1.8 2025/04/10 01:24:39 snw + * Remove C++ style comments + * + * Revision 1.7 2025/04/09 19:52:02 snw + * Eliminate as many warnings as possible while building with -Wall + * + * Revision 1.6 2025/03/24 04:13:12 snw + * Replace action macro dat with fra_dat to avoid symbol conflict on OS/2 + * + * Revision 1.5 2025/03/24 02:54:47 snw + * Transaction compat fixes for OS/2 + * + * Revision 1.4 2025/03/09 19:50:47 snw + * Second phase of REUSE compliance and header reformat + * + * + * SPDX-FileCopyrightText: (C) 2025 Coherent Logic Development LLC + * SPDX-License-Identifier: AGPL-3.0-or-later **/ #include @@ -55,7 +65,7 @@ #define FALSE 0 #define TRUE 1 -#if !defined(__OpenBSD__) && !defined(__APPLE__) +#if !defined(__OpenBSD__) && !defined(__APPLE__) && !defined(__OS2__) union semun { int val; /* Value for SETVAL */ struct semid_ds *buf; /* Buffer for IPC_STAT, IPC_SET */ @@ -76,7 +86,6 @@ tp_transaction transactions[TP_MAX_NEST] void tp_init(void) { union semun arg; - char err[255]; key_t tp_sk; tp_sk = ftok (config_file, 4); @@ -117,14 +126,14 @@ short tp_get_sem(void) char msgbuf[100]; - snprintf (msgbuf, 99, "tp_get_sem: process %d attempting to acquire transaction processing semaphore", pid); + snprintf (msgbuf, sizeof (msgbuf) - 1, "tp_get_sem: process %d attempting to acquire transaction processing semaphore", pid); m_log (1, msgbuf); /* our process already owns the semaphore */ if (shm_config->hdr->tp_owner == pid) { - snprintf (msgbuf, 99, "tp_get_sem: process %d increments transaction processing semaphore counter", pid); + snprintf (msgbuf, sizeof (msgbuf) - 1, "tp_get_sem: process %d increments transaction processing semaphore counter", pid); m_log (1, msgbuf); @@ -149,7 +158,7 @@ short tp_get_sem(void) shm_config->hdr->tp_owner = pid; shm_config->hdr->tp_semctr = 1; - snprintf (msgbuf, 99, "tp_get_sem: process %d takes transaction processing semaphore", pid); + snprintf (msgbuf, sizeof (msgbuf) - 1, "tp_get_sem: process %d takes transaction processing semaphore", pid); m_log (1, msgbuf); @@ -160,7 +169,7 @@ short tp_get_sem(void) return TRUE; } - snprintf (msgbuf, 99, "tp_get_sem: process %d attempting to acquire transaction processing semaphore (tries = %d)", pid, tries); + snprintf (msgbuf, sizeof (msgbuf) - 1, "tp_get_sem: process %d attempting to acquire transaction processing semaphore (tries = %d)", pid, tries); m_log (1, msgbuf); @@ -194,7 +203,7 @@ void tp_release_sem(void) } - snprintf (msgbuf, 99, "tp_get_sem: process %d releases transaction processing semaphore", pid); + snprintf (msgbuf, sizeof (msgbuf) - 1, "tp_get_sem: process %d releases transaction processing semaphore", pid); m_log (1, msgbuf); @@ -207,7 +216,7 @@ void tp_release_sem(void) fprintf (stderr, "tp_release_sem: daemon process decrements critical section counter\r\n"); } - snprintf (msgbuf, 99, "tp_get_sem: process %d decrements transaction processing semaphore counter", pid); + snprintf (msgbuf, sizeof (msgbuf) - 1, "tp_get_sem: process %d decrements transaction processing semaphore counter", pid); m_log (1, msgbuf); shm_config->hdr->tp_semctr--; @@ -221,7 +230,7 @@ int tp_tstart(char *tp_id, short serial, if (tp_level == TP_MAX_NEST) { char m[256]; - snprintf (m, 256, "Attempt to exceed TP_MAX_NEST. Transaction aborted.\r\n\201"); + snprintf (m, sizeof (m) - 1, "Attempt to exceed TP_MAX_NEST. Transaction aborted.\r\n\201"); write_m (m); return FALSE; @@ -266,7 +275,7 @@ int tp_add_op(short islock, short action if (transactions[tp_level].opcount == TP_MAX_OPS) { char m[256]; - snprintf (m, 256, "Attempt to exceed TP_MAX_OPS at transaction level %d. Rolling back.\r\n\201", tp_level); + 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); free (gr); @@ -311,8 +320,8 @@ int tp_add_op(short islock, short action transactions[tp_level].ops[oc].is_lock = islock; transactions[tp_level].ops[oc].action = action; - stcpy (&transactions[tp_level].ops[oc].key, key); - stcpy (&transactions[tp_level].ops[oc].data, data); + stcpy ((char *) &transactions[tp_level].ops[oc].key, key); + stcpy ((char *) &transactions[tp_level].ops[oc].data, data); return TRUE; @@ -384,7 +393,6 @@ int tp_trollback(int levels) register int i; register int j; -// for (i = 0; i < levels; i++) { for (i = tp_level; i >= (((tp_level - levels) >= 0) ? tp_level - levels : 0); i--) { for (j = 1; j <= transactions[i].opcount; j++) { @@ -495,7 +503,7 @@ void tp_get_op_name(char *buf, const sho strcpy (buf, "GET"); break; - case dat: + case fra_dat: strcpy (buf, "$DATA"); break;