Le 28/01/2026 à 13:44, Euler Taveira a écrit :
On Fri, Jan 9, 2026, at 8:27 AM, Gilles Darold wrote:
Here is a v11 version of the patch.

+           if (result <= (TimestampTz) password_expire_warning)
+           {
+               MyClientConnectionInfo.warning_message =
+                   psprintf(_("your password will expire in %d day(s)"),
+                            (int) (result / SECS_PER_DAY));
+           }

You should use ngettext() for plural forms.

Is it a use we must do now or a wish?

   $ grep -r "ngettext(" src/backend/ | wc -l
   9
   $ grep -r "(s)" src/backend/ | wc -l
   831

If this is not a must do now, I prefer to use the old way because we don't have to repeat 2 times the constant.


I don't think you need a string into ClientConnectionInfo. Instead, you could 
store only the number of days.

+   /*
+    * Emit a warning message to the client when set, for example
+    * to warn the user that the password will expire.
+    */
+   if (MyClientConnectionInfo.warning_message)
+       ereport(WARNING, (errmsg("%s", 
MyClientConnectionInfo.warning_message)));
+

... and you construct the message directly in the ereport().


I have explained this choice in my first message:

"I have chosen to add a new field, const char *warning_message, to struct ClientConnectionInfo so that it can be used to send other messages to the client at end of connection ( src/backend/utils/init/postinit.c: InitPostgres() ). Not sure sure that this is the best way to do that but as it is a message dedicated to the connection I've though it could be the right place. If we don't expect other warning message sent to the client at connection time, just using an integer for the number of days remaining will be enough. We could use notice but it is not logged by default and also I think that warning is the good level for this message. "

--
Gilles Darold
http://hexacluster.ai/

Reply via email to