From d0cd78ae5140f66f3a4f3c93236e02af53c5ca08 Mon Sep 17 00:00:00 2001 From: Pavan Deolasee Date: Fri, 14 Sep 2018 10:59:48 +0530 Subject: [PATCH] Fix some more compiler warnings --- src/backend/pgxc/locator/redistrib.c | 1 + src/backend/pgxc/pool/pgxcnode.c | 2 -- src/backend/pgxc/squeue/squeue.c | 2 +- src/backend/postmaster/clustermon.c | 1 - src/backend/tcop/pquery.c | 2 +- src/bin/pgxc_ctl/bash_handler.c | 5 ++++- src/bin/pgxc_ctl/do_command.c | 7 +++---- src/bin/pgxc_ctl/do_shell.c | 5 +++-- src/bin/pgxc_ctl/monitor.c | 9 ++++----- src/bin/pgxc_ctl/pgxc_ctl.c | 20 +++++++++++++++++--- src/bin/pgxc_ctl/utils.c | 9 ++++++++- 11 files changed, 42 insertions(+), 21 deletions(-) diff --git a/src/backend/pgxc/locator/redistrib.c b/src/backend/pgxc/locator/redistrib.c index 1a081b4730..8ba684af51 100644 --- a/src/backend/pgxc/locator/redistrib.c +++ b/src/backend/pgxc/locator/redistrib.c @@ -377,6 +377,7 @@ distrib_execute_command(RedistribState *distribState, RedistribCommand *command) break; case DISTRIB_NONE: default: + command_str = ""; /* keep compiler quiet */ Assert(0); /* Should not happen */ } diff --git a/src/backend/pgxc/pool/pgxcnode.c b/src/backend/pgxc/pool/pgxcnode.c index 01d678dd2f..d59e9cd7f7 100644 --- a/src/backend/pgxc/pool/pgxcnode.c +++ b/src/backend/pgxc/pool/pgxcnode.c @@ -2567,9 +2567,7 @@ Datum pgxc_node_str(PG_FUNCTION_ARGS) { Name result; - int len; - len = strlen(PGXCNodeName); /* We use palloc0 here to ensure result is zero-padded */ result = (Name) palloc0(NAMEDATALEN); memcpy(NameStr(*result), PGXCNodeName, NAMEDATALEN - 1); diff --git a/src/backend/pgxc/squeue/squeue.c b/src/backend/pgxc/squeue/squeue.c index 2f782b92e8..83fe258f95 100644 --- a/src/backend/pgxc/squeue/squeue.c +++ b/src/backend/pgxc/squeue/squeue.c @@ -901,7 +901,7 @@ SharedQueueWrite(SharedQueue squeue, int consumerIdx, /* Create tuplestore if does not exist */ if (*tuplestore == NULL) { - int ptrno; + int ptrno PG_USED_FOR_ASSERTS_ONLY; char storename[64]; #ifdef SQUEUE_STAT diff --git a/src/backend/postmaster/clustermon.c b/src/backend/postmaster/clustermon.c index 34f571c03b..fbe5a1b044 100644 --- a/src/backend/postmaster/clustermon.c +++ b/src/backend/postmaster/clustermon.c @@ -403,7 +403,6 @@ GlobalTransactionId ClusterMonitorGetGlobalXmin(bool invalid_ok) { GlobalTransactionId xmin = InvalidGlobalTransactionId; - int retries = 0; SpinLockAcquire(&ClusterMonitorCtl->mutex); xmin = ClusterMonitorCtl->gtm_recent_global_xmin; diff --git a/src/backend/tcop/pquery.c b/src/backend/tcop/pquery.c index b4fb4c992e..4cae2a0bc7 100644 --- a/src/backend/tcop/pquery.c +++ b/src/backend/tcop/pquery.c @@ -2300,7 +2300,7 @@ AdvanceProducingPortal(Portal portal, bool can_wait) */ if (portal->holdStore == NULL && portal->status != PORTAL_FAILED) { - int idx; + int idx PG_USED_FOR_ASSERTS_ONLY; char storename[64]; PortalCreateProducerStore(portal); diff --git a/src/bin/pgxc_ctl/bash_handler.c b/src/bin/pgxc_ctl/bash_handler.c index c4aa1e27f1..b667436883 100644 --- a/src/bin/pgxc_ctl/bash_handler.c +++ b/src/bin/pgxc_ctl/bash_handler.c @@ -29,6 +29,7 @@ void install_pgxc_ctl_bash(char *path, int read_prototype) char cmd[1024]; FILE *pgxc_ctl_bash = fopen(path, "w"); int i; + int rc; elog(NOTICE, "Installing pgxc_ctl_bash script as %s.\n", path); if (!pgxc_ctl_bash) @@ -44,7 +45,9 @@ void install_pgxc_ctl_bash(char *path, int read_prototype) fprintf(pgxc_ctl_bash, "%s\n", pgxc_ctl_bash_script[i]); fclose(pgxc_ctl_bash); sprintf(cmd, "chmod +x %s", path); - system(cmd); + rc = system(cmd); + if (WEXITSTATUS(rc) != 0) + elog(ERROR, "failed to execute system command \"%s\"", cmd); } /* diff --git a/src/bin/pgxc_ctl/do_command.c b/src/bin/pgxc_ctl/do_command.c index 6fed22c0cf..16cda17d59 100644 --- a/src/bin/pgxc_ctl/do_command.c +++ b/src/bin/pgxc_ctl/do_command.c @@ -2090,14 +2090,13 @@ static void do_clean_command(char *line) continue; } } while(GetToken()); + if (cmdList) { - int rc; - rc = doCmdList(cmdList); + if (doCmdList(cmdList) != 0) + elog(ERROR, "failed to execute command list"); cleanCmdList(cmdList); - elog(INFO, "Done.\n"); } - return; } } diff --git a/src/bin/pgxc_ctl/do_shell.c b/src/bin/pgxc_ctl/do_shell.c index 5165ef3564..53951d4aa5 100644 --- a/src/bin/pgxc_ctl/do_shell.c +++ b/src/bin/pgxc_ctl/do_shell.c @@ -469,6 +469,7 @@ int doCmdList(cmdList_t *cmds) { int pid; pid = waitpid(cmds->cmds[ii]->pid, &status, 0); + (void ) pid; /* keep compiler quiet */ rc = WEXITSTATUS(status); } } @@ -522,9 +523,9 @@ int doCmdList(cmdList_t *cmds) void appendCmdEl(cmd_t *src, cmd_t *new) { - cmd_t *curr; + /* go to the end of the list */ + for(; src->next; src = src->next); - for(curr = src; src->next; src = src->next); src->next = new; } diff --git a/src/bin/pgxc_ctl/monitor.c b/src/bin/pgxc_ctl/monitor.c index f14c24bb47..02997c8322 100644 --- a/src/bin/pgxc_ctl/monitor.c +++ b/src/bin/pgxc_ctl/monitor.c @@ -279,7 +279,6 @@ static void monitor_something(char **nodeList) void do_monitor_command(char *line) { char *token; - int rc = 0; if (!GetToken()) { @@ -302,10 +301,10 @@ void do_monitor_command(char *line) if (isVarYes(VAR_gtmSlave)) monitor_gtm_slave(); else - elog(ERROR, "ERROR: gtm slave is not configured.\n"), rc=-1; + elog(ERROR, "ERROR: gtm slave is not configured.\n"); } else - elog(ERROR, "Invalid monitor gtm command option.\n"), rc=-1; + elog(ERROR, "Invalid monitor gtm command option.\n"); return; } else if (TestToken("gtm_proxy")) @@ -349,7 +348,7 @@ void do_monitor_command(char *line) else if (TestToken("slave")) { if (!isVarYes(VAR_coordSlave)) - elog(ERROR, "ERROR: coordinator slave is not configured.\n"), rc = -1; + elog(ERROR, "ERROR: coordinator slave is not configured.\n"); else if (!GetToken() || TestToken("all")) monitor_coordinator_slave(aval(VAR_coordNames)); @@ -398,7 +397,7 @@ void do_monitor_command(char *line) else if (TestToken("slave")) { if (!isVarYes(VAR_coordSlave)) - elog(ERROR, "ERROR: datanode slave is not configured.\n"), rc = -1; + elog(ERROR, "ERROR: datanode slave is not configured.\n"); else if (!GetToken() || TestToken("all")) monitor_datanode_slave(aval(VAR_coordNames)); diff --git a/src/bin/pgxc_ctl/pgxc_ctl.c b/src/bin/pgxc_ctl/pgxc_ctl.c index 81d732753d..d36fb4f2d9 100644 --- a/src/bin/pgxc_ctl/pgxc_ctl.c +++ b/src/bin/pgxc_ctl/pgxc_ctl.c @@ -151,6 +151,7 @@ set_bash: { struct stat buf; char cmd[MAXLINE+1]; + int rc; if (stat(pgxc_ctl_home, &buf) ==0) { @@ -166,7 +167,14 @@ set_bash: } } snprintf(cmd, MAXLINE, "mkdir -p %s", pgxc_ctl_home); - system(cmd); + + rc = system(cmd); + if (WEXITSTATUS(rc) != 0) + { + fprintf(stderr, "failed to execute system command \"%s\"", cmd); + exit(1); + } + if (stat(pgxc_ctl_home, &buf) ==0) { if (S_ISDIR(buf.st_mode)) @@ -289,10 +297,16 @@ static void prepare_pgxc_ctl_bash(char *path) static void pgxcCtlMkdir(char *path) { - char cmd[MAXPATH+1]; + char cmd[MAXPATH+1]; + int rc; snprintf(cmd, MAXPATH, "mkdir -p %s", path); - system(cmd); + rc = system(cmd); + if (WEXITSTATUS(rc) != 0) + { + fprintf(stderr, "failed to execute system command \"%s\"", cmd); + exit(1); + } } static void startLog(char *path, char *logFileNam) diff --git a/src/bin/pgxc_ctl/utils.c b/src/bin/pgxc_ctl/utils.c index 501e7f83ea..4c8f7dd2b5 100644 --- a/src/bin/pgxc_ctl/utils.c +++ b/src/bin/pgxc_ctl/utils.c @@ -397,8 +397,15 @@ char *getIpAddress(char *hostName) elog(ERROR, "ERROR: could not open the command, \"%s\", %s\n", command, strerror(errno)); return NULL; } + ipAddr = Malloc(MAXTOKEN+1); - fgets(ipAddr, MAXTOKEN, f); + if (fgets(ipAddr, MAXTOKEN, f) == NULL) + { + elog(ERROR, "could not get IP address from the command \"%s\"", + command); + return NULL; + } + pclose(f); trimNl(ipAddr); return ipAddr; -- 2.39.5