| version 1.26, 2025/04/02 14:37:57 | version 1.27, 2025/04/02 15:36:25 | 
| 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.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 | *   Revision 1.26  2025/04/02 14:37:57  snw | 
 | *   Improve environment control parts of fmadm | *   Improve environment control parts of fmadm | 
 | * | * | 
| Line 177  int fm_daemonctl (short action, short ob | Line 180  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 1178  int fm_start_environment (char *env, cha | Line 1182  int fm_start_environment (char *env, cha | 
 | { | { | 
 | char basecmd[255]; | char basecmd[255]; | 
 | char cmd[4096]; | char cmd[4096]; | 
 |  |  | 
 |  | if (fm_environment_running (env) == TRUE) { | 
 |  | return TRUE; | 
 |  | } | 
 |  |  | 
 | #if !defined(__OS2__) | #if !defined(__OS2__) | 
 | snprintf (basecmd, 254, "%s/bin/freem", PREFIX); | snprintf (basecmd, 254, "%s/bin/freem", PREFIX); | 
| Line 1186  int fm_start_environment (char *env, cha | Line 1194  int fm_start_environment (char *env, cha | 
 | #endif | #endif | 
 |  |  | 
 | #if !defined(__OS2__) | #if !defined(__OS2__) | 
| 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, 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, env, e_user, e_grp); | 
 | #endif | #endif | 
 |  |  | 
 |  | system (cmd); | 
 |  |  | 
 |  | sleep (1); | 
 |  |  | 
| return (system (cmd)); | return (fm_environment_running (env)); | 
 | } | } | 
 |  |  | 
 | int fm_stop_environment (char *env) | int fm_stop_environment (char *env) | 
 | { | { | 
 | long epid; | long epid; | 
 |  |  | 
| epid = fm_get_pid (cur_env); | epid = fm_get_pid (env); | 
 | if (epid > -1) { | if (epid > -1) { | 
 | fprintf (stderr, "fmadm:  stopping environment daemon pid %d\n", epid); |  | 
 | kill (epid, SIGINT); | kill (epid, SIGINT); | 
| kill (epid, SIGTERM); | 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 { | else { | 
| fprintf (stderr, "fmadm:  could not obtain environment daemon pid\n"); | 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 1289  int fm_daemonctl (short action, short ob | Line 1338  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: | 
 | result = fm_start_environment (cur_env, e_user, e_grp); | result = fm_start_environment (cur_env, e_user, e_grp); | 
 |  | if (result == TRUE) { | 
 |  | fprintf (stderr, "[OK]\n"); | 
 |  | } | 
 |  | else { | 
 |  | fprintf (stderr, "[FAIL]\n"); | 
 |  | } | 
 | break; | break; | 
 |  |  | 
 | case ACT_STOP: | case ACT_STOP: | 
 | result = fm_stop_environment (cur_env); | result = fm_stop_environment (cur_env); | 
 |  | if (result == TRUE) { | 
 |  | fprintf (stderr, "[OK]\n"); | 
 |  | } | 
 |  | else { | 
 |  | fprintf (stderr, "[FAIL]\n"); | 
 |  | } | 
 | break; | break; | 
 |  |  | 
 | case ACT_RESTART: | case ACT_RESTART: | 
| result = fm_stop_environment (cur_env); | if (fm_stop_environment (cur_env) == TRUE) { | 
|  | result = fm_start_environment (cur_env, e_user, e_grp); | 
| fprintf (stderr, "fmadm:  waiting 2 seconds\n"); | if (result == TRUE) { | 
| sleep (2); | fprintf (stderr, "[OK]\n"); | 
| fprintf (stderr, "fmadm:  starting environment %s\n", cur_env); | } | 
|  | else { | 
|  | fprintf (stderr, "[FAIL]\n"); | 
|  | } | 
|  | } | 
|  | else { | 
|  | fprintf (stderr, "[FAIL]\n"); | 
|  | } | 
 |  |  | 
 | result = fm_start_environment (cur_env, e_user, e_grp); |  | 
 | break; | break; | 
 |  |  | 
 | case ACT_STATUS: | case ACT_STATUS: |