]> andersk Git - moira.git/blobdiff - clients/moira/main.c
second code style cleanup: void/void * usage, proper #includes. try to
[moira.git] / clients / moira / main.c
index f970811c095c3130351b99e7343f02f3f35e859a..3507931fd9ae6981ed3aed127e09255d6a3621ac 100644 (file)
-#ifndef lint
-  static char rcsid_module_c[] = "$Header$";
-#endif lint
-
-/*     This is the file main.c for allmaint, the SMS client that allows
- *      a user to maintaint most important parts of the SMS database.
- *     It Contains:  The main driver for this program.
- *     
+/* $Id $
+ *
+ *     This is the file main.c for the Moira Client, which allows users
+ *      to quickly and easily maintain most parts of the Moira database.
+ *     It Contains: The main driver for the Moira Client.
+ *
  *     Created:        4/12/88
  *     By:             Chris D. Peterson
  *
- *      $Source$
- *      $Author$
- *      $Header$
- *     
- *     Copyright 1987, 1988 by the Massachusetts Institute of Technology.
- *
- *     For further information on copyright and distribution 
- *     see the file mit-copyright.h
+ * Copyright (C) 1988-1998 by the Massachusetts Institute of Technology.
+ * For copying and distribution information, please see the file
+ * <mit-copyright.h>.
  */
 
+#include <mit-copyright.h>
+#include <moira.h>
+#include "defs.h"
+#include "f_defs.h"
+#include "globals.h"
+
 #include <pwd.h>
 #include <signal.h>
 #include <stdio.h>
-#include <strings.h>
-#include <sms.h>
-#include <menu.h>
+#include <string.h>
+#include <unistd.h>
 
-#include "mit-copyright.h"
-#include "allmaint.h"
-#include "globals.h"
+RCSID("$Header$");
+
+static void ErrorExit(char *buf, int status);
+static void Usage(void);
+static void Signal_Handler(void);
+static void CatchInterrupt(void);
 
-static void init_listmaint(), error_exit(), usage();
-void Put_message();
-char *getlogin();
-uid_t getuid();
-struct passwd *getpwuid();
+char *whoami;                  /* used by menu.c ugh!!! */
+char *moira_server;
+int interrupt = 0;
+
+extern Menu moira_top_menu, list_menu, user_menu, dcm_menu;
 
 Bool use_menu = TRUE;          /* whether or not we are using a menu. */
 
 /*     Function Name: main
- *     Description: The main driver for allmaint.
+ *     Description: The main driver for the Moira Client.
  *     Arguments: argc, argv - standard command line args.
  *     Returns: doesn't return.
  */
 
-void
-main(argc, argv)
-    int argc;
-    char ** argv;
+void main(int argc, char **argv)
 {
-    char buf[BUFSIZ];
-
-    if ((user = getlogin()) == NULL) 
-       user = getpwuid((int) getuid())->pw_name;
-    user = (user && strlen(user)) ? Strsave(user) : "";
+  int status;
+  Menu *menu;
+  char *motd, **arg;
+  struct sigaction act;
+
+  if (!(user = getlogin()))
+    user = getpwuid(getuid())->pw_name;
+  user = (user && strlen(user)) ? strdup(user) : "";
+
+  if (!(program_name = strrchr(argv[0], '/')))
+    program_name = argv[0];
+  else
+    program_name++;
+  program_name = strdup(program_name);
+  whoami = strdup(program_name); /* used by menu.c,  ugh !!! */
+
+  verbose = TRUE;
+  arg = argv;
+  moira_server = NULL;
+
+  while (++arg - argv < argc)
+    {
+      if (**arg == '-')
+       {
+         if (!strcmp(*arg, "-nomenu"))
+           use_menu = FALSE;
+         else if (!strcmp(*arg, "-menu"))
+           use_menu = TRUE;
+         else if (!strcmp(*arg, "-db"))
+           {
+             if (arg - argv < argc - 1)
+               {
+                 ++arg;
+                 moira_server = *arg;
+               } else
+                 Usage();
+           }
+         else
+           Usage();
+       }
+    }
 
-    init_sms_err_tbl();
-    init_krb_err_tbl();
+  if ((status = mr_connect(moira_server)))
+    ErrorExit("\nConnection to Moira server failed", status);
+
+  if ((status = mr_motd(&motd)))
+    ErrorExit("\nUnable to check server status", status);
+  if (motd)
+    {
+      fprintf(stderr, "The Moira server is currently unavailable:\n%s\n",
+             motd);
+      mr_disconnect();
+      exit(1);
+    }
 
-    switch (argc) {
-    case 2:
-      if (strcmp(argv[1], "-nomenu") == 0)
-       use_menu = FALSE;
-      else
-       usage();
-                               /* Fall Through. */
-    case 1:
-      if ((program_name = rindex(argv[0], '/')) == NULL)
-       program_name = argv[0];
+  if ((status = mr_auth(program_name)))
+    {
+      if (status == MR_USER_AUTH)
+       {
+         char buf[BUFSIZ];
+         com_err(program_name, status, "\nPress [RETURN] to continue");
+         fgets(buf, BUFSIZ, stdin);
+       }
       else
-       program_name++;
-      break;
-    default:
-      usage();
-      break;
+       {
+         if (status >= ERROR_TABLE_BASE_krb &&
+             status <= ERROR_TABLE_BASE_krb + 256)
+           ErrorExit("\nAuthorization failed -- please run kinit", status);
+         else
+           ErrorExit("\nAuthorization failed.", status);
+       }
     }
-    
-    if ( status = sms_connect() ) 
-       error_exit("\nConnection to SMS server failed", status);
 
-    if ( status = sms_auth(argv[0]) ) 
-       error_exit("\nAuthorization failed -- please run kinit", status);
+  /*
+   * These signals should not be set until just before we fire up the menu
+   * system.
+   */
+
+  sigemptyset(&act.sa_mask);
+  act.sa_flags = 0;
+  act.sa_handler = Signal_Handler;
+  sigaction(SIGHUP, &act, NULL);
+  sigaction(SIGQUIT, &act, NULL);
+  if (use_menu)
+    sigaction(SIGINT, &act, NULL);
+  else
+    {
+      act.sa_handler = CatchInterrupt;
+      sigaction(SIGINT, &act, NULL);
+    }
 
-/*
- * These signals should not be set until just before we fire up the menu
- * system. 
- */
-    (void) signal(SIGHUP, signal_handler);
-    (void) signal(SIGINT, signal_handler);
-    (void) signal(SIGQUIT, signal_handler);
-
-    if (use_menu) {            /* Start menus that execute program */
-        Start_paging();
-       Start_menu(&allmaint_top_menu);
-       Stop_paging();
+  initialize_gdss_error_table();
+
+  if (!strcmp(program_name, "listmaint"))
+    menu = &list_menu;
+  else if (!strcmp(program_name, "usermaint"))
+    menu = &user_menu;
+  else if (!strcmp(program_name, "dcmmaint"))
+    menu = &dcm_menu;
+  else
+    menu = &moira_top_menu;
+
+  if (use_menu)                /* Start menus that execute program */
+    {
+      Start_paging();
+      Start_menu(menu);
+      Stop_paging();
     }
-    else                       /* Start program without menus. */
-       Start_no_menu(&allmaint_top_menu);
+  else                 /* Start program without menus. */
+    Start_no_menu(menu);
 
-    sms_disconnect();
-    exit(0);
+  mr_disconnect();
+  exit(0);
 }
 
-/*     Function Name: error_exit
+/*     Function Name: ErrorExit
  *     Description: This function does the error handling and exits.
  *     Arguments: buf - the error message to print.
  *                 status - the error code.
  *     Returns: doesn't return.
  */
 
-static void
-error_exit(buf,status);
-int status;
-char * whoami, *buf;    
+static void ErrorExit(char *buf, int status)
 {
-    com_err(program_name, status, buf);
-    sms_disconnect();
-    exit(1);
+  com_err(program_name, status, buf);
+  mr_disconnect();
+  exit(1);
 }
 
 /*     Function Name: usage
@@ -125,25 +182,31 @@ char * whoami, *buf;
  *     Returns: doesn't return.
  */
 
-static void
-usage()
+static void Usage(void)
 {
-    fprintf(stderr, "Usage: %s [-nomenu]\n", program_name);
-    exit(1);
+  fprintf(stderr, "Usage: %s [-nomenu | -menu] [-db server[:port]]\n",
+         program_name);
+  exit(1);
 }
 
-/*     Function Name: signal_handler
+/*     Function Name: Signal_Handler
  *     Description: This function cleans up from a signal interrupt.
  *     Arguments: none.
  *     Returns: doesn't
  */
 
-static int *
-signal_handler()
+static void Signal_Handler(void)
+{
+  Put_message("Signal caught - exiting");
+  if (use_menu)
+    Cleanup_menu();
+  mr_disconnect();
+  exit(1);
+}
+
+
+static void CatchInterrupt(void)
 {
-    Put_message("Signal caught - exiting");
-    if (use_menu)
-      Cleanup_menu();
-    sms_disconnect();
-    exit(1);
+  Put_message("Interrupt! Press RETURN to continue");
+  interrupt = 1;
 }
This page took 0.047395 seconds and 4 git commands to generate.