death to register
[openafs.git] / src / rx / test / kstest.c
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  * 
5  * This software has been released under the terms of the IBM Public
6  * License.  For details, see the LICENSE file in the top-level source
7  * directory or online at http://www.openafs.org/dl/license10.html
8  */
9
10 #include "afs/param.h"
11 #include <afsconfig.h>
12
13
14 #include <sys/types.h>
15 #include <netinet/in.h>
16 #include <netdb.h>
17 #include <stdio.h>
18 #include <signal.h>
19 #include "xdr.h"
20 #include "rx.h"
21 #include "rx_globals.h"
22 #include "rx_null.h"
23
24 static int port;
25 static short stats = 0;
26
27 void
28 SigInt(int ignore)
29 {
30     if (rx_debugFile) {
31         rx_PrintStats(rx_debugFile);
32         fflush(rx_debugFile);
33     }
34     if (stats)
35         rx_PrintStats(stdout);
36     exit(1);
37 }
38
39
40 static
41 ParseCmd(argc, argv)
42      int argc;
43      char **argv;
44 {
45     int i;
46     for (i = 1; i < argc; i++) {
47         if (!strcmp(argv[i], "-port")) {
48             port = atoi(argv[i + 1]);
49             port = htons(port);
50             i++;
51         } else if (!strcmp(argv[i], "-log")) {
52             rx_debugFile = fopen("kstest.log", "w");
53             if (rx_debugFile == NULL)
54                 printf("Couldn't open rx_stest.db");
55             signal(SIGINT, SigInt);
56         } else if (!strcmp(argv[i], "-stats"))
57             stats = 1;
58         else {
59             printf("unrecognized switch '%s'\n", argv[i]);
60             return -1;
61         }
62     }
63     return 0;
64 }
65
66 /* er loop */
67 static
68 rxk_erproc(acall)
69      struct rx_call *acall;
70 {
71     XDR xdr;
72     long temp;
73
74     xdrrx_create(&xdr, acall, XDR_DECODE);
75     xdr_long(&xdr, &temp);
76     temp++;
77     xdr.x_op = XDR_ENCODE;
78     xdr_long(&xdr, &temp);
79     return 0;
80 }
81
82 main(argc, argv)
83      int argc;
84      char **argv;
85 {
86     long code;
87     static struct rx_securityClass *sc[3];      /* so other kernel procs can reference it */
88     struct rx_service *tservice;
89
90     port = htons(10000);
91     if (ParseCmd(argc, argv) != 0) {
92         printf("erorr parsing commands\n");
93         exit(1);
94     }
95     code = rx_Init(port);
96     if (code) {
97         printf("init failed code %d\n", code);
98         exit(1);
99     }
100     signal(SIGINT, SigInt);
101     printf("back from rx server init\n");
102     sc[0] = rxnull_NewServerSecurityObject();
103     sc[1] = sc[2] = 0;
104     printf("new secobj created\n");
105     tservice = rx_NewService(0, 1, "test", sc, 1 /* 3 */ , rxk_erproc);
106     printf("service is %x\n", tservice);
107     if (!tservice) {
108         printf("failed to create service\n");
109         exit(1);
110     }
111     rx_StartServer(1);          /* donate self */
112 }