Changeset 101532 in vbox for trunk/src/VBox/Additions
- Timestamp:
- Oct 20, 2023 8:38:33 PM (14 months ago)
- Location:
- trunk/src/VBox/Additions/solaris/Mouse
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/solaris/Mouse/vboxmslnk.c
r98103 r101532 45 45 #include <stropts.h> 46 46 #include <unistd.h> 47 48 static void handleArgs(int argc, char *argv[], int *pfNoLogo); 49 50 int main(int argc, char *argv[]) 51 { 52 int fNoLogo, hVBoxMS, hConsMS, idConnection; 53 54 handleArgs(argc, argv, &fNoLogo); 47 #include <paths.h> 48 #include <libgen.h> 49 #include <getopt.h> 50 51 #define VBOXMSLNK_MUXID_FILE _PATH_SYSVOL "/vboxmslnk.muxid" 52 53 static const char *g_pszProgName; 54 55 56 static void vboxmslnk_fatal(const char *fmt, ...) 57 { 58 va_list ap; 59 60 va_start(ap, fmt); 61 (void) vfprintf(stderr, fmt, ap); 62 if (fmt[strlen(fmt) - 1] != '\n') 63 (void) fprintf(stderr, " The error reported was: %s\n", strerror(errno)); 64 va_end(ap); 65 66 exit(EXIT_FAILURE); 67 } 68 69 static void vboxmslnk_start(bool fNoLogo) 70 { 55 71 /* Open our pointer integration driver (vboxms). */ 56 hVBoxMS = open("/dev/vboxms", O_RDWR);72 int hVBoxMS = open("/dev/vboxms", O_RDWR); 57 73 if (hVBoxMS < 0) 58 { 59 printf("Failed to open /dev/vboxms - please make sure that the node exists and that\n" 60 "you have permission to open it. The error reported was:\n" 61 "%s\n", strerror(errno)); 62 exit(1); 63 } 74 vboxmslnk_fatal("Failed to open /dev/vboxms - please make sure that the node exists and that\n" 75 "you have permission to open it."); 76 64 77 /* Open the Solaris virtual mouse driver (consms). */ 65 hConsMS = open("/dev/mouse", O_RDWR);78 int hConsMS = open("/dev/mouse", O_RDWR); 66 79 if (hConsMS < 0) 67 { 68 printf("Failed to open /dev/mouse - please make sure that the node exists and that\n" 69 "you have permission to open it. The error reported was:\n" 70 "%s\n", strerror(errno)); 71 exit(1); 72 } 80 vboxmslnk_fatal("Failed to open /dev/mouse - please make sure that the node exists and that\n" 81 "you have permission to open it."); 82 73 83 /* Link vboxms to consms from below. What this means is that vboxms is 74 84 * added to the list of input sources multiplexed by consms, and vboxms … … 76 86 * resolution changes) sent to consms. The link can only be broken 77 87 * explicitly using the connection ID returned from the IOCtl. */ 78 i dConnection = ioctl(hConsMS, I_PLINK, hVBoxMS);88 int idConnection = ioctl(hConsMS, I_PLINK, hVBoxMS); 79 89 if (idConnection < 0) 90 vboxmslnk_fatal("Failed to add /dev/vboxms (the pointer integration driver) to /dev/mouse\n" 91 "(the Solaris virtual master mouse)."); 92 93 (void) close(hVBoxMS); 94 (void) close(hConsMS); 95 96 if (!fNoLogo) 97 (void) printf("Successfully enabled pointer integration. Connection ID number to the\n" 98 "Solaris virtual master mouse is:\n"); 99 (void) printf("%d\n", idConnection); 100 101 /* Save the connection ID (aka mux ID) so it can be retrieved later. */ 102 FILE *fp = fopen(VBOXMSLNK_MUXID_FILE, "w"); 103 if (fp == NULL) 104 vboxmslnk_fatal("Failed to open %s for writing the connection ID.", VBOXMSLNK_MUXID_FILE); 105 int rc = fprintf(fp, "%d\n", idConnection); 106 if (rc <= 0) 107 vboxmslnk_fatal("Failed to write the connection ID to %s.", VBOXMSLNK_MUXID_FILE); 108 (void) fclose(fp); 109 } 110 111 static void vboxmslnk_stop() 112 { 113 /* Open the Solaris virtual mouse driver (consms). */ 114 int hConsMS = open("/dev/mouse", O_RDWR); 115 if (hConsMS < 0) 116 vboxmslnk_fatal("Failed to open /dev/mouse - please make sure that the node exists and that\n" 117 "you have permission to open it."); 118 119 /* Open the vboxmslnk.muxid file and retrieve the saved mux ID. */ 120 FILE *fp = fopen(VBOXMSLNK_MUXID_FILE, "r"); 121 if (fp == NULL) 122 vboxmslnk_fatal("Failed to open %s for reading the connection ID.", VBOXMSLNK_MUXID_FILE); 123 int idConnection; 124 int rc = fscanf(fp, "%d\n", &idConnection); 125 if (rc <= 0) 126 vboxmslnk_fatal("Failed to read the connection ID from %s.", VBOXMSLNK_MUXID_FILE); 127 (void) fclose(fp); 128 (void) unlink(VBOXMSLNK_MUXID_FILE); 129 130 /* Unlink vboxms from consms so that vboxms is able to be unloaded. */ 131 rc = ioctl(hConsMS, I_PUNLINK, idConnection); 132 if (rc < 0) 133 vboxmslnk_fatal("Failed to disconnect /dev/vboxms (the pointer integration driver) from\n" 134 "/dev/mouse (the Solaris virtual master mouse)."); 135 (void) close(hConsMS); 136 } 137 138 static void vboxmslnk_usage() 139 { 140 (void) printf("Usage:\n" 141 " %s [--nologo] <--start | --stop>\n" 142 " %s [-V|--version]\n\n" 143 " -V|--version print the tool version.\n" 144 " --nologo do not display the logo text and only output the connection\n" 145 " ID number needed to disable pointer integration\n" 146 " again.\n" 147 " --start Connect the VirtualBox pointer integration kernel module\n" 148 " to the Solaris mouse driver kernel module.\n" 149 " --stop Disconnect the VirtualBox pointer integration kernel module\n" 150 " from the Solaris mouse driver kernel module.\n" 151 " -h|--help display this help text.\n", 152 g_pszProgName, g_pszProgName); 153 exit(EXIT_FAILURE); 154 } 155 156 int main(int argc, char *argv[]) 157 { 158 bool fShowVersion = false, fNoLogo = false, fStart = false, fStop = false; 159 int c; 160 161 g_pszProgName = basename(argv[0]); 162 163 static const struct option vboxmslnk_lopts[] = { 164 {"version", no_argument, 0, 'V' }, 165 {"nologo", no_argument, 0, 'n' }, 166 {"start", no_argument, 0, 's' }, 167 {"stop", no_argument, 0, 't' }, 168 {"help", no_argument, 0, 'h' }, 169 { 0, 0, 0, 0} 170 }; 171 172 while ((c = getopt_long(argc, argv, "Vh", vboxmslnk_lopts, NULL)) != -1) 80 173 { 81 printf("Failed to add /dev/vboxms (the pointer integration driver) to /dev/mouse\n" 82 "(the Solaris virtual master mouse). The error reported was:\n" 83 "%s\n", strerror(errno)); 84 exit(1); 174 switch (c) 175 { 176 case 'V': 177 fShowVersion = true; 178 break; 179 case 'n': 180 fNoLogo = true; 181 break; 182 case 's': 183 fStart = true; 184 break; 185 case 't': 186 fStop = true; 187 break; 188 case 'h': 189 default: 190 vboxmslnk_usage(); 191 } 85 192 } 86 close(hVBoxMS); 87 if (!fNoLogo) 88 printf("Successfully enabled pointer integration. Connection ID number to the\n" 89 "Solaris virtual master mouse:\n"); 90 printf("%d\n", idConnection); 91 exit(0); 92 } 93 94 void handleArgs(int argc, char *argv[], int *pfNoLogo) 95 { 96 int fNoLogo = 0, fShowUsage = 0, fShowVersion = 0; 97 98 if (argc != 1 && argc != 2) 99 fShowUsage = 1; 100 if (argc == 2) 101 { 102 if (!strcmp(argv[1], "--nologo")) 103 fNoLogo = 1; 104 else if (!strcmp(argv[1], "-V") || !strcmp(argv[1], "--version")) 105 fShowVersion = 1; 106 else 107 fShowUsage = 1; 108 } 193 194 if ( (!fStart && !fStop && !fShowVersion) 195 || (fStart && fStop) 196 || (fShowVersion && (fNoLogo || fStart || fStop))) 197 vboxmslnk_usage(); 198 109 199 if (fShowVersion) 110 200 { 111 printf("%sr%u\n", VBOX_VERSION_STRING, RTBldCfgRevision());112 exit( 0);201 (void) printf("%sr%u\n", VBOX_VERSION_STRING, RTBldCfgRevision()); 202 exit(EXIT_SUCCESS); 113 203 } 204 114 205 if (!fNoLogo) 115 printf(VBOX_PRODUCT 116 " Guest Additions enabling utility for Solaris pointer\nintegration Version " 117 VBOX_VERSION_STRING "\n" 118 "Copyright (C) " VBOX_C_YEAR " " VBOX_VENDOR "\n\n"); 119 if (fShowUsage) 120 { 121 printf("Usage:\n -V|--version print the tool version.\n" 122 " --nologo do not display the logo text and only output the connection\n" 123 " ID number needed to disable pointer integration\n" 124 " again.\n" 125 " -h|--help display this help text.\n"); 126 exit(0); 127 } 128 *pfNoLogo = fNoLogo; 129 } 130 206 (void) printf(VBOX_PRODUCT 207 " Guest Additions utility for enabling Solaris pointer\nintegration Version " 208 VBOX_VERSION_STRING "\n" 209 "Copyright (C) " VBOX_C_YEAR " " VBOX_VENDOR "\n\n"); 210 211 if (fStart) 212 vboxmslnk_start(fNoLogo); 213 214 if (fStop) 215 vboxmslnk_stop(); 216 217 exit(EXIT_SUCCESS); 218 } -
trunk/src/VBox/Additions/solaris/Mouse/vboxmslnk.xml
r98103 r101532 69 69 type='method' 70 70 name='start' 71 exec='/usr/sbin/vboxmslnk '71 exec='/usr/sbin/vboxmslnk --start' 72 72 timeout_seconds='30' /> 73 73 … … 75 75 type='method' 76 76 name='stop' 77 exec=' :true'77 exec='/usr/sbin/vboxmslnk --stop' 78 78 timeout_seconds='60' /> 79 79
Note:
See TracChangeset
for help on using the changeset viewer.