You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

102 lines
2.7 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /* source: procan_main.c */
  2. /* Copyright Gerhard Rieger and contributors (see file CHANGES) */
  3. /* Published under the GNU General Public License V.2, see file COPYING */
  4. const char copyright[] = "procan by Gerhard Rieger and contributors - send bug reports to socat@dest-unreach.org";
  5. #include <signal.h> /* sig_atomic_t for error.h */
  6. #include <time.h> /* struct timespec for error.h */
  7. #include <stdlib.h> /* strtoul() */
  8. #include <string.h>
  9. #include <stdio.h>
  10. #include "config.h"
  11. #if HAVE_SYS_SELECT_H
  12. #include <sys/select.h> /* select(), fdset on FreeBSD */
  13. #endif
  14. #include "mytypes.h"
  15. #include "error.h"
  16. #include "procan.h"
  17. #include "hostan.h"
  18. #define WITH_HELP 1
  19. static void procan_usage(FILE *fd);
  20. int main(int argc, const char *argv[]) {
  21. const char **arg1;
  22. #if 0
  23. unsigned int n = 1024; /* this is default on my Linux */
  24. #endif
  25. diag_set('p', strchr(argv[0], '/') ? strrchr(argv[0], '/')+1 : argv[0]);
  26. arg1 = argv+1; --argc;
  27. while (arg1[0] && (arg1[0][0] == '-')) {
  28. switch (arg1[0][1]) {
  29. #if WITH_HELP
  30. case '?': case 'h': procan_usage(stdout); exit(0);
  31. #endif /* WITH_HELP */
  32. case 'c': procan_cdefs(stdout); exit(0);
  33. #if LATER
  34. case 'V': procan_version(stdout); exit(0);
  35. case 'l': diag_set(arg1[0][2], &arg1[0][3]); break;
  36. case 'd': diag_set('d', NULL); break;
  37. #endif
  38. #if 0
  39. case 'n': n = strtoul(&arg1[0][2], NULL, 0); break;
  40. #endif
  41. case '\0': break;
  42. default:
  43. diag_set_int('e', E_FATAL);
  44. Error1("unknown option \"%s\"", arg1[0]);
  45. #if WITH_HELP
  46. procan_usage(stderr);
  47. #endif
  48. exit(1);
  49. }
  50. if (arg1[0][1] == '\0')
  51. break;
  52. ++arg1; --argc;
  53. }
  54. if (argc != 0) {
  55. Error1("%d superfluous arguments", argc);
  56. #if WITH_HELP
  57. procan_usage(stderr);
  58. #endif
  59. exit(1);
  60. }
  61. procan(stdout);
  62. hostan(stdout);
  63. return 0;
  64. }
  65. #if WITH_HELP
  66. static void procan_usage(FILE *fd) {
  67. fputs(copyright, fd); fputc('\n', fd);
  68. fputs("Analyze system parameters of process\n", fd);
  69. fputs("Usage:\n", fd);
  70. fputs("procan [options]\n", fd);
  71. fputs(" options:\n", fd);
  72. #if LATER
  73. fputs(" -V print version information to stdout, and exit\n", fd);
  74. #endif
  75. #if WITH_HELP
  76. fputs(" -?|-h print a help text describing command line options\n", fd);
  77. #endif
  78. fputs(" -c print values of compile time C defines\n", fd);
  79. #if LATER
  80. fputs(" -d increase verbosity (use up to 4 times; 2 are recommended)\n", fd);
  81. #endif
  82. #if 0
  83. fputs(" -ly[facility] log to syslog, using facility (default is daemon)\n", fd);
  84. fputs(" -lf<logfile> log to file\n", fd);
  85. fputs(" -ls log to stderr (default if no other log)\n", fd);
  86. #endif
  87. #if 0
  88. fputs(" -n<fdnum> first file descriptor number not analyzed\n", fd);
  89. #endif
  90. }
  91. #endif /* WITH_HELP */