|
|
| version 1.24, 2025/04/02 03:02:42 | version 1.30, 2025/04/03 20:48:14 |
|---|---|
| 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.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 | * Revision 1.24 2025/04/02 03:02:42 snw |
| * Stop requiring users to pass -e to fmadm when -u or -g are passed | * Stop requiring users to pass -e to fmadm when -u or -g are passed |
| * | * |
| Line 162 extern char config_file[4096]; | Line 180 extern char config_file[4096]; |
| extern char env_config_file[4096]; | extern char env_config_file[4096]; |
| extern char env_user[255]; | extern char env_user[255]; |
| extern char env_group[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); |
| Line 171 int fm_daemonctl (short action, short ob | Line 190 int fm_daemonctl (short action, short ob |
| 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); | 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); | 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 191 int main (int argc, char **argv) | Line 211 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 277 int main (int argc, char **argv) | Line 298 int main (int argc, char **argv) |
| 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 318 int main (int argc, char **argv) | Line 364 int main (int argc, char **argv) |
| snprintf (env_config_file, 4096, "%s/freem/env.conf", SYSCONFDIR); | 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 and daemon stuff */ | /* override for fmadm configure and daemon stuff */ |
| if (got_action) { | if (got_action) { |
| Line 336 int main (int argc, char **argv) | Line 382 int main (int argc, char **argv) |
| else if (strcmp (argv[1], "start") == 0 && strcmp (argv[2], "environment") == 0) { | else if (strcmp (argv[1], "start") == 0 && strcmp (argv[2], "environment") == 0) { |
| act = ACT_START; | act = ACT_START; |
| obj = OBJ_DAEMON; | obj = OBJ_DAEMON; |
| goto act_switch; | goto process_args; |
| } | } |
| else if (strcmp (argv[1], "stop") == 0 && strcmp (argv[2], "environment") == 0) { | else if (strcmp (argv[1], "stop") == 0 && strcmp (argv[2], "environment") == 0) { |
| act = ACT_STOP; | act = ACT_STOP; |
| obj = OBJ_DAEMON; | obj = OBJ_DAEMON; |
| goto act_switch; | goto process_args; |
| } | } |
| else if (strcmp (argv[1], "restart") == 0 && strcmp (argv[2], "environment") == 0) { | else if (strcmp (argv[1], "restart") == 0 && strcmp (argv[2], "environment") == 0) { |
| act = ACT_RESTART; | act = ACT_RESTART; |
| obj = OBJ_DAEMON; | obj = OBJ_DAEMON; |
| goto act_switch; | goto process_args; |
| } | } |
| else if (strcmp (argv[1], "status") == 0 && strcmp (argv[2], "environment") == 0) { | else if (strcmp (argv[1], "status") == 0 && strcmp (argv[2], "environment") == 0) { |
| act = ACT_STATUS; | act = ACT_STATUS; |
| obj = OBJ_DAEMON; | obj = OBJ_DAEMON; |
| goto act_switch; | goto process_args; |
| } | } |
| } | } |
| Line 374 int main (int argc, char **argv) | Line 420 int main (int argc, char **argv) |
| } | } |
| set_namespace (fma_namespace, FALSE); | set_namespace (fma_namespace, FALSE); |
| process_args: | |
| /* allocate opts array */ | /* allocate opts array */ |
| /* first dimension */ | /* first dimension */ |
| Line 397 int main (int argc, char **argv) | Line 444 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 417 int main (int argc, char **argv) | Line 465 int main (int argc, char **argv) |
| else if (strncmp (action, "start", STRLEN - 1) == 0) act = ACT_START; | 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, "stop", STRLEN - 1) == 0) act = ACT_STOP; |
| else if (strncmp (action, "restart", STRLEN - 1) == 0) act = ACT_RESTART; | 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; |
| Line 869 void fmadm_exit (int retval) | Line 918 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, start,\n"); | fprintf (stdout, " import, export, backup, restore, migrate, edit, start,\n"); |
| fprintf (stdout, " stop, restart\n\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, journal, namespace, global, routine, job,\n"); | fprintf (stdout, " lock, journal, namespace, global, routine, job,\n"); |
| Line 1141 long fm_get_pid (char *env) | Line 1189 long fm_get_pid (char *env) |
| } | } |
| } | } |
| 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 *e_user, char *e_grp) | |
| { | |
| 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 -u %s -g %s", basecmd, env, e_user, e_grp); | |
| #else | |
| sprintf (cmd, 4095, "%s -d -k -e %s -u %s -g %s", basecmd, env, e_user, e_grp); | |
| #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) | int fm_daemonctl (short action, short object, int optc, char **options) |
| { | { |
| FILE *ef; | FILE *ef; |
| Line 1149 int fm_daemonctl (short action, short ob | Line 1301 int fm_daemonctl (short action, short ob |
| char line[255]; | char line[255]; |
| char tmps[255]; | char tmps[255]; |
| char *cur_env; | char *cur_env; |
| char cmd[4096]; | |
| char verb[40]; | 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 *savptr; | char *savptr; |
| int result; | int result; |
| long epid; | long epid; |
| int retval; | |
| #if !defined(__OS2__) | |
| snprintf (basecmd, 254, "%s/bin/freem", PREFIX); | retval = 0; |
| #else | |
| snprintf (basecmd, 254, "%s/bin/freemd.exe", PREFIX); | |
| #endif | |
| switch (action) { | switch (action) { |
| case ACT_START: | case ACT_START: |
| Line 1185 int fm_daemonctl (short action, short ob | Line 1332 int fm_daemonctl (short action, short ob |
| envlist = (char *) malloc (sizeof (char) * BIGSTR); | envlist = (char *) malloc (sizeof (char) * BIGSTR); |
| NULLPTRCHK(envlist,"fm_daemonctl"); | NULLPTRCHK(envlist,"fm_daemonctl"); |
| strcpy (envlist, options[0]); | strcpy (envlist, options[1]); |
| } | } |
| else { | else { |
| /* no environment specified; do 'action' for all environments */ | /* no environment specified; do 'action' for all environments */ |
| Line 1210 int fm_daemonctl (short action, short ob | Line 1357 int fm_daemonctl (short action, short ob |
| savptr = envlist; | savptr = envlist; |
| cur_env = strtok_r (envlist, ",", &savptr); | cur_env = strtok_r (envlist, ",", &savptr); |
| do { | 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); | result = read_profile_string (env_config_file, cur_env, "enabled", e_ena); |
| if (result == FALSE || strcmp (e_ena, "true") == 0) { | if (result == FALSE || strcmp (e_ena, "true") == 0) { |
| Line 1222 int fm_daemonctl (short action, short ob | Line 1375 int fm_daemonctl (short action, short ob |
| strcpy (e_grp, "freem"); | strcpy (e_grp, "freem"); |
| } | } |
| printf ("fmadm: %s environment %s\n", verb, cur_env); | 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) { | switch (action) { |
| case ACT_START: | case ACT_START: |
| #if !defined(__OS2__) | result = fm_start_environment (cur_env, e_user, e_grp); |
| snprintf (cmd, 4095, "%s -d -e %s -u %s -g %s", basecmd, cur_env, e_user, e_grp); | if (result == TRUE) { |
| #else | fprintf (stderr, "[OK]\n"); |
| sprintf (cmd, 4095, "%s -d -k -e %s -u %s -g %s", basecmd, cur_env, e_user, e_grp); | } |
| #endif | else { |
| system (cmd); | fprintf (stderr, "[FAIL]\n"); |
| } | |
| break; | break; |
| case ACT_STOP: | case ACT_STOP: |
| epid = fm_get_pid (cur_env); | result = fm_stop_environment (cur_env); |
| if (epid > -1) { | if (result == TRUE) { |
| fprintf (stderr, "fmadm: stopping environment daemon pid %d\n", epid); | fprintf (stderr, "[OK]\n"); |
| kill (epid, SIGINT); | |
| kill (epid, SIGTERM); | |
| } | } |
| else { | else { |
| fprintf (stderr, "fmadm: could not obtain environment daemon pid\n"); | fprintf (stderr, "[FAIL]\n"); |
| } | retval++; |
| } | |
| break; | break; |
| case ACT_RESTART: | case ACT_RESTART: |
| epid = fm_get_pid (cur_env); | if (fm_stop_environment (cur_env) == TRUE) { |
| if (epid > -1) { | result = fm_start_environment (cur_env, e_user, e_grp); |
| fprintf (stderr, "fmadm: stopping environment daemon pid %d\n", epid); | if (result == TRUE) { |
| kill (epid, SIGINT); | fprintf (stderr, "[OK]\n"); |
| kill (epid, SIGTERM); | } |
| else { | |
| fprintf (stderr, "[FAIL]\n"); | |
| retval++; | |
| } | |
| } | } |
| else { | else { |
| fprintf (stderr, "fmadm: could not obtain environment daemon pid\n"); | fprintf (stderr, "[FAIL]\n"); |
| } | retval++; |
| 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); | |
| break; | break; |
| case ACT_STATUS: | case ACT_STATUS: |
| epid = fm_get_pid (cur_env); | epid = fm_get_pid (cur_env); |
| if (epid > -1) { | if (epid > -1) { |
| Line 1283 int fm_daemonctl (short action, short ob | Line 1443 int fm_daemonctl (short action, short ob |
| } while ((cur_env = strtok_r (NULL, ",", &savptr)) != NULL); | } while ((cur_env = strtok_r (NULL, ",", &savptr)) != NULL); |
| free (envlist); | free (envlist); |
| exit (0); | exit (retval); |
| } /* fm_daemonctl() */ | } /* fm_daemonctl() */ |
| Line 1310 void fm_reconfigure(void) | Line 1470 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"); | fprintf (stderr, "[OK]\n"); |
| Line 1327 void fm_reconfigure(void) | Line 1491 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) |
| { | { |
| Line 1352 void fm_configure (void) | Line 1532 void fm_configure (void) |
| char buf[4096]; | char buf[4096]; |
| FILE *fp; | FILE *fp; |
| int reconfigure = FALSE; | |
| struct stat etcstat; | struct stat etcstat; |
| int stat_result; | int stat_result; |
| Line 1362 void fm_configure (void) | Line 1544 void fm_configure (void) |
| char *username = env_user; | char *username = env_user; |
| char *groupname = env_group; | char *groupname = env_group; |
| #if !defined(__OS2__) | #if !defined(__OS2__) |
| if (geteuid () != 0) { | if (geteuid () != 0) { |
| fprintf (stderr, "fmadm: not superuser\n"); | fprintf (stderr, "fmadm: not superuser\n"); |
| Line 1405 void fm_configure (void) | Line 1587 void fm_configure (void) |
| } | } |
| if (file_exists (config_file)) { | if (file_exists (config_file)) { |
| fprintf (stderr, "fmadm: '%s' already exists; running fmadm reconfigure instead\n", config_file); | reconfigure = TRUE; |
| fm_reconfigure (); | |
| return; | |
| } | } |
| gethostname (hostid, 4095); | gethostname (hostid, 4095); |
| uuid_v4 (buf); | uuid_v4 (buf); |
| Line 1437 void fm_configure (void) | Line 1617 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' (owned by %s:%s) in '%s'.\n\n", fma_environment, username, groupname, 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) { |
| Line 1493 void fm_configure (void) | Line 1680 void fm_configure (void) |
| 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); |
| fprintf (stderr, "fmadm: populating new environment '%s'\n", fma_environment); | if (reconfigure == FALSE) { |
| fprintf (stderr, "fmadm: populating new environment '%s'\n", fma_environment); | |
| } | |
| else { | |
| fprintf (stderr, "fmadm: upgrading environment '%s'\n", fma_environment); | |
| } | |
| snprintf (buf, 4095, "%s/freem/%s/SYSTEM", LOCALSTATEDIR, fma_environment); | snprintf (buf, 4095, "%s/freem/%s/SYSTEM", LOCALSTATEDIR, fma_environment); |
| mkdir (buf, 0775); | mkdir (buf, 0775); |
| Line 1520 void fm_configure (void) | Line 1712 void fm_configure (void) |
| mkdir (buf, 0775); | mkdir (buf, 0775); |
| set_permissions (buf, username, groupname, 0775); | set_permissions (buf, username, groupname, 0775); |
| fprintf (stderr, "fmadm: copying routines from '%s' to '%s'...\n", src_dir, dest_dir); | fprintf (stderr, "fmadm: copying vendor routines from '%s' to '%s'...\n", src_dir, dest_dir); |
| if ((dir = opendir (src_dir)) == NULL) { | if ((dir = opendir (src_dir)) == NULL) { |
| fprintf (stderr, "\nfmadm: could not open source directory %s\n", src_dir); | fprintf (stderr, "\nfmadm: could not open source directory %s\n", src_dir); |
| Line 1531 void fm_configure (void) | Line 1723 void fm_configure (void) |
| char infile[4096]; | char infile[4096]; |
| char outfile[4096]; | char outfile[4096]; |
| if ((strcmp (ent->d_name, ".") != 0) && (strcmp (ent->d_name, "..") != 0)) { | 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 (infile, 4095, "%s/%s", src_dir, ent->d_name); |
| snprintf (outfile, 4095, "%s/%s", dest_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 !defined(__OS2__) |
| if (cp (outfile, infile) != 0) { | if (cp (outfile, infile) != 0) { |
| fprintf (stderr, "fmadm: failure copying %s to %s\n", infile, outfile); | fprintf (stderr, "fmadm: failure copying %s to %s\n", infile, outfile); |
| Line 1553 void fm_configure (void) | Line 1751 void fm_configure (void) |
| } | } |
| fp = fopen (env_config_file, "a+"); | if (fm_validate_environment (fma_environment) == FALSE) { |
| fp = fopen (env_config_file, "a+"); | |
| fprintf (stderr, "Creating %s... ", env_config_file); | |
| fprintf (stderr, "Creating %s... ", env_config_file); | |
| snprintf (buf, 4095, "[%s]", fma_environment); | |
| fm_write (fp, buf); | snprintf (buf, 4095, "[%s]", fma_environment); |
| 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 { | |
| char modtmp[255]; | |
| fprintf (stderr, "\nUpdating %s: \n", env_config_file); | |
| snprintf (buf, 4095, "user=%s", env_user); | 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, "group=%s", env_group); | } |
| fm_write (fp, buf); | |
| snprintf (buf, 4095, "enabled=true"); | if (reconfigure == FALSE) { |
| fm_write (fp, buf); | fp = fopen (config_file, "a+"); |
| snprintf (buf, 4095, "env_path=%s/freem/%s", LOCALSTATEDIR, fma_environment); | fprintf (stderr, "Creating %s... ", config_file); |
| fm_write (fp, buf); | |
| snprintf (buf, 4095, "[SYSTEM]"); | |
| fclose (fp); | fm_write (fp, buf); |
| fprintf (stderr, "[OK]\n"); | |
| snprintf (buf, 4095, "root=%s/freem/%s/SYSTEM", LOCALSTATEDIR, fma_environment); | |
| fp = fopen (config_file, "a+"); | fm_write (fp, buf); |
| fprintf (stderr, "Creating %s... ", config_file); | 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"); | |
| snprintf (buf, 4095, "[SYSTEM]"); | printf ("FreeM initial configuration is complete.\n\n"); |
| fm_write (fp, buf); | } |
| else { | |
| snprintf (buf, 4095, "root=%s/freem/%s/SYSTEM", LOCALSTATEDIR, fma_environment); | char tmpsd[255]; |
| fm_write (fp, buf); | read_profile_string (config_file, "SYSTEM", "journal_host_id", tmpsd); |
| snprintf (buf, 4095, "routines_path=%s", sysrtn); | /* existing configuration */ |
| fm_write (fp, buf); | fprintf (stderr, "\nUpdating environment configuration for %s:\n", fma_environment); |
| 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); | 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); | |
| 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); | printf ("\n\nUSER globals: %s\n", usrgbl); |
| set_permissions (config_file, username, groupname, 0755); | printf ("USER routines: %s\n", usrrtn); |
| fprintf (stderr, "[OK]\n"); | printf ("SYSTEM globals: %s\n", sysgbl); |
| printf ("SYSTEM routines: %s\n", sysrtn); | |
| printf ("FreeM initial configuration is complete.\n\n"); | printf ("After-image journal: %s [%s]\n", jnlfile, jnlmode); |
| printf ("Journal cut threshold: %s bytes\n", jnlcut); | |
| printf (" USER globals: %s\n", usrgbl); | printf ("Distributed journaling host ID: %s\n", jnlhostid); |
| printf (" USER routines: %s\n", usrrtn); | |
| printf (" SYSTEM globals: %s\n", sysgbl); | |
| printf (" SYSTEM routines: %s\n", sysrtn); | |
| printf (" After-image journal: %s [%s]\n", jnlfile, jnlmode); | |
| printf (" Journal cut threshold: %s bytes\n", jnlcut); | |
| printf (" Distributed journaling host ID: %s\n", jnlhostid); | |
| if (reconfigure == TRUE) { | |
| 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); | |
| } | |
| } /* fm_configure */ | } /* fm_configure */ |