death to register
[openafs.git] / src / venus / dedebug.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 <afsconfig.h>
11 #include <afs/param.h>
12
13
14
15 #include <sys/types.h>
16 #include <netinet/in.h>
17 #include <sys/socket.h>
18 #include <netdb.h>
19 #include <stdio.h>
20 #ifdef  AFS_AIX32_ENV
21 #include <signal.h>
22 #endif
23 #include <afs/afscbint.h>
24 #include <afs/cmd.h>
25 #include <afs/com_err.h>
26 #include <rx/rx.h>
27 #include <lock.h>
28
29 extern struct rx_securityClass *rxnull_NewServerSecurityObject();
30 extern struct hostent *hostutil_GetHostByName();
31
32 static PrintCacheEntries(struct rx_connection *aconn, int aint32)
33 {
34     int i;
35     afs_int32 code, addr, inode, flags, time;
36     char *fileName;
37
38     for(i=0;i<100000;i++) {
39         code = RXAFSCB_GetDE(aconn, i, &addr, &inode, &flags, &time, &fileName);
40         if (code) {
41             if (code == 1) break;
42             printf("cmdebug: failed to get cache entry %d (%s)\n", i,
43                    afs_error_message(code));
44             return code;
45         }
46
47         /* otherwise print this entry */
48         printf("%d: ** dentry %d %08x %d %d %s\n",
49                i, addr, inode, flags, time, fileName);
50
51         printf("\n");
52     }
53     printf("Returned %d entries.\n", i);
54     return 0;
55 }
56
57 static int
58 CommandProc(struct cmd_syndesc *as, void *arock)
59 {
60     struct rx_connection *conn;
61     char *hostName;
62     struct hostent *thp;
63     afs_int32 port;
64     struct rx_securityClass *secobj;
65     int int32p;
66     afs_int32 addr;
67
68     hostName = as->parms[0].items->data;
69     if (as->parms[1].items)
70         port = atoi(as->parms[1].items->data);
71     else
72         port = 7001;
73     thp = hostutil_GetHostByName(hostName);
74     if (!thp) {
75         printf("cmdebug: can't resolve address for host %s.\n", hostName);
76         exit(1);
77     }
78     memcpy(&addr, thp->h_addr, sizeof(afs_int32));
79     secobj = rxnull_NewServerSecurityObject();
80     conn = rx_NewConnection(addr, htons(port), 1, secobj, 0);
81     if (!conn) {
82         printf("cmdebug: failed to create connection for host %s\n", hostName);
83         exit(1);
84     }
85     if (as->parms[2].items) int32p = 1;
86     else int32p = 0;
87     PrintCacheEntries(conn, int32p);
88     return 0;
89 }
90
91 #include "AFS_component_version_number.c"
92
93 main(argc, argv)
94 int argc;
95 char **argv; {
96     struct cmd_syndesc *ts;
97
98 #ifdef  AFS_AIX32_ENV
99     /*
100      * The following signal action for AIX is necessary so that in case of a 
101      * crash (i.e. core is generated) we can include the user's data section 
102      * in the core dump. Unfortunately, by default, only a partial core is
103      * generated which, in many cases, isn't too useful.
104      */
105     struct sigaction nsa;
106     
107     sigemptyset(&nsa.sa_mask);
108     nsa.sa_handler = SIG_DFL;
109     nsa.sa_flags = SA_FULLDUMP;
110     sigaction(SIGSEGV, &nsa, NULL);
111 #endif
112     rx_Init(0);
113
114     ts = cmd_CreateSyntax(NULL, CommandProc, NULL, "probe unik server");
115     cmd_AddParm(ts, "-servers", CMD_SINGLE, CMD_REQUIRED, "server machine");
116     cmd_AddParm(ts, "-port", CMD_SINGLE, CMD_OPTIONAL, "IP port");
117     cmd_AddParm(ts, "-long", CMD_FLAG, CMD_OPTIONAL, "print all info");
118
119     cmd_Dispatch(argc, argv);
120     exit(0);
121 }