cellsupdownvm.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. #define LOG_TAG "GuiExt"
  2. #include <stdio.h>
  3. #include <sys/socket.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6. #include <strings.h>
  7. #include <unistd.h>
  8. #include <netinet/in.h>
  9. #include <netdb.h>
  10. #include <errno.h>
  11. #include <fcntl.h>
  12. #include <sys/select.h>
  13. #include <sys/stat.h>
  14. #include <sys/time.h>
  15. #include <sys/types.h>
  16. #include <cutils/log.h>
  17. #include <cutils/properties.h>
  18. static void thread_exit_handler(int sig)
  19. {
  20. sig;
  21. pthread_exit(0);
  22. }
  23. int main(int argc, char** argv)
  24. {
  25. struct sigaction actions;
  26. memset(&actions, 0, sizeof(actions));
  27. sigemptyset(&actions.sa_mask);
  28. actions.sa_flags = 0;
  29. actions.sa_handler = thread_exit_handler;
  30. if (sigaction(SIGQUIT|SIGKILL, &actions, NULL) < 0){
  31. ALOGE("sigaction error: %s",strerror(errno));
  32. }
  33. if (argc == 2){
  34. if(strcmp(argv[1],"up") == 0){
  35. property_set("persist.sys.vm.up", "1");
  36. system("rm -rf /data/cells/cell1.tar.gz");
  37. ALOGE("rm -rf /data/cells/cell1.tar.gz \n");
  38. system("cd /data/cells && busybox tar zcvfp cell1.tar.gz cell1-rw");
  39. ALOGE("busybox tar zcvfp /data/cells/cell1.tar.gz /data/cells/cell1-rw \n");
  40. system("cd /data/cells && busybox ftpput -u ftp-hw-user -p 1 129.204.70.73 cell1.tar.gz");
  41. ALOGE("busybox ftpput -u ftp-hw-user -p 1 129.204.70.73 /data/cells/cell1.tar.gz err= %s \n", strerror(errno));
  42. property_set("persist.sys.vm.up", "0");
  43. property_set("persist.sys.vmup", "0");
  44. }else if(strcmp(argv[1],"down") == 0){
  45. property_set("persist.sys.vmstop", "1");
  46. property_set("persist.sys.vmstop", "0");
  47. property_set("persist.sys.vm.down", "1");
  48. if(access("/data/cells/cell1.tar.gz",F_OK)!= 0){
  49. system("touch /data/cells/cell1.tar.gz ");
  50. }
  51. system("cd /data/cells && busybox ftpget -c -u ftp-hw-user -p 1 129.204.70.73 cell1.tar.gz");
  52. ALOGE("busybox ftpget -u ftp-hw-user -p 1 129.204.70.73 /data/cells/cell1.tar.gz err=%s \n", strerror(errno));
  53. system("rm -rf /data/cells/cell1-rw && mkdir /data/cells/cell1-rw");
  54. ALOGE("rm -rf /data/cells/cell1-rw \n");
  55. system("cd /data/cells && busybox tar zxvfp cell1.tar.gz");
  56. ALOGE("busybox tar zxvfp /data/cells/cell1.tar.gz /data/cells/cell1-rw \n");
  57. property_set("persist.sys.vm.down", "0");
  58. property_set("persist.sys.vmdown", "0");
  59. }else if(strcmp(argv[1],"untar") == 0){
  60. if(access("/sdcard/cell1.tar.gz",F_OK) == 0){
  61. if(access("/data/cells/cell1.tar.gz",F_OK) == 0)
  62. system("rm /data/cells/cell1.tar.gz ");
  63. system("mv /sdcard/cell1.tar.gz /data/cells/cell1.tar.gz ");
  64. }else{
  65. if(access("/data/cells/cell1.tar.gz",F_OK) != 0){
  66. return 0;
  67. }
  68. }
  69. property_set("persist.sys.vmstop", "1");
  70. property_set("persist.sys.vmstop", "0");
  71. property_set("persist.sys.vm.untar", "1");
  72. system("rm -rf /data/cells/cell1-rw && mkdir /data/cells/cell1-rw");
  73. ALOGE("rm -rf /data/cells/cell1-rw \n");
  74. system("cd /data/cells && busybox tar zxvfp cell1.tar.gz");
  75. ALOGE("busybox tar zxvfp /data/cells/cell1.tar.gz /data/cells/cell1-rw \n");
  76. property_set("persist.sys.vm.untar", "0");
  77. }
  78. }
  79. return 0;
  80. }