blob: 7f7040217357cd1159ec9b7c87f18b17a61df5c3 [file] [log] [blame]
Gerhard Riegerdf493f12008-01-28 22:37:16 +01001/* source: procan_main.c */
Gerhard Riegerd34493c2016-07-22 08:54:31 +02002/* Copyright Gerhard Rieger and contributors (see file CHANGES) */
Gerhard Riegerb8195722008-01-27 13:00:08 +01003/* Published under the GNU General Public License V.2, see file COPYING */
4
Gerhard Riegerd34493c2016-07-22 08:54:31 +02005const char copyright[] = "procan by Gerhard Rieger and contributors - send bug reports to socat@dest-unreach.org";
Gerhard Riegerb8195722008-01-27 13:00:08 +01006
Gerhard Rieger2af04952015-01-12 21:46:16 +01007#include <signal.h> /* sig_atomic_t for error.h */
8#include <time.h> /* struct timespec for error.h */
Gerhard Riegerb8195722008-01-27 13:00:08 +01009#include <stdlib.h> /* strtoul() */
10#include <string.h>
11#include <stdio.h>
Gerhard Rieger2af04952015-01-12 21:46:16 +010012#include "config.h"
13#if HAVE_SYS_SELECT_H
14#include <sys/select.h> /* select(), fdset on FreeBSD */
15#endif
Gerhard Riegerb8195722008-01-27 13:00:08 +010016#include "mytypes.h"
17#include "error.h"
18#include "procan.h"
19#include "hostan.h"
20
21
22#define WITH_HELP 1
23
24static void procan_usage(FILE *fd);
25
26
27int 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 Rieger989790c2008-01-31 21:41:13 +010041 case 'c': procan_cdefs(stdout); exit(0);
Gerhard Riegerb8195722008-01-27 13:00:08 +010042#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
77static 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 Rieger989790c2008-01-31 21:41:13 +010089 fputs(" -c print values of compile time C defines\n", fd);
Gerhard Riegerb8195722008-01-27 13:00:08 +010090#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 */