1 /* 2 * Copyright (C) 2009 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #include <stdio.h> 18 #include <stdlib.h> 19 #include <unistd.h> 20 21 #include <cutils/properties.h> 22 #include <cutils/sockets.h> 23 24 int main(int argc, char *argv[]) { 25 char buffer[65536]; 26 int i, s; 27 28 /* start the dumpstate service */ 29 property_set("ctl.start", "dumpstate"); 30 31 /* socket will not be available until service starts */ 32 for (i = 0; i < 10; i++) { 33 s = socket_local_client("dumpstate", 34 ANDROID_SOCKET_NAMESPACE_RESERVED, 35 SOCK_STREAM); 36 if (s >= 0) 37 break; 38 /* try again in 1 second */ 39 sleep(1); 40 } 41 42 if (s < 0) { 43 fprintf(stderr, "Failed to connect to dumpstate service\n"); 44 exit(1); 45 } 46 47 while (1) { 48 int length = read(s, buffer, sizeof(buffer)); 49 if (length <= 0) 50 break; 51 fwrite(buffer, 1, length, stdout); 52 } 53 54 close(s); 55 return 0; 56 } 57