VirtualBox

Changeset 4350 in vbox for trunk/src


Ignore:
Timestamp:
Aug 24, 2007 1:27:16 PM (17 years ago)
Author:
vboxsync
Message:

Initial code for seamless mode in Linux guests

Location:
trunk/src/VBox/Additions/linux/xclient
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/linux/xclient/Makefile.kmk

    r4071 r4350  
    2626
    2727vboxadd-xclient_TEMPLATE = VBOXLNX32GUESTR3EXE
    28 vboxadd-xclient_SOURCES  = clipboard.cpp
     28vboxadd-xclient_SOURCES  = clipboard.cpp main.cpp
    2929vboxadd-xclient_LIBPATH  = $(PATH_TARGET)/vboxadd-xclient $(VBOX_LIBPATH32_X11)
    3030vboxadd-xclient_LIBS     = \
  • trunk/src/VBox/Additions/linux/xclient/clipboard.cpp

    r4298 r4350  
    2323#define USE_CTEXT
    2424
    25 #define LOG_GROUP LOG_GROUP_HGCM
     25#define LOG_GROUP LOG_GROUP_DEV_VMM_BACKDOOR
    2626
    2727#include <vector>
     
    3333#include <VBox/VBoxGuest.h>
    3434#include <VBox/HostServices/VBoxClipboardSvc.h>
    35 
     35#include <VBox/log.h>
    3636#include <iprt/alloc.h>
    3737#include <iprt/asm.h>        /* For atomic operations */
     
    4343#include <iprt/process.h>
    4444#include <iprt/semaphore.h>
    45 #include <VBox/log.h>
    4645#include <string.h>
    4746#include <stdio.h>
    4847#include <stdint.h>
    4948#include <sys/ioctl.h>
    50 #include <sys/types.h>
     49// #include <sys/types.h>
    5150#include <sys/stat.h>
    5251#include <fcntl.h>
    5352#include <errno.h>
    5453#include <signal.h>
    55 #include <unistd.h>
    56 #include <getopt.h>
    57 
    58 // #include "VBoxClipboard.h"
     54// #include <unistd.h>
     55// #include <getopt.h>
    5956
    6057#include <X11/Xlib.h>
     
    6360#include <X11/Shell.h>
    6461#include <X11/X.h>
     62
     63#include "clipboard.h"
    6564
    6665#define VBOX_INIT_CALL(__a, __b, __c) do {                                                             \
     
    161160        it. */
    162161    RTSEMEVENT terminating;
    163     /** Are we running as a daemon? */
    164     bool daemonise;
    165162
    166163    /** Format which we are reading from the guest clipboard (valid during a request for the
     
    15211518}
    15221519
    1523 int vboxClipboardXLibErrorHandler(Display *pDisplay, XErrorEvent *pError)
    1524 {
    1525     char errorText[1024];
    1526 
    1527     LogFlowFunc(("\n"));
    1528     if (pError->error_code == BadAtom)
    1529     {
    1530         /* This can be triggered in debug builds if a guest application passes a bad atom
    1531            in its list of supported clipboard formats.  As such it is harmless. */
    1532         LogFlowFunc(("ignoring BadAtom error and returning\n"));
    1533         return 0;
    1534     }
    1535     vboxClipboardDisconnect();
    1536     XGetErrorText(pDisplay, pError->error_code, errorText, sizeof(errorText));
    1537     if (g_ctx.daemonise == 0)
    1538     {
    1539         cout << "An X Window protocol error occurred: " << errorText << endl
    1540             << "  Request code: " << int(pError->request_code) << endl
    1541             << "  Minor code: " << int(pError->minor_code) << endl
    1542             << "  Serial number of the failed request: " << int(pError->serial) << endl;
    1543     }
    1544     Log(("%s: an X Window protocol error occurred: %s.  Request code: %d, minor code: %d, serial number: %d\n",
    1545          __PRETTY_FUNCTION__, pError->error_code, pError->request_code, pError->minor_code,
    1546          pError->serial));
    1547     LogFlowFunc(("exiting\n"));
    1548     exit(1);
    1549 }
    1550 
    15511520
    15521521/**
     
    15621531    AssertReturn(g_ctx.client == 0, VERR_NOT_SUPPORTED);
    15631532
     1533    /* Initialise the termination semaphore. */
     1534    RTSemEventCreate(&g_ctx.terminating);
     1535    /* Open a connection to the driver for sending requests. */
     1536    g_ctx.sendDevice = open(VBOXGUEST_DEVICE_NAME, O_RDWR, 0);
     1537    if (g_ctx.sendDevice < 0)
     1538    {
     1539        int err = errno;
     1540
     1541        Log(("Error opening kernel module! errno = %d\n", err));
     1542        cout << "Failed to open the VirtualBox device in the guest." << endl;
     1543        LogFlowFunc(("returning 1\n"));
     1544        return RTErrConvertFromErrno(err);
     1545    }
     1546    /* Open a connection to the driver for polling for host requests. */
     1547    g_ctx.receiveDevice = open(VBOXGUEST_DEVICE_NAME, O_RDWR, 0);
     1548    if (g_ctx.receiveDevice < 0)
     1549    {
     1550        int err = errno;
     1551
     1552        Log(("Error opening kernel module! rc = %d\n", err));
     1553        cout << "Failed to open the VirtualBox device in the guest" << endl;
     1554        LogFlowFunc(("returning 1\n"));
     1555        return RTErrConvertFromErrno(err);
     1556    }
     1557
    15641558    rc = ioctl(g_ctx.sendDevice, IOCTL_VBOXGUEST_CLIPBOARD_CONNECT, (void*)&g_ctx.client);
    15651559    if (rc >= 0)
     
    15791573        return VERR_NOT_SUPPORTED;
    15801574    }
    1581     /* Set an X11 error handler, so that we don't die when we get BadAtom errors. */
    1582     XSetErrorHandler(vboxClipboardXLibErrorHandler);
    15831575    LogFlowFunc(("returned VINF_SUCCESS\n"));
    15841576    return VINF_SUCCESS;
     
    16841676    return rc;
    16851677}
    1686 
    1687 
    1688 /**
    1689  * Become a daemon process
    1690  */
    1691 void vboxDaemonise(void)
    1692 {
    1693     /* First fork and exit the parent process, so that we are sure we are not session leader. */
    1694     if (fork() != 0)
    1695     {
    1696         exit(0);
    1697     }
    1698     /* Detach from the controlling terminal by creating our own session. */
    1699     setsid();
    1700     /* And change to the root directory to avoid holding the one we were started in open. */
    1701     chdir("/");
    1702     /* Close the standard files. */
    1703     close(0);
    1704     close(1);
    1705     close(2);
    1706 }
    1707 
    1708 int main(int argc, char *argv[])
    1709 {
    1710     int rc;
    1711 
    1712     /* Parse our option(s) */
    1713     g_ctx.daemonise = 1;
    1714     while (1)
    1715     {
    1716         static struct option sOpts[] =
    1717         {
    1718             {"nodaemon", 0, 0, 'd'},
    1719             {0, 0, 0, 0}
    1720         };
    1721         int cOpt = getopt_long(argc, argv, "", sOpts, 0);
    1722         if (cOpt == -1)
    1723         {
    1724             if (optind < argc)
    1725             {
    1726                 cout << "Unrecognized command line argument: " << argv[argc] << endl;
    1727                 exit(1);
    1728             }
    1729             break;
    1730         }
    1731         switch(cOpt)
    1732         {
    1733         case 'd':
    1734             g_ctx.daemonise = 0;
    1735             break;
    1736         default:
    1737             cout << "Unrecognized command line option: " << static_cast<char>(cOpt) << endl;
    1738         case '?':
    1739             exit(1);
    1740         }
    1741     }
    1742     /* Initialise our runtime before all else. */
    1743     RTR3Init(false);
    1744     LogFlowFunc(("\n"));
    1745     /* Initialise threading in Xt before we start any new threads. */
    1746     XtToolkitThreadInitialize();
    1747     /* Initialise the termination semaphore. */
    1748     RTSemEventCreate(&g_ctx.terminating);
    1749     /* Open a connection to the driver for sending requests. */
    1750     g_ctx.sendDevice = open(VBOXGUEST_DEVICE_NAME, O_RDWR, 0);
    1751     if (g_ctx.sendDevice < 0)
    1752     {
    1753         Log(("Error opening kernel module! errno = %d\n", errno));
    1754         cout << "Failed to open the VirtualBox device in the guest." << endl;
    1755         LogFlowFunc(("returning 1\n"));
    1756         return 1;
    1757     }
    1758     /* Open a connection to the driver for polling for host requests. */
    1759     g_ctx.receiveDevice = open(VBOXGUEST_DEVICE_NAME, O_RDWR, 0);
    1760     if (g_ctx.receiveDevice < 0)
    1761     {
    1762         Log(("Error opening kernel module! rc = %d\n", errno));
    1763         cout << "Failed to open the VirtualBox device in the guest" << endl;
    1764         LogFlowFunc(("returning 1\n"));
    1765         return 1;
    1766     }
    1767     /* Connect to the host clipboard. */
    1768     rc = vboxClipboardConnect();
    1769     if (rc != VINF_SUCCESS)
    1770     {
    1771         Log(("vboxClipboardConnect failed with rc = %d\n", rc));
    1772         cout << "Failed to connect to the host clipboard." << endl;
    1773         LogFlowFunc(("returning 1\n"));
    1774         return 1;
    1775     }
    1776     if (g_ctx.daemonise == 1)
    1777     {
    1778         vboxDaemonise();
    1779     }
    1780     vboxClipboardMain();
    1781     vboxClipboardDisconnect();
    1782     LogFlowFunc(("returning 0\n"));
    1783     return 0;
    1784 }
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette