Dear Michael,

Thanks for creating the patch! Let me confirm two points:

Apart from functions related with injection_points, this can be called even when
postgres has been built with -Dinjection_points=false. This is intentional 
because
this function does not have any side-effect and just refers the status. Is my
understanding correct?

I'm not sure it is directly related, but ISTM there are no direct ways to check
whether the injection_points is enabled or not. How do you think adding the
function?


Regarding the internal of the patch, it could be crashed when two points are
attached and then first one is detached [1]. I think we should not use "idx" for
the result array - PSA the fix.

[1]:
```
SELECT injection_points_attach('TestInjectionLog', 'notice');
 injection_points_attach 
-------------------------
 
(1 row)

SELECT injection_points_attach('TestInjectionError', 'error');
 injection_points_attach 
-------------------------
 
(1 row)

SELECT injection_points_detach('TestInjectionLog');
 injection_points_detach 
-------------------------
 
(1 row)

SELECT name, library, function FROM pg_get_injection_points()
  ORDER BY name COLLATE "C";
server closed the connection unexpectedly
        This probably means the server terminated abnormally
        before or while processing the request.
connection to server was lost
```

Best regards,
Hayato Kuroda
FUJITSU LIMITED

diff --git a/src/backend/utils/misc/injection_point.c 
b/src/backend/utils/misc/injection_point.c
index bf1a49f7472..ea7e6dba521 100644
--- a/src/backend/utils/misc/injection_point.c
+++ b/src/backend/utils/misc/injection_point.c
@@ -596,6 +596,7 @@ InjectionPointList(uint32 *num_points)
 #ifdef USE_INJECTION_POINTS
        InjectionPointData *result;
        uint32          max_inuse;
+       int                     cur_pos = 0;
 
        LWLockAcquire(InjectionPointLock, LW_SHARED);
 
@@ -619,14 +620,16 @@ InjectionPointList(uint32 *num_points)
                if (generation % 2 == 0)
                        continue;
 
-               result[idx].name = pstrdup(entry->name);
-               result[idx].library = pstrdup(entry->library);
-               result[idx].function = pstrdup(entry->function);
-               (*num_points)++;
+               result[cur_pos].name = pstrdup(entry->name);
+               result[cur_pos].library = pstrdup(entry->library);
+               result[cur_pos].function = pstrdup(entry->function);
+               cur_pos++;
        }
 
        LWLockRelease(InjectionPointLock);
 
+       *num_points = cur_pos;
+
        return result;
 
 #else

Reply via email to