From b0bd74e35e935aa976b68c594def4e8d2c22ef95 Mon Sep 17 00:00:00 2001 From: Andreas Eversberg Date: Sat, 16 Jan 2010 11:20:23 +0100 Subject: Replaced polling loop for LCR and chan_lcr with select based event loop. Now LCR and chan_lcr will not use any CPU until there is work to do. --- gsm.cpp | 147 ++++++++++++++++++++++++++++++++++++++++------------------------ 1 file changed, 93 insertions(+), 54 deletions(-) (limited to 'gsm.cpp') diff --git a/gsm.cpp b/gsm.cpp index e747ff0..3358329 100644 --- a/gsm.cpp +++ b/gsm.cpp @@ -32,8 +32,16 @@ extern int bsc_shutdown_net(struct gsm_network *net); void talloc_ctx_init(void); void on_dso_load_token(void); void on_dso_load_rrlp(void); +void on_dso_load_ho_dec(void); +int bts_model_unknown_init(void); +int bts_model_bs11_init(void); +int bts_model_nanobts_init(void); static struct debug_target *stderr_target; +/* timer to store statistics */ +#define DB_SYNC_INTERVAL 60, 0 +static struct timer_list db_sync_timer; + #include "gsm_audio.h" #undef AF_ISDN @@ -47,6 +55,18 @@ struct lcr_gsm *gsm = NULL; static unsigned int new_callref = 1; +/* timer handling */ +static int _db_store_counter(struct counter *counter, void *data) +{ + return db_store_counter(counter); +} + +static void db_sync_timer_cb(void *data) +{ + /* store counters to database and re-schedule */ + counters_for_each(_db_store_counter, NULL); + bsc_schedule_timer(&db_sync_timer, DB_SYNC_INTERVAL); +} /* * create and send mncc message @@ -70,6 +90,7 @@ static int send_and_free_mncc(struct gsm_network *net, unsigned int msg_type, vo return ret; } +static int delete_event(struct lcr_work *work, void *instance, int index); /* * constructor @@ -77,6 +98,8 @@ static int send_and_free_mncc(struct gsm_network *net, unsigned int msg_type, vo Pgsm::Pgsm(int type, struct mISDNport *mISDNport, char *portname, struct port_settings *settings, int channel, int exclusive, int mode) : PmISDN(type, mISDNport, portname, settings, channel, exclusive, mode) { p_callerinfo.itype = (mISDNport->ifport->interface->extension)?INFO_ITYPE_ISDN_EXTENSION:INFO_ITYPE_ISDN; + memset(&p_m_g_delete, 0, sizeof(p_m_g_delete)); + add_work(&p_m_g_delete, delete_event, this, 0); p_m_g_callref = 0; p_m_g_mode = 0; p_m_g_gsm_b_sock = -1; @@ -87,7 +110,7 @@ Pgsm::Pgsm(int type, struct mISDNport *mISDNport, char *portname, struct port_se p_m_g_encoder = gsm_audio_create(); if (!p_m_g_encoder || !p_m_g_decoder) { PERROR("Failed to create GSM audio codec instance\n"); - p_m_delete = 1; + trigger_work(&p_m_g_delete); } p_m_g_rxpos = 0; p_m_g_tch_connected = 0; @@ -102,6 +125,8 @@ Pgsm::~Pgsm() { PDEBUG(DEBUG_GSM, "Destroyed GSM process(%s).\n", p_name); + del_work(&p_m_g_delete); + /* remove queued message */ if (p_m_g_notify_pending) message_free(p_m_g_notify_pending); @@ -121,18 +146,21 @@ Pgsm::~Pgsm() /* close bsc side bchannel */ void Pgsm::bchannel_close(void) { - if (p_m_g_gsm_b_sock > -1) + if (p_m_g_gsm_b_sock > -1) { + unregister_fd(&p_m_g_gsm_b_fd); close(p_m_g_gsm_b_sock); + } p_m_g_gsm_b_sock = -1; p_m_g_gsm_b_index = -1; p_m_g_gsm_b_active = 0; } +static int b_handler(struct lcr_fd *fd, unsigned int what, void *instance, int index); + /* open bsc side bchannel */ int Pgsm::bchannel_open(int index) { int ret; - unsigned int on = 1; struct sockaddr_mISDN addr; struct mISDNhead act; @@ -148,14 +176,10 @@ int Pgsm::bchannel_open(int index) bchannel_close(); return(ret); } - - /* set nonblocking io */ - ret = ioctl(p_m_g_gsm_b_sock, FIONBIO, &on); - if (ret < 0) { - PERROR("Failed to set bchannel-socket index %d into nonblocking IO\n", index); - bchannel_close(); - return(ret); - } + memset(&p_m_g_gsm_b_fd, 0, sizeof(p_m_g_gsm_b_fd.fd)); + p_m_g_gsm_b_fd.fd = p_m_g_gsm_b_sock; + register_fd(&p_m_g_gsm_b_fd, LCR_FD_READ, b_handler, this, 0); + /* bind socket to bchannel */ addr.family = AF_ISDN; @@ -374,7 +398,7 @@ void Pgsm::setup_ind(unsigned int msg_type, unsigned int callref, struct gsm_mnc end_trace(); send_and_free_mncc((struct gsm_network *)gsm->network, mncc->msg_type, mncc); new_state(PORT_STATE_RELEASE); - p_m_delete = 1; + trigger_work(&p_m_g_delete); return; } p_m_g_callref = callref; @@ -395,7 +419,7 @@ void Pgsm::setup_ind(unsigned int msg_type, unsigned int callref, struct gsm_mnc end_trace(); send_and_free_mncc((struct gsm_network *)gsm->network, mncc->msg_type, mncc); new_state(PORT_STATE_RELEASE); - p_m_delete = 1; + trigger_work(&p_m_g_delete); return; } @@ -467,7 +491,7 @@ void Pgsm::setup_ind(unsigned int msg_type, unsigned int callref, struct gsm_mnc end_trace(); send_and_free_mncc((struct gsm_network *)gsm->network, mncc->msg_type, mncc); new_state(PORT_STATE_RELEASE); - p_m_delete = 1; + trigger_work(&p_m_g_delete); return; } bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_USE); @@ -725,7 +749,7 @@ void Pgsm::disc_ind(unsigned int msg_type, unsigned int callref, struct gsm_mncc free_epointlist(p_epointlist); } new_state(PORT_STATE_RELEASE); - p_m_delete = 1; + trigger_work(&p_m_g_delete); } /* CC_RELEASE INDICATION */ @@ -754,7 +778,7 @@ void Pgsm::rel_ind(unsigned int msg_type, unsigned int callref, struct gsm_mncc free_epointlist(p_epointlist); } new_state(PORT_STATE_RELEASE); - p_m_delete = 1; + trigger_work(&p_m_g_delete); } /* NOTIFY INDICATION */ @@ -985,7 +1009,7 @@ void Pgsm::message_setup(unsigned int epoint_id, int message_id, union parameter message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL; message_put(message); new_state(PORT_STATE_RELEASE); - p_m_delete = 1; + trigger_work(&p_m_g_delete); return; } @@ -999,7 +1023,7 @@ void Pgsm::message_setup(unsigned int epoint_id, int message_id, union parameter message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL; message_put(message); new_state(PORT_STATE_RELEASE); - p_m_delete = 1; + trigger_work(&p_m_g_delete); return; } @@ -1019,7 +1043,7 @@ void Pgsm::message_setup(unsigned int epoint_id, int message_id, union parameter message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL; message_put(message); new_state(PORT_STATE_RELEASE); - p_m_delete = 1; + trigger_work(&p_m_g_delete); return; } bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_USE); @@ -1351,7 +1375,7 @@ void Pgsm::message_release(unsigned int epoint_id, int message_id, union paramet send_and_free_mncc((struct gsm_network *)gsm->network, mncc->msg_type, mncc); new_state(PORT_STATE_RELEASE); - p_m_delete = 1; + trigger_work(&p_m_g_delete); return; } @@ -1434,28 +1458,29 @@ int Pgsm::message_epoint(unsigned int epoint_id, int message_id, union parameter } +/* deletes only if l3id is release, otherwhise it will be triggered then */ +static int delete_event(struct lcr_work *work, void *instance, int index) +{ + class Pgsm *gsmport = (class Pgsm *)instance; + + delete gsmport; + + return 0; +} + /* - * handler + * handler of bchannel events */ -int Pgsm::handler(void) +static int b_handler(struct lcr_fd *fd, unsigned int what, void *instance, int index) { + class Pgsm *gsmport = (class Pgsm *)instance; int ret; - int work = 0; unsigned char buffer[2048+MISDN_HEADER_LEN]; struct mISDNhead *hh = (struct mISDNhead *)buffer; - if ((ret = PmISDN::handler())) - return(ret); - - /* handle destruction */ - if (p_m_delete) { - delete this; - return(-1); - } - /* handle message from bchannel */ - if (p_m_g_gsm_b_sock > -1) { - ret = recv(p_m_g_gsm_b_sock, buffer, sizeof(buffer), 0); + if (gsmport->p_m_g_gsm_b_sock > -1) { + ret = recv(gsmport->p_m_g_gsm_b_sock, buffer, sizeof(buffer), 0); if (ret >= (int)MISDN_HEADER_LEN) { switch(hh->prim) { /* we don't care about confirms, we use rx data to sync tx */ @@ -1463,37 +1488,21 @@ int Pgsm::handler(void) break; /* we receive audio data, we respond to it AND we send tones */ case PH_DATA_IND: - bchannel_receive(hh, buffer+MISDN_HEADER_LEN, ret-MISDN_HEADER_LEN); + gsmport->bchannel_receive(hh, buffer+MISDN_HEADER_LEN, ret-MISDN_HEADER_LEN); break; case PH_ACTIVATE_IND: - p_m_g_gsm_b_active = 1; + gsmport->p_m_g_gsm_b_active = 1; break; case PH_DEACTIVATE_IND: - p_m_g_gsm_b_active = 0; + gsmport->p_m_g_gsm_b_active = 0; break; } - work = 1; } else { if (ret < 0 && errno != EWOULDBLOCK) PERROR("Read from GSM port, index %d failed with return code %d\n", ret); } } - return(work); -} - - -/* - * handles bsc select function within LCR's main loop - */ -int handle_gsm(void) -{ - int ret1, ret2; - - ret1 = bsc_upqueue((struct gsm_network *)gsm->network); - ret2 = bsc_select_main(1); /* polling */ - if (ret1 || ret2) - return 1; return 0; } @@ -1599,10 +1608,21 @@ int gsm_init(void) mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH; int pcapfd, rc; + debug_init(); tall_bsc_ctx = talloc_named_const(NULL, 1, "openbsc"); talloc_ctx_init(); on_dso_load_token(); on_dso_load_rrlp(); + on_dso_load_ho_dec(); + stderr_target = debug_target_create_stderr(); + debug_add_target(stderr_target); + + bts_model_unknown_init(); + bts_model_bs11_init(); + bts_model_nanobts_init(); + + /* enable filters */ + debug_set_all_filter(stderr_target, 1); /* seed the PRNG */ srand(time(NULL)); @@ -1618,7 +1638,6 @@ int gsm_init(void) } /* set debug */ - stderr_target = debug_target_create_stderr(); if (gsm->conf.debug[0]) debug_parse_category_mask(stderr_target, gsm->conf.debug); @@ -1655,6 +1674,11 @@ int gsm_init(void) } printf("DB: Database prepared.\n"); + /* setup the timer */ + db_sync_timer.cb = db_sync_timer_cb; + db_sync_timer.data = NULL; + bsc_schedule_timer(&db_sync_timer, DB_SYNC_INTERVAL); + /* bootstrap network */ if (gsm->conf.openbsc_cfg[0] == '/') SCPY(cfg, gsm->conf.openbsc_cfg); @@ -1675,3 +1699,18 @@ int gsm_init(void) return 0; } +/* + * handles bsc select function within LCR's main loop + */ +int handle_gsm(void) +{ + int ret1, ret2; + + ret1 = bsc_upqueue((struct gsm_network *)gsm->network); + debug_reset_context(); + ret2 = bsc_select_main(1); /* polling */ + if (ret1 || ret2) + return 1; + return 0; +} + -- cgit v1.2.3-55-g7522 From ce460a94e6371173c4ce063229276b6d32f47abd Mon Sep 17 00:00:00 2001 From: Andreas Eversberg Date: Sat, 30 Jan 2010 11:59:07 +0100 Subject: register_fd() bugfix. --- gsm.cpp | 2 +- mISDN.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'gsm.cpp') diff --git a/gsm.cpp b/gsm.cpp index 3358329..9ffcc4c 100644 --- a/gsm.cpp +++ b/gsm.cpp @@ -176,7 +176,7 @@ int Pgsm::bchannel_open(int index) bchannel_close(); return(ret); } - memset(&p_m_g_gsm_b_fd, 0, sizeof(p_m_g_gsm_b_fd.fd)); + memset(&p_m_g_gsm_b_fd, 0, sizeof(p_m_g_gsm_b_fd)); p_m_g_gsm_b_fd.fd = p_m_g_gsm_b_sock; register_fd(&p_m_g_gsm_b_fd, LCR_FD_READ, b_handler, this, 0); diff --git a/mISDN.cpp b/mISDN.cpp index 035b78b..7be3d4f 100644 --- a/mISDN.cpp +++ b/mISDN.cpp @@ -82,7 +82,7 @@ int mISDN_initialize(void) if (pipe(upqueue_pipe) < 0) FATAL("Failed to open pipe\n"); - memset(&upqueue_fd, 0, sizeof(upqueue_fd.fd)); + memset(&upqueue_fd, 0, sizeof(upqueue_fd)); upqueue_fd.fd = upqueue_pipe[0]; register_fd(&upqueue_fd, LCR_FD_READ, mISDN_upqueue, NULL, 0); -- cgit v1.2.3-55-g7522 From 0c65074b5b88b2da2390078d0fab6c72f228709d Mon Sep 17 00:00:00 2001 From: Andreas Eversberg Date: Thu, 11 Mar 2010 14:07:20 +0100 Subject: Fixed compiler warnings when compiling with gcc 4.3.4. Fixed names of moved include files (OpenBSC). modified: Makefile.am modified: Makefile.in modified: README modified: chan_lcr.c modified: configure modified: configure.ac modified: genrc.c modified: gentones.c modified: genwave.c modified: gsm.cpp modified: mISDN.cpp modified: main.c modified: port.cpp modified: tones.c modified: trace.c --- Makefile.am | 4 ++-- Makefile.in | 12 ++++++------ README | 3 +++ chan_lcr.c | 4 +++- configure | 4 ++-- configure.ac | 2 +- genrc.c | 15 ++++++++------- gentones.c | 21 +++++++++++---------- genwave.c | 7 ++++--- gsm.cpp | 4 ++-- mISDN.cpp | 6 ++++-- main.c | 3 ++- port.cpp | 25 ++++++++++++++----------- tones.c | 13 +++++++------ trace.c | 3 ++- 15 files changed, 71 insertions(+), 55 deletions(-) (limited to 'gsm.cpp') diff --git a/Makefile.am b/Makefile.am index 17f9a29..2125468 100644 --- a/Makefile.am +++ b/Makefile.am @@ -45,11 +45,11 @@ INSTALLATION_DEFINES = \ if ENABLE_GSM -GSM_INCLUDE = -DWITH_GSM -I./openbsc/include +GSM_INCLUDE = -DWITH_GSM -I./openbsc/include -I./libosmocore/include GSM_SOURCE = gsm_audio.c gsm.cpp gsm_conf.c openbsc/src/bsc_init.c openbsc/src/vty_interface.c openbsc/src/vty_interface_layer3.c -GSM_LIB = /usr/lib/libgsm.a ./openbsc/src/libbsc.a ./openbsc/src/libmsc.a ./openbsc/src/libvty.a -ldbi -lcrypt +GSM_LIB = /usr/lib/libgsm.a ./openbsc/src/libbsc.a ./openbsc/src/libmsc.a ./openbsc/src/libvty.a -L./libosmocore/src/ -losmocore -ldbi -lcrypt #gsm_audio.po: gsm_audio.c gsm_audio.h # $(CC) -D_GNU_SOURCE -fPIC -c gsm_audio.c -o gsm_audio.po diff --git a/Makefile.in b/Makefile.in index 1a2bd77..e45b8a0 100644 --- a/Makefile.in +++ b/Makefile.in @@ -249,9 +249,9 @@ INSTALLATION_DEFINES = \ -DLOG_DIR="\"$(LOGdir)\"" \ -DEXTENSION_DATA="\"$(EXTENSIONdir)\"" -@ENABLE_GSM_TRUE@GSM_INCLUDE = -DWITH_GSM -I./openbsc/include +@ENABLE_GSM_TRUE@GSM_INCLUDE = -DWITH_GSM -I./openbsc/include -I./libosmocore/include @ENABLE_GSM_TRUE@GSM_SOURCE = gsm_audio.c gsm.cpp gsm_conf.c openbsc/src/bsc_init.c openbsc/src/vty_interface.c openbsc/src/vty_interface_layer3.c -@ENABLE_GSM_TRUE@GSM_LIB = /usr/lib/libgsm.a ./openbsc/src/libbsc.a ./openbsc/src/libmsc.a ./openbsc/src/libvty.a -ldbi -lcrypt +@ENABLE_GSM_TRUE@GSM_LIB = /usr/lib/libgsm.a ./openbsc/src/libbsc.a ./openbsc/src/libmsc.a ./openbsc/src/libvty.a -L./libosmocore/src/ -losmocore -ldbi -lcrypt #gsm_audio.po: gsm_audio.c gsm_audio.h # $(CC) -D_GNU_SOURCE -fPIC -c gsm_audio.c -o gsm_audio.po @@ -294,15 +294,15 @@ $(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) @for dep in $?; do \ case '$(am__configure_deps)' in \ *$$dep*) \ - echo ' cd $(srcdir) && $(AUTOMAKE) --foreign '; \ - cd $(srcdir) && $(AUTOMAKE) --foreign \ + echo ' cd $(srcdir) && $(AUTOMAKE) --gnu '; \ + cd $(srcdir) && $(AUTOMAKE) --gnu \ && exit 0; \ exit 1;; \ esac; \ done; \ - echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign Makefile'; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu Makefile'; \ cd $(top_srcdir) && \ - $(AUTOMAKE) --foreign Makefile + $(AUTOMAKE) --gnu Makefile .PRECIOUS: Makefile Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status @case '$?' in \ diff --git a/README b/README index 9b8aae1..e6bd449 100644 --- a/README +++ b/README @@ -539,6 +539,9 @@ Changes after Version 1.7 -> Use options "t:q250" for disabling mISDN_dsp and adding a 250ms delay. - Fixed HLC (higher layer capability) modification to LCR routing. - Fixed chan_lcr fax queue buffer. Added LCR_TRANSFERCAPABILITY environment. +- Fixed compiler warnings when compiling with gcc 4.3.4. + + diff --git a/chan_lcr.c b/chan_lcr.c index 040f921..6a953a2 100644 --- a/chan_lcr.c +++ b/chan_lcr.c @@ -2356,9 +2356,11 @@ static int lcr_indicate(struct ast_channel *ast, int cond, const void *data, siz break; #ifdef AST_CONTROL_SRCUPDATE case AST_CONTROL_SRCUPDATE: +#else + case 20: +#endif CDEBUG(call, ast, "Received AST_CONTROL_SRCUPDATE from Asterisk.\n"); break; -#endif default: CERROR(call, ast, "Received indicate from Asterisk with unknown condition %d.\n", cond); res = -1; diff --git a/configure b/configure index 9340f73..62e9cd7 100755 --- a/configure +++ b/configure @@ -6297,9 +6297,9 @@ else if test "x$with_gsm" != xcheck ; then { { $as_echo "$as_me:$LINENO: error: in \`$ac_pwd':" >&5 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} -{ { $as_echo "$as_me:$LINENO: error: --with-gsm was given, but openbsc/include/openbsc/gsm_data.h was not found! Pleas link OpenBSC source directory to LCR source directory: ln -s path_to_openbsc/openbsc/ . +{ { $as_echo "$as_me:$LINENO: error: --with-gsm was given, but openbsc/include/openbsc/gsm_data.h was not found! Pleas link OpenBSC and libosmocore source directory to LCR source directory: ln -s path_to_openbsc/openbsc/ openbsc ; ln -s patch_to_libosmocore osmocore See \`config.log' for more details." >&5 -$as_echo "$as_me: error: --with-gsm was given, but openbsc/include/openbsc/gsm_data.h was not found! Pleas link OpenBSC source directory to LCR source directory: ln -s path_to_openbsc/openbsc/ . +$as_echo "$as_me: error: --with-gsm was given, but openbsc/include/openbsc/gsm_data.h was not found! Pleas link OpenBSC and libosmocore source directory to LCR source directory: ln -s path_to_openbsc/openbsc/ openbsc ; ln -s patch_to_libosmocore osmocore See \`config.log' for more details." >&2;} { (exit 1); exit 1; }; }; } fi diff --git a/configure.ac b/configure.ac index d138e16..cc7cc9b 100644 --- a/configure.ac +++ b/configure.ac @@ -108,7 +108,7 @@ AS_IF([test "x$with_gsm" != xno], [with_gsm="yes"], [if test "x$with_gsm" != xcheck ; then AC_MSG_FAILURE( - [--with-gsm was given, but openbsc/include/openbsc/gsm_data.h was not found! Pleas link OpenBSC source directory to LCR source directory: ln -s path_to_openbsc/openbsc/ .]) + [--with-gsm was given, but openbsc/include/openbsc/gsm_data.h was not found! Pleas link OpenBSC and libosmocore source directory to LCR source directory: ln -s path_to_openbsc/openbsc/ openbsc ; ln -s patch_to_libosmocore osmocore]) fi ]) ]) diff --git a/genrc.c b/genrc.c index 3e349f4..1d5a076 100644 --- a/genrc.c +++ b/genrc.c @@ -39,6 +39,7 @@ int main(void) FILE *fp; int i = 0, j, jj, n; char input[256], file[256]; + int ret; printf("\n\nThis program generates a script, which is used to start/stop/restart mISDN\n"); printf("driver. Please select card only once. Mode and options are given by LCR.\n"); @@ -52,7 +53,7 @@ int main(void) } do { printf("\nSelect driver number[1-n] (or enter 'done'): "); fflush(stdout); - scanf("%s", input); + ret = scanf("%s", input); } while (atoi(input) <= 0 && !!strcmp(input, "done")); type[i] = atoi(input); i++; @@ -66,22 +67,22 @@ int main(void) } printf("\nEnter LAW audio mode. For a-LAW (default), just enter 0. For u-LAW enter 1.\n[0..n | 0xn]: "); fflush(stdout); - scanf("%s", input); + ret = scanf("%s", input); lawopt = strtoul(input, NULL, 0); printf("\nEnter debugging flags of mISDN core. For no debug, just enter 0.\n[0..n | 0xn]: "); fflush(stdout); - scanf("%s", input); + ret = scanf("%s", input); coredebug = strtoul(input, NULL, 0); printf("\nEnter debugging flags of cards. For no debug, just enter 0.\n[0..n | 0xn]: "); fflush(stdout); - scanf("%s", input); + ret = scanf("%s", input); carddebug = strtoul(input, NULL, 0); printf("\nEnter dsp debugging flags of driver. For no debug, just enter 0.\n[0..n | 0xn]: "); fflush(stdout); - scanf("%s", input); + ret = scanf("%s", input); dspdebug = strtoul(input, NULL, 0); n = i; printf("\nWhere do you like to load the modules from, enter 0 for default, 1 for\n'/usr/local/lcr/modules/' or the full path.\n[0 | 1 | ]: "); fflush(stdout); - scanf("%s", input); + ret = scanf("%s", input); if (!strcmp(input, "0")) SCPY(input, ""); if (!strcmp(input, "1")) @@ -90,7 +91,7 @@ int main(void) SCAT(input, "/"); printf("\n\nFinally tell me where to write the mISDN rc file.\nEnter the name 'mISDN' for current directory.\nYou may want to say '/usr/local/lcr/mISDN' or '/etc/rc.d/mISDN'\n: "); fflush(stdout); - scanf("%s", file); + ret = scanf("%s", file); if (!(fp=fopen(file, "w"))) { fprintf(stderr, "\nError: Failed to open '%s', try again.\n", file); exit(EXIT_FAILURE); diff --git a/gentones.c b/gentones.c index 6cdaf37..aaac659 100644 --- a/gentones.c +++ b/gentones.c @@ -150,9 +150,10 @@ void write_wav(FILE *fp, char *wav, char law) short sample, sample2; signed int size, chunk; int gotfmt = 0, gotdata = 0; + int ret; if ((wfp=fopen(wav,"r"))) { - fread(buffer,8,1,wfp); + ret=fread(buffer,8,1,wfp); size=(buffer[4]) + (buffer[5]<<8) + (buffer[6]<<16) + (buffer[7]<<24); if (!!strncmp((char *)buffer, "RIFF", 4)) { fclose(wfp); @@ -160,7 +161,7 @@ void write_wav(FILE *fp, char *wav, char law) return; } printf("%c%c%c%c size=%d\n",buffer[0],buffer[1],buffer[2],buffer[3],size); - fread(buffer,4,1,wfp); + ret=fread(buffer,4,1,wfp); size -= 4; if (!!strncmp((char *)buffer, "WAVE", 4)) { fclose(wfp); @@ -173,7 +174,7 @@ void write_wav(FILE *fp, char *wav, char law) fprintf(stderr, "Error: Remaining file size %d not large enough for next chunk.\n",size); return; } - fread(buffer,8,1,wfp); + ret=fread(buffer,8,1,wfp); chunk=(buffer[4]) + (buffer[5]<<8) + (buffer[6]<<16) + (buffer[7]<<24); //printf("DEBUG: size(%d) - (8+chunk(%d) = size(%d)\n", size, chunk, size-chunk-8); size -= (8+chunk); @@ -189,7 +190,7 @@ void write_wav(FILE *fp, char *wav, char law) fprintf(stderr, "Error: Fmt chunk illegal size.\n"); return; } - fread(buffer, chunk, 1, wfp); + ret=fread(buffer, chunk, 1, wfp); fmt = (struct fmt *)buffer; if (fmt->channels<1 || fmt->channels>2) { fclose(wfp); @@ -221,7 +222,7 @@ void write_wav(FILE *fp, char *wav, char law) i=0; if (bytes==2 && channels==1) { while(i (signed int)sizeof(buffer)) { - fread(buffer, sizeof(buffer), 1, wfp); + ret=fread(buffer, sizeof(buffer), 1, wfp); chunk -= sizeof(buffer); } if (chunk) - fread(buffer, chunk, 1, wfp); + ret=fread(buffer, chunk, 1, wfp); } } diff --git a/genwave.c b/genwave.c index 8f32076..685b5fa 100644 --- a/genwave.c +++ b/genwave.c @@ -100,6 +100,7 @@ void write_law(FILE *fp, char *name, char law) unsigned int i; short sample; unsigned int size, wsize; + int ret; if ((lfp=fopen(name,"r"))) { /* get size */ @@ -125,18 +126,18 @@ void write_law(FILE *fp, char *name, char law) fmt.data_rate = 16000; fmt.bytes_sample = 2; fmt.bits_sample = 16; - fwrite(&fmt, sizeof(fmt), 1, fp); + ret = fwrite(&fmt, sizeof(fmt), 1, fp); /* data */ fprintf(fp, "data%c%c%c%c", (char)(size&0xff), (char)((size>>8)&0xff), (char)((size>>16)&0xff), (char)(size>>24)); i = 0; while(i < size) { - fread(buffer, 1, 1, lfp); + ret = fread(buffer, 1, 1, lfp); if (law == 'a') sample = isdn_audio_alaw_to_s16[*buffer]; else sample = isdn_audio_ulaw_to_s16[*buffer]; - fwrite(&sample, 2, 1, fp); + ret = fwrite(&sample, 2, 1, fp); i+=2; } diff --git a/gsm.cpp b/gsm.cpp index 9ffcc4c..b2bdd6b 100644 --- a/gsm.cpp +++ b/gsm.cpp @@ -18,10 +18,10 @@ extern "C" { #include #include -#include +#include #include #include -#include +#include #include #include struct gsm_network *bsc_gsmnet = 0; diff --git a/mISDN.cpp b/mISDN.cpp index 7be3d4f..f5f8717 100644 --- a/mISDN.cpp +++ b/mISDN.cpp @@ -1832,13 +1832,14 @@ static int mISDN_upqueue(struct lcr_fd *fd, unsigned int what, void *instance, i struct mbuffer *mb; struct l3_msg *l3m; char byte; + int ret; /* unset global semaphore */ upqueue_avail = 0; // with a very small incident, upqueue_avail may be set by mISDN thread and // another byte may be sent to the pipe, which causes a call to this function // again with nothing in the upqueue. this is no problem. - read(fd->fd, &byte, 1); + ret = read(fd->fd, &byte, 1); /* process all ports */ mISDNport = mISDNport_first; @@ -2068,7 +2069,8 @@ int do_layer3(struct mlayer3 *ml3, unsigned int cmd, unsigned int pid, struct l3 // this is no problem. upqueue_avail = 1; char byte = 0; - write(upqueue_pipe[1], &byte, 1); + int ret; + ret = write(upqueue_pipe[1], &byte, 1); } return 0; } diff --git a/main.c b/main.c index b70ed05..b425abe 100644 --- a/main.c +++ b/main.c @@ -242,8 +242,9 @@ int main(int argc, char *argv[]) /* query available isdn ports */ if (!(strcasecmp(argv[1],"query"))) { + int rc; fprintf(stderr, "-> Using 'misdn_info'\n"); - system("misdn_info"); + rc = system("misdn_info"); ret = 0; goto free; } diff --git a/port.cpp b/port.cpp index e88175b..a083fa2 100644 --- a/port.cpp +++ b/port.cpp @@ -647,6 +647,7 @@ int Port::open_record(int type, int vbox, int skip, char *extension, int anon_ig char filename[256]; time_t now; struct tm *now_tm; + int ret; if (!extension) { PERROR("Port(%d) not an extension\n", p_serial); @@ -711,7 +712,7 @@ int Port::open_record(int type, int vbox, int skip, char *extension, int anon_ig case CODEC_MONO: case CODEC_STEREO: case CODEC_8BIT: - fwrite(dummyheader, sizeof(dummyheader), 1, p_record); + ret = fwrite(dummyheader, sizeof(dummyheader), 1, p_record); break; case CODEC_LAW: @@ -739,6 +740,7 @@ void Port::close_record(int beep, int mute) char *p; struct caller_info callerinfo; const char *valid_chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890_.-!$%&/()=+*;~"; + int ret; if (!p_record) return; @@ -801,7 +803,7 @@ void Port::close_record(int beep, int mute) } i = 0; while(i < beep) { - fwrite(beep_mono, sizeof(beep_mono), 1, p_record); + ret = fwrite(beep_mono, sizeof(beep_mono), 1, p_record); i += sizeof(beep_mono); p_record_length += sizeof(beep_mono); } @@ -861,7 +863,7 @@ void Port::close_record(int beep, int mute) fmt.bits_sample = 8; /* one channel */ break; } - fwrite(&fmt, sizeof(fmt), 1, p_record); + ret = fwrite(&fmt, sizeof(fmt), 1, p_record); /* data */ fprintf(p_record, "data%c%c%c%c", (unsigned char)(size&0xff), (unsigned char)((size>>8)&0xff), (unsigned char)((size>>16)&0xff), (unsigned char)(size>>24)); @@ -939,6 +941,7 @@ void Port::record(unsigned char *data, int length, int dir_fromup) signed short *s; int free, i, ii; signed int sample; + int ret; /* no recording */ if (!p_record || !length) @@ -988,7 +991,7 @@ same_again: p_record_buffer_readp = (p_record_buffer_readp + 1) & RECORD_BUFFER_MASK; i++; } - fwrite(write_buffer, 512, 1, p_record); + ret = fwrite(write_buffer, 512, 1, p_record); p_record_length += 512; break; @@ -1011,7 +1014,7 @@ same_again: i++; } } - fwrite(write_buffer, 1024, 1, p_record); + ret = fwrite(write_buffer, 1024, 1, p_record); p_record_length += 1024; break; @@ -1023,7 +1026,7 @@ same_again: p_record_buffer_readp = (p_record_buffer_readp + 1) & RECORD_BUFFER_MASK; i++; } - fwrite(write_buffer, 512, 1, p_record); + ret = fwrite(write_buffer, 512, 1, p_record); p_record_length += 512; break; @@ -1035,7 +1038,7 @@ same_again: p_record_buffer_readp = (p_record_buffer_readp + 1) & RECORD_BUFFER_MASK; i++; } - fwrite(write_buffer, 256, 1, p_record); + ret = fwrite(write_buffer, 256, 1, p_record); p_record_length += 256; break; } @@ -1075,7 +1078,7 @@ different_again: *s++ = sample; i++; } - fwrite(write_buffer, ii<<1, 1, p_record); + ret = fwrite(write_buffer, ii<<1, 1, p_record); p_record_length += (ii<<1); break; @@ -1098,7 +1101,7 @@ different_again: i++; } } - fwrite(write_buffer, ii<<2, 1, p_record); + ret = fwrite(write_buffer, ii<<2, 1, p_record); p_record_length += (ii<<2); break; @@ -1114,7 +1117,7 @@ different_again: *d++ = (sample+0x8000) >> 8; i++; } - fwrite(write_buffer, ii, 1, p_record); + ret = fwrite(write_buffer, ii, 1, p_record); p_record_length += ii; break; @@ -1130,7 +1133,7 @@ different_again: *d++ = audio_s16_to_law[sample & 0xffff]; i++; } - fwrite(write_buffer, ii, 1, p_record); + ret = fwrite(write_buffer, ii, 1, p_record); p_record_length += ii; break; } diff --git a/tones.c b/tones.c index 93d04e9..ad69011 100644 --- a/tones.c +++ b/tones.c @@ -48,6 +48,7 @@ int open_tone(char *file, int *codec, signed int *length, signed int *left) int linksize; int l; char *p; + int ret; /* try to open the law file */ @@ -104,7 +105,7 @@ int open_tone(char *file, int *codec, signed int *length, signed int *left) SPRINT(filename, "%s.wav", file); if ((fh = open(filename, O_RDONLY)) >= 0) { /* get wave header */ - read(fh, buffer, 8); + ret = read(fh, buffer, 8); size=(buffer[4]) + (buffer[5]<<8) + (buffer[6]<<16) + (buffer[7]<<24); if (!!strncmp((char *)buffer, "RIFF", 4)) { close(fh); @@ -113,7 +114,7 @@ int open_tone(char *file, int *codec, signed int *length, signed int *left) return(-1); } // printf("%c%c%c%c size=%ld\n",buffer[0],buffer[1],buffer[2],buffer[3],size); - read(fh, buffer, 4); + ret = read(fh, buffer, 4); size -= 4; if (!!strncmp((char *)buffer, "WAVE", 4)) { close(fh); @@ -128,7 +129,7 @@ int open_tone(char *file, int *codec, signed int *length, signed int *left) PERROR("Remaining file size %ld not large enough for next chunk.\n",size); return(-1); } - read(fh, buffer, 8); + ret = read(fh, buffer, 8); chunk=(buffer[4]) + (buffer[5]<<8) + (buffer[6]<<16) + (buffer[7]<<24); size -= (8+chunk); // printf("%c%c%c%c length=%d\n",buffer[0],buffer[1],buffer[2],buffer[3],chunk); @@ -145,7 +146,7 @@ int open_tone(char *file, int *codec, signed int *length, signed int *left) PERROR("File %s Fmt chunk illegal size.\n", filename); return(-1); } - read(fh, buffer, chunk); + ret = read(fh, buffer, chunk); fmt = (struct fmt *)buffer; if (fmt->channels<1 || fmt->channels>2) { close(fh); @@ -211,11 +212,11 @@ int open_tone(char *file, int *codec, signed int *length, signed int *left) } else { // PDEBUG(DEBUG_PORT, "Unknown chunk '%c%c%c%c'\n",buffer[0],buffer[1],buffer[2],buffer[3]); while(chunk > sizeof(buffer)) { - read(fh, buffer, sizeof(buffer)); + ret = read(fh, buffer, sizeof(buffer)); chunk -= sizeof(buffer); } if (chunk) - read(fh, buffer, chunk); + ret = read(fh, buffer, chunk); } } diff --git a/trace.c b/trace.c index b8dc001..9d192da 100644 --- a/trace.c +++ b/trace.c @@ -264,6 +264,7 @@ void _end_trace(const char *__file, int __line) FILE *fp; struct admin_list *admin; struct admin_queue *response, **responsep; /* response pointer */ + int ret; if (!trace.name[0]) PERROR("trace not started in file %s line %d\n", __file, __line); @@ -278,7 +279,7 @@ void _end_trace(const char *__file, int __line) if (options.log[0]) { fp = fopen(options.log, "a"); if (fp) { - fwrite(string, strlen(string), 1, fp); + ret = fwrite(string, strlen(string), 1, fp); fclose(fp); } } -- cgit v1.2.3-55-g7522 From 2732c3ce40d8e0b3875b5a0c933c98f27c8cbae9 Mon Sep 17 00:00:00 2001 From: Andreas Eversberg Date: Wed, 17 Mar 2010 08:31:07 +0100 Subject: Fixed output problems of error messages while parsing options.conf / gsm.conf. modified: Makefile.in modified: bchannel.c modified: chan_lcr.c modified: genext.c modified: gsm.cpp modified: gsm.h modified: gsm_conf.c modified: lcradmin.c modified: main.c modified: options.c modified: options.h --- Makefile.in | 8 ++++---- bchannel.c | 2 +- chan_lcr.c | 3 ++- genext.c | 3 ++- gsm.cpp | 11 +++++------ gsm.h | 3 +-- gsm_conf.c | 26 ++++++++++++-------------- lcradmin.c | 4 ++-- main.c | 3 ++- options.c | 36 ++++++++++++++++++------------------ options.h | 4 +--- 11 files changed, 50 insertions(+), 53 deletions(-) (limited to 'gsm.cpp') diff --git a/Makefile.in b/Makefile.in index 6bd502b..099f47c 100644 --- a/Makefile.in +++ b/Makefile.in @@ -294,15 +294,15 @@ $(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) @for dep in $?; do \ case '$(am__configure_deps)' in \ *$$dep*) \ - echo ' cd $(srcdir) && $(AUTOMAKE) --gnu '; \ - cd $(srcdir) && $(AUTOMAKE) --gnu \ + echo ' cd $(srcdir) && $(AUTOMAKE) --foreign '; \ + cd $(srcdir) && $(AUTOMAKE) --foreign \ && exit 0; \ exit 1;; \ esac; \ done; \ - echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu Makefile'; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign Makefile'; \ cd $(top_srcdir) && \ - $(AUTOMAKE) --gnu Makefile + $(AUTOMAKE) --foreign Makefile .PRECIOUS: Makefile Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status @case '$?' in \ diff --git a/bchannel.c b/bchannel.c index f49572b..baa8434 100644 --- a/bchannel.c +++ b/bchannel.c @@ -23,7 +23,7 @@ #include #include #include -#include +#include #include int __af_isdn = MISDN_AF_ISDN; diff --git a/chan_lcr.c b/chan_lcr.c index 6a953a2..72bca9f 100644 --- a/chan_lcr.c +++ b/chan_lcr.c @@ -2748,13 +2748,14 @@ static int lcr_config_exec(struct ast_channel *ast, void *data, char **argv) int load_module(void) { u_short i; + char options_error[256]; for (i = 0; i < 256; i++) { flip_bits[i] = (i>>7) | ((i>>5)&2) | ((i>>3)&4) | ((i>>1)&8) | (i<<7) | ((i&2)<<5) | ((i&4)<<3) | ((i&8)<<1); } - if (read_options() == 0) { + if (read_options(options_error) == 0) { CERROR(NULL, NULL, "%s", options_error); #ifdef LCR_FOR_ASTERISK diff --git a/genext.c b/genext.c index 486af09..4d34bbe 100644 --- a/genext.c +++ b/genext.c @@ -52,8 +52,9 @@ int main(int argc, char *argv[]) struct extension ext; char pathname[256]; FILE *fp; + char options_error[256]; - if (!read_options()) { + if (!read_options(options_error)) { PERROR("%s", options_error); return(-1); } diff --git a/gsm.cpp b/gsm.cpp index b2bdd6b..b378df6 100644 --- a/gsm.cpp +++ b/gsm.cpp @@ -44,12 +44,9 @@ static struct timer_list db_sync_timer; #include "gsm_audio.h" -#undef AF_ISDN -#undef PF_ISDN -extern int AF_ISDN; -#define PF_ISDN AF_ISDN } +#include struct lcr_gsm *gsm = NULL; @@ -1607,6 +1604,8 @@ int gsm_init(void) char hlr[128], cfg[128], filename[128]; mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH; int pcapfd, rc; + char conf_error[128] = ""; + debug_init(); tall_bsc_ctx = talloc_named_const(NULL, 1, "openbsc"); @@ -1632,8 +1631,8 @@ int gsm_init(void) gsm->gsm_sock = -1; /* parse options */ - if (!gsm_conf(&gsm->conf)) { - PERROR("%s", gsm_conf_error); + if (!gsm_conf(&gsm->conf, conf_error)) { + PERROR("%s", conf_error); return gsm_exit(-EINVAL); } diff --git a/gsm.h b/gsm.h index 6c09fa8..4959e00 100644 --- a/gsm.h +++ b/gsm.h @@ -76,8 +76,7 @@ class Pgsm : public PmISDN int message_epoint(unsigned int epoint_id, int message_id, union parameter *param); }; -extern char *gsm_conf_error; -int gsm_conf(struct gsm_conf *gsm_conf); +int gsm_conf(struct gsm_conf *gsm_conf, char *conf_error); int handle_gsm(void); int gsm_exit(int rc); int gsm_init(void); diff --git a/gsm_conf.c b/gsm_conf.c index 560d9b3..f5af15a 100644 --- a/gsm_conf.c +++ b/gsm_conf.c @@ -12,13 +12,11 @@ #include "main.h" -char *gsm_conf_error = (char *)""; - /* read options * * read options from options.conf */ -int gsm_conf(struct gsm_conf *gsm_conf) +int gsm_conf(struct gsm_conf *gsm_conf, char *conf_error) { FILE *fp=NULL; char filename[128]; @@ -42,7 +40,7 @@ int gsm_conf(struct gsm_conf *gsm_conf) SPRINT(filename, "%s/gsm.conf", CONFIG_DATA); if (!(fp=fopen(filename,"r"))) { - SPRINT(gsm_conf_error, "Cannot open %s\n",filename); + UPRINT(conf_error, "Cannot open %s\n",filename); return(0); } @@ -63,7 +61,7 @@ int gsm_conf(struct gsm_conf *gsm_conf) i=0; /* read option */ while(*p > 32) { if (i+1 >= sizeof(option)) { - SPRINT(gsm_conf_error, "Error in %s (line %d): option too long.\n",filename,line); + UPRINT(conf_error, "Error in %s (line %d): option too long.\n",filename,line); goto error; } option[i+1] = '\0'; @@ -82,7 +80,7 @@ int gsm_conf(struct gsm_conf *gsm_conf) i=0; /* read param */ while(*p > 32) { if (i+1 >= sizeof(params[pnum])) { - SPRINT(gsm_conf_error, "Error in %s (line %d): param too long.\n",filename,line); + UPRINT(conf_error, "Error in %s (line %d): param too long.\n",filename,line); goto error; } params[pnum][i+1] = '\0'; @@ -102,7 +100,7 @@ int gsm_conf(struct gsm_conf *gsm_conf) /* check option */ if (!strcmp(option,"debug")) { if (params[0][0]==0) { - SPRINT(gsm_conf_error, "Error in %s (line %d): parameter for option %s missing.\n",filename,line,option); + UPRINT(conf_error, "Error in %s (line %d): parameter for option %s missing.\n",filename,line,option); goto error; } SCPY(gsm_conf->debug, params[0]); @@ -110,7 +108,7 @@ int gsm_conf(struct gsm_conf *gsm_conf) } else if (!strcmp(option,"interface-bsc")) { if (params[0][0]==0) { - SPRINT(gsm_conf_error, "Error in %s (line %d): parameter for option %s missing.\n",filename,line, option); + UPRINT(conf_error, "Error in %s (line %d): parameter for option %s missing.\n",filename,line, option); goto error; } SCPY(gsm_conf->interface_bsc, params[0]); @@ -118,7 +116,7 @@ int gsm_conf(struct gsm_conf *gsm_conf) } else if (!strcmp(option,"interface-lcr")) { if (params[0][0]==0) { - SPRINT(gsm_conf_error, "Error in %s (line %d): parameter for option %s missing.\n",filename,line, option); + UPRINT(conf_error, "Error in %s (line %d): parameter for option %s missing.\n",filename,line, option); goto error; } SCPY(gsm_conf->interface_lcr, params[0]); @@ -126,7 +124,7 @@ int gsm_conf(struct gsm_conf *gsm_conf) } else if (!strcmp(option,"config")) { if (params[0][0]==0) { - SPRINT(gsm_conf_error, "Error in %s (line %d): parameter for option %s missing.\n",filename,line, option); + UPRINT(conf_error, "Error in %s (line %d): parameter for option %s missing.\n",filename,line, option); goto error; } SCPY(gsm_conf->openbsc_cfg, params[0]); @@ -134,14 +132,14 @@ int gsm_conf(struct gsm_conf *gsm_conf) } else if (!strcmp(option,"hlr")) { if (params[0][0]==0) { - SPRINT(gsm_conf_error, "Error in %s (line %d): parameter for option %s missing.\n",filename,line, option); + UPRINT(conf_error, "Error in %s (line %d): parameter for option %s missing.\n",filename,line, option); goto error; } SCPY(gsm_conf->hlr, params[0]); } else if (!strcmp(option,"reject-cause")) { - SPRINT(gsm_conf_error, "Option '%s' in gsm.conf has moved to openbsc.cfg", option); + UPRINT(conf_error, "Option '%s' in gsm.conf has moved to openbsc.cfg", option); goto error; } else if (!strcmp(option,"allow-all")) { @@ -156,12 +154,12 @@ int gsm_conf(struct gsm_conf *gsm_conf) } else if (!strcmp(option,"pcapfile")) { if (params[0][0]==0) { - SPRINT(gsm_conf_error, "Error in %s (line %d): parameter for option %s missing.\n",filename,line, option); + UPRINT(conf_error, "Error in %s (line %d): parameter for option %s missing.\n",filename,line, option); goto error; } SCPY(gsm_conf->pcapfile, params[0]); } else { - SPRINT(gsm_conf_error, "Error in %s (line %d): wrong option keyword %s.\n", filename,line,option); + UPRINT(conf_error, "Error in %s (line %d): wrong option keyword %s.\n", filename,line,option); goto error; } } diff --git a/lcradmin.c b/lcradmin.c index 0b6d627..c7691ee 100644 --- a/lcradmin.c +++ b/lcradmin.c @@ -1680,7 +1680,7 @@ int main(int argc, char *argv[]) int sock, conn; struct sockaddr_un sock_address; const char *ret = "invalid mode"; - + char options_error[256]; /* show options */ if (argc <= 1) { @@ -1756,7 +1756,7 @@ int main(int argc, char *argv[]) goto usage; } - if (read_options() == 0) { + if (read_options(options_error) == 0) { exit(EXIT_FAILURE); } diff --git a/main.c b/main.c index b425abe..9d7f834 100644 --- a/main.c +++ b/main.c @@ -174,6 +174,7 @@ int main(int argc, char *argv[]) created_lock = 0, created_signal = 0, created_debug = 0, created_misdn = 0; char tracetext[256], lock[128]; + char options_error[256]; #if 0 /* init fdset */ @@ -250,7 +251,7 @@ int main(int argc, char *argv[]) } /* read options */ - if (read_options() == 0) { + if (read_options(options_error) == 0) { PERROR("%s", options_error); goto free; } diff --git a/options.c b/options.c index eff38ce..1cadbe5 100644 --- a/options.c +++ b/options.c @@ -44,7 +44,7 @@ char options_error[256]; * * read options from options.conf */ -int read_options(void) +int read_options(char *options_error) { FILE *fp=NULL; char filename[128]; @@ -57,7 +57,7 @@ int read_options(void) SPRINT(filename, "%s/options.conf", CONFIG_DATA); if (!(fp=fopen(filename,"r"))) { - SPRINT(options_error, "Cannot open %s\n",filename); + UPRINT(options_error, "Cannot open %s\n",filename); return(0); } @@ -80,7 +80,7 @@ int read_options(void) i=0; /* read option */ while(*p > 32) { if (i+1 >= sizeof(option)) { - SPRINT(options_error, "Error in %s (line %d): option too long.\n",filename,line); + UPRINT(options_error, "Error in %s (line %d): option too long.\n",filename,line); goto error; } option[i+1] = '\0'; @@ -98,7 +98,7 @@ int read_options(void) i=0; /* read param */ while(*p > 31) { if (i+1 >= sizeof(param)) { - SPRINT(options_error, "Error in %s (line %d): param too long.\n",filename,line); + UPRINT(options_error, "Error in %s (line %d): param too long.\n",filename,line); goto error; } param[i+1] = '\0'; @@ -110,12 +110,12 @@ int read_options(void) /* check option */ if (!strcmp(option,"nt_if") || !strcmp(option,"te_if")) { - SPRINT(options_error, "Error in %s (line %d): obsolete option %s. Use multiple 'port' options to define ports to use.\n",filename,line,option); + UPRINT(options_error, "Error in %s (line %d): obsolete option %s. Use multiple 'port' options to define ports to use.\n",filename,line,option); goto error; } else if (!strcmp(option,"debug")) { if (param[0]==0) { - SPRINT(options_error, "Error in %s (line %d): parameter for option %s missing.\n",filename,line,option); + UPRINT(options_error, "Error in %s (line %d): parameter for option %s missing.\n",filename,line,option); goto error; } options.deb = strtol(param, NULL, 0); @@ -123,7 +123,7 @@ int read_options(void) } else if (!strcmp(option,"log")) { if (param[0]==0) { - SPRINT(options_error, "Error in %s (line %d): parameter for option %s missing.\n",filename,line, option); + UPRINT(options_error, "Error in %s (line %d): parameter for option %s missing.\n",filename,line, option); goto error; } SCPY(options.log, param); @@ -139,7 +139,7 @@ int read_options(void) } else if (!strcmp(option,"tones_dir")) { if (param[0]==0) { - SPRINT(options_error, "Error in %s (line %d): parameter for option %s missing.\n",filename,line,option); + UPRINT(options_error, "Error in %s (line %d): parameter for option %s missing.\n",filename,line,option); goto error; } if (param[strlen(param)-1] == '/') @@ -149,7 +149,7 @@ int read_options(void) } else if (!strcmp(option,"fetch_tones")) { if (param[0]==0) { - SPRINT(options_error, "Error in %s (line %d): parameter for option %s missing.\n",filename,line,option); + UPRINT(options_error, "Error in %s (line %d): parameter for option %s missing.\n",filename,line,option); goto error; } if (param[strlen(param)-1] == '/') @@ -173,24 +173,24 @@ int read_options(void) } else if (!strcmp(option,"dsptones")) { - SPRINT(options_error, "Error in %s (line %d): parameter 'dsptones' is obsolete. Just define the tones (american,german,oldgerman) at 'tones_dir' option.\n",filename,line,option); + UPRINT(options_error, "Error in %s (line %d): parameter 'dsptones' is obsolete. Just define the tones (american,german,oldgerman) at 'tones_dir' option.\n",filename,line); goto error; } else if (!strcmp(option,"schedule")) { options.schedule = atoi(param); if (options.schedule < 0) { - SPRINT(options_error, "Error in %s (line %d): parameter for option %s must be at least '0'.\n", filename,line,option); + UPRINT(options_error, "Error in %s (line %d): parameter for option %s must be at least '0'.\n", filename,line,option); goto error; } if (options.schedule > 99) { - SPRINT(options_error, "Error in %s (line %d): parameter for option %s must be '99' or less.\n", filename,line,option); + UPRINT(options_error, "Error in %s (line %d): parameter for option %s must be '99' or less.\n", filename,line,option); goto error; } } else if (!strcmp(option,"email")) { if (param[0]==0) { - SPRINT(options_error, "Error in %s (line %d): parameter for option %s missing.\n", filename,line,option); + UPRINT(options_error, "Error in %s (line %d): parameter for option %s missing.\n", filename,line,option); goto error; } SCPY(options.email, param); @@ -198,7 +198,7 @@ int read_options(void) } else if (!strcmp(option,"lock")) { if (param[0]==0) { - SPRINT(options_error, "Error in %s (line %d): parameter for option %s missing.\n",filename,line,option); + UPRINT(options_error, "Error in %s (line %d): parameter for option %s missing.\n",filename,line,option); goto error; } if (param[strlen(param)-1] == '/') @@ -212,7 +212,7 @@ int read_options(void) if (*endptr != '\0') { struct passwd * pwd = getpwnam(param); if (pwd == NULL) { - SPRINT(options_error, "Error in %s (line %d): no such user: %s.\n",filename,line,param); + UPRINT(options_error, "Error in %s (line %d): no such user: %s.\n",filename,line,param); goto error; } options.socketuser = pwd->pw_uid; @@ -224,7 +224,7 @@ int read_options(void) if (*endptr != '\0') { struct group * grp = getgrnam(param); if (grp == NULL) { - SPRINT(options_error, "Error in %s (line %d): no such group: %s.\n",filename,line,param); + UPRINT(options_error, "Error in %s (line %d): no such group: %s.\n",filename,line,param); goto error; } options.socketgroup = grp->gr_gid; @@ -236,13 +236,13 @@ int read_options(void) if (!strcmp(option,"gsm")) { options.gsm = 1; } else { - SPRINT(options_error, "Error in %s (line %d): wrong option keyword %s.\n", filename,line,option); + UPRINT(options_error, "Error in %s (line %d): wrong option keyword %s.\n", filename,line,option); goto error; } } if (!options.tones_dir[0]) { - SPRINT(options_error, "Error in %s (line %d): option 'tones_dir' with parameter missing.\n", filename); + UPRINT(options_error, "Error in %s (line %d): option 'tones_dir' with parameter missing.\n", filename,line); goto error; } if (fp) fclose(fp); diff --git a/options.h b/options.h index ecf8244..1a256e2 100644 --- a/options.h +++ b/options.h @@ -34,9 +34,7 @@ struct options { extern struct options options; -extern char options_error[256]; - -int read_options(void); +int read_options(char *options_error); #ifdef __cplusplus } -- cgit v1.2.3-55-g7522