--- freem/src/fmadm.c 2025/04/02 03:02:42 1.24
+++ freem/src/fmadm.c 2025/05/13 20:03:53 1.42
@@ -1,5 +1,5 @@
/*
- * $Id: fmadm.c,v 1.24 2025/04/02 03:02:42 snw Exp $
+ * $Id: fmadm.c,v 1.42 2025/05/13 20:03:53 snw Exp $
* FreeM Administration Tool
*
*
@@ -24,6 +24,60 @@
* along with FreeM. If not, see .
*
* $Log: fmadm.c,v $
+ * Revision 1.42 2025/05/13 20:03:53 snw
+ * Error-check fopen in fm_daemonctl
+ *
+ * Revision 1.41 2025/04/25 20:08:19 snw
+ * Work on improving routine importer
+ *
+ * Revision 1.40 2025/04/15 18:19:40 snw
+ * Further attempts to fix FreeBSD
+ *
+ * Revision 1.39 2025/04/15 16:49:36 snw
+ * Make use of logprintf throughout codebase
+ *
+ * Revision 1.38 2025/04/15 02:24:43 snw
+ * Improve FreeM logging capabilities
+ *
+ * Revision 1.37 2025/04/14 19:20:20 snw
+ * Create LOCALSTATEDIR during fmadm configure if needed
+ *
+ * Revision 1.36 2025/04/13 15:12:21 snw
+ * Fix transaction checkpoints on OS/2 [CLOSES #34]
+ *
+ * Revision 1.35 2025/04/13 04:22:43 snw
+ * Fix snprintf calls
+ *
+ * Revision 1.34 2025/04/10 15:31:25 snw
+ * Attempt to fix DosCopy calls for OS/2
+ *
+ * Revision 1.33 2025/04/10 01:24:38 snw
+ * Remove C++ style comments
+ *
+ * Revision 1.32 2025/04/09 19:52:02 snw
+ * Eliminate as many warnings as possible while building with -Wall
+ *
+ * Revision 1.31 2025/04/04 19:43:18 snw
+ * Switch to using environment catalog to determine user and group for environment, and remove -u and -g flags from freem
+ *
+ * Revision 1.30 2025/04/03 20:48:14 snw
+ * Improve daemon error diagnostics and bump to 0.63.0-rc3
+ *
+ * Revision 1.29 2025/04/03 01:41:02 snw
+ * New features frozen; prepare 0.63.0-rc1
+ *
+ * Revision 1.28 2025/04/02 19:59:38 snw
+ * Automatically modify env.conf from fmadm reconfigure
+ *
+ * Revision 1.27 2025/04/02 15:36:25 snw
+ * Do extensive result checking for environment stop/start/restart in fmadm
+ *
+ * Revision 1.26 2025/04/02 14:37:57 snw
+ * Improve environment control parts of fmadm
+ *
+ * Revision 1.25 2025/04/02 04:50:49 snw
+ * Allow vendor routines to be upgraded
+ *
* Revision 1.24 2025/04/02 03:02:42 snw
* Stop requiring users to pass -e to fmadm when -u or -g are passed
*
@@ -95,14 +149,14 @@
#include
#include
#include
+#if defined(__OS2__)
+# include
+#endif
#include "config.h"
#include "transact.h"
#include "namespace.h"
#include "fs.h"
-
-#if defined(__OS2__)
-# include
-#endif
+#include "log.h"
#ifdef HAVE_LIBREADLINE
# if defined(HAVE_READLINE_READLINE_H)
@@ -162,6 +216,8 @@ extern char config_file[4096];
extern char env_config_file[4096];
extern char env_user[255];
extern char env_group[255];
+extern char env_enabled[10];
+extern char shm_env[255];
int fm_shell(void);
void fm_checkperms(void);
@@ -171,6 +227,7 @@ int fm_daemonctl (short action, short ob
void fm_write (FILE *file, char *buf);
int fma_jobs_remove (int optc, char **opts);
void set_permissions(char *path, char *user, char *grp, int mode);
+int fm_environment_running (char *env);
extern int read_profile_string(char *file, char *section, char *key, char *value);
int main (int argc, char **argv)
@@ -191,6 +248,7 @@ int main (int argc, char **argv)
short got_action = FALSE;
short got_object = FALSE;
+ strcpy (env_enabled, "true");
/* snprintf (config_file, 4096, "%s/freem.conf", SYSCONFDIR); */
@@ -277,6 +335,31 @@ int main (int argc, char **argv)
base_arg++;
break;
+
+ case 'E':
+ if (argv[i][2] != '=') {
+ fprintf (stderr, "fmadm: missing equals sign in flag -%c\n", argv[i][1]);
+ fmadm_usage ();
+ exit (1);
+ }
+
+ k = 0;
+
+ for (j = 3; j < strlen (argv[i]); j++) {
+ env_enabled[k++] = argv[i][j];
+ }
+ env_enabled[k] = '\0';
+
+ if ((strcmp (env_enabled, "true") != 0) && (strcmp (env_enabled, "false") != 0)) {
+ fprintf (stderr, "fmadm: -E (environment enabled) option must be either 'true' or 'false'\n");
+ fmadm_usage ();
+ exit (1);
+ }
+
+ base_arg++;
+
+ break;
+
case 'n':
if (argv[i][2] != '=') {
@@ -302,26 +385,28 @@ int main (int argc, char **argv)
if (obj != OBJ_DAEMON) {
if (strlen (env_user) == 0) {
- snprintf (env_user, 6, "freem");
+ snprintf (env_user, sizeof (env_user) - 1, "freem");
}
if (strlen (env_group) == 0) {
- snprintf (env_group, 6, "freem");
+ snprintf (env_group, sizeof (env_group) - 1, "freem");
}
- if (!fma_explicit_environment) snprintf (fma_environment, 4096, "DEFAULT");
- if (!fma_explicit_namespace) snprintf (fma_namespace, 4096, "SYSTEM");
+ if (!fma_explicit_environment) snprintf (fma_environment, sizeof (fma_environment) - 1, "DEFAULT");
+ if (!fma_explicit_namespace) snprintf (fma_namespace, sizeof (fma_namespace) - 1, "SYSTEM");
- snprintf (config_file, 4096, "%s/freem/%s/freem.conf", SYSCONFDIR, fma_environment);
+ snprintf (config_file, sizeof (config_file) - 1, "%s/freem/%s/freem.conf", SYSCONFDIR, fma_environment);
}
- snprintf (env_config_file, 4096, "%s/freem/env.conf", SYSCONFDIR);
+ snprintf (env_config_file, sizeof (env_config_file) - 1, "%s/freem/env.conf", SYSCONFDIR);
- /*
- printf ("action = '%s' object = '%s' environment = '%s' namespace = '%s' config_file = '%s' base_arg = '%d' next argument = '%s'\n", action, obj_str, fma_environment, fma_namespace, config_file, base_arg, argv[base_arg]);
- exit(1);
- */
+
+ //printf ("action = '%s' object = '%s' environment = '%s' namespace = '%s' config_file = '%s' base_arg = '%d' next argument = '%s'\n", action, obj_str, fma_environment, fma_namespace, config_file, base_arg, argv[base_arg]);
+ //exit(1);
+
+ strncpy (shm_env, fma_environment, sizeof (shm_env) - 1);
+ init_log ();
/* override for fmadm configure and daemon stuff */
if (got_action) {
@@ -336,22 +421,22 @@ int main (int argc, char **argv)
else if (strcmp (argv[1], "start") == 0 && strcmp (argv[2], "environment") == 0) {
act = ACT_START;
obj = OBJ_DAEMON;
- goto act_switch;
+ goto process_args;
}
else if (strcmp (argv[1], "stop") == 0 && strcmp (argv[2], "environment") == 0) {
act = ACT_STOP;
obj = OBJ_DAEMON;
- goto act_switch;
+ goto process_args;
}
else if (strcmp (argv[1], "restart") == 0 && strcmp (argv[2], "environment") == 0) {
act = ACT_RESTART;
obj = OBJ_DAEMON;
- goto act_switch;
+ goto process_args;
}
else if (strcmp (argv[1], "status") == 0 && strcmp (argv[2], "environment") == 0) {
act = ACT_STATUS;
obj = OBJ_DAEMON;
- goto act_switch;
+ goto process_args;
}
}
@@ -374,7 +459,8 @@ int main (int argc, char **argv)
}
set_namespace (fma_namespace, FALSE);
-
+
+process_args:
/* allocate opts array */
/* first dimension */
@@ -397,7 +483,8 @@ int main (int argc, char **argv)
j = 1;
for (i = base_arg; i < argc; i++) {
- if (i > FMA_MAXARGS) return fmadm_usage(); /* bail if we're going to overrun the array */
+ if (i > FMA_MAXARGS) return fmadm_usage();
+ /* bail if we're going to overrun the array */
strncpy (opts[j++], argv[i], STRLEN - 1);
}
@@ -417,6 +504,7 @@ int main (int argc, char **argv)
else if (strncmp (action, "start", STRLEN - 1) == 0) act = ACT_START;
else if (strncmp (action, "stop", STRLEN - 1) == 0) act = ACT_STOP;
else if (strncmp (action, "restart", STRLEN - 1) == 0) act = ACT_RESTART;
+ else if (strncmp (action, "status", STRLEN - 1) == 0) act = ACT_STATUS;
else return fmadm_usage();
if (strncmp (obj_str, "lock", STRLEN - 1) == 0) obj = OBJ_LOCK;
@@ -498,6 +586,7 @@ act_switch:
case ACT_IMPORT:
+ //printf ("opts[0] = %s\n", opts[0]);
fmadm_exit (fm_import (obj, optc, opts));
@@ -551,10 +640,7 @@ int fm_shell (void)
char *cmdt = (char *) malloc (65535 * sizeof (char));
char *result = (char *) malloc (65535 * sizeof (char));
- /*
- strcpy (fma_namespace, "SYSTEM");
- set_namespace (fma_namespace, FALSE);
- */
+ obj = 0;
snprintf (fma_prompt, STRLEN - 1, "fmadm [%s]> ", fma_namespace);
@@ -659,7 +745,6 @@ int fm_shell (void)
i = 0;
while ((result = strtok (NULL, " ")) != NULL) {
- // printf ("%d = %s\n", i, result);
strcpy (args[i++], result);
}
@@ -869,15 +954,14 @@ void fmadm_exit (int retval)
int fmadm_usage (void)
{
- fprintf (stdout, "\nusage: fmadm