Commit 5620bd57 authored by John P. Willis's avatar John P. Willis
Browse files

Work on building fmadm into interactive tool

parent 32db7030
Pipeline #726 passed with stage
in 1 minute and 24 seconds
......@@ -45,12 +45,45 @@
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include "config.h"
#if !defined(DISABLE_READLINE)
#ifdef HAVE_LIBREADLINE
# if defined(HAVE_READLINE_READLINE_H)
# include <readline/readline.h>
# elif defined(HAVE_READLINE_H)
# include <readline.h>
# else /* !defined(HAVE_READLINE_H) */
extern char *readline ();
# endif /* !defined(HAVE_READLINE_H) */
/*char *cmdline = NULL;*/
#else /* !defined(HAVE_READLINE_READLINE_H) */
/* no readline */
#endif /* HAVE_LIBREADLINE */
#ifdef HAVE_READLINE_HISTORY
# if defined(HAVE_READLINE_HISTORY_H)
# include <readline/history.h>
# elif defined(HAVE_HISTORY_H)
# include <history.h>
# else /* !defined(HAVE_HISTORY_H) */
extern void add_history ();
extern int write_history ();
extern int read_history ();
# endif /* defined(HAVE_READLINE_HISTORY_H) */
/* no history */
#endif /* HAVE_READLINE_HISTORY */
#endif /* DISABLE_READLINE */
#include "fmadm.h"
#include "errmsg.h"
#include "iniconf.h"
#include "init.h"
#include "version.h"
#include "shmmgr.h"
#include "jobtab.h"
#include "locktab.h"
/* namespace configuration */
char fma_namespace[STRLEN];
......@@ -68,6 +101,7 @@ char obj_str[STRLEN];
extern char config_file[4096];
int fm_shell(void);
void fm_checkperms(void);
void fm_reconfigure(void);
void fm_configure(void);
......@@ -87,6 +121,13 @@ int main (int argc, char **argv)
int j = 1;
snprintf (config_file, 4096, "%s/freem.conf", SYSCONFDIR);
pid = getpid ();
shm_init (1048576);
tp_init ();
jobtab_init ();
job_init (TRUE);
/* override for fmadm configure */
if (argc > 1 && strcmp (argv[1], "configure") == 0) {
......@@ -103,6 +144,9 @@ int main (int argc, char **argv)
fm_checkperms ();
exit (0);
}
/* go to fmadm shell if no arguments passed */
if (argc == 1) return fm_shell();
/* need at least command, action, object, namespace */
if (argc < 4) return fmadm_usage();
......@@ -226,6 +270,148 @@ int main (int argc, char **argv)
} /* main() */
int fm_shell (void)
{
#if defined(HAVE_LIBREADLINE) && !defined(_AIX) && !defined(DISABLE_READLINE)
char *fmarl_buf;
char *fma_prompt = "fmadm> ";
char *cmdt = (char *) malloc (65535 * sizeof (char));
int cmd;
int i;
for (;;) {
fmarl_buf = readline (fma_prompt);
if (fmarl_buf == (char *) NULL) continue;
cmdt = strtok (fmarl_buf, " ");
for (i = 0; i < strlen (cmdt); i++) cmdt[i] = cmdt[i] | 0140;
if (strcmp (cmdt, "exit") == 0) cmd = FMAC_EXIT;
else if (strcmp (cmdt, "quit") == 0) cmd = FMAC_EXIT;
else if (strcmp (cmdt, "select") == 0) cmd = FMAC_SELECT;
else if (strcmp (cmdt, "list") == 0) cmd = FMAC_LIST;
else if (strcmp (cmdt, "examine") == 0) cmd = FMAC_EXAMINE;
else if (strcmp (cmdt, "verify") == 0) cmd = FMAC_VERIFY;
else if (strcmp (cmdt, "compact") == 0) cmd = FMAC_COMPACT;
else if (strcmp (cmdt, "repair") == 0) cmd = FMAC_REPAIR;
else if (strcmp (cmdt, "create") == 0) cmd = FMAC_CREATE;
else if (strcmp (cmdt, "import") == 0) cmd = FMAC_IMPORT;
else if (strcmp (cmdt, "export") == 0) cmd = FMAC_EXPORT;
else if (strcmp (cmdt, "backup") == 0) cmd = FMAC_BACKUP;
else if (strcmp (cmdt, "restore") == 0) cmd = FMAC_RESTORE;
else if (strcmp (cmdt, "migrate") == 0) cmd = FMAC_MIGRATE;
else if (strcmp (cmdt, "edit") == 0) cmd = FMAC_EDIT;
else if (strcmp (cmdt, "set") == 0) cmd = FMAC_SET;
else cmd = FMAC_INVALID;
switch (cmd) {
case FMAC_SELECT:
printf ("select\n");
break;
case FMAC_LIST:
printf ("list\n");
break;
case FMAC_EXAMINE:
printf ("examine\n");
break;
case FMAC_VERIFY:
printf ("verify\n");
break;
case FMAC_COMPACT:
printf ("compact\n");
break;
case FMAC_REPAIR:
printf ("repair\n");
break;
case FMAC_CREATE:
printf ("create\n");
break;
case FMAC_REMOVE:
printf ("remove\n");
break;
case FMAC_IMPORT:
printf ("import\n");
break;
case FMAC_EXPORT:
printf ("export\n");
break;
case FMAC_BACKUP:
printf ("backup\n");
break;
case FMAC_RESTORE:
printf ("restore\n");
break;
case FMAC_MIGRATE:
printf ("migrate\n");
break;
case FMAC_EDIT:
printf ("edit\n");
break;
case FMAC_SET:
printf ("set\n");
break;
case FMAC_EXIT:
fmadm_exit ();
break;
default:
printf ("fmadm: '%s' is not a valid fmadm command\n", cmdt);
break;
}
}
#endif
}
void fmadm_exit (void)
{
locktab_unlock_all ();
job_remove (pid);
shm_exit ();
exit (0);
}
int fmadm_usage (void)
{
......@@ -244,6 +430,8 @@ int fmadm_usage (void)
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");
fmadm_exit ();
return 1;
} /* fmadm_usage() */
......
......@@ -50,6 +50,24 @@
#define FMA_MAXARGS 30
#define FMAC_SELECT 0
#define FMAC_LIST 1
#define FMAC_EXAMINE 2
#define FMAC_VERIFY 3
#define FMAC_COMPACT 4
#define FMAC_REPAIR 5
#define FMAC_CREATE 6
#define FMAC_REMOVE 7
#define FMAC_IMPORT 8
#define FMAC_EXPORT 9
#define FMAC_BACKUP 10
#define FMAC_RESTORE 11
#define FMAC_MIGRATE 12
#define FMAC_EDIT 13
#define FMAC_SET 14
#define FMAC_EXIT 100
#define FMAC_INVALID 255
#define ACT_LIST 0
#define ACT_EXAMINE 1
#define ACT_VERIFY 2
......@@ -81,6 +99,7 @@
#endif
int fmadm_usage (void);
void fmadm_exit (void);
int fm_list (short object, int optc, char **options);
int fm_examine (short object, int optc, char **options);
int fm_verify (short object, int optc, char **options);
......@@ -107,4 +126,6 @@ extern char fma_journal_cut_threshold[STRLEN];
extern char gloplib[PATHLEN];
extern char glopath[PATHLEN];
extern pid_t pid;
#endif
......@@ -167,7 +167,7 @@ short init (char *namespace_name)
jobtab_init ();
if (first_process) fprintf (stderr, "init: adding job to job table\r\n");
job_init ();
job_init (FALSE);
if (first_process) fprintf (stderr, "init: initializing structured system variables\r\n");
init_ssvn ();
......
......@@ -113,7 +113,7 @@ void jobtab_release_sem(void)
}
job_slot_t *job_init(void)
job_slot_t *job_init(short is_fmadm)
{
job_slot_t *s;
......@@ -147,7 +147,12 @@ skip_alloc:
s->flags = JFLG_DAEMON | JFLG_NEW;
}
else {
s->flags = JFLG_NEW;
if (is_fmadm == TRUE) {
s->flags = JFLG_NEW | JFLG_FMADM;
}
else {
s->flags = JFLG_NEW;
}
}
s->next = shm_config->hdr->jobtab_head;
......@@ -366,8 +371,14 @@ void job_gc_mark(void)
s->flags = JFLG_ALIVE | JFLG_DAEMON;
}
else {
fprintf (stderr, "job_gc_mark: registering new process %d\r\n", s->pid);
s->flags = JFLG_ALIVE;
if ((s->flags & JFLG_FMADM) == JFLG_FMADM) {
fprintf (stderr, "job_gc_mark: registering new fmadm process %d\r\n", s->pid);
s->flags = JFLG_ALIVE | JFLG_FMADM;
}
else {
fprintf (stderr, "job_gc_mark: registering new interpreter process %d\r\n", s->pid);
s->flags = JFLG_ALIVE;
}
}
}
......@@ -492,13 +503,13 @@ void job_dump(void)
flag_s[0] = '\0';
stat_s[0] = '\0';
if ((s->flags & JFLG_DAEMON) == JFLG_DAEMON) strcat (flag_s, "DAEMON ");
if ((s->flags & JFLG_NEW) == JFLG_NEW) strcat (flag_s, "NEW");
if ((s->flags & JFLG_ALIVE) == JFLG_ALIVE) strcat (flag_s, "ALIVE ");
if ((s->flags & JFLG_DEFUNCT) == JFLG_DEFUNCT) strcat (flag_s, "DEFUNCT ");
if ((s->flags & JFLG_REPLSENDER) == JFLG_REPLSENDER) strcat (flag_s, "REPLSENDER ");
if ((s->flags & JFLG_REPLRECEIVER) == JFLG_REPLRECEIVER) strcat (flag_s, "REPLRECEIVER ");
if ((s->flags & JFLG_FMADM) == JFLG_FMADM) strcat (flag_s, "FMADM");
if ((s->flags & JFLG_NEW) == JFLG_NEW) strcat (flag_s, "NEW ");
if ((s->flags & JFLG_DAEMON) == JFLG_DAEMON) strcat (flag_s, "DAEMON ");
if (s->status == JSTAT_IDLE) strcat (stat_s, "IDLE");
if (s->status == JSTAT_INTERPRETER) strcat (stat_s, "INTERPRETER");
......
......@@ -103,7 +103,7 @@ typedef struct job_slot_t {
extern short jobtab_get_sem(void);
extern void jobtab_release_sem(void);
extern void jobtab_init(void);
extern job_slot_t *job_init(void);
extern job_slot_t *job_init(short is_fmadm);
extern void job_remove(const pid_t pid);
extern void job_request_stop(const pid_t target_pid);
extern void job_set_ecode(const pid_t target_pid, const char *ecode);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment