47 |
|
|
48 |
#define MAX_TTY_SIZE (sizeof (PATH_TTY_PFX) + sizeof (((UTMP*)0)->ut_line)) |
#define MAX_TTY_SIZE (sizeof (PATH_TTY_PFX) + sizeof (((UTMP*)0)->ut_line)) |
49 |
|
|
50 |
static char short_options[] = "c:dhim:p:t:v"; |
const char *argp_program_version = "comsatd (" PACKAGE ") " VERSION; |
51 |
static struct option long_options[] = |
const char *argp_program_bug_address = "<bug-mailutils@gnu.org>"; |
52 |
|
static char doc[] = "GNU comsatd"; |
53 |
|
|
54 |
|
static struct argp_option options[] = |
55 |
{ |
{ |
56 |
{"config", required_argument, 0, 'c'}, |
{"config", 'c', "FILE", 0, "Read configuration from FILE", 0}, |
57 |
{"daemon", no_argument, 0, 'd'}, |
{ NULL, 0, NULL, 0, NULL, 0 } |
|
{"help", no_argument, 0, 'h'}, |
|
|
{"inetd", no_argument, 0, 'i'}, |
|
|
{"maildir", required_argument, 0, 'm'}, |
|
|
{"port", required_argument, 0, 'p'}, |
|
|
{"timeout", required_argument, 0, 't'}, |
|
|
{"version", no_argument, 0, 'v'}, |
|
|
{0, 0, 0, 0} |
|
58 |
}; |
}; |
59 |
|
|
60 |
#define MODE_INETD 0 |
static error_t comsatd_parse_opt (int key, char *arg, struct argp_state *state); |
61 |
#define MODE_DAEMON 1 |
|
62 |
|
static struct argp argp = { |
63 |
|
options, |
64 |
|
comsatd_parse_opt, |
65 |
|
NULL, |
66 |
|
doc, |
67 |
|
mu_daemon_argp_child, |
68 |
|
NULL, NULL |
69 |
|
}; |
70 |
|
|
71 |
#define SUCCESS 0 |
#define SUCCESS 0 |
72 |
#define NOT_HERE 1 |
#define NOT_HERE 1 |
76 |
# define MAXHOSTNAMELEN 64 |
# define MAXHOSTNAMELEN 64 |
77 |
#endif |
#endif |
78 |
|
|
79 |
int mode = MODE_INETD; |
struct daemon_param daemon_param = { |
80 |
int port = 512; /* Default biff port */ |
MODE_INTERACTIVE, /* Start in interactive (inetd) mode */ |
81 |
int timeout = 0; |
20, /* Default maximum number of children. |
82 |
|
Currently unused */ |
83 |
|
512, /* Default biff port */ |
84 |
|
0, /* Default timeout */ |
85 |
|
}; |
86 |
int maxlines = 5; |
int maxlines = 5; |
87 |
char hostname[MAXHOSTNAMELEN]; |
char hostname[MAXHOSTNAMELEN]; |
88 |
const char *username; |
const char *username; |
|
const char *maildir = MU_PATH_MAILDIR; |
|
89 |
|
|
90 |
static void comsat_init (void); |
static void comsat_init (void); |
91 |
static void comsat_daemon_init (void); |
static void comsat_daemon_init (void); |
99 |
|
|
100 |
static int xargc; |
static int xargc; |
101 |
static char **xargv; |
static char **xargv; |
102 |
|
char *config_file = NULL; |
103 |
|
|
104 |
|
static error_t |
105 |
|
comsatd_parse_opt (int key, char *arg, struct argp_state *state) |
106 |
|
{ |
107 |
|
switch (key) |
108 |
|
{ |
109 |
|
case ARGP_KEY_INIT: |
110 |
|
state->child_inputs[0] = state->input; |
111 |
|
break; |
112 |
|
|
113 |
|
case 'c': |
114 |
|
config_file = arg; |
115 |
|
break; |
116 |
|
|
117 |
|
default: |
118 |
|
return ARGP_ERR_UNKNOWN; |
119 |
|
} |
120 |
|
return 0; |
121 |
|
} |
122 |
|
|
123 |
|
|
124 |
int |
int |
125 |
main(int argc, char **argv) |
main(int argc, char **argv) |
126 |
{ |
{ |
127 |
int c; |
int c; |
128 |
char *config_file = NULL; |
|
129 |
|
mu_create_argcv (argc, argv, &argc, &argv); |
130 |
while ((c = getopt_long (argc, argv, short_options, long_options, NULL)) |
argp_parse (&argp, argc, argv, 0, 0, &daemon_param); |
|
!= -1) |
|
|
{ |
|
|
switch (c) |
|
|
{ |
|
|
case 'c': |
|
|
config_file = optarg; |
|
|
break; |
|
|
|
|
|
case 'd': |
|
|
mode = MODE_DAEMON; |
|
|
break; |
|
|
|
|
|
case 'h': |
|
|
help (); |
|
|
/*NOTREACHED*/ |
|
|
|
|
|
case 'i': |
|
|
mode = MODE_INETD; |
|
|
break; |
|
|
|
|
|
case 'm': |
|
|
maildir = optarg; |
|
|
break; |
|
|
|
|
|
case 'p': |
|
|
port = strtoul (optarg, NULL, 10); |
|
|
break; |
|
|
|
|
|
case 't': |
|
|
timeout = strtoul (optarg, NULL, 10); |
|
|
break; |
|
|
|
|
|
case 'v': |
|
|
printf (IMPL " ("PACKAGE " " VERSION ")\n"); |
|
|
exit (EXIT_SUCCESS); |
|
|
break; |
|
|
|
|
|
default: |
|
|
exit (EXIT_FAILURE); |
|
|
} |
|
|
} |
|
131 |
|
|
132 |
maildir = mu_normalize_maildir (maildir); |
maildir = mu_normalize_maildir (maildir); |
133 |
if (!maildir) |
if (!maildir) |
136 |
exit (1); |
exit (1); |
137 |
} |
} |
138 |
|
|
139 |
if (timeout > 0 && mode == MODE_DAEMON) |
if (daemon_param.timeout > 0 && daemon_param.mode == MODE_DAEMON) |
140 |
{ |
{ |
141 |
fprintf (stderr, "--timeout and --daemon are incompatible\n"); |
fprintf (stderr, "--timeout and --daemon are incompatible\n"); |
142 |
exit (EXIT_FAILURE); |
exit (EXIT_FAILURE); |
144 |
|
|
145 |
comsat_init (); |
comsat_init (); |
146 |
|
|
147 |
if (mode == MODE_DAEMON) |
if (daemon_param.mode == MODE_DAEMON) |
148 |
{ |
{ |
149 |
/* Preserve invocation arguments */ |
/* Preserve invocation arguments */ |
150 |
xargc = argc; |
xargc = argc; |
161 |
|
|
162 |
chdir ("/"); |
chdir ("/"); |
163 |
|
|
164 |
if (mode == MODE_DAEMON) |
if (daemon_param.mode == MODE_DAEMON) |
165 |
comsat_daemon (port); |
comsat_daemon (daemon_param.port); |
166 |
else |
else |
167 |
c = comsat_main (0); |
c = comsat_main (0); |
168 |
|
|