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