diff options
author | Pavel Reichl <pavel.reichl@redhat.com> | 2013-12-02 15:20:01 +0000 |
---|---|---|
committer | Jakub Hrozek <jhrozek@redhat.com> | 2013-12-09 22:08:53 +0100 |
commit | e5502b7652b5c974bc44227f46693d3a43f69b8b (patch) | |
tree | 8670c8a6e61dd68846c005f00abc7a0d0be9fb2b /src | |
parent | f89cf190f58f3f5c73758abd0a24974a78cb160b (diff) | |
download | sssd-e5502b7652b5c974bc44227f46693d3a43f69b8b.tar.gz sssd-e5502b7652b5c974bc44227f46693d3a43f69b8b.tar.xz sssd-e5502b7652b5c974bc44227f46693d3a43f69b8b.zip |
monitor: monitor_kill_service - refactor
After freeing *svc* return immediately instead of creating event operating on
*svc* (use-after-free). Also check tevent_add_timer failure and remove unused
sigkill_ev variable.
Diffstat (limited to 'src')
-rw-r--r-- | src/monitor/monitor.c | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/src/monitor/monitor.c b/src/monitor/monitor.c index 5ea4fc930..4c0c22ce9 100644 --- a/src/monitor/monitor.c +++ b/src/monitor/monitor.c @@ -126,8 +126,6 @@ struct mt_svc { struct tevent_timer *ping_ev; struct sss_child_ctx *child_ctx; - - struct tevent_timer *sigkill_ev; }; struct config_file_callback { @@ -613,23 +611,37 @@ static int monitor_kill_service (struct mt_svc *svc) { int ret; struct timeval tv; + struct tevent_timer *te; ret = kill(svc->pid, SIGTERM); - if (ret != EOK) { + if (ret == -1) { + ret = errno; DEBUG(SSSDBG_FATAL_FAILURE, - ("Sending signal to child (%s:%d) failed! " + ("Sending signal to child (%s:%d) failed: [%d]: %s! " "Ignore and pretend child is dead.\n", - svc->name, svc->pid)); - talloc_free(svc); + svc->name, svc->pid, ret, strerror(ret))); + goto done; } /* Set up a timer to send SIGKILL if this process * doesn't exit within sixty seconds */ tv = tevent_timeval_current_ofs(svc->kill_time, 0); - svc->sigkill_ev = tevent_add_timer(svc->mt_ctx->ev, svc, tv, - mt_svc_sigkill, svc); + te = tevent_add_timer(svc->mt_ctx->ev, svc, tv, mt_svc_sigkill, svc); + if (te == NULL) { + /* Nothing much we can do */ + ret = ENOMEM; + DEBUG(SSSDBG_CRIT_FAILURE, + ("Failed to allocate timed event: mt_svc_sigkill.\n")); + goto done; + } + + ret = EOK; +done: + if (ret != EOK) { + talloc_free(svc); + } return ret; } |