diff --git a/.travis.yml b/.travis.yml index 6fd437d91b..2d8101c0e3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,6 +22,22 @@ matrix: - libcairo2-dev - libimlib2-dev - libxinerama-dev + - libmysqlclient-dev + - libical-dev + - libircclient-dev + - libcairo2-dev + - libmicrohttpd-dev + - ncurses-dev + - liblua5.1-dev + - librsvg2-dev + - libaudclient-dev + - libxmmsclient-dev + - libpulse-dev + - libcurl4-gnutls-dev + - audacious-dev + - libsystemd-journal-dev + - libxml2-dev + - tolua++ - gawk env: - MATRIX_EVAL="CC=gcc-8 && CXX=g++-8" @@ -46,6 +62,22 @@ matrix: - libcairo2-dev - libimlib2-dev - libxinerama-dev + - libmysqlclient-dev + - libical-dev + - libircclient-dev + - libcairo2-dev + - libmicrohttpd-dev + - ncurses-dev + - liblua5.1-dev + - librsvg2-dev + - libaudclient-dev + - libxmmsclient-dev + - libpulse-dev + - libcurl4-gnutls-dev + - audacious-dev + - libsystemd-journal-dev + - libxml2-dev + - tolua++ - gawk sonarcloud: organization: "brndnmtthws-github" @@ -57,11 +89,44 @@ before_install: - eval "${MATRIX_EVAL}" before_script: - mkdir build && cd build - - cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON .. + - > + cmake + -DBUILD_MYSQL=ON + -DBUILD_LUA_CAIRO=ON + -DBUILD_LUA_IMLIB2=ON + -DBUILD_LUA_RSVG=ON + -DBUILD_LUA_CAIRO=ON + -DBUILD_AUDACIOUS=ON + -DBUILD_XMMS2=ON + -DBUILD_ICAL=ON + -DBUILD_IRC=ON + -DBUILD_HTTP=ON + -DBUILD_ICONV=ON + -DBUILD_PULSEAUDIO=ON + -DBUILD_JOURNAL=ON + -DBUILD_RSS=ON + .. - cd .. - mkdir build-no-x11 - cd build-no-x11 - - cmake -DBUILD_X11=OFF .. + - > + cmake + -DBUILD_X11=OFF + -DBUILD_MYSQL=ON + -DBUILD_LUA_CAIRO=ON + -DBUILD_LUA_IMLIB2=ON + -DBUILD_LUA_RSVG=ON + -DBUILD_LUA_CAIRO=ON + -DBUILD_AUDACIOUS=ON + -DBUILD_XMMS2=ON + -DBUILD_ICAL=ON + -DBUILD_IRC=ON + -DBUILD_HTTP=ON + -DBUILD_ICONV=ON + -DBUILD_PULSEAUDIO=ON + -DBUILD_JOURNAL=ON + -DBUILD_RSS=ON + .. - cd .. script: - cd build diff --git a/Dockerfile b/Dockerfile index bb3ec60bb9..8e0b21b1dc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,22 +1,71 @@ FROM ubuntu:latest RUN apt-get update \ - && apt-get install -y \ + && DEBIAN_FRONTEND=noninteractive apt-get install -qy \ cmake \ git \ g++ \ libimlib2-dev \ - liblua5.3-dev \ libxext-dev \ libxft-dev \ libxdamage-dev \ libxinerama-dev \ - ncurses-dev + libmysqlclient-dev \ + libical-dev \ + libircclient-dev \ + libcairo2-dev \ + libmicrohttpd-dev \ + ncurses-dev \ + liblua5.1-dev \ + librsvg2-dev \ + libaudclient-dev \ + libxmmsclient-dev \ + libpulse-dev \ + libcurl4-gnutls-dev \ + audacious-dev \ + libsystemd-dev \ + libxml2-dev \ + tolua++ COPY . /conky WORKDIR /conky/build ARG X11=yes -RUN sh -c 'if [ "$X11" = "yes" ] ; then cmake ../ ; else cmake -DBUILD_X11=OFF ../ ; fi' \ +RUN sh -c 'if [ "$X11" = "yes" ] ; then \ + cmake \ + -DBUILD_MYSQL=ON \ + -DBUILD_LUA_CAIRO=ON \ + -DBUILD_LUA_IMLIB2=ON \ + -DBUILD_LUA_RSVG=ON \ + -DBUILD_LUA_CAIRO=ON \ + -DBUILD_AUDACIOUS=ON \ + -DBUILD_XMMS2=ON \ + -DBUILD_ICAL=ON \ + -DBUILD_IRC=ON \ + -DBUILD_HTTP=ON \ + -DBUILD_ICONV=ON \ + -DBUILD_PULSEAUDIO=ON \ + -DBUILD_JOURNAL=ON \ + -DBUILD_RSS=ON \ + ../ \ + ; else \ + cmake \ + -DBUILD_X11=OFF \ + -DBUILD_MYSQL=ON \ + -DBUILD_LUA_CAIRO=ON \ + -DBUILD_LUA_IMLIB2=ON \ + -DBUILD_LUA_RSVG=ON \ + -DBUILD_LUA_CAIRO=ON \ + -DBUILD_AUDACIOUS=ON \ + -DBUILD_XMMS2=ON \ + -DBUILD_ICAL=ON \ + -DBUILD_IRC=ON \ + -DBUILD_HTTP=ON \ + -DBUILD_ICONV=ON \ + -DBUILD_PULSEAUDIO=ON \ + -DBUILD_JOURNAL=ON \ + -DBUILD_RSS=ON \ + ../ \ + ; fi' \ && make -j5 all \ && make -j5 install \ && apt-get remove -y \ @@ -24,12 +73,26 @@ RUN sh -c 'if [ "$X11" = "yes" ] ; then cmake ../ ; else cmake -DBUILD_X11=OFF . git \ g++ \ libimlib2-dev \ - liblua5.3-dev \ libxext-dev \ libxft-dev \ libxdamage-dev \ libxinerama-dev \ + libmysqlclient-dev \ + libical-dev \ + libircclient-dev \ + libcairo2-dev \ + libmicrohttpd-dev \ ncurses-dev \ + liblua5.1-dev \ + librsvg2-dev \ + audacious-dev \ + libaudclient-dev \ + libxmmsclient-dev \ + libpulse-dev \ + libcurl4-gnutls-dev \ + libsystemd-dev \ + libxml2-dev \ + tolua++ \ && rm -rf /var/lib/apt/lists/* \ && rm -rf /conky \ diff --git a/cmake/ConkyBuildOptions.cmake b/cmake/ConkyBuildOptions.cmake index 9ba21f157a..bf89dc15ad 100644 --- a/cmake/ConkyBuildOptions.cmake +++ b/cmake/ConkyBuildOptions.cmake @@ -43,6 +43,8 @@ if(MAINTAINER_MODE) set(CMAKE_CXX_FLAGS_DEBUG "-ggdb -Wall -W -Wextra -Wunused -pedantic -Werror -Wno-format ${CMAKE_CXX_FLAGS_DEBUG}" CACHE STRING "Flags used by the compiler during debug builds." FORCE) endif(MAINTAINER_MODE) +option(CHECK_CODE_QUALITY "Check code formatting/quality with clang" false) + option(RELEASE "Build release package" false) mark_as_advanced(RELEASE) @@ -146,14 +148,14 @@ option(BUILD_MOC "Enable if you want MOC (music player) support" true) option(BUILD_XMMS2 "Enable if you want XMMS2 (music player) support" false) -option(BUILD_EVE "Enable if you want Eve-Online skill monitoring support" false) +option(BUILD_EVE "Enable if you want Eve-Online skill monitoring support" true) option(BUILD_CURL "Enable if you want Curl support" false) option(BUILD_RSS "Enable if you want RSS support" false) -option(BUILD_WEATHER_METAR "Enable METAR weather support" false) -option(BUILD_WEATHER_XOAP "Enable XOAP weather support" false) +option(BUILD_WEATHER_METAR "Enable METAR weather support" true) +option(BUILD_WEATHER_XOAP "Enable XOAP weather support" true) if(BUILD_WEATHER_METAR OR BUILD_WEATHER_XOAP OR BUILD_RSS) set(BUILD_CURL true) endif(BUILD_WEATHER_METAR OR BUILD_WEATHER_XOAP OR BUILD_RSS) @@ -174,10 +176,8 @@ endif(BUILD_HTTP) option(BUILD_ICONV "Enable iconv support" false) -option(BUILD_CMUS "Enable support for cmus music player" false) +option(BUILD_CMUS "Enable support for cmus music player" true) option(BUILD_JOURNAL "Enable support for reading from the systemd journal" false) option(BUILD_PULSEAUDIO "Enable support for Pulseaudio's default sink and source" false) - -option(CHECK_CODE_QUALITY "Check code formatting/quality with clang" false) diff --git a/cmake/ConkyPlatformChecks.cmake b/cmake/ConkyPlatformChecks.cmake index c2fe4f850b..1b2334695f 100644 --- a/cmake/ConkyPlatformChecks.cmake +++ b/cmake/ConkyPlatformChecks.cmake @@ -422,7 +422,7 @@ if(BUILD_IMLIB2) endif(BUILD_IMLIB2) if(BUILD_JOURNAL) - pkg_search_module(SYSTEMD REQUIRED libsystemd) + pkg_search_module(SYSTEMD REQUIRED libsystemd libsystemd-journal) set(conky_libs ${conky_libs} ${SYSTEMD_LIB} ${SYSTEMD_LDFLAGS}) set(conky_includes ${conky_includes} ${SYSTEMD_INCLUDE_PATH}) endif(BUILD_JOURNAL) diff --git a/src/ccurl_thread.h b/src/ccurl_thread.h index f782771713..4131b15c92 100644 --- a/src/ccurl_thread.h +++ b/src/ccurl_thread.h @@ -27,11 +27,13 @@ #include +#include "logging.h" #include "update-cb.hh" namespace priv { // factored out stuff that does not depend on the template parameters -struct curl_internal { +class curl_internal { + public: std::string last_modified; std::string etag; std::string data; @@ -47,7 +49,7 @@ struct curl_internal { // it should populate the result variable virtual void process_data() = 0; - curl_internal(const std::string &url); + explicit curl_internal(const std::string &url); virtual ~curl_internal() { if (curl) curl_easy_cleanup(curl); } @@ -60,7 +62,7 @@ struct curl_internal { */ template class curl_callback : public conky::callback, - protected priv::curl_internal { + public priv::curl_internal { typedef conky::callback Base1; typedef priv::curl_internal Base2; diff --git a/src/journal.cc b/src/journal.cc index d26e0e7a23..b591fb0db3 100644 --- a/src/journal.cc +++ b/src/journal.cc @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include "common.h" @@ -39,8 +40,13 @@ #include "text_object.h" #define MAX_JOURNAL_LINES 200 +#ifndef SD_JOURNAL_SYSTEM +// SD_JOURNAL_SYSTEM added and SD_JOURNAL_SYSTEM_ONLY deprecated in systemd-205 +#define SD_JOURNAL_SYSTEM SD_JOURNAL_SYSTEM_ONLY +#endif /* SD_JOURNAL_SYSTEM */ -struct journal { +class journal { + public: int wantedlines; int flags; @@ -48,7 +54,7 @@ struct journal { }; void free_journal(struct text_object *obj) { - struct journal *j = (struct journal *)obj->data.opaque; + journal *j = (journal *)obj->data.opaque; obj->data.opaque = nullptr; delete j; } @@ -56,7 +62,7 @@ void free_journal(struct text_object *obj) { void init_journal(const char *type, const char *arg, struct text_object *obj, void *free_at_crash) { unsigned int args; - struct journal *j = new journal; + journal *j = new journal; std::unique_ptr tmp(new char[DEFAULT_TEXT_BUFFER_SIZE]); memset(tmp.get(), 0, DEFAULT_TEXT_BUFFER_SIZE); @@ -73,8 +79,10 @@ void init_journal(const char *type, const char *arg, struct text_object *obj, if (args > 1) { if (strcmp(tmp.get(), "system") == 0) { j->flags |= SD_JOURNAL_SYSTEM; +#ifdef SD_JOURNAL_CURRENT_USER // not present in older version of systemd } else if (strcmp(tmp.get(), "user") == 0) { j->flags |= SD_JOURNAL_CURRENT_USER; +#endif /* SD_JOURNAL_CURRENT_USER */ } else { free_journal(obj); CRIT_ERR(obj, free_at_crash, @@ -110,11 +118,37 @@ static int print_field(sd_journal *jh, const char *field, char spacer, return length ? length - fieldlen : 0; } +bool read_log(size_t *read, size_t *length, struct tm *tm, time_t *time, + uint64_t *timestamp, sd_journal *jh, char *p, int p_max_size) { + if (sd_journal_get_realtime_usec(jh, timestamp) < 0) return false; + *time = *timestamp / 1000000; + tm = localtime(time); + + if ((*length = + strftime(p + *read, p_max_size - *read, "%b %d %H:%M:%S", tm)) <= 0) + return false; + *read += *length; + p[*read++] = ' '; + + if (print_field(jh, "_HOSTNAME", ' ', read, p, p_max_size) < 0) return false; + + if (print_field(jh, "SYSLOG_IDENTIFIER", '[', read, p, p_max_size) < 0) + return false; + + if (print_field(jh, "_PID", ']', read, p, p_max_size) < 0) return false; + + p[*read++] = ':'; + p[*read++] = ' '; + + if (print_field(jh, "MESSAGE", '\n', read, p, p_max_size) < 0) return false; + return true; +} + void print_journal(struct text_object *obj, char *p, int p_max_size) { - size_t read = 0, length; struct journal *j = (struct journal *)obj->data.opaque; sd_journal *jh = nullptr; - + size_t read = 0; + size_t length; struct tm *tm; time_t time; uint64_t timestamp; @@ -134,32 +168,11 @@ void print_journal(struct text_object *obj, char *p, int p_max_size) { goto out; } - do { - if (sd_journal_get_realtime_usec(jh, ×tamp) < 0) break; - time = timestamp / 1000000; - tm = localtime(&time); - - if ((length = - strftime(p + read, p_max_size - read, "%b %d %H:%M:%S", tm)) <= 0) - break; - read += length; - p[read++] = ' '; - - if (print_field(jh, "_HOSTNAME", ' ', &read, p, p_max_size) < 0) break; - - if (print_field(jh, "SYSLOG_IDENTIFIER", '[', &read, p, p_max_size) < 0) - break; - - if (print_field(jh, "_PID", ']', &read, p, p_max_size) < 0) break; - - p[read++] = ':'; - p[read++] = ' '; - - if (print_field(jh, "MESSAGE", '\n', &read, p, p_max_size) < 0) break; - } while (sd_journal_next(jh)); + while (read_log(&read, &length, tm, &time, ×tamp, jh, p, p_max_size) && + sd_journal_next(jh)) + ; out: if (jh) sd_journal_close(jh); p[read] = '\0'; - return; } diff --git a/src/mysql.cc b/src/mysql.cc index 89f6e1e822..bcce21acf1 100644 --- a/src/mysql.cc +++ b/src/mysql.cc @@ -26,9 +26,9 @@ * */ -#include "mysql.h" #include "conky.h" #include "logging.h" +#include "mysql.h" #include @@ -44,6 +44,12 @@ conky::simple_config_setting password("mysql_password", conky::simple_config_setting db("mysql_db", "mysql", false); } // namespace +void mysql_finish(MYSQL *conn, MYSQL_RES *res) { + if (nullptr != res) { mysql_free_result(res); } + mysql_close(conn); + mysql_library_end(); +} + void print_mysql(struct text_object *obj, char *p, int p_max_size) { MYSQL *conn = mysql_init(nullptr); MYSQL_RES *res = nullptr; @@ -58,16 +64,19 @@ void print_mysql(struct text_object *obj, char *p, int p_max_size) { password.get(*state).c_str(), db.get(*state).c_str(), port.get(*state), nullptr, 0)) { NORM_ERR("MySQL: %s", mysql_error(conn)); - goto error; + mysql_finish(conn, res); + return; } if (mysql_query(conn, obj->data.s)) { NORM_ERR("MySQL: %s", mysql_error(conn)); - goto error; + mysql_finish(conn, res); + return; } res = mysql_use_result(conn); if (res == nullptr) { NORM_ERR("MySQL: %s", mysql_error(conn)); - goto error; + mysql_finish(conn, res); + return; } MYSQL_ROW row = mysql_fetch_row(res); if (row) { @@ -75,12 +84,5 @@ void print_mysql(struct text_object *obj, char *p, int p_max_size) { } else { NORM_ERR("MySQL: '%s' returned no results", obj->data.s); } - -error: - if (nullptr != res) { - mysql_free_result(res); - } - mysql_close(conn); - mysql_library_end(); - return; + mysql_finish(conn, res); } diff --git a/src/prss.h b/src/prss.h index f3d79553a6..87517c185a 100644 --- a/src/prss.h +++ b/src/prss.h @@ -19,6 +19,7 @@ #define PRSS_H #include +#include typedef struct PRSS_Item_ { char *title; @@ -29,7 +30,8 @@ typedef struct PRSS_Item_ { char *guid; } PRSS_Item; -struct PRSS { +class PRSS { + public: char *version; char *title; @@ -48,7 +50,7 @@ struct PRSS { PRSS_Item *items; int item_count; - PRSS(const std::string &xml_data); + explicit PRSS(const std::string &xml_data); ~PRSS(); }; diff --git a/src/users.cc b/src/users.cc index bf23cab49f..dbb5cf224e 100644 --- a/src/users.cc +++ b/src/users.cc @@ -52,9 +52,7 @@ static void user_num(int *ptr) { setutent(); while ((usr = getutent()) != nullptr) { - if (usr->ut_type == USER_PROCESS) { - ++users_num; - } + if (usr->ut_type == USER_PROCESS) { ++users_num; } } *ptr = users_num; } @@ -97,9 +95,7 @@ static void tty_user_time(char *ptr, char *tty) { setutent(); strcpy(line.ut_line, tty); usr = getutline(&line); - if (usr == nullptr) { - return; - } + if (usr == nullptr) { return; } log_in = usr->ut_time; @@ -159,9 +155,7 @@ int update_users(void) { } user_num(&t); if (t != 0) { - if (current_info->users.number) { - current_info->users.number = 0; - } + if (current_info->users.number) { current_info->users.number = 0; } current_info->users.number = t; } else { current_info->users.number = 0;