vboxmslnk.c revision 5ce6430a4bdc0d8e64b379e763d5b80a3259e805
95881853170c1ca02b650717fd416a2c2a5e3568nd/* $Id$ */
95881853170c1ca02b650717fd416a2c2a5e3568nd/** @file
95881853170c1ca02b650717fd416a2c2a5e3568nd * VirtualBox Guest Additions Mouse Driver for Solaris: user space loader tool.
af33a4994ae2ff15bc67d19ff1a7feb906745bf8rbowen */
95881853170c1ca02b650717fd416a2c2a5e3568nd
95881853170c1ca02b650717fd416a2c2a5e3568nd/*
db878466c5e95073429dda0bdd001f45e9486e16fielding * Copyright (C) 2012 Oracle Corporation
db878466c5e95073429dda0bdd001f45e9486e16fielding *
db878466c5e95073429dda0bdd001f45e9486e16fielding * This file is part of VirtualBox Open Source Edition (OSE), as
db878466c5e95073429dda0bdd001f45e9486e16fielding * available from http://www.virtualbox.org. This file is free software;
db878466c5e95073429dda0bdd001f45e9486e16fielding * you can redistribute it and/or modify it under the terms of the GNU
db878466c5e95073429dda0bdd001f45e9486e16fielding * General Public License (GPL) as published by the Free Software
95881853170c1ca02b650717fd416a2c2a5e3568nd * Foundation, in version 2 as it comes in the "COPYING" file of the
95881853170c1ca02b650717fd416a2c2a5e3568nd * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
95881853170c1ca02b650717fd416a2c2a5e3568nd * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
95881853170c1ca02b650717fd416a2c2a5e3568nd *
95881853170c1ca02b650717fd416a2c2a5e3568nd * The contents of this file may alternatively be used under the terms
95881853170c1ca02b650717fd416a2c2a5e3568nd * of the Common Development and Distribution License Version 1.0
95881853170c1ca02b650717fd416a2c2a5e3568nd * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
95881853170c1ca02b650717fd416a2c2a5e3568nd * VirtualBox OSE distribution, in which case the provisions of the
95881853170c1ca02b650717fd416a2c2a5e3568nd * CDDL are applicable instead of those of the GPL.
95881853170c1ca02b650717fd416a2c2a5e3568nd *
95881853170c1ca02b650717fd416a2c2a5e3568nd * You may elect to license modified versions of this file under the
95881853170c1ca02b650717fd416a2c2a5e3568nd * terms and conditions of either the GPL or the CDDL or both.
95881853170c1ca02b650717fd416a2c2a5e3568nd */
b51bf223f42d43ca6b1b33c95124edcfa5a871a4nd
b51bf223f42d43ca6b1b33c95124edcfa5a871a4nd#include <VBox/version.h>
95881853170c1ca02b650717fd416a2c2a5e3568nd#include <iprt/buildconfig.h>
95881853170c1ca02b650717fd416a2c2a5e3568nd
33350fa12dd520954b23b41e6a17b07e538d79f8nd#include <errno.h>
95881853170c1ca02b650717fd416a2c2a5e3568nd#include <fcntl.h>
95881853170c1ca02b650717fd416a2c2a5e3568nd#include <stdio.h>
33350fa12dd520954b23b41e6a17b07e538d79f8nd#include <stdlib.h>
95881853170c1ca02b650717fd416a2c2a5e3568nd#include <string.h>
95881853170c1ca02b650717fd416a2c2a5e3568nd#include <stropts.h>
95881853170c1ca02b650717fd416a2c2a5e3568nd#include <unistd.h>
95881853170c1ca02b650717fd416a2c2a5e3568nd
95881853170c1ca02b650717fd416a2c2a5e3568ndstatic void handleArgs(int argc, char *argv[], int *pfNoLogo);
95881853170c1ca02b650717fd416a2c2a5e3568nd
95881853170c1ca02b650717fd416a2c2a5e3568ndint main(int argc, char *argv[])
95881853170c1ca02b650717fd416a2c2a5e3568nd{
95881853170c1ca02b650717fd416a2c2a5e3568nd int fNoLogo, hVBoxMS, hConsMS, idConnection;
95881853170c1ca02b650717fd416a2c2a5e3568nd
33350fa12dd520954b23b41e6a17b07e538d79f8nd handleArgs(argc, argv, &fNoLogo);
95881853170c1ca02b650717fd416a2c2a5e3568nd /* Open our pointer integration driver (vboxms). */
33350fa12dd520954b23b41e6a17b07e538d79f8nd hVBoxMS = open("/dev/vboxms", O_RDWR);
95881853170c1ca02b650717fd416a2c2a5e3568nd if (hVBoxMS < 0)
95881853170c1ca02b650717fd416a2c2a5e3568nd {
95881853170c1ca02b650717fd416a2c2a5e3568nd printf("Failed to open /dev/vboxms - please make sure that the node exists and that\n"
95881853170c1ca02b650717fd416a2c2a5e3568nd "you have permission to open it. The error reported was:\n"
95881853170c1ca02b650717fd416a2c2a5e3568nd "%s\n", strerror(errno));
33350fa12dd520954b23b41e6a17b07e538d79f8nd exit(1);
95881853170c1ca02b650717fd416a2c2a5e3568nd }
95881853170c1ca02b650717fd416a2c2a5e3568nd /* Open the Solaris virtual mouse driver (consms). */
33350fa12dd520954b23b41e6a17b07e538d79f8nd hConsMS = open("/dev/mouse", O_RDWR);
95881853170c1ca02b650717fd416a2c2a5e3568nd if (hConsMS < 0)
95881853170c1ca02b650717fd416a2c2a5e3568nd {
95881853170c1ca02b650717fd416a2c2a5e3568nd printf("Failed to open /dev/mouse - please make sure that the node exists and that\n"
f37877a589391f0c8cf7fe41933039cb199f8896nd "you have permission to open it. The error reported was:\n"
95881853170c1ca02b650717fd416a2c2a5e3568nd "%s\n", strerror(errno));
95881853170c1ca02b650717fd416a2c2a5e3568nd exit(1);
95881853170c1ca02b650717fd416a2c2a5e3568nd }
33350fa12dd520954b23b41e6a17b07e538d79f8nd /* Link vboxms to consms from below. What this means is that vboxms is
33350fa12dd520954b23b41e6a17b07e538d79f8nd * added to the list of input sources multiplexed by consms, and vboxms
95881853170c1ca02b650717fd416a2c2a5e3568nd * will receive any control messages (such as information about guest
6e48215232940ab47baefa4f6eb9cd546eb2400atakashi * resolution changes) sent to consms. The link can only be broken
33350fa12dd520954b23b41e6a17b07e538d79f8nd * explicitly using the connection ID returned from the IOCtl. */
95881853170c1ca02b650717fd416a2c2a5e3568nd idConnection = ioctl(hConsMS, I_PLINK, hVBoxMS);
95881853170c1ca02b650717fd416a2c2a5e3568nd if (idConnection < 0)
95881853170c1ca02b650717fd416a2c2a5e3568nd {
33350fa12dd520954b23b41e6a17b07e538d79f8nd printf("Failed to add /dev/vboxms (the pointer integration driver) to /dev/mouse\n"
33350fa12dd520954b23b41e6a17b07e538d79f8nd "(the Solaris virtual master mouse). The error reported was:\n"
95881853170c1ca02b650717fd416a2c2a5e3568nd "%s\n", strerror(errno));
95881853170c1ca02b650717fd416a2c2a5e3568nd exit(1);
95881853170c1ca02b650717fd416a2c2a5e3568nd }
33350fa12dd520954b23b41e6a17b07e538d79f8nd close(hVBoxMS);
33350fa12dd520954b23b41e6a17b07e538d79f8nd if (!fNoLogo)
95881853170c1ca02b650717fd416a2c2a5e3568nd printf("Successfully enabled pointer integration. Connection ID number to the\n"
95881853170c1ca02b650717fd416a2c2a5e3568nd "Solaris virtual master mouse:\n");
33350fa12dd520954b23b41e6a17b07e538d79f8nd printf("%d\n", idConnection);
95881853170c1ca02b650717fd416a2c2a5e3568nd exit(0);
95881853170c1ca02b650717fd416a2c2a5e3568nd}
95881853170c1ca02b650717fd416a2c2a5e3568nd
95881853170c1ca02b650717fd416a2c2a5e3568ndvoid handleArgs(int argc, char *argv[], int *pfNoLogo)
95881853170c1ca02b650717fd416a2c2a5e3568nd{
95881853170c1ca02b650717fd416a2c2a5e3568nd int fNoLogo = 0, fShowUsage = 0, fShowVersion = 0;
95881853170c1ca02b650717fd416a2c2a5e3568nd
95881853170c1ca02b650717fd416a2c2a5e3568nd if (argc != 1 && argc != 2)
95881853170c1ca02b650717fd416a2c2a5e3568nd fShowUsage = 1;
95881853170c1ca02b650717fd416a2c2a5e3568nd if (argc == 2)
95881853170c1ca02b650717fd416a2c2a5e3568nd {
95881853170c1ca02b650717fd416a2c2a5e3568nd if (!strcmp(argv[1], "--nologo"))
95881853170c1ca02b650717fd416a2c2a5e3568nd fNoLogo = 1;
else if (!strcmp(argv[1], "-V") || !strcmp(argv[1], "--version"))
fShowVersion = 1;
else
fShowUsage = 1;
}
if (fShowVersion)
{
printf("%sr%u\n", VBOX_VERSION_STRING, RTBldCfgRevision());
exit(0);
}
if (!fNoLogo)
printf(VBOX_PRODUCT
" Guest Additions enabling utility for Solaris pointer\nintegration Version "
VBOX_VERSION_STRING "\n"
"(C) " VBOX_C_YEAR " " VBOX_VENDOR "\n"
"All rights reserved.\n\n");
if (fShowUsage)
{
printf("Usage:\n -V|--version print the tool version.\n"
" --nologo do not display the logo text and only output the connection\n"
" ID number needed to disable pointer integration\n"
" again.\n"
" -h|--help display this help text.\n");
exit(0);
}
*pfNoLogo = fNoLogo;
}