Commit | Line | Data |
---|---|---|
805e021f CE |
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 | * Portions Copyright (c) 2003 Apple Computer, Inc. | |
10 | */ | |
11 | ||
12 | /* | |
13 | * This file contains sample code for the rxstats interface | |
14 | */ | |
15 | ||
16 | #include <afsconfig.h> | |
17 | #include <afs/param.h> | |
18 | ||
19 | #include <roken.h> | |
20 | ||
21 | #ifdef AFS_NT40_ENV | |
22 | #include <pthread.h> | |
23 | #endif | |
24 | ||
25 | #include <rx/rx.h> | |
26 | #include <rx/rxstat.h> | |
27 | #include <afs/afs_Admin.h> | |
28 | #include <afs/afs_clientAdmin.h> | |
29 | #include <afs/afs_utilAdmin.h> | |
30 | ||
31 | void | |
32 | Usage(void) | |
33 | { | |
34 | fprintf(stderr, "Usage: rxstat_enable_process <cell> <host> <port>\n"); | |
35 | exit(1); | |
36 | } | |
37 | ||
38 | void | |
39 | ParseArgs(int argc, char *argv[], char **cellName, char **srvrName, | |
40 | long *srvrPort) | |
41 | { | |
42 | char **argp = argv; | |
43 | ||
44 | if (!*(++argp)) | |
45 | Usage(); | |
46 | *cellName = *(argp++); | |
47 | if (!*(argp)) | |
48 | Usage(); | |
49 | *srvrName = *(argp++); | |
50 | if (!*(argp)) | |
51 | Usage(); | |
52 | *srvrPort = strtol(*(argp++), NULL, 0); | |
53 | if (*srvrPort <= 0 || *srvrPort >= 65536) | |
54 | Usage(); | |
55 | if (*(argp)) | |
56 | Usage(); | |
57 | } | |
58 | ||
59 | int | |
60 | main(int argc, char *argv[]) | |
61 | { | |
62 | int rc; | |
63 | afs_status_t st = 0; | |
64 | struct rx_connection *conn; | |
65 | char *srvrName; | |
66 | long srvrPort; | |
67 | char *cellName; | |
68 | void *tokenHandle; | |
69 | void *cellHandle; | |
70 | ||
71 | ParseArgs(argc, argv, &cellName, &srvrName, &srvrPort); | |
72 | ||
73 | rc = afsclient_Init(&st); | |
74 | if (!rc) { | |
75 | fprintf(stderr, "afsclient_Init, status %d\n", st); | |
76 | exit(1); | |
77 | } | |
78 | ||
79 | rc = afsclient_TokenGetExisting(cellName, &tokenHandle, &st); | |
80 | if (!rc) { | |
81 | fprintf(stderr, "afsclient_TokenGetExisting, status %d\n", st); | |
82 | exit(1); | |
83 | } | |
84 | ||
85 | rc = afsclient_CellOpen(cellName, tokenHandle, &cellHandle, &st); | |
86 | if (!rc) { | |
87 | fprintf(stderr, "afsclient_CellOpen, status %d\n", st); | |
88 | exit(1); | |
89 | } | |
90 | ||
91 | rc = afsclient_RPCStatOpenPort(cellHandle, srvrName, srvrPort, &conn, | |
92 | &st); | |
93 | if (!rc) { | |
94 | fprintf(stderr, "afsclient_RPCStatOpenPort, status %d\n", st); | |
95 | exit(1); | |
96 | } | |
97 | ||
98 | rc = util_RPCStatsStateEnable(conn, RXSTATS_EnableProcessRPCStats, &st); | |
99 | if (!rc) { | |
100 | fprintf(stderr, "util_RPCStatsStateEnable, status %d\n", st); | |
101 | exit(1); | |
102 | } | |
103 | ||
104 | rc = afsclient_RPCStatClose(conn, &st); | |
105 | if (!rc) { | |
106 | fprintf(stderr, "afsclient_RPCStatClose, status %d\n", st); | |
107 | exit(1); | |
108 | } | |
109 | ||
110 | rc = afsclient_CellClose(cellHandle, &st); | |
111 | if (!rc) { | |
112 | fprintf(stderr, "afsclient_CellClose, status %d\n", st); | |
113 | exit(1); | |
114 | } | |
115 | ||
116 | rc = afsclient_TokenClose(tokenHandle, &st); | |
117 | if (!rc) { | |
118 | fprintf(stderr, "afsclient_TokenClose, status %d\n", st); | |
119 | exit(1); | |
120 | } | |
121 | ||
122 | exit(0); | |
123 | } |