libadmin: Tidy header includes
[openafs.git] / src / libadmin / samples / rxstat_enable_peer.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  * 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
28 #include <afs/afs_Admin.h>
29 #include <afs/afs_clientAdmin.h>
30 #include <afs/afs_utilAdmin.h>
31
32 #ifdef AFS_DARWIN_ENV
33 pthread_mutex_t des_init_mutex = PTHREAD_MUTEX_INITIALIZER;
34 pthread_mutex_t des_random_mutex = PTHREAD_MUTEX_INITIALIZER;
35 pthread_mutex_t rxkad_random_mutex = PTHREAD_MUTEX_INITIALIZER;
36 #endif /* AFS_DARWIN_ENV */
37
38 void
39 Usage(void)
40 {
41     fprintf(stderr, "Usage: rxstat_enable_peer <cell> <host> <port>\n");
42     exit(1);
43 }
44
45 void
46 ParseArgs(int argc, char *argv[], char **cellName, char **srvrName,
47           long *srvrPort)
48 {
49     char **argp = argv;
50
51     if (!*(++argp))
52         Usage();
53     *cellName = *(argp++);
54     if (!*(argp))
55         Usage();
56     *srvrName = *(argp++);
57     if (!*(argp))
58         Usage();
59     *srvrPort = strtol(*(argp++), NULL, 0);
60     if (*srvrPort <= 0 || *srvrPort >= 65536)
61         Usage();
62     if (*(argp))
63         Usage();
64 }
65
66 int
67 main(int argc, char *argv[])
68 {
69     int rc;
70     afs_status_t st = 0;
71     struct rx_connection *conn;
72     char *srvrName;
73     long srvrPort;
74     char *cellName;
75     void *tokenHandle;
76     void *cellHandle;
77
78     ParseArgs(argc, argv, &cellName, &srvrName, &srvrPort);
79
80     rc = afsclient_Init(&st);
81     if (!rc) {
82         fprintf(stderr, "afsclient_Init, status %d\n", st);
83         exit(1);
84     }
85
86     rc = afsclient_TokenGetExisting(cellName, &tokenHandle, &st);
87     if (!rc) {
88         fprintf(stderr, "afsclient_TokenGetExisting, status %d\n", st);
89         exit(1);
90     }
91
92     rc = afsclient_CellOpen(cellName, tokenHandle, &cellHandle, &st);
93     if (!rc) {
94         fprintf(stderr, "afsclient_CellOpen, status %d\n", st);
95         exit(1);
96     }
97
98     rc = afsclient_RPCStatOpenPort(cellHandle, srvrName, srvrPort, &conn,
99                                    &st);
100     if (!rc) {
101         fprintf(stderr, "afsclient_RPCStatOpenPort, status %d\n", st);
102         exit(1);
103     }
104
105     rc = util_RPCStatsStateEnable(conn, RXSTATS_EnablePeerRPCStats, &st);
106     if (!rc) {
107         fprintf(stderr, "util_RPCStatsStateEnable, status %d\n", st);
108         exit(1);
109     }
110
111     rc = afsclient_RPCStatClose(conn, &st);
112     if (!rc) {
113         fprintf(stderr, "afsclient_RPCStatClose, status %d\n", st);
114         exit(1);
115     }
116
117     rc = afsclient_CellClose(cellHandle, &st);
118     if (!rc) {
119         fprintf(stderr, "afsclient_CellClose, status %d\n", st);
120         exit(1);
121     }
122
123     rc = afsclient_TokenClose(tokenHandle, &st);
124     if (!rc) {
125         fprintf(stderr, "afsclient_TokenClose, status %d\n", st);
126         exit(1);
127     }
128
129     exit(0);
130 }