Improved option checking in ggsn

This commit is contained in:
jjako 2003-07-06 17:07:04 +00:00
parent a7c3381c2b
commit e014978dfb
2 changed files with 41 additions and 35 deletions

View File

@ -1,6 +1,6 @@
bin_PROGRAMS = ggsn bin_PROGRAMS = ggsn
LDFLAGS = -Wl,--rpath -Wl,/usr/local/lib LDFLAGS = -Wl,--rpath -Wl,/usr/local/lib @EXEC_LDFLAGS@
CFLAGS = -O2 -D_GNU_SOURCE -fno-builtin -Wall -ansi -DSBINDIR='"$(sbindir)"' -ggdb -lgtp -L../gtp CFLAGS = -O2 -D_GNU_SOURCE -fno-builtin -Wall -ansi -DSBINDIR='"$(sbindir)"' -ggdb -lgtp -L../gtp

View File

@ -83,8 +83,11 @@ void log_pid(char *pidfile) {
oldmask = umask(022); oldmask = umask(022);
file = fopen(pidfile, "w"); file = fopen(pidfile, "w");
umask(oldmask); umask(oldmask);
if(!file) if(!file) {
sys_err(LOG_ERR, __FILE__, __LINE__, 0,
"Failed to create process ID file: %s!", pidfile);
return; return;
}
fprintf(file, "%d\n", getpid()); fprintf(file, "%d\n", getpid());
fclose(file); fclose(file);
} }
@ -226,39 +229,17 @@ int main(int argc, char **argv)
/* Handle each option */ /* Handle each option */
/* foreground */
/* If flag not given run as a daemon */
if (!args_info.fg_flag)
{
closelog();
/* Close the standard file descriptors. */
/* Is this really needed ? */
freopen("/dev/null", "w", stdout);
freopen("/dev/null", "w", stderr);
freopen("/dev/null", "r", stdin);
daemon(0, 0);
/* Open log again. This time with new pid */
openlog(PACKAGE, LOG_PID, LOG_DAEMON);
}
/* debug */ /* debug */
debug = args_info.debug_flag; debug = args_info.debug_flag;
/* pidfile */
/* This has to be done after we have our final pid */
if (args_info.pidfile_arg) {
log_pid(args_info.pidfile_arg);
}
/* listen */ /* listen */
/* If no listen option is specified listen to any local port */
/* Do hostname lookup to translate hostname to IP address */ /* Do hostname lookup to translate hostname to IP address */
/* Any port listening is not possible as a valid address is */
/* required for create_pdp_context_response messages */
if (args_info.listen_arg) { if (args_info.listen_arg) {
if (!(host = gethostbyname(args_info.listen_arg))) { if (!(host = gethostbyname(args_info.listen_arg))) {
fprintf(stderr, "%s: Invalid listening address: %s!\n", sys_err(LOG_ERR, __FILE__, __LINE__, 0,
PACKAGE, args_info.listen_arg); "Invalid listening address: %s!", args_info.listen_arg);
syslog(LOG_ERR, "Invalid listening address: %s!",
args_info.listen_arg);
exit(1); exit(1);
} }
else { else {
@ -266,7 +247,11 @@ int main(int argc, char **argv)
} }
} }
else { else {
listen_.s_addr = htonl(INADDR_ANY); sys_err(LOG_ERR, __FILE__, __LINE__, 0,
"Listening address must be specified! "
"Please use command line option --listen or "
"edit %s configuration file\n", args_info.conf_arg);
exit(1);
} }
/* net */ /* net */
@ -351,6 +336,28 @@ int main(int argc, char **argv)
apn.l = strlen(args_info.apn_arg) + 1; apn.l = strlen(args_info.apn_arg) + 1;
apn.v[0] = (char) strlen(args_info.apn_arg); apn.v[0] = (char) strlen(args_info.apn_arg);
strncpy(&apn.v[1], args_info.apn_arg, sizeof(apn.v)-1); strncpy(&apn.v[1], args_info.apn_arg, sizeof(apn.v)-1);
/* foreground */
/* If flag not given run as a daemon */
if (!args_info.fg_flag)
{
closelog();
/* Close the standard file descriptors. */
/* Is this really needed ? */
freopen("/dev/null", "w", stdout);
freopen("/dev/null", "w", stderr);
freopen("/dev/null", "r", stdin);
daemon(0, 0);
/* Open log again. This time with new pid */
openlog(PACKAGE, LOG_PID, LOG_DAEMON);
}
/* pidfile */
/* This has to be done after we have our final pid */
if (args_info.pidfile_arg) {
log_pid(args_info.pidfile_arg);
}
if (debug) printf("gtpclient: Initialising GTP tunnel\n"); if (debug) printf("gtpclient: Initialising GTP tunnel\n");
@ -392,11 +399,9 @@ int main(int argc, char **argv)
gtp_retranstimeout(gsn, &idleTime); gtp_retranstimeout(gsn, &idleTime);
switch (select(maxfd + 1, &fds, NULL, NULL, &idleTime)) { switch (select(maxfd + 1, &fds, NULL, NULL, &idleTime)) {
case -1: /* Error with select() * case -1: /* errno == EINTR : unblocked signal */
if (errno != EINTR) sys_err(LOG_ERR, __FILE__, __LINE__, 0,
syslog(LOG_ERR, "CTRL: Error with select(), quitting"); "select() returned -1");
*goto leave_clear_call;*/
syslog(LOG_ERR, "GGSN: select = -1");
break; break;
case 0: case 0:
/* printf("Select returned 0\n"); */ /* printf("Select returned 0\n"); */
@ -408,7 +413,8 @@ int main(int argc, char **argv)
if (tun->fd != -1 && FD_ISSET(tun->fd, &fds) && if (tun->fd != -1 && FD_ISSET(tun->fd, &fds) &&
tun_decaps(tun) < 0) { tun_decaps(tun) < 0) {
syslog(LOG_ERR, "TUN read failed (fd)=(%d)", tun->fd); sys_err(LOG_ERR, __FILE__, __LINE__, 0,
"TUN read failed (fd)=(%d)", tun->fd);
} }
if (FD_ISSET(gsn->fd, &fds)) if (FD_ISSET(gsn->fd, &fds))