main.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with this
  4. * work for additional information regarding copyright ownership. The ASF
  5. * licenses this file to you under the Apache License, Version 2.0 (the
  6. * "License"); you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  13. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  14. * License for the specific language governing permissions and limitations under
  15. * the License.
  16. */
  17. #include "winutils.h"
  18. #include <winbase.h>
  19. static void Usage(LPCWSTR program);
  20. LONG WINAPI WinutilsSehUnhandled(_In_ struct _EXCEPTION_POINTERS *ecxr) {
  21. LogDebugMessage(L"unhandled SEH: code:%x flags:%d\n",
  22. ecxr->ExceptionRecord->ExceptionCode,
  23. ecxr->ExceptionRecord->ExceptionFlags);
  24. fwprintf(stderr, L"Unhandled exception code:%x at address:%p",
  25. ecxr->ExceptionRecord->ExceptionCode,
  26. ecxr->ExceptionRecord->ExceptionAddress);
  27. ExitProcess(ERROR_UNHANDLED_EXCEPTION);
  28. return EXCEPTION_EXECUTE_HANDLER; // not that it matters...
  29. }
  30. int wmain(__in int argc, __in_ecount(argc) wchar_t* argv[])
  31. {
  32. LPCWSTR cmd = NULL;
  33. SetUnhandledExceptionFilter(WinutilsSehUnhandled);
  34. if (argc < 2)
  35. {
  36. Usage(argv[0]);
  37. return EXIT_FAILURE;
  38. }
  39. cmd = argv[1];
  40. if (wcscmp(L"ls", cmd) == 0)
  41. {
  42. return Ls(argc - 1, argv + 1);
  43. }
  44. else if (wcscmp(L"chmod", cmd) == 0)
  45. {
  46. return Chmod(argc - 1, argv + 1);
  47. }
  48. else if (wcscmp(L"chown", cmd) == 0)
  49. {
  50. return Chown(argc - 1, argv + 1);
  51. }
  52. else if (wcscmp(L"groups", cmd) == 0)
  53. {
  54. return Groups(argc - 1, argv + 1);
  55. }
  56. else if (wcscmp(L"hardlink", cmd) == 0)
  57. {
  58. return Hardlink(argc - 1, argv + 1);
  59. }
  60. else if (wcscmp(L"symlink", cmd) == 0)
  61. {
  62. return Symlink(argc - 1, argv + 1);
  63. }
  64. else if (wcscmp(L"readlink", cmd) == 0)
  65. {
  66. return Readlink(argc - 1, argv + 1);
  67. }
  68. else if (wcscmp(L"task", cmd) == 0)
  69. {
  70. return Task(argc - 1, argv + 1);
  71. }
  72. else if (wcscmp(L"systeminfo", cmd) == 0)
  73. {
  74. return SystemInfo();
  75. }
  76. else if (wcscmp(L"service", cmd) == 0)
  77. {
  78. return RunService(argc - 1, argv + 1);
  79. }
  80. else if (wcscmp(L"help", cmd) == 0)
  81. {
  82. Usage(argv[0]);
  83. return EXIT_SUCCESS;
  84. }
  85. else
  86. {
  87. Usage(argv[0]);
  88. return EXIT_FAILURE;
  89. }
  90. }
  91. static void Usage(LPCWSTR program)
  92. {
  93. fwprintf(stdout, L"Usage: %s [command] ...\n\
  94. Provide basic command line utilities for Hadoop on Windows.\n\n\
  95. The available commands and their usages are:\n\n", program);
  96. fwprintf(stdout, L"%-15s%s\n\n", L"chmod", L"Change file mode bits.");
  97. ChmodUsage(L"chmod");
  98. fwprintf(stdout, L"\n\n");
  99. fwprintf(stdout, L"%-15s%s\n\n", L"chown", L"Change file owner.");
  100. ChownUsage(L"chown");
  101. fwprintf(stdout, L"\n\n");
  102. fwprintf(stdout, L"%-15s%s\n\n", L"groups", L"List user groups.");
  103. GroupsUsage(L"groups");
  104. fwprintf(stdout, L"\n\n");
  105. fwprintf(stdout, L"%-15s%s\n\n", L"hardlink", L"Hard link operations.");
  106. HardlinkUsage();
  107. fwprintf(stdout, L"\n\n");
  108. fwprintf(stdout, L"%-15s%s\n\n", L"ls", L"List file information.");
  109. LsUsage(L"ls");
  110. fwprintf(stdout, L"\n\n");
  111. fwprintf(stdout, L"%-10s%s\n\n", L"symlink", L"Create a symbolic link.");
  112. SymlinkUsage();
  113. fwprintf(stdout, L"\n\n");
  114. fwprintf(stdout, L"%-10s%s\n\n", L"readlink", L"Print the target of a symbolic link.");
  115. ReadlinkUsage();
  116. fwprintf(stdout, L"\n\n");
  117. fwprintf(stdout, L"%-15s%s\n\n", L"systeminfo", L"System information.");
  118. SystemInfoUsage();
  119. fwprintf(stdout, L"\n\n");
  120. fwprintf(stdout, L"%-15s%s\n\n", L"task", L"Task operations.");
  121. TaskUsage();
  122. fwprintf(stdout, L"%-15s%s\n\n", L"service", L"Service operations.");
  123. ServiceUsage();
  124. fwprintf(stdout, L"\n\n");
  125. }