Skip to content

Commit

Permalink
core: remove the SHM_MEM #define, the core will not even compile with…
Browse files Browse the repository at this point in the history
…out it

- remove the SHM_MEM #define, the purpose of this was to allow the compilation
  without SHM memory pool support
- this did not worked for a long time, the core will not even compile without
  it (no locking, broken timer etc..). Additionally many modules need it.
- remove 50 ifdef/endif blocks, no functional changes done
  • Loading branch information
henningw committed Dec 26, 2018
1 parent d272daf commit 970fc2a
Show file tree
Hide file tree
Showing 13 changed files with 3 additions and 95 deletions.
28 changes: 0 additions & 28 deletions src/core/cfg.y
Expand Up @@ -41,9 +41,7 @@
#include <errno.h>
#include "route_struct.h"
#include "globals.h"
#ifdef SHM_MEM
#include "shm_init.h"
#endif /* SHM_MEM */
#include "route.h"
#include "switch.h"
#include "dprint.h"
Expand Down Expand Up @@ -1743,23 +1741,19 @@ module_stm:
}
| LOADPATH EQUAL error { yyerror("string expected"); }
| MODPARAM LPAREN STRING COMMA STRING COMMA STRING RPAREN {
#ifdef SHM_MEM
if (!shm_initialized() && init_shm()<0) {
yyerror("Can't initialize shared memory");
YYABORT;
}
#endif /* SHM_MEM */
if (set_mod_param_regex($3, $5, PARAM_STRING, $7) != 0) {
yyerror("Can't set module parameter");
}
}
| MODPARAM LPAREN STRING COMMA STRING COMMA intno RPAREN {
#ifdef SHM_MEM
if (!shm_initialized() && init_shm()<0) {
yyerror("Can't initialize shared memory");
YYABORT;
}
#endif /* SHM_MEM */
if (set_mod_param_regex($3, $5, PARAM_INT, (void*)$7) != 0) {
yyerror("Can't set module parameter");
}
Expand Down Expand Up @@ -1857,21 +1851,17 @@ route_main: ROUTE { routename=NULL; }

route_stm:
route_main LBRACE actions RBRACE {
#ifdef SHM_MEM
if (!shm_initialized() && init_shm()<0) {
yyerror("Can't initialize shared memory");
YYABORT;
}
#endif /* SHM_MEM */
push($3, &main_rt.rlist[DEFAULT_RT]);
}
| ROUTE LBRACK route_name RBRACK LBRACE actions RBRACE {
#ifdef SHM_MEM
if (!shm_initialized() && init_shm()<0) {
yyerror("Can't initialize shared memory");
YYABORT;
}
#endif /* SHM_MEM */
i_tmp=route_get(&main_rt, $3);
if (i_tmp==-1){
yyerror("internal error");
Expand All @@ -1891,21 +1881,17 @@ failure_route_main: ROUTE_FAILURE { routename=NULL; }
;
failure_route_stm:
failure_route_main LBRACE actions RBRACE {
#ifdef SHM_MEM
if (!shm_initialized() && init_shm()<0) {
yyerror("Can't initialize shared memory");
YYABORT;
}
#endif /* SHM_MEM */
push($3, &failure_rt.rlist[DEFAULT_RT]);
}
| ROUTE_FAILURE LBRACK route_name RBRACK LBRACE actions RBRACE {
#ifdef SHM_MEM
if (!shm_initialized() && init_shm()<0) {
yyerror("Can't initialize shared memory");
YYABORT;
}
#endif /* SHM_MEM */
i_tmp=route_get(&failure_rt, $3);
if (i_tmp==-1){
yyerror("internal error");
Expand All @@ -1928,25 +1914,21 @@ route_reply_main: ROUTE_ONREPLY { routename=NULL; }

onreply_route_stm:
route_reply_main LBRACE {rt=CORE_ONREPLY_ROUTE;} actions RBRACE {
#ifdef SHM_MEM
if (!shm_initialized() && init_shm()<0) {
yyerror("Can't initialize shared memory");
YYABORT;
}
#endif /* SHM_MEM */
push($4, &onreply_rt.rlist[DEFAULT_RT]);
}
| ROUTE_ONREPLY error { yyerror("invalid onreply_route statement"); }
| ROUTE_REPLY error { yyerror("invalid onreply_route statement"); }
| ROUTE_ONREPLY LBRACK route_name RBRACK
{rt=(*$3=='0' && $3[1]==0)?CORE_ONREPLY_ROUTE:TM_ONREPLY_ROUTE;}
LBRACE actions RBRACE {
#ifdef SHM_MEM
if (!shm_initialized() && init_shm()<0) {
yyerror("Can't initialize shared memory");
YYABORT;
}
#endif /* SHM_MEM */
if (*$3=='0' && $3[1]==0){
/* onreply_route[0] {} is equivalent with onreply_route {}*/
push($7, &onreply_rt.rlist[DEFAULT_RT]);
Expand All @@ -1972,21 +1954,17 @@ branch_route_main: ROUTE_BRANCH { routename=NULL; }
;
branch_route_stm:
branch_route_main LBRACE actions RBRACE {
#ifdef SHM_MEM
if (!shm_initialized() && init_shm()<0) {
yyerror("Can't initialize shared memory");
YYABORT;
}
#endif /* SHM_MEM */
push($3, &branch_rt.rlist[DEFAULT_RT]);
}
| ROUTE_BRANCH LBRACK route_name RBRACK LBRACE actions RBRACE {
#ifdef SHM_MEM
if (!shm_initialized() && init_shm()<0) {
yyerror("Can't initialize shared memory");
YYABORT;
}
#endif /* SHM_MEM */
i_tmp=route_get(&branch_rt, $3);
if (i_tmp==-1){
yyerror("internal error");
Expand All @@ -2005,21 +1983,17 @@ send_route_main: ROUTE_SEND { routename=NULL; }
;
send_route_stm:
send_route_main LBRACE actions RBRACE {
#ifdef SHM_MEM
if (!shm_initialized() && init_shm()<0) {
yyerror("Can't initialize shared memory");
YYABORT;
}
#endif /* SHM_MEM */
push($3, &onsend_rt.rlist[DEFAULT_RT]);
}
| ROUTE_SEND LBRACK route_name RBRACK LBRACE actions RBRACE {
#ifdef SHM_MEM
if (!shm_initialized() && init_shm()<0) {
yyerror("Can't initialize shared memory");
YYABORT;
}
#endif /* SHM_MEM */
i_tmp=route_get(&onsend_rt, $3);
if (i_tmp==-1){
yyerror("internal error");
Expand All @@ -2038,12 +2012,10 @@ event_route_main: ROUTE_EVENT { routename=NULL; }
;
event_route_stm:
event_route_main LBRACK EVENT_RT_NAME RBRACK LBRACE actions RBRACE {
#ifdef SHM_MEM
if (!shm_initialized() && init_shm()<0) {
yyerror("Can't initialize shared memory");
YYABORT;
}
#endif /* SHM_MEM */
i_tmp=route_get(&event_rt, $3);
if (i_tmp==-1){
yyerror("internal error");
Expand Down
6 changes: 1 addition & 5 deletions src/core/cfg_core.c
Expand Up @@ -47,7 +47,7 @@
#ifdef USE_DNS_CACHE
#include "dns_cache.h"
#endif
#if defined PKG_MALLOC || defined SHM_MEM
#if defined PKG_MALLOC
#include "pt.h"
#endif
#include "msg_translator.h" /* fix_global_req_flags() */
Expand Down Expand Up @@ -100,9 +100,7 @@ struct cfg_group_core default_core_cfg = {
#ifdef PKG_MALLOC
0, /*!< mem_dump_pkg */
#endif
#ifdef SHM_MEM
0, /*!< mem_dump_shm */
#endif
DEFAULT_MAX_WHILE_LOOPS, /*!< max_while_loops */
0, /*!< udp_mtu (disabled by default) */
0, /*!< udp_mtu_try_proto -> default disabled */
Expand Down Expand Up @@ -279,10 +277,8 @@ cfg_def_t core_cfg_def[] = {
{"mem_dump_pkg", CFG_VAR_INT, 0, 0, 0, mem_dump_pkg_cb,
"dump process memory status, parameter: pid_number"},
#endif
#ifdef SHM_MEM
{"mem_dump_shm", CFG_VAR_INT, 0, 0, mem_dump_shm_fixup, 0,
"dump shared memory status"},
#endif
{"max_while_loops", CFG_VAR_INT|CFG_ATOMIC, 0, 0, 0, 0,
"maximum iterations allowed for a while loop" },
{"udp_mtu", CFG_VAR_INT|CFG_ATOMIC, 0, 65535, 0, 0,
Expand Down
2 changes: 0 additions & 2 deletions src/core/cfg_core.h
Expand Up @@ -89,9 +89,7 @@ struct cfg_group_core {
#ifdef PKG_MALLOC
int mem_dump_pkg;
#endif
#ifdef SHM_MEM
int mem_dump_shm;
#endif
int max_while_loops;
int udp_mtu; /*!< maximum send size for udp, if > try another protocol*/
int udp_mtu_try_proto; /*!< if packet> udp_mtu, try proto (e.g. TCP) */
Expand Down
4 changes: 0 additions & 4 deletions src/core/lock_alloc.h
Expand Up @@ -52,11 +52,7 @@ Implements: (see also locking.h)

/*shm_{malloc, free}*/
#include "mem/mem.h"
#ifdef SHM_MEM
#include "mem/shm_mem.h"
#else
#error "locking requires shared memory support"
#endif

#if defined(FAST_LOCK) || defined(USE_PTHREAD_MUTEX) || defined(USE_POSIX_SEM)
/* simple locks*/
Expand Down
4 changes: 0 additions & 4 deletions src/core/mem/mem.c
Expand Up @@ -38,9 +38,7 @@
#include "q_malloc.h"
#endif

#ifdef SHM_MEM
#include "shm_mem.h"
#endif

#if 0

Expand Down Expand Up @@ -122,14 +120,12 @@ void destroy_pkg_mallocs(void)
*/
int init_shm_mallocs(int force_alloc)
{
#ifdef SHM_MEM
if (shm_mem_init(force_alloc)<0) {
LOG(L_CRIT, "could not initialize shared memory pool, exiting...\n");
fprintf(stderr, "Too much shared memory demanded: %ld\n",
shm_mem_size );
return -1;
}
#endif
return 0;
}
#endif
4 changes: 0 additions & 4 deletions src/core/mem/shm_mem.c
Expand Up @@ -23,8 +23,6 @@
*/


#ifdef SHM_MEM

#if 0

#include <stdlib.h>
Expand Down Expand Up @@ -268,5 +266,3 @@ unsigned long shm_available_safe()
}

#endif

#endif
4 changes: 0 additions & 4 deletions src/core/mem/shm_mem.h
Expand Up @@ -26,8 +26,6 @@
*/


#ifdef SHM_MEM

#ifndef shm_mem_h
#define shm_mem_h

Expand Down Expand Up @@ -345,5 +343,3 @@ unsigned long shm_available_safe();

#endif /* shm_mem_h */

#endif /* SHM_MEM */

15 changes: 1 addition & 14 deletions src/core/pt.c
Expand Up @@ -30,10 +30,8 @@
#ifdef PKG_MALLOC
#include "mem/mem.h"
#endif
#ifdef SHM_MEM
#include "mem/shm_mem.h"
#endif
#if defined PKG_MALLOC || defined SHM_MEM
#if defined PKG_MALLOC
#include "cfg_core.h"
#endif
#include "daemonize.h"
Expand Down Expand Up @@ -103,21 +101,12 @@ int init_pt(int proc_no)
estimated_proc_no+=proc_no;
estimated_fds_no+=calc_common_open_fds_no();
/*alloc pids*/
#ifdef SHM_MEM
pt=shm_malloc(sizeof(struct process_table)*estimated_proc_no);
process_count = shm_malloc(sizeof(int));
#else
pt=pkg_malloc(sizeof(struct process_table)*estimated_proc_no);
process_count = pkg_malloc(sizeof(int));
#endif
process_lock = lock_alloc();
process_lock = lock_init(process_lock);
if (pt==0||process_count==0||process_lock==0){
#ifdef SHM_MEM
SHM_MEM_ERROR;
#else
PKG_MEM_ERROR;
#endif
return -1;
}
memset(pt, 0, sizeof(struct process_table)*estimated_proc_no);
Expand Down Expand Up @@ -557,7 +546,6 @@ void mem_dump_pkg_cb(str *gname, str *name)
}
#endif

#ifdef SHM_MEM
/* Dumps shm memory status.
* fixup function that is called
* when mem_dump_shm cfg var is set.
Expand All @@ -584,4 +572,3 @@ int mem_dump_shm_fixup(void *handle, str *gname, str *name, void **val)
}
return 0;
}
#endif
2 changes: 0 additions & 2 deletions src/core/pt.h
Expand Up @@ -92,9 +92,7 @@ int fork_tcp_process(int child_id,char *desc,int r,int *reader_fd_1);
void mem_dump_pkg_cb(str *gname, str *name);
#endif

#ifdef SHM_MEM
int mem_dump_shm_fixup(void *handle, str *gname, str *name, void **val);
#endif

unsigned int set_fork_delay(unsigned int v);

Expand Down
2 changes: 0 additions & 2 deletions src/core/shm_init.c
Expand Up @@ -46,7 +46,6 @@ int shm_initialized()



#ifdef SHM_MEM
/** init shm mem.
* @return 0 on success, < 0 on error
* it _must_ be called:
Expand Down Expand Up @@ -77,6 +76,5 @@ int init_shm()
error:
return -1;
}
#endif /* SHM_MEM */

/* vi: set ts=4 sw=4 tw=79:ai:cindent: */
17 changes: 0 additions & 17 deletions src/core/timer.c
Expand Up @@ -43,9 +43,7 @@
*/
#include "globals.h"
#include "mem/mem.h"
#ifdef SHM_MEM
#include "mem/shm_mem.h"
#endif
#include "locking.h"
#include "sched_yield.h"
#include "cfg/cfg_struct.h"
Expand Down Expand Up @@ -149,19 +147,11 @@ void destroy_timer()
timer_lock=0;
}
if (ticks){
#ifdef SHM_MEM
shm_free(ticks);
#else
pkg_free(ticks);
#endif
ticks=0;
}
if (timer_lst){
#ifdef SHM_MEM
shm_free(timer_lst);
#else
pkg_free(timer_lst);
#endif
timer_lst=0;
}
if (running_timer){
Expand Down Expand Up @@ -216,15 +206,8 @@ int init_timer()
goto error;
}
/* init the shared structs */
#ifdef SHM_MEM
ticks=shm_malloc(sizeof(ticks_t));
timer_lst=shm_malloc(sizeof(struct timer_lists));
#else
/* in this case get_ticks won't work! */
LM_WARN("no shared memory support compiled in get_ticks won't work\n");
ticks=pkg_malloc(sizeof(ticks_t));
timer_lst=pkg_malloc(sizeof(struct timer_lists));
#endif
if (ticks==0){
SHM_MEM_CRITICAL;
ret=E_OUT_OF_MEM;
Expand Down

0 comments on commit 970fc2a

Please sign in to comment.