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