--- freem/src/fmadm.c 2025/04/01 23:21:45 1.22 +++ freem/src/fmadm.c 2025/04/02 02:16:27 1.23 @@ -1,5 +1,5 @@ /* - * $Id: fmadm.c,v 1.22 2025/04/01 23:21:45 snw Exp $ + * $Id: fmadm.c,v 1.23 2025/04/02 02:16:27 snw Exp $ * FreeM Administration Tool * * @@ -24,6 +24,9 @@ * along with FreeM. If not, see . * * $Log: fmadm.c,v $ + * Revision 1.23 2025/04/02 02:16:27 snw + * Add fmadm status environment command and move journals to a better location + * * Revision 1.22 2025/04/01 23:21:45 snw * fmadm commands for stopping, starting, and restarting environments now functional * @@ -343,7 +346,13 @@ int main (int argc, char **argv) act = ACT_RESTART; obj = OBJ_DAEMON; goto act_switch; + } + else if (strcmp (argv[1], "status") == 0 && strcmp (argv[2], "environment") == 0) { + act = ACT_STATUS; + obj = OBJ_DAEMON; + goto act_switch; } + } pid = getpid (); @@ -514,6 +523,7 @@ act_switch: case ACT_START: case ACT_STOP: case ACT_RESTART: + case ACT_STATUS: fmadm_exit (fm_daemonctl (act, obj, optc, opts)); default: @@ -1141,7 +1151,7 @@ int fm_daemonctl (short action, short ob char tmps[255]; char *cur_env; char cmd[4096]; - char verb[20]; + char verb[40]; char e_user[255]; char e_grp[255]; char e_ena[10]; @@ -1166,11 +1176,17 @@ int fm_daemonctl (short action, short ob case ACT_RESTART: sprintf (verb, "restarting"); break; + case ACT_STATUS: + sprintf (verb, "checking status of"); + break; } if (optc) { /* environment list specified as command-line argument */ - envlist = options[0]; + envlist = (char *) malloc (sizeof (char) * BIGSTR); + NULLPTRCHK(envlist,"fm_daemonctl"); + + strcpy (envlist, options[0]); } else { /* no environment specified; do 'action' for all environments */ @@ -1252,6 +1268,14 @@ int fm_daemonctl (short action, short ob break; + case ACT_STATUS: + epid = fm_get_pid (cur_env); + if (epid > -1) { + fprintf (stderr, " - %s environment daemon running as pid %d\n", cur_env, epid); + } + else { + fprintf (stderr, " - %s environment daemon does not appear to be running\n", cur_env); + } } } else { @@ -1316,6 +1340,7 @@ void fm_configure (void) char locktab[4096]; char zalloctab[4096]; + char jnldir[4096]; char jnlfile[4096]; char jnlmode[4]; char jnlhostid[4096]; @@ -1359,8 +1384,7 @@ void fm_configure (void) } d_uid = d_user->pw_uid; #endif - - + snprintf (varbase, 4095, "%s/freem", LOCALSTATEDIR); snprintf (rundir, 4095, "%s/freem/run", LOCALSTATEDIR); snprintf (sysrtn, 4095, "%s/freem/%s/SYSTEM/routines", LOCALSTATEDIR, fma_environment); @@ -1369,7 +1393,8 @@ void fm_configure (void) snprintf (usrgbl, 4095, "%s/freem/%s/USER/globals", LOCALSTATEDIR, fma_environment); snprintf (locktab, 4095, "/tmp/locktab"); snprintf (zalloctab, 4095, "/tmp/zalloctab"); - snprintf (jnlfile, 4095, "/tmp/freem_journal_%s.dat", fma_environment); + snprintf (jnldir, 4095, "%s/freem/%s/journals", LOCALSTATEDIR, fma_environment); + snprintf (jnlfile, 4095, "%s/freem_journal_%s.dat", jnldir, fma_environment); snprintf (jnlmode, 3, "on"); snprintf (jnlhostid, 4095, "DEFAULT"); snprintf (jnlcut, 4095, "4294967000"); @@ -1424,41 +1449,48 @@ void fm_configure (void) /* check for existence of needed directories */ if (stat (SYSCONFDIR, &etcstat) == -1) { - fprintf (stderr, "fmadm: creating %s\n", SYSCONFDIR); + fprintf (stderr, "fmadm: creating %s [SYSCONFDIR]\n", SYSCONFDIR); mkdir (SYSCONFDIR, 0775); set_permissions (SYSCONFDIR, username, groupname, 0775); } if (stat (confbase, &etcstat) == -1) { - fprintf (stderr, "fmadm: creating %s\n", confbase); + fprintf (stderr, "fmadm: creating %s [confbase]\n", confbase); mkdir (confbase, 0775); set_permissions (confbase, username, groupname, 0775); } - if (stat (envbase, &etcstat) == -1) { - fprintf (stderr, "fmadm: creating %s\n", envbase); - mkdir (envbase, 0775); - set_permissions (envbase, username, groupname, 0775); - } - if (stat (varbase, &etcstat) == -1) { - fprintf (stderr, "fmadm: creating %s\n", varbase); + fprintf (stderr, "fmadm: creating %s [varbase]\n", varbase); mkdir (varbase, 0775); set_permissions (varbase, username, groupname, 0775); } + if (stat (envbase, &etcstat) == -1) { + fprintf (stderr, "fmadm: creating %s [envbase]\n", envbase); + mkdir (envbase, 0775); + set_permissions (envbase, username, groupname, 0775); + } + if (stat (rundir, &etcstat) == -1) { - fprintf (stderr, "fmadm: creating %s\n", rundir); + fprintf (stderr, "fmadm: creating %s [rundir]\n", rundir); mkdir (rundir, 0777); chmod (rundir, 0777); } if (stat (nsbase, &etcstat) == -1) { - fprintf (stderr, "fmadm: creating %s\n", nsbase); + fprintf (stderr, "fmadm: creating %s [nsbase]\n", nsbase); mkdir (nsbase, 0775); set_permissions (nsbase, username, groupname, 0775); } + if (stat (jnldir, &etcstat) == -1) { + fprintf (stderr, "fmadm: creating %s [jnldir]\n", jnldir); + mkdir (jnldir, 0775); + set_permissions (jnldir, username, groupname, 0775); + } + + snprintf (src_dir, 4095, "%s/freem/mlib", DATADIR); snprintf (dest_dir, 4095, "%s/freem/%s/SYSTEM/routines", LOCALSTATEDIR, fma_environment);