Skip to content

Commit

Permalink
Implements a (very) experimental 'valgrind' mode. The '--valgrind'
Browse files Browse the repository at this point in the history
parameter forces cherokee to launch its worker process under valgrind.

git-svn-id: svn://cherokee-project.com/cherokee/trunk@5886 5dc97367-97f1-0310-9951-d761b3857238
  • Loading branch information
alobbs committed Dec 7, 2010
1 parent 016f4d4 commit 0d02ba0
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 3 deletions.
67 changes: 65 additions & 2 deletions cherokee/main.c
Expand Up @@ -68,11 +68,14 @@ union semun {
#define DEFAULT_PID_FILE CHEROKEE_VAR_RUN "/cherokee.pid"
#define DEFAULT_CONFIG CHEROKEE_CONFDIR "/cherokee.conf"

#define VALGRIND_PREFIX {"valgrind", "--leak-check=full", "--num-callers=40", "-v", "--leak-resolution=high", NULL}

pid_t pid;
char *pid_file_path;
char *worker_uid;
cherokee_boolean_t graceful_restart;
char *cherokee_worker;
cherokee_boolean_t use_valgrind = false;
char *spawn_shared = NULL;
char *spawn_shared_name = NULL;
int spawn_shared_sem = -1;
Expand Down Expand Up @@ -211,6 +214,24 @@ figure_config_file (int argc, char **argv)
}


static cherokee_boolean_t
figure_use_valgrind (int argc, char **argv)
{
int i;

for (i=0; i<argc; i++) {
if ((strcmp(argv[i], "-v") == 0) ||
(strcmp(argv[i], "--valgrind") == 0))
{
argv[i] = "";
return true;
}
}

return false;
}


static char *
figure_worker_uid (const char *config)
{
Expand Down Expand Up @@ -849,13 +870,47 @@ may_daemonize (int argc, char *argv[])
static pid_t
process_launch (const char *path, char *argv[])
{
pid_t pid;
pid_t pid;
char **new_args = NULL;

if (use_valgrind) {
int total;
int len_argv;
int len_valg;
const char *valgrind_args[] = VALGRIND_PREFIX;

/* Alloc
*/
for (len_argv=0; argv[len_argv]; len_argv++);
for (len_valg=0; valgrind_args[len_valg]; len_valg++);
new_args = malloc ((len_argv + len_valg + 2) * sizeof(char *));

/* Copy
*/
total = 0;

for (len_valg=0; valgrind_args[len_valg]; len_valg++, total++) {
new_args[total] = valgrind_args[len_valg];
}

for (len_argv=0; argv[len_argv]; len_argv++, total++) {
new_args[total] = argv[len_argv];
}

new_args[total+1] = NULL;
argv = new_args;
}

/* Execute the server
*/
pid = fork();
if (pid == 0) {
argv[0] = (char *) path;
if (use_valgrind) {
argv = new_args;
path = "valgrind";
} else {
argv[0] = (char *) path;
}

do {
execvp (path, argv);
Expand All @@ -865,6 +920,13 @@ process_launch (const char *path, char *argv[])
exit (1);
}

/* Clean up
*/
if ((use_valgrind) && (new_args != NULL))
{
free (new_args);
}

return pid;
}

Expand Down Expand Up @@ -907,6 +969,7 @@ main (int argc, char *argv[])
/* Figure out some stuff
*/
config_file_path = figure_config_file (argc, argv);
use_valgrind = figure_use_valgrind (argc, argv);
pid_file_path = figure_pid_file_path (config_file_path);
worker_uid = figure_worker_uid (config_file_path);

Expand Down
3 changes: 2 additions & 1 deletion cherokee/main_worker.c
Expand Up @@ -275,7 +275,8 @@ print_help (void)
" -C, --config=PATH Configuration file\n"
" -p, --port=NUM TCP port number\n"
" -r, --documentroot=PATH Server directory content\n"
" -i, --print-server-info Print server technical information\n\n"
" -i, --print-server-info Print server technical information\n"
" -v, --valgrind Execute the worker process under valgrind\n\n"
"Report bugs to " PACKAGE_BUGREPORT "\n");
}

Expand Down

0 comments on commit 0d02ba0

Please sign in to comment.