]> andersk Git - moira.git/blobdiff - clients/mrcheck/mrcheck.c
Make mrcl_connect authenticate for us rather than doing it seperately.
[moira.git] / clients / mrcheck / mrcheck.c
index b5afaf63d993a28e42c83988852c132820961430..6dfb9ccb675754f4c31f0ba33838ef8d31ece292 100644 (file)
 #include <mit-copyright.h>
 #include <moira.h>
 #include <moira_site.h>
-
-#include <sys/time.h>
+#include <mrclient.h>
 
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <time.h>
 
+#define argis(a, b) (!strcmp(*arg + 1, a) || !strcmp(*arg + 1, b))
+
 RCSID("$Header$");
 
 char *atot(char *itime);
@@ -25,11 +26,11 @@ int process_server(int argc, char **argv, void *sqv);
 void disp_svc(char **argv, char *msg);
 int process_host(int argc, char **argv, void *sqv);
 void disp_sh(char **argv, char *msg);
-int usage(void);
+void usage(void);
 
+char *whoami;
 static int count = 0;
-static char *whoami;
-static struct timeval now;
+static time_t now;
 
 struct service {
   char name[17];
@@ -77,7 +78,7 @@ int process_server(int argc, char **argv, void *sqv)
     disp_svc(argv, "Should this be enabled?\n");
   else if (atoi(argv[SVC_ENABLE]) &&
           60 * atoi(argv[SVC_INTERVAL]) + 86400 + atoi(argv[SVC_DFCHECK])
-          < now.tv_sec)
+          < now)
     disp_svc(argv, "Service has not been updated\n");
 
   return MR_CONT;
@@ -129,7 +130,7 @@ int process_host(int argc, char **argv, void *sqv)
     disp_sh(argv, "Should this be enabled?\n");
   else if (atoi(argv[SH_ENABLE]) && update_int &&
           60 * atoi(update_int) + 86400 + atoi(argv[SH_LASTSUCCESS])
-          < now.tv_sec)
+          < now)
     disp_sh(argv, "Host has not been updated\n");
 
   return MR_CONT;
@@ -162,49 +163,44 @@ void disp_sh(char **argv, char *msg)
 
 int main(int argc, char *argv[])
 {
-  char *args[2], buf[BUFSIZ], *motd;
+  char *args[2], buf[BUFSIZ];
   struct save_queue *sq;
   int status;
   int auth_required = 1;
+  char **arg = argv;
+  char *server = NULL;
 
   if ((whoami = strrchr(argv[0], '/')) == NULL)
     whoami = argv[0];
   else
     whoami++;
 
-  if (argc == 2 && !strcmp(argv[1], "-noauth"))
-    auth_required = 0;
-  else if (argc > 1)
-    usage();
-
-  status = mr_connect(NULL);
-  if (status)
+  /* parse our command line options */
+  while (++arg - argv < argc)
     {
-      sprintf(buf, "\nConnection to the Moira server failed.");
-      goto punt;
+      if (**arg == '-')
+       {
+         if (argis("n", "noauth"))
+           auth_required = 0;
+         else if (argis("db", "database"))
+           {
+             if (arg - argv < argc - 1)
+               {
+                 ++arg;
+                 server = *arg;
+               }
+             else
+               usage();
+           }
+       }
+      else
+       usage();
     }
 
-  status = mr_motd(&motd);
-  if (status)
-    {
-      com_err(whoami, status, " unable to check server status");
-      exit(2);
-    }
-  if (motd)
-    {
-      fprintf(stderr, "The Moira server is currently unavailable:\n%s\n",
-             motd);
-      mr_disconnect();
-      exit(2);
-    }
-  status = mr_auth("mrcheck");
-  if (status && auth_required)
-    {
-      sprintf(buf, "\nAuthorization failure -- run \"kinit\" and try again");
-      goto punt;
-    }
+  if (mrcl_connect(server, "mrcheck", 2, auth_required) != MRCL_SUCCESS)
+    exit(2);
 
-  gettimeofday(&now, 0);
+  now = time(NULL);
   sq = sq_create();
 
   /* Check services first */
@@ -233,8 +229,9 @@ punt:
   exit(1);
 }
 
-int usage(void)
+void usage(void)
 {
-  fprintf(stderr, "Usage: %s [-noauth]\n", whoami);
+  fprintf(stderr, "Usage: %s [-noauth] [-db|-database server[:port]]\n",
+         whoami);
   exit(1);
 }
This page took 0.040188 seconds and 4 git commands to generate.