~ubuntu-branches/ubuntu/oneiric/pgpool2/oneiric

« back to all changes in this revision

Viewing changes to pcp/pcp_node_info.c

  • Committer: Bazaar Package Importer
  • Author(s): Christoph Berg
  • Date: 2011-06-10 10:18:29 UTC
  • mfrom: (1.1.6 upstream) (4.2.2 sid)
  • Revision ID: james.westby@ubuntu.com-20110610101829-m1aig6u0p74qpif3
Tags: 3.0.4-1
* New upstream release
* Use format 3.0 (quilt).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * $Header: /cvsroot/pgpool/pgpool-II/pcp/pcp_node_info.c,v 1.3 2008/12/31 10:25:40 t-ishii Exp $
 
2
 * $Header: /cvsroot/pgpool/pgpool-II/pcp/pcp_node_info.c,v 1.9 2010/08/22 08:24:02 gleu Exp $
3
3
 *
4
4
 * pgpool: a language independent connection pool server for PostgreSQL 
5
5
 * written by Tatsuo Ishii
24
24
#include <stdlib.h>
25
25
#include <string.h>
26
26
#include <unistd.h>
 
27
#ifdef HAVE_GETOPT_H
 
28
#include <getopt.h>
 
29
#else
 
30
#include "getopt_long.h"
 
31
#endif
27
32
 
28
33
#include "pcp.h"
29
34
 
41
46
        int nodeID;
42
47
        BackendInfo *backend_info;
43
48
        int ch;
 
49
        int     optindex;
 
50
    bool verbose = false;
44
51
 
45
 
        while ((ch = getopt(argc, argv, "hd")) != -1) {
 
52
        static struct option long_options[] = {
 
53
                {"debug", no_argument, NULL, 'd'},
 
54
                {"help", no_argument, NULL, 'h'},
 
55
                {"verbose", no_argument, NULL, 'v'},
 
56
                {NULL, 0, NULL, 0}
 
57
        };
 
58
        
 
59
    while ((ch = getopt_long(argc, argv, "hdv", long_options, &optindex)) != -1) {
46
60
                switch (ch) {
47
61
                case 'd':
48
62
                        pcp_enable_debug();
49
63
                        break;
50
64
 
 
65
                case 'v':
 
66
                        verbose = true;
 
67
                        break;
 
68
 
51
69
                case 'h':
52
70
                case '?':
53
71
                default:
126
144
                pcp_disconnect();
127
145
                myexit(errorcode);
128
146
        } else {
129
 
                printf("%s %d %d %f\n", 
130
 
                           backend_info->backend_hostname,
131
 
                           backend_info->backend_port,
132
 
                           backend_info->backend_status,
133
 
                           backend_info->backend_weight);
 
147
        if (verbose)
 
148
        {
 
149
                    printf("Hostname: %s\nPort    : %d\nStatus  : %d\nWeight  : %f\n", 
 
150
                           backend_info->backend_hostname,
 
151
                           backend_info->backend_port,
 
152
                           backend_info->backend_status,
 
153
                           backend_info->backend_weight/RAND_MAX);
 
154
        } else {
 
155
                    printf("%s %d %d %f\n", 
 
156
                           backend_info->backend_hostname,
 
157
                           backend_info->backend_port,
 
158
                           backend_info->backend_status,
 
159
                           backend_info->backend_weight/RAND_MAX);
 
160
        }
134
161
 
135
162
                free(backend_info);
136
163
        }
145
172
{
146
173
        fprintf(stderr, "pcp_node_info - display a pgpool-II node's information\n\n");
147
174
        fprintf(stderr, "Usage: pcp_node_info [-d] timeout hostname port# username password nodeID\n");
148
 
        fprintf(stderr, "Usage: pcp_node_info -h\n\n");
149
 
        fprintf(stderr, "  -d       - enable debug message (optional)\n");
150
 
        fprintf(stderr, "  timeout  - connection timeout value in seconds. command exits on timeout\n");
151
 
        fprintf(stderr, "  hostname - pgpool-II hostname\n");
152
 
        fprintf(stderr, "  port#    - pgpool-II port number\n");
153
 
        fprintf(stderr, "  username - username for PCP authentication\n");
154
 
        fprintf(stderr, "  password - password for PCP authentication\n");
155
 
        fprintf(stderr, "  nodeID   - ID of a node to get information for\n");
156
 
        fprintf(stderr, "  -h       - print this help\n");
 
175
        fprintf(stderr, "  -d, --debug    : enable debug message (optional)\n");
 
176
        fprintf(stderr, "  timeout        : connection timeout value in seconds. command exits on timeout\n");
 
177
        fprintf(stderr, "  hostname       : pgpool-II hostname\n");
 
178
        fprintf(stderr, "  port#          : PCP port number\n");
 
179
        fprintf(stderr, "  username       : username for PCP authentication\n");
 
180
        fprintf(stderr, "  password       : password for PCP authentication\n");
 
181
        fprintf(stderr, "  nodeID         : ID of a node to get information for\n\n");
 
182
        fprintf(stderr, "Usage: pcp_node_info [options]\n");
 
183
    fprintf(stderr, "  Options available are:\n");
 
184
        fprintf(stderr, "  -h, --help     : print this help\n");
 
185
        fprintf(stderr, "  -v, --verbose  : display one line per information with a header\n");
157
186
}
158
187
 
159
188
static void