00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 #include <jsoc_main.h>
00042 #include <sum_rpc.h>
00043 #include <cmdparams.h>
00044 #include <drms.h>
00045 #include <drms_names.h>
00046 #include <stdio.h>
00047 #include <stdlib.h>
00048 #include <ctype.h>
00049 #include <strings.h>
00050 #include <soi_key.h>
00051 #include <sys/time.h>
00052 #include <sys/types.h>
00053 #include <sys/stat.h>
00054 #include <unistd.h>
00055 #include <printk.h>
00056 #include <setjmp.h>
00057 #include "pe.h"
00058
00059 #define MAXLINE 96
00060 #define MAXDSREQ 200
00061 #define MAXFLINES 200
00062 #define NOTSPECIFIED "***NOTSPECIFIED***"
00063
00064 extern void pepeqprog_1(struct svc_req *rqstp, SVCXPRT *transp);
00065 extern int pepeq_wait();
00066 extern int pepeq_poll();
00067 extern KEY *call_drms_inq(KEY *list, int dbflg);
00068 void printkey();
00069 void deregdsds();
00070 int resp_dsds(int dsdstid);
00071 int soi_errno = NO_ERROR;
00072
00073 long uid;
00074 int verbose;
00075 int wdonly;
00076 int wddate;
00077 int taeflg;
00078 int dsds_tid;
00079
00080 int pe_tid;
00081 int ampex_tid;
00082 int tae_tid;
00083 int abort_active;
00084 int retrieveflg;
00085 int ampexflg;
00086 int nocontrolc;
00087 int fileflg;
00088 int touchflg = -1;
00089 int ccactive = 0;
00090 int dbxflg = 0;
00091 int linenum = 0;
00092 int ds_lines = 0;
00093 uint32_t ouruid;
00094
00095 char database[MAX_STR];
00096 char pds_set_host[MAX_STR];
00097 char thishost[MAX_STR];
00098 char line[1024];
00099 char *dbname = "mdi_2";
00100 char *pdshost;
00101 char *username;
00102 char *in_ds;
00103 FILE *dsfp;
00104 KEY *dslist;
00105 KEY *alist;
00106 CLIENT *clntsumpe;
00107 SUM_t *sumhandle = NULL;
00108
00109 static struct timeval TIMEOUT = { 20, 0 };
00110
00111
00112
00113 ModuleArgs_t module_args[] = {
00114 {ARG_STRING, "dsname", NOTSPECIFIED, "dataset name"},
00115 {ARG_FLAG, "t","0","#of days to retain input datasets before deletable"},
00116 {ARG_FLAG, "A", "0", "retrieve from tape flag"},
00117 {ARG_FLAG, "v", "0", "verbose flag"},
00118 {ARG_FLAG, "h", "0", "help flag"},
00119 {ARG_FLAG, "w", "0", "wd only flag"},
00120 {ARG_FLAG, "f", "0", "dsname is a file of dataset names"},
00121 {ARG_END}
00122 };
00123
00124 CmdParams_t cmdparams;
00125 char **argv = NULL;
00126 char *pargv[12];
00127 int argc = 0;
00128 char *module_name = "jpeq";
00129 jmp_buf env;
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148 void abortit()
00149 {
00150 if(abort_active) {
00151 printk("Abort an abort! dsds_svc may not have cleaned up\n");
00152 longjmp(env, 2);
00153 }
00154 abort_active=1;
00155 printk("Abort in progress ...\n");
00156 longjmp(env, 2);
00157 }
00158
00159 void sighandler(sig)
00160 int sig;
00161 {
00162 KEY *list = newkeylist();
00163 int respcnt;
00164
00165 if (signal(SIGINT, SIG_IGN) != SIG_IGN)
00166 signal(SIGINT, sighandler);
00167 if (signal(SIGTERM, SIG_IGN) != SIG_IGN)
00168 signal(SIGTERM, sighandler);
00169 if(nocontrolc) {
00170
00171 if(ccactive) {
00172 printk("A ^C is already active. I'm awaiting a dsds_svc reply...\n");
00173 }
00174 else {
00175 ccactive = 1;
00176 setkey_long(&list, "dsds_uid", uid);
00177 setkey_int(&list, "ampex_tid", ampex_tid);
00178 setkey_str(&list, "USER", username);
00179 printk("^C signal received by peq\n");
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210 }
00211 }
00212 else {
00213 printk("\npeq received a termination signal\n");
00214 abortit();
00215 }
00216 }
00217
00218 void usage()
00219 {
00220 printf("Usage:\n");
00221 printf(" peq [-v] [-w|W] [-A] [-t#] [-f] dataset_name\n");
00222 printf(" where -v = verbose mode\n");
00223 printf(" -w = print out the working dirs only\n");
00224
00225 printf(" -A = access the ampex_svc if need to retrieve data\n");
00226 printf(" -t# = (touch) #of days to retain datasets before deletable\n");
00227 printf(" -f = the dataset_name is a file name containing dataset names\n");
00228 printf(" dataset_name like \"prog:name,level:name,series:name[#]\"\n");
00229 printf(" This file is processed 50 lines at a time.\n");
00230 printf(" The series# can be a range. A level# may be given.\n");
00231 printf(" Note: If you use \"[]\" in the ds name you must put the ds name in quotes\n");
00232 exit(1);
00233 }
00234
00235
00236
00237 int get_ds_lines()
00238 {
00239 int i;
00240 int first = 1;
00241
00242 if(!fileflg) { return(0); }
00243 if((in_ds = (char *)malloc(65536)) == NULL) {
00244 printk("Can't malloc storage for dataset names\n");
00245 longjmp(env, 2);
00246 }
00247 for(i = 0; i < MAXFLINES; i++) {
00248 if(fgets(line, 1024, dsfp)) {
00249 if(line[0] == '#' || line[0] == '\n') continue;
00250 line[strlen(line)-1] = NULL;
00251 if(first) { first = 0; strcpy(in_ds, line); }
00252 else { strcat(in_ds, ";"); strcat(in_ds, line); }
00253 }
00254 else break;
00255 }
00256 if(i == 0) {
00257 fclose(dsfp);
00258 return(0);
00259 }
00260 return(i);
00261 }
00262
00263
00264
00265
00266 void get_cmd(int argc, char *argv[])
00267 {
00268 int c, getpasswd;
00269 char *envpasswd, *cptr;
00270 char hostname[MAX_STR];
00271
00272 gethostname(hostname, MAX_STR);
00273 while(--argc > 0 && (*++argv)[0] == '-') {
00274 while(c = *++argv[0])
00275 switch(c) {
00276 case 't':
00277 if(*++argv[0] != NULL) {
00278 cptr = argv[0];
00279 if(!strcmp(cptr, "keep")) {
00280 touchflg = 9999999;
00281 }
00282 else {
00283 if(!isdigit((int)*cptr)) {
00284 printk("-t switch must say \"keep\" or give integer #of days\n");
00285 exit(1);
00286 }
00287 touchflg = atoi(argv[0]);
00288 }
00289 }
00290 while(*++argv[0] != NULL);
00291 --argv[0];
00292 break;
00293 case 'v':
00294 verbose=1;
00295 break;
00296 case 'w':
00297 wdonly=1;
00298 break;
00299 case 'W':
00300 wdonly=1; wddate = 1;
00301 break;
00302 case 'A':
00303 ampexflg=1;
00304 retrieveflg=1;
00305 break;
00306 case 'f':
00307 fileflg=1;
00308 break;
00309 default:
00310 usage();
00311 break;
00312 }
00313 }
00314 if(argc != 1) usage();
00315 dslist = newkeylist();
00316 if(!fileflg) {
00317 setkey_str(&dslist, "in", argv[0]);
00318 if (parse_list (&dslist, "in")) {
00319 printk("Error in parse_list() of dataset name\n");
00320 longjmp(env, 2);
00321 }
00322 c = getkey_int(dslist, "in_nsets");
00323 if(c > MAXDSREQ) {
00324 printk("Error: max number of ds in any one request is %d\n", MAXDSREQ);
00325 longjmp(env, 2);
00326 }
00327 }
00328 else {
00329
00330
00331
00332 if(!(dsfp=fopen(argv[0], "r"))) {
00333 printk("Can't open the input file %s\n", argv[0]);
00334 longjmp(env, 2);
00335 }
00336 }
00337 }
00338
00339
00341
00342
00343
00344
00345 KEY *renumber_keylist(KEY *list, int bias)
00346 {
00347 KEY *walker = list;
00348 char *cptr, *cptr1, *wptr;
00349 char tmp[256], newkey[256], newnum[32];
00350 int i, m, n;
00351
00352 if (!list) {
00353 return NULL;
00354 }
00355 while (walker) {
00356 if(!(cptr = (char *)index(walker->name, 'in_'))) {
00357 if(!(cptr = (char *)rindex(walker->name, '_'))) {
00358 walker = walker->next;
00359 continue;
00360 }
00361 strcpy(tmp, cptr+1);
00362 }
00363 else {
00364 wptr = (char *)walker->name;
00365 m = (int)(cptr - wptr)+1;
00366 if(cptr1 = (char *)index(cptr+1, '_')) {
00367 n = (int)(cptr1-(cptr+1));
00368 strncpy(tmp, cptr+1, n);
00369 tmp[n] = NULL;
00370 }
00371 else {
00372 strcpy(tmp, cptr+1);
00373 }
00374 }
00375 if(isdigit((unsigned char)tmp[0])) {
00376
00377 i = atoi(tmp);
00378 i += bias;
00379 strncpy((char *)newkey, wptr, m);
00380 newkey[m] = NULL;
00381 sprintf(newnum, "%d", i);
00382 strcat((char *)newkey+m, newnum);
00383 if(cptr1) {
00384 strcat((char *)newkey+m+strlen(newnum), cptr1);
00385 }
00386 cptr = (char *)malloc(strlen(newkey)+1);
00387 strcpy(cptr, newkey);
00388 free(walker->name);
00389 walker->name = cptr;
00390
00391 if(strstr(cptr, "inname")) {
00392 sprintf(tmp, "in_%d", i);
00393 setkey_str(&walker, cptr, tmp);
00394 }
00395 }
00396 walker = walker->next;
00397 }
00398 return walker;
00399 }
00400
00401
00402
00403
00404
00405
00406 void queryds()
00407 {
00408 char keyname[MAX_STR], ext[MAX_STR], server_name[MAX_STR], dummy[MAX_STR];
00409 char *wd, *cd, *instr, *argname, *cptr, *cptr1, *server_name_p, *call_err;
00410 int respcnt, status, i;
00411 int offline = 0;
00412 uint32_t sumpeback;
00413 register SVCXPRT *transp;
00414 KEY *blist = newkeylist();
00415
00416 alist = newkeylist();
00417
00418 setkey_str(&dslist, "arg_data_in_0", "in");
00419 setkey_long(&dslist, "dsds_uid", uid);
00420 setkey_str(&dslist, "pds_host", pdshost);
00421
00422 if(ampexflg)
00423 setkey_int(&dslist, "ampex_tid", ampex_tid);
00424 if(touchflg != -1)
00425 setkey_int(&dslist, "touch", touchflg);
00426
00427 if(dbxflg) {
00428 printk("\nThe dslist at the REQREQALLNR:\n");
00429 keyiterate(printkey, dslist);
00430 }
00431 printk("Querying for the input datasets...\n");
00432 nocontrolc = 1;
00433 alist = (KEY *)call_drms_inq(dslist, dbxflg);
00434 if(alist == NULL) {
00435 printk("Can't resolve/retrieve the input datasets with drms.\n");
00436 printk("(Usually no -A switch specified.)\n");
00437 abortit(1);
00438 }
00439
00440
00441
00442
00444
00445
00446 printk("\n");
00447
00448
00449 for(i = linenum; ; i++) {
00450 sprintf(ext, "inname_%d", i);
00451 if(!findkey(alist, ext)) break;
00452 argname = GETKEY_str(alist, ext);
00453 if(wdonly) {
00454 sprintf(ext, "%s_wd", argname);
00455 wd = GETKEY_str(alist, ext);
00456 printk("%s\tKEYTYP_STRING\t%s\n", ext, wd);
00457 if(wddate) {
00458 sprintf(ext, "%s_creat_date", argname);
00459 cd = GETKEY_str(alist, ext);
00460 printk("%s\tKEYTYP_STRING\t%s\n", ext, cd);
00461 }
00462 }
00463 }
00464 if(!wdonly) keyiterate(printkey, alist);
00465 freekeylist(&alist);
00466 }
00467
00468
00469
00470
00471 void setup()
00472 {
00473 printk_set(printf, printf);
00474 if(!(username = (char *)getenv("USER"))) username = "nouser";
00475 if (signal(SIGINT, SIG_IGN) != SIG_IGN)
00476 signal(SIGINT, sighandler);
00477 if (signal(SIGTERM, SIG_IGN) != SIG_IGN)
00478 signal(SIGTERM, sighandler);
00479 gethostname(thishost,MAX_STR);
00480 }
00481
00482 int DoIt()
00483 {
00484 int c;
00485
00486 if(setjmp(env) != 0) {
00487
00488
00489
00490 if(sumhandle)
00491 SUM_close(sumhandle, printk);
00492 printk("jpeq Abnormal Completion\n");
00493 return(1);
00494 }
00495
00496
00497 cmdparams_get_argv(&cmdparams, &argv, &argc);
00498 for(c=0; c < argc; c++) {
00499 pargv[c] = strdup(argv[c]);
00500 }
00501 setup();
00502 get_cmd(argc, pargv);
00503 if(!wdonly) {
00504 if((sumhandle = SUM_open(NULL, NULL, printk)) == 0) {
00505 printk("Failed on SUM_open()\n");
00506 longjmp(env, 2);
00507 }
00508 }
00509 while(1) {
00510 if(!fileflg) {
00511 queryds();
00512 break;
00513 }
00514 if(!(ds_lines = get_ds_lines())) {
00515 break;
00516 }
00517 dslist = newkeylist();
00518 setkey_str(&dslist, "in", in_ds);
00519 if (parse_list (&dslist, "in")) {
00520 printk("Error in parse_list() of dataset name\n");
00521 longjmp(env, 2);
00522 }
00523 c = getkey_int(dslist, "in_nsets");
00524 if(c > MAXDSREQ) {
00525 printk("Error: the next list of ds exceed the max of %d\n", MAXDSREQ);
00526 longjmp(env, 2);
00527 }
00528 queryds();
00529 if(ds_lines >= MAXFLINES) {
00530 printk("Error: max of %d lines in -f file mode\n", MAXFLINES);
00531 longjmp(env, 2);
00532 }
00533 linenum += ds_lines;
00534 }
00535
00536 if(sumhandle)
00537 SUM_close(sumhandle, printk);
00538 printk("jpeq Normal Completion\n");
00539 return(0);
00540 }