main.cpp revision 87b2fb3f8283472ba7010aedbf2b4dc12302155c
/** @file
*
* VirtualBox Guest Service:
* Linux guest.
*/
/*
* Copyright (C) 2006-2007 innotek GmbH
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
// #define LOG_GROUP LOG_GROUP_DEV_VMM_BACKDOOR
#include <VBox/VBoxGuest.h>
#include <iprt/initterm.h>
#include <iostream>
#include <stdlib.h> /* For exit */
#include <unistd.h>
#include <getopt.h>
#include <X11/Intrinsic.h>
#include "clipboard.h"
#ifdef SEAMLESS_LINUX
# include "seamless.h"
#endif
static bool gbDaemonise = true;
/**
* Xlib error handler for certain errors that we can't avoid.
*/
{
char errorText[1024];
{
/* This can be triggered in debug builds if a guest application passes a bad atom
in its list of supported clipboard formats. As such it is harmless. */
Log(("VBoxService: ignoring BadAtom error and returning\n"));
return 0;
}
{
/* This can be triggered if a guest application destroys a window before we notice. */
Log(("VBoxService: ignoring BadWindow error and returning\n"));
return 0;
}
#ifdef VBOX_X11_CLIPBOARD
#endif
LogRel(("VBoxService: an X Window protocol error occurred: %s. Request code: %d, minor code: %d, serial number: %d\n",
exit(1);
}
{
int rc;
#ifdef SEAMLESS_LINUX
/** Our instance of the seamless class. */
#endif
/* Parse our option(s) */
while (1)
{
{
{"nodaemon", 0, 0, 'd'},
{0, 0, 0, 0}
};
if (cOpt == -1)
{
{
exit(1);
}
break;
}
switch(cOpt)
{
case 'd':
gbDaemonise = false;
break;
default:
case '?':
exit(1);
}
}
gbDaemonise = false; // ram
if (gbDaemonise)
{
if (VbglR3Daemonize(0, 0) != 0)
{
LogRel(("VBoxService: failed to daemonize. exiting."));
return 1;
}
}
/* Initialise our runtime before all else. */
RTR3Init(false);
rc = VbglR3Init();
if (RT_FAILURE(rc))
{
return 1;
}
LogRel(("VBoxService: starting...\n"));
/* Initialise threading in X11 and in Xt. */
if (!XInitThreads() || !XtToolkitThreadInitialize())
{
LogRel(("VBoxService: error initialising threads in X11, exiting."));
return 1;
}
/* Set an X11 error handler, so that we don't die when we get unavoidable errors. */
#ifdef VBOX_X11_CLIPBOARD
/* Connect to the host clipboard. */
LogRel(("VBoxService: starting clipboard Guest Additions...\n"));
rc = vboxClipboardConnect();
if (RT_SUCCESS(rc))
{
}
#endif /* VBOX_X11_CLIPBOARD defined */
#ifdef SEAMLESS_LINUX
try
{
LogRel(("VBoxService: starting seamless Guest Additions...\n"));
if (RT_FAILURE(rc))
{
}
}
{
LogRel(("VBoxService: failed to initialise seamless Additions - caught exception: %s\n", e.what()));
}
catch (...)
{
LogRel(("VBoxService: failed to initialise seamless Additions - caught unknown exception.\n"));
}
#endif /* SEAMLESS_LINUX defined */
#ifdef VBOX_X11_CLIPBOARD
LogRel(("VBoxService: connecting to the shared clipboard service.\n"));
#else /* VBOX_X11_CLIPBOARD not defined */
LogRel(("VBoxService: sleeping...\n"));
pause();
LogRel(("VBoxService: exiting...\n"));
#endif /* VBOX_X11_CLIPBOARD not defined */
#ifdef SEAMLESS_LINUX
try
{
}
{
}
catch (...)
{
LogRel(("VBoxService: error shutting down seamless Additions - caught unknown exception.\n"));
}
#endif /* SEAMLESS_LINUX defined */
return rc;
}