main.cpp revision 0c185819ebfc2c615efe0d9edd4e12b950fadc68
5b281ba489ca18f0380d7efc7a5108b606cce449vboxsync * VirtualBox Guest Service:
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync * Linux guest.
e86794d5ed13ea3053cb8f12be80630236ef2943vboxsync * Copyright (C) 2006-2011 Oracle Corporation
e86794d5ed13ea3053cb8f12be80630236ef2943vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
e86794d5ed13ea3053cb8f12be80630236ef2943vboxsync * available from http://www.virtualbox.org. This file is free software;
e86794d5ed13ea3053cb8f12be80630236ef2943vboxsync * you can redistribute it and/or modify it under the terms of the GNU
e86794d5ed13ea3053cb8f12be80630236ef2943vboxsync * General Public License (GPL) as published by the Free Software
e86794d5ed13ea3053cb8f12be80630236ef2943vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
e86794d5ed13ea3053cb8f12be80630236ef2943vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
e86794d5ed13ea3053cb8f12be80630236ef2943vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync#define TRACE RTPrintf("%s: %d\n", __PRETTY_FUNCTION__, __LINE__); LogRel(("%s: %d\n", __PRETTY_FUNCTION__, __LINE__))
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsyncstatic int (*gpfnOldIOErrorHandler)(Display *) = NULL;
a7aa94e0115a73841f34ebbfa00f63fa1904e51fvboxsync/** Object representing the service we are running. This has to be global
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync * so that the cleanup routine can access it. */
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync/** The name of our pidfile. It is global for the benefit of the cleanup
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync * routine. */
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync/** The file handle of our pidfile. It is global for the benefit of the
5eda82e218d35ae0691febd531e1bfc0324cc4a6vboxsync * cleanup routine. */
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync/** Global critical section held during the clean-up routine (to prevent it
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync * being called on multiple threads at once) or things which may not happen
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync * during clean-up (e.g. pausing and resuming the service).
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync/** Clean up if we get a signal or something. This is extern so that we
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync * can call it from other compilation units. */
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync /* We never release this, as we end up with a call to exit(3) which is not
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync * async-safe. Until we fix this application properly, we should be sure
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync * never to exit from anywhere except from this method. */
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync RTPrintf("VBoxClient: Failure while acquiring the global critical section, rc=%Rrc\n", rc);
0e5731ab59b4ecead38375f26eeea698f00b19fdvboxsync * A standard signal handler which cleans up and exits.
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync LogRel(("VBoxClient: terminated with signal %d\n", cSignal));
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync /** Disable seamless mode */
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync * Xlib error handler for certain errors that we can't avoid.
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsyncint vboxClientXLibErrorHandler(Display *pDisplay, XErrorEvent *pError)
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync XGetErrorText(pDisplay, pError->error_code, errorText, sizeof(errorText));
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync LogRelFlow(("VBoxClient: an X Window protocol error occurred: %s (error code %d). Request code: %d, minor code: %d, serial number: %d\n", errorText, pError->error_code, pError->request_code, pError->minor_code, pError->serial));
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync return 0; /* We should never reach this. */
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync * Xlib error handler for fatal errors. This often means that the programme is still running
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync * when X exits.
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsyncstatic int vboxClientXLibIOErrorHandler(Display *pDisplay)
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync LogRel(("VBoxClient: a fatal guest X Window error occurred. This may just mean that the Window system was shut down while the client was still running.\n"));
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync return 0; /* We should never reach this. */
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync * Reset all standard termination signals to call our signal handler, which
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync * cleans up and exits.
static unsigned long getXOrgVT(void)
int actualFormat;
unsigned long *pValue;
if (!pDisplay)
return VINF_SUCCESS;
(unsigned char **)&pValue);
return cVT;
#ifdef RT_OS_LINUX
&cbRead)))
if (!cTTY)
int rc;
|| rc)
#ifdef RT_OS_LINUX
unsigned long cVT;
if (!cVT)
return VINF_SUCCESS;
return VINF_SUCCESS;
static int startVTMonitorThread()
#ifdef VBOX_WITH_DRAG_AND_DROP
# ifdef VBOX_WITH_GUEST_PROPS
#ifdef VBOX_WITH_DRAG_AND_DROP
#ifdef VBOX_WITH_GUEST_PROPS
exit(0);
if (!XInitThreads())
int rcClipboard;
bool fDaemonise = true;
bool fSuccess = true;
bool fHaveService = false;
fDaemonise = false;
fSuccess = false;
fSuccess = false;
fSuccess = false;
fSuccess = false;
#ifdef VBOX_WITH_DRAG_AND_DROP
fSuccess = false;
if (fDaemonise)
# ifdef DEBUG
VbglR3Term();
#ifdef RT_OS_LINUX
rc);
rc));
VbglR3Term();