summaryrefslogtreecommitdiffstats
path: root/runtime/msg.c
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2013-06-24 12:18:40 +0200
committerRainer Gerhards <rgerhards@adiscon.com>2013-06-24 12:18:40 +0200
commitaa2408f825cd46091af0a8976dc2c14b1b797206 (patch)
treef326a5da550ed154d3127c57327e542143a78aad /runtime/msg.c
parentb8aaacd9ccf5efb353ecf15fe83a976ad44cf6cf (diff)
downloadrsyslog-aa2408f825cd46091af0a8976dc2c14b1b797206.tar.gz
rsyslog-aa2408f825cd46091af0a8976dc2c14b1b797206.tar.bz2
rsyslog-aa2408f825cd46091af0a8976dc2c14b1b797206.zip
$uptime property: fix mem leak and build problems on FreeBSD
Diffstat (limited to 'runtime/msg.c')
-rw-r--r--runtime/msg.c30
1 files changed, 27 insertions, 3 deletions
diff --git a/runtime/msg.c b/runtime/msg.c
index a5c52810..8c50b7b3 100644
--- a/runtime/msg.c
+++ b/runtime/msg.c
@@ -2989,15 +2989,39 @@ uchar *MsgGetProp(msg_t *pMsg, struct templateEntry *pTpe,
break;
case PROP_SYS_UPTIME:
# ifndef HAVE_SYSINFO_UPTIME
- /* An alternative on some systems (eg Solaris) is to scan
- * /var/adm/utmpx for last boot time.
- */
+ /* An alternative on some systems (eg Solaris) is to scan
+ * /var/adm/utmpx for last boot time.
+ */
pRes = (uchar*) "UPTIME NOT available on this system";
*pbMustBeFreed = 0;
+
+# elseif defined(__FreeBSD__)
+
+ {
+ struct timespec tp;
+
+ if(*pbMustBeFreed == 1)
+ free(pRes);
+ if((pRes = (uchar*) MALLOC(sizeof(uchar) * 32)) == NULL) {
+ RET_OUT_OF_MEMORY;
+ }
+ *pbMustBeFreed = 1;
+
+ if(clock_gettime(CLOCK_UPTIME, &tp) == -1) {
+ *pPropLen = sizeof("**SYSCALL FAILED**") - 1;
+ return(UCHAR_CONSTANT("**SYSCALL FAILED**"));
+ }
+
+ snprintf((char*) pRes, sizeof(uchar) * 32, "%ld", tp.tv_sec);
+ }
+
# else
+
{
struct sysinfo s_info;
+ if(*pbMustBeFreed == 1)
+ free(pRes);
if((pRes = (uchar*) MALLOC(sizeof(uchar) * 32)) == NULL) {
RET_OUT_OF_MEMORY;
}