From ba4c53a0caebd95b85184db988d2eea1c6ed5786 Mon Sep 17 00:00:00 2001 From: Jussi Lind Date: Tue, 24 Aug 2010 15:30:26 +0300 Subject: [PATCH 1/4] Changes: Set PWD correctly --- src/launcher/booster.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/launcher/booster.cpp b/src/launcher/booster.cpp index 9e5a0c6..3373335 100644 --- a/src/launcher/booster.cpp +++ b/src/launcher/booster.cpp @@ -171,10 +171,18 @@ int Booster::launchProcess() // Load the application and find out the address of main() void* handle = loadMain(); + // Duplicate I/O descriptors for (unsigned int i = 0; i < m_app.ioDescriptors().size(); i++) if (m_app.ioDescriptors()[i] > 0) dup2(m_app.ioDescriptors()[i], i); + // Set PWD + const char * pwd = getenv("PWD"); + if (pwd) + { + chdir(pwd); + } + Logger::logNotice("launching process: '%s' ", m_app.fileName().c_str()); // Close logger From 9e1768ae1bca3e88770c60921994bb6d6084d2ac Mon Sep 17 00:00:00 2001 From: Jussi Lind Date: Tue, 24 Aug 2010 15:41:24 +0300 Subject: [PATCH 2/4] Changes: Two temp variables eliminated. --- src/launcher/booster.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/launcher/booster.cpp b/src/launcher/booster.cpp index 100c265..52035bf 100644 --- a/src/launcher/booster.cpp +++ b/src/launcher/booster.cpp @@ -174,17 +174,15 @@ int Booster::launchProcess() if (!errno && cur_prio < m_app.priority()) setpriority(PRIO_PROCESS, 0, m_app.priority()); - // Possible set user ID and group ID of calling process - uid_t uid = getuid(); - gid_t gid = getgid(); + // Set user ID and group ID of calling process if differing + // from the ones we got from invoker - if (uid != m_app.userId()) + if (getuid() != m_app.userId()) setuid(m_app.userId()); - if (gid != m_app.groupId()) + if (getgid() != m_app.groupId()) setgid(m_app.groupId()); - // Load the application and find out the address of main() void* handle = loadMain(); From 470a3643734da926f923f8473f56edeebc3e1490 Mon Sep 17 00:00:00 2001 From: Jussi Lind Date: Tue, 24 Aug 2010 16:54:21 +0300 Subject: [PATCH 3/4] Changes: PROG_NAME separated into PROG_NAME_LAUNCHER and PROG_NAME_INVOKER. One compiler warning due to signed to unsigned comparison fixed. --- CMakeLists.txt | 5 +++-- src/invoker/CMakeLists.txt | 2 +- src/invoker/invoker.c | 4 ++-- src/invoker/report.c | 4 ++-- src/launcher/daemon.cpp | 3 +-- src/launcher/logger.cpp | 2 +- src/launcher/main.cpp | 6 +++--- tests/unittests/ut_connection/CMakeLists.txt | 2 +- tests/unittests/ut_daemon/CMakeLists.txt | 2 +- 9 files changed, 15 insertions(+), 15 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 16229af..cac933a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -41,8 +41,9 @@ if ($ENV{DISABLE_VERIFICATION}) add_definitions(-DDISABLE_VERIFICATION) endif ($ENV{DISABLE_VERIFICATION}) -# Set the program name define. Must be at this level due to unit tests. -add_definitions(-DPROG_NAME="applauncherd") +# Set the program name defines. Must be at this level due to unit tests. +add_definitions(-DPROG_NAME_INVOKER="invoker") +add_definitions(-DPROG_NAME_LAUNCHER="applauncherd") # Build with test coverage switch if BUILD_COVERAGE environment variable is set if ($ENV{BUILD_COVERAGE}) diff --git a/src/invoker/CMakeLists.txt b/src/invoker/CMakeLists.txt index cd3e2b0..5cdd229 100644 --- a/src/invoker/CMakeLists.txt +++ b/src/invoker/CMakeLists.txt @@ -8,7 +8,7 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_HOME_DIRECTORY}/src/comm set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -W -Wall -O2") # Set precompiler flags -add_definitions(-DPROG_NAME="invoker") +add_definitions(-DPROG_NAME_INVOKER="invoker") # Set target add_executable(invoker ${SRC}) diff --git a/src/invoker/invoker.c b/src/invoker/invoker.c index f3afe4c..99f0e04 100644 --- a/src/invoker/invoker.c +++ b/src/invoker/invoker.c @@ -394,7 +394,7 @@ static void usage(int status) " -w, --wait-term Wait for launched process to terminate.\n" " -h, --help Print this help message.\n\n" "Example: %s --type=m /usr/bin/helloworld \n", - PROG_NAME, DEFAULT_DELAY, PROG_NAME); + PROG_NAME_INVOKER, DEFAULT_DELAY, PROG_NAME_INVOKER); exit(status); } @@ -487,7 +487,7 @@ int main(int argc, char *argv[]) char **prog_argv = NULL; char *prog_name = NULL; - if (!strstr(argv[0], PROG_NAME) ) + if (!strstr(argv[0], PROG_NAME_INVOKER) ) { // Called with a different name, old way of using invoker die(1, diff --git a/src/invoker/report.c b/src/invoker/report.c index a8cd217..66e9756 100644 --- a/src/invoker/report.c +++ b/src/invoker/report.c @@ -35,7 +35,7 @@ void report_set_output(enum report_output new_output) closelog(); if (new_output == report_syslog) - openlog(PROG_NAME, LOG_PID, LOG_DAEMON); + openlog(PROG_NAME_INVOKER, LOG_PID, LOG_DAEMON); output = new_output; } @@ -72,7 +72,7 @@ static void vreport(enum report_type type, char *msg, va_list arg) vsnprintf(str, sizeof(str), msg, arg); if (output == report_console) - printf("%s: %s%s", PROG_NAME, str_type, str); + printf("%s: %s%s", PROG_NAME_INVOKER, str_type, str); else if (output == report_syslog) syslog(log_type, "%s%s", str_type, str); } diff --git a/src/launcher/daemon.cpp b/src/launcher/daemon.cpp index b85007b..e83210e 100644 --- a/src/launcher/daemon.cpp +++ b/src/launcher/daemon.cpp @@ -147,12 +147,11 @@ void Daemon::run() ssize_t count = read(m_pipefd[0], reinterpret_cast(&msg), 1); if (count) { - // read pid of peer invoker pid_t invoker_pid; count = read(m_pipefd[0], reinterpret_cast(&invoker_pid), sizeof(pid_t)); - if (count < sizeof(pid_t)) + if (count < static_cast(sizeof(pid_t))) { Logger::logErrorAndDie(EXIT_FAILURE, "Daemon: pipe connection with booster failed"); } diff --git a/src/launcher/logger.cpp b/src/launcher/logger.cpp index 851cd3c..2635179 100644 --- a/src/launcher/logger.cpp +++ b/src/launcher/logger.cpp @@ -27,7 +27,7 @@ namespace { const QString logDirectory("/var/log"); - const QString logFileName(logDirectory + QDir::separator() + PROG_NAME + ".log"); + const QString logFileName(logDirectory + QDir::separator() + PROG_NAME_LAUNCHER + ".log"); const QString oldLogFileName(logFileName + ".old"); const QString dateFormat("yyyy-MM-dd hh:mm:ss.zzz"); } diff --git a/src/launcher/main.cpp b/src/launcher/main.cpp index 720df2c..a6d4aca 100644 --- a/src/launcher/main.cpp +++ b/src/launcher/main.cpp @@ -48,7 +48,7 @@ void exitLauncher(int) void usage() { - std::cout << "Usage: "<< PROG_NAME << " [options]\n" + std::cout << "Usage: "<< PROG_NAME_LAUNCHER << " [options]\n" << "\n" << "Options:\n" << " --daemon Fork and go into the background.\n" @@ -77,8 +77,8 @@ int main(int argc, char * argv[]) } // Open the log - Logger::openLog(PROG_NAME); - Logger::logNotice("%s starting..", PROG_NAME); + Logger::openLog(PROG_NAME_LAUNCHER); + Logger::logNotice("%s starting..", PROG_NAME_LAUNCHER); // Check that an instance of launcher is not already running if(!Daemon::lock()) diff --git a/tests/unittests/ut_connection/CMakeLists.txt b/tests/unittests/ut_connection/CMakeLists.txt index 9e10ba5..d162b83 100644 --- a/tests/unittests/ut_connection/CMakeLists.txt +++ b/tests/unittests/ut_connection/CMakeLists.txt @@ -7,7 +7,7 @@ set(SRC ut_connection.cpp ${LAUNCHER}/appdata.cpp ${LAUNCHER}/booster.cpp ${LAUN set(MOC_HDRS ut_connection.h) # Set the program name define used in daemon.cpp -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DPROG_NAME=\\\"applauncherd\\\"") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DPROG_NAME_LAUNCHER=\\\"applauncherd\\\"") # Run moc qt4_wrap_cpp(MOC_SRC ${MOC_HDRS}) diff --git a/tests/unittests/ut_daemon/CMakeLists.txt b/tests/unittests/ut_daemon/CMakeLists.txt index 097d476..2e9a12a 100644 --- a/tests/unittests/ut_daemon/CMakeLists.txt +++ b/tests/unittests/ut_daemon/CMakeLists.txt @@ -6,7 +6,7 @@ set(SRC ut_daemon.cpp ${LAUNCHER}/appdata.cpp ${LAUNCHER}/booster.cpp ${LAUNCHER set(MOC_HDRS ut_daemon.h) # Set the program name define used in daemon.cpp -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DPROG_NAME=\\\"applauncherd\\\"") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DPROG_NAME_LAUNCHER=\\\"applauncherd\\\"") # Run moc qt4_wrap_cpp(MOC_SRC ${MOC_HDRS} ) From f021bde9331ae6b9817d5932179aa7332e1df94e Mon Sep 17 00:00:00 2001 From: Jussi Lind Date: Tue, 24 Aug 2010 18:06:28 +0300 Subject: [PATCH 4/4] Changes: debian/changelog updated, new unstable version --- debian/changelog | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/debian/changelog b/debian/changelog index 33745c4..6ed3e4c 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,10 @@ +applauncherd (0.10.4) unstable; urgency=low + + * Changes: Handle PWD correctly + * Changes: PROG_NAME separated into PROG_NAME_INVOKER and PROG_NAME_LAUNCHER + + -- Jussi Lind Tue, 24 Aug 2010 18:04:39 +0300 + applauncherd (0.10.3) stable; urgency=low * Changes: pass and set gid and uid from invoker process to launcher