No Description

recovery-refresh.cpp 2.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * Copyright (C) 2016 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. // Strictly to deal with reboot into system after OTA, then
  18. // reboot while in system before boot complete landing us back
  19. // into recovery to continue with any mitigations with retained
  20. // log history. This simply refreshes the pmsg files from
  21. // the last pmsg file contents.
  22. //
  23. // Usage:
  24. // recovery-refresh [--force-rotate|--rotate]
  25. //
  26. // All file content representing in the recovery/ directory stored in
  27. // /sys/fs/pstore/pmsg-ramoops-0 in logger format that reside in the
  28. // LOG_ID_SYSTEM buffer at ANDROID_LOG_INFO priority or higher is
  29. // refreshed into /dev/pmsg0. This ensures that an unexpected reboot
  30. // before recovery-persist is run will still contain the associated
  31. // pmsg Android Logger content.
  32. //
  33. // --force-rotate recovery/last_kmsg and recovery.last_log files are
  34. // rotated with .<number> suffixes upwards.
  35. // --rotate rotated only if rocovery/last_msg or recovery/last_log
  36. // exist, otherwise perform 1:1 refresh.
  37. //
  38. #include <string.h>
  39. #include <string>
  40. #include <private/android_logger.h> /* private pmsg functions */
  41. #include "rotate_logs.h"
  42. int main(int argc, char **argv) {
  43. static const char filter[] = "recovery/";
  44. static const char force_rotate_flag[] = "--force-rotate";
  45. static const char rotate_flag[] = "--rotate";
  46. ssize_t ret;
  47. bool doRotate = false;
  48. // Take last pmsg contents and rewrite it to the current pmsg session.
  49. if ((argc <= 1) || !argv[1] ||
  50. (((doRotate = strcmp(argv[1], rotate_flag))) &&
  51. strcmp(argv[1], force_rotate_flag))) {
  52. doRotate = false;
  53. } else if (!doRotate) {
  54. // Do we need to rotate?
  55. __android_log_pmsg_file_read(
  56. LOG_ID_SYSTEM, ANDROID_LOG_INFO, filter,
  57. logbasename, &doRotate);
  58. }
  59. // Take action to refresh pmsg contents
  60. ret = __android_log_pmsg_file_read(
  61. LOG_ID_SYSTEM, ANDROID_LOG_INFO, filter,
  62. logrotate, &doRotate);
  63. return (ret < 0) ? ret : 0;
  64. }