/*
- * The Data Control Manager for SMS.
+ * The Data Control Manager for MOIRA.
*
* Copyright 1987, 1988 by the Massachusetts Institute of Technology.
* For copying and distribution information, see the file
#include <sys/file.h>
#include <sys/time.h>
#include <sys/wait.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <signal.h>
#include <ctype.h>
-#include <sms.h>
-#include <sms_app.h>
+#include <moira.h>
+#include <moira_site.h>
#include "dcm.h"
#include "mit-copyright.h"
+#include <unistd.h>
extern char *ctime();
extern char *getenv();
int i;
char **arg = argv;
char *qargv[3];
+ char *s;
int status;
whoami = argv[0];
- dbg = atoi(getenv("DEBUG"));
+ s = getenv("DEBUG");
+ dbg = s ? atoi(s) : 0;
umask(UMASK);
log_flags = 0;
- setlinebuf(stderr);
- setlinebuf(stdout);
+
+ setvbuf(stderr, NULL, _IOLBF, BUFSIZ);
+ setvbuf(stdout, NULL, _IOLBF, BUFSIZ);
while(++arg - argv < argc) {
if (**arg == '-')
set_com_err_hook(dcm_com_err_hook);
/* if /etc/nodcm exists, punt quietly. */
- if (!access("/etc/nodcm", F_OK)) {
+ if (!access(NODCMFILE, F_OK)) {
exit(1);
}
- if (status = sms_connect()) {
- com_err(whoami, status, " on sms_connect");
+ if (status = mr_connect("")) {
+ com_err(whoami, status, " on mr_connect");
leave("connect failed");
}
- if (status = sms_auth("dcm")) {
+ if (status = mr_auth("dcm")) {
com_err(whoami, status, " on \"authenticate\"");
leave("auth failed");
}
/* if DCM is not enabled, exit after logging */
qargv[0] = "dcm_enable";
- if (status = sms_query("get_value", 1, qargv, gqval, &i)) {
+ if (status = mr_query("get_value", 1, qargv, gqval, &i)) {
com_err(whoami, status, " check dcm_enable");
leave("query failed");
}
}
/* do it! */
- send_zgram("info", "DCM starting up");
do_services();
errno = 0;
leave("");
struct save_queue *sq, *sq_create();
char *service, dfgen_prog[64], dfgen_cmd[128];
struct service svc;
- int status, lock_fd, ex;
+ int status, lock_fd, ex, (*cstat)();
struct timezone tz;
register char *p;
- union wait waits;
+ int waits;
+ struct sigaction action, prevaction;
if (dbg & DBG_VERBOSE)
com_err(whoami, 0, "starting pass over services");
qargv[1] = "dontcare";
qargv[2] = "false";
sq = sq_create();
- if (status = sms_query("qualified_get_server", 3, qargv, qgetsv, sq)) {
+ if (status = mr_query_with_retry("qualified_get_server", 3, qargv,
+ qgetsv, sq)) {
com_err(whoami, status, " getting services");
leave("query failed");
}
*p = tolower(*p);
com_err(whoami, 0, "checking %s...", service);
qargv[0] = service;
- sprintf(dfgen_prog, "%s/bin/%s.gen", SMS_DIR, service);
+ sprintf(dfgen_prog, "%s/%s.gen", BIN_DIR, service);
if (!file_exists(dfgen_prog)) {
com_err(whoami, 0, "prog %s doesn't exist\n", dfgen_prog);
free(service);
continue;
}
- sprintf(dfgen_cmd, "exec %s %s/dcm/%s.out",
- dfgen_prog, SMS_DIR, service);
+ sprintf(dfgen_cmd, "exec %s %s/%s.out",
+ dfgen_prog, DCM_DIR, service);
gettimeofday(&tv, &tz);
- if (status = sms_query("get_server_info", 1, qargv, getsvinfo, &svc)) {
- com_err(whoami, status, " getting service %s info", service);
+ if (status = mr_query_with_retry("get_server_info", 1, qargv,
+ getsvinfo, &svc)) {
+ com_err(whoami, status, " getting service %s info, skipping to next service", service);
+ continue;
}
svc.service = strsave(service);
qargv[0] = strsave(service);
qargv[5] = strsave(svc.errmsg);
if (svc.interval != 0) {
if (svc.interval * 60 + svc.dfcheck < tv.tv_sec) {
- lock_fd = maybe_lock_update(SMS_DIR, "@db@", service, 1);
+ lock_fd = maybe_lock_update("@db@", service, 1);
if (lock_fd < 0)
goto free_service;
free(qargv[3]);
qargv[3] = strsave("1");
qargv[4] = strsave("0");
qargv[5] = strsave("");
- status = sms_query("set_server_internal_flags", 6, qargv,
- scream, NULL);
- if (status != SMS_SUCCESS) {
+ status = mr_query_with_retry("set_server_internal_flags", 6,
+ qargv, scream, NULL);
+ if (status != MR_SUCCESS) {
com_err(whoami, status, " setting server state");
goto free_service;
}
com_err(whoami, status, " running %s", dfgen_prog);
- waits.w_status = system(dfgen_cmd);
- /* extract the process's exit value */
- status = waits.w_retcode;
- if (status) {
- status += sms_err_base;
+
+ action.sa_flags = 0;
+ sigemptyset(&action.sa_mask);
+ action.sa_handler = SIG_DFL;
+ sigaction(SIGCHLD, &action, &prevaction);
+ waits = system(dfgen_cmd);
+ sigaction(SIGCHLD, &prevaction, NULL);
+ if (WIFSIGNALED(waits)) {
+ status = MR_COREDUMP;
+ com_err(whoami, status, " %s exited on signal %d",
+ dfgen_prog, WTERMSIG(waits));
+ } else if (WEXITSTATUS(waits)) {
+ /* extract the process's exit value */
+ status = WEXITSTATUS(waits) + ERROR_TABLE_BASE_sms;
com_err(whoami, status, " %s exited", dfgen_prog);
}
+
if (SOFT_FAIL(status)) {
free(qargv[5]);
qargv[5] = strsave(error_message(status));
- } else if (status == SMS_NO_CHANGE) {
+ } else if (status == MR_NO_CHANGE) {
free(qargv[2]);
qargv[2] = itoa(tv.tv_sec);
svc.dfcheck = tv.tv_sec;
- } else if (status == SMS_SUCCESS) {
+ } else if (status == MR_SUCCESS) {
free(qargv[1]);
free(qargv[2]);
qargv[1] = itoa(tv.tv_sec);
free_service:
free(qargv[3]);
qargv[3] = strsave("0");
- status = sms_query("set_server_internal_flags", 6, qargv,
- scream, NULL);
+ status = mr_query_with_retry("set_server_internal_flags", 6,
+ qargv, scream, NULL);
+ if (status)
+ com_err(whoami, status, " setting service state");
close(lock_fd);
free(qargv[0]);
free(qargv[1]);
ex = 1;
else
ex = 0;
- lock_fd = maybe_lock_update(SMS_DIR, "@db@", service, ex);
+ lock_fd = maybe_lock_update("@db@", service, ex);
if (lock_fd >= 0) {
do_hosts(&svc);
close(lock_fd);
argv[1] = "TRUE";
argv[2] = argv[3] = argv[4] = "DONTCARE";
argv[5] = "FALSE";
- status = sms_query("qualified_get_server_host", 6, argv, qgethost, sq);
- if (status == SMS_NO_MATCH) {
+ status = mr_query_with_retry("qualified_get_server_host", 6, argv,
+ qgethost, sq);
+ if (status == MR_NO_MATCH) {
return;
} else if (status) {
com_err(whoami, status, " getting server_hosts for %s", svc->service);
if (dbg & DBG_TRACE)
com_err(whoami, 0, "checking %s...", machine);
argv[1] = machine;
- status = sms_query("get_server_host_info", 2, argv,gethostinfo, &shost);
+ status = mr_query_with_retry("get_server_host_info", 2, argv,
+ gethostinfo, &shost);
if (status) {
com_err(whoami,status, " getting server_host_info for %s", machine);
goto free_mach;
}
if (!shost.enable || shost.hosterror ||
- (shost.success && shost.lastsuccess > svc->dfgen)) {
+ (shost.success && !shost.override &&
+ shost.lastsuccess >= svc->dfgen)) {
if (dbg & DBG_TRACE)
com_err(whoami, 0, "not updating %s:%s", svc->service, machine);
goto free_mach;
}
- if (!shost.success || shost.override ||
- shost.lasttry + svc->interval < tv.tv_sec) {
- lock_fd = maybe_lock_update(SMS_DIR, machine, svc->service, 1);
- if (lock_fd < 0)
- goto free_mach;
- argv[0] = svc->service;
- argv[1] = machine;
- argv[2] = argv[3] = argv[5] = "0";
- argv[4] = "1";
- argv[6] = strsave("");
- argv[7] = itoa(tv.tv_sec);
- argv[8] = itoa(shost.lastsuccess);
- status = sms_query("set_server_host_internal", 9, argv,scream,NULL);
- if (status != SMS_SUCCESS) {
- com_err(whoami,status," while setting internal state for %s:%s",
- svc->service, machine);
- goto free_mach;
- }
- status = sms_update_server(svc->service, machine, svc->target,
- svc->script);
- if (status == SMS_SUCCESS) {
- argv[2] = "0";
- argv[3] = "1";
- free(argv[8]);
- argv[8] = itoa(tv.tv_sec);
- } else if (SOFT_FAIL(status)) {
- free(argv[6]);
- argv[6] = strsave(error_message(status));
- } else { /* HARD_FAIL */
- argv[2] = itoa(shost.override);
- argv[5] = itoa(status);
- free(argv[6]);
- argv[6] = strsave(error_message(status));
- critical_alert("DCM", "DCM updating %s:%s: %s",
- machine, svc->service, argv[6]);
- if (!strcmp(svc->type, "REPLICAT")) {
- char *qargv[6];
-
- svc->harderror = status;
- svc->errmsg = strsave(argv[6]);
- qargv[0] = strsave(svc->service);
- qargv[1] = itoa(svc->dfgen);
- qargv[2] = itoa(svc->dfcheck);
- qargv[3] = strsave("0");
- qargv[4] = itoa(svc->harderror);
- qargv[5] = strsave(svc->errmsg);
- status = sms_query("set_server_internal_flags",
- 6, qargv, scream, NULL);
- free(qargv[0]);
- free(qargv[1]);
- free(qargv[2]);
- free(qargv[3]);
- free(qargv[4]);
- free(qargv[5]);
- close(lock_fd);
- free(argv[2]);
- argv[4] = "0";
- free(argv[5]);
- status = sms_query("set_server_host_internal",
- 9, argv,scream,NULL);
- return(-1);
- }
+
+ lock_fd = maybe_lock_update(machine, svc->service, 1);
+ if (lock_fd < 0)
+ goto free_mach;
+ argv[0] = svc->service;
+ argv[1] = machine;
+ argv[2] = argv[3] = argv[5] = "0";
+ argv[4] = "1";
+ argv[6] = strsave("");
+ argv[7] = itoa(tv.tv_sec);
+ argv[8] = itoa(shost.lastsuccess);
+ status = mr_query_with_retry("set_server_host_internal", 9, argv,
+ scream, NULL);
+ if (status != MR_SUCCESS) {
+ com_err(whoami,status," while setting internal state for %s:%s",
+ svc->service, machine);
+ goto free_mach;
+ }
+ status = mr_update_server(svc->service, machine, svc->target,
+ svc->script);
+ if (status == MR_SUCCESS) {
+ argv[2] = argv[4] = "0";
+ argv[3] = "1";
+ free(argv[8]);
+ argv[8] = itoa(tv.tv_sec);
+ } else if (SOFT_FAIL(status)) {
+ argv[4] = "0";
+ free(argv[6]);
+ argv[6] = strsave(error_message(status));
+ } else { /* HARD_FAIL */
+ argv[2] = itoa(shost.override);
+ argv[4] = "0";
+ argv[5] = itoa(status);
+ free(argv[6]);
+ argv[6] = strsave(error_message(status));
+ critical_alert("DCM", "DCM updating %s:%s: %s",
+ machine, svc->service, argv[6]);
+ if (!strcmp(svc->type, "REPLICAT")) {
+ char *qargv[6];
+
+ svc->harderror = status;
+ svc->errmsg = strsave(argv[6]);
+ qargv[0] = strsave(svc->service);
+ qargv[1] = itoa(svc->dfgen);
+ qargv[2] = itoa(svc->dfcheck);
+ qargv[3] = strsave("0");
+ qargv[4] = itoa(svc->harderror);
+ qargv[5] = strsave(svc->errmsg);
+ status = mr_query_with_retry("set_server_internal_flags",
+ 6, qargv, scream, NULL);
+ if (status)
+ com_err(whoami, status, " setting service state again");
+ free(qargv[0]);
+ free(qargv[1]);
+ free(qargv[2]);
+ free(qargv[3]);
+ free(qargv[4]);
+ free(qargv[5]);
+ close(lock_fd);
+ status = mr_query_with_retry("set_server_host_internal",
+ 9, argv,scream,NULL);
free(argv[2]);
free(argv[5]);
+ if (status)
+ com_err(whoami, status, " setting host state again");
+ return(-1);
}
- argv[4] = "0";
- close(lock_fd);
- status = sms_query("set_server_host_internal", 9, argv,scream,NULL);
- } else {
- if (dbg & DBG_TRACE)
- com_err(whoami, 0, "not updating %s", machine);
}
+ close(lock_fd);
+ status = mr_query_with_retry("set_server_host_internal", 9, argv,
+ scream, NULL);
+ if (status)
+ com_err(whoami, status, " setting host state again");
+/* free(argv[2]);
+ free(argv[5]); */
free_mach:
free(machine);
close(lock_fd);
}
return(0);
}
-