From ee9fe47996581e0b6d96f2d8dbfb37eec426d0da Mon Sep 17 00:00:00 2001 From: Juha Lintula Date: Mon, 21 Nov 2011 13:34:26 +0200 Subject: [PATCH] Changes: single-instance library writes log messages to syslog instead of stderr RevBy: Alexey Shilov, Dmitry Rozenshtein --- debian/changelog | 1 + src/{invoker => common}/report.c | 6 +++--- src/{invoker => common}/report.h | 4 ++-- src/invoker/CMakeLists.txt | 6 ++++-- src/single-instance/CMakeLists.txt | 10 ++++++---- src/single-instance/main.cpp | 24 ++++++++++++------------ 6 files changed, 28 insertions(+), 23 deletions(-) rename src/{invoker => common}/report.c (93%) rename src/{invoker => common}/report.h (91%) diff --git a/debian/changelog b/debian/changelog index 45ba79f..996f0bf 100644 --- a/debian/changelog +++ b/debian/changelog @@ -4,6 +4,7 @@ applauncherd (3.0.1) unstable; urgency=low * Changes: Updated list of libraries to preload * Fixes: NB#291089 - Installation of clock application fails when applauncherd daemon stopped * Changes: Adds new test for applauncherd re-exec. Checking state of running application when it is updated. + * Changes: single-instance library writes log messages to syslog instead of stderr -- Alexey Shilov Mon, 14 Nov 2011 13:39:38 +0200 diff --git a/src/invoker/report.c b/src/common/report.c similarity index 93% rename from src/invoker/report.c rename to src/common/report.c index 4977df2..ce9d8b7 100644 --- a/src/invoker/report.c +++ b/src/common/report.c @@ -40,7 +40,7 @@ void report_set_output(enum report_output new_output) output = new_output; } -static void vreport(enum report_type type, char *msg, va_list arg) +static void vreport(enum report_type type, const char *msg, va_list arg) { char str[400]; char *str_type = ""; @@ -87,7 +87,7 @@ static void vreport(enum report_type type, char *msg, va_list arg) syslog(log_type, "%s%s", str_type, str); } -void report(enum report_type type, char *msg, ...) +void report(enum report_type type, const char *msg, ...) { va_list arg; @@ -96,7 +96,7 @@ void report(enum report_type type, char *msg, ...) va_end(arg); } -void die(int status, char *msg, ...) +void die(int status, const char *msg, ...) { va_list arg; diff --git a/src/invoker/report.h b/src/common/report.h similarity index 91% rename from src/invoker/report.h rename to src/common/report.h index e187387..08858f4 100644 --- a/src/invoker/report.h +++ b/src/common/report.h @@ -41,7 +41,7 @@ enum report_type { }; extern void report_set_output(enum report_output new_output); -extern void report(enum report_type type, char *msg, ...); +extern void report(enum report_type type, const char *msg, ...); #ifndef DEBUG_LOGGING_DISABLED #define debug(msg, ...) report(report_debug, msg, ##__VA_ARGS__) @@ -53,7 +53,7 @@ extern void report(enum report_type type, char *msg, ...); #define warning(msg, ...) report(report_warning, msg, ##__VA_ARGS__) #define error(msg, ...) report(report_error, msg, ##__VA_ARGS__) -extern void ATTR_NORET die(int status, char *msg, ...); +extern void ATTR_NORET die(int status, const char *msg, ...); #endif diff --git a/src/invoker/CMakeLists.txt b/src/invoker/CMakeLists.txt index d35f1a8..ecb3272 100644 --- a/src/invoker/CMakeLists.txt +++ b/src/invoker/CMakeLists.txt @@ -1,8 +1,10 @@ +set(COMMON "${CMAKE_HOME_DIRECTORY}/src/common") + # Set sources -set(SRC invokelib.c invoker.c report.c search.c) +set(SRC invokelib.c invoker.c ${COMMON}/report.c search.c) # Set include dirs -include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_HOME_DIRECTORY}/src/common) +include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${COMMON}) # Set precompiler flags add_definitions(-DPROG_NAME_INVOKER="invoker") diff --git a/src/single-instance/CMakeLists.txt b/src/single-instance/CMakeLists.txt index 52ef44f..18ce2f0 100644 --- a/src/single-instance/CMakeLists.txt +++ b/src/single-instance/CMakeLists.txt @@ -1,11 +1,13 @@ +set(COMMON "${CMAKE_HOME_DIRECTORY}/src/common") + # Set sources -set(SRC main.cpp) +set(SRC main.cpp ${COMMON}/report.c) # Find X11 pkg_check_modules(X11 x11 REQUIRED) # Set include dirs -include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${X11_INCLUDE_DIRS}) +include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${X11_INCLUDE_DIRS} ${COMMON}) # Hide all symbols except the ones explicitly exported in the code (like main()) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden -fPIC") @@ -13,8 +15,8 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden -fPIC") # Link as position independent executable set(CMAKE_EXE_LINKER_FLAGS "-pie -rdynamic") -# Set C++ flags -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") +# Set C flags because of report.c +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden -fPIC") # Set link libraries link_libraries(${X11_LDFLAGS}) diff --git a/src/single-instance/main.cpp b/src/single-instance/main.cpp index 5acf748..67a0082 100644 --- a/src/single-instance/main.cpp +++ b/src/single-instance/main.cpp @@ -30,6 +30,9 @@ #include #include #include +extern "C" { + #include "report.h" +} #define DECL_EXPORT extern "C" __attribute__ ((__visibility__("default"))) @@ -55,8 +58,7 @@ static bool mkpath(const std::string & path) // are modified by umask if (chmod(part.c_str(), 0777) == -1) { - std::cerr << "ERROR!!: chmod() failed: " << - strerror(errno) << std::endl; + report(report_error, "chmod() failed: %s \n", strerror(errno)); return false; } } @@ -70,7 +72,7 @@ int handleXError(Display *dpy, XErrorEvent *e) { char errorText[1024]; XGetErrorText( dpy, e->error_code, errorText, sizeof(errorText) ); - std::cerr << ( "X ERROR!!: %s\n", errorText ); + report(report_error, "Xerror: %s\n", errorText ); return 0; } @@ -115,7 +117,7 @@ static int clientMsg(Display *disp, Window win, const char *msg, } else { - std::cerr << "ERROR!!: Cannot send " << msg << " event." << std::endl; + report(report_error, "Cannot send %s event.\n", msg); return EXIT_FAILURE; } } @@ -268,8 +270,7 @@ extern "C" std::string path(LOCK_PATH_BASE + binaryName); if (!mkpath(path)) { - std::cerr << "ERROR!!: Couldn't create dir " << - path << std::endl; + report(report_error, "Couldn't create dir %s\n", path.c_str()); return false; } @@ -285,8 +286,8 @@ extern "C" if((g_lockFd = open(path.c_str(), O_WRONLY | O_CREAT, 0666)) == -1) { - std::cerr << "ERROR!!: Couldn't create/open lock file '" << - path << "' : " << strerror(errno) << std::endl; + report(report_error, "Couldn't create/open lock file '%s' : %s\n", + path.c_str(), strerror(errno)); return false; } @@ -322,14 +323,14 @@ extern "C" } else { - std::cerr << "ERROR!!: Lock reserved but no window id for binary name found." << std::endl; + report(report_error, "Lock reserved but no window id for binary name found.\n"); XCloseDisplay(dpy); return false; } } else { - std::cerr << "ERROR!!: Failed to open display!" << std::endl; + report(report_error, "Failed to open display!\n"); return false; } } @@ -364,8 +365,7 @@ int main(int argc, char **argv) { if (execve(argv[1], argv + 1, environ) == -1) { - std::cerr << "ERROR!!: Failed to exec binary '" << - argv[1] << "' : " << strerror(errno) << std::endl; + report(report_error, "Failed to exec binary '%s' : %s\n", argv[1], strerror(errno)); unlock(); return EXIT_FAILURE;