charon-cmd: use a copy of pid in initiate callback

When cancelling a connection that gets established, cmd_connection_t gets
freed before terminate() is called. This results in kill()ing invalid PID.
This commit is contained in:
Martin Willi 2013-06-20 11:02:28 +02:00
parent e044a1a9e5
commit 47ec2e407b
1 changed files with 7 additions and 6 deletions

View File

@ -115,9 +115,9 @@ struct private_cmd_connection_t {
/** /**
* Shut down application * Shut down application
*/ */
static void terminate(private_cmd_connection_t *this) static void terminate(pid_t pid)
{ {
kill(this->pid, SIGUSR1); kill(pid, SIGUSR1);
} }
/** /**
@ -329,17 +329,18 @@ static job_requeue_t initiate(private_cmd_connection_t *this)
{ {
peer_cfg_t *peer_cfg; peer_cfg_t *peer_cfg;
child_cfg_t *child_cfg; child_cfg_t *child_cfg;
pid_t pid = this->pid;
if (!this->host) if (!this->host)
{ {
DBG1(DBG_CFG, "unable to initiate, missing --host option"); DBG1(DBG_CFG, "unable to initiate, missing --host option");
terminate(this); terminate(pid);
return JOB_REQUEUE_NONE; return JOB_REQUEUE_NONE;
} }
if (!this->identity) if (!this->identity)
{ {
DBG1(DBG_CFG, "unable to initiate, missing --identity option"); DBG1(DBG_CFG, "unable to initiate, missing --identity option");
terminate(this); terminate(pid);
return JOB_REQUEUE_NONE; return JOB_REQUEUE_NONE;
} }
@ -348,7 +349,7 @@ static job_requeue_t initiate(private_cmd_connection_t *this)
if (!add_auth_cfgs(this, peer_cfg)) if (!add_auth_cfgs(this, peer_cfg))
{ {
peer_cfg->destroy(peer_cfg); peer_cfg->destroy(peer_cfg);
terminate(this); terminate(pid);
return JOB_REQUEUE_NONE; return JOB_REQUEUE_NONE;
} }
@ -358,7 +359,7 @@ static job_requeue_t initiate(private_cmd_connection_t *this)
if (charon->controller->initiate(charon->controller, peer_cfg, child_cfg, if (charon->controller->initiate(charon->controller, peer_cfg, child_cfg,
controller_cb_empty, NULL, 0) != SUCCESS) controller_cb_empty, NULL, 0) != SUCCESS)
{ {
terminate(this); terminate(pid);
} }
return JOB_REQUEUE_NONE; return JOB_REQUEUE_NONE;
} }