#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);
void disp_sh(char **argv, char *msg);
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];
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;
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;
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 */
void usage(void)
{
- fprintf(stderr, "Usage: %s [-noauth]\n", whoami);
+ fprintf(stderr, "Usage: %s [-noauth] [-db|-database server[:port]]\n",
+ whoami);
exit(1);
}