phoned/phoned/main.c

61 lines
1.1 KiB
C
Raw Normal View History

2005-05-31 20:37:22 -04:00
/*
* main.c - phoned main
* (C)2005, Dan Ponte
* BSD license with advert. clause.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <getopt.h>
#include <unistd.h>
#include <pthread.h>
2005-05-31 20:37:22 -04:00
#include <phoned.h>
extern struct conf cf;
short difflog = 0;
extern pthread_mutex_t cfmx;
extern pthread_t networkth;
extern pthread_t modemth;
2005-05-31 20:37:22 -04:00
void usage(argv)
const char* argv;
{
2005-06-01 22:55:07 -04:00
fprintf(stderr, "%s: usage: %s [-hd] [-c config] [-l log]\n", argv, argv);
2005-05-31 20:37:22 -04:00
}
int main(argc, argv)
int argc;
char* argv[];
{
int c;
pthread_mutex_lock(&cfmx);
2005-05-31 20:37:22 -04:00
cf.cfile = CONFIGFILE;
2005-06-01 22:55:07 -04:00
#define OPTSTRING "dhc:l:"
2005-05-31 20:37:22 -04:00
while((c = getopt(argc, argv, OPTSTRING)) != -1)
switch(c) {
case 'c':
cf.cfile = strdup(optarg);
break;
case 'h':
usage(strdup(*argv));
return 0;
case 'l':
cf.logfile = strdup(optarg);
difflog = 1;
break;
2005-06-01 22:55:07 -04:00
case 'd':
2005-06-01 23:02:33 -04:00
daemon(1, 0);
2005-06-01 22:55:07 -04:00
break;
2005-05-31 20:37:22 -04:00
default:
usage(strdup(*argv));
return -2;
}
cf.modem_tm = 0;
2005-05-31 20:37:22 -04:00
cf.loglevels = LL_ALL;
pthread_mutex_unlock(&cfmx);
2005-05-31 20:37:22 -04:00
initialize();
pthread_create(&networkth, NULL, network, NULL);
pthread_create(&modemth, NULL, modem_io, NULL);
pthread_exit(NULL);
2005-05-31 20:37:22 -04:00
return 0;
}