- Timestamp:
- Aug 24, 2007 1:27:16 PM (17 years ago)
- Location:
- trunk/src/VBox/Additions/linux/xclient
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/linux/xclient/Makefile.kmk
r4071 r4350 26 26 27 27 vboxadd-xclient_TEMPLATE = VBOXLNX32GUESTR3EXE 28 vboxadd-xclient_SOURCES = clipboard.cpp 28 vboxadd-xclient_SOURCES = clipboard.cpp main.cpp 29 29 vboxadd-xclient_LIBPATH = $(PATH_TARGET)/vboxadd-xclient $(VBOX_LIBPATH32_X11) 30 30 vboxadd-xclient_LIBS = \ -
trunk/src/VBox/Additions/linux/xclient/clipboard.cpp
r4298 r4350 23 23 #define USE_CTEXT 24 24 25 #define LOG_GROUP LOG_GROUP_ HGCM25 #define LOG_GROUP LOG_GROUP_DEV_VMM_BACKDOOR 26 26 27 27 #include <vector> … … 33 33 #include <VBox/VBoxGuest.h> 34 34 #include <VBox/HostServices/VBoxClipboardSvc.h> 35 35 #include <VBox/log.h> 36 36 #include <iprt/alloc.h> 37 37 #include <iprt/asm.h> /* For atomic operations */ … … 43 43 #include <iprt/process.h> 44 44 #include <iprt/semaphore.h> 45 #include <VBox/log.h>46 45 #include <string.h> 47 46 #include <stdio.h> 48 47 #include <stdint.h> 49 48 #include <sys/ioctl.h> 50 #include <sys/types.h>49 // #include <sys/types.h> 51 50 #include <sys/stat.h> 52 51 #include <fcntl.h> 53 52 #include <errno.h> 54 53 #include <signal.h> 55 #include <unistd.h> 56 #include <getopt.h> 57 58 // #include "VBoxClipboard.h" 54 // #include <unistd.h> 55 // #include <getopt.h> 59 56 60 57 #include <X11/Xlib.h> … … 63 60 #include <X11/Shell.h> 64 61 #include <X11/X.h> 62 63 #include "clipboard.h" 65 64 66 65 #define VBOX_INIT_CALL(__a, __b, __c) do { \ … … 161 160 it. */ 162 161 RTSEMEVENT terminating; 163 /** Are we running as a daemon? */164 bool daemonise;165 162 166 163 /** Format which we are reading from the guest clipboard (valid during a request for the … … 1521 1518 } 1522 1519 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 atom1531 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 << endl1540 << " Request code: " << int(pError->request_code) << endl1541 << " Minor code: " << int(pError->minor_code) << endl1542 << " 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 1551 1520 1552 1521 /** … … 1562 1531 AssertReturn(g_ctx.client == 0, VERR_NOT_SUPPORTED); 1563 1532 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 1564 1558 rc = ioctl(g_ctx.sendDevice, IOCTL_VBOXGUEST_CLIPBOARD_CONNECT, (void*)&g_ctx.client); 1565 1559 if (rc >= 0) … … 1579 1573 return VERR_NOT_SUPPORTED; 1580 1574 } 1581 /* Set an X11 error handler, so that we don't die when we get BadAtom errors. */1582 XSetErrorHandler(vboxClipboardXLibErrorHandler);1583 1575 LogFlowFunc(("returned VINF_SUCCESS\n")); 1584 1576 return VINF_SUCCESS; … … 1684 1676 return rc; 1685 1677 } 1686 1687 1688 /**1689 * Become a daemon process1690 */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.