Index: pcp/pcp.c =================================================================== RCS file: /cvsroot/pgpool/pgpool-II/pcp/pcp.c,v retrieving revision 1.7 diff -u -r1.7 pcp.c --- pcp/pcp.c 8 Feb 2008 08:10:43 -0000 1.7 +++ pcp/pcp.c 29 Dec 2008 05:21:40 -0000 @@ -42,6 +42,11 @@ struct timeval pcp_timeout; static PCP_CONNECTION *pc; +#ifdef DEBUG +static int debug = 1; +#else +static int debug = 0; +#endif static int pcp_authorize(char *username, char *password); /* -------------------------------- @@ -62,9 +67,7 @@ if (pc != NULL) { -#ifdef DEBUG - fprintf(stderr, "DEBUG: connection to backend \"%s\" already exists\n", hostname); -#endif + if (debug) fprintf(stderr, "DEBUG: connection to backend \"%s\" already exists\n", hostname); return 0; } @@ -76,9 +79,7 @@ if (fd < 0) { -#ifdef DEBUG - fprintf(stderr, "DEBUG: could not create socket\n"); -#endif + if (debug) fprintf(stderr, "DEBUG: could not create socket\n"); errorcode = SOCKERR; return -1; } @@ -100,9 +101,7 @@ if (connect(fd, (struct sockaddr *) &unix_addr, sizeof(unix_addr)) < 0) { -#ifdef DEBUG - fprintf(stderr, "DEBUG: could not connect to \"%s\"\n", unix_addr.sun_path); -#endif + if (debug) fprintf(stderr, "DEBUG: could not connect to \"%s\"\n", unix_addr.sun_path); close(fd); errorcode = CONNERR; return -1; @@ -113,9 +112,7 @@ fd = socket(AF_INET, SOCK_STREAM, 0); if (fd < 0) { -#ifdef DEBUG - fprintf(stderr, "DEBUG: could not create socket\n"); -#endif + if (debug) fprintf(stderr, "DEBUG: could not create socket\n"); errorcode = SOCKERR; return -1; } @@ -123,9 +120,7 @@ if (setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (char *) &on, sizeof(on)) < 0) { -#ifdef DEBUG - fprintf(stderr, "DEBUG: could not set socket option\n"); -#endif + if (debug) fprintf(stderr, "DEBUG: could not set socket option\n"); close(fd); errorcode = SOCKERR; return -1; @@ -136,9 +131,7 @@ hp = gethostbyname(hostname); if ((hp == NULL) || (hp->h_addrtype != AF_INET)) { -#ifdef DEBUG - fprintf(stderr, "DEBUG: could not retrieve hostname\n"); -#endif + if (debug) fprintf(stderr, "DEBUG: could not retrieve hostname\n"); close(fd); errorcode = HOSTERR; return -1; @@ -151,9 +144,7 @@ len = sizeof(struct sockaddr_in); if (connect(fd, (struct sockaddr *) &addr, len) < 0) { -#ifdef DEBUG - fprintf(stderr, "DEBUG: could not connect to \"%s\"\n", hostname); -#endif + if (debug) fprintf(stderr, "DEBUG: could not connect to \"%s\"\n", hostname); close(fd); errorcode = CONNERR; return -1; @@ -163,9 +154,7 @@ pc = pcp_open(fd); if (pc == NULL) { -#ifdef DEBUG - fprintf(stderr, "DEBUG: could not allocate buffer space\n"); -#endif + if (debug) fprintf(stderr, "DEBUG: could not allocate buffer space\n"); close(fd); return -1; } @@ -202,9 +191,7 @@ pcp_write(pc, &wsize, sizeof(int)); if (pcp_flush(pc) < 0) { -#ifdef DEBUG - fprintf(stderr, "DEBUG: could not send data to backend\n"); -#endif + if (debug) fprintf(stderr, "DEBUG: could not send data to backend\n"); return -1; } @@ -243,14 +230,10 @@ pcp_write(pc, encrypt_buf, strlen(encrypt_buf)+1); if (pcp_flush(pc) < 0) { -#ifdef DEBUG - fprintf(stderr, "DEBUG: could not send data to backend\n"); -#endif + if (debug) fprintf(stderr, "DEBUG: could not send data to backend\n"); return -1; } -#ifdef DEBUG - fprintf(stderr, "DEBUG: send: tos=\"R\", len=%d\n", ntohl(wsize)); -#endif + if (debug) fprintf(stderr, "DEBUG: send: tos=\"R\", len=%d\n", ntohl(wsize)); if (pcp_read(pc, &tos, 1)) return -1; @@ -265,15 +248,11 @@ } if (pcp_read(pc, buf, rsize - sizeof(int))) return -1; -#ifdef DEBUG - fprintf(stderr, "DEBUG: recv: tos=\"%c\", len=%d, data=%s\n", tos, rsize, buf); -#endif + if (debug) fprintf(stderr, "DEBUG: recv: tos=\"%c\", len=%d, data=%s\n", tos, rsize, buf); if (tos == 'e') { -#ifdef DEBUG - fprintf(stderr, "DEBUG: command failed. reason=%s\n", buf); -#endif + if (debug) fprintf(stderr, "DEBUG: command failed. reason=%s\n", buf); errorcode = BACKENDERR; } else if (tos == 'r') @@ -284,9 +263,7 @@ return 0; } -#ifdef DEBUG - fprintf(stderr, "DEBUG: authentication failed. reason=%s\n", buf); -#endif + if (debug) fprintf(stderr, "DEBUG: authentication failed. reason=%s\n", buf); errorcode = AUTHERR; } free(buf); @@ -305,9 +282,7 @@ if (pc == NULL) { -#ifdef DEBUG - fprintf(stderr, "DEBUG: connection does not exist\n"); -#endif + if (debug) fprintf(stderr, "DEBUG: connection does not exist\n"); return; } @@ -318,9 +293,7 @@ { /* backend had closed connection already */ } -#ifdef DEBUG - fprintf(stderr, "DEBUG: send: tos=\"X\", len=%d\n", sizeof(int)); -#endif + if (debug) fprintf(stderr, "DEBUG: send: tos=\"X\", len=%d\n", sizeof(int)); pcp_close(pc); pc = NULL; @@ -339,9 +312,7 @@ if (pc == NULL) { -#ifdef DEBUG - fprintf(stderr, "DEBUG: connection does not exist\n"); -#endif + if (debug) fprintf(stderr, "DEBUG: connection does not exist\n"); errorcode = NOCONNERR; return -1; } @@ -352,14 +323,10 @@ pcp_write(pc, &mode, sizeof(char)); if (pcp_flush(pc) < 0) { -#ifdef DEBUG - fprintf(stderr, "DEBUG: could not send data to backend\n"); -#endif + if (debug) fprintf(stderr, "DEBUG: could not send data to backend\n"); return -1; } -#ifdef DEBUG - fprintf(stderr, "DEBUG: send: tos=\"T\", len=%d\n", ntohl(wsize)); -#endif + if (debug) fprintf(stderr, "DEBUG: send: tos=\"T\", len=%d\n", ntohl(wsize)); return 0; } @@ -381,9 +348,7 @@ if (pc == NULL) { -#ifdef DEBUG - fprintf(stderr, "DEBUG: connection does not exist\n"); -#endif + if (debug) fprintf(stderr, "DEBUG: connection does not exist\n"); errorcode = NOCONNERR; return -1; } @@ -393,14 +358,10 @@ pcp_write(pc, &wsize, sizeof(int)); if (pcp_flush(pc) < 0) { -#ifdef DEBUG - fprintf(stderr, "DEBUG: could not send data to backend\n"); -#endif + if (debug) fprintf(stderr, "DEBUG: could not send data to backend\n"); return -1; } -#ifdef DEBUG - fprintf(stderr, "DEBUG: send: tos=\"L\", len=%d\n", ntohl(wsize)); -#endif + if (debug) fprintf(stderr, "DEBUG: send: tos=\"L\", len=%d\n", ntohl(wsize)); if (pcp_read(pc, &tos, 1)) return -1; @@ -419,15 +380,11 @@ return -1; } -#ifdef DEBUG - fprintf(stderr, "DEBUG: recv: tos=\"%c\", len=%d, data=%s\n", tos, rsize, buf); -#endif + if (debug) fprintf(stderr, "DEBUG: recv: tos=\"%c\", len=%d, data=%s\n", tos, rsize, buf); if (tos == 'e') { -#ifdef DEBUG - fprintf(stderr, "DEBUG: command failed. reason=%s\n", buf); -#endif + if (debug) fprintf(stderr, "DEBUG: command failed. reason=%s\n", buf); errorcode = BACKENDERR; } else if (tos == 'l') @@ -466,9 +423,7 @@ if (pc == NULL) { -#ifdef DEBUG - fprintf(stderr, "DEBUG: connection does not exist\n"); -#endif + if (debug) fprintf(stderr, "DEBUG: connection does not exist\n"); errorcode = NOCONNERR; return NULL; } @@ -481,14 +436,10 @@ pcp_write(pc, node_id, strlen(node_id)+1); if (pcp_flush(pc) < 0) { -#ifdef DEBUG - fprintf(stderr, "DEBUG: could not send data to backend\n"); -#endif + if (debug) fprintf(stderr, "DEBUG: could not send data to backend\n"); return NULL; } -#ifdef DEBUG - fprintf(stderr, "DEBUG: send: tos=\"I\", len=%d\n", ntohl(wsize)); -#endif + if (debug) fprintf(stderr, "DEBUG: send: tos=\"I\", len=%d\n", ntohl(wsize)); if (pcp_read(pc, &tos, 1)) return NULL; @@ -507,15 +458,11 @@ return NULL; } -#ifdef DEBUG - fprintf(stderr, "DEBUG: recv: tos=\"%c\", len=%d, data=%s\n", tos, rsize, buf); -#endif + if (debug) fprintf(stderr, "DEBUG: recv: tos=\"%c\", len=%d, data=%s\n", tos, rsize, buf); if (tos == 'e') { -#ifdef DEBUG - fprintf(stderr, "DEBUG: command failed. reason=%s\n", buf); -#endif + if (debug) fprintf(stderr, "DEBUG: command failed. reason=%s\n", buf); errorcode = BACKENDERR; free(buf); return NULL; @@ -578,9 +525,7 @@ if (pc == NULL) { -#ifdef DEBUG - fprintf(stderr, "DEBUG: connection does not exist\n"); -#endif + if (debug) fprintf(stderr, "DEBUG: connection does not exist\n"); errorcode = NOCONNERR; return NULL; } @@ -590,14 +535,10 @@ pcp_write(pc, &wsize, sizeof(int)); if (pcp_flush(pc) < 0) { -#ifdef DEBUG - fprintf(stderr, "DEBUG: could not send data to backend\n"); -#endif + if (debug) fprintf(stderr, "DEBUG: could not send data to backend\n"); return NULL; } -#ifdef DEBUG - fprintf(stderr, "DEBUG: send: tos=\"N\", len=%d\n", ntohl(wsize)); -#endif + if (debug) fprintf(stderr, "DEBUG: send: tos=\"N\", len=%d\n", ntohl(wsize)); if (pcp_read(pc, &tos, 1)) return NULL; @@ -615,15 +556,11 @@ free(buf); return NULL; } -#ifdef DEBUG - fprintf(stderr, "DEBUG: recv: tos=\"%c\", len=%d, data=%s\n", tos, rsize, buf); -#endif + if (debug) fprintf(stderr, "DEBUG: recv: tos=\"%c\", len=%d, data=%s\n", tos, rsize, buf); if (tos == 'e') { -#ifdef DEBUG - fprintf(stderr, "DEBUG: command failed. reason=%s\n", buf); -#endif + if (debug) fprintf(stderr, "DEBUG: command failed. reason=%s\n", buf); free(buf); errorcode = BACKENDERR; return NULL; @@ -685,9 +622,7 @@ if (pc == NULL) { -#ifdef DEBUG - fprintf(stderr, "DEBUG: connection does not exist\n"); -#endif + if (debug) fprintf(stderr, "DEBUG: connection does not exist\n"); errorcode = NOCONNERR; return NULL; } @@ -700,14 +635,10 @@ pcp_write(pc, process_id, strlen(process_id)+1); if (pcp_flush(pc) < 0) { -#ifdef DEBUG - fprintf(stderr, "DEBUG: could not send data to backend\n"); -#endif + if (debug) fprintf(stderr, "DEBUG: could not send data to backend\n"); return NULL; } -#ifdef DEBUG - fprintf(stderr, "DEBUG: send: tos=\"P\", len=%d\n", ntohl(wsize)); -#endif + if (debug) fprintf(stderr, "DEBUG: send: tos=\"P\", len=%d\n", ntohl(wsize)); while (1) { @@ -727,15 +658,11 @@ free(buf); return NULL; } -#ifdef DEBUG - fprintf(stderr, "DEBUG: recv: tos=\"%c\", len=%d, data=%s\n", tos, rsize, buf); -#endif + if (debug) fprintf(stderr, "DEBUG: recv: tos=\"%c\", len=%d, data=%s\n", tos, rsize, buf); if (tos == 'e') { -#ifdef DEBUG - fprintf(stderr, "DEBUG: command failed. reason=%s\n", buf); -#endif + if (debug) fprintf(stderr, "DEBUG: command failed. reason=%s\n", buf); free(buf); errorcode = BACKENDERR; return NULL; @@ -836,9 +763,7 @@ if (pc == NULL) { -#ifdef DEBUG - fprintf(stderr, "DEBUG: connection does not exist\n"); -#endif + if (debug) fprintf(stderr, "DEBUG: connection does not exist\n"); errorcode = NOCONNERR; return NULL; } @@ -848,14 +773,10 @@ pcp_write(pc, &wsize, sizeof(int)); if (pcp_flush(pc) < 0) { -#ifdef DEBUG - fprintf(stderr, "DEBUG: could not send data to backend\n"); -#endif + if (debug) fprintf(stderr, "DEBUG: could not send data to backend\n"); return NULL; } -#ifdef DEBUG - fprintf(stderr, "DEBUG: send: tos=\"S\", len=%d\n", ntohl(wsize)); -#endif + if (debug) fprintf(stderr, "DEBUG: send: tos=\"S\", len=%d\n", ntohl(wsize)); while (1) { if (pcp_read(pc, &tos, 1)) @@ -874,15 +795,11 @@ free(buf); return NULL; } -#ifdef DEBUG - fprintf(stderr, "DEBUG: recv: tos=\"%c\", len=%d, data=%s\n", tos, rsize, buf); -#endif + if (debug) fprintf(stderr, "DEBUG: recv: tos=\"%c\", len=%d, data=%s\n", tos, rsize, buf); if (tos == 'e') { -#ifdef DEBUG - fprintf(stderr, "DEBUG: command failed. reason=%s\n", buf); -#endif + if (debug) fprintf(stderr, "DEBUG: command failed. reason=%s\n", buf); free(buf); errorcode = BACKENDERR; return NULL; @@ -1166,9 +1083,7 @@ if (pc == NULL) { -#ifdef DEBUG - fprintf(stderr, "DEBUG: connection does not exist\n"); -#endif + if (debug) fprintf(stderr, "DEBUG: connection does not exist\n"); errorcode = NOCONNERR; return -1; } @@ -1181,14 +1096,10 @@ pcp_write(pc, node_id, strlen(node_id)+1); if (pcp_flush(pc) < 0) { -#ifdef DEBUG - fprintf(stderr, "DEBUG: could not send data to backend\n"); -#endif + if (debug) fprintf(stderr, "DEBUG: could not send data to backend\n"); return -1; } -#ifdef DEBUG - fprintf(stderr, "DEBUG: send: tos=\"D\", len=%d\n", ntohl(wsize)); -#endif + if (debug) fprintf(stderr, "DEBUG: send: tos=\"D\", len=%d\n", ntohl(wsize)); if (pcp_read(pc, &tos, 1)) return -1; @@ -1206,15 +1117,11 @@ free(buf); return -1; } -#ifdef DEBUG - fprintf(stderr, "DEBUG: recv: tos=\"%c\", len=%d, data=%s\n", tos, rsize, buf); -#endif + if (debug) fprintf(stderr, "DEBUG: recv: tos=\"%c\", len=%d, data=%s\n", tos, rsize, buf); if (tos == 'e') { -#ifdef DEBUG - fprintf(stderr, "DEBUG: command failed. reason=%s\n", buf); -#endif + if (debug) fprintf(stderr, "DEBUG: command failed. reason=%s\n", buf); errorcode = BACKENDERR; } else if (tos == 'd') @@ -1249,9 +1156,7 @@ if (pc == NULL) { -#ifdef DEBUG - fprintf(stderr, "DEBUG: connection does not exist\n"); -#endif + if (debug) fprintf(stderr, "DEBUG: connection does not exist\n"); errorcode = NOCONNERR; return -1; } @@ -1264,14 +1169,10 @@ pcp_write(pc, node_id, strlen(node_id)+1); if (pcp_flush(pc) < 0) { -#ifdef DEBUG - fprintf(stderr, "DEBUG: could not send data to backend\n"); -#endif + if (debug) fprintf(stderr, "DEBUG: could not send data to backend\n"); return -1; } -#ifdef DEBUG - fprintf(stderr, "DEBUG: send: tos=\"D\", len=%d\n", ntohl(wsize)); -#endif + if (debug) fprintf(stderr, "DEBUG: send: tos=\"D\", len=%d\n", ntohl(wsize)); if (pcp_read(pc, &tos, 1)) return -1; @@ -1289,15 +1190,11 @@ free(buf); return -1; } -#ifdef DEBUG - fprintf(stderr, "DEBUG: recv: tos=\"%c\", len=%d, data=%s\n", tos, rsize, buf); -#endif + if (debug) fprintf(stderr, "DEBUG: recv: tos=\"%c\", len=%d, data=%s\n", tos, rsize, buf); if (tos == 'e') { -#ifdef DEBUG - fprintf(stderr, "DEBUG: command failed. reason=%s\n", buf); -#endif + if (debug) fprintf(stderr, "DEBUG: command failed. reason=%s\n", buf); errorcode = BACKENDERR; } else if (tos == 'c') @@ -1334,9 +1231,7 @@ if (pc == NULL) { -#ifdef DEBUG - fprintf(stderr, "DEBUG: connection does not exist\n"); -#endif + if (debug) fprintf(stderr, "DEBUG: connection does not exist\n"); errorcode = NOCONNERR; return -1; } @@ -1349,14 +1244,10 @@ pcp_write(pc, node_id, strlen(node_id)+1); if (pcp_flush(pc) < 0) { -#ifdef DEBUG - fprintf(stderr, "DEBUG: could not send data to backend\n"); -#endif + if (debug) fprintf(stderr, "DEBUG: could not send data to backend\n"); return -1; } -#ifdef DEBUG - fprintf(stderr, "DEBUG: send: tos=\"D\", len=%d\n", ntohl(wsize)); -#endif + if (debug) fprintf(stderr, "DEBUG: send: tos=\"D\", len=%d\n", ntohl(wsize)); if (pcp_read(pc, &tos, 1)) return -1; @@ -1374,15 +1265,11 @@ free(buf); return -1; } -#ifdef DEBUG - fprintf(stderr, "DEBUG: recv: tos=\"%c\", len=%d, data=%s\n", tos, rsize, buf); -#endif + if (debug) fprintf(stderr, "DEBUG: recv: tos=\"%c\", len=%d, data=%s\n", tos, rsize, buf); if (tos == 'e') { -#ifdef DEBUG - fprintf(stderr, "DEBUG: command failed. reason=%s\n", buf); -#endif + if (debug) fprintf(stderr, "DEBUG: command failed. reason=%s\n", buf); errorcode = BACKENDERR; } else if (tos == 'c') @@ -1398,3 +1285,15 @@ free(buf); return -1; } + +void +pcp_enable_debug(void) +{ + debug = 1; +} + +void +pcp_disable_debug(void) +{ + debug = 0; +} Index: pcp/pcp.h =================================================================== RCS file: /cvsroot/pgpool/pgpool-II/pcp/pcp.h,v retrieving revision 1.3 diff -u -r1.3 pcp.h --- pcp/pcp.h 29 Jan 2008 01:56:37 -0000 1.3 +++ pcp/pcp.h 29 Dec 2008 05:21:40 -0000 @@ -62,6 +62,8 @@ extern int pcp_attach_node(int nid); extern void pcp_set_timeout(long sec); extern int pcp_recovery_node(int nid); +extern void pcp_enable_debug(void); +extern void pcp_disable_debug(void); /* ------------------------------ * pcp_error.c Index: pcp/pcp_attach_node.c =================================================================== RCS file: /cvsroot/pgpool/pgpool-II/pcp/pcp_attach_node.c,v retrieving revision 1.2 diff -u -r1.2 pcp_attach_node.c --- pcp/pcp_attach_node.c 29 Jan 2008 01:56:37 -0000 1.2 +++ pcp/pcp_attach_node.c 29 Dec 2008 05:21:40 -0000 @@ -23,6 +23,7 @@ #include #include #include +#include #include "pcp.h" @@ -38,36 +39,47 @@ char user[MAX_USER_PASSWD_LEN]; char pass[MAX_USER_PASSWD_LEN]; int nodeID; + int ch; - if (argc == 2 && (strcmp(argv[1], "-h") == 0) ) - { - usage(); - exit(0); + while ((ch = getopt(argc, argv, "hd")) != -1) { + switch (ch) { + case 'd': + pcp_enable_debug(); + break; + + case 'h': + case '?': + default: + usage(); + exit(0); + } } + argc -= optind; + argv += optind; - if (argc != 7) + if (argc != 6) { errorcode = INVALERR; pcp_errorstr(errorcode); myexit(errorcode); } - timeout = atol(argv[1]); + timeout = atol(argv[0]); if (timeout < 0) { errorcode = INVALERR; pcp_errorstr(errorcode); myexit(errorcode); } - if (strlen(argv[2]) >= MAX_DB_HOST_NAMELEN) + if (strlen(argv[1]) >= MAX_DB_HOST_NAMELEN) { errorcode = INVALERR; pcp_errorstr(errorcode); myexit(errorcode); } - strcpy(host, argv[2]); + strcpy(host, argv[1]); - port = atoi(argv[3]); + port = atoi(argv[2]); if (port <= 1024 || port > 65535) { errorcode = INVALERR; @@ -75,23 +87,23 @@ myexit(errorcode); } - if (strlen(argv[4]) >= MAX_USER_PASSWD_LEN) + if (strlen(argv[3]) >= MAX_USER_PASSWD_LEN) { errorcode = INVALERR; pcp_errorstr(errorcode); myexit(errorcode); } - strcpy(user, argv[4]); + strcpy(user, argv[3]); - if (strlen(argv[5]) >= MAX_USER_PASSWD_LEN) + if (strlen(argv[4]) >= MAX_USER_PASSWD_LEN) { errorcode = INVALERR; pcp_errorstr(errorcode); myexit(errorcode); } - strcpy(pass, argv[5]); + strcpy(pass, argv[4]); - nodeID = atoi(argv[6]); + nodeID = atoi(argv[5]); if (nodeID < 0 || nodeID > MAX_NUM_BACKENDS) { errorcode = INVALERR; @@ -123,8 +135,9 @@ usage(void) { fprintf(stderr, "pcp_attach_node - attach a node from pgpool-II\n\n"); - fprintf(stderr, "Usage: pcp_attach_node timeout hostname port# username password nodeID\n"); + fprintf(stderr, "Usage: pcp_attach_node [-d] timeout hostname port# username password nodeID\n"); fprintf(stderr, "Usage: pcp_attach_node -h\n\n"); + fprintf(stderr, " -d - enable debug message (optional)\n"); fprintf(stderr, " timeout - connection timeout value in seconds. command exits on timeout\n"); fprintf(stderr, " hostname - pgpool-II hostname\n"); fprintf(stderr, " port# - pgpool-II port number\n"); Index: pcp/pcp_detach_node.c =================================================================== RCS file: /cvsroot/pgpool/pgpool-II/pcp/pcp_detach_node.c,v retrieving revision 1.2 diff -u -r1.2 pcp_detach_node.c --- pcp/pcp_detach_node.c 29 Jan 2008 01:56:38 -0000 1.2 +++ pcp/pcp_detach_node.c 29 Dec 2008 05:21:40 -0000 @@ -23,6 +23,7 @@ #include #include #include +#include #include "pcp.h" @@ -38,36 +39,47 @@ char user[MAX_USER_PASSWD_LEN]; char pass[MAX_USER_PASSWD_LEN]; int nodeID; + int ch; - if (argc == 2 && (strcmp(argv[1], "-h") == 0) ) - { - usage(); - exit(0); + while ((ch = getopt(argc, argv, "hd")) != -1) { + switch (ch) { + case 'd': + pcp_enable_debug(); + break; + + case 'h': + case '?': + default: + usage(); + exit(0); + } } + argc -= optind; + argv += optind; - if (argc != 7) + if (argc != 6) { errorcode = INVALERR; pcp_errorstr(errorcode); myexit(errorcode); } - timeout = atol(argv[1]); + timeout = atol(argv[0]); if (timeout < 0) { errorcode = INVALERR; pcp_errorstr(errorcode); myexit(errorcode); } - if (strlen(argv[2]) >= MAX_DB_HOST_NAMELEN) + if (strlen(argv[1]) >= MAX_DB_HOST_NAMELEN) { errorcode = INVALERR; pcp_errorstr(errorcode); myexit(errorcode); } - strcpy(host, argv[2]); + strcpy(host, argv[1]); - port = atoi(argv[3]); + port = atoi(argv[2]); if (port <= 1024 || port > 65535) { errorcode = INVALERR; @@ -75,23 +87,23 @@ myexit(errorcode); } - if (strlen(argv[4]) >= MAX_USER_PASSWD_LEN) + if (strlen(argv[3]) >= MAX_USER_PASSWD_LEN) { errorcode = INVALERR; pcp_errorstr(errorcode); myexit(errorcode); } - strcpy(user, argv[4]); + strcpy(user, argv[3]); - if (strlen(argv[5]) >= MAX_USER_PASSWD_LEN) + if (strlen(argv[4]) >= MAX_USER_PASSWD_LEN) { errorcode = INVALERR; pcp_errorstr(errorcode); myexit(errorcode); } - strcpy(pass, argv[5]); + strcpy(pass, argv[4]); - nodeID = atoi(argv[6]); + nodeID = atoi(argv[5]); if (nodeID < 0 || nodeID > MAX_NUM_BACKENDS) { errorcode = INVALERR; @@ -123,8 +135,9 @@ usage(void) { fprintf(stderr, "pcp_detach_node - detach a node from pgpool-II\n\n"); - fprintf(stderr, "Usage: pcp_detach_node timeout hostname port# username password nodeID\n"); + fprintf(stderr, "Usage: pcp_detach_node [-d] timeout hostname port# username password nodeID\n"); fprintf(stderr, "Usage: pcp_detach_node -h\n\n"); + fprintf(stderr, " -d - enable debug message (optional)\n"); fprintf(stderr, " timeout - connection timeout value in seconds. command exits on timeout\n"); fprintf(stderr, " hostname - pgpool-II hostname\n"); fprintf(stderr, " port# - pgpool-II port number\n"); Index: pcp/pcp_node_count.c =================================================================== RCS file: /cvsroot/pgpool/pgpool-II/pcp/pcp_node_count.c,v retrieving revision 1.2 diff -u -r1.2 pcp_node_count.c --- pcp/pcp_node_count.c 29 Jan 2008 01:56:38 -0000 1.2 +++ pcp/pcp_node_count.c 29 Dec 2008 05:21:40 -0000 @@ -23,6 +23,7 @@ #include #include #include +#include #include "pcp.h" @@ -38,53 +39,64 @@ char user[MAX_USER_PASSWD_LEN]; char pass[MAX_USER_PASSWD_LEN]; int node_count; + int ch; - if (argc == 2 && (strcmp(argv[1], "-h") == 0) ) - { - usage(); - exit(0); + while ((ch = getopt(argc, argv, "hd")) != -1) { + switch (ch) { + case 'd': + pcp_enable_debug(); + break; + + case 'h': + case '?': + default: + usage(); + exit(0); + } } + argc -= optind; + argv += optind; - if (argc != 6) { + if (argc != 5) { errorcode = INVALERR; pcp_errorstr(errorcode); myexit(errorcode); } - timeout = atol(argv[1]); + timeout = atol(argv[0]); if (timeout < 0) { errorcode = INVALERR; pcp_errorstr(errorcode); myexit(errorcode); } - if (strlen(argv[2]) >= MAX_DB_HOST_NAMELEN) { + if (strlen(argv[1]) >= MAX_DB_HOST_NAMELEN) { errorcode = INVALERR; pcp_errorstr(errorcode); myexit(errorcode); } - strcpy(host, argv[2]); + strcpy(host, argv[1]); - port = atoi(argv[3]); + port = atoi(argv[2]); if (port <= 1024 || port > 65535) { errorcode = INVALERR; pcp_errorstr(errorcode); myexit(errorcode); } - if (strlen(argv[4]) >= MAX_USER_PASSWD_LEN) { + if (strlen(argv[3]) >= MAX_USER_PASSWD_LEN) { errorcode = INVALERR; pcp_errorstr(errorcode); myexit(errorcode); } - strcpy(user, argv[4]); + strcpy(user, argv[3]); - if (strlen(argv[5]) >= MAX_USER_PASSWD_LEN) { + if (strlen(argv[4]) >= MAX_USER_PASSWD_LEN) { errorcode = INVALERR; pcp_errorstr(errorcode); myexit(errorcode); } - strcpy(pass, argv[5]); + strcpy(pass, argv[4]); pcp_set_timeout(timeout); @@ -112,8 +124,9 @@ usage(void) { fprintf(stderr, "pcp_node_count - display the total number of nodes under pgpool-II's control\n\n"); - fprintf(stderr, "Usage: pcp_node_count timeout hostname port# username password\n"); + fprintf(stderr, "Usage: pcp_node_count [-d] timeout hostname port# username password\n"); fprintf(stderr, "Usage: pcp_node_count -h\n\n"); + fprintf(stderr, " -d - enable debug message (optional)\n"); fprintf(stderr, " timeout - connection timeout value in seconds. command exits on timeout\n"); fprintf(stderr, " hostname - pgpool-II hostname\n"); fprintf(stderr, " port# - pgpool-II port number\n"); Index: pcp/pcp_node_info.c =================================================================== RCS file: /cvsroot/pgpool/pgpool-II/pcp/pcp_node_info.c,v retrieving revision 1.2 diff -u -r1.2 pcp_node_info.c --- pcp/pcp_node_info.c 29 Jan 2008 01:56:38 -0000 1.2 +++ pcp/pcp_node_info.c 29 Dec 2008 05:21:40 -0000 @@ -23,6 +23,7 @@ #include #include #include +#include #include "pcp.h" @@ -39,36 +40,47 @@ char pass[MAX_USER_PASSWD_LEN]; int nodeID; BackendInfo *backend_info; + int ch; - if (argc == 2 && (strcmp(argv[1], "-h") == 0) ) - { - usage(); - exit(0); + while ((ch = getopt(argc, argv, "hd")) != -1) { + switch (ch) { + case 'd': + pcp_enable_debug(); + break; + + case 'h': + case '?': + default: + usage(); + exit(0); + } } + argc -= optind; + argv += optind; - if (argc != 7) + if (argc != 6) { errorcode = INVALERR; pcp_errorstr(errorcode); myexit(errorcode); } - timeout = atol(argv[1]); + timeout = atol(argv[0]); if (timeout < 0) { errorcode = INVALERR; pcp_errorstr(errorcode); myexit(errorcode); } - if (strlen(argv[2]) >= MAX_DB_HOST_NAMELEN) + if (strlen(argv[1]) >= MAX_DB_HOST_NAMELEN) { errorcode = INVALERR; pcp_errorstr(errorcode); myexit(errorcode); } - strcpy(host, argv[2]); + strcpy(host, argv[1]); - port = atoi(argv[3]); + port = atoi(argv[2]); if (port <= 1024 || port > 65535) { errorcode = INVALERR; @@ -76,23 +88,23 @@ myexit(errorcode); } - if (strlen(argv[4]) >= MAX_USER_PASSWD_LEN) + if (strlen(argv[3]) >= MAX_USER_PASSWD_LEN) { errorcode = INVALERR; pcp_errorstr(errorcode); myexit(errorcode); } - strcpy(user, argv[4]); + strcpy(user, argv[3]); - if (strlen(argv[5]) >= MAX_USER_PASSWD_LEN) + if (strlen(argv[4]) >= MAX_USER_PASSWD_LEN) { errorcode = INVALERR; pcp_errorstr(errorcode); myexit(errorcode); } - strcpy(pass, argv[5]); + strcpy(pass, argv[4]); - nodeID = atoi(argv[6]); + nodeID = atoi(argv[5]); if (nodeID < 0 || nodeID > MAX_NUM_BACKENDS) { errorcode = INVALERR; @@ -132,8 +144,9 @@ usage(void) { fprintf(stderr, "pcp_node_info - display a pgpool-II node's information\n\n"); - fprintf(stderr, "Usage: pcp_node_info timeout hostname port# username password nodeID\n"); + fprintf(stderr, "Usage: pcp_node_info [-d] timeout hostname port# username password nodeID\n"); fprintf(stderr, "Usage: pcp_node_info -h\n\n"); + fprintf(stderr, " -d - enable debug message (optional)\n"); fprintf(stderr, " timeout - connection timeout value in seconds. command exits on timeout\n"); fprintf(stderr, " hostname - pgpool-II hostname\n"); fprintf(stderr, " port# - pgpool-II port number\n"); Index: pcp/pcp_proc_count.c =================================================================== RCS file: /cvsroot/pgpool/pgpool-II/pcp/pcp_proc_count.c,v retrieving revision 1.3 diff -u -r1.3 pcp_proc_count.c --- pcp/pcp_proc_count.c 29 Jan 2008 01:56:38 -0000 1.3 +++ pcp/pcp_proc_count.c 29 Dec 2008 05:21:40 -0000 @@ -23,6 +23,7 @@ #include #include #include +#include #include "pcp.h" @@ -39,53 +40,64 @@ char pass[MAX_USER_PASSWD_LEN]; int process_count; int *process_list = NULL; + int ch; - if (argc == 2 && (strcmp(argv[1], "-h") == 0) ) - { - usage(); - exit(0); + while ((ch = getopt(argc, argv, "hd")) != -1) { + switch (ch) { + case 'd': + pcp_enable_debug(); + break; + + case 'h': + case '?': + default: + usage(); + exit(0); + } } + argc -= optind; + argv += optind; - if (argc != 6) { + if (argc != 5) { errorcode = INVALERR; pcp_errorstr(errorcode); myexit(errorcode); } - timeout = atol(argv[1]); + timeout = atol(argv[0]); if (timeout < 0) { errorcode = INVALERR; pcp_errorstr(errorcode); myexit(errorcode); } - if (strlen(argv[2]) >= MAX_DB_HOST_NAMELEN) { + if (strlen(argv[1]) >= MAX_DB_HOST_NAMELEN) { errorcode = INVALERR; pcp_errorstr(errorcode); myexit(errorcode); } - strcpy(host, argv[2]); + strcpy(host, argv[1]); - port = atoi(argv[3]); + port = atoi(argv[2]); if (port <= 1024 || port > 65535) { errorcode = INVALERR; pcp_errorstr(errorcode); myexit(errorcode); } - if (strlen(argv[4]) >= MAX_USER_PASSWD_LEN) { + if (strlen(argv[3]) >= MAX_USER_PASSWD_LEN) { errorcode = INVALERR; pcp_errorstr(errorcode); myexit(errorcode); } - strcpy(user, argv[4]); + strcpy(user, argv[3]); - if (strlen(argv[5]) >= MAX_USER_PASSWD_LEN) { + if (strlen(argv[4]) >= MAX_USER_PASSWD_LEN) { errorcode = INVALERR; pcp_errorstr(errorcode); myexit(errorcode); } - strcpy(pass, argv[5]); + strcpy(pass, argv[4]); pcp_set_timeout(timeout); Index: pcp/pcp_proc_info.c =================================================================== RCS file: /cvsroot/pgpool/pgpool-II/pcp/pcp_proc_info.c,v retrieving revision 1.2 diff -u -r1.2 pcp_proc_info.c --- pcp/pcp_proc_info.c 29 Jan 2008 01:56:38 -0000 1.2 +++ pcp/pcp_proc_info.c 29 Dec 2008 05:21:40 -0000 @@ -23,6 +23,7 @@ #include #include #include +#include #include "pcp.h" @@ -40,36 +41,47 @@ int processID; ProcessInfo *process_info; int array_size; + int ch; - if (argc == 2 && (strcmp(argv[1], "-h") == 0) ) - { - usage(); - exit(0); + while ((ch = getopt(argc, argv, "hd")) != -1) { + switch (ch) { + case 'd': + pcp_enable_debug(); + break; + + case 'h': + case '?': + default: + usage(); + exit(0); + } } + argc -= optind; + argv += optind; - if (argc != 7) + if (argc != 6) { errorcode = INVALERR; pcp_errorstr(errorcode); myexit(errorcode); } - timeout = atol(argv[1]); + timeout = atol(argv[0]); if (timeout < 0) { errorcode = INVALERR; pcp_errorstr(errorcode); myexit(errorcode); } - if (strlen(argv[2]) >= MAX_DB_HOST_NAMELEN) + if (strlen(argv[1]) >= MAX_DB_HOST_NAMELEN) { errorcode = INVALERR; pcp_errorstr(errorcode); myexit(errorcode); } - strcpy(host, argv[2]); + strcpy(host, argv[1]); - port = atoi(argv[3]); + port = atoi(argv[2]); if (port <= 1024 || port > 65535) { errorcode = INVALERR; @@ -77,23 +89,23 @@ myexit(errorcode); } - if (strlen(argv[4]) >= MAX_USER_PASSWD_LEN) + if (strlen(argv[3]) >= MAX_USER_PASSWD_LEN) { errorcode = INVALERR; pcp_errorstr(errorcode); myexit(errorcode); } - strcpy(user, argv[4]); + strcpy(user, argv[3]); - if (strlen(argv[5]) >= MAX_USER_PASSWD_LEN) + if (strlen(argv[4]) >= MAX_USER_PASSWD_LEN) { errorcode = INVALERR; pcp_errorstr(errorcode); myexit(errorcode); } - strcpy(pass, argv[5]); + strcpy(pass, argv[4]); - processID = atoi(argv[6]); + processID = atoi(argv[5]); if (processID < 0) { errorcode = INVALERR; @@ -142,8 +154,9 @@ usage(void) { fprintf(stderr, "pcp_proc_info - display a pgpool-II child process' information\n\n"); - fprintf(stderr, "Usage: pcp_proc_info timeout hostname port# username password PID\n"); + fprintf(stderr, "Usage: pcp_proc_info [-d] timeout hostname port# username password PID\n"); fprintf(stderr, "Usage: pcp_proc_info -h\n\n"); + fprintf(stderr, " -d - enable debug message (optional)\n"); fprintf(stderr, " timeout - connection timeout value in seconds. command exits on timeout\n"); fprintf(stderr, " hostname - pgpool-II hostname\n"); fprintf(stderr, " port# - pgpool-II port number\n"); Index: pcp/pcp_recovery_node.c =================================================================== RCS file: /cvsroot/pgpool/pgpool-II/pcp/pcp_recovery_node.c,v retrieving revision 1.3 diff -u -r1.3 pcp_recovery_node.c --- pcp/pcp_recovery_node.c 12 Mar 2008 04:53:51 -0000 1.3 +++ pcp/pcp_recovery_node.c 29 Dec 2008 05:21:40 -0000 @@ -23,6 +23,7 @@ #include #include #include +#include #include "pcp.h" @@ -38,36 +39,47 @@ char user[MAX_USER_PASSWD_LEN]; char pass[MAX_USER_PASSWD_LEN]; int nodeID; + int ch; - if (argc == 2 && (strcmp(argv[1], "-h") == 0) ) - { - usage(); - exit(0); + while ((ch = getopt(argc, argv, "hd")) != -1) { + switch (ch) { + case 'd': + pcp_enable_debug(); + break; + + case 'h': + case '?': + default: + usage(); + exit(0); + } } + argc -= optind; + argv += optind; - if (argc != 7) + if (argc != 6) { errorcode = INVALERR; pcp_errorstr(errorcode); myexit(errorcode); } - timeout = atol(argv[1]); + timeout = atol(argv[0]); if (timeout < 0) { errorcode = INVALERR; pcp_errorstr(errorcode); myexit(errorcode); } - if (strlen(argv[2]) >= MAX_DB_HOST_NAMELEN) + if (strlen(argv[1]) >= MAX_DB_HOST_NAMELEN) { errorcode = INVALERR; pcp_errorstr(errorcode); myexit(errorcode); } - strcpy(host, argv[2]); + strcpy(host, argv[1]); - port = atoi(argv[3]); + port = atoi(argv[2]); if (port <= 1024 || port > 65535) { errorcode = INVALERR; @@ -75,30 +87,30 @@ myexit(errorcode); } - if (strlen(argv[4]) >= MAX_USER_PASSWD_LEN) + if (strlen(argv[3]) >= MAX_USER_PASSWD_LEN) { errorcode = INVALERR; pcp_errorstr(errorcode); myexit(errorcode); } - strcpy(user, argv[4]); + strcpy(user, argv[3]); - if (strlen(argv[5]) >= MAX_USER_PASSWD_LEN) + if (strlen(argv[4]) >= MAX_USER_PASSWD_LEN) { errorcode = INVALERR; pcp_errorstr(errorcode); myexit(errorcode); } - strcpy(pass, argv[5]); + strcpy(pass, argv[4]); - nodeID = atoi(argv[6]); + nodeID = atoi(argv[5]); if (nodeID < 0 || nodeID > MAX_NUM_BACKENDS) { errorcode = INVALERR; pcp_errorstr(errorcode); myexit(errorcode); } - + pcp_set_timeout(timeout); if (pcp_connect(host, port, user, pass)) @@ -123,8 +135,9 @@ usage(void) { fprintf(stderr, "pcp_recovery_node - recovery a node\n\n"); - fprintf(stderr, "Usage: pcp_recovery_node timeout hostname port# username password nodeID\n"); + fprintf(stderr, "Usage: pcp_recovery_node [-d] timeout hostname port# username password nodeID\n"); fprintf(stderr, "Usage: pcp_recovery_node -h\n\n"); + fprintf(stderr, " -d - enable debug message (optional)\n"); fprintf(stderr, " timeout - connection timeout value in seconds. command exits on timeout\n"); fprintf(stderr, " hostname - pgpool-II hostname\n"); fprintf(stderr, " port# - pgpool-II port number\n"); Index: pcp/pcp_stop_pgpool.c =================================================================== RCS file: /cvsroot/pgpool/pgpool-II/pcp/pcp_stop_pgpool.c,v retrieving revision 1.2 diff -u -r1.2 pcp_stop_pgpool.c --- pcp/pcp_stop_pgpool.c 29 Jan 2008 01:56:38 -0000 1.2 +++ pcp/pcp_stop_pgpool.c 29 Dec 2008 05:21:40 -0000 @@ -23,6 +23,7 @@ #include #include #include +#include #include "pcp.h" @@ -38,36 +39,47 @@ char user[MAX_USER_PASSWD_LEN]; char pass[MAX_USER_PASSWD_LEN]; char mode; + int ch; - if (argc == 2 && (strcmp(argv[1], "-h") == 0) ) - { - usage(); - exit(0); + while ((ch = getopt(argc, argv, "hd")) != -1) { + switch (ch) { + case 'd': + pcp_enable_debug(); + break; + + case 'h': + case '?': + default: + usage(); + exit(0); + } } + argc -= optind; + argv += optind; - if (argc != 7) + if (argc != 6) { errorcode = INVALERR; pcp_errorstr(errorcode); myexit(errorcode); } - timeout = atol(argv[1]); + timeout = atol(argv[0]); if (timeout < 0) { errorcode = INVALERR; pcp_errorstr(errorcode); myexit(errorcode); } - if (strlen(argv[2]) >= MAX_DB_HOST_NAMELEN) + if (strlen(argv[1]) >= MAX_DB_HOST_NAMELEN) { errorcode = INVALERR; pcp_errorstr(errorcode); myexit(errorcode); } - strcpy(host, argv[2]); + strcpy(host, argv[1]); - port = atoi(argv[3]); + port = atoi(argv[2]); if (port <= 1024 || port > 65535) { errorcode = INVALERR; @@ -75,29 +87,29 @@ myexit(errorcode); } - if (strlen(argv[4]) >= MAX_USER_PASSWD_LEN) + if (strlen(argv[3]) >= MAX_USER_PASSWD_LEN) { errorcode = INVALERR; pcp_errorstr(errorcode); myexit(errorcode); } - strcpy(user, argv[4]); + strcpy(user, argv[3]); - if (strlen(argv[5]) >= MAX_USER_PASSWD_LEN) + if (strlen(argv[4]) >= MAX_USER_PASSWD_LEN) { errorcode = INVALERR; pcp_errorstr(errorcode); myexit(errorcode); } - strcpy(pass, argv[5]); + strcpy(pass, argv[4]); - if (strlen(argv[6]) != 1) + if (strlen(argv[5]) != 1) { errorcode = INVALERR; pcp_errorstr(errorcode); myexit(errorcode); } - mode = argv[6][0]; + mode = argv[5][0]; if (mode != 's' && mode != 'f' && mode != 'i') { errorcode = INVALERR; @@ -131,8 +143,9 @@ usage(void) { fprintf(stderr, "pcp_stop_pgpool - terminate pgpool-II\n\n"); - fprintf(stderr, "Usage: pcp_stop_pgpool timeout hostname port# username password mode\n"); + fprintf(stderr, "Usage: pcp_stop_pgpool [-d] timeout hostname port# username password mode\n"); fprintf(stderr, "Usage: pcp_stop_pgpool -h\n\n"); + fprintf(stderr, " -d - enable debug message (optional)\n"); fprintf(stderr, " timeout - connection timeout value in seconds. command exits on timeout\n"); fprintf(stderr, " hostname - pgpool-II hostname\n"); fprintf(stderr, " port# - pgpool-II port number\n"); Index: pcp/pcp_systemdb_info.c =================================================================== RCS file: /cvsroot/pgpool/pgpool-II/pcp/pcp_systemdb_info.c,v retrieving revision 1.2 diff -u -r1.2 pcp_systemdb_info.c --- pcp/pcp_systemdb_info.c 29 Jan 2008 01:56:38 -0000 1.2 +++ pcp/pcp_systemdb_info.c 29 Dec 2008 05:21:40 -0000 @@ -23,6 +23,7 @@ #include #include #include +#include #include "pcp.h" @@ -39,36 +40,47 @@ char pass[MAX_USER_PASSWD_LEN]; SystemDBInfo *systemdb_info; int i, j; + int ch; - if (argc == 2 && (strcmp(argv[1], "-h") == 0) ) - { - usage(); - exit(0); + while ((ch = getopt(argc, argv, "hd")) != -1) { + switch (ch) { + case 'd': + pcp_enable_debug(); + break; + + case 'h': + case '?': + default: + usage(); + exit(0); + } } + argc -= optind; + argv += optind; - if (argc != 6) + if (argc != 5) { errorcode = INVALERR; pcp_errorstr(errorcode); myexit(errorcode); } - timeout = atol(argv[1]); + timeout = atol(argv[0]); if (timeout < 0) { errorcode = INVALERR; pcp_errorstr(errorcode); myexit(errorcode); } - if (strlen(argv[2]) >= MAX_DB_HOST_NAMELEN) + if (strlen(argv[1]) >= MAX_DB_HOST_NAMELEN) { errorcode = INVALERR; pcp_errorstr(errorcode); myexit(errorcode); } - strcpy(host, argv[2]); + strcpy(host, argv[1]); - port = atoi(argv[3]); + port = atoi(argv[2]); if (port <= 1024 || port > 65535) { errorcode = INVALERR; @@ -76,21 +88,21 @@ myexit(errorcode); } - if (strlen(argv[4]) >= MAX_USER_PASSWD_LEN) + if (strlen(argv[3]) >= MAX_USER_PASSWD_LEN) { errorcode = INVALERR; pcp_errorstr(errorcode); myexit(errorcode); } - strcpy(user, argv[4]); + strcpy(user, argv[3]); - if (strlen(argv[5]) >= MAX_USER_PASSWD_LEN) + if (strlen(argv[4]) >= MAX_USER_PASSWD_LEN) { errorcode = INVALERR; pcp_errorstr(errorcode); myexit(errorcode); } - strcpy(pass, argv[5]); + strcpy(pass, argv[4]); if (pcp_connect(host, port, user, pass)) { @@ -146,8 +158,9 @@ usage(void) { fprintf(stderr, "pcp_systemdb_info - display the pgpool-II systemDB information\n\n"); - fprintf(stderr, "Usage: pcp_systemdb_info timeout hostname port# username password\n"); + fprintf(stderr, "Usage: pcp_systemdb_info [-d] timeout hostname port# username password\n"); fprintf(stderr, "Usage: pcp_systemdb_info -h\n\n"); + fprintf(stderr, " -d - enable debug message (optional)\n"); fprintf(stderr, " timeout - connection timeout value in seconds. command exits on timeout\n"); fprintf(stderr, " hostname - pgpool-II hostname\n"); fprintf(stderr, " port# - pgpool-II port number\n");