From ab4118a7acb4a608c9c24e56424c66fbc9084f31 Mon Sep 17 00:00:00 2001 From: Troy Denton Date: Fri, 3 Apr 2020 11:17:40 -0500 Subject: [PATCH] Replace system() with execl() to remove extra forking The behaviour of forking and then calling system() results in a fork-of-a-fork and is unaccounted for. This causes extra incrond processes to pile up. Replaced system() with its equivalent exec, sans fork. --- usertable.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/usertable.cpp b/usertable.cpp index 11fd04b..cf98902 100644 --- a/usertable.cpp +++ b/usertable.cpp @@ -471,11 +471,10 @@ void UserTable::OnEvent(InotifyEvent& rEvt) // for system table if (m_fSysTable) { - if (system(cmd.c_str()) != 0) // exec failed - { - syslog(LOG_ERR, "cannot exec process: %s", strerror(errno)); - _exit(1); - } + execl("/bin/sh", "sh", "-c", cmd.c_str(), (char *) 0); + int rc = errno; + syslog(LOG_ERR, "cannot exec process: %s", strerror(rc)); + _exit(1); } else { // for user table