X-Git-Url: http://andersk.mit.edu/gitweb/moira.git/blobdiff_plain/8ac04a81b3c5b5985968d10edaf5c7bb29828795..fc3ac28ec7737df66a909dc53446cef46e2093ab:/clients/mrtest/mrtest.c diff --git a/clients/mrtest/mrtest.c b/clients/mrtest/mrtest.c index e1117cde..6abcf996 100644 --- a/clients/mrtest/mrtest.c +++ b/clients/mrtest/mrtest.c @@ -5,13 +5,6 @@ * * Copyright (C) 1987 by the Massachusetts Institute of Technology * - * $Log$ - * Revision 1.2 1987-08-22 23:45:10 wesommer - * Removed extra RCS headers. - * - * Revision 1.1 87/08/22 18:31:59 wesommer - * Initial revision - * */ #ifndef lint @@ -19,11 +12,15 @@ static char *rcsid_test_c = "$Header$"; #endif lint #include +#include +#include #include #include int ss; +int recursion = 0; extern ss_request_table sms_test; +extern int sending_version_no; #ifndef __SABER__ main(argc, argv) @@ -46,7 +43,7 @@ sms() init_sms_err_tbl(); init_krb_err_tbl(); - ss = ss_create_invocation("sms", "0.1", (char *)NULL, + ss = ss_create_invocation("sms", "2.0", (char *)NULL, &sms_test, &status); if (status != 0) { com_err(whoami, status, "Unable to create invocation"); @@ -65,6 +62,16 @@ test_noop() if (status) ss_perror(ss, status, 0); } +test_new() +{ + sending_version_no = SMS_VERSION_2; +} + +test_old() +{ + sending_version_no = SMS_VERSION_1; +} + test_connect() { int status = sms_connect(); @@ -79,10 +86,93 @@ test_disconnect() test_auth() { - int status = sms_auth(); + int status; + + status = sms_auth("smstest"); if (status) ss_perror(ss, status, 0); } +test_script(argc, argv) +int argc; +char *argv[]; +{ + FILE *inp; + char input[BUFSIZ], *cp, *index(); + int status, oldstdout, oldstderr; + + if (recursion > 8) { + ss_perror(ss, 0, "too many levels deep in script files\n"); + return; + } + + if (argc < 2) { + ss_perror(ss, 0, "Usage: script input_file [ output_file ]"); + return; + } + + inp = fopen(argv[1], "r"); + if (inp == NULL) { + ss_perror(ss, 0, "Cannot open input file %s", argv[1]); + return; + } + + if (argc == 3) { + printf("Redirecting output to %s\n", argv[2]); + fflush(stdout); + oldstdout = dup(1); + close(1); + status = open(argv[2], O_CREAT|O_WRONLY|O_APPEND, 0664); + if (status != 1) { + close(status); + dup2(oldstdout, 1); + argc = 2; + ss_perror(ss, errno, "Unable to redirect output to %s\n", argv[2]); + } else { + fflush(stderr); + oldstderr = dup(2); + close(2); + dup2(1, 2); + } + } + + recursion++; + + for(;;) { + if (fgets(input, BUFSIZ, inp) == NULL) + break; + if ((cp = index(input, '\n')) != (char *)NULL) + *cp = 0; + if (input[0] == 0) { + printf("\n"); + continue; + } + if (input[0] == '%') { + for (cp = &input[1]; *cp && isspace(*cp); cp++); + printf("Comment: %s\n", cp); + continue; + } + printf("Executing: %s\n", input); + ss_execute_line(ss, input, &status); + if (status == SS_ET_COMMAND_NOT_FOUND) { + printf("Bad command: %s\n", input); + } + } + + recursion--; + + fclose(inp); + if (argc == 3) { + fflush(stdout); + close(1); + dup2(oldstdout, 1); + close(oldstdout); + fflush(stderr); + close(2); + dup2(oldstderr, 2); + close(oldstderr); + } +} + char *concat(str1, str2) char *str1, *str2; { @@ -103,25 +193,6 @@ char *concat(str1, str2) return rtn; } -test_shutdown(argc, argv) - int argc; - char **argv; -{ - char *reason = NULL; - int status, i; - - if (argc < 2) { - ss_perror(ss, 0, "Usage: shutdown reason ..."); - return; - } - - for (i = 1 ; i < argc; i++) { - if (i != 1) reason = concat(reason, " "); - reason = concat(reason, argv[i]); - } - status = sms_shutdown(reason); - if (status) ss_perror(ss, status, 0); -} static int count; @@ -136,6 +207,7 @@ print_reply(argc, argv) } printf("\n"); count++; + return(SMS_CONT); } test_query(argc, argv) @@ -147,9 +219,10 @@ test_query(argc, argv) ss_perror(ss, 0, "Usage: query handle [ args ... ]"); return; } + count = 0; status = sms_query(argv[1], argc-2, argv+2, print_reply, (char *)NULL); - printf("%d tuples\n", count); + printf("%d tuple%s\n", count, ((count == 1) ? "" : "s")); if (status) ss_perror(ss, status, 0); } @@ -166,3 +239,13 @@ test_access(argc, argv) if (status) ss_perror(ss, status, 0); } + +test_dcm(argc, argv) + int argc; + char **argv; +{ + int status; + + if (status = sms_do_update()) + ss_perror(ss, status, " while triggering dcm"); +}