pkubat / rpms / pg_journal

Forked from rpms/pg_journal 5 years ago
Clone
Blob Blame History Raw
diff -uNr pg_journal-0.2.0.old/src/pg_journal.c pg_journal-0.2.0.rm_fmt/src/pg_journal.c
--- pg_journal-0.2.0.old/src/pg_journal.c	2013-05-17 17:19:06.000000000 +0000
+++ pg_journal-0.2.0.rm_fmt/src/pg_journal.c	2016-04-12 17:28:28.033445748 +0000
@@ -206,6 +206,15 @@
 }
 
 static void
+append_int(StringInfo str, struct iovec *field, const char *key, int value)
+{
+	char value_str[1024];
+	
+	sprintf(value_str, "%d", value);
+	append_string(str, field, key, value_str);
+}
+
+static void
 append_string3(StringInfo str, struct iovec *field, const char *key,
 			   const char *s1, const char *s2, const char *s3)
 {
@@ -219,36 +228,7 @@
 	field->iov_len = str->len - old_len;
 }
 
-static void
-append_fmt(StringInfo str, struct iovec *field, const char *fmt, ...)
-/* This extension allows gcc to check the format string */
-__attribute__((format(PG_PRINTF_ATTRIBUTE, 3, 4)));
-
-/* See backend/lib/stringinfo.c function appendStringInfo */
-static void
-append_fmt(StringInfo str, struct iovec *field, const char *fmt, ...)
-{
-	size_t old_len = str->len;
-	va_list args;
-	bool success;
-
-	/* appendStringInfoVA can fail due to insufficient space */
-	while (1) {
-		va_start(args, fmt);
-		success = appendStringInfoVA(str, fmt, args);
-		va_end(args);
-
-		if (success)
-			break;
-
-		/* Double the buffer size and try again. */
-		enlargeStringInfo(str, str->maxlen);
-	}
-
-	field->iov_len = str->len - old_len;
-}
-
-#define MAX_FIELDS	 23 /* NB! Keep this in sync when adding fields! */
+#define MAX_FIELDS	 25 /* NB! Keep this in sync when adding fields! */
 
 static void
 journal_emit_log(ErrorData *edata)
@@ -283,8 +263,8 @@
 										   ":  ",
 										   edata->message);
 
-	append_fmt(&buf, &fields[n++], "PRIORITY=%d", elevel_to_syslog(edata->elevel));
-	append_fmt(&buf, &fields[n++], "PGLEVEL=%d", edata->elevel);
+	append_int(&buf, &fields[n++], "PRIORITY=", elevel_to_syslog(edata->elevel));
+	append_int(&buf, &fields[n++], "PGLEVEL=", edata->elevel);
 
 	if (edata->sqlerrcode)
 		append_string(&buf, &fields[n++], "SQLSTATE=",
@@ -329,7 +309,7 @@
 	if (edata->filename)
 		append_string(&buf, &fields[n++], "CODE_FILE=", edata->filename);
 	if (edata->lineno > 0)
-		append_fmt(&buf, &fields[n++],    "CODE_LINE=%d", edata->lineno);
+		append_int(&buf, &fields[n++],    "CODE_LINE=", edata->lineno);
 	if (edata->funcname)
 		append_string(&buf, &fields[n++], "CODE_FUNCTION=", edata->funcname);
 #endif /* SD_JOURNAL_SUPPRESS_LOCATION */