File: procan_main.c

package info (click to toggle)
socat 2.0.0~beta9-1
  • links: PTS
  • area: main
  • in suites: experimental
  • size: 3,740 kB
  • sloc: ansic: 30,875; sh: 11,630; makefile: 149
file content (102 lines) | stat: -rw-r--r-- 2,760 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/* source: procan_main.c */
/* Copyright Gerhard Rieger */
/* Published under the GNU General Public License V.2, see file COPYING */

const char copyright[] = "procan by Gerhard Rieger - send bug reports to socat@dest-unreach.org";

#include <signal.h>	/* sig_atomic_t for error.h */
#include <time.h>	/* struct timespec for error.h */
#include <stdlib.h>	/* strtoul() */
#include <string.h>
#include <stdio.h>
#include "config.h"
#if HAVE_SYS_SELECT_H
#include <sys/select.h>	/* select(), fdset on FreeBSD */
#endif
#include "mytypes.h"
#include "error.h"
#include "procan.h"
#include "hostan.h"


#define WITH_HELP 1

static void procan_usage(FILE *fd);


int main(int argc, const char *argv[]) {
   const char **arg1;
#if 0
   unsigned int n = 1024;	/* this is default on my Linux */
#endif

   diag_set('p', strchr(argv[0], '/') ? strrchr(argv[0], '/')+1 : argv[0]);

   arg1 = argv+1;  --argc;
   while (arg1[0] && (arg1[0][0] == '-')) {
      switch (arg1[0][1]) {
#if WITH_HELP
      case '?': case 'h': procan_usage(stdout); exit(0);
#endif /* WITH_HELP */
      case 'c': procan_cdefs(stdout); exit(0);
#if LATER
      case 'V': procan_version(stdout); exit(0);
      case 'l': diag_set(arg1[0][2], &arg1[0][3]); break;
      case 'd': diag_set('d', NULL); break;
#endif
#if 0
      case 'n': n = strtoul(&arg1[0][2], NULL, 0); break;
#endif
      case '\0': break;
      default:
	 diag_set_int('e', E_FATAL);
	 Error1("unknown option \"%s\"", arg1[0]);
#if WITH_HELP
	 procan_usage(stderr);
#endif
	 exit(1);
      }
      if (arg1[0][1] == '\0')
	 break;
      ++arg1; --argc;
   }
   if (argc != 0) {
      Error1("%d superfluous arguments", argc);
#if WITH_HELP
      procan_usage(stderr);
#endif
      exit(1);
   }
   procan(stdout);
   hostan(stdout);
   return 0;
}


#if WITH_HELP
static void procan_usage(FILE *fd) {
   fputs(copyright, fd); fputc('\n', fd);
   fputs("Analyze system parameters of process\n", fd);
   fputs("Usage:\n", fd);
   fputs("procan [options]\n", fd);
   fputs("   options:\n", fd);
#if LATER
   fputs("      -V     print version information to stdout, and exit\n", fd);
#endif
#if WITH_HELP
   fputs("      -?|-h  print a help text describing command line options\n", fd);
#endif
   fputs("      -c     print values of compile time C defines\n", fd);
#if LATER
   fputs("      -d     increase verbosity (use up to 4 times; 2 are recommended)\n", fd);
#endif
#if 0
   fputs("      -ly[facility]  log to syslog, using facility (default is daemon)\n", fd);
   fputs("      -lf<logfile>   log to file\n", fd);
   fputs("      -ls            log to stderr (default if no other log)\n", fd);
#endif
#if 0
   fputs("      -n<fdnum>      first file descriptor number not analyzed\n", fd);
#endif
}
#endif /* WITH_HELP */