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