23
23
#include < errno.h>
24
24
#include < fcntl.h>
25
25
26
- #define LOG_TAG " CommandListener "
26
+ #define LOG_TAG " VoldCmdListener "
27
27
#include < cutils/log.h>
28
28
29
29
#include < sysutils/SocketClient.h>
33
33
#include " ResponseCode.h"
34
34
#include " Process.h"
35
35
#include " Xwarp.h"
36
+ #include " Loop.h"
37
+ #include " Devmapper.h"
36
38
37
39
CommandListener::CommandListener () :
38
40
FrameworkListener(" vold" ) {
41
+ registerCmd (new DumpCmd ());
39
42
registerCmd (new VolumeCmd ());
40
43
registerCmd (new AsecCmd ());
41
44
registerCmd (new ShareCmd ());
42
45
registerCmd (new StorageCmd ());
43
46
registerCmd (new XwarpCmd ());
44
47
}
45
48
49
+ void CommandListener::dumpArgs (int argc, char **argv, int argObscure) {
50
+ char buffer[4096 ];
51
+ char *p = buffer;
52
+
53
+ memset (buffer, 0 , sizeof (buffer));
54
+ int i;
55
+ for (i = 0 ; i < argc; i++) {
56
+ int len = strlen (argv[i]) + 1 ; // Account for space
57
+ if (i == argObscure) {
58
+ len += 2 ; // Account for {}
59
+ }
60
+ if (((p - buffer) + len) < (sizeof (buffer)-1 )) {
61
+ if (i == argObscure) {
62
+ *p++ = ' {' ;
63
+ *p++ = ' }' ;
64
+ *p++ = ' ' ;
65
+ continue ;
66
+ }
67
+ strcpy (p, argv[i]);
68
+ p+= strlen (argv[i]);
69
+ if (i != (argc -1 )) {
70
+ *p++ = ' ' ;
71
+ }
72
+ }
73
+ }
74
+ LOGD (" %s" , buffer);
75
+ }
76
+
77
+ CommandListener::DumpCmd::DumpCmd () :
78
+ VoldCommand(" dump" ) {
79
+ }
80
+
81
+ int CommandListener::DumpCmd::runCommand (SocketClient *cli,
82
+ int argc, char **argv) {
83
+ cli->sendMsg (0 , " Dumping loop status" , false );
84
+ if (Loop::dumpState (cli)) {
85
+ cli->sendMsg (ResponseCode::CommandOkay, " Loop dump failed" , true );
86
+ }
87
+ cli->sendMsg (0 , " Dumping DM status" , false );
88
+ if (Devmapper::dumpState (cli)) {
89
+ cli->sendMsg (ResponseCode::CommandOkay, " Devmapper dump failed" , true );
90
+ }
91
+
92
+ cli->sendMsg (ResponseCode::CommandOkay, " dump complete" , false );
93
+ return 0 ;
94
+ }
95
+
96
+
46
97
CommandListener::VolumeCmd::VolumeCmd () :
47
98
VoldCommand(" volume" ) {
48
99
}
49
100
50
101
int CommandListener::VolumeCmd::runCommand (SocketClient *cli,
51
102
int argc, char **argv) {
103
+ dumpArgs (argc, argv, -1 );
104
+
52
105
if (argc < 2 ) {
53
106
cli->sendMsg (ResponseCode::CommandSyntaxError, " Missing Argument" , false );
54
107
return 0 ;
@@ -59,6 +112,8 @@ int CommandListener::VolumeCmd::runCommand(SocketClient *cli,
59
112
60
113
if (!strcmp (argv[1 ], " list" )) {
61
114
return vm->listVolumes (cli);
115
+ } else if (!strcmp (argv[1 ], " debug" )) {
116
+ vm->setDebug (true );
62
117
} else if (!strcmp (argv[1 ], " mount" )) {
63
118
rc = vm->mountVolume (argv[2 ]);
64
119
} else if (!strcmp (argv[1 ], " unmount" )) {
@@ -105,6 +160,8 @@ CommandListener::ShareCmd::ShareCmd() :
105
160
106
161
int CommandListener::ShareCmd::runCommand (SocketClient *cli,
107
162
int argc, char **argv) {
163
+ dumpArgs (argc, argv, -1 );
164
+
108
165
if (argc < 2 ) {
109
166
cli->sendMsg (ResponseCode::CommandSyntaxError, " Missing Argument" , false );
110
167
return 0 ;
@@ -136,6 +193,8 @@ CommandListener::StorageCmd::StorageCmd() :
136
193
137
194
int CommandListener::StorageCmd::runCommand (SocketClient *cli,
138
195
int argc, char **argv) {
196
+ dumpArgs (argc, argv, -1 );
197
+
139
198
if (argc < 2 ) {
140
199
cli->sendMsg (ResponseCode::CommandSyntaxError, " Missing Argument" , false );
141
200
return 0 ;
@@ -194,6 +253,7 @@ int CommandListener::AsecCmd::runCommand(SocketClient *cli,
194
253
int rc = 0 ;
195
254
196
255
if (!strcmp (argv[1 ], " list" )) {
256
+ dumpArgs (argc, argv, -1 );
197
257
DIR *d = opendir (Volume::SEC_ASECDIR);
198
258
199
259
if (!d) {
@@ -214,6 +274,7 @@ int CommandListener::AsecCmd::runCommand(SocketClient *cli,
214
274
}
215
275
closedir (d);
216
276
} else if (!strcmp (argv[1 ], " create" )) {
277
+ dumpArgs (argc, argv, 5 );
217
278
if (argc != 7 ) {
218
279
cli->sendMsg (ResponseCode::CommandSyntaxError,
219
280
" Usage: asec create <container-id> <size_mb> <fstype> <key> <ownerUid>" , false );
@@ -223,12 +284,14 @@ int CommandListener::AsecCmd::runCommand(SocketClient *cli,
223
284
unsigned int numSectors = (atoi (argv[3 ]) * (1024 * 1024 )) / 512 ;
224
285
rc = vm->createAsec (argv[2 ], numSectors, argv[4 ], argv[5 ], atoi (argv[6 ]));
225
286
} else if (!strcmp (argv[1 ], " finalize" )) {
287
+ dumpArgs (argc, argv, -1 );
226
288
if (argc != 3 ) {
227
289
cli->sendMsg (ResponseCode::CommandSyntaxError, " Usage: asec finalize <container-id>" , false );
228
290
return 0 ;
229
291
}
230
292
rc = vm->finalizeAsec (argv[2 ]);
231
293
} else if (!strcmp (argv[1 ], " destroy" )) {
294
+ dumpArgs (argc, argv, -1 );
232
295
if (argc < 3 ) {
233
296
cli->sendMsg (ResponseCode::CommandSyntaxError, " Usage: asec destroy <container-id> [force]" , false );
234
297
return 0 ;
@@ -239,13 +302,15 @@ int CommandListener::AsecCmd::runCommand(SocketClient *cli,
239
302
}
240
303
rc = vm->destroyAsec (argv[2 ], force);
241
304
} else if (!strcmp (argv[1 ], " mount" )) {
305
+ dumpArgs (argc, argv, 3 );
242
306
if (argc != 5 ) {
243
307
cli->sendMsg (ResponseCode::CommandSyntaxError,
244
308
" Usage: asec mount <namespace-id> <key> <ownerUid>" , false );
245
309
return 0 ;
246
310
}
247
311
rc = vm->mountAsec (argv[2 ], argv[3 ], atoi (argv[4 ]));
248
312
} else if (!strcmp (argv[1 ], " unmount" )) {
313
+ dumpArgs (argc, argv, -1 );
249
314
if (argc < 3 ) {
250
315
cli->sendMsg (ResponseCode::CommandSyntaxError, " Usage: asec unmount <container-id> [force]" , false );
251
316
return 0 ;
@@ -256,13 +321,15 @@ int CommandListener::AsecCmd::runCommand(SocketClient *cli,
256
321
}
257
322
rc = vm->unmountAsec (argv[2 ], force);
258
323
} else if (!strcmp (argv[1 ], " rename" )) {
324
+ dumpArgs (argc, argv, -1 );
259
325
if (argc != 4 ) {
260
326
cli->sendMsg (ResponseCode::CommandSyntaxError,
261
327
" Usage: asec rename <old_id> <new_id>" , false );
262
328
return 0 ;
263
329
}
264
330
rc = vm->renameAsec (argv[2 ], argv[3 ]);
265
331
} else if (!strcmp (argv[1 ], " path" )) {
332
+ dumpArgs (argc, argv, -1 );
266
333
if (argc != 3 ) {
267
334
cli->sendMsg (ResponseCode::CommandSyntaxError, " Usage: asec path <container-id>" , false );
268
335
return 0 ;
@@ -276,6 +343,7 @@ int CommandListener::AsecCmd::runCommand(SocketClient *cli,
276
343
}
277
344
return 0 ;
278
345
} else {
346
+ dumpArgs (argc, argv, -1 );
279
347
cli->sendMsg (ResponseCode::CommandSyntaxError, " Unknown asec cmd" , false );
280
348
}
281
349
0 commit comments