version 1.21, 2025/04/01 20:11:46
|
version 1.24, 2025/04/02 03:02:42
|
Line 24
|
Line 24
|
* along with FreeM. If not, see <https://www.gnu.org/licenses/>. |
* along with FreeM. If not, see <https://www.gnu.org/licenses/>. |
* |
* |
* $Log$ |
* $Log$ |
|
* Revision 1.24 2025/04/02 03:02:42 snw |
|
* Stop requiring users to pass -e to fmadm when -u or -g are passed |
|
* |
|
* 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 |
|
* |
* Revision 1.21 2025/04/01 20:11:46 snw |
* Revision 1.21 2025/04/01 20:11:46 snw |
* Further work on fmadm |
* Further work on fmadm |
* |
* |
Line 224 int main (int argc, char **argv)
|
Line 233 int main (int argc, char **argv)
|
env_user[k++] = argv[i][j]; |
env_user[k++] = argv[i][j]; |
} |
} |
|
|
fma_explicit_environment = TRUE; |
|
base_arg++; |
base_arg++; |
|
|
break; |
break; |
Line 242 int main (int argc, char **argv)
|
Line 250 int main (int argc, char **argv)
|
env_group[k++] = argv[i][j]; |
env_group[k++] = argv[i][j]; |
} |
} |
|
|
fma_explicit_environment = TRUE; |
|
base_arg++; |
base_arg++; |
|
|
break; |
break; |
Line 292 int main (int argc, char **argv)
|
Line 299 int main (int argc, char **argv)
|
} |
} |
} |
} |
} |
} |
|
|
if (obj != OBJ_DAEMON) { |
if (obj != OBJ_DAEMON) { |
if (strlen (env_user) == 0) { |
if (strlen (env_user) == 0) { |
snprintf (env_user, 6, "freem"); |
snprintf (env_user, 6, "freem"); |
Line 340 int main (int argc, char **argv)
|
Line 347 int main (int argc, char **argv)
|
act = ACT_RESTART; |
act = ACT_RESTART; |
obj = OBJ_DAEMON; |
obj = OBJ_DAEMON; |
goto act_switch; |
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 (); |
pid = getpid (); |
Line 407 int main (int argc, char **argv)
|
Line 420 int main (int argc, char **argv)
|
else return fmadm_usage(); |
else return fmadm_usage(); |
|
|
if (strncmp (obj_str, "lock", STRLEN - 1) == 0) obj = OBJ_LOCK; |
if (strncmp (obj_str, "lock", STRLEN - 1) == 0) obj = OBJ_LOCK; |
else if (strncmp (obj_str, "zallocate", STRLEN - 1) == 0) obj = OBJ_ZALLOC; |
|
else if (strncmp (obj_str, "journal", STRLEN - 1) == 0) obj = OBJ_JOURNAL; |
else if (strncmp (obj_str, "journal", STRLEN - 1) == 0) obj = OBJ_JOURNAL; |
else if (strncmp (obj_str, "namespace", STRLEN - 1) == 0) obj = OBJ_NAMESPACE; |
else if (strncmp (obj_str, "namespace", STRLEN - 1) == 0) obj = OBJ_NAMESPACE; |
else if (strncmp (obj_str, "global", STRLEN - 1) == 0) obj = OBJ_GLOBAL; |
else if (strncmp (obj_str, "global", STRLEN - 1) == 0) obj = OBJ_GLOBAL; |
Line 511 act_switch:
|
Line 523 act_switch:
|
case ACT_START: |
case ACT_START: |
case ACT_STOP: |
case ACT_STOP: |
case ACT_RESTART: |
case ACT_RESTART: |
|
case ACT_STATUS: |
fmadm_exit (fm_daemonctl (act, obj, optc, opts)); |
fmadm_exit (fm_daemonctl (act, obj, optc, opts)); |
|
|
default: |
default: |
Line 664 int fm_shell (void)
|
Line 677 int fm_shell (void)
|
strcpy (obj_str, args[0]); |
strcpy (obj_str, args[0]); |
|
|
if (strncmp (obj_str, "lock", STRLEN - 1) == 0) obj = OBJ_LOCK; |
if (strncmp (obj_str, "lock", STRLEN - 1) == 0) obj = OBJ_LOCK; |
else if (strncmp (obj_str, "zallocate", STRLEN - 1) == 0) obj = OBJ_ZALLOC; |
|
else if (strncmp (obj_str, "journal", STRLEN - 1) == 0) obj = OBJ_JOURNAL; |
else if (strncmp (obj_str, "journal", STRLEN - 1) == 0) obj = OBJ_JOURNAL; |
else if (strncmp (obj_str, "namespace", STRLEN - 1) == 0) obj = OBJ_NAMESPACE; |
else if (strncmp (obj_str, "namespace", STRLEN - 1) == 0) obj = OBJ_NAMESPACE; |
else if (strncmp (obj_str, "global", STRLEN - 1) == 0) obj = OBJ_GLOBAL; |
else if (strncmp (obj_str, "global", STRLEN - 1) == 0) obj = OBJ_GLOBAL; |
Line 868 int fmadm_usage (void)
|
Line 880 int fmadm_usage (void)
|
fprintf (stdout, " stop, restart\n\n"); |
fprintf (stdout, " stop, restart\n\n"); |
|
|
fprintf (stdout, " <object> can be one of:\n"); |
fprintf (stdout, " <object> can be one of:\n"); |
fprintf (stdout, " lock, zallocate, journal, namespace, global, routine, job,\n"); |
fprintf (stdout, " lock, journal, namespace, global, routine, job,\n"); |
fprintf (stdout, " environment\n\n"); |
fprintf (stdout, " environment\n\n"); |
|
|
fprintf (stdout, " Not all actions are valid for all objects. Please see the FreeM manual\n"); |
fprintf (stdout, " Not all actions are valid for all objects. Please see the FreeM manual\n"); |
Line 1104 int fm_edit (short object, int optc, cha
|
Line 1116 int fm_edit (short object, int optc, cha
|
|
|
} /* fm_edit() */ |
} /* fm_edit() */ |
|
|
|
long fm_get_pid (char *env) |
|
{ |
|
char pid_file[4096]; |
|
char tmp_pid[255]; |
|
long res; |
|
|
|
FILE *fp; |
|
|
|
snprintf (pid_file, 4095, "%s/freem/run/%s.pid", LOCALSTATEDIR, env); |
|
|
|
if ((fp = fopen (pid_file, "r")) != NULL) { |
|
if (fgets (tmp_pid, 255, fp)) { |
|
fclose (fp); |
|
return atol (tmp_pid); |
|
} |
|
else { |
|
fclose (fp); |
|
return -1; |
|
} |
|
} |
|
else { |
|
return -1; |
|
} |
|
} |
|
|
int fm_daemonctl (short action, short object, int optc, char **options) |
int fm_daemonctl (short action, short object, int optc, char **options) |
{ |
{ |
FILE *ef; |
FILE *ef; |
Line 1113 int fm_daemonctl (short action, short ob
|
Line 1150 int fm_daemonctl (short action, short ob
|
char tmps[255]; |
char tmps[255]; |
char *cur_env; |
char *cur_env; |
char cmd[4096]; |
char cmd[4096]; |
char verb[20]; |
char verb[40]; |
char e_user[255]; |
char e_user[255]; |
char e_grp[255]; |
char e_grp[255]; |
char e_ena[10]; |
char e_ena[10]; |
char basecmd[255]; |
char basecmd[255]; |
char *savptr; |
char *savptr; |
int result; |
int result; |
|
long epid; |
|
|
#if !defined(__OS2__) |
#if !defined(__OS2__) |
snprintf (basecmd, 254, "%s/bin/freem", PREFIX); |
snprintf (basecmd, 254, "%s/bin/freem", PREFIX); |
Line 1137 int fm_daemonctl (short action, short ob
|
Line 1175 int fm_daemonctl (short action, short ob
|
case ACT_RESTART: |
case ACT_RESTART: |
sprintf (verb, "restarting"); |
sprintf (verb, "restarting"); |
break; |
break; |
|
case ACT_STATUS: |
|
sprintf (verb, "checking status of"); |
|
break; |
} |
} |
|
|
if (optc) { |
if (optc) { |
/* environment list specified as command-line argument */ |
/* 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 { |
else { |
/* no environment specified; do 'action' for all environments */ |
/* no environment specified; do 'action' for all environments */ |
Line 1177 int fm_daemonctl (short action, short ob
|
Line 1221 int fm_daemonctl (short action, short ob
|
if (result == FALSE) { |
if (result == FALSE) { |
strcpy (e_grp, "freem"); |
strcpy (e_grp, "freem"); |
} |
} |
|
|
printf ("fmadm: %s environment %s\n", verb, cur_env); |
printf ("fmadm: %s environment %s\n", verb, cur_env); |
|
|
switch (action) { |
switch (action) { |
Line 1186 int fm_daemonctl (short action, short ob
|
Line 1230 int fm_daemonctl (short action, short ob
|
snprintf (cmd, 4095, "%s -d -e %s -u %s -g %s", basecmd, cur_env, e_user, e_grp); |
snprintf (cmd, 4095, "%s -d -e %s -u %s -g %s", basecmd, cur_env, e_user, e_grp); |
#else |
#else |
sprintf (cmd, 4095, "%s -d -k -e %s -u %s -g %s", basecmd, cur_env, e_user, e_grp); |
sprintf (cmd, 4095, "%s -d -k -e %s -u %s -g %s", basecmd, cur_env, e_user, e_grp); |
#endif |
#endif |
|
system (cmd); |
break; |
break; |
case ACT_STOP: |
case ACT_STOP: |
case ACT_RESTART: |
epid = fm_get_pid (cur_env); |
printf ("fmadm: stop and restart not yet implemented\n"); |
if (epid > -1) { |
|
fprintf (stderr, "fmadm: stopping environment daemon pid %d\n", epid); |
|
kill (epid, SIGINT); |
|
kill (epid, SIGTERM); |
|
} |
|
else { |
|
fprintf (stderr, "fmadm: could not obtain environment daemon pid\n"); |
|
} |
|
|
break; |
break; |
} |
case ACT_RESTART: |
|
epid = fm_get_pid (cur_env); |
|
if (epid > -1) { |
|
fprintf (stderr, "fmadm: stopping environment daemon pid %d\n", epid); |
|
kill (epid, SIGINT); |
|
kill (epid, SIGTERM); |
|
} |
|
else { |
|
fprintf (stderr, "fmadm: could not obtain environment daemon pid\n"); |
|
} |
|
fprintf (stderr, "fmadm: waiting 2 seconds\n"); |
|
sleep (2); |
|
fprintf (stderr, "fmadm: starting environment %s\n", cur_env); |
|
#if !defined(__OS2__) |
|
snprintf (cmd, 4095, "%s -d -e %s -u %s -g %s", basecmd, cur_env, e_user, e_grp); |
|
#else |
|
sprintf (cmd, 4095, "%s -d -k -e %s -u %s -g %s", basecmd, cur_env, e_user, e_grp); |
|
#endif |
|
system (cmd); |
|
|
|
|
system (cmd); |
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 { |
else { |
printf ("fmadm: %s environment is disabled; skipping\n", cur_env); |
printf ("fmadm: %s environment is disabled; skipping\n", cur_env); |
Line 1256 void fm_configure (void)
|
Line 1337 void fm_configure (void)
|
char usrrtn[4096]; |
char usrrtn[4096]; |
char usrgbl[4096]; |
char usrgbl[4096]; |
|
|
char locktab[4096]; |
char jnldir[4096]; |
char zalloctab[4096]; |
|
char jnlfile[4096]; |
char jnlfile[4096]; |
char jnlmode[4]; |
char jnlmode[4]; |
char jnlhostid[4096]; |
char jnlhostid[4096]; |
Line 1284 void fm_configure (void)
|
Line 1364 void fm_configure (void)
|
char *groupname = env_group; |
char *groupname = env_group; |
|
|
#if !defined(__OS2__) |
#if !defined(__OS2__) |
|
if (geteuid () != 0) { |
|
fprintf (stderr, "fmadm: not superuser\n"); |
|
exit (1); |
|
} |
|
|
struct group *d_grp; |
struct group *d_grp; |
struct passwd *d_user; |
struct passwd *d_user; |
gid_t d_gid; |
gid_t d_gid; |
Line 1301 void fm_configure (void)
|
Line 1386 void fm_configure (void)
|
} |
} |
d_uid = d_user->pw_uid; |
d_uid = d_user->pw_uid; |
#endif |
#endif |
|
|
|
|
snprintf (varbase, 4095, "%s/freem", LOCALSTATEDIR); |
snprintf (varbase, 4095, "%s/freem", LOCALSTATEDIR); |
snprintf (rundir, 4095, "%s/freem/run", LOCALSTATEDIR); |
snprintf (rundir, 4095, "%s/freem/run", LOCALSTATEDIR); |
snprintf (sysrtn, 4095, "%s/freem/%s/SYSTEM/routines", LOCALSTATEDIR, fma_environment); |
snprintf (sysrtn, 4095, "%s/freem/%s/SYSTEM/routines", LOCALSTATEDIR, fma_environment); |
snprintf (sysgbl, 4095, "%s/freem/%s/SYSTEM/globals", LOCALSTATEDIR, fma_environment); |
snprintf (sysgbl, 4095, "%s/freem/%s/SYSTEM/globals", LOCALSTATEDIR, fma_environment); |
snprintf (usrrtn, 4095, "%s/freem/%s/USER/routines", LOCALSTATEDIR, fma_environment); |
snprintf (usrrtn, 4095, "%s/freem/%s/USER/routines", LOCALSTATEDIR, fma_environment); |
snprintf (usrgbl, 4095, "%s/freem/%s/USER/globals", LOCALSTATEDIR, fma_environment); |
snprintf (usrgbl, 4095, "%s/freem/%s/USER/globals", LOCALSTATEDIR, fma_environment); |
snprintf (locktab, 4095, "/tmp/locktab"); |
snprintf (jnldir, 4095, "%s/freem/%s/journals", LOCALSTATEDIR, fma_environment); |
snprintf (zalloctab, 4095, "/tmp/zalloctab"); |
snprintf (jnlfile, 4095, "%s/freem_journal_%s.dat", jnldir, fma_environment); |
snprintf (jnlfile, 4095, "/tmp/freem_journal_%s.dat", fma_environment); |
|
snprintf (jnlmode, 3, "on"); |
snprintf (jnlmode, 3, "on"); |
snprintf (jnlhostid, 4095, "DEFAULT"); |
snprintf (jnlhostid, 4095, "DEFAULT"); |
snprintf (jnlcut, 4095, "4294967000"); |
snprintf (jnlcut, 4095, "4294967000"); |
Line 1366 void fm_configure (void)
|
Line 1449 void fm_configure (void)
|
|
|
/* check for existence of needed directories */ |
/* check for existence of needed directories */ |
if (stat (SYSCONFDIR, &etcstat) == -1) { |
if (stat (SYSCONFDIR, &etcstat) == -1) { |
fprintf (stderr, "fmadm: creating %s\n", SYSCONFDIR); |
fprintf (stderr, "fmadm: creating %s [SYSCONFDIR]\n", SYSCONFDIR); |
mkdir (SYSCONFDIR, 0775); |
mkdir (SYSCONFDIR, 0775); |
set_permissions (SYSCONFDIR, username, groupname, 0775); |
set_permissions (SYSCONFDIR, username, groupname, 0775); |
} |
} |
|
|
if (stat (confbase, &etcstat) == -1) { |
if (stat (confbase, &etcstat) == -1) { |
fprintf (stderr, "fmadm: creating %s\n", confbase); |
fprintf (stderr, "fmadm: creating %s [confbase]\n", confbase); |
mkdir (confbase, 0775); |
mkdir (confbase, 0775); |
set_permissions (confbase, username, groupname, 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) { |
if (stat (varbase, &etcstat) == -1) { |
fprintf (stderr, "fmadm: creating %s\n", varbase); |
fprintf (stderr, "fmadm: creating %s [varbase]\n", varbase); |
mkdir (varbase, 0775); |
mkdir (varbase, 0775); |
set_permissions (varbase, username, groupname, 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) { |
if (stat (rundir, &etcstat) == -1) { |
fprintf (stderr, "fmadm: creating %s\n", rundir); |
fprintf (stderr, "fmadm: creating %s [rundir]\n", rundir); |
mkdir (rundir, 0777); |
mkdir (rundir, 0777); |
chmod (rundir, 0777); |
chmod (rundir, 0777); |
} |
} |
|
|
if (stat (nsbase, &etcstat) == -1) { |
if (stat (nsbase, &etcstat) == -1) { |
fprintf (stderr, "fmadm: creating %s\n", nsbase); |
fprintf (stderr, "fmadm: creating %s [nsbase]\n", nsbase); |
mkdir (nsbase, 0775); |
mkdir (nsbase, 0775); |
set_permissions (nsbase, username, groupname, 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 (src_dir, 4095, "%s/freem/mlib", DATADIR); |
snprintf (dest_dir, 4095, "%s/freem/%s/SYSTEM/routines", LOCALSTATEDIR, fma_environment); |
snprintf (dest_dir, 4095, "%s/freem/%s/SYSTEM/routines", LOCALSTATEDIR, fma_environment); |
|
|