Fix a few compiler warnings
authorPavan Deolasee <[email protected]>
Fri, 14 Sep 2018 04:43:54 +0000 (10:13 +0530)
committerPavan Deolasee <[email protected]>
Fri, 14 Sep 2018 04:43:54 +0000 (10:13 +0530)
src/gtm/client/gtm_client.c
src/gtm/common/elog.c
src/gtm/recovery/register_common.c

index a9e0c6f911e573898da8d889ce31db890545711c..1f069a6eeffc89ef95af092cfbca04985edf37f9 100644 (file)
@@ -1077,7 +1077,7 @@ get_snapshot(GTM_Conn *conn, GlobalTransactionId gxid, bool canbe_grouped)
 {
        GTM_Result *res = NULL;
        time_t finish_time;
-       GTM_ResultType res_type;
+       GTM_ResultType res_type PG_USED_FOR_ASSERTS_ONLY;
 
        res_type = canbe_grouped ? SNAPSHOT_GET_MULTI_RESULT : SNAPSHOT_GET_RESULT;
 
index 4bda0c103c9642242fd9c303e080e725d37bfcf6..11a362f2a2d4665bb587bc9562333e815929b7e8 100644 (file)
@@ -846,7 +846,11 @@ send_message_to_server_log(ErrorData *edata)
 
        /* Write to stderr, if enabled */
        if (Log_destination & LOG_DESTINATION_STDERR)
-               write(fileno(stderr), buf.data, buf.len);
+       {
+               /* keep compiler quiet */
+               int rc = write(fileno(stderr), buf.data, buf.len);
+               (void) rc;
+       }
 
        pfree(buf.data);
 }
index a77c5896fc3a5e55cea2bd5c17f7b9df8c6ea597..236c43a7a5ce29661c9da92b52956a65398821df 100644 (file)
@@ -478,20 +478,11 @@ Recovery_SaveRegisterInfo(void)
        GTM_PGXCNodeInfo *nodeinfo = NULL;
        int hash, ctlfd;
        char filebkp[GTM_NODE_FILE_MAX_PATH];
+       StringInfoData  buf;
 
-       GTM_RWLockAcquire(&RegisterFileLock, GTM_LOCKMODE_WRITE);
-
-       /* Create a backup file in case their is a problem during file writing */
-       sprintf(filebkp, "%s.bkp", GTMPGXCNodeFile);
+       initStringInfo(&buf);
 
-       ctlfd = open(filebkp, O_WRONLY | O_CREAT | O_TRUNC,
-                                S_IRUSR | S_IWUSR);
-
-       if (ctlfd < 0)
-       {
-               GTM_RWLockRelease(&RegisterFileLock);
-               return;
-       }
+       GTM_RWLockAcquire(&RegisterFileLock, GTM_LOCKMODE_WRITE);
 
        GTM_RWLockAcquire(&PGXCNodesLock, GTM_LOCKMODE_READ);
        for (hash = 0; hash < NODE_HASH_TABLE_SIZE; hash++)
@@ -509,68 +500,91 @@ Recovery_SaveRegisterInfo(void)
 
                        GTM_RWLockAcquire(&nodeinfo->node_lock, GTM_LOCKMODE_READ);
 
-                       write(ctlfd, &NodeRegisterMagic, sizeof (NodeRegisterMagic));
+                       appendBinaryStringInfo(&buf, (const char *) &NodeRegisterMagic, sizeof (NodeRegisterMagic));
+                       appendBinaryStringInfo(&buf, (const char *) &nodeinfo->type, sizeof (GTM_PGXCNodeType));
 
-                       write(ctlfd, &nodeinfo->type, sizeof (GTM_PGXCNodeType));
                        if (nodeinfo->nodename)
                        {
                                len = strlen(nodeinfo->nodename);
-                               write(ctlfd, &len, sizeof(uint32));
-                               write(ctlfd, nodeinfo->nodename, len);
+                               appendBinaryStringInfo(&buf, (const char *) &len, sizeof(uint32));
+                               appendBinaryStringInfo(&buf, (const char *) nodeinfo->nodename, len);
                        }
                        else
                        {
                                len = 0;
-                               write(ctlfd, &len, sizeof(uint32));
+                               appendBinaryStringInfo(&buf, (const char *) &len, sizeof(uint32));
                        }
 
-                       write(ctlfd, &nodeinfo->port, sizeof (GTM_PGXCNodePort));
+                       appendBinaryStringInfo(&buf, (const char *) &nodeinfo->port, sizeof (GTM_PGXCNodePort));
 
                        if (nodeinfo->proxyname)
                        {
                                len = strlen(nodeinfo->proxyname);
-                               write(ctlfd, &len, sizeof(uint32));
-                               write(ctlfd, nodeinfo->proxyname, len);
+                               appendBinaryStringInfo(&buf, (const char *) &len, sizeof(uint32));
+                               appendBinaryStringInfo(&buf, (const char *) nodeinfo->proxyname, len);
                        }
                        else
                        {
                                len = 0;
-                               write(ctlfd, &len, sizeof(uint32));
+                               appendBinaryStringInfo(&buf, (const char *) &len, sizeof(uint32));
                        }
 
-                       write(ctlfd, &nodeinfo->status, sizeof (GTM_PGXCNodeStatus));
+                       appendBinaryStringInfo(&buf, (const char *) &nodeinfo->status, sizeof (GTM_PGXCNodeStatus));
 
                        if (nodeinfo->ipaddress)
                        {
                                len = strlen(nodeinfo->ipaddress);
-                               write(ctlfd, &len, sizeof(uint32));
-                               write(ctlfd, nodeinfo->ipaddress, len);
+                               appendBinaryStringInfo(&buf, (const char *) &len, sizeof(uint32));
+                               appendBinaryStringInfo(&buf, (const char *) nodeinfo->ipaddress, len);
                        }
                        else
                        {
                                len = 0;
-                               write(ctlfd, &len, sizeof(uint32));
+                               appendBinaryStringInfo(&buf, (const char *) &len, sizeof(uint32));
                        }
 
                        if (nodeinfo->datafolder)
                        {
                                len = strlen(nodeinfo->datafolder);
-                               write(ctlfd, &len, sizeof(uint32));
-                               write(ctlfd, nodeinfo->datafolder, len);
+                               appendBinaryStringInfo(&buf, (const char *) &len, sizeof(uint32));
+                               appendBinaryStringInfo(&buf, (const char *) nodeinfo->datafolder, len);
                        }
                        else
                        {
                                len = 0;
-                               write(ctlfd, &len, sizeof(uint32));
+                               appendBinaryStringInfo(&buf, (const char *) &len, sizeof(uint32));
                        }
 
-                       write(ctlfd, &NodeEndMagic, sizeof(NodeEndMagic));
+                       appendBinaryStringInfo(&buf, (const char *) &NodeEndMagic, sizeof(NodeEndMagic));
 
                        GTM_RWLockRelease(&nodeinfo->node_lock);
                }
        }
        GTM_RWLockRelease(&PGXCNodesLock);
 
+       /* Create a backup file in case their is a problem during file writing */
+       sprintf(filebkp, "%s.bkp", GTMPGXCNodeFile);
+
+       ctlfd = open(filebkp, O_WRONLY | O_CREAT | O_TRUNC,
+                                S_IRUSR | S_IWUSR);
+
+       if (ctlfd < 0)
+       {
+               GTM_RWLockRelease(&RegisterFileLock);
+               elog(ERROR, "could not open registration backup file \"%s\"",
+                               filebkp);
+               return;
+       }
+       if (write(ctlfd, buf.data, buf.len) != buf.len)
+       {
+               GTM_RWLockRelease(&RegisterFileLock);
+               elog(ERROR, "could not write to registration backup file \"%s\"",
+                               filebkp);
+               return;
+       }
+
+       pfree(buf.data);
+
        close(ctlfd);
 
        /* Replace former file by backup file */
@@ -588,91 +602,101 @@ Recovery_SaveRegisterInfo(void)
 static void
 Recovery_RecordRegisterInfo(GTM_PGXCNodeInfo *nodeinfo, bool is_register)
 {
-       int ctlfd;
-       int len;
-
-       GTM_RWLockAcquire(&RegisterFileLock, GTM_LOCKMODE_WRITE);
+       int                             ctlfd;
+       int                             len;
+       StringInfoData  buf;
 
-       ctlfd = open(GTMPGXCNodeFile, O_WRONLY | O_CREAT | O_APPEND,
-                                S_IRUSR | S_IWUSR);
-
-       if (ctlfd == -1 || nodeinfo == NULL)
-       {
-               GTM_RWLockRelease(&RegisterFileLock);
-               return;
-       }
+       initStringInfo(&buf);
 
+       GTM_RWLockAcquire(&RegisterFileLock, GTM_LOCKMODE_WRITE);
        GTM_RWLockAcquire(&nodeinfo->node_lock, GTM_LOCKMODE_READ);
 
        if (is_register)
-               write(ctlfd, &NodeRegisterMagic, sizeof (NodeRegisterMagic));
+               appendBinaryStringInfo(&buf, (const char *) &NodeRegisterMagic, sizeof (NodeRegisterMagic));
        else
-               write(ctlfd, &NodeUnregisterMagic, sizeof (NodeUnregisterMagic));
+               appendBinaryStringInfo(&buf, (const char *) &NodeUnregisterMagic, sizeof (NodeUnregisterMagic));
 
-       write(ctlfd, &nodeinfo->type, sizeof (GTM_PGXCNodeType));
+       appendBinaryStringInfo(&buf, (const char *) &nodeinfo->type, sizeof (GTM_PGXCNodeType));
 
        if (nodeinfo->nodename)
        {
                len = strlen(nodeinfo->nodename);
-               write(ctlfd, &len, sizeof(uint32));
-               write(ctlfd, nodeinfo->nodename, len);
+               appendBinaryStringInfo(&buf, (const char *) &len, sizeof(uint32));
+               appendBinaryStringInfo(&buf, (const char *) nodeinfo->nodename, len);
        }
        else
        {
                len = 0;
-               write(ctlfd, &len, sizeof(uint32));
+               appendBinaryStringInfo(&buf, (const char *) &len, sizeof(uint32));
        }
 
        if (is_register)
        {
                int len;
 
-               write(ctlfd, &nodeinfo->port, sizeof (GTM_PGXCNodePort));
+               appendBinaryStringInfo(&buf, (const char *) &nodeinfo->port, sizeof (GTM_PGXCNodePort));
 
                if (nodeinfo->proxyname)
                {
                        len = strlen(nodeinfo->proxyname);
-                       write(ctlfd, &len, sizeof(uint32));
-                       write(ctlfd, nodeinfo->proxyname, len);
+                       appendBinaryStringInfo(&buf, (const char *) &len, sizeof(uint32));
+                       appendBinaryStringInfo(&buf, (const char *) nodeinfo->proxyname, len);
                }
                else
                {
                        len = 0;
-                       write(ctlfd, &len, sizeof(uint32));
+                       appendBinaryStringInfo(&buf, (const char *) &len, sizeof(uint32));
                }
 
-               write(ctlfd, &nodeinfo->status, sizeof (GTM_PGXCNodeStatus));
+               appendBinaryStringInfo(&buf, (const char *) &nodeinfo->status, sizeof (GTM_PGXCNodeStatus));
 
                if (nodeinfo->ipaddress)
                {
                        len = strlen(nodeinfo->ipaddress);
-                       write(ctlfd, &len, sizeof(uint32));
-                       write(ctlfd, nodeinfo->ipaddress, len);
+                       appendBinaryStringInfo(&buf, (const char *) &len, sizeof(uint32));
+                       appendBinaryStringInfo(&buf, (const char *) nodeinfo->ipaddress, len);
                }
                else
                {
                        len = 0;
-                       write(ctlfd, &len, sizeof(uint32));
+                       appendBinaryStringInfo(&buf, (const char *) &len, sizeof(uint32));
                }
 
                if (nodeinfo->datafolder)
                {
                        len = strlen(nodeinfo->datafolder);
-                       write(ctlfd, &len, sizeof(uint32));
-                       write(ctlfd, nodeinfo->datafolder, len);
+                       appendBinaryStringInfo(&buf, (const char *) &len, sizeof(uint32));
+                       appendBinaryStringInfo(&buf, (const char *) nodeinfo->datafolder, len);
                }
                else
                {
                        len = 0;
-                       write(ctlfd, &len, sizeof(uint32));
+                       appendBinaryStringInfo(&buf, (const char *) &len, sizeof(uint32));
                }
        }
 
-       write(ctlfd, &NodeEndMagic, sizeof(NodeEndMagic));
+       appendBinaryStringInfo(&buf, (const char *) &NodeEndMagic, sizeof(NodeEndMagic));
 
-       GTM_RWLockRelease(&nodeinfo->node_lock);
+       ctlfd = open(GTMPGXCNodeFile, O_WRONLY | O_CREAT | O_APPEND,
+                                S_IRUSR | S_IWUSR);
+
+       if (ctlfd == -1 || nodeinfo == NULL)
+       {
+               GTM_RWLockRelease(&RegisterFileLock);
+               return;
+       }
+
+       if (write(ctlfd, buf.data, buf.len) != buf.len)
+       {
+               GTM_RWLockRelease(&RegisterFileLock);
+               return;
+       }
+
+       pfree(buf.data);
 
        close(ctlfd);
+
+       GTM_RWLockRelease(&nodeinfo->node_lock);
        GTM_RWLockRelease(&RegisterFileLock);
 }