/*********************************************************
- * Copyright (C) 1998-2016 VMware, Inc. All rights reserved.
+ * Copyright (C) 1998-2016,2018 VMware, Inc. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published
uint64 System_GetTimeMonotonic(void);
uint64 System_Uptime(void);
-char *System_GetTimeAsString(void);
void System_Shutdown(Bool reboot);
Bool System_GetNodeName(size_t outBufSize, char *outBuf);
/*********************************************************
- * Copyright (C) 2008-2017 VMware, Inc. All rights reserved.
+ * Copyright (C) 2008-2018 VMware, Inc. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published
void
VMTools_RestartLogging(void);
+gchar *
+VMTools_GetTimeAsString(void);
+
void
VMTools_SuspendLogIO(void);
/*********************************************************
- * Copyright (C) 1998-2017 VMware, Inc. All rights reserved.
+ * Copyright (C) 1998-2018 VMware, Inc. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published
}
-/*
- *-----------------------------------------------------------------------------
- *
- * System_GetTimeAsString --
- *
- * Returns the current time as a formatted string, useful for prepending
- * to debugging output.
- *
- * For example: "Oct 05 18:03:24.948"
- *
- * Results:
- * On success, allocates and returns a string containing the formatted
- * time.
- * On failure, returns NULL.
- *
- * Side effects:
- * None.
- *
- *-----------------------------------------------------------------------------
- */
-
-char *
-System_GetTimeAsString(void)
-{
- struct timeval tv;
- time_t sec;
- int msec;
- size_t charsWritten;
- size_t bufSize = 8; // Multiplied by 2 for the initial allocation.
- char *buf = NULL;
- char *dateTime = NULL;
- char *output = NULL;
-
- if (gettimeofday(&tv, NULL)) {
- goto out;
- }
- sec = tv.tv_sec;
- msec = tv.tv_usec / 1000;
-
- /*
- * Loop repeatedly trying to format the time into a buffer, doubling the
- * buffer with each failure. This should be safe as the manpage for
- * strftime(3) seems to suggest that it only fails if the buffer isn't large
- * enough.
- *
- * The resultant string is encoded according to the current locale.
- */
- do {
- char *newBuf;
- bufSize *= 2;
-
- newBuf = realloc(buf, bufSize);
- if (newBuf == NULL) {
- goto out;
- }
- buf = newBuf;
- charsWritten = strftime(buf, bufSize, "%b %d %H:%M:%S", localtime(&sec));
- } while (charsWritten == 0);
-
- /*
- * Append the milliseconds field, but only after converting the date/time
- * string from encoding specified in the current locale to an opaque type.
- */
- dateTime = Unicode_Alloc(buf, STRING_ENCODING_DEFAULT);
- if (dateTime == NULL) {
- goto out;
- }
- output = Unicode_Format("%s.%03d", dateTime, msec);
-
- out:
- free(buf);
- free(dateTime);
- return output;
-}
-
-
/*
*-----------------------------------------------------------------------------
*
}
+/**
+ * VMTools_GetTimeAsString --
+ *
+ * Returns the current UTC timestamp information
+ *
+ * Ex: "2018-02-22T21:17:38.517Z"
+ *
+ * The caller must free the return value using g_free
+ *
+ * @return Properly formatted string that contains the timestamp.
+ * NULL if the timestamp cannot be retrieved.
+ */
+
+gchar *
+VMTools_GetTimeAsString(void)
+{
+ gchar *timePrefix = NULL;
+ GDateTime *utcTime = g_date_time_new_now_utc();
+
+ if (utcTime != NULL) {
+ gchar *dateFormat = g_date_time_format(utcTime, "%FT%T");
+
+ if (dateFormat != NULL) {
+ gint msec = g_date_time_get_microsecond(utcTime) / 1000;
+
+ timePrefix = g_strdup_printf("%s.%03dZ", dateFormat, msec);
+
+ g_free(dateFormat);
+ dateFormat = NULL;
+ }
+
+ g_date_time_unref(utcTime);
+ }
+
+ return timePrefix;
+}
+
+
/**
* Creates a formatted message to be logged. The format of the message will be:
*
size_t len = 0;
gboolean shared = TRUE;
gboolean addsTimestamp = TRUE;
- char *tstamp;
+ gchar *tstamp;
if (domain == NULL) {
domain = gLogDomain;
addsTimestamp = data->logger->addsTimestamp;
}
- tstamp = System_GetTimeAsString();
+ tstamp = VMTools_GetTimeAsString();
if (!addsTimestamp) {
if (shared) {
}
}
- free(tstamp);
+ g_free(tstamp);
/*
* The log messages from glib itself (and probably other libraries based
#include "deployPkgInt.h"
#include "imgcust-common/log.h"
-#include <glib.h>
#include "util.h"
#include "file.h"
#include "str.h"
+#include "vmware/tools/utils.h"
#include <stdio.h>
}
-/*
- *----------------------------------------------------------------------
- *
- * DeployPkgLogGetTimeAsString --
- *
- * Returns the current UTC timestamp information that should be printed
- * at the beginning of each log message.
- *
- * Ex: "2018-02-22T21:17:38.517Z"
- *
- * The caller must free the return value using g_free
- *
- * Results:
- * Properly formatted string that contains the timestamp.
- * NULL if the timestamp cannot be retrieved.
- *
- * Side effects:
- * None
- *
- *----------------------------------------------------------------------
- */
-
-static gchar*
-DeployPkgLogGetTimeAsString()
-{
- gchar *timePrefix = NULL;
- GDateTime *utcTime = g_date_time_new_now_utc();
-
- if (utcTime != NULL) {
- gchar *dateFormat = g_date_time_format(utcTime, "%FT%T");
-
- if (dateFormat != NULL) {
- gint msec = g_date_time_get_microsecond(utcTime) / 1000;
-
- timePrefix = g_strdup_printf("%s.%03dZ", dateFormat, msec);
-
- g_free(dateFormat);
- dateFormat = NULL;
- }
-
- g_date_time_unref(utcTime);
- }
-
- return timePrefix;
-}
-
-
/*
*----------------------------------------------------------------------
*
}
va_start(args, fmtstr);
- tstamp = DeployPkgLogGetTimeAsString();
+ tstamp = VMTools_GetTimeAsString();
fprintf(_file, "[%s] [%8s] ",
(tstamp != NULL) ? tstamp : "no time", logLevel);
vfprintf(_file, fmtstr, args);