fork/exec: search for helper in libexec

Added code which checks for existence of the helper binary in the
libexec dir when it is given without any path component. Searching
inside the PATH env variable is still used as fallback when not
found in libexec (useful for testing without actually installing
in the final destination).
This commit is contained in:
Patrick Ohly 2012-01-16 17:51:23 +01:00
parent e405d2b7ea
commit f5af2bcc6a
3 changed files with 32 additions and 4 deletions

View File

@ -1048,6 +1048,10 @@ SYNCEVOLUTION_DATA_DIR
SYNCEVOLUTION_BACKEND_DIR
Overrides the default path to plugins, normally `/usr/lib/syncevolution/backends`.
SYNCEVOLUTION_LIBEXEC_DIR
Overrides the path where additional helper executables are found, normally
`/usr/libexec`.
SYNCEVOLUTION_TEMPLATE_DIR
Overrides the default path to template files, normally
`/usr/share/syncevolution/templates`.

View File

@ -80,7 +80,32 @@ void ForkExecParent::start()
}
m_server->setNewConnectionCallback(boost::bind(&ForkExecParent::newClientConnection, this, _2));
m_argvStrings.push_back(m_helper);
// look for helper binary
std::string helper;
GSpawnFlags flags = G_SPAWN_DO_NOT_REAP_CHILD;
if (m_helper.find('/') == m_helper.npos) {
helper = getEnv("SYNCEVOLUTION_LIBEXEC_DIR", "");
if (helper.empty()) {
// env variable not set, look in libexec dir
helper = SYNCEVO_LIBEXEC;
helper += "/";
helper += m_helper;
if (access(helper.c_str(), R_OK)) {
// some error, try PATH
flags = (GSpawnFlags)(flags | G_SPAWN_SEARCH_PATH);
helper = m_helper;
}
} else {
// use env variable without further checks, must work
helper += "/";
helper += m_helper;
}
} else {
// absolute path, use it
m_helper = helper;
}
m_argvStrings.push_back(helper);
m_argv.reset(AllocStringArray(m_argvStrings));
for (char **env = environ;
*env;
@ -98,8 +123,7 @@ void ForkExecParent::start()
if (!g_spawn_async_with_pipes(NULL, // working directory
static_cast<gchar **>(m_argv.get()),
static_cast<gchar **>(m_env.get()),
(GSpawnFlags)((m_helper.find('/') == m_helper.npos ? G_SPAWN_SEARCH_PATH : 0) |
G_SPAWN_DO_NOT_REAP_CHILD),
flags,
setStdoutToStderr, // child setup function: redirect stdout to stderr where it will be caught by our own output redirection code
// TODO: avoid logging child errors as "[ERROR] stderr: [ERROR] onConnect not implemented"
// TODO: log child INFO messages?

View File

@ -3,7 +3,7 @@ include $(top_srcdir)/src/syncevo/configs/configs.am
# applies to sources in SyncEvolution repository, but not
# the Funambol C++ client library
src_syncevo_cxxflags = @SYNCEVOLUTION_CXXFLAGS@
src_syncevo_cppflags = @BACKEND_CPPFLAGS@ @GLIB_CFLAGS@ -I$(top_srcdir)/test -I$(gdbus_dir) $(DBUS_CFLAGS) -I$(top_builddir)/src/syncevo -I$(top_srcdir)/src -DSYNCEVO_BACKEND=\"$(BACKENDS_SEARCH_DIRECTORY)\"
src_syncevo_cppflags = @BACKEND_CPPFLAGS@ @GLIB_CFLAGS@ -I$(top_srcdir)/test -I$(gdbus_dir) $(DBUS_CFLAGS) -I$(top_builddir)/src/syncevo -I$(top_srcdir)/src -DSYNCEVO_LIBEXEC=\"$(libexecdir)\" -DSYNCEVO_BACKEND=\"$(BACKENDS_SEARCH_DIRECTORY)\"
src_syncevo_ldadd = @SYNCEVOLUTION_LDADD@
if COND_DBUS