00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include <SUM.h>
00012 #include <sys/socket.h>
00013 #include <sys/errno.h>
00014 #include <signal.h>
00015 #include <rpc/rpc.h>
00016 #include <sum_rpc.h>
00017 #include <soi_error.h>
00018 #if defined(SUMS_TAPE_AVAILABLE) && SUMS_TAPE_AVAILABLE
00019 #include <tape.h>
00020 #endif
00021 #include <printk.h>
00022
00023 void logkey();
00024 extern int errno;
00025 static struct timeval TIMEOUT = { 120, 0 };
00026
00027 FILE *logfp;
00028 CLIENT *current_client, *clnttape;
00029 char *dbname;
00030 char thishost[MAX_STR];
00031 char datestr[32];
00032 int soi_errno = NO_ERROR;
00033
00034
00035 void open_log(char *filename)
00036 {
00037 if((logfp=fopen(filename, "w")) == NULL) {
00038 fprintf(stderr, "Can't open the log file %s\n", filename);
00039 }
00040 }
00041
00042
00043
00044 static char *datestring()
00045 {
00046 struct timeval tvalr;
00047 struct tm *t_ptr;
00048
00049 gettimeofday(&tvalr, NULL);
00050 t_ptr = localtime((const time_t *)&tvalr);
00051 sprintf(datestr, "%s", asctime(t_ptr));
00052 datestr[19] = (char)NULL;
00053 return(&datestr[4]);
00054 }
00055
00056
00057
00058
00059 int write_log(const char *fmt, ...)
00060 {
00061 va_list args;
00062 char string[4096];
00063
00064 va_start(args, fmt);
00065 vsprintf(string, fmt, args);
00066 if(logfp) {
00067 fprintf(logfp, string);
00068 fflush(logfp);
00069 }
00070 else
00071 fprintf(stderr, string);
00072 va_end(args);
00073 return(0);
00074 }
00075
00076
00077 void sighandler(sig)
00078 int sig;
00079 {
00080 if(sig == SIGTERM) {
00081 write_log("*** %s impexp got SIGTERM. Exiting.\n", datestring());
00082 exit(1);
00083 }
00084 if(sig == SIGINT) {
00085 write_log("*** %s impexp got SIGINT. Exiting.\n", datestring());
00086 exit(1);
00087 }
00088 write_log("*** %s impexp got an illegal signal %d, ignoring...\n",
00089 datestring(), sig);
00090 if (signal(SIGINT, SIG_IGN) != SIG_IGN)
00091 signal(SIGINT, sighandler);
00092 if (signal(SIGALRM, SIG_IGN) != SIG_IGN)
00093 signal(SIGALRM, sighandler);
00094 }
00095
00096
00097 void setup()
00098 {
00099 int pid;
00100 char *cptr;
00101 char logname[MAX_STR];
00102
00103
00104
00105
00106 sprintf(thishost, "localhost");
00107 pid = getpid();
00108 sprintf(logname, "/usr/local/logs/SUM/impexp_%d.log", pid);
00109 open_log(logname);
00110 printk_set(write_log, write_log);
00111 write_log("\n## %s impexp on %s for pid = %d ##\n",
00112 datestring(), thishost, pid);
00113
00114
00115 if (signal(SIGINT, SIG_IGN) != SIG_IGN)
00116 signal(SIGINT, sighandler);
00117 if (signal(SIGTERM, SIG_IGN) != SIG_IGN)
00118 signal(SIGTERM, sighandler);
00119 if (signal(SIGALRM, SIG_IGN) != SIG_IGN)
00120 signal(SIGALRM, sighandler);
00121 }
00122
00123
00124 int main(int argc, char *argv[])
00125 {
00126 KEY *retlist;
00127 uint32_t tapeback;
00128 enum clnt_stat status;
00129 int i;
00130 char *call_err;
00131 char ext[64];
00132
00133 setup();
00134
00135 clnttape = clnt_create(thishost, TAPEPROG, TAPEVERS, "tcp");
00136 if(!clnttape) {
00137 clnt_pcreateerror("Can't get client handle to tape_svc");
00138 write_log("tape_svc not there on %s\n", thishost);
00139 exit(1);
00140 }
00141 retlist = newkeylist();
00142 if(!strcmp(argv[1], "stop")) {
00143 setkey_str(&retlist, "OP", "stop");
00144 }
00145 else if(!strcmp(argv[1], "clean")) {
00146 setkey_str(&retlist, "OP", "clean_start");
00147 setkey_str(&retlist, "cleanslot", argv[2]);
00148 setkey_str(&retlist, "cleandrive", argv[3]);
00149 write_log("In impexp: cleanslot=%s cleandrive=%s\n", argv[2], argv[3]);
00150 }
00151 else {
00152 argc = argc - 2;
00153 setkey_int(&retlist, "reqcnt", argc);
00154 setkey_str(&retlist, "OP", "start");
00155 for(i=0; i < argc; i++) {
00156 sprintf(ext, "tapeid_%d", i);
00157 setkey_str(&retlist, ext, argv[i+2]);
00158 write_log("In impexp: %s = %s\n", ext, argv[i+2]);
00159 }
00160 }
00161 status = clnt_call(clnttape, IMPEXPDO, (xdrproc_t)xdr_Rkey, (char *)retlist,
00162 (xdrproc_t)xdr_uint32_t, (char *)&tapeback, TIMEOUT);
00163 write_log("impexp: tapeback=%ld, status=%d\n", tapeback, status);
00164 if(status != RPC_SUCCESS) {
00165 call_err = clnt_sperror(clnttape, "Err clnt_call for IMPEXPDO");
00166 write_log("%s %s\n", datestring(), call_err);
00167 }
00168 if(tapeback == 1) {
00169 write_log("**Error in IMPEXPDO call to tape_svc in impexp\n");
00170 }
00171 if(!strcmp(argv[1], "clean")) {
00172 sleep(180);
00173 setkey_str(&retlist, "OP", "clean_stop");
00174 write_log("In impexp: clean_stop cleanslot=%s cleandrive=%s\n",
00175 argv[2], argv[3]);
00176 status = clnt_call(clnttape, IMPEXPDO, (xdrproc_t)xdr_Rkey, (char *)retlist,
00177 (xdrproc_t)xdr_uint32_t, (char *)&tapeback, TIMEOUT);
00178 write_log("impexp: tapeback=%ld, status=%d\n", tapeback, status);
00179 if(status != RPC_SUCCESS) {
00180 call_err = clnt_sperror(clnttape, "Err clnt_call for IMPEXPDO");
00181 write_log("%s %s\n", datestring(), call_err);
00182 }
00183 if(tapeback == 1) {
00184 write_log("**Error in IMPEXPDO call to tape_svc in impexp\n");
00185 }
00186 }
00187 clnt_destroy(clnttape);
00188 fclose(logfp);
00189
00190 }