00001
00002
00003
00004
00005
00006
00007 #include <SUM.h>
00008 #include <soi_key.h>
00009 #include <rpc/rpc.h>
00010 #include <rpc/pmap_clnt.h>
00011 #include <sys/time.h>
00012 #include <sys/errno.h>
00013 #include <sum_rpc.h>
00014
00015 extern int errno;
00016 static int RESPDO_called;
00017 char *jdatestring(void);
00018 void sumexportprog_1(struct svc_req *rqstp, SVCXPRT *transp);
00019 int sumexport_wait(void);
00020 int sumexport_poll(void);
00021 KEY *alist;
00022 static struct timeval TIMEOUT = { 20, 0 };
00023
00024
00025 static int xgetanymsg(int block);
00026
00027 int SUM_export(SUMEXP_t *sumexp, int (*history)(const char *fmt, ...))
00028 {
00029 KEY *list = newkeylist();
00030 CLIENT *clntsumex;
00031 register SVCXPRT *transp;
00032 char server_name[MAX_STR], ext[MAX_STR];
00033 char *server_name_p, *call_err, *cptr;
00034 char **sptr, **dptr;
00035 uint32_t sumexback, uid;
00036 int status, i, reqcnt;
00037
00038 if (!(server_name_p = getenv("SUMSERVER")))
00039 {
00040 strcpy(server_name, SUMSERVER);
00041 }
00042 else {
00043 strcpy(server_name, server_name_p);
00044 }
00045 cptr = (char *)index(server_name, '.');
00046 if(cptr) *cptr = '\0';
00047
00048
00049
00050 uid = sumexp->uid;
00051 (void) pmap_unset(REMSUMPROG, uid);
00052 transp = (SVCXPRT *)svctcp_create(RPC_ANYSOCK, 0, 0);
00053 if (transp == NULL) {
00054 (*history)("***cannot create tcp service\n");
00055 return(1);
00056 }
00057 if(!svc_register(transp, REMSUMPROG, uid, sumexportprog_1,IPPROTO_TCP)) {
00058 (*history)("***unable to register (REMSUMPROG, REMSUMVERS, tcp)\n");
00059 return(1);
00060 }
00061
00062
00063 clntsumex = clnt_create(server_name, SUMEXPROG, SUMEXVERS, "tcp");
00064 if(!clntsumex) {
00065 clnt_pcreateerror("Can't get client handle to sum_export_svc");
00066 (*history)("sum_export_svc not there on %s\n", server_name);
00067 return(1);
00068 }
00069 alist = newkeylist();
00070 reqcnt = sumexp->reqcnt;
00071 setkey_int(&list, "reqcnt", reqcnt);
00072 sptr = sumexp->src;
00073 dptr = sumexp->dest;
00074 for(i = 0; i < reqcnt; i++) {
00075 sprintf(ext, "src_%d", i);
00076 setkey_str(&list, ext, *sptr++);
00077 sprintf(ext, "dest_%d", i);
00078 setkey_str(&list, ext, *dptr++);
00079 }
00080 setkey_str(&list, "cmd", sumexp->cmd);
00081 setkey_str(&list, "host", sumexp->host);
00082 setkey_uint32(&list, "uid", sumexp->uid);
00083 setkey_uint(&list, "port", sumexp->port);
00084
00085 status = clnt_call(clntsumex,SUMEXDO, (xdrproc_t)xdr_Rkey, (char *)list,
00086 (xdrproc_t)xdr_uint32_t, (char *)&sumexback, TIMEOUT);
00087 if(status != RPC_SUCCESS) {
00088 call_err = clnt_sperror(clntsumex, "Err clnt_call for SUMEXDO");
00089 (*history)("%s %s\n", jdatestring(), call_err);
00090 if(status != RPC_TIMEDOUT) {
00091 return(1);
00092 }
00093 }
00094 if(sumexback != 0) {
00095 (*history)("Error status= %d from clnt_call to SUMEXDO = %d\n", sumexback);
00096 return(1);
00097 }
00098 status = sumexport_wait();
00099 status = getkey_int(alist, "STATUS");
00100 if(status) {
00101 (*history)("%s", getkey_str(alist, "ERRMSG"));
00102 return(1);
00103 }
00104 return(0);
00105 }
00106
00107
00108
00109
00110
00111
00112
00113 int sumexport_poll()
00114 {
00115 int stat;
00116
00117 stat = xgetanymsg(0);
00118 if(stat == RPCMSG) return(0);
00119 else return(stat);
00120 }
00121
00122
00123
00124
00125
00126 int sumexport_wait()
00127 {
00128 int stat;
00129
00130 stat = xgetanymsg(1);
00131 if(stat == RPCMSG) return(0);
00132 else return(stat);
00133 }
00134
00135
00136
00137
00138
00139
00140
00141
00142 int xgetanymsg(int block)
00143 {
00144 fd_set readfds;
00145 struct timeval timeout;
00146 int wait, retcode = ERRMSG, srdy;
00147
00148
00149 int ts=FD_SETSIZE;
00150
00151 wait = 1;
00152 while(wait) {
00153 readfds=svc_fdset;
00154 if(block) {
00155 srdy=select(ts,&readfds,(fd_set *)0,(fd_set *)0,NULL);
00156 }
00157 else {
00158 timeout.tv_sec=0;
00159 timeout.tv_usec=500000;
00160 srdy=select(ts,&readfds,(fd_set *)0,(fd_set *)0,&timeout);
00161 }
00162 switch(srdy) {
00163 case -1:
00164 if(errno==EINTR) {
00165 continue;
00166 }
00167 perror("xgetanymsg: select failed");
00168 retcode = ERRMSG;
00169 wait = 0;
00170 break;
00171 case 0:
00172 if(block) continue;
00173 retcode = TIMEOUTMSG;
00174 wait = 0;
00175 break;
00176 default:
00177
00178
00179 RESPDO_called = 0;
00180 svc_getreqset(&readfds);
00181 retcode = RPCMSG;
00182 if(RESPDO_called) wait = 0;
00183 break;
00184 }
00185 }
00186 return(retcode);
00187 }
00188
00189
00190
00191
00192
00193 KEY *xrespdo_1(KEY *params)
00194 {
00195 char *wd;
00196 char **cptr;
00197 int i, reqcode;
00198
00199 char name[80];
00200
00201
00202
00203
00204 reqcode = getkey_int(params, "REQCODE");
00205 switch(reqcode) {
00206 case REMSUMRESPDO:
00207
00208
00209
00210
00211
00212
00213
00214 if(findkey(params, "ERRSTR")) {
00215 printf("ERRSTR in xrespdo_1: %s\n", getkey_str(params, "ERRSTR"));
00216 }
00217 add_keys(params, &alist);
00218 break;
00219 default:
00220 printf("**Unexpected REQCODE in xrespdo_1()\n");
00221 break;
00222 }
00223 return((KEY *)NULL);
00224 }
00225
00226
00227
00228
00229
00230
00231
00232 void sumexportprog_1(rqstp, transp)
00233 struct svc_req *rqstp;
00234 SVCXPRT *transp;
00235 {
00236 union __svcargun {
00237 Rkey respdo_1_arg;
00238 } argument;
00239 char *result;
00240 bool_t (*xdr_argument)(), (*xdr_result)();
00241 char *(*local)();
00242
00243 switch (rqstp->rq_proc) {
00244 case NULLPROC:
00245 (void) svc_sendreply(transp, (xdrproc_t)xdr_void, (char *)NULL);
00246 return;
00247 case REMSUMRESPDO:
00248 xdr_argument = xdr_Rkey;
00249
00250 local = (char *(*)()) xrespdo_1;
00251 RESPDO_called = 1;
00252 break;
00253 default:
00254 svcerr_noproc(transp);
00255 return;
00256 }
00257 bzero((char *)&argument, sizeof(argument));
00258 if(!svc_getargs(transp, (xdrproc_t)xdr_argument, (char *)&argument)) {
00259 svcerr_decode(transp);
00260 return;
00261 }
00262
00263 if(!svc_sendreply(transp, (xdrproc_t)xdr_void, (char *)NULL)) {
00264 svcerr_systemerr(transp);
00265 return;
00266 }
00267
00268 (*local)(&argument, rqstp);
00269
00270 if(!svc_freeargs(transp, (xdrproc_t)xdr_argument, (char *)&argument)) {
00271 printf("unable to free arguments in respd()\n");
00272
00273 }
00274 }
00275
00276
00277 char *jdatestring(void)
00278 {
00279 time_t t;
00280 char *str;
00281
00282 t = time(NULL);
00283 str = ctime(&t);
00284 str[19] = 0;
00285 return str+4;
00286 }
00287