|
|
| version 1.16, 2025/03/24 20:59:58 | version 1.33, 2025/04/10 01:24:38 |
|---|---|
| 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.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 | |
| * | |
| * 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 | |
| * Further work on fmadm | |
| * | |
| * Revision 1.20 2025/04/01 16:37:12 snw | |
| * Configure DEFAULT environment the same as others, and set permissions/ownership directly in fmadm configure. Add env.conf file as a centralized configuration listing all environments. | |
| * | |
| * Revision 1.19 2025/04/01 14:32:11 snw | |
| * Begin work on environment and namespace reorg | |
| * | |
| * Revision 1.18 2025/03/31 16:33:56 snw | |
| * Work on fmadm edit global | |
| * | |
| * Revision 1.17 2025/03/30 01:36:58 snw | |
| * Make it easier to bring back fma_gedit, fix double-free in global handler, limit $CHAR to 7-bit ASCII | |
| * | |
| * Revision 1.16 2025/03/24 20:59:58 snw | * Revision 1.16 2025/03/24 20:59:58 snw |
| * Try using DosCopy API instead of built-in cp function on OS/2 | * Try using DosCopy API instead of built-in cp function on OS/2 |
| * | * |
| Line 61 | Line 112 |
| #include <sys/types.h> | #include <sys/types.h> |
| #include <sys/stat.h> | #include <sys/stat.h> |
| #include <pwd.h> | |
| #include <grp.h> | |
| #include <stddef.h> | #include <stddef.h> |
| #include <stdio.h> | #include <stdio.h> |
| #include <string.h> | #include <string.h> |
| Line 133 short fma_explicit_environment = FALSE; | Line 186 short fma_explicit_environment = FALSE; |
| char obj_str[STRLEN]; | char obj_str[STRLEN]; |
| extern char config_file[4096]; | 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]; | |
| int fm_shell(void); | int fm_shell(void); |
| void fm_checkperms(void); | void fm_checkperms(void); |
| void fm_reconfigure(void); | void fm_reconfigure(void); |
| void fm_configure(void); | void fm_configure(void); |
| int fm_daemonctl (short action, short object, int optc, char **options); | |
| void fm_write (FILE *file, char *buf); | void fm_write (FILE *file, char *buf); |
| int fma_jobs_remove (int optc, char **opts); | 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) | int main (int argc, char **argv) |
| { | { |
| Line 159 int main (int argc, char **argv) | Line 220 int main (int argc, char **argv) |
| short got_action = FALSE; | short got_action = FALSE; |
| short got_object = FALSE; | short got_object = FALSE; |
| strcpy (env_enabled, "true"); | |
| /* snprintf (config_file, 4096, "%s/freem.conf", SYSCONFDIR); */ | /* snprintf (config_file, 4096, "%s/freem.conf", SYSCONFDIR); */ |
| Line 187 int main (int argc, char **argv) | Line 249 int main (int argc, char **argv) |
| if (argv[i][0] == '-') { | if (argv[i][0] == '-') { |
| switch (argv[i][1]) { | switch (argv[i][1]) { |
| case 'u': | |
| 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_user[k++] = argv[i][j]; | |
| } | |
| base_arg++; | |
| break; | |
| case 'g': | |
| 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_group[k++] = argv[i][j]; | |
| } | |
| base_arg++; | |
| break; | |
| case 'e': | case 'e': |
| if (argv[i][2] != '=') { | if (argv[i][2] != '=') { |
| Line 200 int main (int argc, char **argv) | Line 297 int main (int argc, char **argv) |
| for (j = 3; j < strlen (argv[i]); j++) { | for (j = 3; j < strlen (argv[i]); j++) { |
| fma_environment[k++] = argv[i][j]; | fma_environment[k++] = argv[i][j]; |
| } | } |
| if (strcmp (fma_environment, "all") == 0 ) { | |
| fprintf (stderr, "fmadm: 'all' is an invalid environment name\n"); | |
| exit (1); | |
| } | |
| fma_explicit_environment = TRUE; | fma_explicit_environment = TRUE; |
| base_arg++; | base_arg++; |
| break; | 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': | case 'n': |
| if (argv[i][2] != '=') { | if (argv[i][2] != '=') { |
| Line 227 int main (int argc, char **argv) | Line 354 int main (int argc, char **argv) |
| } | } |
| } | } |
| } | } |
| if (!fma_explicit_environment) snprintf (fma_environment, 4096, "DEFAULT"); | |
| if (!fma_explicit_namespace) snprintf (fma_namespace, 4096, "SYSTEM"); | |
| snprintf (config_file, 4096, "%s/freem/%s/freem.conf", SYSCONFDIR, fma_environment); | if (obj != OBJ_DAEMON) { |
| if (strlen (env_user) == 0) { | |
| snprintf (env_user, 6, "freem"); | |
| } | |
| if (strlen (env_group) == 0) { | |
| snprintf (env_group, 6, "freem"); | |
| } | |
| /* | |
| if (!fma_explicit_environment) snprintf (fma_environment, 4096, "DEFAULT"); | |
| if (!fma_explicit_namespace) snprintf (fma_namespace, 4096, "SYSTEM"); | |
| snprintf (config_file, 4096, "%s/freem/%s/freem.conf", SYSCONFDIR, fma_environment); | |
| } | |
| snprintf (env_config_file, 4096, "%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]); | 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); | exit(1); |
| */ | */ |
| /* override for fmadm configure */ | /* override for fmadm configure and daemon stuff */ |
| if (got_action) { | if (got_action) { |
| if (strcmp (argv[1], "configure") == 0) { | if (strcmp (argv[1], "configure") == 0) { |
| fm_configure (); | fm_configure (); |
| Line 248 int main (int argc, char **argv) | Line 388 int main (int argc, char **argv) |
| fm_reconfigure (); | fm_reconfigure (); |
| exit (0); | exit (0); |
| } | } |
| else if (strcmp (argv[1], "start") == 0 && strcmp (argv[2], "environment") == 0) { | |
| act = ACT_START; | |
| obj = OBJ_DAEMON; | |
| goto process_args; | |
| } | |
| else if (strcmp (argv[1], "stop") == 0 && strcmp (argv[2], "environment") == 0) { | |
| act = ACT_STOP; | |
| obj = OBJ_DAEMON; | |
| goto process_args; | |
| } | |
| else if (strcmp (argv[1], "restart") == 0 && strcmp (argv[2], "environment") == 0) { | |
| act = ACT_RESTART; | |
| obj = OBJ_DAEMON; | |
| goto process_args; | |
| } | |
| else if (strcmp (argv[1], "status") == 0 && strcmp (argv[2], "environment") == 0) { | |
| act = ACT_STATUS; | |
| obj = OBJ_DAEMON; | |
| goto process_args; | |
| } | |
| } | } |
| pid = getpid (); | pid = getpid (); |
| Line 258 int main (int argc, char **argv) | Line 419 int main (int argc, char **argv) |
| job_init (TRUE); | job_init (TRUE); |
| fm_sig_init (); | fm_sig_init (); |
| /* go to fmadm shell if no arguments passed */ | /* go to fmadm shell if no arguments passed */ |
| if (!got_action && !got_object) return fm_shell (); | if (!got_action && !got_object) return fm_shell (); |
| Line 266 int main (int argc, char **argv) | Line 427 int main (int argc, char **argv) |
| fm_checkperms (); | fm_checkperms (); |
| exit (0); | exit (0); |
| } | } |
| #if 0 | |
| /* how many args do we have? */ | |
| switch (argc) { | |
| case 3: /* action, object */ | |
| strncpy (action, argv[1], STRLEN - 1); | |
| strncpy (obj_str, argv[2], STRLEN - 1); | |
| strncpy (fma_namespace, "SYSTEM", STRLEN - 1); | |
| optc = argc - 2; | |
| fma_explicit_namespace = FALSE; | |
| fma_min_args = 1; | |
| base_arg = 3; | |
| break; | |
| case 4: /* action, object, namespace */ | |
| strncpy (action, argv[1], STRLEN - 1); | |
| strncpy (obj_str, argv[2], STRLEN - 1); | |
| if (validate_namespace (argv[3]) == TRUE) { | |
| strncpy (fma_namespace, argv[3], STRLEN - 1); | |
| fma_min_args = 2; | |
| fma_explicit_namespace = TRUE; | |
| base_arg = 4; | |
| optc = argc - 3; | |
| } | |
| else { | |
| strncpy (fma_namespace, "SYSTEM", 10); | |
| fma_min_args = 1; | |
| fma_explicit_namespace = FALSE; | |
| base_arg = 3; | |
| optc = argc - 2; | |
| } | |
| break; | |
| default: | |
| if (argc < 4) fmadm_usage(); | |
| /* we don't know what any but the first two args actually mean */ | |
| strncpy (action, argv[1], STRLEN - 1); | |
| strncpy (obj_str, argv[2], STRLEN - 1); | |
| if (validate_namespace (argv[3]) == TRUE) { | |
| strncpy (fma_namespace, argv[3], STRLEN - 1); | |
| fma_min_args = 2; | |
| fma_explicit_namespace = TRUE; | |
| base_arg = 4; | |
| optc = argc - 3; | |
| } | |
| else { | |
| strncpy (fma_namespace, "SYSTEM", 10); | |
| fma_min_args = 1; | |
| fma_explicit_namespace = FALSE; | |
| base_arg = 3; | |
| optc = argc - 2; | |
| } | |
| } | |
| #endif | |
| set_namespace (fma_namespace, FALSE); | set_namespace (fma_namespace, FALSE); |
| process_args: | |
| /* allocate opts array */ | /* allocate opts array */ |
| /* first dimension */ | /* first dimension */ |
| Line 356 int main (int argc, char **argv) | Line 453 int main (int argc, char **argv) |
| j = 1; | j = 1; |
| for (i = base_arg; i < argc; i++) { | 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); | strncpy (opts[j++], argv[i], STRLEN - 1); |
| } | } |
| Line 372 int main (int argc, char **argv) | Line 470 int main (int argc, char **argv) |
| else if (strncmp (action, "backup", STRLEN - 1) == 0) act = ACT_BACKUP; | else if (strncmp (action, "backup", STRLEN - 1) == 0) act = ACT_BACKUP; |
| else if (strncmp (action, "restore", STRLEN - 1) == 0) act = ACT_RESTORE; | else if (strncmp (action, "restore", STRLEN - 1) == 0) act = ACT_RESTORE; |
| else if (strncmp (action, "migrate", STRLEN - 1) == 0) act = ACT_MIGRATE; | else if (strncmp (action, "migrate", STRLEN - 1) == 0) act = ACT_MIGRATE; |
| else if (strncmp (action, "edit", STRLEN -1) == 0) act = ACT_EDIT; | else if (strncmp (action, "edit", STRLEN - 1) == 0) act = ACT_EDIT; |
| 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(); | 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; |
| else if (strncmp (obj_str, "routine", STRLEN - 1) == 0) obj = OBJ_ROUTINE; | else if (strncmp (obj_str, "routine", STRLEN - 1) == 0) obj = OBJ_ROUTINE; |
| else if (strncmp (obj_str, "job", STRLEN - 1) == 0) obj = OBJ_JOB; | else if (strncmp (obj_str, "job", STRLEN - 1) == 0) obj = OBJ_JOB; |
| else if (strncmp (obj_str, "environment", STRLEN - 1) == 0) obj = OBJ_DAEMON; | |
| else return fmadm_usage(); | else return fmadm_usage(); |
| if (act > ACT_EDIT) goto act_switch; | |
| if (get_conf (fma_namespace, "routines_path", fma_routine_path) == FALSE) { | if (get_conf (fma_namespace, "routines_path", fma_routine_path) == FALSE) { |
| fprintf (stderr, "fmadm: cannot determine routine path for namespace %s\n", fma_namespace); | fprintf (stderr, "fmadm: cannot determine routine path for namespace %s\n", fma_namespace); |
| return 1; | return 1; |
| Line 419 int main (int argc, char **argv) | Line 523 int main (int argc, char **argv) |
| stcnv_c2m (glopath); | stcnv_c2m (glopath); |
| act_switch: | |
| switch (act) { | switch (act) { |
| Line 473 int main (int argc, char **argv) | Line 578 int main (int argc, char **argv) |
| case ACT_EDIT: | case ACT_EDIT: |
| fmadm_exit (fm_edit (obj, optc, opts)); | fmadm_exit (fm_edit (obj, optc, opts)); |
| case ACT_START: | |
| case ACT_STOP: | |
| case ACT_RESTART: | |
| case ACT_STATUS: | |
| fmadm_exit (fm_daemonctl (act, obj, optc, opts)); | |
| default: | default: |
| return fmadm_usage(); | return fmadm_usage(); |
| Line 499 int fm_shell (void) | Line 609 int fm_shell (void) |
| char *cmdt = (char *) malloc (65535 * sizeof (char)); | char *cmdt = (char *) malloc (65535 * sizeof (char)); |
| char *result = (char *) malloc (65535 * sizeof (char)); | char *result = (char *) malloc (65535 * sizeof (char)); |
| /* | obj = 0; |
| strcpy (fma_namespace, "SYSTEM"); | |
| set_namespace (fma_namespace, FALSE); | |
| */ | |
| snprintf (fma_prompt, STRLEN - 1, "fmadm [%s]> ", fma_namespace); | snprintf (fma_prompt, STRLEN - 1, "fmadm [%s]> ", fma_namespace); |
| Line 607 int fm_shell (void) | Line 714 int fm_shell (void) |
| i = 0; | i = 0; |
| while ((result = strtok (NULL, " ")) != NULL) { | while ((result = strtok (NULL, " ")) != NULL) { |
| // printf ("%d = %s\n", i, result); | |
| strcpy (args[i++], result); | strcpy (args[i++], result); |
| } | } |
| Line 625 int fm_shell (void) | Line 731 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 818 void fmadm_exit (int retval) | Line 923 void fmadm_exit (int retval) |
| int fmadm_usage (void) | int fmadm_usage (void) |
| { | { |
| fprintf (stdout, "\nusage: fmadm <action> <object> [-e=<environment] [-n=<namespace>] [OPTIONS]\n"); | fprintf (stdout, "\nusage: fmadm <action> <object> [-e=<environment] [-n=<namespace>] [-u=<user>] [-g=<group>] [-E=true|false] [OPTIONS]\n"); |
| fprintf (stdout, " fmadm configure\n"); | fprintf (stdout, " fmadm configure\n"); |
| fprintf (stdout, " fmadm reconfigure\n"); | fprintf (stdout, " fmadm reconfigure\n"); |
| /* fprintf (stdout, " fmadm checkperms\n\n"); */ | |
| fprintf (stdout, " <action> can be one of:\n"); | fprintf (stdout, " <action> can be one of:\n"); |
| fprintf (stdout, " list, examine, verify, compact, repair, create, remove,\n"); | fprintf (stdout, " list, examine, verify, compact, repair, create, remove,\n"); |
| fprintf (stdout, " import, export, backup, restore, migrate, edit\n\n"); | fprintf (stdout, " import, export, backup, restore, migrate, edit, start,\n"); |
| fprintf (stdout, " stop, restart, status\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\n"); | fprintf (stdout, " lock, journal, namespace, global, routine, job,\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"); |
| fprintf (stdout, " for details on fmadm usage and options.\n\n"); | fprintf (stdout, " for details on fmadm usage and options.\n\n"); |
| Line 1052 int fm_edit (short object, int optc, cha | Line 1158 int fm_edit (short object, int optc, cha |
| case OBJ_ROUTINE: | case OBJ_ROUTINE: |
| return fma_routines_edit (optc, options); | return fma_routines_edit (optc, options); |
| /* | |
| case OBJ_GLOBAL: | case OBJ_GLOBAL: |
| return fma_globals_edit (optc, options); | return fma_globals_edit (optc, options); |
| */ | |
| default: | default: |
| fprintf (stderr, "fmadm: 'edit' is an invalid action for '%s'\n", obj_str); | fprintf (stderr, "fmadm: 'edit' is an invalid action for '%s'\n", obj_str); |
| return 1; | return 1; |
| Line 1065 int fm_edit (short object, int optc, cha | Line 1169 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]; | |
| 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_validate_environment (char *env) | |
| { | |
| FILE *fp; | |
| char line[255]; | |
| char chkline[255]; | |
| snprintf (chkline, 254, "[%s]\n", env); | |
| if ((fp = fopen (env_config_file, "r")) == NULL) { | |
| fprintf (stderr, "fmadm: could not open %s [%s]\n", env_config_file, strerror (errno)); | |
| return FALSE; | |
| } | |
| while (fgets (line, 254, fp)) { | |
| if (strncmp (line, chkline, 254) == 0) { | |
| fclose (fp); | |
| return TRUE; | |
| } | |
| } | |
| fclose (fp); | |
| return FALSE; | |
| } | |
| int fm_start_environment (char *env) | |
| { | |
| char basecmd[255]; | |
| char cmd[4096]; | |
| if (fm_environment_running (env) == TRUE) { | |
| return TRUE; | |
| } | |
| #if !defined(__OS2__) | |
| snprintf (basecmd, 254, "%s/bin/freem", PREFIX); | |
| #else | |
| snprintf (basecmd, 254, "%s/bin/freemd.exe", PREFIX); | |
| #endif | |
| #if !defined(__OS2__) | |
| snprintf (cmd, 4095, "%s -d -e %s", basecmd, env); | |
| #else | |
| sprintf (cmd, 4095, "%s -d -k -e %s", basecmd, env); | |
| #endif | |
| system (cmd); | |
| sleep (1); | |
| return (fm_environment_running (env)); | |
| } | |
| int fm_stop_environment (char *env) | |
| { | |
| long epid; | |
| epid = fm_get_pid (env); | |
| if (epid > -1) { | |
| kill (epid, SIGINT); | |
| sleep (5); | |
| if (fm_environment_running (env) == FALSE) { | |
| return TRUE; | |
| } | |
| else { | |
| kill (epid, SIGTERM); | |
| sleep (5); | |
| if (fm_environment_running (env) == FALSE) { | |
| return TRUE; | |
| } | |
| else { | |
| kill (epid, SIGKILL); | |
| sleep (5); | |
| if (fm_environment_running (env) == FALSE) { | |
| return TRUE; | |
| } | |
| else { | |
| return FALSE; | |
| } | |
| } | |
| } | |
| } | |
| else { | |
| return FALSE; | |
| } | |
| } | |
| int fm_environment_running (char *env) | |
| { | |
| long epid; | |
| int result; | |
| epid = fm_get_pid (env); | |
| if (epid == -1) { | |
| return FALSE; | |
| } | |
| else { | |
| result = kill (epid, 0); | |
| return ((result == 0) ? TRUE : FALSE); | |
| } | |
| } | |
| int fm_daemonctl (short action, short object, int optc, char **options) | |
| { | |
| FILE *ef; | |
| char *envlist; | |
| char env[255]; | |
| char line[255]; | |
| char tmps[255]; | |
| char *cur_env; | |
| char verb[40]; | |
| char e_user[255]; | |
| char e_grp[255]; | |
| char e_ena[10]; | |
| char *savptr; | |
| int result; | |
| long epid; | |
| int retval; | |
| retval = 0; | |
| switch (action) { | |
| case ACT_START: | |
| sprintf (verb, "starting"); | |
| break; | |
| case ACT_STOP: | |
| sprintf (verb, "stopping"); | |
| break; | |
| 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 = (char *) malloc (sizeof (char) * BIGSTR); | |
| NULLPTRCHK(envlist,"fm_daemonctl"); | |
| strcpy (envlist, options[1]); | |
| } | |
| else { | |
| /* no environment specified; do 'action' for all environments */ | |
| envlist = (char *) malloc (sizeof (char) * BIGSTR); | |
| NULLPTRCHK(envlist,"fm_daemonctl"); | |
| ef = fopen (env_config_file, "r"); | |
| while (fgets (line, 254, ef)) { | |
| if (line[0] == '[') { | |
| strncpy (env, &(line[1]), 255); | |
| env[strlen (env) - 2] = '\0'; | |
| snprintf (tmps, 255, "%s,", env); | |
| strncat (envlist, tmps, BIGSTR - 1); | |
| } | |
| } | |
| envlist[strlen (envlist) - 1] = '\0'; | |
| fclose (ef); | |
| } | |
| savptr = envlist; | |
| cur_env = strtok_r (envlist, ",", &savptr); | |
| do { | |
| if (fm_validate_environment (cur_env) == FALSE) { | |
| fprintf (stderr, "fmadm: %s is not a valid environment\n", cur_env); | |
| continue; | |
| } | |
| result = read_profile_string (env_config_file, cur_env, "enabled", e_ena); | |
| if (result == FALSE || strcmp (e_ena, "true") == 0) { | |
| result = read_profile_string (env_config_file, cur_env, "user", e_user); | |
| if (result == FALSE) { | |
| strcpy (e_user, "freem"); | |
| } | |
| result = read_profile_string (env_config_file, cur_env, "group", e_grp); | |
| if (result == FALSE) { | |
| strcpy (e_grp, "freem"); | |
| } | |
| switch (action) { | |
| case ACT_START: | |
| case ACT_STOP: | |
| case ACT_RESTART: | |
| fprintf (stderr, "fmadm: %s environment %s... ", verb, cur_env); | |
| break; | |
| case ACT_STATUS: | |
| fprintf (stderr, "fmadm: %s environment %s\n", verb, cur_env); | |
| break; | |
| } | |
| switch (action) { | |
| case ACT_START: | |
| result = fm_start_environment (cur_env); | |
| if (result == TRUE) { | |
| fprintf (stderr, "[OK]\n"); | |
| } | |
| else { | |
| fprintf (stderr, "[FAIL]\n"); | |
| } | |
| break; | |
| case ACT_STOP: | |
| result = fm_stop_environment (cur_env); | |
| if (result == TRUE) { | |
| fprintf (stderr, "[OK]\n"); | |
| } | |
| else { | |
| fprintf (stderr, "[FAIL]\n"); | |
| retval++; | |
| } | |
| break; | |
| case ACT_RESTART: | |
| if (fm_stop_environment (cur_env) == TRUE) { | |
| result = fm_start_environment (cur_env); | |
| if (result == TRUE) { | |
| fprintf (stderr, "[OK]\n"); | |
| } | |
| else { | |
| fprintf (stderr, "[FAIL]\n"); | |
| retval++; | |
| } | |
| } | |
| else { | |
| fprintf (stderr, "[FAIL]\n"); | |
| retval++; | |
| } | |
| break; | |
| case ACT_STATUS: | |
| epid = fm_get_pid (cur_env); | |
| if (epid > -1) { | |
| fprintf (stderr, " - %s environment daemon running as pid %ld\n", cur_env, epid); | |
| } | |
| else { | |
| fprintf (stderr, " - %s environment daemon does not appear to be running\n", cur_env); | |
| } | |
| } | |
| } | |
| else { | |
| printf ("fmadm: %s environment is disabled; skipping\n", cur_env); | |
| } | |
| } while ((cur_env = strtok_r (NULL, ",", &savptr)) != NULL); | |
| free (envlist); | |
| exit (retval); | |
| } /* fm_daemonctl() */ | |
| void fm_checkperms(void) | void fm_checkperms(void) |
| { | { |
| Line 1074 void fm_checkperms(void) | Line 1459 void fm_checkperms(void) |
| void fm_reconfigure(void) | void fm_reconfigure(void) |
| { | { |
| char config_backup[4096]; | char config_backup[4096]; |
| char vers[4096]; | |
| int retval; | int retval; |
| Line 1088 void fm_reconfigure(void) | Line 1472 void fm_reconfigure(void) |
| fprintf (stderr, "fmadm: reconfiguring FreeM with system defaults for %s...\n", FREEM_VERSION_CSTR); | fprintf (stderr, "fmadm: reconfiguring FreeM with system defaults for %s...\n", FREEM_VERSION_CSTR); |
| fprintf (stderr, "fmadm: backing up %s to %s...\t", config_file, config_backup); | fprintf (stderr, "fmadm: backing up %s to %s...\t", config_file, config_backup); |
| retval = rename (config_file, config_backup); | #if !defined(__OS2__) |
| retval = cp (config_backup, config_file); | |
| #else | |
| retval = DosCopy (config_file, config_backup); | |
| #endif | |
| if (retval == 0) { | if (retval == 0) { |
| fprintf (stderr, "[OK]\n\n"); | fprintf (stderr, "[OK]\n"); |
| fm_configure (); | fm_configure (); |
| Line 1105 void fm_reconfigure(void) | Line 1493 void fm_reconfigure(void) |
| } /* fm_reconfigure() */ | } /* fm_reconfigure() */ |
| void update_conf (char *file, char *section, char *key, char *new_value) | |
| { | |
| char old_value[255]; | |
| char tbuf[255]; | |
| snprintf (tbuf, 254, "%s.%s", section, key); | |
| read_profile_string (file, section, key, old_value); | |
| if (strcmp (old_value, new_value) != 0) { | |
| modify_profile_string (file, section, key, new_value); | |
| fprintf (stderr, "\t%-40s%-20s -> %s\n", tbuf, old_value, new_value); | |
| } | |
| else { | |
| fprintf (stderr, "\t%-40s%-20s\n", tbuf, "no change"); | |
| } | |
| } | |
| void fm_configure (void) | void fm_configure (void) |
| { | { |
| char rundir[4096]; | |
| char varbase[4096]; | |
| char sysrtn[4096]; | char sysrtn[4096]; |
| char sysgbl[4096]; | char sysgbl[4096]; |
| 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 1130 void fm_configure (void) | Line 1534 void fm_configure (void) |
| char buf[4096]; | char buf[4096]; |
| FILE *fp; | FILE *fp; |
| struct stat etcstat; | int reconfigure = FALSE; |
| int stat_result; | |
| struct stat etcstat; | |
| DIR *dir; | |
| struct dirent *ent; | |
| char src_dir[4096]; | |
| char dest_dir[4096]; | |
| char *username = env_user; | |
| char *groupname = env_group; | |
| #if !defined(__OS2__) | |
| struct group *d_grp; | |
| struct passwd *d_user; | |
| if (geteuid () != 0) { | |
| fprintf (stderr, "fmadm: not superuser\n"); | |
| exit (1); | |
| } | |
| if ((d_grp = getgrnam (groupname)) == NULL) { | |
| fprintf (stderr, "fmadm: '%s' group must exist before configuring\n", groupname); | |
| exit (1); | |
| } | |
| if ((d_user = getpwnam (username)) == NULL) { | |
| fprintf (stderr, "fmadm: '%s' user must exist before configuring\n", username); | |
| exit (1); | |
| } | |
| #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); | 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 1150 void fm_configure (void) | Line 1583 void fm_configure (void) |
| } | } |
| if (file_exists (config_file)) { | if (file_exists (config_file)) { |
| fprintf (stderr, "fmadm: '%s' already exists.\n\n", config_file); | reconfigure = TRUE; |
| fprintf (stderr, "'fmadm configure' may only be used on a fresh installation of FreeM.\n"); | |
| exit (1); | |
| } | } |
| gethostname (hostid, 4095); | gethostname (hostid, 4095); |
| uuid_v4 (buf); | uuid_v4 (buf); |
| snprintf (jnlhostid, 4095, "%s:%s", hostid, buf); | snprintf (jnlhostid, 4095, "%s:%s", hostid, buf); |
| snprintf (confbase, 4095, "%s/freem", SYSCONFDIR); | snprintf (confbase, 4095, "%s/freem", SYSCONFDIR); |
| snprintf (envbase, 4095, "%s/freem/%s", SYSCONFDIR, fma_environment); | snprintf (envbase, 4095, "%s/freem/%s", SYSCONFDIR, fma_environment); |
| snprintf (nsbase, 4095, "%s/freem/%s", LOCALSTATEDIR, fma_environment); | snprintf (nsbase, 4095, "%s/freem/%s", LOCALSTATEDIR, fma_environment); |
| Line 1184 void fm_configure (void) | Line 1613 void fm_configure (void) |
| chmod (dstfile, 0755); | chmod (dstfile, 0755); |
| } | } |
| #else | |
| fprintf (stderr, "fmadm: not running on OS/2\n"); | |
| #endif | #endif |
| printf ("\nFreeM Initial Configuration\n"); | |
| printf ("---------------------------\n\n"); | |
| printf ("This utility will create the initial configuration file for "); | if (reconfigure == FALSE) { |
| printf ("FreeM environment '%s' in %s.\n\n", fma_environment, config_file); | printf ("\nFreeM Initial Environment Configuration\n"); |
| printf ("---------------------------------------\n\n"); | |
| printf ("This utility will create the initial configuration files for "); | |
| printf ("FreeM environment '%s' (owned by %s:%s) in '%s'.\n\n", fma_environment, username, groupname, config_file); | |
| } | |
| else { | |
| printf ("\nFreeM Environment Upgrade/Reconfiguration\n"); | |
| printf ("-----------------------------------------\n\n"); | |
| printf ("This utility will update the configuration files for "); | |
| printf ("FreeM environment '%s' (owned by %s:%s) in '%s'.\n\n", fma_environment, username, groupname, config_file); | |
| } | |
| /* 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, 0755); | mkdir (SYSCONFDIR, 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, 0755); | mkdir (confbase, 0775); |
| set_permissions (confbase, username, groupname, 0775); | |
| } | |
| if (stat (varbase, &etcstat) == -1) { | |
| fprintf (stderr, "fmadm: creating %s [varbase]\n", varbase); | |
| mkdir (varbase, 0775); | |
| set_permissions (varbase, username, groupname, 0775); | |
| } | } |
| if (stat (envbase, &etcstat) == -1) { | if (stat (envbase, &etcstat) == -1) { |
| fprintf (stderr, "fmadm: creating %s\n", envbase); | fprintf (stderr, "fmadm: creating %s [envbase]\n", envbase); |
| mkdir (envbase, 0755); | mkdir (envbase, 0775); |
| set_permissions (envbase, username, groupname, 0775); | |
| } | |
| if (stat (rundir, &etcstat) == -1) { | |
| fprintf (stderr, "fmadm: creating %s [rundir]\n", rundir); | |
| mkdir (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, 0755); | mkdir (nsbase, 0775); |
| set_permissions (nsbase, username, groupname, 0775); | |
| } | } |
| if (stat (jnldir, &etcstat) == -1) { | |
| fprintf (stderr, "fmadm: creating %s [jnldir]\n", jnldir); | |
| if (strcmp (fma_environment, "DEFAULT") != 0) { | mkdir (jnldir, 0775); |
| set_permissions (jnldir, username, groupname, 0775); | |
| } | |
| DIR *dir; | |
| struct dirent *ent; | snprintf (src_dir, 4095, "%s/freem/mlib", DATADIR); |
| char src_dir[4096]; | snprintf (dest_dir, 4095, "%s/freem/%s/SYSTEM/routines", LOCALSTATEDIR, fma_environment); |
| char dest_dir[4096]; | |
| snprintf (src_dir, 4095, "%s/freem/DEFAULT/SYSTEM/routines", LOCALSTATEDIR); | if (reconfigure == FALSE) { |
| snprintf (dest_dir, 4095, "%s/freem/%s/SYSTEM/routines", LOCALSTATEDIR, fma_environment); | |
| fprintf (stderr, "fmadm: populating new environment '%s'\n", fma_environment); | fprintf (stderr, "fmadm: populating new environment '%s'\n", fma_environment); |
| } | |
| snprintf (buf, 4095, "%s/freem/%s/SYSTEM", LOCALSTATEDIR, fma_environment); | else { |
| mkdir (buf, 0755); | fprintf (stderr, "fmadm: upgrading environment '%s'\n", fma_environment); |
| } | |
| snprintf (buf, 4095, "%s/freem/%s/USER", LOCALSTATEDIR, fma_environment); | |
| mkdir (buf, 0755); | snprintf (buf, 4095, "%s/freem/%s/SYSTEM", LOCALSTATEDIR, fma_environment); |
| mkdir (buf, 0775); | |
| snprintf (buf, 4095, "%s/freem/%s/SYSTEM/routines", LOCALSTATEDIR, fma_environment); | set_permissions (buf, username, groupname, 0775); |
| mkdir (buf, 0755); | |
| snprintf (buf, 4095, "%s/freem/%s/USER", LOCALSTATEDIR, fma_environment); | |
| snprintf (buf, 4095, "%s/freem/%s/USER/globals", LOCALSTATEDIR, fma_environment); | mkdir (buf, 0775); |
| mkdir (buf, 0755); | set_permissions (buf, username, groupname, 0775); |
| snprintf (buf, 4095, "%s/freem/%s/SYSTEM/globals", LOCALSTATEDIR, fma_environment); | snprintf (buf, 4095, "%s/freem/%s/SYSTEM/routines", LOCALSTATEDIR, fma_environment); |
| mkdir (buf, 0755); | mkdir (buf, 0775); |
| set_permissions (buf, username, groupname, 0775); | |
| snprintf (buf, 4095, "%s/freem/%s/USER/routines", LOCALSTATEDIR, fma_environment); | |
| mkdir (buf, 0755); | snprintf (buf, 4095, "%s/freem/%s/USER/globals", LOCALSTATEDIR, fma_environment); |
| mkdir (buf, 0775); | |
| fprintf (stderr, "fmadm: copying routines from '%s' to '%s'...\n", src_dir, dest_dir); | set_permissions (buf, username, groupname, 0775); |
| if ((dir = opendir (src_dir)) == NULL) { | snprintf (buf, 4095, "%s/freem/%s/SYSTEM/globals", LOCALSTATEDIR, fma_environment); |
| fprintf (stderr, "\nfmadm: could not open source directory %s\n", src_dir); | mkdir (buf, 0775); |
| exit (1); | set_permissions (buf, username, groupname, 0775); |
| } | |
| snprintf (buf, 4095, "%s/freem/%s/USER/routines", LOCALSTATEDIR, fma_environment); | |
| while ((ent = readdir (dir)) != NULL) { | mkdir (buf, 0775); |
| char infile[4096]; | set_permissions (buf, username, groupname, 0775); |
| char outfile[4096]; | |
| fprintf (stderr, "fmadm: copying vendor routines from '%s' to '%s'...\n", src_dir, dest_dir); | |
| if ((strcmp (ent->d_name, ".") != 0) && (strcmp (ent->d_name, "..") != 0)) { | |
| fprintf (stderr, "\t%s\n", ent->d_name); | |
| snprintf (infile, 4095, "%s/%s", src_dir, ent->d_name); | |
| snprintf (outfile, 4095, "%s/%s", dest_dir, ent->d_name); | |
| if (cp (outfile, infile) != 0) { | if ((dir = opendir (src_dir)) == NULL) { |
| fprintf (stderr, "fmadm: failure copying %s to %s\n", infile, outfile); | fprintf (stderr, "\nfmadm: could not open source directory %s\n", src_dir); |
| } | exit (1); |
| } | |
| while ((ent = readdir (dir)) != NULL) { | |
| char infile[4096]; | |
| char outfile[4096]; | |
| if ((strcmp (ent->d_name, ".") != 0) && (strcmp (ent->d_name, "..") != 0)) { | |
| snprintf (infile, 4095, "%s/%s", src_dir, ent->d_name); | |
| snprintf (outfile, 4095, "%s/%s", dest_dir, ent->d_name); | |
| if (stat (outfile, &etcstat) == 0) { | |
| unlink (outfile); | |
| fprintf (stderr, "\tupgrade -> %s\n", ent->d_name); | |
| } | |
| else { | |
| fprintf (stderr, "\tnew -> %s\n", ent->d_name); | |
| } | } |
| } | #if !defined(__OS2__) |
| if (cp (outfile, infile) != 0) { | |
| fprintf (stderr, "fmadm: failure copying %s to %s\n", infile, outfile); | |
| } | |
| set_permissions (outfile, username, groupname, 0755); | |
| #else | |
| if (DosCopy (infile, outfile, 1) != 0) { | |
| fprintf (stderr, "fmadm: failure copying %s to %s\n", infile, outfile); | |
| } | |
| #endif | |
| } | |
| } | } |
| fp = fopen (config_file, "a+"); | |
| printf ("Creating %s... ", config_file); | |
| snprintf (buf, 4095, "[SYSTEM]"); | |
| fm_write (fp, buf); | |
| snprintf (buf, 4095, "root=%s/freem/%s/SYSTEM", LOCALSTATEDIR, fma_environment); | if (fm_validate_environment (fma_environment) == FALSE) { |
| fm_write (fp, buf); | fp = fopen (env_config_file, "a+"); |
| snprintf (buf, 4095, "routines_path=%s", sysrtn); | fprintf (stderr, "Creating %s... ", env_config_file); |
| fm_write (fp, buf); | |
| snprintf (buf, 4095, "[%s]", fma_environment); | |
| snprintf (buf, 4095, "globals_path=%s", sysgbl); | fm_write (fp, buf); |
| fm_write (fp, buf); | |
| snprintf (buf, 4095, "user=%s", env_user); | |
| fm_write (fp, buf); | |
| snprintf (buf, 4095, "group=%s", env_group); | |
| fm_write (fp, buf); | |
| snprintf (buf, 4095, "enabled=%s", env_enabled); | |
| fm_write (fp, buf); | |
| snprintf (buf, 4095, "env_path=%s/freem/%s", LOCALSTATEDIR, fma_environment); | |
| fm_write (fp, buf); | |
| fclose (fp); | |
| fprintf (stderr, "[OK]\n"); | |
| } | |
| else { | |
| fprintf (stderr, "\nUpdating %s: \n", env_config_file); | |
| snprintf (buf, 4095, "journal_file=%s", jnlfile); | update_conf (env_config_file, fma_environment, "user", env_user); |
| fm_write (fp, buf); | update_conf (env_config_file, fma_environment, "group", env_group); |
| update_conf (env_config_file, fma_environment, "enabled", env_enabled); | |
| } | |
| snprintf (buf, 4095, "journal_mode=%s", jnlmode); | if (reconfigure == FALSE) { |
| fm_write (fp, buf); | fp = fopen (config_file, "a+"); |
| fprintf (stderr, "Creating %s... ", config_file); | |
| snprintf (buf, 4095, "[SYSTEM]"); | |
| fm_write (fp, buf); | |
| snprintf (buf, 4095, "root=%s/freem/%s/SYSTEM", LOCALSTATEDIR, fma_environment); | |
| fm_write (fp, buf); | |
| snprintf (buf, 4095, "routines_path=%s", sysrtn); | |
| fm_write (fp, buf); | |
| snprintf (buf, 4095, "globals_path=%s", sysgbl); | |
| fm_write (fp, buf); | |
| snprintf (buf, 4095, "journal_file=%s", jnlfile); | |
| fm_write (fp, buf); | |
| snprintf (buf, 4095, "journal_mode=%s", jnlmode); | |
| fm_write (fp, buf); | |
| snprintf (buf, 4095, "journal_host_id=%s", jnlhostid); | |
| fm_write (fp, buf); | |
| snprintf (buf, 4095, "journal_cut_threshold=%s", jnlcut); | |
| fm_write (fp, buf); | |
| snprintf (buf, 4095, "zdate_format=%%x"); | |
| fm_write (fp, buf); | |
| snprintf (buf, 4095, "ztime_format=%%X"); | |
| fm_write (fp, buf); | |
| snprintf (buf, 4095, "\n[USER]"); | |
| fm_write (fp, buf); | |
| snprintf (buf, 4095, "root=%s/freem/%s/USER", LOCALSTATEDIR, fma_environment); | |
| fm_write (fp, buf); | |
| snprintf (buf, 4095, "routines_path=%s", usrrtn); | |
| fm_write (fp, buf); | |
| snprintf (buf, 4095, "globals_path=%s", usrgbl); | |
| fm_write (fp, buf); | |
| fclose (fp); | |
| set_permissions (config_file, username, groupname, 0755); | |
| fprintf (stderr, "[OK]\n"); | |
| printf ("FreeM initial configuration is complete.\n\n"); | |
| } | |
| else { | |
| char tmpsd[255]; | |
| read_profile_string (config_file, "SYSTEM", "journal_host_id", tmpsd); | |
| /* existing configuration */ | |
| fprintf (stderr, "\nUpdating environment configuration for %s:\n", fma_environment); | |
| snprintf (buf, 4095, "journal_host_id=%s", jnlhostid); | snprintf (buf, 4095, "%s/freem/%s/SYSTEM", LOCALSTATEDIR, fma_environment); |
| fm_write (fp, buf); | update_conf (config_file, "SYSTEM", "root", buf); |
| update_conf (config_file, "SYSTEM", "routines_path", sysrtn); | |
| update_conf (config_file, "SYSTEM", "globals_path", sysgbl); | |
| update_conf (config_file, "SYSTEM", "journal_file", jnlfile); | |
| update_conf (config_file, "SYSTEM", "journal_mode", jnlmode); | |
| update_conf (config_file, "SYSTEM", "journal_host_id", tmpsd); | |
| update_conf (config_file, "SYSTEM", "journal_cut_threshold", jnlcut); | |
| snprintf (buf, 4095, "journal_cut_threshold=%s", jnlcut); | snprintf (buf, 4095, "%%x"); |
| fm_write (fp, buf); | update_conf (config_file, "SYSTEM", "zdate_format", buf); |
| snprintf (buf, 4095, "%%X"); | |
| update_conf (config_file, "SYSTEM", "ztime_format", buf); | |
| snprintf (buf, 4095, "zdate_format=%%x"); | /* USER */ |
| fm_write (fp, buf); | snprintf (buf, 4095, "%s/freem/%s/USER", LOCALSTATEDIR, fma_environment); |
| update_conf (config_file, "USER", "root", buf); | |
| update_conf (config_file, "USER", "routines_path", usrrtn); | |
| update_conf (config_file, "USER", "globals_path", usrgbl); | |
| snprintf (buf, 4095, "ztime_format=%%X"); | } |
| fm_write (fp, buf); | |
| snprintf (buf, 4095, "\n[USER]"); | |
| fm_write (fp, buf); | printf ("\n\nUSER globals: %s\n", usrgbl); |
| printf ("USER routines: %s\n", usrrtn); | |
| snprintf (buf, 4095, "root=%s/freem/%s/USER", LOCALSTATEDIR, fma_environment); | printf ("SYSTEM globals: %s\n", sysgbl); |
| fm_write (fp, buf); | printf ("SYSTEM routines: %s\n", sysrtn); |
| printf ("After-image journal: %s [%s]\n", jnlfile, jnlmode); | |
| snprintf (buf, 4095, "routines_path=%s", usrrtn); | printf ("Journal cut threshold: %s bytes\n", jnlcut); |
| fm_write (fp, buf); | printf ("Distributed journaling host ID: %s\n", jnlhostid); |
| snprintf (buf, 4095, "globals_path=%s", usrgbl); | if (reconfigure == TRUE) { |
| fm_write (fp, buf); | fprintf (stderr, "\nIf you previously defined environments other than '%s', you should run\n'fmadm reconfigure -e=<environment-name>' on each of them to ensure they have\nthe latest vendor routines and correct, updated settings.\n\n", fma_environment); |
| } | |
| fclose (fp); | } /* fm_configure */ |
| printf ("[OK]\n\n"); | |
| /* | |
| printf ("Setting USER namespace permissions... "); | |
| snprintf (buf, 4095, "%s/freem/USER/globals", LOCALSTATEDIR); | |
| chmod (buf, 0777); | |
| snprintf (buf, 4095, "%s/freem/USER/routines", LOCALSTATEDIR); | |
| chmod (buf, 0777); | |
| printf ("[OK]\n"); | void set_permissions(char *path, char *user, char *grp, int mode) |
| printf ("Setting SYSTEM namespace permissions... "); | { |
| snprintf (buf, 4095, "%s/freem/SYSTEM/globals", LOCALSTATEDIR); | #if !defined(__OS2__) |
| chmod (buf, 0755); | struct group *d_grp; |
| struct passwd *d_user; | |
| gid_t d_gid; | |
| uid_t d_uid; | |
| #endif | |
| snprintf (buf, 4095, "%s/freem/SYSTEM/routines", LOCALSTATEDIR); | |
| chmod (buf, 0755); | |
| printf ("[OK]\n\n\n"); | #if !defined(__OS2__) |
| */ | if ((d_grp = getgrnam (grp)) == NULL) { |
| printf ("FreeM initial configuration is complete.\n\n"); | fprintf (stderr, "fmadm: '%s' group must exist before configuring\n", grp); |
| exit (1); | |
| } | |
| d_gid = d_grp->gr_gid; | |
| printf (" USER globals: %s\n", usrgbl); | if ((d_user = getpwnam (user)) == NULL) { |
| printf (" USER routines: %s\n", usrrtn); | fprintf (stderr, "fmadm: '%s' user must exist before configuring\n", user); |
| printf (" SYSTEM globals: %s\n", sysgbl); | exit (1); |
| printf (" SYSTEM routines: %s\n", sysrtn); | } |
| printf (" After-image journal: %s [%s]\n", jnlfile, jnlmode); | d_uid = d_user->pw_uid; |
| printf (" Journal cut threshold: %s bytes\n", jnlcut); | |
| printf (" Distributed journaling host ID: %s\n", jnlhostid); | |
| if (chown (path, d_uid, d_gid) != 0) { | |
| fprintf (stderr, "fmadm: error setting ownership on %s\n", path); | |
| exit (1); | |
| } | |
| #endif | |
| if (chmod (path, mode) != 0) { | |
| fprintf (stderr, "fmadm: error setting permissions on %s to %d\n", path, mode); | |
| exit (1); | |
| } | |
| } /* fm_configure */ | } |
| void fm_write (FILE *file, char *buf) | void fm_write (FILE *file, char *buf) |
| { | { |