--- /dev/null
+/*********************************************************
+ * Copyright (C) 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
+ * by the Free Software Foundation version 2.1 and no later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the Lesser GNU General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ *********************************************************/
+
+/*
+ * logToHost.h --
+ *
+ * Log function prototypes to discretionarily direct log to the host or the
+ * guest.
+ */
+
+#ifndef __LOG_TO_HOST_H__
+#define __LOG_TO_HOST_H__
+
+void WarningToGuest(const char *fmt, ...);
+void WarningToHost(const char *fmt, ...);
+
+#endif /* __LOG_TO_HOST_H__ */
#include "strutil.h"
#include "codeset.h"
#include "unicode.h"
+#include "logToHost.h"
#ifdef USERWORLD
#include <vm_basic_types.h>
#include <vmkusercompat.h>
#endif
+
/*
* All signals that:
* . Can terminate the process
ret = setresgid(ppw->pw_gid, ppw->pw_gid, root_gid);
#endif
if (ret < 0) {
- Warning("Failed to set gid for user %s\n", user);
+ WarningToGuest("Failed to set gid for user %s\n", user);
+ WarningToHost("Failed to set gid\n");
return FALSE;
}
#ifndef USERWORLD
ret = initgroups(ppw->pw_name, ppw->pw_gid);
if (ret < 0) {
- Warning("Failed to initgroups() for user %s\n", user);
+ WarningToGuest("Failed to initgroups() for user %s\n", user);
+ WarningToHost("Failed to initgroups()\n");
goto failure;
}
#endif
ret = setresuid(ppw->pw_uid, ppw->pw_uid, 0);
#endif
if (ret < 0) {
- Warning("Failed to set uid for user %s\n", user);
+ WarningToGuest("Failed to set uid for user %s\n", user);
+ WarningToHost("Failed to set uid\n");
goto failure;
}
#include "vmware/tools/guestrpc.h"
#include "vmware/guestrpc/tclodefs.h"
#include "err.h"
+#include "logToHost.h"
#define LOGGING_GROUP "logging"
GLogLevelFlags level,
const gchar *message);
void Debug(const char *fmt, ...);
+static void LogWhereLevelV(LogWhere where,
+ GLogLevelFlags level,
+ const gchar *domain,
+ const gchar *fmt,
+ va_list args);
/* Internal functions. */
}
+/*
+ *******************************************************************************
+ * VmwareLogWrapper -- */ /**
+ *
+ * Generic wrapper for VMware log functions to directly log to either guest
+ * or host.
+ *
+ * @param[in] where Log to host or guest.
+ * @param[in] level Log level.
+ * @param[in] fmt Message format.
+ * @param[in] args Message arguments.
+ *
+ *******************************************************************************
+ */
+
+static void
+VmwareLogWrapper(LogWhere where,
+ GLogLevelFlags level,
+ const char *fmt,
+ va_list args)
+{
+ if (!gLogInitialized && !IS_FATAL(level)) {
+ /*
+ * Avoid logging without initialization because
+ * it leads to spamming of the console output.
+ * Fatal messages are exception.
+ */
+ return;
+ }
+
+ VMTools_AcquireLogStateLock();
+
+ LogWhereLevelV(where, level, gLogDomain, fmt, args);
+
+ VMTools_ReleaseLogStateLock();
+}
+
+
+/*
+ *******************************************************************************
+ * WarningToHost -- */ /**
+ *
+ * Logs a message at the host side using the G_LOG_LEVEL_WARNING level
+ *
+ * @param[in] fmt Log message format.
+ *
+ *******************************************************************************
+ */
+
+void
+WarningToHost(const char *fmt, ...)
+{
+ va_list args;
+ va_start(args, fmt);
+ if (gGuestSDKMode) {
+ GuestSDK_Warning(fmt, args);
+ } else {
+ WITH_ERRNO(err,
+ VmwareLogWrapper(TO_HOST, G_LOG_LEVEL_WARNING, fmt, args));
+ }
+ va_end(args);
+}
+
+
+/*
+ *******************************************************************************
+ * WarningToGuest -- */ /**
+ *
+ * Logs a message at the guest side using the G_LOG_LEVEL_WARNING level
+ *
+ * @param[in] fmt Log message format.
+ *
+ *******************************************************************************
+ */
+
+void
+WarningToGuest(const char *fmt, ...)
+{
+ va_list args;
+ va_start(args, fmt);
+ if (gGuestSDKMode) {
+ GuestSDK_Warning(fmt, args);
+ } else {
+ WITH_ERRNO(err,
+ VmwareLogWrapper(IN_GUEST, G_LOG_LEVEL_WARNING, fmt, args));
+ }
+ va_end(args);
+}
+
+
/*
*******************************************************************************
* VMTools_ChangeLogFilePath -- */ /**