1 | /* $Id: SUPLoggerCtl.cpp 28800 2010-04-27 08:22:32Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * SUPLoggerCtl - Support Driver Logger Control.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2009 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | *
|
---|
17 | * The contents of this file may alternatively be used under the terms
|
---|
18 | * of the Common Development and Distribution License Version 1.0
|
---|
19 | * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
20 | * VirtualBox OSE distribution, in which case the provisions of the
|
---|
21 | * CDDL are applicable instead of those of the GPL.
|
---|
22 | *
|
---|
23 | * You may elect to license modified versions of this file under the
|
---|
24 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
25 | */
|
---|
26 |
|
---|
27 | /*******************************************************************************
|
---|
28 | * Header Files *
|
---|
29 | *******************************************************************************/
|
---|
30 | #include <VBox/sup.h>
|
---|
31 | #include <iprt/buildconfig.h>
|
---|
32 | #include <iprt/initterm.h>
|
---|
33 | #include <iprt/getopt.h>
|
---|
34 | #include <iprt/stream.h>
|
---|
35 | #include <iprt/string.h>
|
---|
36 | #include <iprt/ctype.h>
|
---|
37 | #include <iprt/err.h>
|
---|
38 |
|
---|
39 |
|
---|
40 | /**
|
---|
41 | * Prints the usage.
|
---|
42 | * @returns 1.
|
---|
43 | */
|
---|
44 | static int usage(void)
|
---|
45 | {
|
---|
46 | RTPrintf("usage: SUPLoggerCtl [-f|--flags <flags-settings>] \\\n"
|
---|
47 | " [-g|--groups <groups-settings>] \\\n"
|
---|
48 | " [-d|--dest <destination-specifiers>] \\\n"
|
---|
49 | " [-l|--which <release|debug>] \\\n"
|
---|
50 | " [-o|--what <set|create|destroy>]\n"
|
---|
51 | " or: SUPLoggerCtl <-h|--help>\n"
|
---|
52 | "\n"
|
---|
53 | );
|
---|
54 | return 1;
|
---|
55 | }
|
---|
56 |
|
---|
57 |
|
---|
58 | int main(int argc, char **argv)
|
---|
59 | {
|
---|
60 | RTR3InitAndSUPLib();
|
---|
61 |
|
---|
62 | /*
|
---|
63 | * Options are mandatory.
|
---|
64 | */
|
---|
65 | if (argc <= 1)
|
---|
66 | return usage();
|
---|
67 |
|
---|
68 | /*
|
---|
69 | * Parse the options.
|
---|
70 | */
|
---|
71 | static const RTGETOPTDEF s_aOptions[] =
|
---|
72 | {
|
---|
73 | { "--flags", 'f', RTGETOPT_REQ_STRING },
|
---|
74 | { "--groups", 'g', RTGETOPT_REQ_STRING },
|
---|
75 | { "--dest", 'd', RTGETOPT_REQ_STRING },
|
---|
76 | { "--what", 'o', RTGETOPT_REQ_STRING },
|
---|
77 | { "--which", 'l', RTGETOPT_REQ_STRING },
|
---|
78 | };
|
---|
79 |
|
---|
80 | const char *pszFlags = "";
|
---|
81 | const char *pszGroups = "";
|
---|
82 | const char *pszDest = "";
|
---|
83 | SUPLOGGER enmWhich = SUPLOGGER_DEBUG;
|
---|
84 | enum
|
---|
85 | {
|
---|
86 | kSupLoggerCtl_Set, kSupLoggerCtl_Create, kSupLoggerCtl_Destroy
|
---|
87 | } enmWhat = kSupLoggerCtl_Set;
|
---|
88 |
|
---|
89 | int ch;
|
---|
90 | int i = 1;
|
---|
91 | RTGETOPTUNION Val;
|
---|
92 | RTGETOPTSTATE GetState;
|
---|
93 | RTGetOptInit(&GetState, argc, argv, s_aOptions, RT_ELEMENTS(s_aOptions), 1, 0);
|
---|
94 | while ((ch = RTGetOpt(&GetState, &Val)))
|
---|
95 | {
|
---|
96 | switch (ch)
|
---|
97 | {
|
---|
98 | case 'f':
|
---|
99 | pszFlags = Val.psz;
|
---|
100 | break;
|
---|
101 |
|
---|
102 | case 'g':
|
---|
103 | pszGroups = Val.psz;
|
---|
104 | break;
|
---|
105 |
|
---|
106 | case 'd':
|
---|
107 | pszDest = Val.psz;
|
---|
108 | break;
|
---|
109 |
|
---|
110 | case 'o':
|
---|
111 | if (!strcmp(Val.psz, "set"))
|
---|
112 | enmWhat = kSupLoggerCtl_Set;
|
---|
113 | else if (!strcmp(Val.psz, "create"))
|
---|
114 | enmWhat = kSupLoggerCtl_Create;
|
---|
115 | else if (!strcmp(Val.psz, "destroy"))
|
---|
116 | enmWhat = kSupLoggerCtl_Destroy;
|
---|
117 | else
|
---|
118 | {
|
---|
119 | RTStrmPrintf(g_pStdErr, "SUPLoggerCtl: error: Unknown operation '%s'.\n", Val.psz);
|
---|
120 | return 1;
|
---|
121 | }
|
---|
122 | break;
|
---|
123 |
|
---|
124 | case 'l':
|
---|
125 | if (!strcmp(Val.psz, "debug"))
|
---|
126 | enmWhich = SUPLOGGER_DEBUG;
|
---|
127 | else if (!strcmp(Val.psz, "release"))
|
---|
128 | enmWhich = SUPLOGGER_RELEASE;
|
---|
129 | else
|
---|
130 | {
|
---|
131 | RTStrmPrintf(g_pStdErr, "SUPLoggerCtl: error: Unknown logger '%s'.\n", Val.psz);
|
---|
132 | return 1;
|
---|
133 | }
|
---|
134 | break;
|
---|
135 |
|
---|
136 | case 'h':
|
---|
137 | return usage();
|
---|
138 |
|
---|
139 | case 'V':
|
---|
140 | RTPrintf("%sr%s\n", RTBldCfgVersion(), RTBldCfgRevisionStr());
|
---|
141 | return 0;
|
---|
142 |
|
---|
143 | case VINF_GETOPT_NOT_OPTION:
|
---|
144 | RTStrmPrintf(g_pStdErr, "SUPLoggerCtl: error: Unexpected argument '%s'.\n", Val.psz);
|
---|
145 | return 1;
|
---|
146 |
|
---|
147 | default:
|
---|
148 | return RTGetOptPrintError(ch, &Val);
|
---|
149 | }
|
---|
150 | }
|
---|
151 |
|
---|
152 | /*
|
---|
153 | * Do the requested job.
|
---|
154 | */
|
---|
155 | int rc;
|
---|
156 | switch (enmWhat)
|
---|
157 | {
|
---|
158 | case kSupLoggerCtl_Set:
|
---|
159 | rc = SUPR3LoggerSettings(enmWhich, pszFlags, pszGroups, pszDest);
|
---|
160 | break;
|
---|
161 | case kSupLoggerCtl_Create:
|
---|
162 | rc = SUPR3LoggerCreate(enmWhich, pszFlags, pszGroups, pszDest);
|
---|
163 | break;
|
---|
164 | case kSupLoggerCtl_Destroy:
|
---|
165 | rc = SUPR3LoggerDestroy(enmWhich);
|
---|
166 | break;
|
---|
167 | default:
|
---|
168 | rc = VERR_INTERNAL_ERROR;
|
---|
169 | break;
|
---|
170 | }
|
---|
171 | if (RT_SUCCESS(rc))
|
---|
172 | RTPrintf("SUPLoggerCtl: Success\n");
|
---|
173 | else
|
---|
174 | RTStrmPrintf(g_pStdErr, "SUPLoggerCtl: error: rc=%Rrc\n", rc);
|
---|
175 |
|
---|
176 | return RT_SUCCESS(rc) ? 0 : 1;
|
---|
177 | }
|
---|
178 |
|
---|