mirror of
https://github.com/3cky/mbusd.git
synced 2025-02-11 00:11:28 +01:00
Mostly cosmetical changes in switches handling
This commit is contained in:
parent
2a83a72816
commit
207a3f9e9e
94
src/main.c
94
src/main.c
@ -28,10 +28,12 @@
|
|||||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*
|
*
|
||||||
* $Id: main.c,v 1.2 2003/09/27 13:22:52 kapyar Exp $
|
* $Id: main.c,v 1.3 2003/10/10 20:40:53 kapyar Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "globals.h"
|
#include "globals.h"
|
||||||
|
#include "string.h"
|
||||||
|
#include "errno.h"
|
||||||
#include "cfg.h"
|
#include "cfg.h"
|
||||||
#include "tty.h"
|
#include "tty.h"
|
||||||
#include "sock.h"
|
#include "sock.h"
|
||||||
@ -42,6 +44,7 @@
|
|||||||
# include "log.h"
|
# include "log.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
extern char logfullname[];
|
||||||
int isdaemon = TRUE;
|
int isdaemon = TRUE;
|
||||||
|
|
||||||
void usage(char *exename);
|
void usage(char *exename);
|
||||||
@ -96,33 +99,34 @@ daemon(nochdir, noclose)
|
|||||||
void
|
void
|
||||||
usage(char *exename)
|
usage(char *exename)
|
||||||
{
|
{
|
||||||
printf("%s-%s copyright (c) Victor Antonovich, 2002-2003 // 2:5055/124.13@fidonet\n"
|
printf("%s-%s Copyright (C) 2002, 2003 Victor Antonovich <avmlink@vlink.ru>\n\n"
|
||||||
"usage: %s [<options>] \n"
|
"Usage: %s [-h] [-d] [-v level] [-L name] [-p name] [-s value] [-P number]\n"
|
||||||
"-h this help\n"
|
" [-C number] [-N number] [-R value] [-W value] [-T value]\n\n"
|
||||||
"-d don't daemonize\n"
|
" -h this help\n"
|
||||||
|
" -d don't daemonize\n"
|
||||||
#ifdef LOG
|
#ifdef LOG
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
"-v<level> set log level (0-9, default %d, 0 - errors only)\n"
|
" -v<level> set log level (0-9, default %d, 0 - errors only)\n"
|
||||||
#else
|
#else
|
||||||
"-v<level> set log level (0-2, default %d, 0 - errors only)\n"
|
" -v<level> set log level (0-2, default %d, 0 - errors only)\n"
|
||||||
#endif
|
#endif
|
||||||
"-L<name> set log file name (default %s%s)\n"
|
" -L<name> set log file name (default %s%s)\n"
|
||||||
#endif
|
#endif
|
||||||
"-p<name> set serial port device name (default %s)\n"
|
" -p<name> set serial port device name (default %s)\n"
|
||||||
"-s<value> set serial port speed (default %d)\n"
|
" -s<value> set serial port speed (default %d)\n"
|
||||||
#ifdef TRXCTL
|
#ifdef TRXCTL
|
||||||
"-t force RTS RS-485 transmitting/receiving control\n"
|
" -t force RTS RS-485 transmitting/receiving control\n"
|
||||||
#endif
|
#endif
|
||||||
"-P<number> set TCP server port number (default %d)\n"
|
" -P<number> set TCP server port number (default %d)\n"
|
||||||
"-C<number> set number of simultaneous connections\n"
|
" -C<number> set maximum number of simultaneous connections\n"
|
||||||
" (1-128, default %d)\n"
|
" (1-128, default %d)\n"
|
||||||
"-N<number> set number of request retries\n"
|
" -N<number> set maximum number of request retries\n"
|
||||||
" (0-15, default %d, 0 - without retries)\n"
|
" (0-15, default %d, 0 - without retries)\n"
|
||||||
"-R<value> set pause between requests, millisecs\n"
|
" -R<value> set pause between requests in milliseconds\n"
|
||||||
" (1-10000, default %lu)\n"
|
" (1-10000, default %lu)\n"
|
||||||
"-W<value> set response wait time, millisecs\n"
|
" -W<value> set response wait time in milliseconds\n"
|
||||||
" (1-10000, default %lu)\n"
|
" (1-10000, default %lu)\n"
|
||||||
"-T<value> set connection timeout value, secs\n"
|
" -T<value> set connection timeout value in seconds\n"
|
||||||
" (0-1000, default %d, 0 - no timeout)"
|
" (0-1000, default %d, 0 - no timeout)"
|
||||||
"\n", PACKAGE, VERSION, exename,
|
"\n", PACKAGE, VERSION, exename,
|
||||||
#ifdef LOG
|
#ifdef LOG
|
||||||
@ -137,10 +141,17 @@ int
|
|||||||
main(int argc, char *argv[])
|
main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int err = 0, rc;
|
int err = 0, rc;
|
||||||
|
char *exename;
|
||||||
|
|
||||||
sig_init();
|
sig_init();
|
||||||
cfg_init();
|
cfg_init();
|
||||||
|
|
||||||
/* command line parsing */
|
if ((exename = strrchr(argv[0], '/')) == NULL)
|
||||||
|
exename = argv[0];
|
||||||
|
else
|
||||||
|
exename++;
|
||||||
|
|
||||||
|
/* command line argument list parsing */
|
||||||
while ((rc = getopt(argc, argv,
|
while ((rc = getopt(argc, argv,
|
||||||
"dh"
|
"dh"
|
||||||
#ifdef TRXCTL
|
#ifdef TRXCTL
|
||||||
@ -153,6 +164,8 @@ main(int argc, char *argv[])
|
|||||||
{
|
{
|
||||||
switch (rc)
|
switch (rc)
|
||||||
{
|
{
|
||||||
|
case '?':
|
||||||
|
exit(-1);
|
||||||
case 'd':
|
case 'd':
|
||||||
isdaemon = FALSE;
|
isdaemon = FALSE;
|
||||||
break;
|
break;
|
||||||
@ -167,13 +180,13 @@ main(int argc, char *argv[])
|
|||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
if (cfg.dbglvl < 0 || cfg.dbglvl > 9)
|
if (cfg.dbglvl < 0 || cfg.dbglvl > 9)
|
||||||
{ /* report about invalid log level */
|
{ /* report about invalid log level */
|
||||||
printf("-v: invalid loglevel"
|
printf("%s: -v: invalid loglevel value"
|
||||||
" (%d, must be 0-9)\n", cfg.dbglvl);
|
" (%d, must be 0-9)\n", exename, cfg.dbglvl);
|
||||||
#else
|
#else
|
||||||
if (cfg.dbglvl < 0 || cfg.dbglvl > 9)
|
if (cfg.dbglvl < 0 || cfg.dbglvl > 9)
|
||||||
{ /* report about invalid log level */
|
{ /* report about invalid log level */
|
||||||
printf("-v: invalid loglevel"
|
printf("%s: -v: invalid loglevel value"
|
||||||
" (%d, must be 0-2)\n", cfg.dbglvl);
|
" (%d, must be 0-2)\n", exename, cfg.dbglvl);
|
||||||
#endif
|
#endif
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
@ -190,8 +203,8 @@ main(int argc, char *argv[])
|
|||||||
#endif
|
#endif
|
||||||
case 'p':
|
case 'p':
|
||||||
if (*optarg != '/')
|
if (*optarg != '/')
|
||||||
{ /* concatenate given port name with default */
|
{ /* concatenate given port name with default
|
||||||
/* path to devices mountpoint */
|
path to devices mountpoint */
|
||||||
strncpy(cfg.ttyport, "/dev/", INTBUFSIZE);
|
strncpy(cfg.ttyport, "/dev/", INTBUFSIZE);
|
||||||
strncat(cfg.ttyport, optarg,
|
strncat(cfg.ttyport, optarg,
|
||||||
INTBUFSIZE - strlen(cfg.ttyport));
|
INTBUFSIZE - strlen(cfg.ttyport));
|
||||||
@ -208,17 +221,17 @@ main(int argc, char *argv[])
|
|||||||
cfg.maxconn = strtoul(optarg, NULL, 0);
|
cfg.maxconn = strtoul(optarg, NULL, 0);
|
||||||
if (cfg.maxconn < 1 || cfg.maxconn > 128)
|
if (cfg.maxconn < 1 || cfg.maxconn > 128)
|
||||||
{ /* report about invalid max conn number */
|
{ /* report about invalid max conn number */
|
||||||
printf("-C: invalid number"
|
printf("%s: -C: invalid maxconn value"
|
||||||
" (%d, must be 1-128)\n", cfg.maxconn);
|
" (%d, must be 1-128)\n", exename, cfg.maxconn);
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'N':
|
case 'N':
|
||||||
cfg.maxtry = strtoul(optarg, NULL, 0);
|
cfg.maxtry = strtoul(optarg, NULL, 0);
|
||||||
if (cfg.maxtry > 15)
|
if (cfg.maxtry > 15)
|
||||||
{ /* report about invalid max conn number */
|
{ /* report about invalid max try number */
|
||||||
printf("-N: invalid number"
|
printf("%s: -N: invalid maxtry value"
|
||||||
" (%d, must be 0-15)\n", cfg.maxtry);
|
" (%d, must be 0-15)\n", exename, cfg.maxtry);
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -226,8 +239,8 @@ main(int argc, char *argv[])
|
|||||||
cfg.rqstpause = strtoul(optarg, NULL, 0);
|
cfg.rqstpause = strtoul(optarg, NULL, 0);
|
||||||
if (cfg.rqstpause < 1 || cfg.rqstpause > 10000)
|
if (cfg.rqstpause < 1 || cfg.rqstpause > 10000)
|
||||||
{ /* report about invalid rqst pause value */
|
{ /* report about invalid rqst pause value */
|
||||||
printf("-R: invalid number"
|
printf("%s: -R: invalid inter-request pause value"
|
||||||
" (%lu, must be 1-10000)\n", cfg.rqstpause);
|
" (%lu, must be 1-10000)\n", exename, cfg.rqstpause);
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -235,8 +248,8 @@ main(int argc, char *argv[])
|
|||||||
cfg.respwait = strtoul(optarg, NULL, 0);
|
cfg.respwait = strtoul(optarg, NULL, 0);
|
||||||
if (cfg.respwait < 1 || cfg.respwait > 10000)
|
if (cfg.respwait < 1 || cfg.respwait > 10000)
|
||||||
{ /* report about invalid resp wait value */
|
{ /* report about invalid resp wait value */
|
||||||
printf("-W: invalid number"
|
printf("%s: -W: invalid response wait time value"
|
||||||
" (%lu, must be 1-10000)\n", cfg.respwait);
|
" (%lu, must be 1-10000)\n", exename, cfg.respwait);
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -244,18 +257,25 @@ main(int argc, char *argv[])
|
|||||||
cfg.conntimeout = strtoul(optarg, NULL, 0);
|
cfg.conntimeout = strtoul(optarg, NULL, 0);
|
||||||
if (cfg.conntimeout > 1000)
|
if (cfg.conntimeout > 1000)
|
||||||
{ /* report about invalid conn timeout value */
|
{ /* report about invalid conn timeout value */
|
||||||
printf("-T: invalid number"
|
printf("%s: -T: invalid conn timeout value"
|
||||||
" (%d, must be 1-1000)\n", cfg.conntimeout);
|
" (%d, must be 1-1000)\n", exename, cfg.conntimeout);
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'h':
|
case 'h':
|
||||||
usage(argv[0]);
|
usage(exename);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef LOG
|
#ifdef LOG
|
||||||
log_init(cfg.logname);
|
if (log_init(cfg.logname) != RC_OK)
|
||||||
|
{
|
||||||
|
printf("%s: can't open logfile '%s' (%s), exiting...\n",
|
||||||
|
exename,
|
||||||
|
logfullname[0] ? logfullname : "no log name was given",
|
||||||
|
strerror(errno));
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
log(2, "%s-%s started...", PACKAGE, VERSION);
|
log(2, "%s-%s started...", PACKAGE, VERSION);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user