Skip to content

Commit

Permalink
Fix error and warnings for compile flag USE_SHM_MEM
Browse files Browse the repository at this point in the history
  • Loading branch information
rvlad-patrascu committed Jul 5, 2016
1 parent 0b4cbaa commit c9d8030
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 23 deletions.
6 changes: 6 additions & 0 deletions cfg.y
Original file line number Diff line number Diff line change
Expand Up @@ -759,10 +759,16 @@ assign_stm: DEBUG EQUAL snumber
| EVENT_SHM_THRESHOLD EQUAL error { yyerror("int value expected"); }
| EVENT_PKG_THRESHOLD EQUAL NUMBER {
#ifdef STATISTICS
#ifdef USE_SHM_MEM
warn("No PKG memory, all allocations are mapped to SHM;
Use event_shm_threshold instead or recompile with PKG_MALLOC
instead of USE_SHM_MEM in order to have separate PKG memory");
#else
if ($3 < 0 || $3 > 100)
yyerror("PKG threshold has to be a percentage between "
"0 and 100");
event_pkg_threshold=$3;
#endif
#else
yyerror("statistics support not compiled in");
#endif
Expand Down
54 changes: 32 additions & 22 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -758,8 +758,36 @@ int main(int argc, char** argv)
};

break;
case 'm':
shm_mem_size=strtol(optarg, &tmp, 10) * 1024 * 1024;
if (tmp &&(*tmp)){
LM_ERR("bad shmem size number: -m %s\n", optarg);
goto error00;
};
break;
case 'u':
user=optarg;
break;
case 'g':
group=optarg;
break;
}
}

/* get uid/gid */
if (user){
if (user2uid(&uid, &gid, user)<0){
LM_ERR("bad user name/uid number: -u %s\n", user);
goto error00;
}
}
if (group){
if (group2gid(&gid, group)<0){
LM_ERR("bad group name/gid number: -u %s\n", group);
goto error00;
}
}

/*init pkg mallocs (before parsing cfg but after parsing cmd line !)*/
if (init_pkg_mallocs()==-1)
goto error00;
Expand All @@ -783,11 +811,7 @@ int main(int argc, char** argv)
cfg_log_stderr=1; /* force stderr logging */
break;
case 'm':
shm_mem_size=strtol(optarg, &tmp, 10) * 1024 * 1024;
if (tmp &&(*tmp)){
LM_ERR("bad shmem size number: -m %s\n", optarg);
goto error00;
};
/* ignoring it, parsed previously */
break;
case 'M':
/* ignoring it, parsed previously */
Expand Down Expand Up @@ -876,10 +900,10 @@ int main(int argc, char** argv)
chroot_dir=optarg;
break;
case 'u':
user=optarg;
/* ignoring it, parsed previously */
break;
case 'g':
group=optarg;
/* ignoring it, parsed previously */
break;
case 'P':
pid_file=optarg;
Expand Down Expand Up @@ -955,21 +979,7 @@ int main(int argc, char** argv)
yydebug = 1;
#endif

/* get uid/gid */
if (user){
if (user2uid(&uid, &gid, user)<0){
LM_ERR("bad user name/uid number: -u %s\n", user);
goto error00;
}
}
if (group){
if (group2gid(&gid, group)<0){
LM_ERR("bad group name/gid number: -u %s\n", group);
goto error00;
}
}

/*init shm mallocs
/* init shm mallocs
* this must be here
* -to allow setting shm mem size from the command line
* -it must be also before init_timer and init_tcp
Expand Down
17 changes: 16 additions & 1 deletion mem/mem.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,11 @@ int init_pkg_mallocs(void)
pkg_mem_size );
return -1;
}
#endif
#elif defined USE_SHM_MEM
return init_shm_mallocs();
#else
return 0;
#endif
}


Expand Down Expand Up @@ -190,12 +193,24 @@ void pkg_threshold_check(void)

int init_shm_mallocs(void)
{
#ifdef USE_SHM_MEM
static int initialized = 0;

if (initialized)
return 0;
#endif

if (shm_mem_init()<0) {
LM_CRIT("could not initialize shared memory pool, exiting...\n");
fprintf(stderr, "Too much shared memory demanded: %ld\n",
shm_mem_size );
return -1;
}

#ifdef USE_SHM_MEM
initialized = 1;
#endif

return 0;
}

Expand Down
1 change: 1 addition & 0 deletions mem/mem.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ void set_pkg_stats(pkg_status_holder*);
#elif defined(USE_SHM_MEM)
# include "shm_mem.h"
# define pkg_malloc(s) shm_malloc((s))
# define pkg_realloc(p, s) shm_realloc((p), (s))
# define pkg_free(p) shm_free((p))
# define pkg_status() shm_status()
# define MY_PKG_GET_SIZE()
Expand Down

0 comments on commit c9d8030

Please sign in to comment.