Fix OpenBSD build (#2080)
- Fix unclosed OBJ in core.cc when target is OpenBSD - `to_real_path` changes: - Canonicalize result to mimic `realpath` behavior - Partially implement `to_real_path` for OpenBSD - Add more tests for `to_real_path`. - Build system improvements: - Use same i18n include/link logic for all platforms - Replace `HAVE_SOME_SOUNDCARD_H` and `HAVE_LINUX_SOUNDCARD_H` with `HAVE_SOUNDCARD_H` and use other defines (__linux__) to guard include - Replace `<XXX>_LIBRARIES` with `<XXX>_LINK_LIBRARIES` for linking. - Libraries weren't in default linker search path on OpenBSD - OpenBSD specific: - Fix bsdapm.cc - Remove diskio stats stubs - Stub get_battery_short_status - Remove `-stdlib=libc++` build flag on OpenBSD Signed-off-by: Tin Švagelj <tin.svagelj@live.com> Co-authored-by: gmb <gmb@openbsd76.my.domain> Co-authored-by: Tin Švagelj <tin.svagelj@live.com>
This commit is contained in:
5
3rdparty/Vc/Vc/scalar/math.h
vendored
5
3rdparty/Vc/Vc/scalar/math.h
vendored
@@ -115,7 +115,12 @@ template<> Vc_ALWAYS_INLINE void sincos(const Scalar::Vector<double> &x, Scalar:
|
|||||||
#elif Vc_HAS_BUILTIN(__builtin_sincos) || defined Vc_GCC
|
#elif Vc_HAS_BUILTIN(__builtin_sincos) || defined Vc_GCC
|
||||||
__builtin_sincos(x.data(), &sin->data(), &cos->data());
|
__builtin_sincos(x.data(), &sin->data(), &cos->data());
|
||||||
#else
|
#else
|
||||||
|
#if defined(__OpenBSD__)
|
||||||
|
sin->data() = ::sin(x.data());
|
||||||
|
cos->data() = ::cos(x.data());
|
||||||
|
#else /* OpenBSD */
|
||||||
::sincos(x.data(), &sin->data(), &cos->data());
|
::sincos(x.data(), &sin->data(), &cos->data());
|
||||||
|
#endif /* OpenBSD */
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -96,13 +96,13 @@ set(conky_includes ${CMAKE_BINARY_DIR})
|
|||||||
# enabled! Thus disable this and _LARGEFILE64_SOURCE isnt needed, it is already
|
# enabled! Thus disable this and _LARGEFILE64_SOURCE isnt needed, it is already
|
||||||
# used on macOS.
|
# used on macOS.
|
||||||
#
|
#
|
||||||
if(NOT OS_DARWIN)
|
if(NOT OS_DARWIN AND NOT OS_OPENBSD)
|
||||||
add_definitions(-D_LARGEFILE64_SOURCE -D_POSIX_C_SOURCE=200809L) # Standard definitions
|
add_definitions(-D_LARGEFILE64_SOURCE -D_POSIX_C_SOURCE=200809L) # Standard definitions
|
||||||
set(
|
set(
|
||||||
CMAKE_REQUIRED_DEFINITIONS
|
CMAKE_REQUIRED_DEFINITIONS
|
||||||
"${CMAKE_REQUIRED_DEFINITIONS} -D_LARGEFILE64_SOURCE -D_POSIX_C_SOURCE=200809L"
|
"${CMAKE_REQUIRED_DEFINITIONS} -D_LARGEFILE64_SOURCE -D_POSIX_C_SOURCE=200809L"
|
||||||
)
|
)
|
||||||
endif(NOT OS_DARWIN)
|
endif(NOT OS_DARWIN AND NOT OS_OPENBSD)
|
||||||
|
|
||||||
if(OS_FREEBSD)
|
if(OS_FREEBSD)
|
||||||
add_definitions(-D__BSD_VISIBLE=1 -D_XOPEN_SOURCE=700)
|
add_definitions(-D__BSD_VISIBLE=1 -D_XOPEN_SOURCE=700)
|
||||||
@@ -117,6 +117,15 @@ if(OS_DRAGONFLY)
|
|||||||
set(conky_includes ${conky_includes} -I/usr/pkg/include)
|
set(conky_includes ${conky_includes} -I/usr/pkg/include)
|
||||||
endif(OS_DRAGONFLY)
|
endif(OS_DRAGONFLY)
|
||||||
|
|
||||||
|
if(OS_OPENBSD)
|
||||||
|
# For asprintf
|
||||||
|
add_definitions(-D_GNU_SOURCE) # Standard definitions
|
||||||
|
set(
|
||||||
|
CMAKE_REQUIRED_DEFINITIONS
|
||||||
|
"${CMAKE_REQUIRED_DEFINITIONS} -D_GNU_SOURCE"
|
||||||
|
)
|
||||||
|
endif(OS_OPENBSD)
|
||||||
|
|
||||||
if(OS_SOLARIS)
|
if(OS_SOLARIS)
|
||||||
set(conky_libs ${conky_libs} -L/usr/local/lib)
|
set(conky_libs ${conky_libs} -L/usr/local/lib)
|
||||||
endif(OS_SOLARIS)
|
endif(OS_SOLARIS)
|
||||||
|
@@ -50,12 +50,17 @@ if(MAINTAINER_MODE)
|
|||||||
set(BUILD_TESTS true)
|
set(BUILD_TESTS true)
|
||||||
endif(MAINTAINER_MODE)
|
endif(MAINTAINER_MODE)
|
||||||
|
|
||||||
|
if(NOT OS_OPENBSD)
|
||||||
# Always use libc++ when compiling w/ clang
|
# Always use libc++ when compiling w/ clang
|
||||||
|
# Not on OpenBSD because that's the default for its vendored Clang
|
||||||
|
add_compile_options(
|
||||||
|
$<$<COMPILE_LANG_AND_ID:CXX,Clang>:-stdlib=libc++>)
|
||||||
|
add_link_options($<$<COMPILE_LANG_AND_ID:CXX,Clang>:-stdlib=libc++>)
|
||||||
|
endif(NOT OS_OPENBSD)
|
||||||
|
|
||||||
add_compile_options(
|
add_compile_options(
|
||||||
$<$<COMPILE_LANG_AND_ID:CXX,Clang>:-stdlib=libc++>
|
|
||||||
$<$<COMPILE_LANG_AND_ID:CXX,Clang>:-Wno-unknown-warning-option>
|
$<$<COMPILE_LANG_AND_ID:CXX,Clang>:-Wno-unknown-warning-option>
|
||||||
$<$<COMPILE_LANG_AND_ID:CXX,GCC>:-Wno-unknown-warning>)
|
$<$<COMPILE_LANG_AND_ID:CXX,GCC>:-Wno-unknown-warning>)
|
||||||
add_link_options($<$<COMPILE_LANG_AND_ID:CXX,Clang>:-stdlib=libc++>)
|
|
||||||
|
|
||||||
option(CHECK_CODE_QUALITY "Check code formatting/quality with clang" false)
|
option(CHECK_CODE_QUALITY "Check code formatting/quality with clang" false)
|
||||||
|
|
||||||
@@ -228,6 +233,8 @@ dependent_option(BUILD_LUA_RSVG "Build rsvg bindings for Lua" false
|
|||||||
"BUILD_GUI" false
|
"BUILD_GUI" false
|
||||||
"RSVG Lua bindings depend on BUILD_GUI")
|
"RSVG Lua bindings depend on BUILD_GUI")
|
||||||
|
|
||||||
|
option(BUILD_OPENSOUNDSYS "Build with Open Sound System support" true)
|
||||||
|
|
||||||
option(BUILD_AUDACIOUS "Build audacious (music player) support" false)
|
option(BUILD_AUDACIOUS "Build audacious (music player) support" false)
|
||||||
|
|
||||||
option(BUILD_MPD "Enable if you want MPD (music player) support" true)
|
option(BUILD_MPD "Enable if you want MPD (music player) support" true)
|
||||||
|
@@ -65,7 +65,7 @@ endif(CMAKE_SYSTEM_NAME MATCHES "Linux")
|
|||||||
|
|
||||||
if(CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
|
if(CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
|
||||||
set(OS_FREEBSD true)
|
set(OS_FREEBSD true)
|
||||||
set(conky_libs ${conky_libs} -lkvm -ldevstat -lintl -linotify)
|
set(conky_libs ${conky_libs} -lkvm -ldevstat -linotify)
|
||||||
|
|
||||||
if(BUILD_IRC)
|
if(BUILD_IRC)
|
||||||
set(conky_libs ${conky_libs} -lssl -lcrypto)
|
set(conky_libs ${conky_libs} -lssl -lcrypto)
|
||||||
@@ -83,6 +83,7 @@ endif(CMAKE_SYSTEM_NAME MATCHES "DragonFly")
|
|||||||
|
|
||||||
if(CMAKE_SYSTEM_NAME MATCHES "OpenBSD")
|
if(CMAKE_SYSTEM_NAME MATCHES "OpenBSD")
|
||||||
set(OS_OPENBSD true)
|
set(OS_OPENBSD true)
|
||||||
|
set(conky_libs ${conky_libs} -lkvm)
|
||||||
else(CMAKE_SYSTEM_NAME MATCHES "OpenBSD")
|
else(CMAKE_SYSTEM_NAME MATCHES "OpenBSD")
|
||||||
set(OS_OPENBSD false)
|
set(OS_OPENBSD false)
|
||||||
endif(CMAKE_SYSTEM_NAME MATCHES "OpenBSD")
|
endif(CMAKE_SYSTEM_NAME MATCHES "OpenBSD")
|
||||||
@@ -102,7 +103,7 @@ endif(CMAKE_SYSTEM_NAME MATCHES "NetBSD")
|
|||||||
|
|
||||||
if(CMAKE_SYSTEM_NAME MATCHES "Haiku")
|
if(CMAKE_SYSTEM_NAME MATCHES "Haiku")
|
||||||
set(OS_HAIKU true)
|
set(OS_HAIKU true)
|
||||||
set(conky_libs ${conky_libs} -lnetwork -lintl)
|
set(conky_libs ${conky_libs} -lnetwork)
|
||||||
else(CMAKE_SYSTEM_NAME MATCHES "Haiku")
|
else(CMAKE_SYSTEM_NAME MATCHES "Haiku")
|
||||||
set(OS_HAIKU false)
|
set(OS_HAIKU false)
|
||||||
endif(CMAKE_SYSTEM_NAME MATCHES "Haiku")
|
endif(CMAKE_SYSTEM_NAME MATCHES "Haiku")
|
||||||
@@ -145,42 +146,45 @@ endif(NOT
|
|||||||
NOT
|
NOT
|
||||||
OS_DARWIN)
|
OS_DARWIN)
|
||||||
|
|
||||||
# Check for soundcard header
|
|
||||||
if(OS_LINUX)
|
if(OS_LINUX)
|
||||||
check_include_files("linux/soundcard.h" HAVE_SOME_SOUNDCARD_H)
|
|
||||||
check_include_files("linux/soundcard.h" HAVE_LINUX_SOUNDCARD_H)
|
|
||||||
check_include_files("linux/sockios.h" HAVE_LINUX_SOCKIOS_H)
|
check_include_files("linux/sockios.h" HAVE_LINUX_SOCKIOS_H)
|
||||||
elseif(OS_OPENBSD)
|
|
||||||
check_include_files("soundcard.h" HAVE_SOME_SOUNDCARD_H)
|
|
||||||
else(OS_LINUX)
|
|
||||||
check_include_files("sys/soundcard.h" HAVE_SOME_SOUNDCARD_H)
|
|
||||||
endif(OS_LINUX)
|
endif(OS_LINUX)
|
||||||
|
|
||||||
if(BUILD_I18N AND OS_DRAGONFLY)
|
# Handle Open Sound System
|
||||||
set(conky_libs ${conky_libs} -lintl)
|
if(BUILD_OPENSOUNDSYS)
|
||||||
endif(BUILD_I18N AND OS_DRAGONFLY)
|
if(OS_LINUX)
|
||||||
|
check_include_files("linux/soundcard.h" HAVE_SOUNDCARD_H)
|
||||||
|
elseif(OS_OPENBSD)
|
||||||
|
check_include_files("soundcard.h" HAVE_SOUNDCARD_H)
|
||||||
|
# OpenBSD (and FreeBSD?) provide emulation layer on top of sndio.
|
||||||
|
if(HAVE_SOUNDCARD_H)
|
||||||
|
find_library(OSS_AUDIO_LIB
|
||||||
|
NAMES ossaudio
|
||||||
|
PATHS /usr/lib
|
||||||
|
/usr/local/lib)
|
||||||
|
set(conky_libs ${conky_libs} ${OSS_AUDIO_LIB})
|
||||||
|
endif(HAVE_SOUNDCARD_H)
|
||||||
|
else(OS_LINUX)
|
||||||
|
check_include_files("sys/soundcard.h" HAVE_SOUNDCARD_H)
|
||||||
|
endif(OS_LINUX)
|
||||||
|
endif(BUILD_OPENSOUNDSYS)
|
||||||
|
|
||||||
if(BUILD_I18N AND OS_DARWIN)
|
|
||||||
find_path(LIBINTL_H_N libintl.h
|
|
||||||
PATHS /usr/local/opt/gettext/include
|
|
||||||
/usr/include
|
|
||||||
/usr/local/include
|
|
||||||
/usr/local/opt/include)
|
|
||||||
|
|
||||||
if(LIBINTL_H_N)
|
if(BUILD_I18N)
|
||||||
include_directories(${LIBINTL_H_N})
|
include(FindIntl)
|
||||||
else(LIBINTL_H_N)
|
find_package(Intl)
|
||||||
message(FATAL_ERROR "Unable to find libintl.h (try `brew install gettext`)")
|
|
||||||
endif(LIBINTL_H_N)
|
|
||||||
|
|
||||||
find_library(INTL_LIB
|
if(NOT Intl_FOUND)
|
||||||
NAMES intl
|
if(OS_DARWIN)
|
||||||
PATHS /usr/local/opt/gettext/lib
|
message(WARNING "Try running `brew install gettext` for I18N support")
|
||||||
/usr/lib
|
# Should be present by default everywhere else
|
||||||
/usr/local/lib
|
endif(OS_DARWIN)
|
||||||
/usr/local/opt/lib)
|
message(FATAL_ERROR "Unable to find libintl")
|
||||||
set(conky_libs ${conky_libs} ${INTL_LIB})
|
endif(NOT Intl_FOUND)
|
||||||
endif(BUILD_I18N AND OS_DARWIN)
|
|
||||||
|
include_directories(${Intl_INCLUDE_DIRS})
|
||||||
|
set(conky_libs ${conky_libs} ${Intl_LIBRARIES})
|
||||||
|
endif(BUILD_I18N)
|
||||||
|
|
||||||
if(BUILD_NCURSES AND OS_DARWIN)
|
if(BUILD_NCURSES AND OS_DARWIN)
|
||||||
set(conky_libs ${conky_libs} -lncurses)
|
set(conky_libs ${conky_libs} -lncurses)
|
||||||
@@ -239,7 +243,7 @@ endif(BUILD_IPV6)
|
|||||||
|
|
||||||
if(BUILD_HTTP)
|
if(BUILD_HTTP)
|
||||||
pkg_check_modules(MICROHTTPD REQUIRED libmicrohttpd>=0.9.25)
|
pkg_check_modules(MICROHTTPD REQUIRED libmicrohttpd>=0.9.25)
|
||||||
set(conky_libs ${conky_libs} ${MICROHTTPD_LIBRARIES})
|
set(conky_libs ${conky_libs} ${MICROHTTPD_LINK_LIBRARIES})
|
||||||
set(conky_includes ${conky_includes} ${MICROHTTPD_INCLUDE_DIRS})
|
set(conky_includes ${conky_includes} ${MICROHTTPD_INCLUDE_DIRS})
|
||||||
endif(BUILD_HTTP)
|
endif(BUILD_HTTP)
|
||||||
|
|
||||||
@@ -468,28 +472,28 @@ if(BUILD_WAYLAND)
|
|||||||
|
|
||||||
if(OS_DARWIN OR OS_DRAGONFLY OR OS_FREEBSD OR OS_NETBSD OR OS_OPENBSD)
|
if(OS_DARWIN OR OS_DRAGONFLY OR OS_FREEBSD OR OS_NETBSD OR OS_OPENBSD)
|
||||||
pkg_check_modules(EPOLL REQUIRED epoll-shim)
|
pkg_check_modules(EPOLL REQUIRED epoll-shim)
|
||||||
set(conky_libs ${conky_libs} ${EPOLL_LIBRARIES})
|
set(conky_libs ${conky_libs} ${EPOLL_LINK_LIBRARIES})
|
||||||
set(conky_includes ${conky_includes} ${EPOLL_INCLUDE_DIRS})
|
set(conky_includes ${conky_includes} ${EPOLL_INCLUDE_DIRS})
|
||||||
endif(OS_DARWIN OR OS_DRAGONFLY OR OS_FREEBSD OR OS_NETBSD OR OS_OPENBSD)
|
endif(OS_DARWIN OR OS_DRAGONFLY OR OS_FREEBSD OR OS_NETBSD OR OS_OPENBSD)
|
||||||
|
|
||||||
pkg_check_modules(CAIRO REQUIRED cairo)
|
pkg_check_modules(CAIRO REQUIRED cairo)
|
||||||
set(conky_libs ${conky_libs} ${CAIRO_LIBRARIES})
|
set(conky_libs ${conky_libs} ${CAIRO_LINK_LIBRARIES})
|
||||||
set(conky_includes ${conky_includes} ${CAIRO_INCLUDE_DIR})
|
set(conky_includes ${conky_includes} ${CAIRO_INCLUDE_DIR})
|
||||||
|
|
||||||
pkg_check_modules(PANGO REQUIRED pango)
|
pkg_check_modules(PANGO REQUIRED pango)
|
||||||
set(conky_libs ${conky_libs} ${PANGO_LIBRARIES})
|
set(conky_libs ${conky_libs} ${PANGO_LINK_LIBRARIES})
|
||||||
set(conky_includes ${conky_includes} ${PANGO_INCLUDE_DIRS})
|
set(conky_includes ${conky_includes} ${PANGO_INCLUDE_DIRS})
|
||||||
|
|
||||||
pkg_check_modules(PANGOCAIRO pangocairo)
|
pkg_check_modules(PANGOCAIRO pangocairo)
|
||||||
set(conky_libs ${conky_libs} ${PANGOCAIRO_LIBRARIES})
|
set(conky_libs ${conky_libs} ${PANGOCAIRO_LINK_LIBRARIES})
|
||||||
set(conky_includes ${conky_includes} ${PANGOCAIRO_INCLUDE_DIRS})
|
set(conky_includes ${conky_includes} ${PANGOCAIRO_INCLUDE_DIRS})
|
||||||
|
|
||||||
pkg_check_modules(PANGOFC pangofc)
|
pkg_check_modules(PANGOFC pangofc)
|
||||||
set(conky_libs ${conky_libs} ${PANGOFC_LIBRARIES})
|
set(conky_libs ${conky_libs} ${PANGOFC_LINK_LIBRARIES})
|
||||||
set(conky_includes ${conky_includes} ${PANGOFC_INCLUDE_DIRS})
|
set(conky_includes ${conky_includes} ${PANGOFC_INCLUDE_DIRS})
|
||||||
|
|
||||||
pkg_check_modules(PANGOFT2 pangoft2)
|
pkg_check_modules(PANGOFT2 pangoft2)
|
||||||
set(conky_libs ${conky_libs} ${PANGOFT2_LIBRARIES})
|
set(conky_libs ${conky_libs} ${PANGOFT2_LINK_LIBRARIES})
|
||||||
set(conky_includes ${conky_includes} ${PANGOFT2_INCLUDE_DIRS})
|
set(conky_includes ${conky_includes} ${PANGOFT2_INCLUDE_DIRS})
|
||||||
endif(BUILD_WAYLAND)
|
endif(BUILD_WAYLAND)
|
||||||
|
|
||||||
@@ -502,12 +506,12 @@ include_directories(3rdparty/toluapp/include)
|
|||||||
# Check for libraries used by Lua bindings
|
# Check for libraries used by Lua bindings
|
||||||
if(BUILD_LUA_CAIRO)
|
if(BUILD_LUA_CAIRO)
|
||||||
pkg_check_modules(CAIRO REQUIRED cairo>=1.14)
|
pkg_check_modules(CAIRO REQUIRED cairo>=1.14)
|
||||||
set(luacairo_libs ${CAIRO_LIBRARIES} ${LUA_LIBRARIES})
|
set(luacairo_libs ${CAIRO_LINK_LIBRARIES} ${LUA_LIBRARIES})
|
||||||
set(luacairo_includes ${CAIRO_INCLUDE_DIRS} ${LUA_INCLUDE_DIR})
|
set(luacairo_includes ${CAIRO_INCLUDE_DIRS} ${LUA_INCLUDE_DIR})
|
||||||
|
|
||||||
if(BUILD_LUA_CAIRO_XLIB)
|
if(BUILD_LUA_CAIRO_XLIB)
|
||||||
pkg_check_modules(CAIROXLIB REQUIRED cairo-xlib)
|
pkg_check_modules(CAIROXLIB REQUIRED cairo-xlib)
|
||||||
set(luacairo_libs ${CAIROXLIB_LIBRARIES} ${luacairo_libs})
|
set(luacairo_libs ${CAIROXLIB_LINK_LIBRARIES} ${luacairo_libs})
|
||||||
set(luacairo_includes ${CAIROXLIB_INCLUDE_DIRS} ${luacairo_includes})
|
set(luacairo_includes ${CAIROXLIB_INCLUDE_DIRS} ${luacairo_includes})
|
||||||
endif(BUILD_LUA_CAIRO_XLIB)
|
endif(BUILD_LUA_CAIRO_XLIB)
|
||||||
|
|
||||||
@@ -529,7 +533,7 @@ endif(BUILD_LUA_IMLIB2)
|
|||||||
|
|
||||||
if(BUILD_LUA_RSVG)
|
if(BUILD_LUA_RSVG)
|
||||||
pkg_check_modules(RSVG REQUIRED librsvg-2.0>=2.52)
|
pkg_check_modules(RSVG REQUIRED librsvg-2.0>=2.52)
|
||||||
set(luarsvg_libs ${RSVG_LIBRARIES} ${LUA_LIBRARIES})
|
set(luarsvg_libs ${RSVG_LINK_LIBRARIES} ${LUA_LIBRARIES})
|
||||||
set(luarsvg_includes ${RSVG_INCLUDE_DIRS} ${LUA_INCLUDE_DIR})
|
set(luarsvg_includes ${RSVG_INCLUDE_DIRS} ${LUA_INCLUDE_DIR})
|
||||||
endif(BUILD_LUA_RSVG)
|
endif(BUILD_LUA_RSVG)
|
||||||
|
|
||||||
@@ -544,7 +548,7 @@ if(BUILD_AUDACIOUS)
|
|||||||
pkg_check_modules(AUDACIOUS REQUIRED audacious<1.4.0)
|
pkg_check_modules(AUDACIOUS REQUIRED audacious<1.4.0)
|
||||||
endif(NEW_AUDACIOUS_FOUND)
|
endif(NEW_AUDACIOUS_FOUND)
|
||||||
|
|
||||||
set(conky_libs ${conky_libs} ${AUDACIOUS_LIBRARIES} ${DBUS_GLIB_LIBRARIES})
|
set(conky_libs ${conky_libs} ${AUDACIOUS_LINK_LIBRARIES} ${DBUS_GLIB_LIBRARIES})
|
||||||
set(conky_includes
|
set(conky_includes
|
||||||
${conky_includes}
|
${conky_includes}
|
||||||
${AUDACIOUS_INCLUDE_DIRS}
|
${AUDACIOUS_INCLUDE_DIRS}
|
||||||
@@ -553,7 +557,7 @@ endif(BUILD_AUDACIOUS)
|
|||||||
|
|
||||||
if(BUILD_XMMS2)
|
if(BUILD_XMMS2)
|
||||||
pkg_check_modules(XMMS2 REQUIRED xmms2-client>=0.6)
|
pkg_check_modules(XMMS2 REQUIRED xmms2-client>=0.6)
|
||||||
set(conky_libs ${conky_libs} ${XMMS2_LIBRARIES})
|
set(conky_libs ${conky_libs} ${XMMS2_LINK_LIBRARIES})
|
||||||
set(conky_includes ${conky_includes} ${XMMS2_INCLUDE_DIRS})
|
set(conky_includes ${conky_includes} ${XMMS2_INCLUDE_DIRS})
|
||||||
endif(BUILD_XMMS2)
|
endif(BUILD_XMMS2)
|
||||||
|
|
||||||
@@ -593,26 +597,26 @@ endif(BUILD_JOURNAL)
|
|||||||
|
|
||||||
if(BUILD_PULSEAUDIO)
|
if(BUILD_PULSEAUDIO)
|
||||||
pkg_check_modules(PULSEAUDIO REQUIRED libpulse)
|
pkg_check_modules(PULSEAUDIO REQUIRED libpulse)
|
||||||
set(conky_libs ${conky_libs} ${PULSEAUDIO_LIBRARIES})
|
set(conky_libs ${conky_libs} ${PULSEAUDIO_LINK_LIBRARIES})
|
||||||
set(conky_includes ${conky_includes} ${PULSEAUDIO_INCLUDE_DIRS})
|
set(conky_includes ${conky_includes} ${PULSEAUDIO_INCLUDE_DIRS})
|
||||||
endif(BUILD_PULSEAUDIO)
|
endif(BUILD_PULSEAUDIO)
|
||||||
|
|
||||||
if(WANT_CURL)
|
if(WANT_CURL)
|
||||||
pkg_check_modules(CURL REQUIRED libcurl)
|
pkg_check_modules(CURL REQUIRED libcurl)
|
||||||
set(conky_libs ${conky_libs} ${CURL_LIBRARIES})
|
set(conky_libs ${conky_libs} ${CURL_LINK_LIBRARIES})
|
||||||
set(conky_includes ${conky_includes} ${CURL_INCLUDE_DIRS})
|
set(conky_includes ${conky_includes} ${CURL_INCLUDE_DIRS})
|
||||||
endif(WANT_CURL)
|
endif(WANT_CURL)
|
||||||
|
|
||||||
# Common libraries
|
# Common libraries
|
||||||
if(WANT_GLIB)
|
if(WANT_GLIB)
|
||||||
pkg_check_modules(GLIB REQUIRED glib-2.0>=2.36)
|
pkg_check_modules(GLIB REQUIRED glib-2.0>=2.36)
|
||||||
set(conky_libs ${conky_libs} ${GLIB_LIBRARIES})
|
set(conky_libs ${conky_libs} ${GLIB_LINK_LIBRARIES})
|
||||||
set(conky_includes ${conky_includes} ${GLIB_INCLUDE_DIRS})
|
set(conky_includes ${conky_includes} ${GLIB_INCLUDE_DIRS})
|
||||||
endif(WANT_GLIB)
|
endif(WANT_GLIB)
|
||||||
|
|
||||||
if(WANT_CURL)
|
if(WANT_CURL)
|
||||||
pkg_check_modules(CURL REQUIRED libcurl)
|
pkg_check_modules(CURL REQUIRED libcurl)
|
||||||
set(conky_libs ${conky_libs} ${CURL_LIBRARIES})
|
set(conky_libs ${conky_libs} ${CURL_LINK_LIBRARIES})
|
||||||
set(conky_includes ${conky_includes} ${CURL_INCLUDE_DIRS})
|
set(conky_includes ${conky_includes} ${CURL_INCLUDE_DIRS})
|
||||||
endif(WANT_CURL)
|
endif(WANT_CURL)
|
||||||
|
|
||||||
|
@@ -29,8 +29,7 @@
|
|||||||
#cmakedefine HAVE_SYS_INOTIFY_H 1
|
#cmakedefine HAVE_SYS_INOTIFY_H 1
|
||||||
#cmakedefine HAVE_DIRENT_H 1
|
#cmakedefine HAVE_DIRENT_H 1
|
||||||
|
|
||||||
#cmakedefine HAVE_SOME_SOUNDCARD_H 1
|
#cmakedefine HAVE_SOUNDCARD_H 1
|
||||||
#cmakedefine HAVE_LINUX_SOUNDCARD_H 1
|
|
||||||
|
|
||||||
#cmakedefine HAVE_STRNDUP 1
|
#cmakedefine HAVE_STRNDUP 1
|
||||||
|
|
||||||
|
@@ -189,10 +189,10 @@ if(OS_DARWIN)
|
|||||||
endif(OS_DARWIN)
|
endif(OS_DARWIN)
|
||||||
|
|
||||||
# Optional sources
|
# Optional sources
|
||||||
if(HAVE_SOME_SOUNDCARD_H)
|
if(HAVE_SOUNDCARD_H)
|
||||||
set(mixer mixer.cc mixer.h)
|
set(mixer mixer.cc mixer.h)
|
||||||
set(optional_sources ${optional_sources} ${mixer})
|
set(optional_sources ${optional_sources} ${mixer})
|
||||||
endif(HAVE_SOME_SOUNDCARD_H)
|
endif(HAVE_SOUNDCARD_H)
|
||||||
|
|
||||||
if(BUILD_AUDACIOUS)
|
if(BUILD_AUDACIOUS)
|
||||||
set(audacious audacious.cc audacious.h)
|
set(audacious audacious.cc audacious.h)
|
||||||
|
100
src/bsdapm.cc
100
src/bsdapm.cc
@@ -27,15 +27,21 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <machine/apm_bios.h>
|
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "conky.h"
|
#include "conky.h"
|
||||||
#include "text_object.h"
|
#include "text_object.h"
|
||||||
|
|
||||||
#define APMDEV "/dev/apm"
|
#if defined(__OpenBSD__)
|
||||||
#define APM_UNKNOWN 255
|
#include <machine/apmvar.h>
|
||||||
|
#else
|
||||||
|
#include <machine/apm_bios.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
const char *APMDEV = "/dev/apm";
|
||||||
|
const u_int APM_UNKNOWN = 255;
|
||||||
|
|
||||||
#ifndef APM_AC_OFF
|
#ifndef APM_AC_OFF
|
||||||
#define APM_AC_OFF 0
|
#define APM_AC_OFF 0
|
||||||
@@ -49,27 +55,26 @@
|
|||||||
#define APM_BATT_CHARGING 3
|
#define APM_BATT_CHARGING 3
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static int apm_getinfo(int fd, apm_info_t aip) {
|
|
||||||
#ifdef __OpenBSD__
|
#ifdef __OpenBSD__
|
||||||
if (ioctl(fd, APM_IOC_GETPOWER, aip) == -1) {
|
const u_long GET_APM_INFO = APM_IOC_GETPOWER;
|
||||||
|
using apm_info = apm_power_info;
|
||||||
|
#define seconds_left minutes_left * 1000
|
||||||
#else
|
#else
|
||||||
if (ioctl(fd, APMIO_GETINFO, aip) == -1) {
|
const u_long GET_APM_INFO = APMIO_GETINFO;
|
||||||
|
#define ac_state ai_acline
|
||||||
|
#define battery_state ai_batt_stat
|
||||||
|
#define battery_life ai_batt_life
|
||||||
|
#define seconds_left ai_batt_time
|
||||||
#endif
|
#endif
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
static bool apm_getinfo(int fd, apm_info *aip) {
|
||||||
|
return ioctl(fd, GET_APM_INFO, aip) == -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_apm_adapter(struct text_object *obj, char *p,
|
void print_apm_adapter(struct text_object *obj, char *p,
|
||||||
unsigned int p_max_size) {
|
unsigned int p_max_size) {
|
||||||
int fd;
|
int fd;
|
||||||
const char *out;
|
apm_info info;
|
||||||
#ifdef __OpenBSD__
|
|
||||||
struct apm_power_info a_info;
|
|
||||||
#else
|
|
||||||
struct apm_info a_info;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
(void)obj;
|
(void)obj;
|
||||||
|
|
||||||
@@ -79,25 +84,20 @@ void print_apm_adapter(struct text_object *obj, char *p,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (apm_getinfo(fd, &a_info) != 0) {
|
if (!apm_getinfo(fd, &info)) {
|
||||||
close(fd);
|
close(fd);
|
||||||
snprintf(p, p_max_size, "%s", "ERR");
|
snprintf(p, p_max_size, "%s", "ERR");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
||||||
#ifdef __OpenBSD__
|
const char *out;
|
||||||
#define ai_acline ac_state
|
switch (info.ac_state) {
|
||||||
#endif
|
|
||||||
switch (a_info.ai_acline) {
|
|
||||||
case APM_AC_OFF:
|
case APM_AC_OFF:
|
||||||
out = "off-line";
|
out = "off-line";
|
||||||
break;
|
break;
|
||||||
case APM_AC_ON:
|
case APM_AC_ON:
|
||||||
#ifdef __OpenBSD__
|
if (info.battery_state == APM_BATT_CHARGING) {
|
||||||
#define ai_batt_stat battery_state
|
|
||||||
#endif
|
|
||||||
if (a_info.ai_batt_stat == APM_BATT_CHARGING) {
|
|
||||||
out = "charging";
|
out = "charging";
|
||||||
} else {
|
} else {
|
||||||
out = "on-line";
|
out = "on-line";
|
||||||
@@ -113,13 +113,7 @@ void print_apm_adapter(struct text_object *obj, char *p,
|
|||||||
void print_apm_battery_life(struct text_object *obj, char *p,
|
void print_apm_battery_life(struct text_object *obj, char *p,
|
||||||
unsigned int p_max_size) {
|
unsigned int p_max_size) {
|
||||||
int fd;
|
int fd;
|
||||||
u_int batt_life;
|
apm_info info;
|
||||||
const char *out;
|
|
||||||
#ifdef __OpenBSD__
|
|
||||||
struct apm_power_info a_info;
|
|
||||||
#else
|
|
||||||
struct apm_info a_info;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
(void)obj;
|
(void)obj;
|
||||||
|
|
||||||
@@ -129,22 +123,21 @@ void print_apm_battery_life(struct text_object *obj, char *p,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (apm_getinfo(fd, &a_info) != 0) {
|
if (!apm_getinfo(fd, &info)) {
|
||||||
close(fd);
|
close(fd);
|
||||||
snprintf(p, p_max_size, "%s", "ERR");
|
snprintf(p, p_max_size, "%s", "ERR");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
||||||
#ifdef __OpenBSD__
|
if (info.battery_life <= 100) {
|
||||||
#define ai_batt_life battery_life
|
snprintf(p, p_max_size, "%d%%", info.battery_life);
|
||||||
#endif
|
|
||||||
batt_life = a_info.ai_batt_life;
|
|
||||||
if (batt_life == APM_UNKNOWN) {
|
|
||||||
out = "unknown";
|
|
||||||
} else if (batt_life <= 100) {
|
|
||||||
snprintf(p, p_max_size, "%d%%", batt_life);
|
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *out;
|
||||||
|
if (info.battery_life == APM_UNKNOWN) {
|
||||||
|
out = "unknown";
|
||||||
} else {
|
} else {
|
||||||
out = "ERR";
|
out = "ERR";
|
||||||
}
|
}
|
||||||
@@ -155,14 +148,8 @@ void print_apm_battery_life(struct text_object *obj, char *p,
|
|||||||
void print_apm_battery_time(struct text_object *obj, char *p,
|
void print_apm_battery_time(struct text_object *obj, char *p,
|
||||||
unsigned int p_max_size) {
|
unsigned int p_max_size) {
|
||||||
int fd;
|
int fd;
|
||||||
int batt_time;
|
|
||||||
#ifdef __OpenBSD__
|
|
||||||
int h, m;
|
|
||||||
struct apm_power_info a_info;
|
|
||||||
#else
|
|
||||||
int h, m, s;
|
int h, m, s;
|
||||||
struct apm_info a_info;
|
apm_info info;
|
||||||
#endif
|
|
||||||
|
|
||||||
(void)obj;
|
(void)obj;
|
||||||
|
|
||||||
@@ -172,29 +159,17 @@ void print_apm_battery_time(struct text_object *obj, char *p,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (apm_getinfo(fd, &a_info) != 0) {
|
if (!apm_getinfo(fd, &info)) {
|
||||||
close(fd);
|
close(fd);
|
||||||
snprintf(p, p_max_size, "%s", "ERR");
|
snprintf(p, p_max_size, "%s", "ERR");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
||||||
#ifdef __OpenBSD__
|
int batt_time = info.seconds_left;
|
||||||
#define ai_batt_time minutes_left
|
|
||||||
#endif
|
|
||||||
batt_time = a_info.ai_batt_time;
|
|
||||||
|
|
||||||
if (batt_time == -1) {
|
if (batt_time == -1) {
|
||||||
snprintf(p, p_max_size, "%s", "unknown");
|
snprintf(p, p_max_size, "%s", "unknown");
|
||||||
} else
|
} else {
|
||||||
#ifdef __OpenBSD__
|
|
||||||
{
|
|
||||||
h = batt_time / 60;
|
|
||||||
m = batt_time % 60;
|
|
||||||
snprintf(p, p_max_size, "%2d:%02d", h, m);
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
{
|
|
||||||
h = batt_time;
|
h = batt_time;
|
||||||
s = h % 60;
|
s = h % 60;
|
||||||
h /= 60;
|
h /= 60;
|
||||||
@@ -202,5 +177,4 @@ void print_apm_battery_time(struct text_object *obj, char *p,
|
|||||||
h /= 60;
|
h /= 60;
|
||||||
snprintf(p, p_max_size, "%2d:%02d:%02d", h, m, s);
|
snprintf(p, p_max_size, "%2d:%02d:%02d", h, m, s);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
152
src/common.cc
152
src/common.cc
@@ -27,18 +27,23 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "common.h"
|
||||||
|
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <net/if.h>
|
#include <net/if.h>
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
|
#include <pwd.h>
|
||||||
#include <semaphore.h>
|
#include <semaphore.h>
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <cctype>
|
#include <cctype>
|
||||||
#include <cerrno>
|
#include <cerrno>
|
||||||
|
#include <cstdio>
|
||||||
|
#include <cstdlib>
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <wordexp.h>
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "conky.h"
|
#include "conky.h"
|
||||||
#include "core.h"
|
#include "core.h"
|
||||||
@@ -51,6 +56,10 @@
|
|||||||
#include "timeinfo.h"
|
#include "timeinfo.h"
|
||||||
#include "top.h"
|
#include "top.h"
|
||||||
|
|
||||||
|
#if defined(_POSIX_C_SOURCE) && !defined(__OpenBSD__)
|
||||||
|
#include <wordexp.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
/* check for OS and include appropriate headers */
|
/* check for OS and include appropriate headers */
|
||||||
#if defined(__linux__)
|
#if defined(__linux__)
|
||||||
#include "linux.h"
|
#include "linux.h"
|
||||||
@@ -130,21 +139,55 @@ double get_time() {
|
|||||||
return tv.tv_sec + (tv.tv_nsec * 1e-9);
|
return tv.tv_sec + (tv.tv_nsec * 1e-9);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Converts '~/...' paths to '/home/blah/...'. It's similar to
|
#if defined(_POSIX_C_SOURCE) && !defined(__OpenBSD__)
|
||||||
* variable_substitute, works for any enviroment variable */
|
std::filesystem::path to_real_path(const std::string &source) {
|
||||||
std::string to_real_path(const std::string &source) {
|
|
||||||
wordexp_t p;
|
wordexp_t p;
|
||||||
char **w;
|
char **w;
|
||||||
int i;
|
int i;
|
||||||
const char *csource = source.c_str();
|
const char *csource = source.c_str();
|
||||||
if (wordexp(csource, &p, 0) != 0) {
|
if (wordexp(csource, &p, 0) != 0) {
|
||||||
return nullptr;
|
return std::string();
|
||||||
}
|
}
|
||||||
w = p.we_wordv;
|
w = p.we_wordv;
|
||||||
const char *resolved_path = strdup(w[0]);
|
const char *resolved_path = strdup(w[0]);
|
||||||
wordfree(&p);
|
wordfree(&p);
|
||||||
return std::string(resolved_path);
|
return std::filesystem::weakly_canonical(resolved_path);
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
// TODO: Use this implementation once it's finished.
|
||||||
|
// `wordexp` calls shell which is inconsistent across different environments.
|
||||||
|
std::filesystem::path to_real_path(const std::string &source) {
|
||||||
|
/*
|
||||||
|
Wordexp (via default shell) does:
|
||||||
|
- [x] tilde substitution `~`
|
||||||
|
- [x] variable substitution (via `variable_substitute`)
|
||||||
|
- [ ] command substitution `$(command)`
|
||||||
|
- exec.cc does execution already; missing recursive descent parser for
|
||||||
|
$(...) because they can be nested and mixed with self & other expressions
|
||||||
|
from this list
|
||||||
|
- [ ] [arithmetic
|
||||||
|
expansion](https://www.gnu.org/software/bash/manual/html_node/Arithmetic-Expansion.html)
|
||||||
|
`$((10 + 2))`
|
||||||
|
- would be nice to have for other things as well, could possibly use lua and
|
||||||
|
replace stuff like $VAR and $(...) with equivalent functions.
|
||||||
|
- [ ] [field
|
||||||
|
splitting](https://www.gnu.org/software/bash/manual/html_node/Word-Splitting.html)
|
||||||
|
- [ ] wildcard expansion
|
||||||
|
- [ ] quote removal Extra:
|
||||||
|
- canonicalization added
|
||||||
|
*/
|
||||||
|
try {
|
||||||
|
std::string input = tilde_expand(source);
|
||||||
|
std::string expanded = variable_substitute(input);
|
||||||
|
std::filesystem::path absolute = std::filesystem::absolute(expanded);
|
||||||
|
return std::filesystem::weakly_canonical(absolute);
|
||||||
|
} catch (const std::filesystem::filesystem_error &e) {
|
||||||
|
// file not found or permission issues
|
||||||
|
NORM_ERR("can't canonicalize path: %s", source.c_str());
|
||||||
|
return source;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
int open_fifo(const char *file, int *reported) {
|
int open_fifo(const char *file, int *reported) {
|
||||||
int fd = 0;
|
int fd = 0;
|
||||||
@@ -178,6 +221,103 @@ FILE *open_file(const char *file, int *reported) {
|
|||||||
return fp;
|
return fp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::filesystem::path get_cwd() {
|
||||||
|
char *cwd;
|
||||||
|
char buffer[1024];
|
||||||
|
|
||||||
|
// Attempt to get the current working directory
|
||||||
|
cwd = getcwd(buffer, sizeof(buffer));
|
||||||
|
if (cwd == NULL) {
|
||||||
|
const char *error;
|
||||||
|
perror(error);
|
||||||
|
NORM_ERR("can't get conky current working directory: %s", error);
|
||||||
|
DBGP("returning '.' as PWD"); // hope things work out well
|
||||||
|
return std::string(".");
|
||||||
|
}
|
||||||
|
|
||||||
|
return std::string(buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string current_username() {
|
||||||
|
const char *user = std::getenv("USER");
|
||||||
|
|
||||||
|
if (!user) {
|
||||||
|
NORM_ERR(
|
||||||
|
"can't determine current user (USER environment variable not set)");
|
||||||
|
return std::string();
|
||||||
|
}
|
||||||
|
|
||||||
|
return std::string(user);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::optional<std::filesystem::path> user_home(const std::string &username) {
|
||||||
|
if (username == current_username()) {
|
||||||
|
const char *home = std::getenv("HOME");
|
||||||
|
if (home) { return std::filesystem::path(home); }
|
||||||
|
}
|
||||||
|
|
||||||
|
struct passwd *pw = getpwnam(username.c_str());
|
||||||
|
if (!pw) {
|
||||||
|
DBGP(
|
||||||
|
"can't determine HOME directory for user %s (neither w/ HOME nor "
|
||||||
|
"getpwnam)",
|
||||||
|
username.c_str());
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
return std::filesystem::path(pw->pw_dir);
|
||||||
|
}
|
||||||
|
std::optional<std::filesystem::path> user_home() {
|
||||||
|
return user_home(current_username());
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string tilde_expand(const std::string &unexpanded) {
|
||||||
|
if (unexpanded.compare(0, 1, "~") != 0) { return unexpanded; }
|
||||||
|
if (unexpanded.length() == 1) {
|
||||||
|
auto home = user_home();
|
||||||
|
if (home->empty()) {
|
||||||
|
NORM_ERR(
|
||||||
|
"can't expand '~' path because user_home couldn't locate home "
|
||||||
|
"directory");
|
||||||
|
return unexpanded;
|
||||||
|
}
|
||||||
|
return home.value();
|
||||||
|
}
|
||||||
|
char next = unexpanded.at(1);
|
||||||
|
if (next == '/') {
|
||||||
|
auto home = user_home();
|
||||||
|
if (home->empty()) {
|
||||||
|
NORM_ERR(
|
||||||
|
"can't expand '~' path because user_home couldn't locate home "
|
||||||
|
"directory");
|
||||||
|
return unexpanded;
|
||||||
|
}
|
||||||
|
return home.value().string() + unexpanded.substr(1);
|
||||||
|
}
|
||||||
|
if (next == '+') { return get_cwd().string() + unexpanded.substr(2); }
|
||||||
|
// if (next == '-') {
|
||||||
|
// auto oldpwd = std::getenv("OLDPWD");
|
||||||
|
// if (oldpwd == nullptr) {
|
||||||
|
// return unexpanded;
|
||||||
|
// }
|
||||||
|
// return std::string(oldpwd) + unexpanded.substr(2);
|
||||||
|
// }
|
||||||
|
// ~+/-N is tied to bash functionality
|
||||||
|
if (std::isalpha(next)) { // handles ~USERNAME
|
||||||
|
auto name_end = unexpanded.find_first_of('/', 1);
|
||||||
|
std::string name;
|
||||||
|
if (name_end == std::string::npos) {
|
||||||
|
name = unexpanded.substr(1);
|
||||||
|
name_end = unexpanded.length();
|
||||||
|
} else {
|
||||||
|
name = unexpanded.substr(1, name_end - 1);
|
||||||
|
}
|
||||||
|
auto home = user_home(name);
|
||||||
|
if (home->empty()) { return unexpanded; }
|
||||||
|
return home.value().string() + unexpanded.substr(name_end);
|
||||||
|
}
|
||||||
|
return unexpanded;
|
||||||
|
}
|
||||||
|
|
||||||
std::string variable_substitute(std::string s) {
|
std::string variable_substitute(std::string s) {
|
||||||
std::string::size_type pos = 0;
|
std::string::size_type pos = 0;
|
||||||
while ((pos = s.find('$', pos)) != std::string::npos) {
|
while ((pos = s.find('$', pos)) != std::string::npos) {
|
||||||
|
25
src/common.h
25
src/common.h
@@ -29,7 +29,10 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
|
#include <filesystem>
|
||||||
|
#include <optional>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "setting.hh"
|
#include "setting.hh"
|
||||||
#include "text_object.h"
|
#include "text_object.h"
|
||||||
|
|
||||||
@@ -58,11 +61,27 @@ struct process *get_first_process(void);
|
|||||||
void get_cpu_count(void);
|
void get_cpu_count(void);
|
||||||
double get_time(void);
|
double get_time(void);
|
||||||
|
|
||||||
/* Converts '~/...' paths to '/home/blah/...'. It's similar to
|
/// @brief Handles environment variable expansion in paths and canonicalization.
|
||||||
* variable_substitute, works for any enviroment variable */
|
///
|
||||||
std::string to_real_path(const std::string &source);
|
/// Examples:
|
||||||
|
/// - `~/conky` -> `/home/conky_user/conky`
|
||||||
|
/// - `$HOME/conky` -> `/home/conky_user/conky`
|
||||||
|
/// - `$HOME/a/b/../c/../../conky` -> `/home/conky_user/conky`
|
||||||
|
std::filesystem::path to_real_path(const std::string &source);
|
||||||
FILE *open_file(const char *file, int *reported);
|
FILE *open_file(const char *file, int *reported);
|
||||||
int open_fifo(const char *file, int *reported);
|
int open_fifo(const char *file, int *reported);
|
||||||
|
|
||||||
|
/// Returns current working directory of conky.
|
||||||
|
std::filesystem::path get_cwd();
|
||||||
|
/// Returns the username of user/account that started conky.
|
||||||
|
std::string current_username();
|
||||||
|
/// Returns home directory of user with `username`.
|
||||||
|
std::optional<std::filesystem::path> user_home(const std::string &username);
|
||||||
|
/// Returns home directory of user with `current_username`.
|
||||||
|
std::optional<std::filesystem::path> user_home();
|
||||||
|
/// Performs tilde expansion on a path-like string and returns the result.
|
||||||
|
std::string tilde_expand(const std::string &unexpanded);
|
||||||
|
/// Performs variable substitution on a string and returns the result.
|
||||||
std::string variable_substitute(std::string s);
|
std::string variable_substitute(std::string s);
|
||||||
|
|
||||||
void format_seconds(char *buf, unsigned int n, long seconds);
|
void format_seconds(char *buf, unsigned int n, long seconds);
|
||||||
|
@@ -432,8 +432,9 @@ struct text_object *construct_text_object(char *s, const char *arg, long line,
|
|||||||
}
|
}
|
||||||
obj->callbacks.print = &print_acpiacadapter;
|
obj->callbacks.print = &print_acpiacadapter;
|
||||||
obj->callbacks.free = &gen_free_opaque;
|
obj->callbacks.free = &gen_free_opaque;
|
||||||
|
END
|
||||||
#endif /* !__OpenBSD__ */
|
#endif /* !__OpenBSD__ */
|
||||||
END OBJ(freq, nullptr) get_cpu_count();
|
OBJ(freq, nullptr) get_cpu_count();
|
||||||
if ((arg == nullptr) || strlen(arg) >= 3 ||
|
if ((arg == nullptr) || strlen(arg) >= 3 ||
|
||||||
strtol(&arg[0], nullptr, 10) == 0 ||
|
strtol(&arg[0], nullptr, 10) == 0 ||
|
||||||
static_cast<unsigned int>(strtol(&arg[0], nullptr, 10)) >
|
static_cast<unsigned int>(strtol(&arg[0], nullptr, 10)) >
|
||||||
@@ -1246,7 +1247,7 @@ struct text_object *construct_text_object(char *s, const char *arg, long line,
|
|||||||
END OBJ(memwithbuffersgraph, &update_meminfo) scan_graph(obj, arg, 1, FALSE);
|
END OBJ(memwithbuffersgraph, &update_meminfo) scan_graph(obj, arg, 1, FALSE);
|
||||||
obj->callbacks.graphval = &mem_with_buffers_barval;
|
obj->callbacks.graphval = &mem_with_buffers_barval;
|
||||||
#endif /* BUILD_GUI*/
|
#endif /* BUILD_GUI*/
|
||||||
#ifdef HAVE_SOME_SOUNDCARD_H
|
#ifdef HAVE_SOUNDCARD_H
|
||||||
END OBJ(mixer, 0) parse_mixer_arg(obj, arg);
|
END OBJ(mixer, 0) parse_mixer_arg(obj, arg);
|
||||||
obj->callbacks.percentage = &mixer_percentage;
|
obj->callbacks.percentage = &mixer_percentage;
|
||||||
END OBJ(mixerl, 0) parse_mixer_arg(obj, arg);
|
END OBJ(mixerl, 0) parse_mixer_arg(obj, arg);
|
||||||
@@ -1261,7 +1262,7 @@ struct text_object *construct_text_object(char *s, const char *arg, long line,
|
|||||||
obj->callbacks.barval = &mixerr_barval;
|
obj->callbacks.barval = &mixerr_barval;
|
||||||
END OBJ_IF(if_mixer_mute, 0) parse_mixer_arg(obj, arg);
|
END OBJ_IF(if_mixer_mute, 0) parse_mixer_arg(obj, arg);
|
||||||
obj->callbacks.iftest = &check_mixer_muted;
|
obj->callbacks.iftest = &check_mixer_muted;
|
||||||
#endif /* HAVE_SOME_SOUNDCARD_H */
|
#endif /* HAVE_SOUNDCARD_H */
|
||||||
#ifdef BUILD_GUI
|
#ifdef BUILD_GUI
|
||||||
END OBJ(monitor, nullptr) obj->callbacks.print = &print_monitor;
|
END OBJ(monitor, nullptr) obj->callbacks.print = &print_monitor;
|
||||||
END OBJ(monitor_number, nullptr) obj->callbacks.print = &print_monitor_number;
|
END OBJ(monitor_number, nullptr) obj->callbacks.print = &print_monitor_number;
|
||||||
|
@@ -49,6 +49,8 @@
|
|||||||
|
|
||||||
#if defined(__FreeBSD__)
|
#if defined(__FreeBSD__)
|
||||||
#include "freebsd.h"
|
#include "freebsd.h"
|
||||||
|
#elif defined(__OpenBSD__)
|
||||||
|
#include "openbsd.h"
|
||||||
#elif defined(__DragonFly__)
|
#elif defined(__DragonFly__)
|
||||||
#include "dragonfly.h"
|
#include "dragonfly.h"
|
||||||
#elif defined(__HAIKU__)
|
#elif defined(__HAIKU__)
|
||||||
|
@@ -124,9 +124,9 @@ static void print_version() {
|
|||||||
#ifdef BUILD_IMLIB2
|
#ifdef BUILD_IMLIB2
|
||||||
<< _(" * Imlib2\n")
|
<< _(" * Imlib2\n")
|
||||||
#endif /* BUILD_IMLIB2 */
|
#endif /* BUILD_IMLIB2 */
|
||||||
#ifdef HAVE_SOME_SOUNDCARD_H
|
#ifdef HAVE_SOUNDCARD_H
|
||||||
<< _(" * OSS mixer support\n")
|
<< _(" * OSS mixer support\n")
|
||||||
#endif /* HAVE_SOME_SOUNDCARD_H */
|
#endif /* HAVE_SOUNDCARD_H */
|
||||||
#ifdef BUILD_MIXER_ALSA
|
#ifdef BUILD_MIXER_ALSA
|
||||||
<< _(" * ALSA mixer support\n")
|
<< _(" * ALSA mixer support\n")
|
||||||
#endif /* BUILD_MIXER_ALSA */
|
#endif /* BUILD_MIXER_ALSA */
|
||||||
|
10
src/mixer.cc
10
src/mixer.cc
@@ -36,15 +36,15 @@
|
|||||||
#include "specials.h"
|
#include "specials.h"
|
||||||
#include "text_object.h"
|
#include "text_object.h"
|
||||||
|
|
||||||
#ifdef HAVE_LINUX_SOUNDCARD_H
|
#ifdef HAVE_SOUNDCARD_H
|
||||||
|
#if defined(__linux__)
|
||||||
#include <linux/soundcard.h>
|
#include <linux/soundcard.h>
|
||||||
#else
|
#elif defined(__OpenBSD__)
|
||||||
#ifdef __OpenBSD__
|
|
||||||
#include <soundcard.h>
|
#include <soundcard.h>
|
||||||
#else
|
#else
|
||||||
#include <sys/soundcard.h>
|
#include <sys/soundcard.h>
|
||||||
#endif /* __OpenBSD__ */
|
#endif
|
||||||
#endif /* HAVE_LINUX_SOUNDCARD_H */
|
#endif /* HAVE_SOUNDCARD_H */
|
||||||
|
|
||||||
#if defined(__sun)
|
#if defined(__sun)
|
||||||
#include <stropts.h>
|
#include <stropts.h>
|
||||||
|
@@ -28,11 +28,11 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <kvm.h>
|
#include <kvm.h>
|
||||||
#include <sys/dkstat.h>
|
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
#include <sys/malloc.h>
|
#include <sys/malloc.h>
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
#include <sys/resource.h>
|
#include <sys/resource.h>
|
||||||
|
#include <sys/proc.h>
|
||||||
#include <sys/sensors.h>
|
#include <sys/sensors.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <sys/swap.h>
|
#include <sys/swap.h>
|
||||||
@@ -62,6 +62,7 @@
|
|||||||
#include "logging.h"
|
#include "logging.h"
|
||||||
#include "net_stat.h"
|
#include "net_stat.h"
|
||||||
#include "openbsd.h"
|
#include "openbsd.h"
|
||||||
|
#include "temphelper.h"
|
||||||
#include "top.h"
|
#include "top.h"
|
||||||
|
|
||||||
#define MAXSHOWDEVS 16
|
#define MAXSHOWDEVS 16
|
||||||
@@ -69,6 +70,13 @@
|
|||||||
#define LOG1024 10
|
#define LOG1024 10
|
||||||
#define pagetok(size) ((size) << pageshift)
|
#define pagetok(size) ((size) << pageshift)
|
||||||
|
|
||||||
|
#define CP_USER 0
|
||||||
|
#define CP_NICE 1
|
||||||
|
#define CP_SYS 2
|
||||||
|
#define CP_INTR 3
|
||||||
|
#define CP_IDLE 4
|
||||||
|
#define CPUSTATES 5
|
||||||
|
|
||||||
inline void proc_find_top(struct process **cpu, struct process **mem);
|
inline void proc_find_top(struct process **cpu, struct process **mem);
|
||||||
|
|
||||||
static short cpu_setup = 0;
|
static short cpu_setup = 0;
|
||||||
@@ -103,7 +111,7 @@ static int swapmode(int *used, int *total) {
|
|||||||
nswap = swapctl(SWAP_NSWAP, 0, 0);
|
nswap = swapctl(SWAP_NSWAP, 0, 0);
|
||||||
if (nswap == 0) { return 0; }
|
if (nswap == 0) { return 0; }
|
||||||
|
|
||||||
swdev = malloc(nswap * sizeof(*swdev));
|
swdev = (struct swapent *)malloc(nswap * sizeof(*swdev));
|
||||||
if (swdev == nullptr) { return 0; }
|
if (swdev == nullptr) { return 0; }
|
||||||
|
|
||||||
rnswap = swapctl(SWAP_STATS, swdev, nswap);
|
rnswap = swapctl(SWAP_STATS, swdev, nswap);
|
||||||
@@ -132,7 +140,7 @@ int check_mount(struct text_object *obj) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void update_uptime() {
|
int update_uptime() {
|
||||||
int mib[2] = {CTL_KERN, KERN_BOOTTIME};
|
int mib[2] = {CTL_KERN, KERN_BOOTTIME};
|
||||||
struct timeval boottime;
|
struct timeval boottime;
|
||||||
time_t now;
|
time_t now;
|
||||||
@@ -146,9 +154,11 @@ void update_uptime() {
|
|||||||
NORM_ERR("Could not get uptime");
|
NORM_ERR("Could not get uptime");
|
||||||
info.uptime = 0;
|
info.uptime = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void update_meminfo() {
|
int update_meminfo() {
|
||||||
static int mib[2] = {CTL_VM, VM_METER};
|
static int mib[2] = {CTL_VM, VM_METER};
|
||||||
struct vmtotal vmtotal;
|
struct vmtotal vmtotal;
|
||||||
size_t size;
|
size_t size;
|
||||||
@@ -185,9 +195,11 @@ void update_meminfo() {
|
|||||||
info.swap = 0;
|
info.swap = 0;
|
||||||
info.swapfree = 0;
|
info.swapfree = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void update_net_stats() {
|
int update_net_stats() {
|
||||||
struct net_stat *ns;
|
struct net_stat *ns;
|
||||||
double delta;
|
double delta;
|
||||||
long long r, t, last_recv, last_trans;
|
long long r, t, last_recv, last_trans;
|
||||||
@@ -196,9 +208,9 @@ void update_net_stats() {
|
|||||||
|
|
||||||
/* get delta */
|
/* get delta */
|
||||||
delta = current_update_time - last_update_time;
|
delta = current_update_time - last_update_time;
|
||||||
if (delta <= 0.0001) { return; }
|
if (delta <= 0.0001) { return 0; }
|
||||||
|
|
||||||
if (getifaddrs(&ifap) < 0) { return; }
|
if (getifaddrs(&ifap) < 0) { return 0; }
|
||||||
|
|
||||||
for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
|
for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
|
||||||
ns = get_net_stat((const char *)ifa->ifa_name, nullptr, NULL);
|
ns = get_net_stat((const char *)ifa->ifa_name, nullptr, NULL);
|
||||||
@@ -249,33 +261,36 @@ void update_net_stats() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
freeifaddrs(ifap);
|
freeifaddrs(ifap);
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int update_total_processes() {
|
int update_total_processes() {
|
||||||
int n_processes;
|
int n_processes;
|
||||||
|
|
||||||
kvm_init();
|
kvm_init();
|
||||||
kvm_getprocs(kd, KERN_PROC_ALL, 0, &n_processes);
|
kvm_getprocs(kd, KERN_PROC_ALL, 0, sizeof(struct kinfo_proc), &n_processes);
|
||||||
|
|
||||||
info.procs = n_processes;
|
info.procs = n_processes;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void update_running_processes() {
|
int update_running_processes() {
|
||||||
struct kinfo_proc2 *p;
|
struct kinfo_proc *p;
|
||||||
int n_processes;
|
int n_processes;
|
||||||
int i, cnt = 0;
|
int i, cnt = 0;
|
||||||
|
|
||||||
kvm_init();
|
kvm_init();
|
||||||
int max_size = sizeof(struct kinfo_proc2);
|
int max_size = sizeof(struct kinfo_proc);
|
||||||
|
|
||||||
p = kvm_getproc2(kd, KERN_PROC_ALL, 0, max_size, &n_processes);
|
p = kvm_getprocs(kd, KERN_PROC_ALL, 0, max_size, &n_processes);
|
||||||
for (i = 0; i < n_processes; i++) {
|
for (i = 0; i < n_processes; i++) {
|
||||||
if (p[i].p_stat == SRUN) { cnt++; }
|
if (p[i].p_stat == SRUN) { cnt++; }
|
||||||
}
|
}
|
||||||
|
|
||||||
info.run_procs = cnt;
|
info.run_procs = cnt;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* new SMP code can be enabled by commenting the following line */
|
/* new SMP code can be enabled by commenting the following line */
|
||||||
@@ -309,7 +324,7 @@ void get_cpu_count() {
|
|||||||
#endif
|
#endif
|
||||||
info.cpu_count = cpu_count;
|
info.cpu_count = cpu_count;
|
||||||
|
|
||||||
info.cpu_usage = malloc(info.cpu_count * sizeof(float));
|
info.cpu_usage = (float *)malloc(info.cpu_count * sizeof(float));
|
||||||
if (info.cpu_usage == nullptr) { CRIT_ERR("malloc"); }
|
if (info.cpu_usage == nullptr) { CRIT_ERR("malloc"); }
|
||||||
|
|
||||||
#ifndef OLDCPU
|
#ifndef OLDCPU
|
||||||
@@ -321,7 +336,7 @@ void get_cpu_count() {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void update_cpu_usage() {
|
int update_cpu_usage() {
|
||||||
#ifdef OLDCPU
|
#ifdef OLDCPU
|
||||||
int mib[2] = {CTL_KERN, KERN_CPTIME};
|
int mib[2] = {CTL_KERN, KERN_CPTIME};
|
||||||
long used, total;
|
long used, total;
|
||||||
@@ -401,12 +416,14 @@ void update_cpu_usage() {
|
|||||||
oldtotal[i] = total;
|
oldtotal[i] = total;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void free_cpu(struct text_object *) { /* no-op */
|
void free_cpu(struct text_object *) { /* no-op */
|
||||||
}
|
}
|
||||||
|
|
||||||
void update_load_average() {
|
int update_load_average() {
|
||||||
double v[3];
|
double v[3];
|
||||||
|
|
||||||
getloadavg(v, 3);
|
getloadavg(v, 3);
|
||||||
@@ -414,8 +431,11 @@ void update_load_average() {
|
|||||||
info.loadavg[0] = (float)v[0];
|
info.loadavg[0] = (float)v[0];
|
||||||
info.loadavg[1] = (float)v[1];
|
info.loadavg[1] = (float)v[1];
|
||||||
info.loadavg[2] = (float)v[2];
|
info.loadavg[2] = (float)v[2];
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define MAXSENSORDEVICES 128
|
||||||
#define OBSD_MAX_SENSORS 256
|
#define OBSD_MAX_SENSORS 256
|
||||||
static struct obsd_sensors_struct {
|
static struct obsd_sensors_struct {
|
||||||
int device;
|
int device;
|
||||||
@@ -428,7 +448,7 @@ static conky::simple_config_setting<int> sensor_device("sensor_device", 0,
|
|||||||
false);
|
false);
|
||||||
|
|
||||||
/* read sensors from sysctl */
|
/* read sensors from sysctl */
|
||||||
void update_obsd_sensors() {
|
int update_obsd_sensors() {
|
||||||
int sensor_cnt, dev, numt, mib[5] = {CTL_HW, HW_SENSORS, 0, 0, 0};
|
int sensor_cnt, dev, numt, mib[5] = {CTL_HW, HW_SENSORS, 0, 0, 0};
|
||||||
struct sensor sensor;
|
struct sensor sensor;
|
||||||
struct sensordev sensordev;
|
struct sensordev sensordev;
|
||||||
@@ -446,10 +466,11 @@ void update_obsd_sensors() {
|
|||||||
mib[2] = dev;
|
mib[2] = dev;
|
||||||
if (sysctl(mib, 3, &sensordev, &sdlen, nullptr, 0) == -1) {
|
if (sysctl(mib, 3, &sensordev, &sdlen, nullptr, 0) == -1) {
|
||||||
if (errno != ENOENT) { warn("sysctl"); }
|
if (errno != ENOENT) { warn("sysctl"); }
|
||||||
return;
|
return 0;
|
||||||
// continue;
|
// continue;
|
||||||
}
|
}
|
||||||
for (type = 0; type < SENSOR_MAX_TYPES; type++) {
|
for (int t = 0; t < SENSOR_MAX_TYPES; t++) {
|
||||||
|
type = (enum sensor_type) t;
|
||||||
mib[3] = type;
|
mib[3] = type;
|
||||||
for (numt = 0; numt < sensordev.maxnumt[type]; numt++) {
|
for (numt = 0; numt < sensordev.maxnumt[type]; numt++) {
|
||||||
mib[4] = numt;
|
mib[4] = numt;
|
||||||
@@ -480,6 +501,8 @@ void update_obsd_sensors() {
|
|||||||
/* } */
|
/* } */
|
||||||
|
|
||||||
init_sensors = 1;
|
init_sensors = 1;
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void parse_obsd_sensor(struct text_object *obj, const char *arg) {
|
void parse_obsd_sensor(struct text_object *obj, const char *arg) {
|
||||||
@@ -491,21 +514,24 @@ void parse_obsd_sensor(struct text_object *obj, const char *arg) {
|
|||||||
obj->data.l = atoi(&arg[0]);
|
obj->data.l = atoi(&arg[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_obsd_sensors_temp(struct text_object *obj, char *p, int p_max_size) {
|
void print_obsd_sensors_temp(struct text_object *obj, char *p,
|
||||||
|
unsigned int p_max_size) {
|
||||||
obsd_sensors.device = sensor_device.get(*state);
|
obsd_sensors.device = sensor_device.get(*state);
|
||||||
update_obsd_sensors();
|
update_obsd_sensors();
|
||||||
temp_print(p, p_max_size, obsd_sensors.temp[obsd_sensors.device][obj->data.l],
|
temp_print(p, p_max_size, obsd_sensors.temp[obsd_sensors.device][obj->data.l],
|
||||||
TEMP_CELSIUS, 1);
|
TEMP_CELSIUS, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_obsd_sensors_fan(struct text_object *obj, char *p, int p_max_size) {
|
void print_obsd_sensors_fan(struct text_object *obj, char *p,
|
||||||
|
unsigned int p_max_size) {
|
||||||
obsd_sensors.device = sensor_device.get(*state);
|
obsd_sensors.device = sensor_device.get(*state);
|
||||||
update_obsd_sensors();
|
update_obsd_sensors();
|
||||||
snprintf(p, p_max_size, "%d",
|
snprintf(p, p_max_size, "%d",
|
||||||
obsd_sensors.fan[obsd_sensors.device][obj->data.l]);
|
obsd_sensors.fan[obsd_sensors.device][obj->data.l]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_obsd_sensors_volt(struct text_object *obj, char *p, int p_max_size) {
|
void print_obsd_sensors_volt(struct text_object *obj, char *p,
|
||||||
|
unsigned int p_max_size) {
|
||||||
obsd_sensors.device = sensor_device.get(*state);
|
obsd_sensors.device = sensor_device.get(*state);
|
||||||
update_obsd_sensors();
|
update_obsd_sensors();
|
||||||
snprintf(p, p_max_size, "%.2f",
|
snprintf(p, p_max_size, "%.2f",
|
||||||
@@ -514,7 +540,7 @@ void print_obsd_sensors_volt(struct text_object *obj, char *p, int p_max_size) {
|
|||||||
|
|
||||||
/* chipset vendor */
|
/* chipset vendor */
|
||||||
void get_obsd_vendor(struct text_object *obj, char *buf,
|
void get_obsd_vendor(struct text_object *obj, char *buf,
|
||||||
size_t client_buffer_size) {
|
unsigned int client_buffer_size) {
|
||||||
int mib[2];
|
int mib[2];
|
||||||
char vendor[64];
|
char vendor[64];
|
||||||
size_t size = sizeof(vendor);
|
size_t size = sizeof(vendor);
|
||||||
@@ -534,7 +560,7 @@ void get_obsd_vendor(struct text_object *obj, char *buf,
|
|||||||
|
|
||||||
/* chipset name */
|
/* chipset name */
|
||||||
void get_obsd_product(struct text_object *obj, char *buf,
|
void get_obsd_product(struct text_object *obj, char *buf,
|
||||||
size_t client_buffer_size) {
|
unsigned int client_buffer_size) {
|
||||||
int mib[2];
|
int mib[2];
|
||||||
char product[64];
|
char product[64];
|
||||||
size_t size = sizeof(product);
|
size_t size = sizeof(product);
|
||||||
@@ -628,38 +654,40 @@ cleanup:
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void clear_diskio_stats() {}
|
int update_diskio() { return 0; /* XXX: implement? hifi: not sure how */ }
|
||||||
|
|
||||||
struct diskio_stat *prepare_diskio_stat(const char *s) {}
|
|
||||||
|
|
||||||
void update_diskio() { return; /* XXX: implement? hifi: not sure how */ }
|
|
||||||
|
|
||||||
/* While topless is obviously better, top is also not bad. */
|
/* While topless is obviously better, top is also not bad. */
|
||||||
|
|
||||||
void get_top_info(void) {
|
void get_top_info(void) {
|
||||||
struct kinfo_proc2 *p;
|
struct kinfo_proc *p;
|
||||||
struct process *proc;
|
struct process *proc;
|
||||||
int n_processes;
|
int n_processes;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
kvm_init();
|
kvm_init();
|
||||||
|
|
||||||
p = kvm_getproc2(kd, KERN_PROC_ALL, 0, sizeof(struct kinfo_proc2),
|
p = kvm_getprocs(kd, KERN_PROC_ALL, 0, sizeof(struct kinfo_proc),
|
||||||
&n_processes);
|
&n_processes);
|
||||||
|
|
||||||
for (i = 0; i < n_processes; i++) {
|
for (i = 0; i < n_processes; i++) {
|
||||||
if (!((p[i].p_flag & P_SYSTEM)) && p[i].p_comm != nullptr) {
|
if (!((p[i].p_flag & P_SYSTEM)) && p[i].p_comm[0] != 0) {
|
||||||
proc = find_process(p[i].p_pid);
|
proc = get_process(p[i].p_pid);
|
||||||
if (!proc) proc = new_process(p[i].p_pid);
|
if (!proc) continue;
|
||||||
|
|
||||||
proc->time_stamp = g_time;
|
proc->time_stamp = g_time;
|
||||||
proc->name = strndup(p[i].p_comm, text_buffer_size);
|
proc->name = strndup(p[i].p_comm, DEFAULT_TEXT_BUFFER_SIZE);
|
||||||
proc->amount = 100.0 * p[i].p_pctcpu / FSCALE;
|
proc->amount = 100.0 * p[i].p_pctcpu / FSCALE;
|
||||||
/* TODO: vsize, rss, total_cpu_time */
|
/* TODO: vsize, rss, total_cpu_time */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void get_battery_short_status(char *buffer, unsigned int n, const char *bat) {
|
||||||
|
/* Not implemented */
|
||||||
|
(void)bat;
|
||||||
|
if (buffer && n > 0) memset(buffer, 0, n);
|
||||||
|
}
|
||||||
|
|
||||||
/* empty stubs so conky links */
|
/* empty stubs so conky links */
|
||||||
void prepare_update() {}
|
void prepare_update() {}
|
||||||
|
|
||||||
|
@@ -7,16 +7,19 @@
|
|||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
#include <sys/sensors.h>
|
#include <sys/sensors.h>
|
||||||
#include <sys/sysctl.h>
|
#include <sys/sysctl.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/mount.h>
|
||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
|
||||||
void parse_obsd_sensor(struct text_object *, const char *);
|
void parse_obsd_sensor(struct text_object *, const char *);
|
||||||
void print_obsd_sensors_temp(struct text_object *, char *, int);
|
void print_obsd_sensors_temp(struct text_object *, char *, unsigned int);
|
||||||
void print_obsd_sensors_fan(struct text_object *, char *, int);
|
void print_obsd_sensors_fan(struct text_object *, char *, unsigned int);
|
||||||
void print_obsd_sensors_volt(struct text_object *, char *, int);
|
void print_obsd_sensors_volt(struct text_object *, char *, unsigned int);
|
||||||
void get_obsd_vendor(struct text_object *, char *buf,
|
void get_obsd_vendor(struct text_object *, char *buf,
|
||||||
size_t client_buffer_size);
|
unsigned int client_buffer_size);
|
||||||
void get_obsd_product(struct text_object *, char *buf,
|
void get_obsd_product(struct text_object *, char *buf,
|
||||||
size_t client_buffer_size);
|
unsigned int client_buffer_size);
|
||||||
|
|
||||||
#if defined(i386) || defined(__i386__)
|
#if defined(i386) || defined(__i386__)
|
||||||
typedef struct apm_power_info *apm_info_t;
|
typedef struct apm_power_info *apm_info_t;
|
||||||
|
@@ -65,7 +65,13 @@ std::string get_invalid_environment_variable_name() {
|
|||||||
return variable_name;
|
return variable_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("to_real_path becomes homedir", "[to_real_path]") {
|
TEST_CASE("to_real_path simplifies complex paths", "[to_real_path]") {
|
||||||
|
REQUIRE(to_real_path("/a/b/c/../d/../../e") == "/a/e");
|
||||||
|
}
|
||||||
|
TEST_CASE("to_real_path resolves variables", "[to_real_path]") {
|
||||||
|
REQUIRE(to_real_path("$HOME/test") == std::string(getenv("HOME")) + "/test");
|
||||||
|
}
|
||||||
|
TEST_CASE("to_real_path resolves `~` symbol", "[to_real_path]") {
|
||||||
REQUIRE(to_real_path("~/test") == std::string(getenv("HOME")) + "/test");
|
REQUIRE(to_real_path("~/test") == std::string(getenv("HOME")) + "/test");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user