Add formatting/static analysis (#486)

* Reform source with clang-format.

Rules applied with:
    $ find . -iname *.h -o -iname *.cc | xargs clang-format \
        -style=file -i -fallback-style=google

* Add clang-format and analyze to build.

Based on the excellent work at: https://github.com/ttroy50/cmake-examples

* Clean up CMake stuff on macOS.

* Remove vim/emacs modelines.

* Update copyright dates.

* Build fixes.

* Build fixes.

* Build fixes.

* Build fixes.

* Build fixes.

* Build fixes.
This commit is contained in:
Brenden Matthews
2018-05-12 12:03:00 -04:00
committed by GitHub
parent b20d83b747
commit eebc8c653b
180 changed files with 28420 additions and 28996 deletions

107
.clang-format Normal file
View File

@@ -0,0 +1,107 @@
---
Language: Cpp
# BasedOnStyle: Google
AccessModifierOffset: -1
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: Left
AlignOperands: true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: All
AllowShortIfStatementsOnASingleLine: true
AllowShortLoopsOnASingleLine: true
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: true
AlwaysBreakTemplateDeclarations: true
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
AfterClass: false
AfterControlStatement: false
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
BeforeCatch: false
BeforeElse: false
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Attach
BreakBeforeInheritanceComma: false
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeColon
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 80
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: true
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IncludeCategories:
- Regex: '^<.*\.h>'
Priority: 1
- Regex: '^<.*'
Priority: 2
- Regex: '.*'
Priority: 3
IncludeIsMainRegex: '([-_](test|unittest))?$'
IndentCaseLabels: true
IndentWidth: 2
IndentWrappedFunctionNames: false
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: false
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBlockIndentWidth: 2
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: false
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 1
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 200
PointerAlignment: Left
ReflowComments: true
SortIncludes: true
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 2
SpacesInAngles: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Auto
TabWidth: 2
UseTab: Never
...

7
.editorconfig Normal file
View File

@@ -0,0 +1,7 @@
root = true
[*]
end_of_line = lf
insert_final_newline = true
indent_style = space
intend_size = 2

View File

@@ -1,8 +1,39 @@
language: cpp language: cpp
compiler: dist: trusty
- gcc matrix:
include:
- os: linux
addons: addons:
apt: apt:
sources:
- ubuntu-toolchain-r-test
- llvm-toolchain-trusty-5.0
packages:
- g++-7
- cmake
- libxdamage-dev
- libx11-dev
- libxft-dev
- libxext-dev
- libglib2.0-dev
- libxml2-dev
- libcurl4-gnutls-dev
- liblua5.1-0-dev
- libtolua++5.1-dev
- libcairo2-dev
- libimlib2-dev
- libxinerama-dev
- gawk
- clang-5.0
- clang-format-5.0
env:
- MATRIX_EVAL="CC=gcc-7 && CXX=g++-7"
- os: linux
addons:
apt:
sources:
- ubuntu-toolchain-r-test
- llvm-toolchain-trusty-5.0
packages: packages:
- cmake - cmake
- libxdamage-dev - libxdamage-dev
@@ -18,12 +49,27 @@ addons:
- libimlib2-dev - libimlib2-dev
- libxinerama-dev - libxinerama-dev
- gawk - gawk
- clang-5.0
- clang-format-5.0
env:
- MATRIX_EVAL="CC=clang && CXX=clang++"
before_install:
- eval "${MATRIX_EVAL}"
before_script: before_script:
- mkdir build && cd build && cmake .. && cd .. - mkdir build
- mkdir build-no-x11 && cd build-no-x11 && cmake -DBUILD_X11=OFF .. && cd .. - cd build
- scan-build --use-cc=$CC --use-c++=$CXX -o scanbuildout cmake -DCHECK_CODE_FORMAT=ON ..
- travis_wait 30 make format-check
- cd ..
- mkdir build-no-x11
- cd build-no-x11
- scan-build --use-cc=$CC --use-c++=$CXX -o scanbuildout cmake -DCHECK_CODE_FORMAT=ON -DBUILD_X11=OFF ..
- cd ..
script: script:
- cd build && make -j4 && cd .. - cd build
- cd build-no-x11 && make -j4 && cd .. - scan-build --use-cc=$CC --use-c++=$CXX -o scanbuildout make -j4
- cd ../build-no-x11
- scan-build --use-cc=$CC --use-c++=$CXX -o scanbuildout make -j4
branches: branches:
only: only:
- master - master

View File

@@ -1,10 +1,9 @@
# vim: ts=4 sw=4 noet ai cindent syntax=cmake
# #
# Conky, a system monitor, based on torsmo # Conky, a system monitor, based on torsmo
# #
# Please see COPYING for details # Please see COPYING for details
# #
# Copyright (c) 2005-2010 Brenden Matthews, et. al. (see AUTHORS) # Copyright (c) 2005-2018 Brenden Matthews, et. al. (see AUTHORS)
# All rights reserved. # All rights reserved.
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
@@ -20,7 +19,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# #
cmake_minimum_required(VERSION 2.6) cmake_minimum_required(VERSION 3.5)
project(conky) project(conky)
@@ -39,10 +38,22 @@ include(ConkyPlatformChecks)
# CPack module for installation tasks # CPack module for installation tasks
include(ConkyCPackSetup) include(ConkyCPackSetup)
if(CHECK_CODE_FORMAT)
# Set up clang-format
set(CLANG_FORMAT_BIN_NAME clang-format clang-format-5.0)
set(CLANG_FORMAT_EXCLUDE_PATTERNS "build/" ${CMAKE_BINARY_DIR})
find_package(ClangFormat)
endif(CHECK_CODE_FORMAT)
# setup our configuration headers # setup our configuration headers
configure_file(${CMAKE_MODULE_PATH}/config.h.in ${CMAKE_BINARY_DIR}/config.h) configure_file(${CMAKE_MODULE_PATH}/config.h.in ${CMAKE_BINARY_DIR}/config.h)
configure_file(${CMAKE_MODULE_PATH}/build.h.in ${CMAKE_BINARY_DIR}/build.h) configure_file(${CMAKE_MODULE_PATH}/build.h.in ${CMAKE_BINARY_DIR}/build.h)
set(conky_sources
${CMAKE_BINARY_DIR}/config.h
${CMAKE_BINARY_DIR}/build.h
)
# Finally, add some code # Finally, add some code
add_subdirectory(lua) add_subdirectory(lua)
add_subdirectory(data) add_subdirectory(data)

View File

@@ -1,5 +1,5 @@
Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
Copyright (c) 2005-2010 Brenden Matthews, Philip Kovacs, et. al. (see AUTHORS) Copyright (c) 2005-2018 Brenden Matthews, Philip Kovacs, et. al. (see AUTHORS)
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without

5
apply-clang-format.sh Executable file
View File

@@ -0,0 +1,5 @@
#!/bin/bash
find . -iname "*.h" -o -iname "*.cc" -o -iname "*.hh" \
| xargs clang-format \
-style=file -i -fallback-style=google

View File

@@ -1,10 +1,9 @@
# vim: ts=4 sw=4 noet ai cindent syntax=cmake
# #
# Conky, a system monitor, based on torsmo # Conky, a system monitor, based on torsmo
# #
# Please see COPYING for details # Please see COPYING for details
# #
# Copyright (c) 2005-2010 Brenden Matthews, et. al. (see AUTHORS) # Copyright (c) 2005-2018 Brenden Matthews, et. al. (see AUTHORS)
# All rights reserved. # All rights reserved.
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
@@ -134,7 +133,7 @@ else(RELEASE)
set(VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}_pre${COMMIT_COUNT}") set(VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}_pre${COMMIT_COUNT}")
endif(RELEASE) endif(RELEASE)
set(COPYRIGHT "Copyright Brenden Matthews, et al, 2005-2015") set(COPYRIGHT "Copyright Brenden Matthews, et al, 2005-2018")
macro(AC_SEARCH_LIBS FUNCTION_NAME INCLUDES TARGET_VAR) macro(AC_SEARCH_LIBS FUNCTION_NAME INCLUDES TARGET_VAR)
if("${TARGET_VAR}" MATCHES "^${TARGET_VAR}$") if("${TARGET_VAR}" MATCHES "^${TARGET_VAR}$")

View File

@@ -1,10 +1,9 @@
# vim: ts=4 sw=4 noet ai cindent syntax=cmake
# #
# Conky, a system monitor, based on torsmo # Conky, a system monitor, based on torsmo
# #
# Please see COPYING for details # Please see COPYING for details
# #
# Copyright (c) 2005-2010 Brenden Matthews, et. al. (see AUTHORS) # Copyright (c) 2005-2018 Brenden Matthews, et. al. (see AUTHORS)
# All rights reserved. # All rights reserved.
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
@@ -179,3 +178,5 @@ option(BUILD_CMUS "Enable support for cmus music player" false)
option(BUILD_JOURNAL "Enable support for reading from the systemd journal" false) 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(BUILD_PULSEAUDIO "Enable support for Pulseaudio's default sink and source" false)
option(CHECK_CODE_FORMAT "Check code formatting with clang-format" false)

View File

@@ -1,10 +1,9 @@
# vim: ts=4 sw=4 noet ai cindent syntax=cmake
# #
# Conky, a system monitor, based on torsmo # Conky, a system monitor, based on torsmo
# #
# Please see COPYING for details # Please see COPYING for details
# #
# Copyright (c) 2005-2010 Brenden Matthews, et. al. (see AUTHORS) # Copyright (c) 2005-2018 Brenden Matthews, et. al. (see AUTHORS)
# All rights reserved. # All rights reserved.
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify

View File

@@ -1,10 +1,9 @@
# vim: ts=4 sw=4 noet ai cindent syntax=cmake
# #
# Conky, a system monitor, based on torsmo # Conky, a system monitor, based on torsmo
# #
# Please see COPYING for details # Please see COPYING for details
# #
# Copyright (c) 2005-2010 Brenden Matthews, et. al. (see AUTHORS) # Copyright (c) 2005-2018 Brenden Matthews, et. al. (see AUTHORS)
# All rights reserved. # All rights reserved.
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
@@ -114,7 +113,24 @@ if(BUILD_I18N AND OS_DRAGONFLY)
endif(BUILD_I18N AND OS_DRAGONFLY) endif(BUILD_I18N AND OS_DRAGONFLY)
if(BUILD_I18N AND OS_DARWIN) if(BUILD_I18N AND OS_DARWIN)
set(conky_libs ${conky_libs} -lintl) 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)
include_directories(${LIBINTL_H_N})
else(LIBINTL_H_N)
message(FATAL_ERROR "Unable to find libintl.h (try `brew install gettext`)")
endif(LIBINTL_H_N)
find_library(INTL_LIB NAMES intl PATHS
/usr/local/opt/gettext/lib
/usr/lib
/usr/local/lib
/usr/local/opt/lib
)
set(conky_libs ${conky_libs} ${INTL_LIB})
endif(BUILD_I18N AND OS_DARWIN) endif(BUILD_I18N AND OS_DARWIN)
if(BUILD_NCURSES AND OS_DARWIN) if(BUILD_NCURSES AND OS_DARWIN)

View File

@@ -1,10 +1,9 @@
# vim: ts=4 sw=4 noet ai cindent syntax=cmake
# #
# Conky, a system monitor, based on torsmo # Conky, a system monitor, based on torsmo
# #
# Please see COPYING for details # Please see COPYING for details
# #
# Copyright (c) 2005-2010 Brenden Matthews, et. al. (see AUTHORS) # Copyright (c) 2005-2018 Brenden Matthews, et. al. (see AUTHORS)
# All rights reserved. # All rights reserved.
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify

View File

@@ -0,0 +1,34 @@
# Find Clang format
#
#
if(NOT CLANG_FORMAT_BIN_NAME)
set(CLANG_FORMAT_BIN_NAME clang-format)
endif()
# if custom path check there first
if(CLANG_FORMAT_ROOT_DIR)
find_program(CLANG_FORMAT_BIN
NAMES
${CLANG_FORMAT_BIN_NAME}
PATHS
"${CLANG_FORMAT_ROOT_DIR}"
NO_DEFAULT_PATH)
endif()
find_program(CLANG_FORMAT_BIN NAMES ${CLANG_FORMAT_BIN_NAME})
include(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(
CLANG_FORMAT
DEFAULT_MSG
CLANG_FORMAT_BIN)
mark_as_advanced(
CLANG_FORMAT_BIN)
if(CLANG_FORMAT_FOUND)
# A CMake script to find all source files and setup clang-format targets for them
include(clang-format)
else()
message("clang-format not found. Not setting up format targets")
endif()

View File

@@ -1,10 +1,9 @@
# vim: ts=4 sw=4 noet ai cindent syntax=cmake
# #
# Conky, a system monitor, based on torsmo # Conky, a system monitor, based on torsmo
# #
# Please see COPYING for details # Please see COPYING for details
# #
# Copyright (c) 2005-2010 Brenden Matthews, et. al. (see AUTHORS) # Copyright (c) 2005-2018 Brenden Matthews, et. al. (see AUTHORS)
# All rights reserved. # All rights reserved.
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify

62
cmake/clang-format.cmake Normal file
View File

@@ -0,0 +1,62 @@
# A CMake script to find all source files and setup clang-format targets for them
# Find all source files
set(CLANG_FORMAT_CXX_FILE_EXTENSIONS ${CLANG_FORMAT_CXX_FILE_EXTENSIONS} *.cpp *.h *.cxx *.hxx *.hpp *.cc *.ipp)
file(GLOB_RECURSE ALL_SOURCE_FILES ${CLANG_FORMAT_CXX_FILE_EXTENSIONS})
# Don't include some common build folders
set(CLANG_FORMAT_EXCLUDE_PATTERNS ${CLANG_FORMAT_EXCLUDE_PATTERNS} "/CMakeFiles/" "cmake")
# get all project files file
foreach (SOURCE_FILE ${ALL_SOURCE_FILES})
foreach (EXCLUDE_PATTERN ${CLANG_FORMAT_EXCLUDE_PATTERNS})
string(FIND ${SOURCE_FILE} ${EXCLUDE_PATTERN} EXCLUDE_FOUND)
if (NOT ${EXCLUDE_FOUND} EQUAL -1)
list(REMOVE_ITEM ALL_SOURCE_FILES ${SOURCE_FILE})
endif ()
endforeach ()
endforeach ()
add_custom_target(format
COMMENT "Running clang-format to change files"
COMMAND ${CLANG_FORMAT_BIN}
-style=file
-i
${ALL_SOURCE_FILES}
)
add_custom_target(format-check
COMMENT "Checking clang-format changes"
# Use ! to negate the result for correct output
COMMAND !
${CLANG_FORMAT_BIN}
-style=file
-output-replacements-xml
${ALL_SOURCE_FILES}
| grep -q "replacement offset"
)
# Get the path to this file
get_filename_component(_clangcheckpath ${CMAKE_CURRENT_LIST_FILE} PATH)
# have at least one here by default
set(CHANGED_FILE_EXTENSIONS ".cpp")
foreach(EXTENSION ${CLANG_FORMAT_CXX_FILE_EXTENSIONS})
set(CHANGED_FILE_EXTENSIONS "${CHANGED_FILE_EXTENSIONS},${EXTENSION}" )
endforeach()
set(EXCLUDE_PATTERN_ARGS)
foreach(EXCLUDE_PATTERN ${CLANG_FORMAT_EXCLUDE_PATTERNS})
list(APPEND EXCLUDE_PATTERN_ARGS "--exclude=${EXCLUDE_PATTERN}")
endforeach()
# call the script to chech changed files in git
add_custom_target(format-check-changed
COMMENT "Checking changed files in git"
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
COMMAND ${_clangcheckpath}/../scripts/clang-format-check-changed.py
--file-extensions \"${CHANGED_FILE_EXTENSIONS}\"
${EXCLUDE_PATTERN_ARGS}
--clang-format-bin ${CLANG_FORMAT_BIN}
)

View File

@@ -0,0 +1,18 @@
#!/bin/bash
# Required because cmake root isn't git root in this example
CLANG_FORMAT_BIN=$1
GIT_ROOT=`git rev-parse --show-toplevel`
pushd ${GIT_ROOT} > /dev/null
git status --porcelain \
| egrep '*\.cpp|*\.h|*\.cxx|*\.hxx|*\.hpp|*\.cc' \
| awk -F " " '{print $NF}' \
| xargs -r ${CLANG_FORMAT_BIN} -style=file -output-replacements-xml \
| grep "replacement offset" 2>&1 > /dev/null
RET=$?
popd > /dev/null
exit ${RET}

View File

@@ -0,0 +1,163 @@
#!/usr/bin/env python
import argparse
import os
import sys
import subprocess
def check_file(filename, excludes, extensions):
"""
Check if a file should be included in our check
"""
name, ext = os.path.splitext(filename)
if len(ext) > 0 and ext in extensions:
if len(excludes) == 0:
return True
for exclude in excludes:
if exclude in filename:
return False
return True
return False
def check_directory(directory, excludes, extensions):
output = []
if len(excludes) > 0:
for exclude in excludes:
if exclude in directory:
directory_excluded = False
return output
for root, _, files in os.walk(directory):
for file in files:
filename = os.path.join(root, file)
if check_file(filename, excludes, extensions):
print("Will check file [{}]".format(filename))
output.append(filename)
return output
def get_git_root(git_bin):
cmd = [git_bin, "rev-parse", "--show-toplevel"]
try:
return subprocess.check_output(cmd).strip()
except subprocess.CalledProcessError, e:
print("Error calling git [{}]".format(e))
raise
def clean_git_filename(line):
"""
Takes a line from git status --porcelain and returns the filename
"""
file = None
git_status = line[:2]
# Not an exhaustive list of git status output but should
# be enough for this case
# check if this is a delete
if 'D' in git_status:
return None
# ignored file
if '!' in git_status:
return None
# Covers renamed files
if '->' in line:
file = line[3:].split('->')[-1].strip()
else:
file = line[3:].strip()
return file
def get_changed_files(git_bin, excludes, file_extensions):
"""
Run git status and return the list of changed files
"""
extensions = file_extensions.split(",")
# arguments coming from cmake will be *.xx. We want to remove the *
for i, extension in enumerate(extensions):
if extension[0] == '*':
extensions[i] = extension[1:]
git_root = get_git_root(git_bin)
cmd = [git_bin, "status", "--porcelain", "--ignore-submodules"]
print("git cmd = {}".format(cmd))
output = []
returncode = 0
try:
cmd_output = subprocess.check_output(cmd)
for line in cmd_output.split('\n'):
if len(line) > 0:
file = clean_git_filename(line)
if not file:
continue
file = os.path.join(git_root, file)
if file[-1] == "/":
directory_files = check_directory(
file, excludes, file_extensions)
output = output + directory_files
else:
if check_file(file, excludes, file_extensions):
print("Will check file [{}]".format(file))
output.append(file)
except subprocess.CalledProcessError, e:
print("Error calling git [{}]".format(e))
returncode = e.returncode
return output, returncode
def run_clang_format(clang_format_bin, changed_files):
"""
Run clang format on a list of files
@return 0 if formatted correctly.
"""
if len(changed_files) == 0:
return 0
cmd = [clang_format_bin, "-style=file",
"-output-replacements-xml"] + changed_files
print("clang-format cmd = {}".format(cmd))
try:
cmd_output = subprocess.check_output(cmd)
if "replacement offset" in cmd_output:
print("ERROR: Changed files don't match format")
return 1
except subprocess.CalledProcessError, e:
print("Error calling clang-format [{}]".format(e))
return e.returncode
return 0
def cli():
# global params
parser = argparse.ArgumentParser(prog='clang-format-check-changed',
description='Checks if files chagned in git match the .clang-format specification')
parser.add_argument("--file-extensions", type=str,
default=".cpp,.h,.cxx,.hxx,.hpp,.cc,.ipp",
help="Comma seperated list of file extensions to check")
parser.add_argument('--exclude', action='append', default=[],
help='Will not match the files / directories with these in the name')
parser.add_argument('--clang-format-bin', type=str, default="clang-format",
help="The clang format binary")
parser.add_argument('--git-bin', type=str, default="git",
help="The git binary")
args = parser.parse_args()
# Run gcovr to get the .gcda files form .gcno
changed_files, returncode = get_changed_files(
args.git_bin, args.exclude, args.file_extensions)
if returncode != 0:
return returncode
return run_clang_format(args.clang_format_bin, changed_files)
if __name__ == '__main__':
sys.exit(cli())

View File

@@ -1,10 +1,9 @@
# vim: ts=4 sw=4 noet ai cindent syntax=cmake
# #
# Conky, a system monitor, based on torsmo # Conky, a system monitor, based on torsmo
# #
# Please see COPYING for details # Please see COPYING for details
# #
# Copyright (c) 2005-2012 Brenden Matthews, et. al. (see AUTHORS) # Copyright (c) 2005-2018 Brenden Matthews, et. al. (see AUTHORS)
# All rights reserved. # All rights reserved.
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify

View File

@@ -1,31 +0,0 @@
# -*- mode: Makefile; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*-
#
# Conky, a system monitor, based on torsmo
#
# Any original torsmo code is licensed under the BSD license
#
# All code written since the fork of torsmo is licensed under the GPL
#
# Please see COPYING for details
#
# Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
# Copyright (c) 2005-2012 Brenden Matthews, Philip Kovacs, et. al. (see AUTHORS)
# All rights reserved.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
configdir = ${sysconfdir}/conky
dist_config_DATA = conky.conf conky_no_x11.conf
# vi:set ts=4 sw=4 noet ai nocindent syntax=automake:

View File

@@ -1,4 +1,3 @@
-- vim: ts=4 sw=4 noet ai cindent syntax=lua
--[[ --[[
Conky, a system monitor, based on torsmo Conky, a system monitor, based on torsmo
@@ -9,7 +8,7 @@ All code written since the fork of torsmo is licensed under the GPL
Please see COPYING for details Please see COPYING for details
Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
Copyright (c) 2005-2010 Brenden Matthews, Philip Kovacs, et. al. (see AUTHORS) Copyright (c) 2005-2018 Brenden Matthews, Philip Kovacs, et. al. (see AUTHORS)
All rights reserved. All rights reserved.
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify

View File

@@ -1,4 +1,3 @@
-- vim: ts=4 sw=4 noet ai cindent syntax=lua
--[[ --[[
Conky, a system monitor, based on torsmo Conky, a system monitor, based on torsmo
@@ -9,7 +8,7 @@ All code written since the fork of torsmo is licensed under the GPL
Please see COPYING for details Please see COPYING for details
Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
Copyright (c) 2005-2012 Brenden Matthews, Philip Kovacs, et. al. (see AUTHORS) Copyright (c) 2005-2018 Brenden Matthews, Philip Kovacs, et. al. (see AUTHORS)
All rights reserved. All rights reserved.
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify

View File

@@ -7,7 +7,7 @@
-- Please see COPYING for details -- Please see COPYING for details
-- Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen -- Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
-- Copyright (c) 2005-2012 Brenden Matthews, Philip Kovacs, et. al. (see AUTHORS) -- Copyright (c) 2005-2018 Brenden Matthews, Philip Kovacs, et. al. (see AUTHORS)
-- All rights reserved. -- All rights reserved.
-- This program is free software: you can redistribute it and/or modify -- This program is free software: you can redistribute it and/or modify

View File

@@ -1,10 +1,9 @@
# vim: ts=4 sw=4 noet ai cindent syntax=cmake
# #
# Conky, a system monitor, based on torsmo # Conky, a system monitor, based on torsmo
# #
# Please see COPYING for details # Please see COPYING for details
# #
# Copyright (c) 2005-2012 Brenden Matthews, et. al. (see AUTHORS) # Copyright (c) 2005-2018 Brenden Matthews, et. al. (see AUTHORS)
# All rights reserved. # All rights reserved.
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify

View File

@@ -303,7 +303,7 @@
</refsect1> </refsect1>
<refsect1> <refsect1>
<title>Copying</title> <title>Copying</title>
<para>Copyright (c) 2005-2012 Brenden Matthews, Philip <para>Copyright (c) 2005-2018 Brenden Matthews, Philip
Kovacs, et. al. Any original torsmo code is licensed under Kovacs, et. al. Any original torsmo code is licensed under
the BSD license (see LICENSE.BSD for a copy). All code the BSD license (see LICENSE.BSD for a copy). All code
written since the fork of torsmo is licensed under the GPL written since the fork of torsmo is licensed under the GPL

View File

@@ -1,10 +1,9 @@
# vim: ts=4 sw=4 noet ai cindent syntax=cmake
# #
# Conky, a system monitor, based on torsmo # Conky, a system monitor, based on torsmo
# #
# Please see COPYING for details # Please see COPYING for details
# #
# Copyright (c) 2005-2012 Brenden Matthews, et. al. (see AUTHORS) # Copyright (c) 2005-2018 Brenden Matthews, et. al. (see AUTHORS)
# All rights reserved. # All rights reserved.
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify

View File

@@ -1,10 +1,10 @@
/* -*- mode: c; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*- /*
* *
* Conky, a system monitor, based on torsmo * Conky, a system monitor, based on torsmo
* *
* Please see COPYING for details * Please see COPYING for details
* *
* Copyright (c) 2005-2012 Brenden Matthews, Philip Kovacs, et. al. * Copyright (c) 2005-2018 Brenden Matthews, Philip Kovacs, et. al.
* (see AUTHORS) * (see AUTHORS)
* All rights reserved. * All rights reserved.
* *

View File

@@ -1,10 +1,10 @@
/* -*- mode: c; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*- /*
* *
* Conky, a system monitor, based on torsmo * Conky, a system monitor, based on torsmo
* *
* Please see COPYING for details * Please see COPYING for details
* *
* Copyright (c) 2005-2012 Brenden Matthews, Philip Kovacs, et. al. * Copyright (c) 2005-2018 Brenden Matthews, Philip Kovacs, et. al.
* (see AUTHORS) * (see AUTHORS)
* All rights reserved. * All rights reserved.
* *
@@ -25,22 +25,22 @@
#ifndef _LIBCAIRO_IMAGE_HELPER_H_ #ifndef _LIBCAIRO_IMAGE_HELPER_H_
#define _LIBCAIRO_IMAGE_HELPER_H_ #define _LIBCAIRO_IMAGE_HELPER_H_
#include <cairo.h>
#include <Imlib2.h> #include <Imlib2.h>
#include <cairo.h>
void void cairo_draw_image(const char *file, cairo_surface_t *cs, int x, int y,
cairo_draw_image(const char * file, cairo_surface_t * cs, int x, int y, double scale_x, double scale_y, double *return_scale_w,
double scale_x, double scale_y, double *return_scale_h) {
double * return_scale_w, double * return_scale_h)
{
Imlib_Image *image = imlib_load_image(file); Imlib_Image *image = imlib_load_image(file);
if (! image) { return; } if (!image) {
return;
}
imlib_context_set_image(image); imlib_context_set_image(image);
int w = imlib_image_get_width(), h = imlib_image_get_height(); int w = imlib_image_get_width(), h = imlib_image_get_height();
double scaled_w = *return_scale_w = scale_x * (double)w double scaled_w = *return_scale_w = scale_x * (double)w,
, scaled_h = *return_scale_h = scale_y * (double)h; scaled_h = *return_scale_h = scale_y * (double)h;
/* create temporary image */ /* create temporary image */
Imlib_Image premul = imlib_create_image(scaled_w, scaled_h); Imlib_Image premul = imlib_create_image(scaled_w, scaled_h);
@@ -60,8 +60,8 @@ cairo_draw_image(const char * file, cairo_surface_t * cs, int x, int y,
/* now pass the result to cairo */ /* now pass the result to cairo */
cairo_surface_t *result = cairo_image_surface_create_for_data( cairo_surface_t *result = cairo_image_surface_create_for_data(
(void *) imlib_image_get_data_for_reading_only(), (void *)imlib_image_get_data_for_reading_only(), CAIRO_FORMAT_ARGB32,
CAIRO_FORMAT_ARGB32, scaled_w, scaled_h, sizeof(DATA32) * scaled_w); scaled_w, scaled_h, sizeof(DATA32) * scaled_w);
cairo_t *cr = cairo_create(cs); cairo_t *cr = cairo_create(cs);
cairo_set_source_surface(cr, result, x, y); cairo_set_source_surface(cr, result, x, y);

View File

@@ -1,10 +1,10 @@
/* -*- mode: c; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*- /*
* *
* Conky, a system monitor, based on torsmo * Conky, a system monitor, based on torsmo
* *
* Please see COPYING for details * Please see COPYING for details
* *
* Copyright (c) 2005-2012 Brenden Matthews, Philip Kovacs, et. al. * Copyright (c) 2005-2018 Brenden Matthews, Philip Kovacs, et. al.
* (see AUTHORS) * (see AUTHORS)
* All rights reserved. * All rights reserved.
* *
@@ -26,19 +26,15 @@
#define _LIBRSVG_HELPER_H_ #define _LIBRSVG_HELPER_H_
#include <glib.h> #include <glib.h>
#include <stdlib.h>
#include <librsvg/rsvg.h> #include <librsvg/rsvg.h>
#include <stdlib.h>
RsvgDimensionData * RsvgDimensionData *rsvgDimensionDataCreate(void) {
rsvgDimensionDataCreate(void)
{
return (RsvgDimensionData *)calloc(1, sizeof(RsvgDimensionData)); return (RsvgDimensionData *)calloc(1, sizeof(RsvgDimensionData));
} }
void void rsvgDimensionDataGet(RsvgDimensionData *dd, int *width, int *height,
rsvgDimensionDataGet(RsvgDimensionData * dd, double *em, double *ex) {
int * width, int * height, double * em, double * ex)
{
if (dd) { if (dd) {
*width = dd->width; *width = dd->width;
*height = dd->height; *height = dd->height;
@@ -47,51 +43,40 @@ rsvgDimensionDataGet(RsvgDimensionData * dd,
} }
} }
RsvgPositionData * RsvgPositionData *rsvgPositionDataCreate(void) {
rsvgPositionDataCreate(void)
{
return (RsvgPositionData *)calloc(1, sizeof(RsvgPositionData)); return (RsvgPositionData *)calloc(1, sizeof(RsvgPositionData));
} }
void void rsvgPositionDataGet(RsvgPositionData *pd, int *x, int *y) {
rsvgPositionDataGet(RsvgPositionData * pd, int * x, int * y)
{
if (pd) { if (pd) {
*x = pd->x; *x = pd->x;
*y = pd->y; *y = pd->y;
} }
} }
RsvgHandle * RsvgHandle *rsvg_create_handle_from_file(const char *filename) {
rsvg_create_handle_from_file(const char * filename)
{
GError *error = NULL; GError *error = NULL;
RsvgHandle *handle = rsvg_handle_new_from_file(filename, &error); RsvgHandle *handle = rsvg_handle_new_from_file(filename, &error);
if (error) { if (error) {
g_object_unref(error); g_object_unref(error);
if (handle) if (handle) g_object_unref(handle);
g_object_unref(handle);
handle = NULL; handle = NULL;
} }
return handle; return handle;
} }
int int rsvg_destroy_handle(RsvgHandle *handle) {
rsvg_destroy_handle(RsvgHandle * handle)
{
int status = 0; int status = 0;
if (handle) { if (handle) {
GError *error = NULL; GError *error = NULL;
status = rsvg_handle_close(handle, &error); status = rsvg_handle_close(handle, &error);
if (status) if (status) g_object_unref(handle);
g_object_unref(handle);
if (error) if (error) g_object_unref(error);
g_object_unref(error);
} }
return status; return status;

View File

@@ -1,10 +1,9 @@
# vim: ts=4 sw=4 noet ai cindent syntax=cmake
# #
# Conky, a system monitor, based on torsmo # Conky, a system monitor, based on torsmo
# #
# Please see COPYING for details # Please see COPYING for details
# #
# Copyright (c) 2005-2012 Brenden Matthews, et. al. (see AUTHORS) # Copyright (c) 2005-2018 Brenden Matthews, et. al. (see AUTHORS)
# All rights reserved. # All rights reserved.
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
@@ -37,114 +36,197 @@ if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/defconfig.h)
message(FATAL_ERROR "You must remove the autotools generated file '${CMAKE_CURRENT_SOURCE_DIR}/defconfig.h' in order to build with CMake.") message(FATAL_ERROR "You must remove the autotools generated file '${CMAKE_CURRENT_SOURCE_DIR}/defconfig.h' in order to build with CMake.")
endif(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/defconfig.h) endif(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/defconfig.h)
set(conky_sources c++wrap.cc colours.cc combine.cc common.cc conky.cc core.cc set(conky_sources
diskio.cc entropy.cc exec.cc fs.cc mail.cc net_stat.cc template.cc ${conky_sources}
mboxscan.cc read_tcpip.cc scroll.cc specials.cc tailhead.cc temphelper.cc c++wrap.cc c++wrap.hh
text_object.cc timeinfo.cc top.cc algebra.cc prioqueue.cc proc.cc user.cc colours.cc colours.h
luamm.cc data-source.cc lua-config.cc setting.cc llua.cc update-cb.cc) combine.cc combine.h
common.cc common.h
conky.cc conky.h
core.cc core.h
diskio.cc diskio.h
entropy.cc entropy.h
exec.cc exec.h
fs.cc fs.h
mail.cc mail.h
net_stat.cc net_stat.h
template.cc template.h
mboxscan.cc mboxscan.h
read_tcpip.cc read_tcpip.h
scroll.cc scroll.h
specials.cc specials.h
tailhead.cc tailhead.h
temphelper.cc temphelper.h
text_object.cc text_object.h
timeinfo.cc timeinfo.h
top.cc top.h
algebra.cc algebra.h
prioqueue.cc prioqueue.h
proc.cc proc.h
user.cc user.h
luamm.cc luamm.hh
data-source.cc data-source.hh
lua-config.cc lua-config.hh
setting.cc setting.hh
llua.cc llua.h
update-cb.cc update-cb.hh
logging.h
semaphore.hh
)
# Platform specific sources # Platform specific sources
if(OS_LINUX) if(OS_LINUX)
set(linux linux.cc users.cc sony.cc i8k.cc) set(linux
linux.cc linux.h
users.cc users.h
sony.cc sony.h
i8k.cc i8k.h
)
set(optional_sources ${optional_sources} ${linux}) set(optional_sources ${optional_sources} ${linux})
endif(OS_LINUX) endif(OS_LINUX)
if(OS_FREEBSD) if(OS_FREEBSD)
set(freebsd freebsd.cc bsdapm.cc) set(freebsd
freebsd.cc freebsd.h
bsdapm.cc bsdapm.h
)
set(optional_sources ${optional_sources} ${freebsd}) set(optional_sources ${optional_sources} ${freebsd})
endif(OS_FREEBSD) endif(OS_FREEBSD)
if(OS_DRAGONFLY) if(OS_DRAGONFLY)
set(dragonfly dragonfly.cc bsdapm.cc) set(dragonfly
dragonfly.cc dragonfly.h
bsdapm.cc bsdapm.h
)
set(optional_sources ${optional_sources} ${dragonfly}) set(optional_sources ${optional_sources} ${dragonfly})
endif(OS_DRAGONFLY) endif(OS_DRAGONFLY)
if(OS_OPENBSD) if(OS_OPENBSD)
set(openbsd openbsd.cc bsdapm.cc) set(openbsd
openbsd.cc openbsd.h
bsdapm.cc bsdapm.h
)
set(optional_sources ${optional_sources} ${openbsd}) set(optional_sources ${optional_sources} ${openbsd})
endif(OS_OPENBSD) endif(OS_OPENBSD)
# These below are not actually supported. No idea what their status is. # These below are not actually supported. No idea what their status is.
if(OS_SOLARIS) if(OS_SOLARIS)
set(solaris solaris.cc) set(solaris
solaris.cc solaris.h
)
set(optional_sources ${optional_sources} ${solaris}) set(optional_sources ${optional_sources} ${solaris})
endif(OS_SOLARIS) endif(OS_SOLARIS)
if(OS_NETBSD) if(OS_NETBSD)
set(netbsd netbsd.cc) set(netbsd
netbsd.cc netbsd.h
)
set(optional_sources ${optional_sources} ${netbsd}) set(optional_sources ${optional_sources} ${netbsd})
endif(OS_NETBSD) endif(OS_NETBSD)
if(OS_HAIKU) if(OS_HAIKU)
set(haiku haiku.cc) set(haiku
haiku.cc haiku.h
)
set(optional_sources ${optional_sources} ${haiku}) set(optional_sources ${optional_sources} ${haiku})
endif(OS_HAIKU) endif(OS_HAIKU)
if(OS_DARWIN) if(OS_DARWIN)
set(darwin darwin.cc) set(darwin
darwin.cc darwin.h
darwin_sip.h
i18n.h
)
set(optional_sources ${optional_sources} ${darwin}) set(optional_sources ${optional_sources} ${darwin})
endif(OS_DARWIN) endif(OS_DARWIN)
# Optional sources # Optional sources
if(HAVE_SOME_SOUNDCARD_H) if(HAVE_SOME_SOUNDCARD_H)
set(mixer mixer.cc) 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_SOME_SOUNDCARD_H)
if(BUILD_AUDACIOUS) if(BUILD_AUDACIOUS)
set(audacious audacious.cc) set(audacious
audacious.cc audacious.h
)
set(optional_sources ${optional_sources} ${audacious}) set(optional_sources ${optional_sources} ${audacious})
endif(BUILD_AUDACIOUS) endif(BUILD_AUDACIOUS)
if(BUILD_BMPX) if(BUILD_BMPX)
set(bmpx bmpx.cc) set(bmpx
bmpx.cc bmpx.h
)
set(optional_sources ${optional_sources} ${bmpx}) set(optional_sources ${optional_sources} ${bmpx})
endif(BUILD_BMPX) endif(BUILD_BMPX)
if(BUILD_IBM) if(BUILD_IBM)
set(ibm ibm.cc smapi.cc) set(ibm
ibm.cc ibm.h
smapi.cc smapi.h
)
set(optional_sources ${optional_sources} ${ibm}) set(optional_sources ${optional_sources} ${ibm})
endif(BUILD_IBM) endif(BUILD_IBM)
if(BUILD_MPD) if(BUILD_MPD)
set(mpd mpd.cc libmpdclient.cc) set(mpd
mpd.cc mpd.h
libmpdclient.cc libmpdclient.h
)
set(optional_sources ${optional_sources} ${mpd}) set(optional_sources ${optional_sources} ${mpd})
endif(BUILD_MPD) endif(BUILD_MPD)
if(BUILD_MYSQL) if(BUILD_MYSQL)
set(mysql mysql.cc) set(mysql
mysql.cc mysql.h
)
set(optional_sources ${optional_sources} ${mysql}) set(optional_sources ${optional_sources} ${mysql})
endif(BUILD_MYSQL) endif(BUILD_MYSQL)
if(BUILD_MOC) if(BUILD_MOC)
set(moc moc.cc) set(moc
moc.cc moc.h
)
set(optional_sources ${optional_sources} ${moc}) set(optional_sources ${optional_sources} ${moc})
endif(BUILD_MOC) endif(BUILD_MOC)
if(BUILD_CMUS) if(BUILD_CMUS)
set(cmus cmus.cc) set(cmus
cmus.cc cmus.h
)
set(optional_sources ${optional_sources} ${cmus}) set(optional_sources ${optional_sources} ${cmus})
endif(BUILD_CMUS) endif(BUILD_CMUS)
if(BUILD_JOURNAL) if(BUILD_JOURNAL)
set(journal journal.cc) set(journal
journal.cc journal.h
)
set(optional_sources ${optional_sources} ${journal}) set(optional_sources ${optional_sources} ${journal})
endif(BUILD_JOURNAL) endif(BUILD_JOURNAL)
if(BUILD_XMMS2) if(BUILD_XMMS2)
set(xmms2 xmms2.cc) set(xmms2
xmms2.cc xmms2.h
)
set(optional_sources ${optional_sources} ${xmms2}) set(optional_sources ${optional_sources} ${xmms2})
endif(BUILD_XMMS2) endif(BUILD_XMMS2)
if(BUILD_PORT_MONITORS) if(BUILD_PORT_MONITORS)
add_library(tcp-portmon libtcp-portmon.cc) add_library(tcp-portmon libtcp-portmon.cc libtcp-portmon.h)
set(conky_libs ${conky_libs} tcp-portmon) set(conky_libs ${conky_libs} tcp-portmon)
set(port_monitors tcp-portmon.cc) set(port_monitors
tcp-portmon.cc tcp-portmon.h
)
set(optional_sources ${optional_sources} ${port_monitors}) set(optional_sources ${optional_sources} ${port_monitors})
endif(BUILD_PORT_MONITORS) endif(BUILD_PORT_MONITORS)
if(BUILD_X11) if(BUILD_X11)
set(x11 x11.cc fonts.cc) set(x11
x11.cc x11.h
fonts.cc fonts.h
)
set(optional_sources ${optional_sources} ${x11}) set(optional_sources ${optional_sources} ${x11})
if(BUILD_XINERAMA) if(BUILD_XINERAMA)
@@ -154,66 +236,94 @@ if(BUILD_X11)
endif(BUILD_X11) endif(BUILD_X11)
if(BUILD_HDDTEMP) if(BUILD_HDDTEMP)
set(hddtemp hddtemp.cc) set(hddtemp
hddtemp.cc hddtemp.h
)
set(optional_sources ${optional_sources} ${hddtemp}) set(optional_sources ${optional_sources} ${hddtemp})
endif(BUILD_HDDTEMP) endif(BUILD_HDDTEMP)
if(BUILD_EVE) if(BUILD_EVE)
set(eve eve.cc) set(eve
eve.cc eve.h
)
set(optional_sources ${optional_sources} ${eve}) set(optional_sources ${optional_sources} ${eve})
endif(BUILD_EVE) endif(BUILD_EVE)
if(BUILD_CURL) if(BUILD_CURL)
set(ccurl_thread ccurl_thread.cc) set(ccurl_thread
ccurl_thread.cc ccurl_thread.h
)
set(optional_sources ${optional_sources} ${ccurl_thread}) set(optional_sources ${optional_sources} ${ccurl_thread})
endif(BUILD_CURL) endif(BUILD_CURL)
if(BUILD_RSS) if(BUILD_RSS)
set(rss rss.cc prss.cc) set(rss
rss.cc rss.h
prss.cc prss.h
)
set(optional_sources ${optional_sources} ${rss}) set(optional_sources ${optional_sources} ${rss})
endif(BUILD_RSS) endif(BUILD_RSS)
if(BUILD_WEATHER) if(BUILD_WEATHER)
set(weather weather.cc) set(weather
weather.cc weather.h
)
set(optional_sources ${optional_sources} ${weather}) set(optional_sources ${optional_sources} ${weather})
endif(BUILD_WEATHER) endif(BUILD_WEATHER)
if(BUILD_NVIDIA) if(BUILD_NVIDIA)
set(nvidia nvidia.cc) set(nvidia
nvidia.cc nvidia.h
)
set(optional_sources ${optional_sources} ${nvidia}) set(optional_sources ${optional_sources} ${nvidia})
endif(BUILD_NVIDIA) endif(BUILD_NVIDIA)
if(BUILD_IMLIB2) if(BUILD_IMLIB2)
set(imlib2 imlib2.cc) set(imlib2
imlib2.cc imlib2.h
)
set(optional_sources ${optional_sources} ${imlib2}) set(optional_sources ${optional_sources} ${imlib2})
endif(BUILD_IMLIB2) endif(BUILD_IMLIB2)
if(BUILD_APCUPSD) if(BUILD_APCUPSD)
set(apcupsd apcupsd.cc) set(apcupsd
apcupsd.cc apcupsd.h
)
set(optional_sources ${optional_sources} ${apcupsd}) set(optional_sources ${optional_sources} ${apcupsd})
endif(BUILD_APCUPSD) endif(BUILD_APCUPSD)
if(BUILD_ICAL) if(BUILD_ICAL)
set(ical ical.cc) set(ical
ical.cc ical.h
)
set(optional_sources ${optional_sources} ${ical}) set(optional_sources ${optional_sources} ${ical})
endif(BUILD_ICAL) endif(BUILD_ICAL)
if(BUILD_IRC) if(BUILD_IRC)
set(irc irc.cc) set(irc
irc.cc irc.h
)
set(optional_sources ${optional_sources} ${irc}) set(optional_sources ${optional_sources} ${irc})
endif(BUILD_IRC) endif(BUILD_IRC)
if(BUILD_ICONV) if(BUILD_ICONV)
set(iconv iconv_tools.cc) set(iconv
iconv_tools.cc iconv_tools.h
)
set(optional_sources ${optional_sources} ${iconv}) set(optional_sources ${optional_sources} ${iconv})
endif(BUILD_ICONV) endif(BUILD_ICONV)
if(BUILD_NCURSES) if(BUILD_NCURSES)
set(optional_sources ${optional_sources} nc.cc) set(ncurses_srcs
nc.cc nc.h
)
set(optional_sources ${optional_sources} ${ncurses_srcs})
endif(BUILD_NCURSES) endif(BUILD_NCURSES)
if(BUILD_PULSEAUDIO) if(BUILD_PULSEAUDIO)
set(pulseaudio pulseaudio.cc) set(pulseaudio
pulseaudio.cc pulseaudio.h
)
set(optional_sources ${optional_sources} ${pulseaudio}) set(optional_sources ${optional_sources} ${pulseaudio})
endif(BUILD_PULSEAUDIO) endif(BUILD_PULSEAUDIO)

View File

@@ -1,5 +1,4 @@
/* -*- mode: c++; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*- /*
* vim: ts=4 sw=4 noet ai cindent syntax=cpp
* *
* Conky, a system monitor, based on torsmo * Conky, a system monitor, based on torsmo
* *
@@ -10,7 +9,7 @@
* Please see COPYING for details * Please see COPYING for details
* *
* Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen * Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
* Copyright (c) 2005-2012 Brenden Matthews, Philip Kovacs, et. al. * Copyright (c) 2005-2018 Brenden Matthews, Philip Kovacs, et. al.
* (see AUTHORS) * (see AUTHORS)
* All rights reserved. * All rights reserved.
* *
@@ -27,29 +26,27 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
* *
*/ */
#include "config.h"
#include "conky.h"
#include "algebra.h" #include "algebra.h"
#include "logging.h"
#include <ctype.h> #include <ctype.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <memory> #include <memory>
#include "config.h"
#include "conky.h"
#include "logging.h"
/* find the operand in the given expression /* find the operand in the given expression
* returns the index of the first op character or -1 on error * returns the index of the first op character or -1 on error
*/ */
int find_match_op(const char *expr) int find_match_op(const char *expr) {
{
unsigned int idx; unsigned int idx;
for (idx = 0; idx < strlen(expr); idx++) { for (idx = 0; idx < strlen(expr); idx++) {
switch (expr[idx]) { switch (expr[idx]) {
case '=': case '=':
case '!': case '!':
if (expr[idx + 1] != '=') if (expr[idx + 1] != '=') return -1;
return -1;
/* fall through */ /* fall through */
case '<': case '<':
case '>': case '>':
@@ -60,13 +57,11 @@ int find_match_op(const char *expr)
return -1; return -1;
} }
int get_match_type(const char *expr) int get_match_type(const char *expr) {
{
int idx; int idx;
const char *str; const char *str;
if ((idx = find_match_op(expr)) == -1) if ((idx = find_match_op(expr)) == -1) return -1;
return -1;
str = expr + idx; str = expr + idx;
if (*str == '=' && *(str + 1) == '=') if (*str == '=' && *(str + 1) == '=')
@@ -74,19 +69,15 @@ int get_match_type(const char *expr)
else if (*str == '!' && *(str + 1) == '=') else if (*str == '!' && *(str + 1) == '=')
return OP_NEQ; return OP_NEQ;
else if (*str == '>') { else if (*str == '>') {
if (*(str + 1) == '=') if (*(str + 1) == '=') return OP_GEQ;
return OP_GEQ;
return OP_GT; return OP_GT;
} else if (*str == '<') { } else if (*str == '<') {
if (*(str + 1) == '=') if (*(str + 1) == '=') return OP_LEQ;
return OP_LEQ;
return OP_LT; return OP_LT;
} }
return -1; return -1;
} }
/* generic compare function /* generic compare function
* *
* v is actually the difference of the compared values. For strings * v is actually the difference of the compared values. For strings
@@ -95,61 +86,57 @@ int get_match_type(const char *expr)
*/ */
#define COMPARE(v, t) \ #define COMPARE(v, t) \
switch (t) { \ switch (t) { \
case OP_GT: return (v > 0); \ case OP_GT: \
case OP_LT: return (v < 0); \ return (v > 0); \
case OP_EQ: return (v == 0); \ case OP_LT: \
case OP_GEQ: return (v >= 0); \ return (v < 0); \
case OP_LEQ: return (v <= 0); \ case OP_EQ: \
case OP_NEQ: return (v != 0); \ return (v == 0); \
case OP_GEQ: \
return (v >= 0); \
case OP_LEQ: \
return (v <= 0); \
case OP_NEQ: \
return (v != 0); \
} \ } \
return 0 return 0
int lcompare(long a, enum match_type mtype, long b) int lcompare(long a, enum match_type mtype, long b) {
{
DBGP2("comparing longs '%ld' and '%ld'", a, b); DBGP2("comparing longs '%ld' and '%ld'", a, b);
COMPARE((a - b), mtype); COMPARE((a - b), mtype);
} }
int dcompare(double a, enum match_type mtype, double b) int dcompare(double a, enum match_type mtype, double b) {
{
DBGP2("comparing doubles '%.lf' and '%.lf'", a, b); DBGP2("comparing doubles '%.lf' and '%.lf'", a, b);
COMPARE((a - b), mtype); COMPARE((a - b), mtype);
} }
int scompare(const char *a, enum match_type mtype, const char *b) int scompare(const char *a, enum match_type mtype, const char *b) {
{
DBGP2("comparing strings '%s' and '%s'", a, b); DBGP2("comparing strings '%s' and '%s'", a, b);
COMPARE(strcmp(a, b), mtype); COMPARE(strcmp(a, b), mtype);
} }
enum arg_type get_arg_type(const char *arg) enum arg_type get_arg_type(const char *arg) {
{
const char *p, *e; const char *p, *e;
p = arg; p = arg;
e = arg + strlen(arg) - 1; e = arg + strlen(arg) - 1;
while (p != e && *e && *e == ' ') while (p != e && *e && *e == ' ') e--;
e--; while (p != e && *p == ' ') p++;
while (p != e && *p == ' ')
p++;
if (*p == '"' && *e == '"') if (*p == '"' && *e == '"') return ARG_STRING;
return ARG_STRING;
if (*p == '-') // allow negative values if (*p == '-') // allow negative values
p++; p++;
while (p <= e) { while (p <= e) {
if (!isdigit(*p)) if (!isdigit(*p)) break;
break;
p++; p++;
} }
if (p == e+1) if (p == e + 1) return ARG_LONG;
return ARG_LONG;
if (*p == '.') { if (*p == '.') {
p++; p++;
while (p <= e) { while (p <= e) {
if (!isdigit(*p)) if (!isdigit(*p)) return ARG_BAD;
return ARG_BAD;
p++; p++;
} }
return ARG_DOUBLE; return ARG_DOUBLE;
@@ -157,23 +144,18 @@ enum arg_type get_arg_type(const char *arg)
return ARG_BAD; return ARG_BAD;
} }
char *arg_to_string(const char *arg) char *arg_to_string(const char *arg) {
{
const char *start; const char *start;
int len; int len;
start = arg; start = arg;
len = 0; len = 0;
while (*start && *start == ' ') while (*start && *start == ' ') start++;
start++; if (!(*(start++) == '"')) return NULL;
if (!(*(start++) == '"')) while (start[len] != '"') len++;
return NULL;
while (start[len] != '"')
len++;
return strndup(start, len); return strndup(start, len);
} }
double arg_to_double(const char *arg) double arg_to_double(const char *arg) {
{
double d; double d;
if (sscanf(arg, "%lf", &d) != 1) { if (sscanf(arg, "%lf", &d) != 1) {
NORM_ERR("converting '%s' to double failed", arg); NORM_ERR("converting '%s' to double failed", arg);
@@ -181,8 +163,7 @@ double arg_to_double(const char *arg)
} }
return d; return d;
} }
long arg_to_long(const char *arg) long arg_to_long(const char *arg) {
{
long l; long l;
if (sscanf(arg, "%ld", &l) != 1) { if (sscanf(arg, "%ld", &l) != 1) {
NORM_ERR("converting '%s' to long failed", arg); NORM_ERR("converting '%s' to long failed", arg);
@@ -190,8 +171,7 @@ long arg_to_long(const char *arg)
} }
return l; return l;
} }
int compare(const char *expr) int compare(const char *expr) {
{
char *expr_dup; char *expr_dup;
int idx, mtype; int idx, mtype;
enum arg_type type1, type2; enum arg_type type1, type2;
@@ -208,8 +188,7 @@ int compare(const char *expr)
expr_dup = strdup(expr); expr_dup = strdup(expr);
expr_dup[idx] = '\0'; expr_dup[idx] = '\0';
if (expr_dup[idx + 1] == '=') if (expr_dup[idx + 1] == '=') expr_dup[++idx] = '\0';
expr_dup[++idx] = '\0';
type1 = get_arg_type(expr_dup); type1 = get_arg_type(expr_dup);
type2 = get_arg_type(expr_dup + idx + 1); type2 = get_arg_type(expr_dup + idx + 1);
@@ -218,19 +197,16 @@ int compare(const char *expr)
free(expr_dup); free(expr_dup);
return -2; return -2;
} }
if (type1 == ARG_LONG && type2 == ARG_DOUBLE) if (type1 == ARG_LONG && type2 == ARG_DOUBLE) type1 = ARG_DOUBLE;
type1 = ARG_DOUBLE; if (type1 == ARG_DOUBLE && type2 == ARG_LONG) type2 = ARG_DOUBLE;
if (type1 == ARG_DOUBLE && type2 == ARG_LONG)
type2 = ARG_DOUBLE;
if (type1 != type2) { if (type1 != type2) {
NORM_ERR("trying to compare args '%s' and '%s' of different type", NORM_ERR("trying to compare args '%s' and '%s' of different type", expr_dup,
expr_dup, (expr_dup + idx + 1)); (expr_dup + idx + 1));
free(expr_dup); free(expr_dup);
return -2; return -2;
} }
switch (type1) { switch (type1) {
case ARG_STRING: case ARG_STRING: {
{
char *a, *b; char *a, *b;
a = arg_to_string(expr_dup); a = arg_to_string(expr_dup);
b = arg_to_string(expr_dup + idx + 1); b = arg_to_string(expr_dup + idx + 1);
@@ -257,13 +233,13 @@ int compare(const char *expr)
return -2; return -2;
} }
int check_if_match(struct text_object *obj) int check_if_match(struct text_object *obj) {
{
std::unique_ptr<char[]> expression(new char[max_user_text.get(*state)]); std::unique_ptr<char[]> expression(new char[max_user_text.get(*state)]);
int val; int val;
int result = 1; int result = 1;
generate_text_internal(expression.get(), max_user_text.get(*state), *obj->sub); generate_text_internal(expression.get(), max_user_text.get(*state),
*obj->sub);
DBGP("parsed arg into '%s'", expression.get()); DBGP("parsed arg into '%s'", expression.get());
val = compare(expression.get()); val = compare(expression.get());

View File

@@ -1,5 +1,4 @@
/* -*- mode: c; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*- /*
* vim: ts=4 sw=4 noet ai cindent syntax=c
* *
* Conky, a system monitor, based on torsmo * Conky, a system monitor, based on torsmo
* *
@@ -10,7 +9,7 @@
* Please see COPYING for details * Please see COPYING for details
* *
* Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen * Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
* Copyright (c) 2005-2012 Brenden Matthews, Philip Kovacs, et. al. * Copyright (c) 2005-2018 Brenden Matthews, Philip Kovacs, et. al.
* (see AUTHORS) * (see AUTHORS)
* All rights reserved. * All rights reserved.
* *

View File

@@ -1,5 +1,4 @@
/* -*- mode: c++; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*- /*
* vim: ts=4 sw=4 noet ai cindent syntax=cpp
* *
* apcupsd.c: conky module for APC UPS daemon monitoring * apcupsd.c: conky module for APC UPS daemon monitoring
* *
@@ -22,14 +21,14 @@
* *
*/ */
#include "conky.h"
#include "apcupsd.h" #include "apcupsd.h"
#include "conky.h"
#include "logging.h" #include "logging.h"
#include "text_object.h" #include "text_object.h"
#include <errno.h> #include <errno.h>
#include <netinet/in.h>
#include <netdb.h> #include <netdb.h>
#include <netinet/in.h>
#include <sys/time.h> #include <sys/time.h>
#include <unistd.h> #include <unistd.h>
@@ -51,19 +50,18 @@ enum _apcupsd_items {
/* type for data exchange with main thread */ /* type for data exchange with main thread */
#define APCUPSD_MAXSTR 32 #define APCUPSD_MAXSTR 32
typedef struct apcupsd_s { typedef struct apcupsd_s {
char items[_APCUPSD_COUNT][APCUPSD_MAXSTR+1]; /* e.g. items[APCUPSD_STATUS] */ char items[_APCUPSD_COUNT]
[APCUPSD_MAXSTR + 1]; /* e.g. items[APCUPSD_STATUS] */
char host[64]; char host[64];
int port; int port;
} APCUPSD_S, *PAPCUPSD_S; } APCUPSD_S, *PAPCUPSD_S;
static APCUPSD_S apcupsd; static APCUPSD_S apcupsd;
// //
// encapsulated recv() // encapsulated recv()
// //
static int net_recv_ex(int sock, void *buf, int size, struct timeval *tv) static int net_recv_ex(int sock, void *buf, int size, struct timeval *tv) {
{
fd_set fds; fd_set fds;
int res; int res;
@@ -99,8 +97,7 @@ static int net_recv_ex(int sock, void *buf, int size, struct timeval *tv)
// //
// read whole buffer or fail // read whole buffer or fail
// //
static int net_recv(int sock, void* buf, int size) static int net_recv(int sock, void *buf, int size) {
{
int todo = size; int todo = size;
int off = 0; int off = 0;
int len; int len;
@@ -118,8 +115,7 @@ static int net_recv(int sock, void* buf, int size)
// //
// get one response line // get one response line
// //
static int get_line(int sock, char line[], short linesize) static int get_line(int sock, char line[], short linesize) {
{
// get the line length // get the line length
short sz; short sz;
if (!net_recv(sock, &sz, sizeof(sz))) return -1; if (!net_recv(sock, &sz, sizeof(sz))) return -1;
@@ -141,7 +137,8 @@ static int get_line(int sock, char line[], short linesize)
if (!strncmp(NAME, line, sizeof(NAME) - 1)) { \ if (!strncmp(NAME, line, sizeof(NAME) - 1)) { \
strncpy(apc->items[FIELD], line + 11, APCUPSD_MAXSTR); \ strncpy(apc->items[FIELD], line + 11, APCUPSD_MAXSTR); \
/* remove trailing newline and assure termination */ \ /* remove trailing newline and assure termination */ \
apc->items[FIELD][len-11 > APCUPSD_MAXSTR ? APCUPSD_MAXSTR : len-12] = 0; \ apc->items[FIELD][len - 11 > APCUPSD_MAXSTR ? APCUPSD_MAXSTR : len - 12] = \
0; \
if (FIRST) { \ if (FIRST) { \
char *c; \ char *c; \
for (c = apc->items[FIELD]; *c; ++c) \ for (c = apc->items[FIELD]; *c; ++c) \
@@ -155,8 +152,7 @@ static int get_line(int sock, char line[], short linesize)
// //
// fills in the data received from a socket // fills in the data received from a socket
// //
static int fill_items(int sock, PAPCUPSD_S apc) static int fill_items(int sock, PAPCUPSD_S apc) {
{
char line[512]; char line[512];
int len; int len;
while ((len = get_line(sock, line, sizeof(line)))) { while ((len = get_line(sock, line, sizeof(line)))) {
@@ -180,8 +176,7 @@ static int fill_items(int sock, PAPCUPSD_S apc)
// //
// Conky update function for apcupsd data // Conky update function for apcupsd data
// //
int update_apcupsd(void) int update_apcupsd(void) {
{
int i; int i;
APCUPSD_S apc; APCUPSD_S apc;
int sock; int sock;
@@ -230,7 +225,8 @@ int update_apcupsd(void)
// //
sz = htons(6); sz = htons(6);
// no waiting to become writeable is really needed // no waiting to become writeable is really needed
if (send(sock, &sz, sizeof(sz), 0) != sizeof(sz) || send(sock, "status", 6, 0) != 6) { if (send(sock, &sz, sizeof(sz), 0) != sizeof(sz) ||
send(sock, "status", 6, 0) != 6) {
perror("send"); perror("send");
break; break;
} }
@@ -251,28 +247,25 @@ int update_apcupsd(void)
return 0; return 0;
} }
int apcupsd_scan_arg(const char *arg) int apcupsd_scan_arg(const char *arg) {
{
char host[64]; char host[64];
int port; int port;
if (sscanf(arg, "%63s %d", host, &port) != 2) if (sscanf(arg, "%63s %d", host, &port) != 2) return 1;
return 1;
apcupsd.port = port; apcupsd.port = port;
strncpy(apcupsd.host, host, sizeof(apcupsd.host)); strncpy(apcupsd.host, host, sizeof(apcupsd.host));
return 0; return 0;
} }
double apcupsd_loadbarval(struct text_object *obj) double apcupsd_loadbarval(struct text_object *obj) {
{
(void)obj; (void)obj;
return atof(apcupsd.items[APCUPSD_LOAD]); return atof(apcupsd.items[APCUPSD_LOAD]);
} }
#define APCUPSD_PRINT_GENERATOR(name, idx) \ #define APCUPSD_PRINT_GENERATOR(name, idx) \
void print_apcupsd_##name(struct text_object *obj, char *p, int p_max_size) \ void print_apcupsd_##name(struct text_object *obj, char *p, \
{ \ int p_max_size) { \
(void)obj; \ (void)obj; \
snprintf(p, p_max_size, "%s", apcupsd.items[APCUPSD_##idx]); \ snprintf(p, p_max_size, "%s", apcupsd.items[APCUPSD_##idx]); \
} }

View File

@@ -1,5 +1,4 @@
/* -*- mode: c; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*- /*
* vim: ts=4 sw=4 noet ai cindent syntax=c
* *
* apcupsd.h: conky module for APC UPS daemon monitoring * apcupsd.h: conky module for APC UPS daemon monitoring
* *

View File

@@ -1,5 +1,4 @@
/* -*- mode: c++; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*- /*
* vim: ts=4 sw=4 noet ai cindent syntax=cpp
* *
* audacious.c: conky support for audacious music player * audacious.c: conky support for audacious music player
* *
@@ -26,35 +25,29 @@
#include <cmath> #include <cmath>
#include <mutex>
#include "audacious.h"
#include "conky.h" #include "conky.h"
#include "logging.h" #include "logging.h"
#include "audacious.h"
#include <mutex>
#include "update-cb.hh" #include "update-cb.hh"
#include <glib.h> #include <glib.h>
#ifdef NEW_AUDACIOUS_FOUND #ifdef NEW_AUDACIOUS_FOUND
#include <glib-object.h>
#include <audacious/audctrl.h> #include <audacious/audctrl.h>
#include <audacious/dbus.h> #include <audacious/dbus.h>
#include <glib-object.h>
#else /* NEW_AUDACIOUS_FOUND */ #else /* NEW_AUDACIOUS_FOUND */
#include <audacious/beepctrl.h> #include <audacious/beepctrl.h>
#define audacious_remote_is_running(x) \ #define audacious_remote_is_running(x) xmms_remote_is_running(x)
xmms_remote_is_running(x) #define audacious_remote_is_paused(x) xmms_remote_is_paused(x)
#define audacious_remote_is_paused(x) \ #define audacious_remote_is_playing(x) xmms_remote_is_playing(x)
xmms_remote_is_paused(x) #define audacious_remote_get_playlist_pos(x) xmms_remote_get_playlist_pos(x)
#define audacious_remote_is_playing(x) \
xmms_remote_is_playing(x)
#define audacious_remote_get_playlist_pos(x) \
xmms_remote_get_playlist_pos(x)
#define audacious_remote_get_playlist_title(x, y) \ #define audacious_remote_get_playlist_title(x, y) \
xmms_remote_get_playlist_title(x, y) xmms_remote_get_playlist_title(x, y)
#define audacious_remote_get_playlist_time(x, y) \ #define audacious_remote_get_playlist_time(x, y) \
xmms_remote_get_playlist_time(x, y) xmms_remote_get_playlist_time(x, y)
#define audacious_remote_get_output_time(x) \ #define audacious_remote_get_output_time(x) xmms_remote_get_output_time(x)
xmms_remote_get_output_time(x) #define audacious_remote_get_info(w, x, y, z) xmms_remote_get_info(w, x, y, z)
#define audacious_remote_get_info(w, x, y, z) \
xmms_remote_get_info(w, x, y, z)
#define audacious_remote_get_playlist_file(x, y) \ #define audacious_remote_get_playlist_file(x, y) \
xmms_remote_get_playlist_file(x, y) xmms_remote_get_playlist_file(x, y)
#define audacious_remote_get_playlist_length(x) \ #define audacious_remote_get_playlist_length(x) \
@@ -64,7 +57,8 @@
namespace { namespace {
enum aud_status { AS_NOT_RUNNING, AS_PAUSED, AS_PLAYING, AS_STOPPED }; enum aud_status { AS_NOT_RUNNING, AS_PAUSED, AS_PLAYING, AS_STOPPED };
const char * const as_message[] = { "Not running", "Paused", "Playing", "Stopped" }; const char *const as_message[] = {"Not running", "Paused", "Playing",
"Stopped"};
struct aud_result { struct aud_result {
std::string title; std::string title;
@@ -80,9 +74,15 @@ namespace {
aud_status status; aud_status status;
aud_result() aud_result()
: length(0), position(0), bitrate(0), frequency(0), channels(0), playlist_length(0), : length(0),
playlist_position(0), main_volume(0), status(AS_NOT_RUNNING) position(0),
{} bitrate(0),
frequency(0),
channels(0),
playlist_length(0),
playlist_position(0),
main_volume(0),
status(AS_NOT_RUNNING) {}
}; };
class audacious_cb : public conky::callback<aud_result> { class audacious_cb : public conky::callback<aud_result> {
@@ -98,9 +98,7 @@ namespace {
virtual void work(); virtual void work();
public: public:
audacious_cb(uint32_t period) audacious_cb(uint32_t period) : Base(period, false, Tuple()) {
: Base(period, false, Tuple())
{
#ifdef NEW_AUDACIOUS_FOUND #ifdef NEW_AUDACIOUS_FOUND
g_type_init(); g_type_init();
DBusGConnection *connection = dbus_g_bus_get(DBUS_BUS_SESSION, NULL); DBusGConnection *connection = dbus_g_bus_get(DBUS_BUS_SESSION, NULL);
@@ -108,17 +106,16 @@ namespace {
throw std::runtime_error("unable to establish dbus connection"); throw std::runtime_error("unable to establish dbus connection");
session = dbus_g_proxy_new_for_name(connection, AUDACIOUS_DBUS_SERVICE, session = dbus_g_proxy_new_for_name(connection, AUDACIOUS_DBUS_SERVICE,
AUDACIOUS_DBUS_PATH, AUDACIOUS_DBUS_INTERFACE); AUDACIOUS_DBUS_PATH,
if (!session) AUDACIOUS_DBUS_INTERFACE);
throw std::runtime_error("unable to create dbus proxy"); if (!session) throw std::runtime_error("unable to create dbus proxy");
#else #else
session = 0; session = 0;
#endif /* NEW_AUDACIOUS_FOUND */ #endif /* NEW_AUDACIOUS_FOUND */
} }
#ifdef NEW_AUDACIOUS_FOUND #ifdef NEW_AUDACIOUS_FOUND
~audacious_cb() ~audacious_cb() {
{
/* release reference to dbus proxy */ /* release reference to dbus proxy */
g_object_unref(session); g_object_unref(session);
} }
@@ -128,8 +125,7 @@ namespace {
/* --------------------------------------------------- /* ---------------------------------------------------
* Worker thread function for audacious data sampling. * Worker thread function for audacious data sampling.
* --------------------------------------------------- */ * --------------------------------------------------- */
void audacious_cb::work() void audacious_cb::work() {
{
aud_result tmp; aud_result tmp;
gchar *psong, *pfilename; gchar *psong, *pfilename;
psong = NULL; psong = NULL;
@@ -159,16 +155,19 @@ namespace {
} }
/* Current song length */ /* Current song length */
tmp.length = audacious_remote_get_playlist_time(session, tmp.playlist_position); tmp.length =
audacious_remote_get_playlist_time(session, tmp.playlist_position);
/* Current song position */ /* Current song position */
tmp.position = audacious_remote_get_output_time(session); tmp.position = audacious_remote_get_output_time(session);
/* Current song bitrate, frequency, channels */ /* Current song bitrate, frequency, channels */
audacious_remote_get_info(session, &tmp.bitrate, &tmp.frequency, &tmp.channels); audacious_remote_get_info(session, &tmp.bitrate, &tmp.frequency,
&tmp.channels);
/* Current song filename */ /* Current song filename */
pfilename = audacious_remote_get_playlist_file(session, tmp.playlist_position); pfilename =
audacious_remote_get_playlist_file(session, tmp.playlist_position);
if (pfilename) { if (pfilename) {
tmp.filename = pfilename; tmp.filename = pfilename;
g_free(pfilename); g_free(pfilename);
@@ -187,47 +186,42 @@ namespace {
} }
} }
aud_result get_res() aud_result get_res() {
{
uint32_t period = std::max( uint32_t period = std::max(
lround(music_player_interval.get(*state)/active_update_interval()), 1l lround(music_player_interval.get(*state) / active_update_interval()), 1l);
);
return conky::register_cb<audacious_cb>(period)->get_result_copy(); return conky::register_cb<audacious_cb>(period)->get_result_copy();
} }
} } // namespace
void print_audacious_status(struct text_object *, char *p, int p_max_size) void print_audacious_status(struct text_object *, char *p, int p_max_size) {
{
const aud_result &res = get_res(); const aud_result &res = get_res();
snprintf(p, p_max_size, "%s", as_message[res.status]); snprintf(p, p_max_size, "%s", as_message[res.status]);
} }
void print_audacious_title(struct text_object *obj, char *p, int p_max_size) void print_audacious_title(struct text_object *obj, char *p, int p_max_size) {
{
snprintf(p, std::min(obj->data.i, p_max_size), "%s", get_res().title.c_str()); snprintf(p, std::min(obj->data.i, p_max_size), "%s", get_res().title.c_str());
} }
void print_audacious_filename(struct text_object *obj, char *p, int p_max_size) void print_audacious_filename(struct text_object *obj, char *p,
{ int p_max_size) {
snprintf(p, std::min(obj->data.i, p_max_size), "%s", get_res().filename.c_str()); snprintf(p, std::min(obj->data.i, p_max_size), "%s",
get_res().filename.c_str());
} }
double audacious_barval(struct text_object *) double audacious_barval(struct text_object *) {
{
const aud_result &res = get_res(); const aud_result &res = get_res();
return (double)res.position / res.length; return (double)res.position / res.length;
} }
#define AUDACIOUS_TIME_GENERATOR(name) \ #define AUDACIOUS_TIME_GENERATOR(name) \
void print_audacious_##name(struct text_object *, char *p, int p_max_size) \ void print_audacious_##name(struct text_object *, char *p, int p_max_size) { \
{ \
const aud_result &res = get_res(); \ const aud_result &res = get_res(); \
int sec = res.name / 1000; \ int sec = res.name / 1000; \
snprintf(p, p_max_size, "%d:%.2d", sec / 60, sec % 60); \ snprintf(p, p_max_size, "%d:%.2d", sec / 60, sec % 60); \
} \ } \
\ \
void print_audacious_##name##_seconds(struct text_object *, char *p, int p_max_size) \ void print_audacious_##name##_seconds(struct text_object *, char *p, \
{ \ int p_max_size) { \
snprintf(p, p_max_size, "%d", get_res().name); \ snprintf(p, p_max_size, "%d", get_res().name); \
} }
@@ -235,8 +229,7 @@ AUDACIOUS_TIME_GENERATOR(length)
AUDACIOUS_TIME_GENERATOR(position) AUDACIOUS_TIME_GENERATOR(position)
#define AUDACIOUS_INT_GENERATOR(name, offset) \ #define AUDACIOUS_INT_GENERATOR(name, offset) \
void print_audacious_##name(struct text_object *, char *p, int p_max_size) \ void print_audacious_##name(struct text_object *, char *p, int p_max_size) { \
{ \
snprintf(p, p_max_size, "%d", get_res().name + offset); \ snprintf(p, p_max_size, "%d", get_res().name + offset); \
} }

View File

@@ -1,5 +1,4 @@
/* -*- mode: c++; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*- /*
* vim: ts=4 sw=4 noet ai cindent syntax=cpp
* *
* audacious.h: conky support for audacious music player * audacious.h: conky support for audacious music player
* *

View File

@@ -1,5 +1,4 @@
/* -*- mode: c++; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*- /*
* vim: ts=4 sw=4 noet ai cindent syntax=cpp
* *
* Conky, a system monitor, based on torsmo * Conky, a system monitor, based on torsmo
* *
@@ -9,7 +8,7 @@
* *
* Please see COPYING for details * Please see COPYING for details
* *
* Copyright (c) 2005-2012 Brenden Matthews, Philip Kovacs, et. al. * Copyright (c) 2005-2018 Brenden Matthews, Philip Kovacs, et. al.
* (see AUTHORS) * (see AUTHORS)
* All rights reserved. * All rights reserved.
* *
@@ -31,8 +30,8 @@
#include "conky.h" #include "conky.h"
#include "logging.h" #include "logging.h"
#include <bmp/dbus.hh>
#include <dbus/dbus-glib.h> #include <dbus/dbus-glib.h>
#include <bmp/dbus.hh>
#define DBUS_TYPE_G_STRING_VALUE_HASHTABLE \ #define DBUS_TYPE_G_STRING_VALUE_HASHTABLE \
(dbus_g_type_get_map("GHashTable", G_TYPE_STRING, G_TYPE_VALUE)) (dbus_g_type_get_map("GHashTable", G_TYPE_STRING, G_TYPE_VALUE))
@@ -44,8 +43,7 @@ static char *unknown = "unknown";
void fail(GError *error, struct information *); void fail(GError *error, struct information *);
void update_bmpx() void update_bmpx() {
{
GError *error = NULL; GError *error = NULL;
struct information *current_info = &info; struct information *current_info = &info;
gint current_track; gint current_track;
@@ -62,8 +60,8 @@ void update_bmpx()
return; return;
} }
remote_object = dbus_g_proxy_new_for_name(bus, BMP_DBUS_SERVICE, remote_object = dbus_g_proxy_new_for_name(
BMP_DBUS_PATH__BMP, BMP_DBUS_INTERFACE__BMP); bus, BMP_DBUS_SERVICE, BMP_DBUS_PATH__BMP, BMP_DBUS_INTERFACE__BMP);
if (!remote_object) { if (!remote_object) {
NORM_ERR("BMPx error 2: %s\n", error->message); NORM_ERR("BMPx error 2: %s\n", error->message);
fail(error, current_info); fail(error, current_info);
@@ -75,7 +73,8 @@ void update_bmpx()
if (connected == 1) { if (connected == 1) {
if (dbus_g_proxy_call(remote_object, "GetCurrentTrack", &error, if (dbus_g_proxy_call(remote_object, "GetCurrentTrack", &error,
G_TYPE_INVALID, G_TYPE_INT, &current_track, G_TYPE_INVALID)) { G_TYPE_INVALID, G_TYPE_INT, &current_track,
G_TYPE_INVALID)) {
} else { } else {
NORM_ERR("BMPx error 3: %s\n", error->message); NORM_ERR("BMPx error 3: %s\n", error->message);
fail(error, current_info); fail(error, current_info);
@@ -113,8 +112,7 @@ void update_bmpx()
} }
} }
void fail(GError *error, struct information *current_info) void fail(GError *error, struct information *current_info) {
{
if (error) { if (error) {
g_error_free(error); g_error_free(error);
} }
@@ -138,8 +136,7 @@ void fail(GError *error, struct information *current_info)
} }
#define BMPX_PRINT_GENERATOR(name, fmt) \ #define BMPX_PRINT_GENERATOR(name, fmt) \
void print_bmpx_##name(struct text_object *obj, char *p, int p_max_size) \ void print_bmpx_##name(struct text_object *obj, char *p, int p_max_size) { \
{ \
(void)obj; \ (void)obj; \
snprintf(p, p_max_size, fmt, info.bmpx.name); \ snprintf(p, p_max_size, fmt, info.bmpx.name); \
} }
@@ -152,4 +149,3 @@ BMPX_PRINT_GENERATOR(track, "%i")
BMPX_PRINT_GENERATOR(bitrate, "%i") BMPX_PRINT_GENERATOR(bitrate, "%i")
#undef BMPX_PRINT_GENERATOR #undef BMPX_PRINT_GENERATOR

View File

@@ -1,11 +1,10 @@
/* -*- mode: c; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*- /*
* vim: ts=4 sw=4 noet ai cindent syntax=c
* *
* Conky, a system monitor, based on torsmo * Conky, a system monitor, based on torsmo
* *
* Please see COPYING for details * Please see COPYING for details
* *
* Copyright (c) 2005-2012 Brenden Matthews, Philip Kovacs, et. al. * Copyright (c) 2005-2018 Brenden Matthews, Philip Kovacs, et. al.
* (see AUTHORS) * (see AUTHORS)
* All rights reserved. * All rights reserved.
* *

View File

@@ -1,5 +1,4 @@
/* -*- mode: c++; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*- /*
* vim: ts=4 sw=4 noet ai cindent syntax=cpp
* *
* Conky, a system monitor, based on torsmo * Conky, a system monitor, based on torsmo
* *
@@ -10,7 +9,7 @@
* Please see COPYING for details * Please see COPYING for details
* *
* Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen * Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
* Copyright (c) 2005-2012 Brenden Matthews, Philip Kovacs, et. al. * Copyright (c) 2005-2018 Brenden Matthews, Philip Kovacs, et. al.
* (see AUTHORS) * (see AUTHORS)
* All rights reserved. * All rights reserved.
* *
@@ -27,13 +26,13 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
* *
*/ */
#include <fcntl.h>
#include <machine/apm_bios.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include "config.h" #include "config.h"
#include "conky.h" #include "conky.h"
#include "text_object.h" #include "text_object.h"
#include <fcntl.h>
#include <sys/ioctl.h>
#include <machine/apm_bios.h>
#include <unistd.h>
#define APMDEV "/dev/apm" #define APMDEV "/dev/apm"
#define APM_UNKNOWN 255 #define APM_UNKNOWN 255
@@ -50,8 +49,7 @@
#define APM_BATT_CHARGING 3 #define APM_BATT_CHARGING 3
#endif #endif
static int apm_getinfo(int fd, apm_info_t aip) static int apm_getinfo(int fd, apm_info_t aip) {
{
#ifdef __OpenBSD__ #ifdef __OpenBSD__
if (ioctl(fd, APM_IOC_GETPOWER, aip) == -1) { if (ioctl(fd, APM_IOC_GETPOWER, aip) == -1) {
#else #else
@@ -63,8 +61,7 @@ static int apm_getinfo(int fd, apm_info_t aip)
return 0; return 0;
} }
void print_apm_adapter(struct text_object *obj, char *p, int p_max_size) void print_apm_adapter(struct text_object *obj, char *p, int p_max_size) {
{
int fd; int fd;
const char *out; const char *out;
#ifdef __OpenBSD__ #ifdef __OpenBSD__
@@ -99,8 +96,7 @@ void print_apm_adapter(struct text_object *obj, char *p, int p_max_size)
#ifdef __OpenBSD__ #ifdef __OpenBSD__
#define ai_batt_stat battery_state #define ai_batt_stat battery_state
#endif #endif
if (a_info.ai_batt_stat if (a_info.ai_batt_stat == APM_BATT_CHARGING) {
== APM_BATT_CHARGING) {
out = "charging"; out = "charging";
} else { } else {
out = "on-line"; out = "on-line";
@@ -113,8 +109,7 @@ void print_apm_adapter(struct text_object *obj, char *p, int p_max_size)
snprintf(p, p_max_size, "%s", out); snprintf(p, p_max_size, "%s", out);
} }
void print_apm_battery_life(struct text_object *obj, char *p, int p_max_size) void print_apm_battery_life(struct text_object *obj, char *p, int p_max_size) {
{
int fd; int fd;
u_int batt_life; u_int batt_life;
const char *out; const char *out;
@@ -155,8 +150,7 @@ void print_apm_battery_life(struct text_object *obj, char *p, int p_max_size)
snprintf(p, p_max_size, "%s", out); snprintf(p, p_max_size, "%s", out);
} }
void print_apm_battery_time(struct text_object *obj, char *p, int p_max_size) void print_apm_battery_time(struct text_object *obj, char *p, int p_max_size) {
{
int fd; int fd;
int batt_time; int batt_time;
#ifdef __OpenBSD__ #ifdef __OpenBSD__
@@ -190,7 +184,6 @@ void print_apm_battery_time(struct text_object *obj, char *p, int p_max_size)
if (batt_time == -1) { if (batt_time == -1) {
snprintf(p, p_max_size, "unknown"); snprintf(p, p_max_size, "unknown");
} else } else
#ifdef __OpenBSD__ #ifdef __OpenBSD__
{ {
h = batt_time / 60; h = batt_time / 60;

View File

@@ -1,5 +1,4 @@
/* -*- mode: c; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*- /*
* vim: ts=4 sw=4 noet ai cindent syntax=c
* *
* Conky, a system monitor, based on torsmo * Conky, a system monitor, based on torsmo
* *
@@ -10,7 +9,7 @@
* Please see COPYING for details * Please see COPYING for details
* *
* Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen * Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
* Copyright (c) 2005-2012 Brenden Matthews, Philip Kovacs, et. al. * Copyright (c) 2005-2018 Brenden Matthews, Philip Kovacs, et. al.
* (see AUTHORS) * (see AUTHORS)
* All rights reserved. * All rights reserved.
* *

View File

@@ -1,5 +1,4 @@
/* -*- mode: c++; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*- /*
* vim: ts=4 sw=4 noet ai cindent syntax=cpp
* *
* Conky, a system monitor, based on torsmo * Conky, a system monitor, based on torsmo
* *
@@ -25,8 +24,8 @@
#include "c++wrap.hh" #include "c++wrap.hh"
#include <unistd.h>
#include <stdio.h> #include <stdio.h>
#include <unistd.h>
/* force use of POSIX strerror_r instead of non-portable GNU specific */ /* force use of POSIX strerror_r instead of non-portable GNU specific */
#ifdef _GNU_SOURCE #ifdef _GNU_SOURCE
@@ -42,10 +41,8 @@
#include <fcntl.h> #include <fcntl.h>
namespace { namespace {
int pipe2_emulate(int pipefd[2], int flags) int pipe2_emulate(int pipefd[2], int flags) {
{ if (pipe(pipefd) == -1) return -1;
if(pipe(pipefd) == -1)
return -1;
if (flags & O_CLOEXEC) { if (flags & O_CLOEXEC) {
// we emulate O_CLOEXEC if the system does not have it // we emulate O_CLOEXEC if the system does not have it
@@ -53,11 +50,9 @@ namespace {
for (int i = 0; i < 2; ++i) { for (int i = 0; i < 2; ++i) {
int r = fcntl(pipefd[i], F_GETFD); int r = fcntl(pipefd[i], F_GETFD);
if(r == -1) if (r == -1) return -1;
return -1;
if(fcntl(pipefd[i], F_SETFD, r | FD_CLOEXEC) == -1) if (fcntl(pipefd[i], F_SETFD, r | FD_CLOEXEC) == -1) return -1;
return -1;
} }
} }
@@ -65,21 +60,19 @@ namespace {
} }
int (*const pipe2_ptr)(int[2], int) = &pipe2_emulate; int (*const pipe2_ptr)(int[2], int) = &pipe2_emulate;
} } // namespace
#else #else
int (*const pipe2_ptr)(int[2], int) = &pipe2; int (*const pipe2_ptr)(int[2], int) = &pipe2;
#endif #endif
std::string strerror_r(int errnum) std::string strerror_r(int errnum) {
{
static thread_local char buf[100]; static thread_local char buf[100];
if (strerror_r(errnum, buf, sizeof buf) != 0) if (strerror_r(errnum, buf, sizeof buf) != 0)
snprintf(buf, sizeof buf, "Unknown error %i", errnum); snprintf(buf, sizeof buf, "Unknown error %i", errnum);
return buf; return buf;
} }
std::pair<int, int> pipe2(int flags) std::pair<int, int> pipe2(int flags) {
{
int fd[2]; int fd[2];
if (pipe2_ptr(fd, flags) == -1) if (pipe2_ptr(fd, flags) == -1)
throw errno_error("pipe2"); throw errno_error("pipe2");

View File

@@ -1,5 +1,4 @@
/* -*- mode: c++; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*- /*
* vim: ts=4 sw=4 noet ai cindent syntax=cpp
* *
* Conky, a system monitor, based on torsmo * Conky, a system monitor, based on torsmo
* *
@@ -43,8 +42,7 @@ class errno_error: public std::runtime_error {
public: public:
errno_error(const std::string &prefix, int err_ = errno) errno_error(const std::string &prefix, int err_ = errno)
: Base(prefix + ": " + strerror_r(err_)), err(err_) : Base(prefix + ": " + strerror_r(err_)), err(err_) {}
{}
const int err; const int err;
}; };

View File

@@ -1,11 +1,10 @@
/* -*- mode: c++; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*- /*
* vim: ts=4 sw=4 noet ai cindent syntax=cpp
* *
* Conky, a system monitor, based on torsmo * Conky, a system monitor, based on torsmo
* *
* Please see COPYING for details * Please see COPYING for details
* *
* Copyright (c) 2005-2012 Brenden Matthews, Philip Kovacs, et. al. * Copyright (c) 2005-2018 Brenden Matthews, Philip Kovacs, et. al.
* (see AUTHORS) * (see AUTHORS)
* All rights reserved. * All rights reserved.
* *
@@ -23,12 +22,12 @@
* *
*/ */
#include "conky.h"
#include "logging.h"
#include "ccurl_thread.h" #include "ccurl_thread.h"
#include "text_object.h"
#include <cmath> #include <cmath>
#include <mutex> #include <mutex>
#include "conky.h"
#include "logging.h"
#include "text_object.h"
#ifdef DEBUG #ifdef DEBUG
#include <assert.h> #include <assert.h>
@@ -45,8 +44,8 @@
namespace priv { namespace priv {
/* callback used by curl for parsing the header data */ /* callback used by curl for parsing the header data */
size_t curl_internal::parse_header_cb(void *ptr, size_t size, size_t nmemb, void *data) size_t curl_internal::parse_header_cb(void *ptr, size_t size, size_t nmemb,
{ void *data) {
curl_internal *obj = static_cast<curl_internal *>(data); curl_internal *obj = static_cast<curl_internal *>(data);
const char *value = static_cast<const char *>(ptr); const char *value = static_cast<const char *>(ptr);
size_t realsize = size * nmemb; size_t realsize = size * nmemb;
@@ -64,8 +63,8 @@ namespace priv {
} }
/* callback used by curl for writing the received data */ /* callback used by curl for writing the received data */
size_t curl_internal::write_cb(void *ptr, size_t size, size_t nmemb, void *data) size_t curl_internal::write_cb(void *ptr, size_t size, size_t nmemb,
{ void *data) {
curl_internal *obj = static_cast<curl_internal *>(data); curl_internal *obj = static_cast<curl_internal *>(data);
const char *value = static_cast<const char *>(ptr); const char *value = static_cast<const char *>(ptr);
size_t realsize = size * nmemb; size_t realsize = size * nmemb;
@@ -75,11 +74,8 @@ namespace priv {
return realsize; return realsize;
} }
curl_internal::curl_internal(const std::string &url) curl_internal::curl_internal(const std::string &url) : curl(curl_easy_init()) {
: curl(curl_easy_init()) if (not curl) throw std::runtime_error("curl_easy_init() failed");
{
if(not curl)
throw std::runtime_error("curl_easy_init() failed");
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1); curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1);
curl_easy_setopt(curl, CURLOPT_HEADERDATA, this); curl_easy_setopt(curl, CURLOPT_HEADERDATA, this);
@@ -92,15 +88,13 @@ namespace priv {
curl_easy_setopt(curl, CURLOPT_LOW_SPEED_LIMIT, 1000); curl_easy_setopt(curl, CURLOPT_LOW_SPEED_LIMIT, 1000);
curl_easy_setopt(curl, CURLOPT_LOW_SPEED_TIME, 60); curl_easy_setopt(curl, CURLOPT_LOW_SPEED_TIME, 60);
// curl's usage of alarm()+longjmp() is a really bad idea for multi-threaded applications // curl's usage of alarm()+longjmp() is a really bad idea for multi-threaded
// applications
curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1); curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
} }
/* fetch our datums */ /* fetch our datums */
void curl_internal::do_work() void curl_internal::do_work() {
{
CURLcode res; CURLcode res;
struct headers_ { struct headers_ {
struct curl_slist *h; struct curl_slist *h;
@@ -112,11 +106,13 @@ namespace priv {
data.clear(); data.clear();
if (not last_modified.empty()) { if (not last_modified.empty()) {
headers.h = curl_slist_append(headers.h, ("If-Modified-Since: " + last_modified).c_str()); headers.h = curl_slist_append(
headers.h, ("If-Modified-Since: " + last_modified).c_str());
last_modified.clear(); last_modified.clear();
} }
if (not etag.empty()) { if (not etag.empty()) {
headers.h = curl_slist_append(headers.h, ("If-None-Match: " + etag).c_str()); headers.h =
curl_slist_append(headers.h, ("If-None-Match: " + etag).c_str());
etag.clear(); etag.clear();
} }
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers.h); curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers.h);
@@ -125,7 +121,8 @@ namespace priv {
if (res == CURLE_OK) { if (res == CURLE_OK) {
long http_status_code; long http_status_code;
if (curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &http_status_code) == CURLE_OK) { if (curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &http_status_code) ==
CURLE_OK) {
switch (http_status_code) { switch (http_status_code) {
case 200: case 200:
process_data(); process_data();
@@ -144,25 +141,23 @@ namespace priv {
NORM_ERR("curl: could not retrieve data from server"); NORM_ERR("curl: could not retrieve data from server");
} }
} }
} } // namespace priv
namespace { namespace {
class simple_curl_cb : public curl_callback<std::string> { class simple_curl_cb : public curl_callback<std::string> {
typedef curl_callback<std::string> Base; typedef curl_callback<std::string> Base;
protected: protected:
virtual void process_data() virtual void process_data() {
{
std::lock_guard<std::mutex> lock(result_mutex); std::lock_guard<std::mutex> lock(result_mutex);
result = data; result = data;
} }
public: public:
simple_curl_cb(uint32_t period, const std::string &uri) simple_curl_cb(uint32_t period, const std::string &uri)
: Base(period, Tuple(uri)) : Base(period, Tuple(uri)) {}
{}
}; };
} } // namespace
/* /*
* This is where the $curl section begins. * This is where the $curl section begins.
@@ -174,16 +169,15 @@ struct curl_data {
}; };
/* prints result data to text buffer, used by $curl */ /* prints result data to text buffer, used by $curl */
void ccurl_process_info(char *p, int p_max_size, const std::string &uri, int interval) void ccurl_process_info(char *p, int p_max_size, const std::string &uri,
{ int interval) {
uint32_t period = std::max(lround(interval / active_update_interval()), 1l); uint32_t period = std::max(lround(interval / active_update_interval()), 1l);
auto cb = conky::register_cb<simple_curl_cb>(period, uri); auto cb = conky::register_cb<simple_curl_cb>(period, uri);
strncpy(p, cb->get_result_copy().c_str(), p_max_size); strncpy(p, cb->get_result_copy().c_str(), p_max_size);
} }
void curl_parse_arg(struct text_object *obj, const char *arg) void curl_parse_arg(struct text_object *obj, const char *arg) {
{
int argc; int argc;
struct curl_data *cd; struct curl_data *cd;
float interval = 0; float interval = 0;
@@ -204,8 +198,7 @@ void curl_parse_arg(struct text_object *obj, const char *arg)
obj->data.opaque = cd; obj->data.opaque = cd;
} }
void curl_print(struct text_object *obj, char *p, int p_max_size) void curl_print(struct text_object *obj, char *p, int p_max_size) {
{
struct curl_data *cd = (struct curl_data *)obj->data.opaque; struct curl_data *cd = (struct curl_data *)obj->data.opaque;
if (!cd || !cd->uri) { if (!cd || !cd->uri) {
@@ -215,7 +208,4 @@ void curl_print(struct text_object *obj, char *p, int p_max_size)
ccurl_process_info(p, p_max_size, cd->uri, cd->interval); ccurl_process_info(p, p_max_size, cd->uri, cd->interval);
} }
void curl_obj_free(struct text_object *obj) void curl_obj_free(struct text_object *obj) { free_and_zero(obj->data.opaque); }
{
free_and_zero(obj->data.opaque);
}

View File

@@ -1,11 +1,10 @@
/* -*- mode: c++; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*- /*
* vim: ts=4 sw=4 noet ai cindent syntax=cpp
* *
* Conky, a system monitor, based on torsmo * Conky, a system monitor, based on torsmo
* *
* Please see COPYING for details * Please see COPYING for details
* *
* Copyright (c) 2005-2012 Brenden Matthews, Philip Kovacs, et. al. * Copyright (c) 2005-2018 Brenden Matthews, Philip Kovacs, et. al.
* (see AUTHORS) * (see AUTHORS)
* All rights reserved. * All rights reserved.
* *
@@ -38,7 +37,8 @@ namespace priv {
std::string data; std::string data;
CURL *curl; CURL *curl;
static size_t parse_header_cb(void *ptr, size_t size, size_t nmemb, void *data); static size_t parse_header_cb(void *ptr, size_t size, size_t nmemb,
void *data);
static size_t write_cb(void *ptr, size_t size, size_t nmemb, void *data); static size_t write_cb(void *ptr, size_t size, size_t nmemb, void *data);
void do_work(); void do_work();
@@ -48,9 +48,11 @@ namespace priv {
virtual void process_data() = 0; virtual void process_data() = 0;
curl_internal(const std::string &url); curl_internal(const std::string &url);
virtual ~curl_internal() { if(curl) curl_easy_cleanup(curl); } virtual ~curl_internal() {
}; if (curl) curl_easy_cleanup(curl);
} }
};
} // namespace priv
/* /*
* Curl callback class template * Curl callback class template
@@ -63,23 +65,21 @@ class curl_callback: public conky::callback<Result, std::string, Keys...>,
typedef priv::curl_internal Base2; typedef priv::curl_internal Base2;
protected: protected:
virtual void work() virtual void work() {
{
DBGP("reading curl data from '%s'", std::get<0>(Base1::tuple).c_str()); DBGP("reading curl data from '%s'", std::get<0>(Base1::tuple).c_str());
do_work(); do_work();
} }
public: public:
curl_callback(uint32_t period, const typename Base1::Tuple &tuple) curl_callback(uint32_t period, const typename Base1::Tuple &tuple)
: Base1(period, false, tuple), Base2(std::get<0>(tuple)) : Base1(period, false, tuple), Base2(std::get<0>(tuple)) {}
{}
}; };
/* $curl exports begin */ /* $curl exports begin */
/* runs instance of $curl */ /* runs instance of $curl */
void ccurl_process_info(char *p, int p_max_size, const std::string &uri, int interval); void ccurl_process_info(char *p, int p_max_size, const std::string &uri,
int interval);
void curl_parse_arg(struct text_object *, const char *); void curl_parse_arg(struct text_object *, const char *);
void curl_print(struct text_object *, char *, int); void curl_print(struct text_object *, char *, int);
@@ -88,4 +88,3 @@ void curl_obj_free(struct text_object *);
/* $curl exports end */ /* $curl exports end */
#endif /* _CURL_THREAD_H_ */ #endif /* _CURL_THREAD_H_ */

View File

@@ -1,5 +1,4 @@
/* -*- mode: c++; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*- /*
* vim: ts=4 sw=4 noet ai cindent syntax=cpp
* *
* CMUS Conky integration * CMUS Conky integration
* *
@@ -25,12 +24,12 @@
#include "logging.h" #include "logging.h"
#include "text_object.h" #include "text_object.h"
#include <math.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <cmath> #include <cmath>
#include <mutex> #include <mutex>
#include <math.h>
#include "update-cb.hh" #include "update-cb.hh"
@@ -60,13 +59,10 @@ namespace {
virtual void work(); virtual void work();
public: public:
cmus_cb(uint32_t period) cmus_cb(uint32_t period) : Base(period, false, Tuple()) {}
: Base(period, false, Tuple())
{}
}; };
void cmus_cb::work() void cmus_cb::work() {
{
cmus_result cmus; cmus_result cmus;
FILE *fp; FILE *fp;
@@ -79,10 +75,8 @@ namespace {
char *p; char *p;
/* Read a line from the pipe and strip the possible '\n'. */ /* Read a line from the pipe and strip the possible '\n'. */
if (!fgets(line, 255, fp)) if (!fgets(line, 255, fp)) break;
break; if ((p = strrchr(line, '\n'))) *p = '\0';
if ((p = strrchr(line, '\n')))
*p = '\0';
/* Parse infos. */ /* Parse infos. */
if (strncmp(line, "status ", 7) == 0) if (strncmp(line, "status ", 7) == 0)
@@ -103,27 +97,26 @@ namespace {
else if (strncmp(line, "duration ", 9) == 0) else if (strncmp(line, "duration ", 9) == 0)
cmus.totaltime = line + 9; cmus.totaltime = line + 9;
else if (strncmp(line, "position ", 9) == 0) else if (strncmp(line, "position ", 9) == 0) {
{
cmus.curtime = line + 9; cmus.curtime = line + 9;
cmus.timeleft = atoi(cmus.totaltime.c_str()) - atoi(cmus.curtime.c_str()); cmus.timeleft =
atoi(cmus.totaltime.c_str()) - atoi(cmus.curtime.c_str());
if (cmus.curtime.size() > 0) if (cmus.curtime.size() > 0)
cmus.progress = (float) atoi(cmus.curtime.c_str()) / atoi(cmus.totaltime.c_str()); cmus.progress =
(float)atoi(cmus.curtime.c_str()) / atoi(cmus.totaltime.c_str());
else else
cmus.progress = 0; cmus.progress = 0;
} }
else if (strncmp(line, "set shuffle ", 12) == 0) else if (strncmp(line, "set shuffle ", 12) == 0)
cmus.random = (strncmp(line+12, "true", 4) == 0 ? cmus.random = (strncmp(line + 12, "true", 4) == 0 ? "on" : "off");
"on" : "off" );
else if (strncmp(line, "set repeat ", 11) == 0) else if (strncmp(line, "set repeat ", 11) == 0)
cmus.repeat = (strncmp((line+11), "true", 4) == 0 ? cmus.repeat = (strncmp((line + 11), "true", 4) == 0 ? "all" : "off");
"all" : "off" );
else if (strncmp(line, "set repeat_current ", 19) == 0) else if (strncmp(line, "set repeat_current ", 19) == 0)
cmus.repeat = (strncmp((line + 19), "true", 4) == 0 ? cmus.repeat =
"song" : cmus.repeat ); (strncmp((line + 19), "true", 4) == 0 ? "song" : cmus.repeat);
else if (strncmp(line, "set aaa_mode ", 13) == 0) else if (strncmp(line, "set aaa_mode ", 13) == 0)
cmus.aaa = line + 13; cmus.aaa = line + 13;
@@ -141,17 +134,18 @@ namespace {
std::lock_guard<std::mutex> l(result_mutex); std::lock_guard<std::mutex> l(result_mutex);
result = cmus; result = cmus;
} }
} } // namespace
#define CMUS_PRINT_GENERATOR(type, alt) \ #define CMUS_PRINT_GENERATOR(type, alt) \
void print_cmus_##type(struct text_object *obj, char *p, int p_max_size) \ void print_cmus_##type(struct text_object *obj, char *p, int p_max_size) { \
{ \
(void)obj; \ (void)obj; \
uint32_t period = std::max( \ uint32_t period = std::max( \
lround(music_player_interval.get(*state)/active_update_interval()), 1l \ lround(music_player_interval.get(*state) / active_update_interval()), \
); \ 1l); \
const cmus_result &cmus = conky::register_cb<cmus_cb>(period)->get_result_copy(); \ const cmus_result &cmus = \
snprintf(p, p_max_size, "%s", (cmus.type.length() ? cmus.type.c_str() : alt)); \ conky::register_cb<cmus_cb>(period)->get_result_copy(); \
snprintf(p, p_max_size, "%s", \
(cmus.type.length() ? cmus.type.c_str() : alt)); \
} }
CMUS_PRINT_GENERATOR(state, "Off") CMUS_PRINT_GENERATOR(state, "Off")
@@ -166,49 +160,49 @@ CMUS_PRINT_GENERATOR(track, "no track")
CMUS_PRINT_GENERATOR(genre, "") CMUS_PRINT_GENERATOR(genre, "")
CMUS_PRINT_GENERATOR(date, "") CMUS_PRINT_GENERATOR(date, "")
uint8_t cmus_percent(struct text_object *obj) uint8_t cmus_percent(struct text_object *obj) {
{
(void)obj; (void)obj;
uint32_t period = std::max( uint32_t period = std::max(
lround(music_player_interval.get(*state) / active_update_interval()), 1l); lround(music_player_interval.get(*state) / active_update_interval()), 1l);
const cmus_result &cmus = conky::register_cb<cmus_cb>(period)->get_result_copy(); const cmus_result &cmus =
conky::register_cb<cmus_cb>(period)->get_result_copy();
return (uint8_t)round(cmus.progress * 100.0f); return (uint8_t)round(cmus.progress * 100.0f);
} }
double cmus_progress(struct text_object *obj) double cmus_progress(struct text_object *obj) {
{
(void)obj; (void)obj;
uint32_t period = std::max( uint32_t period = std::max(
lround(music_player_interval.get(*state) / active_update_interval()), 1l); lround(music_player_interval.get(*state) / active_update_interval()), 1l);
const cmus_result &cmus = conky::register_cb<cmus_cb>(period)->get_result_copy(); const cmus_result &cmus =
conky::register_cb<cmus_cb>(period)->get_result_copy();
return (double)cmus.progress; return (double)cmus.progress;
} }
void print_cmus_totaltime(struct text_object *obj, char *p, int p_max_size) void print_cmus_totaltime(struct text_object *obj, char *p, int p_max_size) {
{
(void)obj; (void)obj;
uint32_t period = std::max( uint32_t period = std::max(
lround(music_player_interval.get(*state) / active_update_interval()), 1l); lround(music_player_interval.get(*state) / active_update_interval()), 1l);
const cmus_result &cmus = conky::register_cb<cmus_cb>(period)->get_result_copy(); const cmus_result &cmus =
conky::register_cb<cmus_cb>(period)->get_result_copy();
format_seconds_short(p, p_max_size, atol(cmus.totaltime.c_str())); format_seconds_short(p, p_max_size, atol(cmus.totaltime.c_str()));
} }
void print_cmus_timeleft(struct text_object *obj, char *p, int p_max_size) void print_cmus_timeleft(struct text_object *obj, char *p, int p_max_size) {
{
(void)obj; (void)obj;
uint32_t period = std::max( uint32_t period = std::max(
lround(music_player_interval.get(*state) / active_update_interval()), 1l); lround(music_player_interval.get(*state) / active_update_interval()), 1l);
const cmus_result &cmus = conky::register_cb<cmus_cb>(period)->get_result_copy(); const cmus_result &cmus =
conky::register_cb<cmus_cb>(period)->get_result_copy();
// format_seconds_short(p, p_max_size, atol(cmus.timeleft.c_str())); // format_seconds_short(p, p_max_size, atol(cmus.timeleft.c_str()));
format_seconds_short(p, p_max_size, (long)cmus.timeleft); format_seconds_short(p, p_max_size, (long)cmus.timeleft);
} }
void print_cmus_curtime(struct text_object *obj, char *p, int p_max_size) void print_cmus_curtime(struct text_object *obj, char *p, int p_max_size) {
{
(void)obj; (void)obj;
uint32_t period = std::max( uint32_t period = std::max(
lround(music_player_interval.get(*state) / active_update_interval()), 1l); lround(music_player_interval.get(*state) / active_update_interval()), 1l);
const cmus_result &cmus = conky::register_cb<cmus_cb>(period)->get_result_copy(); const cmus_result &cmus =
conky::register_cb<cmus_cb>(period)->get_result_copy();
format_seconds_short(p, p_max_size, atol(cmus.curtime.c_str())); format_seconds_short(p, p_max_size, atol(cmus.curtime.c_str()));
} }

View File

@@ -1,5 +1,4 @@
/* -*- mode: c++; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*- /*
* vim: ts=4 sw=4 noet ai cindent syntax=cpp
* *
* CMUS Conky integration * CMUS Conky integration
* *
@@ -43,4 +42,3 @@ double cmus_progress(struct text_object *obj);
uint8_t cmus_percent(struct text_object *obj); uint8_t cmus_percent(struct text_object *obj);
#endif /* CMUS_H_ */ #endif /* CMUS_H_ */

View File

@@ -1,5 +1,4 @@
/* -*- mode: c++; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*- /*
* vim: ts=4 sw=4 noet ai cindent syntax=cpp
* *
* Conky, a system monitor, based on torsmo * Conky, a system monitor, based on torsmo
* *
@@ -10,7 +9,7 @@
* Please see COPYING for details * Please see COPYING for details
* *
* Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen * Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
* Copyright (c) 2005-2012 Brenden Matthews, Philip Kovacs, et. al. * Copyright (c) 2005-2018 Brenden Matthews, Philip Kovacs, et. al.
* (see AUTHORS) * (see AUTHORS)
* All rights reserved. * All rights reserved.
* *
@@ -40,8 +39,7 @@
static short colour_depth = 0; static short colour_depth = 0;
static long redmask, greenmask, bluemask; static long redmask, greenmask, bluemask;
static void set_up_gradient(void) static void set_up_gradient(void) {
{
int i; int i;
#ifdef BUILD_X11 #ifdef BUILD_X11
if (out_to_x.get(*state)) { if (out_to_x.get(*state)) {
@@ -52,7 +50,8 @@ static void set_up_gradient(void)
colour_depth = 16; colour_depth = 16;
} }
if (colour_depth != 24 && colour_depth != 16) { if (colour_depth != 24 && colour_depth != 16) {
NORM_ERR("using non-standard colour depth, gradients may look like a " NORM_ERR(
"using non-standard colour depth, gradients may look like a "
"lolly-pop"); "lolly-pop");
} }
@@ -72,8 +71,7 @@ static void set_up_gradient(void)
} }
/* adjust colour values depending on colour depth */ /* adjust colour values depending on colour depth */
unsigned int adjust_colours(unsigned int colour) unsigned int adjust_colours(unsigned int colour) {
{
double r, g, b; double r, g, b;
if (colour_depth == 0) { if (colour_depth == 0) {
@@ -91,14 +89,15 @@ unsigned int adjust_colours(unsigned int colour)
} }
/* this function returns the next colour between two colours for a gradient */ /* this function returns the next colour between two colours for a gradient */
unsigned long *do_gradient(int width, unsigned long first_colour, unsigned long last_colour) unsigned long *do_gradient(int width, unsigned long first_colour,
{ unsigned long last_colour) {
int red1, green1, blue1; // first colour int red1, green1, blue1; // first colour
int red2, green2, blue2; // last colour int red2, green2, blue2; // last colour
int reddiff, greendiff, bluediff; // difference int reddiff, greendiff, bluediff; // difference
short redshift = (2 * colour_depth / 3 + colour_depth % 3); short redshift = (2 * colour_depth / 3 + colour_depth % 3);
short greenshift = (colour_depth / 3); short greenshift = (colour_depth / 3);
unsigned long *colours = (unsigned long*)malloc(width * sizeof(unsigned long)); unsigned long *colours =
(unsigned long *)malloc(width * sizeof(unsigned long));
int i; int i;
if (colour_depth == 0) { if (colour_depth == 0) {
@@ -164,8 +163,7 @@ unsigned long *do_gradient(int width, unsigned long first_colour, unsigned long
} }
#ifdef BUILD_X11 #ifdef BUILD_X11
long get_x11_color(const char *name) long get_x11_color(const char *name) {
{
XColor color; XColor color;
color.pixel = 0; color.pixel = 0;
@@ -190,6 +188,7 @@ long get_x11_color(const char *name)
return (long)color.pixel; return (long)color.pixel;
} }
long get_x11_color(const std::string &colour) long get_x11_color(const std::string &colour) {
{ return get_x11_color(colour.c_str()); } return get_x11_color(colour.c_str());
}
#endif #endif

View File

@@ -1,5 +1,4 @@
/* -*- mode: c++; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*- /*
* vim: ts=4 sw=4 noet ai cindent syntax=cpp
* *
* Conky, a system monitor, based on torsmo * Conky, a system monitor, based on torsmo
* *
@@ -10,7 +9,7 @@
* Please see COPYING for details * Please see COPYING for details
* *
* Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen * Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
* Copyright (c) 2005-2012 Brenden Matthews, Philip Kovacs, et. al. * Copyright (c) 2005-2018 Brenden Matthews, Philip Kovacs, et. al.
* (see AUTHORS) * (see AUTHORS)
* All rights reserved. * All rights reserved.
* *
@@ -30,6 +29,8 @@
#ifndef _COLOURS_H #ifndef _COLOURS_H
#define _COLOURS_H #define _COLOURS_H
#include <string>
unsigned int adjust_colours(unsigned int); unsigned int adjust_colours(unsigned int);
unsigned long *do_gradient(int, unsigned long, unsigned long); unsigned long *do_gradient(int, unsigned long, unsigned long);

View File

@@ -1,5 +1,4 @@
/* -*- mode: c++; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*- /*
* vim: ts=4 sw=4 noet ai cindent syntax=cpp
* *
* Conky, a system monitor, based on torsmo * Conky, a system monitor, based on torsmo
* *
@@ -10,7 +9,7 @@
* Please see COPYING for details * Please see COPYING for details
* *
* Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen * Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
* Copyright (c) 2005-2012 Brenden Matthews, Philip Kovacs, et. al. * Copyright (c) 2005-2018 Brenden Matthews, Philip Kovacs, et. al.
* (see AUTHORS) * (see AUTHORS)
* All rights reserved. * All rights reserved.
* *
@@ -40,8 +39,7 @@ struct combine_data {
char *right; char *right;
}; };
void parse_combine_arg(struct text_object *obj, const char *arg) void parse_combine_arg(struct text_object *obj, const char *arg) {
{
struct combine_data *cd; struct combine_data *cd;
unsigned int i, j; unsigned int i, j;
unsigned int indenting = 0; // vars can be used as args for other vars unsigned int indenting = 0; // vars can be used as args for other vars
@@ -60,13 +58,16 @@ void parse_combine_arg(struct text_object *obj, const char *arg)
} else if (arg[i] == '}') { } else if (arg[i] == '}') {
indenting--; indenting--;
} }
if (indenting == 0 && arg[i+1] < 48) { //<48 has 0, $, and the most used chars not used in varnames but not { or } if (indenting == 0 &&
arg[i + 1] < 48) { //<48 has 0, $, and the most used chars not used
// in varnames but not { or }
endvar[j] = i + 1; endvar[j] = i + 1;
j++; j++;
} }
} }
} }
if(startvar[0] >= 0 && endvar[0] >= 0 && startvar[1] >= 0 && endvar[1] >= 0) { if (startvar[0] >= 0 && endvar[0] >= 0 && startvar[1] >= 0 &&
endvar[1] >= 0) {
cd = (struct combine_data *)malloc(sizeof(struct combine_data)); cd = (struct combine_data *)malloc(sizeof(struct combine_data));
memset(cd, 0, sizeof(struct combine_data)); memset(cd, 0, sizeof(struct combine_data));
@@ -93,8 +94,7 @@ void parse_combine_arg(struct text_object *obj, const char *arg)
} }
} }
void print_combine(struct text_object *obj, char *p, int p_max_size) void print_combine(struct text_object *obj, char *p, int p_max_size) {
{
struct combine_data *cd = (struct combine_data *)obj->data.opaque; struct combine_data *cd = (struct combine_data *)obj->data.opaque;
std::vector<std::vector<char>> buf; std::vector<std::vector<char>> buf;
buf.resize(2); buf.resize(2);
@@ -111,8 +111,7 @@ void print_combine(struct text_object *obj, char *p, int p_max_size)
struct llrows *ll_rows[2], *current[2]; struct llrows *ll_rows[2], *current[2];
struct text_object *objsub = obj->sub; struct text_object *objsub = obj->sub;
if (!cd || !p_max_size) if (!cd || !p_max_size) return;
return;
p[0] = 0; p[0] = 0;
for (i = 0; i < 2; i++) { for (i = 0; i < 2; i++) {
@@ -124,11 +123,14 @@ void print_combine(struct text_object *obj, char *p, int p_max_size)
generate_text_internal(&(buf[i][0]), max_user_text.get(*state), *objsub); generate_text_internal(&(buf[i][0]), max_user_text.get(*state), *objsub);
for (j = 0; buf[i][j] != 0; j++) { for (j = 0; buf[i][j] != 0; j++) {
if (buf[i][j] == '\t') buf[i][j] = ' '; if (buf[i][j] == '\t') buf[i][j] = ' ';
if(buf[i][j] == '\n') buf[i][j] = 0; //the vars inside combine may not have a \n at the end if (buf[i][j] == '\n')
if(buf[i][j] == 2) { // \002 is used instead of \n to separate lines inside a var buf[i][j] = 0; // the vars inside combine may not have a \n at the end
if (buf[i][j] ==
2) { // \002 is used instead of \n to separate lines inside a var
buf[i][j] = 0; buf[i][j] = 0;
current[i]->row = strdup(&(buf[i][0]) + nextstart); current[i]->row = strdup(&(buf[i][0]) + nextstart);
if(i==0 && (long)strlen(current[i]->row) > longest) longest = (long)strlen(current[i]->row); if (i == 0 && (long)strlen(current[i]->row) > longest)
longest = (long)strlen(current[i]->row);
current[i]->next = (struct llrows *)malloc(sizeof(struct llrows)); current[i]->next = (struct llrows *)malloc(sizeof(struct llrows));
current[i] = current[i]->next; current[i] = current[i]->next;
nextstart = j + 1; nextstart = j + 1;
@@ -136,7 +138,8 @@ void print_combine(struct text_object *obj, char *p, int p_max_size)
} }
} }
current[i]->row = strdup(&(buf[i][0]) + nextstart); current[i]->row = strdup(&(buf[i][0]) + nextstart);
if(i==0 && (long)strlen(current[i]->row) > longest) longest = (long)strlen(current[i]->row); if (i == 0 && (long)strlen(current[i]->row) > longest)
longest = (long)strlen(current[i]->row);
current[i]->next = NULL; current[i]->next = NULL;
current[i] = ll_rows[i]; current[i] = ll_rows[i];
} }
@@ -144,7 +147,8 @@ void print_combine(struct text_object *obj, char *p, int p_max_size)
if (current[0]) { if (current[0]) {
strcat(p, current[0]->row); strcat(p, current[0]->row);
i = strlen(current[0]->row); i = strlen(current[0]->row);
}else i = 0; } else
i = 0;
while (i < longest) { while (i < longest) {
strcat(p, " "); strcat(p, " ");
i++; i++;
@@ -157,7 +161,8 @@ void print_combine(struct text_object *obj, char *p, int p_max_size)
#ifdef HAVE_OPENMP #ifdef HAVE_OPENMP
#pragma omp parallel for schedule(dynamic, 10) #pragma omp parallel for schedule(dynamic, 10)
#endif /* HAVE_OPENMP */ #endif /* HAVE_OPENMP */
for(i=0; i<2; i++) if(current[i]) current[i]=current[i]->next; for (i = 0; i < 2; i++)
if (current[i]) current[i] = current[i]->next;
} }
#ifdef HAVE_OPENMP #ifdef HAVE_OPENMP
#pragma omp parallel for schedule(dynamic, 10) #pragma omp parallel for schedule(dynamic, 10)
@@ -172,12 +177,10 @@ void print_combine(struct text_object *obj, char *p, int p_max_size)
} }
} }
void free_combine(struct text_object *obj) void free_combine(struct text_object *obj) {
{
struct combine_data *cd = (struct combine_data *)obj->data.opaque; struct combine_data *cd = (struct combine_data *)obj->data.opaque;
if (!cd) if (!cd) return;
return;
free(cd->left); free(cd->left);
free(cd->seperation); free(cd->seperation);
free(cd->right); free(cd->right);

View File

@@ -1,5 +1,4 @@
/* -*- mode: c++; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*- /*
* vim: ts=4 sw=4 noet ai cindent syntax=cpp
* *
* Conky, a system monitor, based on torsmo * Conky, a system monitor, based on torsmo
* *
@@ -10,7 +9,7 @@
* Please see COPYING for details * Please see COPYING for details
* *
* Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen * Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
* Copyright (c) 2005-2012 Brenden Matthews, Philip Kovacs, et. al. * Copyright (c) 2005-2018 Brenden Matthews, Philip Kovacs, et. al.
* (see AUTHORS) * (see AUTHORS)
* All rights reserved. * All rights reserved.
* *

View File

@@ -1,5 +1,4 @@
/* -*- mode: c++; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*- /*
* vim: ts=4 sw=4 noet ai cindent syntax=cpp
* *
* Conky, a system monitor, based on torsmo * Conky, a system monitor, based on torsmo
* *
@@ -10,7 +9,7 @@
* Please see COPYING for details * Please see COPYING for details
* *
* Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen * Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
* Copyright (c) 2005-2012 Brenden Matthews, Philip Kovacs, et. al. * Copyright (c) 2005-2018 Brenden Matthews, Philip Kovacs, et. al.
* (see AUTHORS) * (see AUTHORS)
* All rights reserved. * All rights reserved.
* *
@@ -28,6 +27,17 @@
* *
*/ */
#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
#include <net/if.h>
#include <netinet/in.h>
#include <pthread.h>
#include <semaphore.h>
#include <sys/ioctl.h>
#include <time.h>
#include <unistd.h>
#include <vector>
#include "config.h" #include "config.h"
#include "conky.h" #include "conky.h"
#include "core.h" #include "core.h"
@@ -38,17 +48,6 @@
#include "temphelper.h" #include "temphelper.h"
#include "timeinfo.h" #include "timeinfo.h"
#include "top.h" #include "top.h"
#include <ctype.h>
#include <errno.h>
#include <time.h>
#include <sys/ioctl.h>
#include <net/if.h>
#include <netinet/in.h>
#include <pthread.h>
#include <semaphore.h>
#include <unistd.h>
#include <fcntl.h>
#include <vector>
/* check for OS and include appropriate headers */ /* check for OS and include appropriate headers */
#if defined(__linux__) #if defined(__linux__)
@@ -73,8 +72,7 @@
* *
* if start is "blah", and you call it with count = 1, the result will be "lah" * if start is "blah", and you call it with count = 1, the result will be "lah"
*/ */
void strfold(char *start, int count) void strfold(char *start, int count) {
{
char *curplace; char *curplace;
for (curplace = start + count; *curplace != 0; curplace++) { for (curplace = start + count; *curplace != 0; curplace++) {
*(curplace - count) = *curplace; *(curplace - count) = *curplace;
@@ -84,8 +82,7 @@ void strfold(char *start, int count)
#ifndef HAVE_STRNDUP #ifndef HAVE_STRNDUP
// use our own strndup() if it's not available // use our own strndup() if it's not available
char *strndup(const char *s, size_t n) char *strndup(const char *s, size_t n) {
{
if (strlen(s) > n) { if (strlen(s) > n) {
char *ret = malloc(n + 1); char *ret = malloc(n + 1);
strncpy(ret, s, n); strncpy(ret, s, n);
@@ -97,13 +94,13 @@ char *strndup(const char *s, size_t n)
} }
#endif /* HAVE_STRNDUP */ #endif /* HAVE_STRNDUP */
int update_uname(void) int update_uname(void) {
{
uname(&info.uname_s); uname(&info.uname_s);
#if defined(__DragonFly__) #if defined(__DragonFly__)
{ {
size_t desc_n; char desc[256]; size_t desc_n;
char desc[256];
if (sysctlbyname("kern.version", NULL, &desc_n, NULL, 0) == -1 || if (sysctlbyname("kern.version", NULL, &desc_n, NULL, 0) == -1 ||
sysctlbyname("kern.version", desc, &desc_n, NULL, 0) == -1) sysctlbyname("kern.version", desc, &desc_n, NULL, 0) == -1)
@@ -121,8 +118,7 @@ int update_uname(void)
return 0; return 0;
} }
double get_time(void) double get_time(void) {
{
struct timespec tv; struct timespec tv;
#ifdef _POSIX_MONOTONIC_CLOCK #ifdef _POSIX_MONOTONIC_CLOCK
clock_gettime(CLOCK_MONOTONIC, &tv); clock_gettime(CLOCK_MONOTONIC, &tv);
@@ -135,8 +131,7 @@ double get_time(void)
/* Converts '~/...' paths to '/home/blah/...'. It's similar to /* Converts '~/...' paths to '/home/blah/...'. It's similar to
* variable_substitute, except only cheques for $HOME and ~/ in * variable_substitute, except only cheques for $HOME and ~/ in
* path. If HOME is unset it uses an empty string for substitution */ * path. If HOME is unset it uses an empty string for substitution */
std::string to_real_path(const std::string &source) std::string to_real_path(const std::string &source) {
{
const char *homedir = getenv("HOME") ?: ""; const char *homedir = getenv("HOME") ?: "";
if (source.find("~/") == 0) if (source.find("~/") == 0)
return homedir + source.substr(1); return homedir + source.substr(1);
@@ -146,8 +141,7 @@ std::string to_real_path(const std::string &source)
return source; return source;
} }
int open_fifo(const char *file, int *reported) int open_fifo(const char *file, int *reported) {
{
int fd = 0; int fd = 0;
fd = open(file, O_RDONLY | O_NONBLOCK); fd = open(file, O_RDONLY | O_NONBLOCK);
@@ -165,8 +159,7 @@ int open_fifo(const char *file, int *reported)
return fd; return fd;
} }
FILE *open_file(const char *file, int *reported) FILE *open_file(const char *file, int *reported) {
{
FILE *fp = 0; FILE *fp = 0;
fp = fopen(file, "r"); fp = fopen(file, "r");
@@ -184,12 +177,10 @@ FILE *open_file(const char *file, int *reported)
return fp; return fp;
} }
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) {
if(pos + 1 >= s.size()) if (pos + 1 >= s.size()) break;
break;
if (s[pos + 1] == '$') { if (s[pos + 1] == '$') {
s.erase(pos, 1); s.erase(pos, 1);
@@ -200,13 +191,11 @@ std::string variable_substitute(std::string s)
if (isalpha(s[pos + 1])) { if (isalpha(s[pos + 1])) {
l = 1; l = 1;
while(pos+l < s.size() && isalnum(s[pos+l])) while (pos + l < s.size() && isalnum(s[pos + l])) ++l;
++l;
var = s.substr(pos + 1, l - 1); var = s.substr(pos + 1, l - 1);
} else if (s[pos + 1] == '{') { } else if (s[pos + 1] == '{') {
l = s.find('}', pos); l = s.find('}', pos);
if(l == std::string::npos) if (l == std::string::npos) break;
break;
l -= pos - 1; l -= pos - 1;
var = s.substr(pos + 2, l - 3); var = s.substr(pos + 2, l - 3);
} else } else
@@ -219,7 +208,6 @@ std::string variable_substitute(std::string s)
s.insert(pos, val); s.insert(pos, val);
pos += strlen(val); pos += strlen(val);
} }
} }
} }
} }
@@ -227,8 +215,7 @@ std::string variable_substitute(std::string s)
return s; return s;
} }
void format_seconds(char *buf, unsigned int n, long seconds) void format_seconds(char *buf, unsigned int n, long seconds) {
{
long days; long days;
int hours, minutes; int hours, minutes;
@@ -251,8 +238,7 @@ void format_seconds(char *buf, unsigned int n, long seconds)
} }
} }
void format_seconds_short(char *buf, unsigned int n, long seconds) void format_seconds_short(char *buf, unsigned int n, long seconds) {
{
long days; long days;
int hours, minutes; int hours, minutes;
@@ -279,8 +265,7 @@ void format_seconds_short(char *buf, unsigned int n, long seconds)
conky::simple_config_setting<bool> no_buffers("no_buffers", true, true); conky::simple_config_setting<bool> no_buffers("no_buffers", true, true);
void update_stuff(void) void update_stuff(void) {
{
/* clear speeds, addresses and up status in case device was removed and /* clear speeds, addresses and up status in case device was removed and
* doesn't get updated */ * doesn't get updated */
@@ -313,8 +298,7 @@ void update_stuff(void)
} }
/* Ohkie to return negative values for temperatures */ /* Ohkie to return negative values for temperatures */
int round_to_int_temp(float f) int round_to_int_temp(float f) {
{
if (f >= 0.0) { if (f >= 0.0) {
return (int)(f + 0.5); return (int)(f + 0.5);
} else { } else {
@@ -323,8 +307,7 @@ int round_to_int_temp(float f)
} }
/* Don't return negative values for cpugraph, bar, gauge, percentage. /* Don't return negative values for cpugraph, bar, gauge, percentage.
* Causes unreasonable numbers to show */ * Causes unreasonable numbers to show */
unsigned int round_to_int(float f) unsigned int round_to_int(float f) {
{
if (f >= 0.0) { if (f >= 0.0) {
return (int)(f + 0.5); return (int)(f + 0.5);
} else { } else {
@@ -332,8 +315,7 @@ unsigned int round_to_int(float f)
} }
} }
void scan_loadavg_arg(struct text_object *obj, const char *arg) void scan_loadavg_arg(struct text_object *obj, const char *arg) {
{
obj->data.i = 0; obj->data.i = 0;
if (arg && !arg[1] && isdigit(arg[0])) { if (arg && !arg[1] && isdigit(arg[0])) {
obj->data.i = atoi(arg); obj->data.i = atoi(arg);
@@ -346,8 +328,7 @@ void scan_loadavg_arg(struct text_object *obj, const char *arg)
obj->data.i--; obj->data.i--;
} }
void print_loadavg(struct text_object *obj, char *p, int p_max_size) void print_loadavg(struct text_object *obj, char *p, int p_max_size) {
{
float *v = info.loadavg; float *v = info.loadavg;
if (obj->data.i < 0) { if (obj->data.i < 0) {
@@ -357,44 +338,36 @@ void print_loadavg(struct text_object *obj, char *p, int p_max_size)
} }
} }
void scan_no_update(struct text_object *obj, const char *arg) void scan_no_update(struct text_object *obj, const char *arg) {
{
obj->data.s = (char *)malloc(text_buffer_size.get(*state)); obj->data.s = (char *)malloc(text_buffer_size.get(*state));
evaluate(arg, obj->data.s, text_buffer_size.get(*state)); evaluate(arg, obj->data.s, text_buffer_size.get(*state));
obj->data.s = (char *)realloc(obj->data.s, strlen(obj->data.s) + 1); obj->data.s = (char *)realloc(obj->data.s, strlen(obj->data.s) + 1);
} }
void free_no_update(struct text_object *obj) { void free_no_update(struct text_object *obj) { free(obj->data.s); }
free(obj->data.s);
}
void print_no_update(struct text_object *obj, char *p, int p_max_size) void print_no_update(struct text_object *obj, char *p, int p_max_size) {
{
snprintf(p, p_max_size, "%s", obj->data.s); snprintf(p, p_max_size, "%s", obj->data.s);
} }
#ifdef BUILD_X11 #ifdef BUILD_X11
void scan_loadgraph_arg(struct text_object *obj, const char *arg) void scan_loadgraph_arg(struct text_object *obj, const char *arg) {
{
char *buf = 0; char *buf = 0;
buf = scan_graph(obj, arg, 0); buf = scan_graph(obj, arg, 0);
free_and_zero(buf); free_and_zero(buf);
} }
double loadgraphval(struct text_object *obj) double loadgraphval(struct text_object *obj) {
{
(void)obj; (void)obj;
return info.loadavg[0]; return info.loadavg[0];
} }
#endif /* BUILD_X11 */ #endif /* BUILD_X11 */
uint8_t cpu_percentage(struct text_object *obj) uint8_t cpu_percentage(struct text_object *obj) {
{
if (obj->data.i > info.cpu_count) { if (obj->data.i > info.cpu_count) {
NORM_ERR("obj->data.i %i info.cpu_count %i", NORM_ERR("obj->data.i %i info.cpu_count %i", obj->data.i, info.cpu_count);
obj->data.i, info.cpu_count);
CRIT_ERR(NULL, NULL, "attempting to use more CPUs than you have!"); CRIT_ERR(NULL, NULL, "attempting to use more CPUs than you have!");
} }
if (info.cpu_usage) { if (info.cpu_usage) {
@@ -404,8 +377,7 @@ uint8_t cpu_percentage(struct text_object *obj)
} }
} }
double cpu_barval(struct text_object *obj) double cpu_barval(struct text_object *obj) {
{
if (info.cpu_usage) { if (info.cpu_usage) {
return info.cpu_usage[obj->data.i]; return info.cpu_usage[obj->data.i];
} else { } else {
@@ -414,8 +386,7 @@ double cpu_barval(struct text_object *obj)
} }
#define PRINT_HR_GENERATOR(name) \ #define PRINT_HR_GENERATOR(name) \
void print_##name(struct text_object *obj, char *p, int p_max_size) \ void print_##name(struct text_object *obj, char *p, int p_max_size) { \
{ \
(void)obj; \ (void)obj; \
human_readable(info.name * 1024, p, p_max_size); \ human_readable(info.name * 1024, p, p_max_size); \
} }
@@ -430,61 +401,52 @@ PRINT_HR_GENERATOR(swap)
PRINT_HR_GENERATOR(swapfree) PRINT_HR_GENERATOR(swapfree)
PRINT_HR_GENERATOR(swapmax) PRINT_HR_GENERATOR(swapmax)
uint8_t mem_percentage(struct text_object *obj) uint8_t mem_percentage(struct text_object *obj) {
{
(void)obj; (void)obj;
return (info.memmax ? round_to_int(info.mem * 100 / info.memmax) : 0); return (info.memmax ? round_to_int(info.mem * 100 / info.memmax) : 0);
} }
double mem_barval(struct text_object *obj) double mem_barval(struct text_object *obj) {
{
(void)obj; (void)obj;
return info.memmax ? ((double)info.mem / info.memmax) : 0; return info.memmax ? ((double)info.mem / info.memmax) : 0;
} }
double mem_with_buffers_barval(struct text_object *obj) double mem_with_buffers_barval(struct text_object *obj) {
{
(void)obj; (void)obj;
return info.memmax ? ((double)info.memwithbuffers / info.memmax) : 0; return info.memmax ? ((double)info.memwithbuffers / info.memmax) : 0;
} }
uint8_t swap_percentage(struct text_object *obj) uint8_t swap_percentage(struct text_object *obj) {
{
(void)obj; (void)obj;
return (info.swapmax ? round_to_int(info.swap * 100 / info.swapmax) : 0); return (info.swapmax ? round_to_int(info.swap * 100 / info.swapmax) : 0);
} }
double swap_barval(struct text_object *obj) double swap_barval(struct text_object *obj) {
{
(void)obj; (void)obj;
return info.swapmax ? ((double)info.swap / info.swapmax) : 0; return info.swapmax ? ((double)info.swap / info.swapmax) : 0;
} }
void print_kernel(struct text_object *obj, char *p, int p_max_size) void print_kernel(struct text_object *obj, char *p, int p_max_size) {
{
(void)obj; (void)obj;
snprintf(p, p_max_size, "%s", info.uname_s.release); snprintf(p, p_max_size, "%s", info.uname_s.release);
} }
void print_machine(struct text_object *obj, char *p, int p_max_size) void print_machine(struct text_object *obj, char *p, int p_max_size) {
{
(void)obj; (void)obj;
snprintf(p, p_max_size, "%s", info.uname_s.machine); snprintf(p, p_max_size, "%s", info.uname_s.machine);
} }
void print_nodename(struct text_object *obj, char *p, int p_max_size) void print_nodename(struct text_object *obj, char *p, int p_max_size) {
{
(void)obj; (void)obj;
snprintf(p, p_max_size, "%s", info.uname_s.nodename); snprintf(p, p_max_size, "%s", info.uname_s.nodename);
} }
void print_nodename_short(struct text_object *obj, char *p, int p_max_size) void print_nodename_short(struct text_object *obj, char *p, int p_max_size) {
{
(void)obj; (void)obj;
snprintf(p, p_max_size, "%s", info.uname_s.nodename); snprintf(p, p_max_size, "%s", info.uname_s.nodename);
for (int i = 0; p[i] != 0; i++) { for (int i = 0; p[i] != 0; i++) {
@@ -495,77 +457,65 @@ void print_nodename_short(struct text_object *obj, char *p, int p_max_size)
} }
} }
void print_sysname(struct text_object *obj, char *p, int p_max_size) void print_sysname(struct text_object *obj, char *p, int p_max_size) {
{
(void)obj; (void)obj;
snprintf(p, p_max_size, "%s", info.uname_s.sysname); snprintf(p, p_max_size, "%s", info.uname_s.sysname);
} }
#if defined(__DragonFly__) #if defined(__DragonFly__)
void print_version(struct text_object *obj, char *p, int p_max_size) void print_version(struct text_object *obj, char *p, int p_max_size) {
{
(void)obj; (void)obj;
snprintf(p, p_max_size, "%s", info.uname_v); snprintf(p, p_max_size, "%s", info.uname_v);
} }
#endif #endif
void print_uptime(struct text_object *obj, char *p, int p_max_size) void print_uptime(struct text_object *obj, char *p, int p_max_size) {
{
(void)obj; (void)obj;
format_seconds(p, p_max_size, (int)info.uptime); format_seconds(p, p_max_size, (int)info.uptime);
} }
void print_uptime_short(struct text_object *obj, char *p, int p_max_size) void print_uptime_short(struct text_object *obj, char *p, int p_max_size) {
{
(void)obj; (void)obj;
format_seconds_short(p, p_max_size, (int)info.uptime); format_seconds_short(p, p_max_size, (int)info.uptime);
} }
void print_processes(struct text_object *obj, char *p, int p_max_size) void print_processes(struct text_object *obj, char *p, int p_max_size) {
{
(void)obj; (void)obj;
spaced_print(p, p_max_size, "%hu", 4, info.procs); spaced_print(p, p_max_size, "%hu", 4, info.procs);
} }
void print_running_processes(struct text_object *obj, char *p, int p_max_size) void print_running_processes(struct text_object *obj, char *p, int p_max_size) {
{
(void)obj; (void)obj;
spaced_print(p, p_max_size, "%hu", 4, info.run_procs); spaced_print(p, p_max_size, "%hu", 4, info.run_procs);
} }
void print_running_threads(struct text_object *obj, char *p, int p_max_size) void print_running_threads(struct text_object *obj, char *p, int p_max_size) {
{
(void)obj; (void)obj;
spaced_print(p, p_max_size, "%hu", 4, info.run_threads); spaced_print(p, p_max_size, "%hu", 4, info.run_threads);
} }
void print_threads(struct text_object *obj, char *p, int p_max_size) void print_threads(struct text_object *obj, char *p, int p_max_size) {
{
(void)obj; (void)obj;
spaced_print(p, p_max_size, "%hu", 4, info.threads); spaced_print(p, p_max_size, "%hu", 4, info.threads);
} }
void print_buffers(struct text_object *obj, char *p, int p_max_size) void print_buffers(struct text_object *obj, char *p, int p_max_size) {
{
(void)obj; (void)obj;
human_readable(info.buffers * 1024, p, p_max_size); human_readable(info.buffers * 1024, p, p_max_size);
} }
void print_cached(struct text_object *obj, char *p, int p_max_size) void print_cached(struct text_object *obj, char *p, int p_max_size) {
{
(void)obj; (void)obj;
human_readable(info.cached * 1024, p, p_max_size); human_readable(info.cached * 1024, p, p_max_size);
} }
void print_evaluate(struct text_object *obj, char *p, int p_max_size) void print_evaluate(struct text_object *obj, char *p, int p_max_size) {
{
std::vector<char> buf(text_buffer_size.get(*state)); std::vector<char> buf(text_buffer_size.get(*state));
evaluate(obj->data.s, &buf[0], buf.size()); evaluate(obj->data.s, &buf[0], buf.size());
evaluate(&buf[0], p, p_max_size); evaluate(&buf[0], p, p_max_size);
} }
int if_empty_iftest(struct text_object *obj) int if_empty_iftest(struct text_object *obj) {
{
std::vector<char> buf(max_user_text.get(*state)); std::vector<char> buf(max_user_text.get(*state));
int result = 1; int result = 1;
@@ -577,8 +527,7 @@ int if_empty_iftest(struct text_object *obj)
return result; return result;
} }
static int check_contains(char *f, char *s) static int check_contains(char *f, char *s) {
{
int ret = 0; int ret = 0;
FILE *where = open_file(f, 0); FILE *where = open_file(f, 0);
@@ -598,8 +547,7 @@ static int check_contains(char *f, char *s)
return ret; return ret;
} }
int if_existing_iftest(struct text_object *obj) int if_existing_iftest(struct text_object *obj) {
{
char *spc; char *spc;
int result = 0; int result = 0;
@@ -612,8 +560,7 @@ int if_existing_iftest(struct text_object *obj)
return result; return result;
} }
int if_running_iftest(struct text_object *obj) int if_running_iftest(struct text_object *obj) {
{
#ifdef __linux__ #ifdef __linux__
if (!get_process_by_name(obj->data.s)) { if (!get_process_by_name(obj->data.s)) {
#else #else
@@ -625,27 +572,21 @@ int if_running_iftest(struct text_object *obj)
} }
#ifndef __OpenBSD__ #ifndef __OpenBSD__
void print_acpitemp(struct text_object *obj, char *p, int p_max_size) void print_acpitemp(struct text_object *obj, char *p, int p_max_size) {
{
temp_print(p, p_max_size, get_acpi_temperature(obj->data.i), TEMP_CELSIUS); temp_print(p, p_max_size, get_acpi_temperature(obj->data.i), TEMP_CELSIUS);
} }
void free_acpitemp(struct text_object *obj) void free_acpitemp(struct text_object *obj) { close(obj->data.i); }
{
close(obj->data.i);
}
#endif /* !__OpenBSD__ */ #endif /* !__OpenBSD__ */
void print_freq(struct text_object *obj, char *p, int p_max_size) void print_freq(struct text_object *obj, char *p, int p_max_size) {
{
static int ok = 1; static int ok = 1;
if (ok) { if (ok) {
ok = get_freq(p, p_max_size, "%.0f", 1, obj->data.i); ok = get_freq(p, p_max_size, "%.0f", 1, obj->data.i);
} }
} }
void print_freq_g(struct text_object *obj, char *p, int p_max_size) void print_freq_g(struct text_object *obj, char *p, int p_max_size) {
{
static int ok = 1; static int ok = 1;
if (ok) { if (ok) {
#ifndef __OpenBSD__ #ifndef __OpenBSD__
@@ -658,42 +599,35 @@ void print_freq_g(struct text_object *obj, char *p, int p_max_size)
} }
#ifndef __OpenBSD__ #ifndef __OpenBSD__
void print_acpifan(struct text_object *obj, char *p, int p_max_size) void print_acpifan(struct text_object *obj, char *p, int p_max_size) {
{
(void)obj; (void)obj;
get_acpi_fan(p, p_max_size); get_acpi_fan(p, p_max_size);
} }
void print_acpiacadapter(struct text_object *obj, char *p, int p_max_size) void print_acpiacadapter(struct text_object *obj, char *p, int p_max_size) {
{
get_acpi_ac_adapter(p, p_max_size, (const char *)obj->data.opaque); get_acpi_ac_adapter(p, p_max_size, (const char *)obj->data.opaque);
} }
void print_battery(struct text_object *obj, char *p, int p_max_size) void print_battery(struct text_object *obj, char *p, int p_max_size) {
{
get_battery_stuff(p, p_max_size, obj->data.s, BATTERY_STATUS); get_battery_stuff(p, p_max_size, obj->data.s, BATTERY_STATUS);
} }
void print_battery_time(struct text_object *obj, char *p, int p_max_size) void print_battery_time(struct text_object *obj, char *p, int p_max_size) {
{
get_battery_stuff(p, p_max_size, obj->data.s, BATTERY_TIME); get_battery_stuff(p, p_max_size, obj->data.s, BATTERY_TIME);
} }
uint8_t battery_percentage(struct text_object *obj) uint8_t battery_percentage(struct text_object *obj) {
{
return get_battery_perct(obj->data.s); return get_battery_perct(obj->data.s);
} }
void print_battery_short(struct text_object *obj, char *p, int p_max_size) void print_battery_short(struct text_object *obj, char *p, int p_max_size) {
{
get_battery_short_status(p, p_max_size, obj->data.s); get_battery_short_status(p, p_max_size, obj->data.s);
} }
#endif /* !__OpenBSD__ */ #endif /* !__OpenBSD__ */
void print_blink(struct text_object *obj, char *p, int p_max_size) {
void print_blink(struct text_object *obj, char *p, int p_max_size) // blinking like this can look a bit ugly if the chars in the font don't have
{ // the same width
//blinking like this can look a bit ugly if the chars in the font don't have the same width
std::vector<char> buf(max_user_text.get(*state)); std::vector<char> buf(max_user_text.get(*state));
static int visible = 1; static int visible = 1;
static int last_len = 0; static int last_len = 0;
@@ -703,28 +637,24 @@ void print_blink(struct text_object *obj, char *p, int p_max_size)
generate_text_internal(&(buf[0]), max_user_text.get(*state), *obj->sub); generate_text_internal(&(buf[0]), max_user_text.get(*state), *obj->sub);
last_len = strlen(&(buf[0])); last_len = strlen(&(buf[0]));
} else { } else {
for (i = 0; i < last_len; i++) for (i = 0; i < last_len; i++) buf[i] = ' ';
buf[i] = ' ';
} }
snprintf(p, p_max_size, "%s", &(buf[0])); snprintf(p, p_max_size, "%s", &(buf[0]));
visible = !visible; visible = !visible;
} }
void print_include(struct text_object *obj, char *p, int p_max_size) void print_include(struct text_object *obj, char *p, int p_max_size) {
{
std::vector<char> buf(max_user_text.get(*state)); std::vector<char> buf(max_user_text.get(*state));
if (!obj->sub) if (!obj->sub) return;
return;
generate_text_internal(&(buf[0]), max_user_text.get(*state), *obj->sub); generate_text_internal(&(buf[0]), max_user_text.get(*state), *obj->sub);
snprintf(p, p_max_size, "%s", &(buf[0])); snprintf(p, p_max_size, "%s", &(buf[0]));
} }
#ifdef BUILD_CURL #ifdef BUILD_CURL
void print_stock(struct text_object *obj, char *p, int p_max_size) void print_stock(struct text_object *obj, char *p, int p_max_size) {
{
if (!obj->data.s) { if (!obj->data.s) {
p[0] = 0; p[0] = 0;
return; return;
@@ -732,39 +662,39 @@ void print_stock(struct text_object *obj, char *p, int p_max_size)
ccurl_process_info(p, p_max_size, obj->data.s, 1); ccurl_process_info(p, p_max_size, obj->data.s, 1);
} }
void free_stock(struct text_object *obj) void free_stock(struct text_object *obj) { free(obj->data.s); }
{
free(obj->data.s);
}
#endif /* BUILD_CURL */ #endif /* BUILD_CURL */
void print_to_bytes(struct text_object *obj, char *p, int p_max_size) void print_to_bytes(struct text_object *obj, char *p, int p_max_size) {
{
std::vector<char> buf(max_user_text.get(*state)); std::vector<char> buf(max_user_text.get(*state));
long double bytes; long double bytes;
char unit[16]; // 16 because we can also have long names (like mega-bytes) char unit[16]; // 16 because we can also have long names (like mega-bytes)
generate_text_internal(&(buf[0]), max_user_text.get(*state), *obj->sub); generate_text_internal(&(buf[0]), max_user_text.get(*state), *obj->sub);
if (sscanf(&(buf[0]), "%Lf%s", &bytes, unit) == 2 && strlen(unit) < 16) { if (sscanf(&(buf[0]), "%Lf%s", &bytes, unit) == 2 && strlen(unit) < 16) {
if(strncasecmp("b", unit, 1) == 0) snprintf(&(buf[0]), max_user_text.get(*state), "%Lf", bytes); if (strncasecmp("b", unit, 1) == 0)
else if(strncasecmp("k", unit, 1) == 0) snprintf(&(buf[0]), max_user_text.get(*state), "%Lf", bytes * 1024); snprintf(&(buf[0]), max_user_text.get(*state), "%Lf", bytes);
else if(strncasecmp("m", unit, 1) == 0) snprintf(&(buf[0]), max_user_text.get(*state), "%Lf", bytes * 1024 * 1024); else if (strncasecmp("k", unit, 1) == 0)
else if(strncasecmp("g", unit, 1) == 0) snprintf(&(buf[0]), max_user_text.get(*state), "%Lf", bytes * 1024 * 1024 * 1024); snprintf(&(buf[0]), max_user_text.get(*state), "%Lf", bytes * 1024);
else if(strncasecmp("t", unit, 1) == 0) snprintf(&(buf[0]), max_user_text.get(*state), "%Lf", bytes * 1024 * 1024 * 1024 * 1024); else if (strncasecmp("m", unit, 1) == 0)
snprintf(&(buf[0]), max_user_text.get(*state), "%Lf",
bytes * 1024 * 1024);
else if (strncasecmp("g", unit, 1) == 0)
snprintf(&(buf[0]), max_user_text.get(*state), "%Lf",
bytes * 1024 * 1024 * 1024);
else if (strncasecmp("t", unit, 1) == 0)
snprintf(&(buf[0]), max_user_text.get(*state), "%Lf",
bytes * 1024 * 1024 * 1024 * 1024);
} }
snprintf(p, p_max_size, "%s", &(buf[0])); snprintf(p, p_max_size, "%s", &(buf[0]));
} }
void print_updates(struct text_object *obj, char *p, int p_max_size) {
void print_updates(struct text_object *obj, char *p, int p_max_size)
{
(void)obj; (void)obj;
snprintf(p, p_max_size, "%d", get_total_updates()); snprintf(p, p_max_size, "%d", get_total_updates());
} }
int updatenr_iftest(struct text_object *obj) int updatenr_iftest(struct text_object *obj) {
{ if (get_total_updates() % get_updatereset() != obj->data.i - 1) return 0;
if (get_total_updates() % get_updatereset() != obj->data.i - 1)
return 0;
return 1; return 1;
} }

View File

@@ -1,11 +1,10 @@
/* -*- mode: c++; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*- /*
* vim: ts=4 sw=4 noet ai cindent syntax=cpp
* *
* Conky, a system monitor, based on torsmo * Conky, a system monitor, based on torsmo
* *
* Please see COPYING for details * Please see COPYING for details
* *
* Copyright (c) 2005-2012 Brenden Matthews, Philip Kovacs, et. al. * Copyright (c) 2005-2018 Brenden Matthews, Philip Kovacs, et. al.
* (see AUTHORS) * (see AUTHORS)
* All rights reserved. * All rights reserved.
* *
@@ -28,11 +27,11 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string>
#include <string.h> #include <string.h>
#include <sys/socket.h> #include <sys/socket.h>
#include "text_object.h" #include <string>
#include "setting.hh" #include "setting.hh"
#include "text_object.h"
char *readfile(const char *filename, int *total_read, char showerror); char *readfile(const char *filename, int *total_read, char showerror);
@@ -60,7 +59,8 @@ void get_cpu_count(void);
double get_time(void); double get_time(void);
/* Converts '~/...' paths to '/home/blah/...' /* Converts '~/...' paths to '/home/blah/...'
* It's similar to variable_substitute, except only cheques for $HOME and ~/ in path */ * It's similar to variable_substitute, except only cheques for $HOME and ~/ in
* path */
std::string to_real_path(const std::string &source); std::string 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);
@@ -77,7 +77,8 @@ extern conky::simple_config_setting<bool> no_buffers;
int open_acpi_temperature(const char *name); int open_acpi_temperature(const char *name);
double get_acpi_temperature(int fd); double get_acpi_temperature(int fd);
void get_acpi_ac_adapter(char *p_client_buffer, size_t client_buffer_size, const char *adapter); void get_acpi_ac_adapter(char *p_client_buffer, size_t client_buffer_size,
const char *adapter);
void get_acpi_fan(char *, size_t); void get_acpi_fan(char *, size_t);
void get_battery_stuff(char *buf, unsigned int n, const char *bat, int item); void get_battery_stuff(char *buf, unsigned int n, const char *bat, int item);
int get_battery_perct(const char *bat); int get_battery_perct(const char *bat);
@@ -123,7 +124,6 @@ void print_sysname(struct text_object *, char *, int);
void print_version(struct text_object *obj, char *p, int p_max_size); void print_version(struct text_object *obj, char *p, int p_max_size);
#endif #endif
void print_uptime(struct text_object *, char *, int); void print_uptime(struct text_object *, char *, int);
void print_uptime_short(struct text_object *, char *, int); void print_uptime_short(struct text_object *, char *, int);

File diff suppressed because it is too large Load Diff

View File

@@ -1,5 +1,4 @@
/* -*- mode: c++; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*- /*
* vim: ts=4 sw=4 noet ai cindent syntax=cpp
* *
* Conky, a system monitor, based on torsmo * Conky, a system monitor, based on torsmo
* *
@@ -10,7 +9,7 @@
* Please see COPYING for details * Please see COPYING for details
* *
* Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen * Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
* Copyright (c) 2005-2012 Brenden Matthews, Philip Kovacs, et. al. * Copyright (c) 2005-2018 Brenden Matthews, Philip Kovacs, et. al.
* (see AUTHORS) * (see AUTHORS)
* All rights reserved. * All rights reserved.
* *
@@ -33,11 +32,11 @@
#define __STDC_FORMAT_MACROS #define __STDC_FORMAT_MACROS
#include <config.h> /* defines */
#include "common.h" /* at least for struct dns_data */
#include <sys/utsname.h> /* struct uname_s */
#include <arpa/inet.h> #include <arpa/inet.h>
#include <config.h> /* defines */
#include <sys/utsname.h> /* struct uname_s */
#include <memory> #include <memory>
#include "common.h" /* at least for struct dns_data */
#include "luamm.hh" #include "luamm.hh"
#if defined(HAS_MCHECK_H) #if defined(HAS_MCHECK_H)
@@ -164,10 +163,7 @@ char **get_templates(void);
/* get_battery_stuff() item selector /* get_battery_stuff() item selector
* needed by conky.c, linux.c and freebsd.c */ * needed by conky.c, linux.c and freebsd.c */
enum { enum { BATTERY_STATUS, BATTERY_TIME };
BATTERY_STATUS,
BATTERY_TIME
};
struct information { struct information {
unsigned int mask; unsigned int mask;
@@ -182,7 +178,8 @@ struct information {
double uptime; double uptime;
/* memory information in kilobytes */ /* memory information in kilobytes */
unsigned long long mem, memwithbuffers, memeasyfree, memfree, memmax, memdirty; unsigned long long mem, memwithbuffers, memeasyfree, memfree, memmax,
memdirty;
unsigned long long swap, swapfree, swapmax; unsigned long long swap, swapfree, swapmax;
unsigned long long bufmem, buffers, cached; unsigned long long bufmem, buffers, cached;
@@ -244,16 +241,15 @@ struct information {
#endif /* defined(__APPLE__) && defined(__MACH__) */ #endif /* defined(__APPLE__) && defined(__MACH__) */
}; };
class music_player_interval_setting: public conky::simple_config_setting<double> { class music_player_interval_setting
: public conky::simple_config_setting<double> {
typedef conky::simple_config_setting<double> Base; typedef conky::simple_config_setting<double> Base;
protected: protected:
virtual void lua_setter(lua::state &l, bool init); virtual void lua_setter(lua::state &l, bool init);
public: public:
music_player_interval_setting() music_player_interval_setting() : Base("music_player_interval", 0, true) {}
: Base("music_player_interval", 0, true)
{}
}; };
extern music_player_interval_setting music_player_interval; extern music_player_interval_setting music_player_interval;
@@ -278,16 +274,20 @@ enum {
#if !defined(MAX) #if !defined(MAX)
#define MAX(x, y) \ #define MAX(x, y) \
({ __typeof__ (x) _x = (x); \ ({ \
__typeof__(x) _x = (x); \
__typeof__(y) _y = (y); \ __typeof__(y) _y = (y); \
_x > _y ? _x : _y;}) _x > _y ? _x : _y; \
})
#endif #endif
#if !defined(MIN) #if !defined(MIN)
#define MIN(x, y) \ #define MIN(x, y) \
({ __typeof__ (x) _x = (x); \ ({ \
__typeof__(x) _x = (x); \
__typeof__(y) _y = (y); \ __typeof__(y) _y = (y); \
_x < _y ? _x : _y;}) _x < _y ? _x : _y; \
})
#endif #endif
/* defined in conky.c, needed by top.c */ /* defined in conky.c, needed by top.c */

File diff suppressed because it is too large Load Diff

View File

@@ -1,5 +1,4 @@
/* -*- mode: c++; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*- /*
* vim: ts=4 sw=4 noet ai cindent syntax=cpp
* *
* Conky, a system monitor, based on torsmo * Conky, a system monitor, based on torsmo
* *
@@ -10,7 +9,7 @@
* Please see COPYING for details * Please see COPYING for details
* *
* Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen * Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
* Copyright (c) 2005-2012 Brenden Matthews, Philip Kovacs, et. al. * Copyright (c) 2005-2018 Brenden Matthews, Philip Kovacs, et. al.
* (see AUTHORS) * (see AUTHORS)
* All rights reserved. * All rights reserved.
* *
@@ -33,12 +32,14 @@
#include "conky.h" #include "conky.h"
struct text_object *construct_text_object(const char *s, const char *arg, long struct text_object *construct_text_object(const char *s, const char *arg,
line, void **ifblock_opaque, void *free_at_crash); long line, void **ifblock_opaque,
void *free_at_crash);
size_t remove_comments(char *string); size_t remove_comments(char *string);
int extract_variable_text_internal(struct text_object *retval, const char *const_p); int extract_variable_text_internal(struct text_object *retval,
const char *const_p);
void free_text_objects(struct text_object *root); void free_text_objects(struct text_object *root);

File diff suppressed because it is too large Load Diff

View File

@@ -26,10 +26,10 @@
#ifndef DARWIN_H #ifndef DARWIN_H
#define DARWIN_H #define DARWIN_H
#include <sys/param.h>
#include <sys/mount.h>
#include <strings.h>
#include <stdio.h> #include <stdio.h>
#include <strings.h>
#include <sys/mount.h>
#include <sys/param.h>
/* /*
* on versions prior to Sierra clock_gettime is not implemented. * on versions prior to Sierra clock_gettime is not implemented.

View File

@@ -25,7 +25,8 @@
// //
// Defines for System Integrity Protection monitoring // Defines for System Integrity Protection monitoring
// based on csrstat tool by Pike R. Alpha. https://github.com/Piker-Alpha/csrstat // based on csrstat tool by Pike R. Alpha.
// https://github.com/Piker-Alpha/csrstat
// //
#ifndef DARWIN_SIP_H #ifndef DARWIN_SIP_H
@@ -43,22 +44,19 @@
#define CSR_ALLOW_ANY_RECOVERY_OS (1 << 8) // 256 #define CSR_ALLOW_ANY_RECOVERY_OS (1 << 8) // 256
#define CSR_ALLOW_UNAPPROVED_KEXTS (1 << 9) // 512 #define CSR_ALLOW_UNAPPROVED_KEXTS (1 << 9) // 512
#define CSR_VALID_FLAGS (CSR_ALLOW_UNTRUSTED_KEXTS | \ #define CSR_VALID_FLAGS \
CSR_ALLOW_UNRESTRICTED_FS | \ (CSR_ALLOW_UNTRUSTED_KEXTS | CSR_ALLOW_UNRESTRICTED_FS | \
CSR_ALLOW_TASK_FOR_PID | \ CSR_ALLOW_TASK_FOR_PID | CSR_ALLOW_KERNEL_DEBUGGER | \
CSR_ALLOW_KERNEL_DEBUGGER | \ CSR_ALLOW_APPLE_INTERNAL | CSR_ALLOW_UNRESTRICTED_DTRACE | \
CSR_ALLOW_APPLE_INTERNAL | \ CSR_ALLOW_UNRESTRICTED_NVRAM | CSR_ALLOW_DEVICE_CONFIGURATION | \
CSR_ALLOW_UNRESTRICTED_DTRACE | \ CSR_ALLOW_ANY_RECOVERY_OS | CSR_ALLOW_UNAPPROVED_KEXTS)
CSR_ALLOW_UNRESTRICTED_NVRAM | \
CSR_ALLOW_DEVICE_CONFIGURATION | \
CSR_ALLOW_ANY_RECOVERY_OS | \
CSR_ALLOW_UNAPPROVED_KEXTS)
/* Syscalls */ /* Syscalls */
// mark these symbols as weakly linked, as they may not be available // mark these symbols as weakly linked, as they may not be available
// at runtime on older OS X versions. // at runtime on older OS X versions.
extern "C" { extern "C" {
int csr_get_active_config(information::csr_config_t* config) __attribute__((weak_import)); int csr_get_active_config(information::csr_config_t* config)
__attribute__((weak_import));
}; };
#endif #endif

View File

@@ -1,5 +1,4 @@
/* -*- mode: c++; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*- /*
* vim: ts=4 sw=4 noet ai cindent syntax=cpp
* *
* Conky, a system monitor, based on torsmo * Conky, a system monitor, based on torsmo
* *
@@ -33,25 +32,24 @@ namespace conky {
namespace { namespace {
/* /*
* Returned when there is no data available. * Returned when there is no data available.
* An alternative would be to throw an exception, but if we don't want to react too * An alternative would be to throw an exception, but if we don't want to react
* aggresively when the user e.g. uses a nonexisting variable, then returning NaN will do * too aggresively when the user e.g. uses a nonexisting variable, then
* just fine. * returning NaN will do just fine.
*/ */
float NaN = std::numeric_limits<float>::quiet_NaN(); float NaN = std::numeric_limits<float>::quiet_NaN();
typedef std::unordered_map<std::string, lua::cpp_function> data_sources_t; typedef std::unordered_map<std::string, lua::cpp_function> data_sources_t;
/* /*
* We cannot construct this object statically, because order of object construction in * We cannot construct this object statically, because order of object
* different modules is not defined, so register_source could be called before this * construction in different modules is not defined, so register_source could be
* object is constructed. Therefore, we create it on the first call to register_source. * called before this object is constructed. Therefore, we create it on the
* first call to register_source.
*/ */
data_sources_t *data_sources; data_sources_t *data_sources;
data_source_base& get_data_source(lua::state *l) data_source_base &get_data_source(lua::state *l) {
{ if (l->gettop() != 1) throw std::runtime_error("Wrong number of parameters");
if(l->gettop() != 1)
throw std::runtime_error("Wrong number of parameters");
l->rawgetfield(lua::REGISTRYINDEX, priv::data_source_metatable); l->rawgetfield(lua::REGISTRYINDEX, priv::data_source_metatable);
if (not l->getmetatable(-2) or not l->rawequal(-1, -2)) if (not l->getmetatable(-2) or not l->rawequal(-1, -2))
@@ -60,15 +58,13 @@ namespace conky {
return *static_cast<data_source_base *>(l->touserdata(1)); return *static_cast<data_source_base *>(l->touserdata(1));
} }
int data_source_asnumber(lua::state *l) int data_source_asnumber(lua::state *l) {
{
double x = get_data_source(l).get_number(); double x = get_data_source(l).get_number();
l->pushnumber(x); l->pushnumber(x);
return 1; return 1;
} }
int data_source_astext(lua::state *l) int data_source_astext(lua::state *l) {
{
std::string x = get_data_source(l).get_text(); std::string x = get_data_source(l).get_text();
l->pushstring(x); l->pushstring(x);
return 1; return 1;
@@ -84,55 +80,57 @@ namespace conky {
" print(string.format([[Invalid data source operation: '%s']], key));\n" " print(string.format([[Invalid data source operation: '%s']], key));\n"
" return 0/0;\n" " return 0/0;\n"
"end\n"; "end\n";
} } // namespace
namespace priv { namespace priv {
void do_register_data_source(const std::string &name, const lua::cpp_function &fn) void do_register_data_source(const std::string &name,
{ const lua::cpp_function &fn) {
struct data_source_constructor { struct data_source_constructor {
data_source_constructor() { data_sources = new data_sources_t(); } data_source_constructor() { data_sources = new data_sources_t(); }
~data_source_constructor() { delete data_sources; data_sources = NULL; } ~data_source_constructor() {
delete data_sources;
data_sources = NULL;
}
}; };
static data_source_constructor constructor; static data_source_constructor constructor;
bool inserted = data_sources->insert({name, fn}).second; bool inserted = data_sources->insert({name, fn}).second;
if (not inserted) if (not inserted)
throw std::logic_error("Data source with name '" + name + "' already registered"); throw std::logic_error("Data source with name '" + name +
"' already registered");
} }
disabled_data_source::disabled_data_source(lua::state *l, const std::string &name, disabled_data_source::disabled_data_source(lua::state *l,
const std::string &name,
const std::string &setting) const std::string &setting)
: simple_numeric_source<float>(l, name, &NaN) : simple_numeric_source<float>(l, name, &NaN) {
{
// XXX some generic way of reporting errors? NORM_ERR? // XXX some generic way of reporting errors? NORM_ERR?
std::cerr << "Support for variable '" << name std::cerr << "Support for variable '" << name
<< "' has been disabled during compilation. Please recompile with '" << "' has been disabled during compilation. Please recompile with '"
<< setting << "'" << std::endl; << setting << "'" << std::endl;
} }
} } // namespace priv
double data_source_base::get_number() const double data_source_base::get_number() const { return NaN; }
{ return NaN; }
std::string data_source_base::get_text() const std::string data_source_base::get_text() const {
{
std::ostringstream s; std::ostringstream s;
s << get_number(); s << get_number();
return s.str(); return s.str();
} }
register_disabled_data_source::register_disabled_data_source(const std::string &name, register_disabled_data_source::register_disabled_data_source(
const std::string &setting) const std::string &name, const std::string &setting)
: register_data_source<priv::disabled_data_source>(name, setting) : register_data_source<priv::disabled_data_source>(name, setting) {}
{}
// at least one data source should always be registered, so data_sources will not be null // at least one data source should always be registered, so data_sources will
void export_data_sources(lua::state &l) // not be null
{ void export_data_sources(lua::state &l) {
lua::stack_sentry s(l); lua::stack_sentry s(l);
l.checkstack(2); l.checkstack(2);
l.newmetatable(priv::data_source_metatable); { l.newmetatable(priv::data_source_metatable);
{
l.pushboolean(false); l.pushboolean(false);
l.rawsetfield(-2, "__metatable"); l.rawsetfield(-2, "__metatable");
@@ -141,14 +139,17 @@ namespace conky {
l.loadstring(data_source__index); l.loadstring(data_source__index);
l.rawsetfield(-2, "__index"); l.rawsetfield(-2, "__index");
} l.pop(); }
l.pop();
l.newtable(); { l.newtable();
{
for (auto i = data_sources->begin(); i != data_sources->end(); ++i) { for (auto i = data_sources->begin(); i != data_sources->end(); ++i) {
l.pushfunction(i->second); l.pushfunction(i->second);
l.rawsetfield(-2, i->first.c_str()); l.rawsetfield(-2, i->first.c_str());
} }
} l.rawsetfield(-2, "variables"); }
l.rawsetfield(-2, "variables");
l.pushfunction(data_source_asnumber); l.pushfunction(data_source_asnumber);
l.rawsetfield(-2, "asnumber"); l.rawsetfield(-2, "asnumber");
@@ -156,10 +157,12 @@ namespace conky {
l.pushfunction(data_source_astext); l.pushfunction(data_source_astext);
l.rawsetfield(-2, "astext"); l.rawsetfield(-2, "astext");
} }
} } // namespace conky
/////////// example data sources, remove after real data sources are available /////// /////////// example data sources, remove after real data sources are available
//////////
int asdf_ = 47; int asdf_ = 47;
conky::register_data_source<conky::simple_numeric_source<int>> asdf("asdf", &asdf_); conky::register_data_source<conky::simple_numeric_source<int>> asdf("asdf",
&asdf_);
conky::register_disabled_data_source zxcv("zxcv", "BUILD_ZXCV"); conky::register_disabled_data_source zxcv("zxcv", "BUILD_ZXCV");

View File

@@ -1,5 +1,4 @@
/* -*- mode: c++; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*- /*
* vim: ts=4 sw=4 noet ai cindent syntax=cpp
* *
* Conky, a system monitor, based on torsmo * Conky, a system monitor, based on torsmo
* *
@@ -35,19 +34,19 @@ namespace conky {
/* /*
* A base class for all data sources. * A base class for all data sources.
* API consists of two functions: * API consists of two functions:
* - get_number should return numeric representation of the data (if available). This can * - get_number should return numeric representation of the data (if available).
* then be used when drawing graphs, bars, ... The default implementation returns NaN. * This can then be used when drawing graphs, bars, ... The default
* - get_text should return textual representation of the data. This is used when simple * implementation returns NaN.
* displaying the value of the data source. The default implementation converts * - get_text should return textual representation of the data. This is used
* get_number() to a string, but you can override to return anything (e.g. add units) * when simple displaying the value of the data source. The default
* implementation converts get_number() to a string, but you can override to
* return anything (e.g. add units)
*/ */
class data_source_base { class data_source_base {
public: public:
const std::string name; const std::string name;
data_source_base(const std::string &name_) data_source_base(const std::string &name_) : name(name_) {}
: name(name_)
{}
virtual ~data_source_base() {} virtual ~data_source_base() {}
virtual double get_number() const; virtual double get_number() const;
@@ -55,33 +54,35 @@ namespace conky {
}; };
/* /*
* A simple data source that returns the value of some variable. It ignores the lua table. * A simple data source that returns the value of some variable. It ignores the
* The source variable can be specified as a fixed parameter to the register_data_source * lua table. The source variable can be specified as a fixed parameter to the
* constructor, or one can create a subclass and then set the source from the subclass * register_data_source constructor, or one can create a subclass and then set
* constructor. * the source from the subclass constructor.
*/ */
template <typename T> template <typename T>
class simple_numeric_source : public data_source_base { class simple_numeric_source : public data_source_base {
static_assert(std::is_convertible<T, double>::value, "T must be convertible to double"); static_assert(std::is_convertible<T, double>::value,
"T must be convertible to double");
const T *source; const T *source;
public:
simple_numeric_source(lua::state *, const std::string &name_, const T *source_)
: data_source_base(name_), source(source_)
{}
virtual double get_number() const public:
{ return *source; } simple_numeric_source(lua::state *, const std::string &name_,
const T *source_)
: data_source_base(name_), source(source_) {}
virtual double get_number() const { return *source; }
}; };
/* /*
* This is a part of the implementation, but it cannot be in .cc file because the template * This is a part of the implementation, but it cannot be in .cc file because
* functions below call it * the template functions below call it
*/ */
namespace priv { namespace priv {
const char data_source_metatable[] = "conky::data_source_metatable"; const char data_source_metatable[] = "conky::data_source_metatable";
void do_register_data_source(const std::string &name, const lua::cpp_function &fn); void do_register_data_source(const std::string &name,
const lua::cpp_function &fn);
class disabled_data_source : public simple_numeric_source<float> { class disabled_data_source : public simple_numeric_source<float> {
public: public:
@@ -89,17 +90,18 @@ namespace conky {
const std::string &setting); const std::string &setting);
}; };
} } // namespace priv
/* /*
* Declaring an object of this type at global scope will register a data source with the * Declaring an object of this type at global scope will register a data source
* given name. Any additional parameters are passed on to the data source constructor. * with the given name. Any additional parameters are passed on to the data
* source constructor.
*/ */
template <typename T> template <typename T>
class register_data_source { class register_data_source {
template <typename... Args> template <typename... Args>
static int factory(lua::state *l, const std::string &name, const Args&... args) static int factory(lua::state *l, const std::string &name,
{ const Args &... args) {
T *t = static_cast<T *>(l->newuserdata(sizeof(T))); T *t = static_cast<T *>(l->newuserdata(sizeof(T)));
l->insert(1); l->insert(1);
new (t) T(l, name, args...); new (t) T(l, name, args...);
@@ -111,28 +113,30 @@ namespace conky {
public: public:
template <typename... Args> template <typename... Args>
register_data_source(const std::string &name, Args&&... args) register_data_source(const std::string &name, Args &&... args) {
{ priv::do_register_data_source(
priv::do_register_data_source( name, std::bind(&factory<Args...>, name,
std::placeholders::_1, name, args... std::bind(&factory<Args...>, std::placeholders::_1, name, args...));
));
} }
}; };
/* /*
* Use this to declare a data source that has been disabled during compilation. We can then * Use this to declare a data source that has been disabled during compilation.
* print a nice error message telling the used which setting to enable. * We can then print a nice error message telling the used which setting to
* enable.
*/ */
class register_disabled_data_source: public register_data_source<priv::disabled_data_source> { class register_disabled_data_source
: public register_data_source<priv::disabled_data_source> {
public: public:
register_disabled_data_source(const std::string &name, const std::string &setting); register_disabled_data_source(const std::string &name,
const std::string &setting);
}; };
/* /*
* It expects to have a table at the top of lua stack. It then exports all the data sources * It expects to have a table at the top of lua stack. It then exports all the
* into that table (actually, into a "variables" subtable). * data sources into that table (actually, into a "variables" subtable).
*/ */
void export_data_sources(lua::state &l); void export_data_sources(lua::state &l);
} } // namespace conky
#endif /* DATA_SOURCE_HH */ #endif /* DATA_SOURCE_HH */

View File

@@ -1,5 +1,4 @@
/* -*- mode: c++; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*- /*
* vim: ts=4 sw=4 noet ai cindent syntax=cpp
* *
* Conky, a system monitor, based on torsmo * Conky, a system monitor, based on torsmo
* *
@@ -10,7 +9,7 @@
* Please see COPYING for details * Please see COPYING for details
* *
* Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen * Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
* Copyright (c) 2005-2012 Brenden Matthews, Philip Kovacs, et. al. * Copyright (c) 2005-2018 Brenden Matthews, Philip Kovacs, et. al.
* (see AUTHORS) * (see AUTHORS)
* All rights reserved. * All rights reserved.
* *
@@ -28,24 +27,23 @@
* *
*/ */
#include "diskio.h"
#include <stdlib.h>
#include <sys/stat.h>
#include <vector>
#include "common.h"
#include "config.h" #include "config.h"
#include "conky.h" /* text_buffer_size */ #include "conky.h" /* text_buffer_size */
#include "core.h" #include "core.h"
#include "logging.h" #include "logging.h"
#include "diskio.h"
#include "common.h"
#include "specials.h" #include "specials.h"
#include "text_object.h" #include "text_object.h"
#include <stdlib.h>
#include <sys/stat.h>
#include <vector>
/* this is the root of all per disk stats, /* this is the root of all per disk stats,
* also containing the totals. */ * also containing the totals. */
struct diskio_stat stats; struct diskio_stat stats;
void clear_diskio_stats(void) void clear_diskio_stats(void) {
{
struct diskio_stat *cur; struct diskio_stat *cur;
while (stats.next) { while (stats.next) {
cur = stats.next; cur = stats.next;
@@ -55,10 +53,11 @@ void clear_diskio_stats(void)
} }
} }
struct diskio_stat *prepare_diskio_stat(const char *s) struct diskio_stat *prepare_diskio_stat(const char *s) {
{
struct stat sb; struct stat sb;
std::vector<char> stat_name(text_buffer_size.get(*state)), device_name(text_buffer_size.get(*state)), device_s(text_buffer_size.get(*state)); std::vector<char> stat_name(text_buffer_size.get(*state)),
device_name(text_buffer_size.get(*state)),
device_s(text_buffer_size.get(*state));
struct diskio_stat *cur = &stats; struct diskio_stat *cur = &stats;
char *rpbuf; char *rpbuf;
@@ -67,7 +66,8 @@ struct diskio_stat *prepare_diskio_stat(const char *s)
} }
if (strncmp(s, "label:", 6) == 0) { if (strncmp(s, "label:", 6) == 0) {
snprintf(&(device_name[0]), text_buffer_size.get(*state), "/dev/disk/by-label/%s", s+6); snprintf(&(device_name[0]), text_buffer_size.get(*state),
"/dev/disk/by-label/%s", s + 6);
rpbuf = realpath(&device_name[0], NULL); rpbuf = realpath(&device_name[0], NULL);
} else { } else {
rpbuf = realpath(s, NULL); rpbuf = realpath(s, NULL);
@@ -92,7 +92,8 @@ struct diskio_stat *prepare_diskio_stat(const char *s)
* On Solaris we currently don't use the name of disk's special file so * On Solaris we currently don't use the name of disk's special file so
* this test is useless. * this test is useless.
*/ */
snprintf(&(stat_name[0]), text_buffer_size.get(*state), "/dev/%s", &(device_name[0])); snprintf(&(stat_name[0]), text_buffer_size.get(*state), "/dev/%s",
&(device_name[0]));
if (stat(&(stat_name[0]), &sb) || !S_ISBLK(sb.st_mode)) { if (stat(&(stat_name[0]), &sb) || !S_ISBLK(sb.st_mode)) {
NORM_ERR("diskio device '%s' does not exist", &device_s[0]); NORM_ERR("diskio device '%s' does not exist", &device_s[0]);
@@ -118,8 +119,7 @@ struct diskio_stat *prepare_diskio_stat(const char *s)
return cur; return cur;
} }
void parse_diskio_arg(struct text_object *obj, const char *arg) void parse_diskio_arg(struct text_object *obj, const char *arg) {
{
obj->data.opaque = prepare_diskio_stat(arg); obj->data.opaque = prepare_diskio_stat(arg);
} }
@@ -128,13 +128,12 @@ void parse_diskio_arg(struct text_object *obj, const char *arg)
* 0: read + write * 0: read + write
* 1: write * 1: write
*/ */
static void print_diskio_dir(struct text_object *obj, int dir, char *p, int p_max_size) static void print_diskio_dir(struct text_object *obj, int dir, char *p,
{ int p_max_size) {
struct diskio_stat *diskio = (struct diskio_stat *)obj->data.opaque; struct diskio_stat *diskio = (struct diskio_stat *)obj->data.opaque;
double val; double val;
if (!diskio) if (!diskio) return;
return;
if (dir < 0) if (dir < 0)
val = diskio->current_read; val = diskio->current_read;
@@ -148,24 +147,20 @@ static void print_diskio_dir(struct text_object *obj, int dir, char *p, int p_ma
human_readable((val / active_update_interval()) * 1024LL, p, p_max_size); human_readable((val / active_update_interval()) * 1024LL, p, p_max_size);
} }
void print_diskio(struct text_object *obj, char *p, int p_max_size) void print_diskio(struct text_object *obj, char *p, int p_max_size) {
{
print_diskio_dir(obj, 0, p, p_max_size); print_diskio_dir(obj, 0, p, p_max_size);
} }
void print_diskio_read(struct text_object *obj, char *p, int p_max_size) void print_diskio_read(struct text_object *obj, char *p, int p_max_size) {
{
print_diskio_dir(obj, -1, p, p_max_size); print_diskio_dir(obj, -1, p, p_max_size);
} }
void print_diskio_write(struct text_object *obj, char *p, int p_max_size) void print_diskio_write(struct text_object *obj, char *p, int p_max_size) {
{
print_diskio_dir(obj, 1, p, p_max_size); print_diskio_dir(obj, 1, p, p_max_size);
} }
#ifdef BUILD_X11 #ifdef BUILD_X11
void parse_diskiograph_arg(struct text_object *obj, const char *arg) void parse_diskiograph_arg(struct text_object *obj, const char *arg) {
{
char *buf = 0; char *buf = 0;
buf = scan_graph(obj, arg, 0); buf = scan_graph(obj, arg, 0);
@@ -173,31 +168,27 @@ void parse_diskiograph_arg(struct text_object *obj, const char *arg)
free_and_zero(buf); free_and_zero(buf);
} }
double diskiographval(struct text_object *obj) double diskiographval(struct text_object *obj) {
{
struct diskio_stat *diskio = (struct diskio_stat *)obj->data.opaque; struct diskio_stat *diskio = (struct diskio_stat *)obj->data.opaque;
return (diskio ? diskio->current : 0); return (diskio ? diskio->current : 0);
} }
double diskiographval_read(struct text_object *obj) double diskiographval_read(struct text_object *obj) {
{
struct diskio_stat *diskio = (struct diskio_stat *)obj->data.opaque; struct diskio_stat *diskio = (struct diskio_stat *)obj->data.opaque;
return (diskio ? diskio->current_read : 0); return (diskio ? diskio->current_read : 0);
} }
double diskiographval_write(struct text_object *obj) double diskiographval_write(struct text_object *obj) {
{
struct diskio_stat *diskio = (struct diskio_stat *)obj->data.opaque; struct diskio_stat *diskio = (struct diskio_stat *)obj->data.opaque;
return (diskio ? diskio->current_write : 0); return (diskio ? diskio->current_write : 0);
} }
#endif /* BUILD_X11 */ #endif /* BUILD_X11 */
void update_diskio_values(struct diskio_stat *ds, void update_diskio_values(struct diskio_stat *ds, unsigned int reads,
unsigned int reads, unsigned int writes) unsigned int writes) {
{
int i; int i;
double sum = 0, sum_r = 0, sum_w = 0; double sum = 0, sum_r = 0, sum_w = 0;
@@ -237,4 +228,3 @@ void update_diskio_values(struct diskio_stat *ds,
ds->last_write = writes; ds->last_write = writes;
ds->last = ds->last_read + ds->last_write; ds->last = ds->last_read + ds->last_write;
} }

View File

@@ -1,5 +1,4 @@
/* -*- mode: c++; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*- /*
* vim: ts=4 sw=4 noet ai cindent syntax=cpp
* *
* Conky, a system monitor, based on torsmo * Conky, a system monitor, based on torsmo
* *
@@ -10,7 +9,7 @@
* Please see COPYING for details * Please see COPYING for details
* *
* Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen * Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
* Copyright (c) 2005-2012 Brenden Matthews, Philip Kovacs, et. al. * Copyright (c) 2005-2018 Brenden Matthews, Philip Kovacs, et. al.
* (see AUTHORS) * (see AUTHORS)
* All rights reserved. * All rights reserved.
* *
@@ -32,20 +31,21 @@
#define DISKIO_H_ #define DISKIO_H_
#include <limits.h> #include <limits.h>
#include <cstring>
struct diskio_stat { struct diskio_stat {
diskio_stat() : diskio_stat()
next(NULL), : next(nullptr),
current(0), current(0),
current_read(0), current_read(0),
current_write(0), current_write(0),
last(UINT_MAX), last(UINT_MAX),
last_read(UINT_MAX), last_read(UINT_MAX),
last_write(UINT_MAX) last_write(UINT_MAX) {
{ std::memset(sample, 0, sizeof(sample) / sizeof(sample[0]));
memset(sample, 0, sizeof(sample) / sizeof(sample[0])); std::memset(sample_read, 0, sizeof(sample_read) / sizeof(sample_read[0]));
memset(sample_read, 0, sizeof(sample_read) / sizeof(sample_read[0])); std::memset(sample_write, 0,
memset(sample_write, 0, sizeof(sample_write) / sizeof(sample_write[0])); sizeof(sample_write) / sizeof(sample_write[0]));
} }
struct diskio_stat *next; struct diskio_stat *next;
char *dev; char *dev;

View File

@@ -1,5 +1,4 @@
/* -*- mode: c++; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*- /*
* vim: ts=4 sw=4 noet ai cindent syntax=cpp
* *
* Conky, a system monitor, based on torsmo * Conky, a system monitor, based on torsmo
* *
@@ -28,6 +27,7 @@
#include "config.h" #include "config.h"
#include <kinfo_pcpu.h>
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <sys/param.h> #include <sys/param.h>
#include <sys/resource.h> #include <sys/resource.h>
@@ -37,27 +37,26 @@
#include <sys/time.h> #include <sys/time.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/user.h> #include <sys/user.h>
#include <kinfo_pcpu.h>
#include <net/if.h> #include <net/if.h>
#include <net/if_mib.h>
#include <net/if_media.h> #include <net/if_media.h>
#include <net/if_mib.h>
#include <net/if_var.h> #include <net/if_var.h>
#include <devstat.h> #include <devstat.h>
#include <ifaddrs.h> #include <ifaddrs.h>
#include <limits.h> #include <limits.h>
#include <unistd.h>
#include <pthread.h> #include <pthread.h>
#include <unistd.h>
#include <dev/acpica/acpiio.h> #include <dev/acpica/acpiio.h>
#include "conky.h" #include "conky.h"
#include "diskio.h"
#include "dragonfly.h" #include "dragonfly.h"
#include "logging.h" #include "logging.h"
#include "net_stat.h" #include "net_stat.h"
#include "top.h" #include "top.h"
#include "diskio.h"
#define GETSYSCTL(name, var) getsysctl(name, &(var), sizeof(var)) #define GETSYSCTL(name, var) getsysctl(name, &(var), sizeof(var))
#define KELVTOC(x) ((x - 2732) / 10.0) #define KELVTOC(x) ((x - 2732) / 10.0)
@@ -65,13 +64,11 @@
static short cpu_setup = 0; static short cpu_setup = 0;
static int getsysctl(const char *name, void *ptr, size_t len) static int getsysctl(const char *name, void *ptr, size_t len) {
{
size_t nlen = len; size_t nlen = len;
if (sysctlbyname(name, ptr, &nlen, NULL, 0) == -1) { if (sysctlbyname(name, ptr, &nlen, NULL, 0) == -1) {
fprintf(stderr, "getsysctl(): %s failed '%s'\n", fprintf(stderr, "getsysctl(): %s failed '%s'\n", name, strerror(errno));
name, strerror(errno));
return -1; return -1;
} }
@@ -83,9 +80,9 @@ static int getsysctl(const char *name, void *ptr, size_t len)
return 0; return 0;
} }
static int swapmode(unsigned long *retavail, unsigned long *retfree) static int swapmode(unsigned long *retavail, unsigned long *retfree) {
{ int total, used;
int total, used; size_t len = sizeof(int); size_t len = sizeof(int);
if (sysctlbyname("vm.swap_size", &total, &len, NULL, 0) == -1) if (sysctlbyname("vm.swap_size", &total, &len, NULL, 0) == -1)
perror("vm_swap_usage(): vm.swap_size"); perror("vm_swap_usage(): vm.swap_size");
@@ -104,12 +101,9 @@ static int swapmode(unsigned long *retavail, unsigned long *retfree)
return 0; return 0;
} }
void prepare_update(void) void prepare_update(void) {}
{
}
int update_uptime(void) int update_uptime(void) {
{
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;
@@ -126,8 +120,7 @@ int update_uptime(void)
return 0; return 0;
} }
int check_mount(char *s) int check_mount(char *s) {
{
struct statfs *mntbuf; struct statfs *mntbuf;
int i, mntsize; int i, mntsize;
@@ -141,8 +134,7 @@ int check_mount(char *s)
return 0; return 0;
} }
int update_meminfo(void) int update_meminfo(void) {
{
u_int total_pages, inactive_pages, free_pages; u_int total_pages, inactive_pages, free_pages;
unsigned long swap_avail, swap_free; unsigned long swap_avail, swap_free;
@@ -177,8 +169,7 @@ int update_meminfo(void)
return 0; return 0;
} }
int update_net_stats(void) int update_net_stats(void) {
{
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;
@@ -213,8 +204,7 @@ int update_net_stats(void)
iftmp != NULL && strcmp(ifa->ifa_name, iftmp->ifa_name) == 0; iftmp != NULL && strcmp(ifa->ifa_name, iftmp->ifa_name) == 0;
iftmp = iftmp->ifa_next) { iftmp = iftmp->ifa_next) {
if (iftmp->ifa_addr->sa_family == AF_INET) { if (iftmp->ifa_addr->sa_family == AF_INET) {
memcpy(&(ns->addr), iftmp->ifa_addr, memcpy(&(ns->addr), iftmp->ifa_addr, iftmp->ifa_addr->sa_len);
iftmp->ifa_addr->sa_len);
} }
} }
@@ -231,8 +221,7 @@ int update_net_stats(void)
ns->last_read_recv = r; ns->last_read_recv = r;
if (t < ns->last_read_trans) { if (t < ns->last_read_trans) {
ns->trans += ((long long) 4294967295U - ns->trans += ((long long)4294967295U - ns->last_read_trans) + t;
ns->last_read_trans) + t;
} else { } else {
ns->trans += (t - ns->last_read_trans); ns->trans += (t - ns->last_read_trans);
} }
@@ -251,8 +240,7 @@ int update_net_stats(void)
return 0; return 0;
} }
static int kern_proc_all_n() static int kern_proc_all_n() {
{
size_t len = 0; size_t len = 0;
if (sysctlbyname("kern.proc.all_lwp", NULL, &len, NULL, 0) == -1) { if (sysctlbyname("kern.proc.all_lwp", NULL, &len, NULL, 0) == -1) {
@@ -261,7 +249,8 @@ static int kern_proc_all_n()
} }
if (len % sizeof(struct kinfo_proc)) { if (len % sizeof(struct kinfo_proc)) {
fprintf(stderr, "kern_proc(): " fprintf(stderr,
"kern_proc(): "
"len %% sizeof(struct kinfo_proc) != 0"); "len %% sizeof(struct kinfo_proc) != 0");
return -1; return -1;
} }
@@ -269,8 +258,7 @@ static int kern_proc_all_n()
return len / sizeof(struct kinfo_proc); return len / sizeof(struct kinfo_proc);
} }
static struct kinfo_proc *kern_proc_all(size_t proc_n) static struct kinfo_proc *kern_proc_all(size_t proc_n) {
{
if (proc_n > 0) { if (proc_n > 0) {
size_t len = proc_n * sizeof(struct kinfo_proc); size_t len = proc_n * sizeof(struct kinfo_proc);
struct kinfo_proc *kp = (struct kinfo_proc *)malloc(len); struct kinfo_proc *kp = (struct kinfo_proc *)malloc(len);
@@ -278,16 +266,16 @@ static struct kinfo_proc *kern_proc_all(size_t proc_n)
if (kp) { if (kp) {
if (sysctlbyname("kern.proc.all_lwp", kp, &len, NULL, 0) == -1) if (sysctlbyname("kern.proc.all_lwp", kp, &len, NULL, 0) == -1)
perror("kern_proc(): kern.proc.all_lwp"); perror("kern_proc(): kern.proc.all_lwp");
else return kp; else
return kp;
free(kp); free(kp);
} } else
else perror("malloc"); perror("malloc");
} }
return NULL; return NULL;
} }
void get_cpu_count(void) void get_cpu_count(void) {
{
int cpu_count = 0; int cpu_count = 0;
if (GETSYSCTL("hw.ncpu", cpu_count) == 0) { if (GETSYSCTL("hw.ncpu", cpu_count) == 0) {
@@ -310,22 +298,21 @@ struct cpu_info {
PCPU_STATISTICS_FUNC(cputime, struct kinfo_cputime, uint64_t); PCPU_STATISTICS_FUNC(cputime, struct kinfo_cputime, uint64_t);
static void stat_cpu(struct cpu_info *cpu, static void stat_cpu(struct cpu_info *cpu, struct kinfo_cputime *percpu,
struct kinfo_cputime *percpu, float *usage) float *usage) {
{ long int used = (percpu->cp_user + percpu->cp_nice + percpu->cp_sys +
long int used = (percpu->cp_user + percpu->cp_nice + percpu->cp_intr),
percpu->cp_sys + percpu->cp_intr),
total = used + percpu->cp_idle; total = used + percpu->cp_idle;
*usage = (total - cpu->oldtotal) && cpu->oldtotal ? *usage = (total - cpu->oldtotal) && cpu->oldtotal
((float) (used - cpu->oldused)) / (total - cpu->oldtotal) : 0; ? ((float)(used - cpu->oldused)) / (total - cpu->oldtotal)
: 0;
cpu->oldused = used; cpu->oldused = used;
cpu->oldtotal = total; cpu->oldtotal = total;
} }
int update_cpu_usage(void) int update_cpu_usage(void) {
{
static struct cpu_info *cpu = NULL; static struct cpu_info *cpu = NULL;
extern void *global_cpu; extern void *global_cpu;
@@ -336,23 +323,23 @@ int update_cpu_usage(void)
} }
if (!global_cpu) { if (!global_cpu) {
if (!cpu) cpu = (struct cpu_info *) if (!cpu)
calloc(sizeof(struct cpu_info), info.cpu_count + 1); cpu = (struct cpu_info *)calloc(sizeof(struct cpu_info),
info.cpu_count + 1);
global_cpu = cpu; global_cpu = cpu;
} }
{ {
size_t percpu_n = info.cpu_count * sizeof(struct kinfo_cputime); size_t percpu_n = info.cpu_count * sizeof(struct kinfo_cputime);
struct kinfo_cputime *percpu = (struct kinfo_cputime *) struct kinfo_cputime *percpu = (struct kinfo_cputime *)malloc(
malloc(info.cpu_count * sizeof(struct kinfo_cputime)); info.cpu_count * sizeof(struct kinfo_cputime));
if (percpu) { if (percpu) {
if (sysctlbyname("kern.cputime", percpu, if (sysctlbyname("kern.cputime", percpu, &percpu_n, NULL, 0) == -1 &&
&percpu_n, NULL, 0) == -1 && errno != ENOMEM) { errno != ENOMEM) {
printf("update_cpu_usage(): with %d cpu(s) ", info.cpu_count); printf("update_cpu_usage(): with %d cpu(s) ", info.cpu_count);
perror("kern.cputime"); perror("kern.cputime");
} } else {
else {
struct kinfo_cputime total; struct kinfo_cputime total;
cputime_pcpu_statistics(&percpu[0], &total, info.cpu_count); cputime_pcpu_statistics(&percpu[0], &total, info.cpu_count);
@@ -370,8 +357,7 @@ int update_cpu_usage(void)
return 0; return 0;
} }
int update_load_average(void) int update_load_average(void) {
{
double v[3]; double v[3];
getloadavg(v, 3); getloadavg(v, 3);
@@ -383,21 +369,20 @@ int update_load_average(void)
return 0; return 0;
} }
double get_acpi_temperature(int fd) double get_acpi_temperature(int fd) {
{
int temp; int temp;
(void)fd; (void)fd;
if (GETSYSCTL("hw.acpi.thermal.tz0.temperature", temp)) { if (GETSYSCTL("hw.acpi.thermal.tz0.temperature", temp)) {
fprintf(stderr, fprintf(stderr, "Cannot read sysctl \"hw.acpi.thermal.tz0.temperature\"\n");
"Cannot read sysctl \"hw.acpi.thermal.tz0.temperature\"\n");
return 0.0; return 0.0;
} }
return KELVTOC(temp); return KELVTOC(temp);
} }
static void get_battery_stats(int *battime, int *batcapacity, int *batstate, int *ac) { static void get_battery_stats(int *battime, int *batcapacity, int *batstate,
int *ac) {
if (battime && GETSYSCTL("hw.acpi.battery.time", *battime)) { if (battime && GETSYSCTL("hw.acpi.battery.time", *battime)) {
fprintf(stderr, "Cannot read sysctl \"hw.acpi.battery.time\"\n"); fprintf(stderr, "Cannot read sysctl \"hw.acpi.battery.time\"\n");
} }
@@ -412,8 +397,7 @@ static void get_battery_stats(int *battime, int *batcapacity, int *batstate, int
} }
} }
void get_battery_stuff(char *buf, unsigned int n, const char *bat, int item) void get_battery_stuff(char *buf, unsigned int n, const char *bat, int item) {
{
int battime, batcapacity, batstate, ac; int battime, batcapacity, batstate, ac;
(void)bat; (void)bat;
@@ -435,8 +419,10 @@ void get_battery_stuff(char *buf, unsigned int n, const char *bat, int item)
if (batstate == 1) // Discharging if (batstate == 1) // Discharging
snprintf(buf, n, "remaining %d%%", batcapacity); snprintf(buf, n, "remaining %d%%", batcapacity);
else else
snprintf(buf, n, batstate == 2 ? "charging (%d%%)" : snprintf(buf, n,
(batstate == 7 ? "absent/on AC" : "charged (%d%%)"), batstate == 2
? "charging (%d%%)"
: (batstate == 7 ? "absent/on AC" : "charged (%d%%)"),
batcapacity); batcapacity);
break; break;
default: default:
@@ -444,8 +430,7 @@ void get_battery_stuff(char *buf, unsigned int n, const char *bat, int item)
} }
} }
static int check_bat(const char *bat) static int check_bat(const char *bat) {
{
int batnum, numbatts; int batnum, numbatts;
char *endptr; char *endptr;
if (GETSYSCTL("hw.acpi.battery.units", numbatts)) { if (GETSYSCTL("hw.acpi.battery.units", numbatts)) {
@@ -456,22 +441,20 @@ static int check_bat(const char *bat)
fprintf(stderr, "No battery unit detected\n"); fprintf(stderr, "No battery unit detected\n");
return -1; return -1;
} }
if (!bat || (batnum = strtol(bat, &endptr, 10)) < 0 || if (!bat || (batnum = strtol(bat, &endptr, 10)) < 0 || bat == endptr ||
bat == endptr || batnum > numbatts) { batnum > numbatts) {
fprintf(stderr, "Wrong battery unit %s requested\n", bat ? bat : ""); fprintf(stderr, "Wrong battery unit %s requested\n", bat ? bat : "");
return -1; return -1;
} }
return batnum; return batnum;
} }
int get_battery_perct(const char *bat) int get_battery_perct(const char *bat) {
{
union acpi_battery_ioctl_arg battio; union acpi_battery_ioctl_arg battio;
int batnum, acpifd; int batnum, acpifd;
int designcap, lastfulcap, batperct; int designcap, lastfulcap, batperct;
if ((battio.unit = batnum = check_bat(bat)) < 0) if ((battio.unit = batnum = check_bat(bat)) < 0) return 0;
return 0;
if ((acpifd = open("/dev/acpi", O_RDONLY)) < 0) { if ((acpifd = open("/dev/acpi", O_RDONLY)) < 0) {
fprintf(stderr, "Can't open ACPI device\n"); fprintf(stderr, "Can't open ACPI device\n");
return 0; return 0;
@@ -483,26 +466,25 @@ int get_battery_perct(const char *bat)
close(acpifd); close(acpifd);
designcap = battio.bif.dcap; designcap = battio.bif.dcap;
lastfulcap = battio.bif.lfcap; lastfulcap = battio.bif.lfcap;
batperct = (designcap > 0 && lastfulcap > 0) ? batperct = (designcap > 0 && lastfulcap > 0)
(((float) lastfulcap / designcap) * 100) : 0; ? (((float)lastfulcap / designcap) * 100)
: 0;
return batperct > 100 ? 100 : batperct; return batperct > 100 ? 100 : batperct;
} }
double get_battery_perct_bar(struct text_object *obj) double get_battery_perct_bar(struct text_object *obj) {
{
int batperct = get_battery_perct(obj->data.s); int batperct = get_battery_perct(obj->data.s);
return batperct * 2.56 - 1; return batperct * 2.56 - 1;
} }
int open_acpi_temperature(const char *name) int open_acpi_temperature(const char *name) {
{
(void)name; (void)name;
/* Not applicable for FreeBSD. */ /* Not applicable for FreeBSD. */
return 0; return 0;
} }
void get_acpi_ac_adapter(char *p_client_buffer, size_t client_buffer_size, const char *adapter) void get_acpi_ac_adapter(char *p_client_buffer, size_t client_buffer_size,
{ const char *adapter) {
int state; int state;
(void)adapter; // only linux uses this (void)adapter; // only linux uses this
@@ -523,8 +505,7 @@ void get_acpi_ac_adapter(char *p_client_buffer, size_t client_buffer_size, const
} }
} }
void get_acpi_fan(char *p_client_buffer, size_t client_buffer_size) void get_acpi_fan(char *p_client_buffer, size_t client_buffer_size) {
{
/* not implemented */ /* not implemented */
if (p_client_buffer && client_buffer_size > 0) { if (p_client_buffer && client_buffer_size > 0) {
memset(p_client_buffer, 0, client_buffer_size); memset(p_client_buffer, 0, client_buffer_size);
@@ -532,9 +513,8 @@ void get_acpi_fan(char *p_client_buffer, size_t client_buffer_size)
} }
/* void */ /* void */
char get_freq(char *p_client_buffer, size_t client_buffer_size, const char *p_format, char get_freq(char *p_client_buffer, size_t client_buffer_size,
int divisor, unsigned int cpu) const char *p_format, int divisor, unsigned int cpu) {
{
int64_t freq; int64_t freq;
if (p_client_buffer && client_buffer_size > 0 && p_format && divisor > 0) { if (p_client_buffer && client_buffer_size > 0 && p_format && divisor > 0) {
@@ -604,8 +584,7 @@ cleanup:
} }
#endif #endif
int update_diskio(void) int update_diskio(void) {
{
int devs_count, num_selected, num_selections, dn; int devs_count, num_selected, num_selections, dn;
struct device_selection *dev_select = NULL; struct device_selection *dev_select = NULL;
long select_generation; long select_generation;
@@ -615,7 +594,6 @@ int update_diskio(void)
unsigned int reads, writes; unsigned int reads, writes;
unsigned int total_reads = 0, total_writes = 0; unsigned int total_reads = 0, total_writes = 0;
memset(&statinfo_cur, 0, sizeof(statinfo_cur)); memset(&statinfo_cur, 0, sizeof(statinfo_cur));
statinfo_cur.dinfo = (struct devinfo *)calloc(1, sizeof(struct devinfo)); statinfo_cur.dinfo = (struct devinfo *)calloc(1, sizeof(struct devinfo));
stats.current = stats.current_read = stats.current_write = 0; stats.current = stats.current_read = stats.current_write = 0;
@@ -657,18 +635,15 @@ int update_diskio(void)
return 0; return 0;
} }
static int proc_rusage(struct kinfo_proc *p) static int proc_rusage(struct kinfo_proc *p) {
{
struct kinfo_lwp *lwp = &p->kp_lwp; struct kinfo_lwp *lwp = &p->kp_lwp;
struct rusage *cru = &p->kp_cru; struct rusage *cru = &p->kp_cru;
return (lwp->kl_uticks + return (lwp->kl_uticks + lwp->kl_sticks + lwp->kl_iticks) +
lwp->kl_sticks + lwp->kl_iticks) +
(cru->ru_stime.tv_sec + cru->ru_utime.tv_sec) * 1000000; (cru->ru_stime.tv_sec + cru->ru_utime.tv_sec) * 1000000;
} }
static void proc_count(struct kinfo_proc *kp, size_t proc_n) static void proc_count(struct kinfo_proc *kp, size_t proc_n) {
{
size_t i, act = 0, run = 0; size_t i, act = 0, run = 0;
for (i = 0; i < proc_n; i++) { for (i = 0; i < proc_n; i++) {
@@ -686,8 +661,7 @@ static void proc_count(struct kinfo_proc *kp, size_t proc_n)
info.run_procs = run; info.run_procs = run;
} }
static void proc_fill(struct kinfo_proc *kp, size_t proc_n) static void proc_fill(struct kinfo_proc *kp, size_t proc_n) {
{
size_t i, f = getpagesize(); size_t i, f = getpagesize();
static long prev_ticks = 0; /* safe as long as in same thread */ static long prev_ticks = 0; /* safe as long as in same thread */
@@ -695,8 +669,8 @@ static void proc_fill(struct kinfo_proc *kp, size_t proc_n)
struct kinfo_proc *p = &kp[i]; struct kinfo_proc *p = &kp[i];
struct kinfo_lwp *lwp = &p->kp_lwp; struct kinfo_lwp *lwp = &p->kp_lwp;
if (!(p->kp_flags & P_SYSTEM) && if (!(p->kp_flags & P_SYSTEM) && p->kp_comm &&
p->kp_comm && *p->kp_comm && /* just to be sure */ *p->kp_comm && /* just to be sure */
!lwp->kl_tid) { /* 'main' lwp, the real process (observed) */ !lwp->kl_tid) { /* 'main' lwp, the real process (observed) */
struct process *my = get_process(p->kp_pid); struct process *my = get_process(p->kp_pid);
@@ -721,8 +695,7 @@ static void proc_fill(struct kinfo_proc *kp, size_t proc_n)
} }
} }
void get_top_info(void) void get_top_info(void) {
{
size_t proc_n = kern_proc_all_n(); size_t proc_n = kern_proc_all_n();
struct kinfo_proc *kp = kern_proc_all(proc_n); struct kinfo_proc *kp = kern_proc_all(proc_n);
@@ -737,8 +710,7 @@ void get_top_info(void)
#define APMDEV "/dev/apm" #define APMDEV "/dev/apm"
#define APM_UNKNOWN 255 #define APM_UNKNOWN 255
int apm_getinfo(int fd, apm_info_t aip) int apm_getinfo(int fd, apm_info_t aip) {
{
if (ioctl(fd, APMIO_GETINFO, aip) == -1) { if (ioctl(fd, APMIO_GETINFO, aip) == -1) {
return -1; return -1;
} }
@@ -746,8 +718,7 @@ int apm_getinfo(int fd, apm_info_t aip)
return 0; return 0;
} }
char *get_apm_adapter(void) char *get_apm_adapter(void) {
{
int fd; int fd;
struct apm_info a_info; struct apm_info a_info;
char *out; char *out;
@@ -788,8 +759,7 @@ char *get_apm_adapter(void)
} }
} }
char *get_apm_battery_life(void) char *get_apm_battery_life(void) {
{
int fd; int fd;
u_int batt_life; u_int batt_life;
struct apm_info a_info; struct apm_info a_info;
@@ -823,8 +793,7 @@ char *get_apm_battery_life(void)
return out; return out;
} }
char *get_apm_battery_time(void) char *get_apm_battery_time(void) {
{
int fd; int fd;
int batt_time; int batt_time;
int h, m, s; int h, m, s;
@@ -864,8 +833,7 @@ char *get_apm_battery_time(void)
#endif #endif
void get_battery_short_status(char *buffer, unsigned int n, const char *bat) void get_battery_short_status(char *buffer, unsigned int n, const char *bat) {
{
get_battery_stuff(buffer, n, bat, BATTERY_STATUS); get_battery_stuff(buffer, n, bat, BATTERY_STATUS);
if (0 == strncmp("charging", buffer, 8)) { if (0 == strncmp("charging", buffer, 8)) {
buffer[0] = 'C'; buffer[0] = 'C';
@@ -879,15 +847,13 @@ void get_battery_short_status(char *buffer, unsigned int n, const char *bat)
} }
} }
int get_entropy_avail(unsigned int *val) int get_entropy_avail(unsigned int *val) {
{
/* Not applicable for FreeBSD as it uses the yarrow prng. */ /* Not applicable for FreeBSD as it uses the yarrow prng. */
(void)val; (void)val;
return 1; return 1;
} }
int get_entropy_poolsize(unsigned int *val) int get_entropy_poolsize(unsigned int *val) {
{
/* Not applicable for FreeBSD as it uses the yarrow prng. */ /* Not applicable for FreeBSD as it uses the yarrow prng. */
(void)val; (void)val;
return 1; return 1;

View File

@@ -1,14 +1,14 @@
/* -*- mode: c; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*- */ /* */
#ifndef DRAGONFLY_H_ #ifndef DRAGONFLY_H_
#define DRAGONFLY_H_ #define DRAGONFLY_H_
#include "common.h"
#include <sys/param.h>
#include <sys/mount.h>
#include <sys/ucred.h>
#include <fcntl.h> #include <fcntl.h>
#include <kvm.h> #include <kvm.h>
#include <sys/mount.h>
#include <sys/param.h>
#include <sys/ucred.h>
#include "common.h"
#if (defined(i386) || defined(__i386__)) #if (defined(i386) || defined(__i386__))
#include <machine/apm_bios.h> #include <machine/apm_bios.h>
#endif /* i386 || __i386__ */ #endif /* i386 || __i386__ */

View File

@@ -1,5 +1,4 @@
/* -*- mode: c++; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*- /*
* vim: ts=4 sw=4 noet ai cindent syntax=cpp
* *
* Conky, a system monitor, based on torsmo * Conky, a system monitor, based on torsmo
* *
@@ -10,7 +9,7 @@
* Please see COPYING for details * Please see COPYING for details
* *
* Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen * Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
* Copyright (c) 2005-2012 Brenden Matthews, Philip Kovacs, et. al. * Copyright (c) 2005-2018 Brenden Matthews, Philip Kovacs, et. al.
* (see AUTHORS) * (see AUTHORS)
* All rights reserved. * All rights reserved.
* *
@@ -57,33 +56,28 @@ struct _entropy {
static _entropy entropy; static _entropy entropy;
int update_entropy(void) int update_entropy(void) {
{
get_entropy_avail(&entropy.avail); get_entropy_avail(&entropy.avail);
get_entropy_poolsize(&entropy.poolsize); get_entropy_poolsize(&entropy.poolsize);
return 0; return 0;
} }
void print_entropy_avail(struct text_object *obj, char *p, int p_max_size) void print_entropy_avail(struct text_object *obj, char *p, int p_max_size) {
{
(void)obj; (void)obj;
snprintf(p, p_max_size, "%u", entropy.avail); snprintf(p, p_max_size, "%u", entropy.avail);
} }
uint8_t entropy_percentage(struct text_object *obj) uint8_t entropy_percentage(struct text_object *obj) {
{
(void)obj; (void)obj;
return round_to_int((double)entropy.avail * 100.0 / (double)entropy.poolsize); return round_to_int((double)entropy.avail * 100.0 / (double)entropy.poolsize);
} }
void print_entropy_poolsize(struct text_object *obj, char *p, int p_max_size) void print_entropy_poolsize(struct text_object *obj, char *p, int p_max_size) {
{
(void)obj; (void)obj;
snprintf(p, p_max_size, "%u", entropy.poolsize); snprintf(p, p_max_size, "%u", entropy.poolsize);
} }
double entropy_barval(struct text_object *obj) double entropy_barval(struct text_object *obj) {
{
(void)obj; (void)obj;
return (double)entropy.avail / entropy.poolsize; return (double)entropy.avail / entropy.poolsize;

View File

@@ -1,5 +1,4 @@
/* -*- mode: c++; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*- /*
* vim: ts=4 sw=4 noet ai cindent syntax=cpp
* *
* Conky, a system monitor, based on torsmo * Conky, a system monitor, based on torsmo
* *
@@ -10,7 +9,7 @@
* Please see COPYING for details * Please see COPYING for details
* *
* Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen * Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
* Copyright (c) 2005-2012 Brenden Matthews, Philip Kovacs, et. al. * Copyright (c) 2005-2018 Brenden Matthews, Philip Kovacs, et. al.
* (see AUTHORS) * (see AUTHORS)
* All rights reserved. * All rights reserved.
* *

View File

@@ -1,10 +1,9 @@
/* -*- mode: c++; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*- /*
* vim: ts=4 sw=4 noet ai cindent syntax=cpp
* *
* Conky, a system monitor, based on torsmo * Conky, a system monitor, based on torsmo
* *
* Copyright (c) 2008 Asbjørn Zweidorff Kjær * Copyright (c) 2008 Asbjørn Zweidorff Kjær
* Copyright (c) 2005-2012 Brenden Matthews, Philip Kovacs, et. al. * Copyright (c) 2005-2018 Brenden Matthews, Philip Kovacs, et. al.
* (see AUTHORS) * (see AUTHORS)
* All rights reserved. * All rights reserved.
* *
@@ -23,17 +22,17 @@
*/ */
#include "eve.h" #include "eve.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <utime.h>
#include <string>
#include "config.h" #include "config.h"
#include "logging.h" #include "logging.h"
#include "text_object.h" #include "text_object.h"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <string>
#include <sys/stat.h>
#include <sys/types.h>
#include <utime.h>
#include <libxml/parser.h> #include <libxml/parser.h>
#include <libxml/tree.h> #include <libxml/tree.h>
@@ -80,8 +79,7 @@ struct eve_data {
int num_chars = 0; int num_chars = 0;
Character eveCharacters[MAXCHARS]; Character eveCharacters[MAXCHARS];
static size_t write_data(void *ptr, size_t size, size_t nmemb, void *stream) static size_t write_data(void *ptr, size_t size, size_t nmemb, void *stream) {
{
size_t realsize = 0; size_t realsize = 0;
struct xmlData *data = 0; struct xmlData *data = 0;
data = (struct xmlData *)stream; data = (struct xmlData *)stream;
@@ -97,8 +95,7 @@ static size_t write_data(void *ptr, size_t size, size_t nmemb, void *stream)
return realsize; return realsize;
} }
int parseTrainingXml(char *data, Character * s) int parseTrainingXml(char *data, Character *s) {
{
char *skill, *level, *ends, *cache, *isTraining; char *skill, *level, *ends, *cache, *isTraining;
xmlNodePtr n; xmlNodePtr n;
xmlDocPtr doc = 0; xmlDocPtr doc = 0;
@@ -110,8 +107,7 @@ int parseTrainingXml(char *data, Character * s)
localtime_r(&now, &end_tm); localtime_r(&now, &end_tm);
localtime_r(&now, &cache_tm); localtime_r(&now, &cache_tm);
if (!data) if (!data) return 1;
return 1;
doc = xmlReadMemory(data, strlen(data), "", NULL, XML_PARSE_RECOVER); doc = xmlReadMemory(data, strlen(data), "", NULL, XML_PARSE_RECOVER);
root = xmlDocGetRootElement(doc); root = xmlDocGetRootElement(doc);
@@ -128,8 +124,7 @@ int parseTrainingXml(char *data, Character * s)
} else if (!strcasecmp((const char *)c->name, "trainingEndTime")) { } else if (!strcasecmp((const char *)c->name, "trainingEndTime")) {
ends = (char *)c->children->content; ends = (char *)c->children->content;
} else if (!strcasecmp((const char *)c->name, "trainingTypeID")) { } else if (!strcasecmp((const char *)c->name, "trainingTypeID")) {
if (c->children->content) if (c->children->content) skill = (char *)c->children->content;
skill = (char *)c->children->content;
} else if (!strcasecmp((const char *)c->name, "trainingToLevel")) { } else if (!strcasecmp((const char *)c->name, "trainingToLevel")) {
level = (char *)c->children->content; level = (char *)c->children->content;
} }
@@ -156,8 +151,8 @@ int parseTrainingXml(char *data, Character * s)
return 0; return 0;
} }
static char *getXmlFromAPI(const char *apiKeyID, const char *apiVCode, const char *charid, const char *url) static char *getXmlFromAPI(const char *apiKeyID, const char *apiVCode,
{ const char *charid, const char *url) {
struct curl_httppost *post = NULL; struct curl_httppost *post = NULL;
struct curl_httppost *last = NULL; struct curl_httppost *last = NULL;
struct xmlData chr; struct xmlData chr;
@@ -198,8 +193,7 @@ static char *getXmlFromAPI(const char *apiKeyID, const char *apiVCode, const cha
return content; return content;
} }
static void init_eve(void) static void init_eve(void) {
{
int i; int i;
for (i = 0; i < MAXCHARS; i++) { for (i = 0; i < MAXCHARS; i++) {
@@ -212,8 +206,7 @@ static void init_eve(void)
} }
} }
static int isCacheValid(struct tm cached) static int isCacheValid(struct tm cached) {
{
// struct timeval tv; // struct timeval tv;
// struct timezone tz; // struct timezone tz;
double offset = 0; double offset = 0;
@@ -235,8 +228,7 @@ static int isCacheValid(struct tm cached)
return 1; return 1;
} }
static char *formatTime(struct tm *ends) static char *formatTime(struct tm *ends) {
{
// struct timeval tv; // struct timeval tv;
// struct timezone tz; // struct timezone tz;
double offset = 0; double offset = 0;
@@ -260,7 +252,8 @@ static char *formatTime(struct tm *ends)
int days = (int)(diff / 60 / 60 / 24); int days = (int)(diff / 60 / 60 / 24);
int hours = (int)((diff / 60 / 60) - (days * 24)); int hours = (int)((diff / 60 / 60) - (days * 24));
int minutes = (int)((diff / 60) - ((hours * 60) + (days * 60 * 24))); int minutes = (int)((diff / 60) - ((hours * 60) + (days * 60 * 24)));
int seconds = (int)(diff - ((minutes * 60) + (hours * 60 * 60) + (days * 60 * 60 * 24))); int seconds = (int)(diff - ((minutes * 60) + (hours * 60 * 60) +
(days * 60 * 60 * 24)));
char *output = (char *)malloc(100 * sizeof(char)); char *output = (char *)malloc(100 * sizeof(char));
if (days > 0) if (days > 0)
@@ -277,16 +270,14 @@ static char *formatTime(struct tm *ends)
} }
} }
static void writeSkilltree(char *content, const char *filename) static void writeSkilltree(char *content, const char *filename) {
{
FILE *fp = fopen(filename, "w"); FILE *fp = fopen(filename, "w");
if (fwrite(content, sizeof(char), strlen(content), fp) < strlen(content)) if (fwrite(content, sizeof(char), strlen(content), fp) < strlen(content))
NORM_ERR("skill tree write failed"); NORM_ERR("skill tree write failed");
fclose(fp); fclose(fp);
} }
static char *getSkillname(const char *file, int skillid) static char *getSkillname(const char *file, int skillid) {
{
char *skilltree; char *skilltree;
char *skill = NULL; char *skill = NULL;
xmlNodePtr n; xmlNodePtr n;
@@ -294,16 +285,14 @@ static char *getSkillname(const char *file, int skillid)
xmlNodePtr root = 0; xmlNodePtr root = 0;
skilltree = getXmlFromAPI(NULL, NULL, NULL, EVEURL_SKILLTREE); skilltree = getXmlFromAPI(NULL, NULL, NULL, EVEURL_SKILLTREE);
if(skilltree) if (skilltree) {
{
writeSkilltree(skilltree, file); writeSkilltree(skilltree, file);
free(skilltree); free(skilltree);
} }
doc = xmlReadFile(file, NULL, XML_PARSE_RECOVER); doc = xmlReadFile(file, NULL, XML_PARSE_RECOVER);
unlink(file); unlink(file);
if (!doc) if (!doc) return NULL;
return NULL;
root = xmlDocGetRootElement(doc); root = xmlDocGetRootElement(doc);
@@ -347,8 +336,7 @@ static char *getSkillname(const char *file, int skillid)
return skill; return skill;
} }
static char *eve(char *apiKeyID, char *apiVCode, char *charid) static char *eve(char *apiKeyID, char *apiVCode, char *charid) {
{
Character *chr = NULL; Character *chr = NULL;
char skillfile[] = "/tmp/.cesfXXXXXX"; char skillfile[] = "/tmp/.cesfXXXXXX";
int i = 0; int i = 0;
@@ -360,7 +348,6 @@ static char *eve(char *apiKeyID, char *apiVCode, char *charid)
char *error = 0; char *error = 0;
int tmp_fd, old_umask; int tmp_fd, old_umask;
for (i = 0; i < num_chars; i++) { for (i = 0; i < num_chars; i++) {
if (eveCharacters[i].charid != NULL) { if (eveCharacters[i].charid != NULL) {
if (strcasecmp(eveCharacters[i].charid, charid) == 0) { if (strcasecmp(eveCharacters[i].charid, charid) == 0) {
@@ -371,8 +358,7 @@ static char *eve(char *apiKeyID, char *apiVCode, char *charid)
} }
if (!chr) { if (!chr) {
if (num_chars == MAXCHARS - 1) if (num_chars == MAXCHARS - 1) return NULL;
return NULL;
chr = &eveCharacters[num_chars]; chr = &eveCharacters[num_chars];
memset(chr, 0, sizeof(Character)); memset(chr, 0, sizeof(Character));
chr->charid = strdup(charid); chr->charid = strdup(charid);
@@ -435,11 +421,9 @@ static char *eve(char *apiKeyID, char *apiVCode, char *charid)
return strdup(TRAINING_INACTIVE); return strdup(TRAINING_INACTIVE);
} }
} }
} }
void scan_eve(struct text_object *obj, const char *arg) void scan_eve(struct text_object *obj, const char *arg) {
{
int argc; int argc;
struct eve_data *ed; struct eve_data *ed;
@@ -452,18 +436,15 @@ void scan_eve(struct text_object *obj, const char *arg)
obj->data.opaque = ed; obj->data.opaque = ed;
} }
void print_eve(struct text_object *obj, char *p, int p_max_size) void print_eve(struct text_object *obj, char *p, int p_max_size) {
{
struct eve_data *ed = (struct eve_data *)obj->data.opaque; struct eve_data *ed = (struct eve_data *)obj->data.opaque;
if (!ed) if (!ed) return;
return;
snprintf(p, p_max_size, "%s", eve(ed->apiKeyID, ed->apiVCode, ed->charid)); snprintf(p, p_max_size, "%s", eve(ed->apiKeyID, ed->apiVCode, ed->charid));
} }
void free_eve(struct text_object *obj) void free_eve(struct text_object *obj) {
{
free_and_zero(obj->data.opaque); free_and_zero(obj->data.opaque);
num_chars = 0; num_chars = 0;
} }

View File

@@ -1,10 +1,9 @@
/* -*- mode: c; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*- /*
* vim: ts=4 sw=4 noet ai cindent syntax=cpp
* *
* Conky, a system monitor, based on torsmo * Conky, a system monitor, based on torsmo
* *
* Copyright (c) 2008 Asbjørn Zweidorff Kjær * Copyright (c) 2008 Asbjørn Zweidorff Kjær
* Copyright (c) 2005-2012 Brenden Matthews, Philip Kovacs, et. al. * Copyright (c) 2005-2018 Brenden Matthews, Philip Kovacs, et. al.
* (see AUTHORS) * (see AUTHORS)
* All rights reserved. * All rights reserved.
* *
@@ -25,7 +24,8 @@
#ifndef _EVE_H #ifndef _EVE_H
#define _EVE_H #define _EVE_H
#define EVEURL_TRAINING "https://api.eveonline.com/char/SkillInTraining.xml.aspx" #define EVEURL_TRAINING \
"https://api.eveonline.com/char/SkillInTraining.xml.aspx"
#define EVEURL_SKILLTREE "https://api.eveonline.com/eve/Skilltree.xml.aspx" #define EVEURL_SKILLTREE "https://api.eveonline.com/eve/Skilltree.xml.aspx"
#define EVE_OUTPUT_FORMAT "%s %d in %s" #define EVE_OUTPUT_FORMAT "%s %d in %s"

View File

@@ -1,5 +1,4 @@
/* -*- mode: c++; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*- /*
* vim: ts=4 sw=4 noet ai cindent syntax=cpp
* *
* Conky, a system monitor, based on torsmo * Conky, a system monitor, based on torsmo
* *
@@ -10,7 +9,7 @@
* Please see COPYING for details * Please see COPYING for details
* *
* Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen * Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
* Copyright (c) 2005-2012 Brenden Matthews, Philip Kovacs, et. al. * Copyright (c) 2005-2018 Brenden Matthews, Philip Kovacs, et. al.
* (see AUTHORS) * (see AUTHORS)
* All rights reserved. * All rights reserved.
* *
@@ -28,19 +27,19 @@
* *
*/ */
#include "conky.h"
#include "core.h"
#include "exec.h" #include "exec.h"
#include "logging.h"
#include "specials.h"
#include "text_object.h"
#include "update-cb.hh"
#include <cmath>
#include <mutex>
#include <stdio.h> #include <stdio.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/wait.h> #include <sys/wait.h>
#include <unistd.h> #include <unistd.h>
#include <cmath>
#include <mutex>
#include "conky.h"
#include "core.h"
#include "logging.h"
#include "specials.h"
#include "text_object.h"
#include "update-cb.hh"
struct execi_data { struct execi_data {
float interval; float interval;
@@ -48,15 +47,16 @@ struct execi_data {
execi_data() : interval(0), cmd(0) {} execi_data() : interval(0), cmd(0) {}
}; };
//our own implementation of popen, the difference : the value of 'childpid' will be filled with // our own implementation of popen, the difference : the value of 'childpid'
//the pid of the running 'command'. This is useful if want to kill it when it hangs while reading // will be filled with the pid of the running 'command'. This is useful if want
//or writing to it. We have to kill it because pclose will wait until the process dies by itself // to kill it when it hangs while reading or writing to it. We have to kill it
// because pclose will wait until the process dies by itself
static FILE *pid_popen(const char *command, const char *mode, pid_t *child) { static FILE *pid_popen(const char *command, const char *mode, pid_t *child) {
int ends[2]; int ends[2];
int parentend, childend; int parentend, childend;
//by running pipe after the strcmp's we make sure that we don't have to create a pipe // by running pipe after the strcmp's we make sure that we don't have to
//and close the ends if mode is something illegal // create a pipe and close the ends if mode is something illegal
if (strcmp(mode, "r") == 0) { if (strcmp(mode, "r") == 0) {
if (pipe(ends) != 0) { if (pipe(ends) != 0) {
return NULL; return NULL;
@@ -91,12 +91,12 @@ static FILE* pid_popen(const char *command, const char *mode, pid_t *child) {
close(parentend); close(parentend);
// by dupping childend, the returned fd will have close-on-exec turned off // by dupping childend, the returned fd will have close-on-exec turned off
if (dup(childend) == -1) if (dup(childend) == -1) perror("dup()");
perror("dup()");
close(childend); close(childend);
execl("/bin/sh", "sh", "-c", command, (char *)NULL); execl("/bin/sh", "sh", "-c", command, (char *)NULL);
_exit(EXIT_FAILURE); //child should die here, (normally execl will take care of this but it can fail) _exit(EXIT_FAILURE); // child should die here, (normally execl will take
// care of this but it can fail)
} }
return fdopen(parentend, mode); return fdopen(parentend, mode);
@@ -113,8 +113,7 @@ static FILE* pid_popen(const char *command, const char *mode, pid_t *child) {
* results, use the stored callback to call get_result_copy(), which * results, use the stored callback to call get_result_copy(), which
* returns a std::string. * returns a std::string.
*/ */
void exec_cb::work() void exec_cb::work() {
{
pid_t childpid; pid_t childpid;
std::string buf; std::string buf;
std::shared_ptr<FILE> fp; std::shared_ptr<FILE> fp;
@@ -130,8 +129,7 @@ void exec_cb::work()
buf.append(b, length); buf.append(b, length);
} }
if (*buf.rbegin() == '\n') if (*buf.rbegin() == '\n') buf.resize(buf.size() - 1);
buf.resize(buf.size()-1);
std::lock_guard<std::mutex> l(result_mutex); std::lock_guard<std::mutex> l(result_mutex);
result = buf; result = buf;
@@ -147,8 +145,12 @@ static void remove_deleted_chars(char *string){
if (i != 0) { if (i != 0) {
strcpy(&(string[i - 1]), &(string[i + 1])); strcpy(&(string[i - 1]), &(string[i + 1]));
i--; i--;
} else strcpy( &(string[i]), &(string[i+1]) ); //necessary for ^H's at the start of a string } else
} else i++; strcpy(
&(string[i]),
&(string[i + 1])); // necessary for ^H's at the start of a string
} else
i++;
} }
} }
@@ -159,17 +161,18 @@ static void remove_deleted_chars(char *string){
* @param[in] buf output of a command executed by an exec_cb object * @param[in] buf output of a command executed by an exec_cb object
* @return number between 0.0 and 100.0 * @return number between 0.0 and 100.0
*/ */
static inline double get_barnum(const char *buf) static inline double get_barnum(const char *buf) {
{
double barnum; double barnum;
if (sscanf(buf, "%lf", &barnum) != 1) { if (sscanf(buf, "%lf", &barnum) != 1) {
NORM_ERR("reading exec value failed (perhaps it's not the " NORM_ERR(
"reading exec value failed (perhaps it's not the "
"correct format?)"); "correct format?)");
return 0.0; return 0.0;
} }
if (barnum > 100.0 || barnum < 0.0) { if (barnum > 100.0 || barnum < 0.0) {
NORM_ERR("your exec value is not between 0 and 100, " NORM_ERR(
"your exec value is not between 0 and 100, "
"therefore it will be ignored"); "therefore it will be ignored");
return 0.0; return 0.0;
} }
@@ -186,7 +189,8 @@ static inline double get_barnum(const char *buf)
* @param[out] p the string in which we store command output * @param[out] p the string in which we store command output
* @param[in] p_max_size the maximum size of p... * @param[in] p_max_size the maximum size of p...
*/ */
void fill_p(const char *buffer, struct text_object *obj, char *p, int p_max_size) { void fill_p(const char *buffer, struct text_object *obj, char *p,
int p_max_size) {
if (obj->parse == true) { if (obj->parse == true) {
evaluate(buffer, p, p_max_size); evaluate(buffer, p, p_max_size);
} else { } else {
@@ -200,12 +204,14 @@ void fill_p(const char *buffer, struct text_object *obj, char *p, int p_max_size
* Parses arg to find the command to be run, as well as special options * Parses arg to find the command to be run, as well as special options
* like height, width, color, and update interval * like height, width, color, and update interval
* *
* @param[out] obj stores the command and an execi_data structure (if applicable) * @param[out] obj stores the command and an execi_data structure (if
* applicable)
* @param[in] arg the argument to an ${exec*} object * @param[in] arg the argument to an ${exec*} object
* @param[in] execflag bitwise flag used to specify the exec variant we need to process * @param[in] execflag bitwise flag used to specify the exec variant we need to
* process
*/ */
void scan_exec_arg(struct text_object *obj, const char *arg, unsigned int execflag) void scan_exec_arg(struct text_object *obj, const char *arg,
{ unsigned int execflag) {
const char *cmd = arg; const char *cmd = arg;
struct execi_data *ed; struct execi_data *ed;
@@ -240,7 +246,8 @@ void scan_exec_arg(struct text_object *obj, const char *arg, unsigned int execfl
#endif /* BUILD_X11 */ #endif /* BUILD_X11 */
} }
/* finally, store the resulting command, or an empty string if something went wrong */ /* finally, store the resulting command, or an empty string if something went
* wrong */
if (execflag & EF_EXEC) { if (execflag & EF_EXEC) {
obj->data.s = strndup(cmd ? cmd : "", text_buffer_size.get(*state)); obj->data.s = strndup(cmd ? cmd : "", text_buffer_size.get(*state));
} else if (execflag & EF_EXECI) { } else if (execflag & EF_EXECI) {
@@ -254,8 +261,7 @@ void scan_exec_arg(struct text_object *obj, const char *arg, unsigned int execfl
* *
* @param[out] obj stores the callback handle * @param[out] obj stores the callback handle
*/ */
void register_exec(struct text_object *obj) void register_exec(struct text_object *obj) {
{
if (obj->data.s && obj->data.s[0]) { if (obj->data.s && obj->data.s[0]) {
obj->exec_handle = new conky::callback_handle<exec_cb>( obj->exec_handle = new conky::callback_handle<exec_cb>(
conky::register_cb<exec_cb>(1, true, obj->data.s)); conky::register_cb<exec_cb>(1, true, obj->data.s));
@@ -272,12 +278,12 @@ void register_exec(struct text_object *obj)
* *
* @param[out] obj stores the callback handle * @param[out] obj stores the callback handle
*/ */
void register_execi(struct text_object *obj) void register_execi(struct text_object *obj) {
{
struct execi_data *ed = (struct execi_data *)obj->data.opaque; struct execi_data *ed = (struct execi_data *)obj->data.opaque;
if (ed && ed->cmd && ed->cmd[0]) { if (ed && ed->cmd && ed->cmd[0]) {
uint32_t period = std::max(lround(ed->interval/active_update_interval()), 1l); uint32_t period =
std::max(lround(ed->interval / active_update_interval()), 1l);
obj->exec_handle = new conky::callback_handle<exec_cb>( obj->exec_handle = new conky::callback_handle<exec_cb>(
conky::register_cb<exec_cb>(period, !obj->thread, ed->cmd)); conky::register_cb<exec_cb>(period, !obj->thread, ed->cmd));
} else { } else {
@@ -292,8 +298,7 @@ void register_execi(struct text_object *obj)
* @param[out] p the string in which we store command output * @param[out] p the string in which we store command output
* @param[in] p_max_size the maximum size of p... * @param[in] p_max_size the maximum size of p...
*/ */
void print_exec(struct text_object *obj, char *p, int p_max_size) void print_exec(struct text_object *obj, char *p, int p_max_size) {
{
if (obj->exec_handle) { if (obj->exec_handle) {
fill_p((*obj->exec_handle)->get_result_copy().c_str(), obj, p, p_max_size); fill_p((*obj->exec_handle)->get_result_copy().c_str(), obj, p, p_max_size);
} }
@@ -305,8 +310,7 @@ void print_exec(struct text_object *obj, char *p, int p_max_size)
* @param[in] obj hold an exec_handle, assuming one was registered * @param[in] obj hold an exec_handle, assuming one was registered
* @return a value between 0.0 and 100.0 * @return a value between 0.0 and 100.0
*/ */
double execbarval(struct text_object *obj) double execbarval(struct text_object *obj) {
{
if (obj->exec_handle) { if (obj->exec_handle) {
return get_barnum((*obj->exec_handle)->get_result_copy().c_str()); return get_barnum((*obj->exec_handle)->get_result_copy().c_str());
} else { } else {
@@ -319,8 +323,7 @@ double execbarval(struct text_object *obj)
* *
* @param[in] obj holds the data that we need to free up * @param[in] obj holds the data that we need to free up
*/ */
void free_exec(struct text_object *obj) void free_exec(struct text_object *obj) {
{
free_and_zero(obj->data.s); free_and_zero(obj->data.s);
delete obj->exec_handle; delete obj->exec_handle;
obj->exec_handle = NULL; obj->exec_handle = NULL;
@@ -331,13 +334,11 @@ void free_exec(struct text_object *obj)
* *
* @param[in] obj holds the data that we need to free up * @param[in] obj holds the data that we need to free up
*/ */
void free_execi(struct text_object *obj) void free_execi(struct text_object *obj) {
{
struct execi_data *ed = (struct execi_data *)obj->data.opaque; struct execi_data *ed = (struct execi_data *)obj->data.opaque;
/* if ed is NULL, there is nothing to do */ /* if ed is NULL, there is nothing to do */
if (!ed) if (!ed) return;
return;
delete obj->exec_handle; delete obj->exec_handle;
obj->exec_handle = NULL; obj->exec_handle = NULL;

View File

@@ -1,5 +1,4 @@
/* -*- mode: c++; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*- /*
* vim: ts=4 sw=4 noet ai cindent syntax=cpp
* *
* Conky, a system monitor, based on torsmo * Conky, a system monitor, based on torsmo
* *
@@ -10,7 +9,7 @@
* Please see COPYING for details * Please see COPYING for details
* *
* Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen * Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
* Copyright (c) 2005-2012 Brenden Matthews, Philip Kovacs, et. al. * Copyright (c) 2005-2018 Brenden Matthews, Philip Kovacs, et. al.
* (see AUTHORS) * (see AUTHORS)
* All rights reserved. * All rights reserved.
* *
@@ -31,7 +30,7 @@
#ifndef _EXEC_H #ifndef _EXEC_H
#define _EXEC_H #define _EXEC_H
#include "text_object.h" #include "update-cb.hh"
/** /**
* A callback that executes a command and stores the output as a std::string. * A callback that executes a command and stores the output as a std::string.
@@ -56,8 +55,7 @@ class exec_cb: public conky::callback<std::string, std::string> {
public: public:
exec_cb(uint32_t period, bool wait, const std::string &cmd) exec_cb(uint32_t period, bool wait, const std::string &cmd)
: Base(period, wait, Base::Tuple(cmd)) : Base(period, wait, Base::Tuple(cmd)) {}
{}
}; };
/** /**

View File

@@ -1,5 +1,4 @@
/* -*- mode: c++; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*- /*
* vim: ts=4 sw=4 noet ai cindent syntax=cpp
* *
* Conky, a system monitor, based on torsmo * Conky, a system monitor, based on torsmo
* *
@@ -10,7 +9,7 @@
* Please see COPYING for details * Please see COPYING for details
* *
* Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen * Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
* Copyright (c) 2005-2012 Brenden Matthews, Philip Kovacs, et. al. * Copyright (c) 2005-2018 Brenden Matthews, Philip Kovacs, et. al.
* (see AUTHORS) * (see AUTHORS)
* All rights reserved. * All rights reserved.
* *
@@ -27,7 +26,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
* *
*/ */
#include "conky.h"
#include "fonts.h" #include "fonts.h"
#include "logging.h" #include "logging.h"
@@ -35,15 +34,13 @@ int selected_font = 0;
std::vector<font_list> fonts; std::vector<font_list> fonts;
char fontloaded = 0; char fontloaded = 0;
void font_setting::lua_setter(lua::state &l, bool init) void font_setting::lua_setter(lua::state &l, bool init) {
{
lua::stack_sentry s(l, -2); lua::stack_sentry s(l, -2);
Base::lua_setter(l, init); Base::lua_setter(l, init);
if (init && out_to_x.get(*state)) { if (init && out_to_x.get(*state)) {
if(fonts.size() == 0) if (fonts.size() == 0) fonts.resize(1);
fonts.resize(1);
fonts[0].name = do_convert(l, -1).first; fonts[0].name = do_convert(l, -1).first;
} }
@@ -58,8 +55,7 @@ namespace {
typedef conky::simple_config_setting<float> Base; typedef conky::simple_config_setting<float> Base;
protected: protected:
virtual void lua_setter(lua::state &l, bool init) virtual void lua_setter(lua::state &l, bool init) {
{
lua::stack_sentry s(l, -2); lua::stack_sentry s(l, -2);
Base::lua_setter(l, init); Base::lua_setter(l, init);
@@ -72,17 +68,14 @@ namespace {
} }
public: public:
xftalpha_setting() xftalpha_setting() : Base("xftalpha", 1.0, false) {}
: Base("xftalpha", 1.0, false)
{}
}; };
xftalpha_setting xftalpha; xftalpha_setting xftalpha;
} } // namespace
#endif /* BUILD_XFT */ #endif /* BUILD_XFT */
void set_font(void) void set_font(void) {
{
#ifdef BUILD_XFT #ifdef BUILD_XFT
if (use_xft.get(*state)) return; if (use_xft.get(*state)) return;
#endif /* BUILD_XFT */ #endif /* BUILD_XFT */
@@ -91,8 +84,7 @@ void set_font(void)
} }
} }
void setup_fonts(void) void setup_fonts(void) {
{
if (not out_to_x.get(*state)) { if (not out_to_x.get(*state)) {
return; return;
} }
@@ -102,15 +94,14 @@ void setup_fonts(void)
XftDrawDestroy(window.xftdraw); XftDrawDestroy(window.xftdraw);
window.xftdraw = 0; window.xftdraw = 0;
} }
window.xftdraw = XftDrawCreate(display, window.drawable, window.xftdraw = XftDrawCreate(display, window.drawable, window.visual,
window.visual, window.colourmap); window.colourmap);
} }
#endif /* BUILD_XFT */ #endif /* BUILD_XFT */
set_font(); set_font();
} }
int add_font(const char *data_in) int add_font(const char *data_in) {
{
if (not out_to_x.get(*state)) { if (not out_to_x.get(*state)) {
return 0; return 0;
} }
@@ -156,22 +147,22 @@ void free_fonts(bool utf8) {
} }
void load_fonts(bool utf8) { void load_fonts(bool utf8) {
if (not out_to_x.get(*state)) if (not out_to_x.get(*state)) return;
return;
for (size_t i = 0; i < fonts.size(); i++) { for (size_t i = 0; i < fonts.size(); i++) {
#ifdef BUILD_XFT #ifdef BUILD_XFT
/* load Xft font */ /* load Xft font */
if (use_xft.get(*state)) { if (use_xft.get(*state)) {
if (not fonts[i].xftfont) if (not fonts[i].xftfont)
fonts[i].xftfont = XftFontOpenName(display, screen, fonts[i].name.c_str()); fonts[i].xftfont =
XftFontOpenName(display, screen, fonts[i].name.c_str());
if (fonts[i].xftfont) { if (fonts[i].xftfont) {
continue; continue;
} }
NORM_ERR("can't load Xft font '%s'", fonts[i].name.c_str()); NORM_ERR("can't load Xft font '%s'", fonts[i].name.c_str());
if ((fonts[i].xftfont = XftFontOpenName(display, screen, if ((fonts[i].xftfont = XftFontOpenName(display, screen, "courier-12")) !=
"courier-12")) != NULL) { NULL) {
continue; continue;
} }
@@ -184,18 +175,21 @@ void load_fonts(bool utf8) {
char **missing; char **missing;
int missingnum; int missingnum;
char *missingdrawn; char *missingdrawn;
fonts[i].fontset = XCreateFontSet(display, fonts[i].name.c_str(), &missing, &missingnum, &missingdrawn); fonts[i].fontset = XCreateFontSet(display, fonts[i].name.c_str(),
&missing, &missingnum, &missingdrawn);
XFreeStringList(missing); XFreeStringList(missing);
if (fonts[i].fontset == NULL) { if (fonts[i].fontset == NULL) {
NORM_ERR("can't load font '%s'", fonts[i].name.c_str()); NORM_ERR("can't load font '%s'", fonts[i].name.c_str());
fonts[i].fontset = XCreateFontSet(display, "fixed", &missing, &missingnum, &missingdrawn); fonts[i].fontset = XCreateFontSet(display, "fixed", &missing,
&missingnum, &missingdrawn);
if (fonts[i].fontset == NULL) { if (fonts[i].fontset == NULL) {
CRIT_ERR(NULL, NULL, "can't load font '%s'", "fixed"); CRIT_ERR(NULL, NULL, "can't load font '%s'", "fixed");
} }
} }
} }
/* load normal font */ /* load normal font */
if (!fonts[i].font && (fonts[i].font = XLoadQueryFont(display, fonts[i].name.c_str())) == NULL) { if (!fonts[i].font && (fonts[i].font = XLoadQueryFont(
display, fonts[i].name.c_str())) == NULL) {
NORM_ERR("can't load font '%s'", fonts[i].name.c_str()); NORM_ERR("can't load font '%s'", fonts[i].name.c_str());
if ((fonts[i].font = XLoadQueryFont(display, "fixed")) == NULL) { if ((fonts[i].font = XLoadQueryFont(display, "fixed")) == NULL) {
CRIT_ERR(NULL, NULL, "can't load font '%s'", "fixed"); CRIT_ERR(NULL, NULL, "can't load font '%s'", "fixed");

View File

@@ -1,5 +1,4 @@
/* -*- mode: c; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*- /*
* vim: ts=4 sw=4 noet ai cindent syntax=cpp
* *
* Conky, a system monitor, based on torsmo * Conky, a system monitor, based on torsmo
* *
@@ -10,7 +9,7 @@
* Please see COPYING for details * Please see COPYING for details
* *
* Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen * Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
* Copyright (c) 2005-2012 Brenden Matthews, Philip Kovacs, et. al. * Copyright (c) 2005-2018 Brenden Matthews, Philip Kovacs, et. al.
* (see AUTHORS) * (see AUTHORS)
* All rights reserved. * All rights reserved.
* *
@@ -27,17 +26,16 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
* *
*/ */
#ifdef BUILD_X11
#ifndef _FONTS_H #ifndef _FONTS_H
#define _FONTS_H #define _FONTS_H
#include <vector> #include <vector>
#include "conky.h"
#include "x11.h" #include "x11.h"
/* for fonts */ /* for fonts */
struct font_list { struct font_list {
std::string name; std::string name;
XFontStruct *font; XFontStruct *font;
XFontSet fontset; XFontSet fontset;
@@ -48,27 +46,36 @@ struct font_list {
#endif #endif
font_list() font_list()
: name(), font(NULL), fontset(NULL) : name(),
font(NULL),
fontset(NULL)
#ifdef BUILD_XFT #ifdef BUILD_XFT
, xftfont(NULL), font_alpha(0xffff) ,
xftfont(NULL),
font_alpha(0xffff)
#endif #endif
{} {
}
}; };
#ifdef BUILD_XFT #ifdef BUILD_XFT
#define font_height() (use_xft.get(*state) ? (fonts[selected_font].xftfont->ascent + \ #define font_height() \
(use_xft.get(*state) ? (fonts[selected_font].xftfont->ascent + \
fonts[selected_font].xftfont->descent) \ fonts[selected_font].xftfont->descent) \
: (fonts[selected_font].font->max_bounds.ascent + \ : (fonts[selected_font].font->max_bounds.ascent + \
fonts[selected_font].font->max_bounds.descent)) fonts[selected_font].font->max_bounds.descent))
#define font_ascent() (use_xft.get(*state) ? fonts[selected_font].xftfont->ascent \ #define font_ascent() \
(use_xft.get(*state) ? fonts[selected_font].xftfont->ascent \
: fonts[selected_font].font->max_bounds.ascent) : fonts[selected_font].font->max_bounds.ascent)
#define font_descent() (use_xft.get(*state) ? fonts[selected_font].xftfont->descent \ #define font_descent() \
(use_xft.get(*state) ? fonts[selected_font].xftfont->descent \
: fonts[selected_font].font->max_bounds.descent) : fonts[selected_font].font->max_bounds.descent)
#else #else
#define font_height() (fonts[selected_font].font->max_bounds.ascent + \ #define font_height() \
(fonts[selected_font].font->max_bounds.ascent + \
fonts[selected_font].font->max_bounds.descent) fonts[selected_font].font->max_bounds.descent)
#define font_ascent() fonts[selected_font].font->max_bounds.ascent #define font_ascent() fonts[selected_font].font->max_bounds.ascent
#define font_descent() fonts[selected_font].font->max_bounds.descent #define font_descent() fonts[selected_font].font->max_bounds.descent
@@ -92,12 +99,9 @@ protected:
virtual void lua_setter(lua::state &l, bool init); virtual void lua_setter(lua::state &l, bool init);
public: public:
font_setting() font_setting() : Base("font", "6x10", false) {}
: Base("font", "6x10", false)
{}
}; };
extern font_setting font; extern font_setting font;
#endif /* _FONTS_H */ #endif /* _FONTS_H */
#endif /* BUILD_X11 */

View File

@@ -1,5 +1,4 @@
/* -*- mode: c++; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*- /*
* vim: ts=4 sw=4 noet ai cindent syntax=cpp
* *
* Conky, a system monitor, based on torsmo * Conky, a system monitor, based on torsmo
* *
@@ -9,7 +8,7 @@
* *
* Please see COPYING for details * Please see COPYING for details
* *
* Copyright (c) 2005-2012 Brenden Matthews, Philip Kovacs, et. al. * Copyright (c) 2005-2018 Brenden Matthews, Philip Kovacs, et. al.
* (see AUTHORS) * (see AUTHORS)
* All rights reserved. * All rights reserved.
* *
@@ -29,8 +28,8 @@
#include "config.h" #include "config.h"
#include <sys/ioctl.h>
#include <sys/dkstat.h> #include <sys/dkstat.h>
#include <sys/ioctl.h>
#include <sys/param.h> #include <sys/param.h>
#include <sys/resource.h> #include <sys/resource.h>
#include <sys/socket.h> #include <sys/socket.h>
@@ -41,8 +40,8 @@
#include <sys/user.h> #include <sys/user.h>
#include <net/if.h> #include <net/if.h>
#include <net/if_mib.h>
#include <net/if_media.h> #include <net/if_media.h>
#include <net/if_mib.h>
#include <net/if_var.h> #include <net/if_var.h>
#include <devstat.h> #include <devstat.h>
@@ -50,18 +49,18 @@
#include <limits.h> #include <limits.h>
#include <unistd.h> #include <unistd.h>
#include <dev/wi/if_wavelan_ieee.h>
#include <dev/acpica/acpiio.h> #include <dev/acpica/acpiio.h>
#include <dev/wi/if_wavelan_ieee.h>
#include <mutex> #include <mutex>
#include "conky.h" #include "conky.h"
#include "diskio.h"
#include "freebsd.h" #include "freebsd.h"
#include "logging.h" #include "logging.h"
#include "net_stat.h" #include "net_stat.h"
#include "text_object.h" #include "text_object.h"
#include "top.h" #include "top.h"
#include "diskio.h"
#define GETSYSCTL(name, var) getsysctl(name, &(var), sizeof(var)) #define GETSYSCTL(name, var) getsysctl(name, &(var), sizeof(var))
#define KELVTOC(x) ((x - 2732) / 10.0) #define KELVTOC(x) ((x - 2732) / 10.0)
@@ -74,14 +73,13 @@
kvm_t *kd; kvm_t *kd;
std::mutex kvm_proc_mutex; std::mutex kvm_proc_mutex;
__attribute__((gnu_inline)) inline void proc_find_top(struct process **cpu,
__attribute__((gnu_inline)) inline void struct process **mem,
proc_find_top(struct process **cpu, struct process **mem, struct process **time); struct process **time);
static short cpu_setup = 0; static short cpu_setup = 0;
static int getsysctl(const char *name, void *ptr, size_t len) static int getsysctl(const char *name, void *ptr, size_t len) {
{
size_t nlen = len; size_t nlen = len;
if (sysctlbyname(name, ptr, &nlen, NULL, 0) == -1) { if (sysctlbyname(name, ptr, &nlen, NULL, 0) == -1) {
@@ -98,8 +96,7 @@ static int getsysctl(const char *name, void *ptr, size_t len)
struct ifmibdata *data = NULL; struct ifmibdata *data = NULL;
size_t len = 0; size_t len = 0;
static int swapmode(unsigned long *retavail, unsigned long *retfree) static int swapmode(unsigned long *retavail, unsigned long *retfree) {
{
int n; int n;
unsigned long pagesize = getpagesize(); unsigned long pagesize = getpagesize();
struct kvm_swap swapary[1]; struct kvm_swap swapary[1];
@@ -117,25 +114,21 @@ static int swapmode(unsigned long *retavail, unsigned long *retfree)
*retavail = CONVERT(swapary[0].ksw_total); *retavail = CONVERT(swapary[0].ksw_total);
*retfree = CONVERT(swapary[0].ksw_total - swapary[0].ksw_used); *retfree = CONVERT(swapary[0].ksw_total - swapary[0].ksw_used);
n = (int) ((double) swapary[0].ksw_used * 100.0 / n = (int)((double)swapary[0].ksw_used * 100.0 / (double)swapary[0].ksw_total);
(double) swapary[0].ksw_total);
return n; return n;
} }
void prepare_update(void) void prepare_update(void) {}
{
}
int update_uptime(void) int update_uptime(void) {
{
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;
size_t size = sizeof(boottime); size_t size = sizeof(boottime);
if ((sysctl(mib, 2, &boottime, &size, NULL, 0) != -1) if ((sysctl(mib, 2, &boottime, &size, NULL, 0) != -1) &&
&& (boottime.tv_sec != 0)) { (boottime.tv_sec != 0)) {
time(&now); time(&now);
info.uptime = now - boottime.tv_sec; info.uptime = now - boottime.tv_sec;
} else { } else {
@@ -146,13 +139,11 @@ int update_uptime(void)
return 0; return 0;
} }
int check_mount(struct text_object *obj) int check_mount(struct text_object *obj) {
{
struct statfs *mntbuf; struct statfs *mntbuf;
int i, mntsize; int i, mntsize;
if (!obj->data.s) if (!obj->data.s) return 0;
return 0;
mntsize = getmntinfo(&mntbuf, MNT_NOWAIT); mntsize = getmntinfo(&mntbuf, MNT_NOWAIT);
for (i = mntsize - 1; i >= 0; i--) { for (i = mntsize - 1; i >= 0; i--) {
@@ -164,8 +155,7 @@ int check_mount(struct text_object *obj)
return 0; return 0;
} }
int update_meminfo(void) int update_meminfo(void) {
{
u_int total_pages, inactive_pages, free_pages; u_int total_pages, inactive_pages, free_pages;
unsigned long swap_avail, swap_free; unsigned long swap_avail, swap_free;
@@ -201,8 +191,7 @@ int update_meminfo(void)
return 0; return 0;
} }
int update_net_stats(void) int update_net_stats(void) {
{
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;
@@ -237,8 +226,7 @@ int update_net_stats(void)
iftmp != NULL && strcmp(ifa->ifa_name, iftmp->ifa_name) == 0; iftmp != NULL && strcmp(ifa->ifa_name, iftmp->ifa_name) == 0;
iftmp = iftmp->ifa_next) { iftmp = iftmp->ifa_next) {
if (iftmp->ifa_addr->sa_family == AF_INET) { if (iftmp->ifa_addr->sa_family == AF_INET) {
memcpy(&(ns->addr), iftmp->ifa_addr, memcpy(&(ns->addr), iftmp->ifa_addr, iftmp->ifa_addr->sa_len);
iftmp->ifa_addr->sa_len);
} }
} }
@@ -255,8 +243,7 @@ int update_net_stats(void)
ns->last_read_recv = r; ns->last_read_recv = r;
if (t < ns->last_read_trans) { if (t < ns->last_read_trans) {
ns->trans += ((long long) 4294967295U - ns->trans += ((long long)4294967295U - ns->last_read_trans) + t;
ns->last_read_trans) + t;
} else { } else {
ns->trans += (t - ns->last_read_trans); ns->trans += (t - ns->last_read_trans);
} }
@@ -275,8 +262,7 @@ int update_net_stats(void)
return 0; return 0;
} }
int update_total_processes(void) int update_total_processes(void) {
{
int n_processes; int n_processes;
std::lock_guard<std::mutex> guard(kvm_proc_mutex); std::lock_guard<std::mutex> guard(kvm_proc_mutex);
@@ -286,8 +272,7 @@ int update_total_processes(void)
return 0; return 0;
} }
int update_running_processes(void) int update_running_processes(void) {
{
struct kinfo_proc *p; struct kinfo_proc *p;
int n_processes; int n_processes;
int i, cnt = 0; int i, cnt = 0;
@@ -304,8 +289,7 @@ int update_running_processes(void)
return 0; return 0;
} }
void get_cpu_count(void) void get_cpu_count(void) {
{
int cpu_count = 0; int cpu_count = 0;
size_t cpu_count_len = sizeof(cpu_count); size_t cpu_count_len = sizeof(cpu_count);
@@ -327,8 +311,7 @@ struct cpu_info {
long oldused; long oldused;
}; };
int update_cpu_usage(void) int update_cpu_usage(void) {
{
int i, j = 0; int i, j = 0;
long used, total; long used, total;
long *cp_time = NULL; long *cp_time = NULL;
@@ -359,14 +342,13 @@ int update_cpu_usage(void)
} }
total = 0; total = 0;
for (j = 0; j < CPUSTATES; j++) for (j = 0; j < CPUSTATES; j++) total += cp_time[j];
total += cp_time[j];
used = total - cp_time[CP_IDLE]; used = total - cp_time[CP_IDLE];
if ((total - cpu[0].oldtotal) != 0) { if ((total - cpu[0].oldtotal) != 0) {
info.cpu_usage[0] = ((double) (used - cpu[0].oldused)) / info.cpu_usage[0] =
(double) (total - cpu[0].oldtotal); ((double)(used - cpu[0].oldused)) / (double)(total - cpu[0].oldtotal);
} else { } else {
info.cpu_usage[0] = 0; info.cpu_usage[0] = 0;
} }
@@ -380,16 +362,16 @@ int update_cpu_usage(void)
cp_len = CPUSTATES * sizeof(long) * info.cpu_count; cp_len = CPUSTATES * sizeof(long) * info.cpu_count;
cp_time = (long int *)malloc(cp_len); cp_time = (long int *)malloc(cp_len);
/* on e.g. i386 SMP we may have more values than actual cpus; this will just drop extra values */ /* on e.g. i386 SMP we may have more values than actual cpus; this will just
if (sysctlbyname("kern.cp_times", cp_time, &cp_len, NULL, 0) < 0 && errno != ENOMEM) { * drop extra values */
if (sysctlbyname("kern.cp_times", cp_time, &cp_len, NULL, 0) < 0 &&
errno != ENOMEM) {
fprintf(stderr, "Cannot get kern.cp_times\n"); fprintf(stderr, "Cannot get kern.cp_times\n");
} }
for (i = 0; i < info.cpu_count; i++) for (i = 0; i < info.cpu_count; i++) {
{
total = 0; total = 0;
for (j = 0; j < CPUSTATES; j++) for (j = 0; j < CPUSTATES; j++) total += cp_time[i * CPUSTATES + j];
total += cp_time[i*CPUSTATES + j];
used = total - cp_time[i * CPUSTATES + CP_IDLE]; used = total - cp_time[i * CPUSTATES + CP_IDLE];
@@ -408,8 +390,7 @@ int update_cpu_usage(void)
return 0; return 0;
} }
int update_load_average(void) int update_load_average(void) {
{
double v[3]; double v[3];
getloadavg(v, 3); getloadavg(v, 3);
@@ -421,8 +402,7 @@ int update_load_average(void)
return 0; return 0;
} }
double get_acpi_temperature(int fd) double get_acpi_temperature(int fd) {
{
int temp; int temp;
(void)fd; (void)fd;
@@ -438,7 +418,8 @@ double get_acpi_temperature(int fd)
return 0.0; return 0.0;
} }
static void get_battery_stats(int *battime, int *batcapacity, int *batstate, int *ac) { static void get_battery_stats(int *battime, int *batcapacity, int *batstate,
int *ac) {
if (battime && GETSYSCTL("hw.acpi.battery.time", *battime)) { if (battime && GETSYSCTL("hw.acpi.battery.time", *battime)) {
fprintf(stderr, "Cannot read sysctl \"hw.acpi.battery.time\"\n"); fprintf(stderr, "Cannot read sysctl \"hw.acpi.battery.time\"\n");
} }
@@ -453,8 +434,7 @@ static void get_battery_stats(int *battime, int *batcapacity, int *batstate, int
} }
} }
void get_battery_stuff(char *buf, unsigned int n, const char *bat, int item) void get_battery_stuff(char *buf, unsigned int n, const char *bat, int item) {
{
int battime, batcapacity, batstate, ac; int battime, batcapacity, batstate, ac;
(void)bat; (void)bat;
@@ -476,8 +456,10 @@ void get_battery_stuff(char *buf, unsigned int n, const char *bat, int item)
if (batstate == 1) // Discharging if (batstate == 1) // Discharging
snprintf(buf, n, "remaining (%d%%)", batcapacity); snprintf(buf, n, "remaining (%d%%)", batcapacity);
else else
snprintf(buf, n, batstate == 2 ? "charging (%d%%)" : snprintf(buf, n,
(batstate == 7 ? "absent/on AC" : "charged (%d%%)"), batstate == 2
? "charging (%d%%)"
: (batstate == 7 ? "absent/on AC" : "charged (%d%%)"),
batcapacity); batcapacity);
break; break;
default: default:
@@ -485,8 +467,7 @@ void get_battery_stuff(char *buf, unsigned int n, const char *bat, int item)
} }
} }
static int check_bat(const char *bat) static int check_bat(const char *bat) {
{
int batnum, numbatts; int batnum, numbatts;
char *endptr; char *endptr;
if (GETSYSCTL("hw.acpi.battery.units", numbatts)) { if (GETSYSCTL("hw.acpi.battery.units", numbatts)) {
@@ -497,37 +478,34 @@ static int check_bat(const char *bat)
fprintf(stderr, "No battery unit detected\n"); fprintf(stderr, "No battery unit detected\n");
return -1; return -1;
} }
if (!bat || (batnum = strtol(bat, &endptr, 10)) < 0 || if (!bat || (batnum = strtol(bat, &endptr, 10)) < 0 || bat == endptr ||
bat == endptr || batnum > numbatts) { batnum > numbatts) {
fprintf(stderr, "Wrong battery unit %s requested\n", bat ? bat : ""); fprintf(stderr, "Wrong battery unit %s requested\n", bat ? bat : "");
return -1; return -1;
} }
return batnum; return batnum;
} }
int get_battery_perct(const char *bat) int get_battery_perct(const char *bat) {
{
int batcapacity; int batcapacity;
get_battery_stats(NULL, &batcapacity, NULL, NULL); get_battery_stats(NULL, &batcapacity, NULL, NULL);
return batcapacity; return batcapacity;
} }
double get_battery_perct_bar(struct text_object *obj) double get_battery_perct_bar(struct text_object *obj) {
{
int batperct = get_battery_perct(obj->data.s); int batperct = get_battery_perct(obj->data.s);
return batperct; return batperct;
} }
int open_acpi_temperature(const char *name) int open_acpi_temperature(const char *name) {
{
(void)name; (void)name;
/* Not applicable for FreeBSD. */ /* Not applicable for FreeBSD. */
return 0; return 0;
} }
void get_acpi_ac_adapter(char *p_client_buffer, size_t client_buffer_size, const char *adapter) void get_acpi_ac_adapter(char *p_client_buffer, size_t client_buffer_size,
{ const char *adapter) {
int state; int state;
(void)adapter; // only linux uses this (void)adapter; // only linux uses this
@@ -548,8 +526,7 @@ void get_acpi_ac_adapter(char *p_client_buffer, size_t client_buffer_size, const
} }
} }
void get_acpi_fan(char *p_client_buffer, size_t client_buffer_size) void get_acpi_fan(char *p_client_buffer, size_t client_buffer_size) {
{
/* not implemented */ /* not implemented */
if (p_client_buffer && client_buffer_size > 0) { if (p_client_buffer && client_buffer_size > 0) {
memset(p_client_buffer, 0, client_buffer_size); memset(p_client_buffer, 0, client_buffer_size);
@@ -557,14 +534,13 @@ void get_acpi_fan(char *p_client_buffer, size_t client_buffer_size)
} }
/* void */ /* void */
char get_freq(char *p_client_buffer, size_t client_buffer_size, const char *p_format, char get_freq(char *p_client_buffer, size_t client_buffer_size,
int divisor, unsigned int cpu) const char *p_format, int divisor, unsigned int cpu) {
{
int freq; int freq;
char *freq_sysctl; char *freq_sysctl;
if (!p_client_buffer || client_buffer_size <= 0 || !p_format if (!p_client_buffer || client_buffer_size <= 0 || !p_format ||
|| divisor <= 0) { divisor <= 0) {
return 0; return 0;
} }
@@ -641,8 +617,7 @@ cleanup:
} }
#endif #endif
int update_diskio(void) int update_diskio(void) {
{
int devs_count, num_selected, num_selections, dn; int devs_count, num_selected, num_selections, dn;
struct device_selection *dev_select = NULL; struct device_selection *dev_select = NULL;
long select_generation; long select_generation;
@@ -652,7 +627,6 @@ int update_diskio(void)
unsigned int reads, writes; unsigned int reads, writes;
unsigned int total_reads = 0, total_writes = 0; unsigned int total_reads = 0, total_writes = 0;
memset(&statinfo_cur, 0, sizeof(statinfo_cur)); memset(&statinfo_cur, 0, sizeof(statinfo_cur));
statinfo_cur.dinfo = (struct devinfo *)calloc(1, sizeof(struct devinfo)); statinfo_cur.dinfo = (struct devinfo *)calloc(1, sizeof(struct devinfo));
stats.current = stats.current_read = stats.current_write = 0; stats.current = stats.current_read = stats.current_write = 0;
@@ -665,8 +639,8 @@ int update_diskio(void)
devs_count = statinfo_cur.dinfo->numdevs; devs_count = statinfo_cur.dinfo->numdevs;
if (devstat_selectdevs(&dev_select, &num_selected, &num_selections, if (devstat_selectdevs(&dev_select, &num_selected, &num_selections,
&select_generation, statinfo_cur.dinfo->generation, &select_generation, statinfo_cur.dinfo->generation,
statinfo_cur.dinfo->devices, devs_count, NULL, 0, NULL, 0, statinfo_cur.dinfo->devices, devs_count, NULL, 0, NULL,
DS_SELECT_ONLY, MAXSHOWDEVS, 1) >= 0) { 0, DS_SELECT_ONLY, MAXSHOWDEVS, 1) >= 0) {
for (dn = 0; dn < devs_count; dn++) { for (dn = 0; dn < devs_count; dn++) {
int di; int di;
struct devstat *dev; struct devstat *dev;
@@ -696,8 +670,7 @@ int update_diskio(void)
/* 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_proc *p; struct kinfo_proc *p;
struct process *proc; struct process *proc;
int n_processes; int n_processes;
@@ -723,8 +696,7 @@ void get_top_info(void)
} }
} }
void get_battery_short_status(char *buffer, unsigned int n, const char *bat) void get_battery_short_status(char *buffer, unsigned int n, const char *bat) {
{
get_battery_stuff(buffer, n, bat, BATTERY_STATUS); get_battery_stuff(buffer, n, bat, BATTERY_STATUS);
if (0 == strncmp("charging", buffer, 8)) { if (0 == strncmp("charging", buffer, 8)) {
buffer[0] = 'C'; buffer[0] = 'C';
@@ -741,15 +713,13 @@ void get_battery_short_status(char *buffer, unsigned int n, const char *bat)
} }
} }
int get_entropy_avail(unsigned int *val) int get_entropy_avail(unsigned int *val) {
{
/* Not applicable for FreeBSD as it uses the yarrow prng. */ /* Not applicable for FreeBSD as it uses the yarrow prng. */
(void)val; (void)val;
return 1; return 1;
} }
int get_entropy_poolsize(unsigned int *val) int get_entropy_poolsize(unsigned int *val) {
{
/* Not applicable for FreeBSD as it uses the yarrow prng. */ /* Not applicable for FreeBSD as it uses the yarrow prng. */
(void)val; (void)val;
return 1; return 1;

View File

@@ -1,15 +1,15 @@
/* -*- mode: c; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*- */ /* */
#ifndef FREEBSD_H_ #ifndef FREEBSD_H_
#define FREEBSD_H_ #define FREEBSD_H_
#include "common.h"
#include <sys/param.h>
#include <sys/mount.h>
#include <sys/ucred.h>
#include <strings.h>
#include <fcntl.h> #include <fcntl.h>
#include <kvm.h> #include <kvm.h>
#include <strings.h>
#include <sys/mount.h>
#include <sys/param.h>
#include <sys/ucred.h>
#include "common.h"
#if (defined(i386) || defined(__i386__)) #if (defined(i386) || defined(__i386__))
#include <machine/apm_bios.h> #include <machine/apm_bios.h>
#endif /* i386 || __i386__ */ #endif /* i386 || __i386__ */

View File

@@ -1,5 +1,4 @@
/* -*- mode: c++; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*- /*
* vim: ts=4 sw=4 noet ai cindent syntax=cpp
* *
* Conky, a system monitor, based on torsmo * Conky, a system monitor, based on torsmo
* *
@@ -10,7 +9,7 @@
* Please see COPYING for details * Please see COPYING for details
* *
* Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen * Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
* Copyright (c) 2005-2012 Brenden Matthews, Philip Kovacs, et. al. * Copyright (c) 2005-2018 Brenden Matthews, Philip Kovacs, et. al.
* (see AUTHORS) * (see AUTHORS)
* All rights reserved. * All rights reserved.
* *
@@ -28,24 +27,24 @@
* *
*/ */
#include "fs.h"
#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
#include <sys/types.h>
#include <unistd.h>
#include "conky.h" #include "conky.h"
#include "logging.h" #include "logging.h"
#include "fs.h"
#include "specials.h" #include "specials.h"
#include "text_object.h" #include "text_object.h"
#include <ctype.h>
#include <unistd.h>
#include <errno.h>
#include <sys/types.h>
#include <fcntl.h>
#ifdef HAVE_SYS_STATFS_H #ifdef HAVE_SYS_STATFS_H
#include <sys/statfs.h> #include <sys/statfs.h>
#endif #endif
#if defined(__sun) #if defined(__sun)
#include <sys/types.h>
#include <sys/statvfs.h> #include <sys/statvfs.h>
#include <sys/types.h>
#endif #endif
#if defined(__FreeBSD__) #if defined(__FreeBSD__)
@@ -58,11 +57,9 @@
#include "darwin.h" #include "darwin.h"
#endif #endif
#if !defined(HAVE_STRUCT_STATFS_F_FSTYPENAME) && !defined(__OpenBSD__) && \
#if !defined(HAVE_STRUCT_STATFS_F_FSTYPENAME) && \ !defined(__FreeBSD__) && !defined(__DragonFly__) && !defined(__sun) && \
!defined (__OpenBSD__) && !defined(__FreeBSD__) && \ !defined(__HAIKU__) && !(defined(__APPLE__) && defined(__MACH__))
!defined(__DragonFly__) && !defined(__sun) && !defined(__HAIKU__) && \
!(defined(__APPLE__) && defined(__MACH__))
#include <mntent.h> #include <mntent.h>
#endif #endif
@@ -75,13 +72,11 @@ static void update_fs_stat(struct fs_stat *fs);
void get_fs_type(const char *path, char *result); void get_fs_type(const char *path, char *result);
int update_fs_stats(void) int update_fs_stats(void) {
{
unsigned i; unsigned i;
static double last_fs_update = 0.0; static double last_fs_update = 0.0;
if (current_update_time - last_fs_update < 13) if (current_update_time - last_fs_update < 13) return 0;
return 0;
for (i = 0; i < MAX_FS_STATS; ++i) { for (i = 0; i < MAX_FS_STATS; ++i) {
if (fs_stats[i].set) { if (fs_stats[i].set) {
@@ -92,16 +87,14 @@ int update_fs_stats(void)
return 0; return 0;
} }
void clear_fs_stats(void) void clear_fs_stats(void) {
{
unsigned i; unsigned i;
for (i = 0; i < MAX_FS_STATS; ++i) { for (i = 0; i < MAX_FS_STATS; ++i) {
memset(&fs_stats[i], 0, sizeof(struct fs_stat)); memset(&fs_stats[i], 0, sizeof(struct fs_stat));
} }
} }
struct fs_stat *prepare_fs_stat(const char *s) struct fs_stat *prepare_fs_stat(const char *s) {
{
struct fs_stat *next = 0; struct fs_stat *next = 0;
unsigned i; unsigned i;
@@ -126,8 +119,7 @@ struct fs_stat *prepare_fs_stat(const char *s)
return next; return next;
} }
static void update_fs_stat(struct fs_stat *fs) static void update_fs_stat(struct fs_stat *fs) {
{
#if defined(__sun) #if defined(__sun)
struct statvfs s; struct statvfs s;
@@ -155,11 +147,10 @@ static void update_fs_stat(struct fs_stat *fs)
} }
} }
void get_fs_type(const char *path, char *result) void get_fs_type(const char *path, char *result) {
{ #if defined(HAVE_STRUCT_STATFS_F_FSTYPENAME) || defined(__FreeBSD__) || \
defined(__OpenBSD__) || defined(__DragonFly__) || defined(__HAIKU__) || \
#if defined(HAVE_STRUCT_STATFS_F_FSTYPENAME) || \ (defined(__APPLE__) && defined(__MACH__))
defined(__FreeBSD__) || defined (__OpenBSD__) || defined(__DragonFly__) || defined(__HAIKU__) || (defined(__APPLE__) && defined(__MACH__))
struct statfs64 s; struct statfs64 s;
if (statfs64(path, &s) == 0) { if (statfs64(path, &s) == 0) {
@@ -189,14 +180,12 @@ void get_fs_type(const char *path, char *result)
// find our path in the mtab // find our path in the mtab
search_path = strdup(path); search_path = strdup(path);
do { do {
while ((match = strcmp(search_path, me->mnt_dir)) while ((match = strcmp(search_path, me->mnt_dir)) && getmntent(mtab))
&& getmntent(mtab)); ;
if (!match) if (!match) break;
break;
fseek(mtab, 0, SEEK_SET); fseek(mtab, 0, SEEK_SET);
slash = strrchr(search_path, '/'); slash = strrchr(search_path, '/');
if (slash == NULL) if (slash == NULL) CRIT_ERR(NULL, NULL, "invalid path '%s'", path);
CRIT_ERR(NULL, NULL, "invalid path '%s'", path);
if (strlen(slash) == 1) /* trailing slash */ if (strlen(slash) == 1) /* trailing slash */
*(slash) = '\0'; *(slash) = '\0';
else if (strlen(slash) > 1) else if (strlen(slash) > 1)
@@ -215,11 +204,9 @@ void get_fs_type(const char *path, char *result)
#endif /* HAVE_STRUCT_STATFS_F_FSTYPENAME */ #endif /* HAVE_STRUCT_STATFS_F_FSTYPENAME */
strncpy(result, "unknown", DEFAULT_TEXT_BUFFER_SIZE); strncpy(result, "unknown", DEFAULT_TEXT_BUFFER_SIZE);
} }
void init_fs_bar(struct text_object *obj, const char *arg) void init_fs_bar(struct text_object *obj, const char *arg) {
{
arg = scan_bar(obj, arg, 1); arg = scan_bar(obj, arg, 1);
if (arg) { if (arg) {
while (isspace(*arg)) { while (isspace(*arg)) {
@@ -234,8 +221,7 @@ void init_fs_bar(struct text_object *obj, const char *arg)
obj->data.opaque = prepare_fs_stat(arg); obj->data.opaque = prepare_fs_stat(arg);
} }
static double get_fs_perc(struct text_object *obj, bool get_free) static double get_fs_perc(struct text_object *obj, bool get_free) {
{
struct fs_stat *fs = static_cast<struct fs_stat *>(obj->data.opaque); struct fs_stat *fs = static_cast<struct fs_stat *>(obj->data.opaque);
double ret = 0.0; double ret = 0.0;
@@ -250,47 +236,36 @@ static double get_fs_perc(struct text_object *obj, bool get_free)
return ret; return ret;
} }
double fs_barval(struct text_object *obj) double fs_barval(struct text_object *obj) { return get_fs_perc(obj, false); }
{
return get_fs_perc(obj, false);
}
double fs_free_barval(struct text_object *obj) double fs_free_barval(struct text_object *obj) {
{
return get_fs_perc(obj, true); return get_fs_perc(obj, true);
} }
void init_fs(struct text_object *obj, const char *arg) void init_fs(struct text_object *obj, const char *arg) {
{
obj->data.opaque = prepare_fs_stat(arg ? arg : "/"); obj->data.opaque = prepare_fs_stat(arg ? arg : "/");
} }
uint8_t fs_free_percentage(struct text_object *obj) uint8_t fs_free_percentage(struct text_object *obj) {
{
return get_fs_perc(obj, true) * 100; return get_fs_perc(obj, true) * 100;
} }
uint8_t fs_used_percentage(struct text_object *obj) uint8_t fs_used_percentage(struct text_object *obj) {
{
return get_fs_perc(obj, false) * 100; return get_fs_perc(obj, false) * 100;
} }
#define HUMAN_PRINT_FS_GENERATOR(name, expr) \ #define HUMAN_PRINT_FS_GENERATOR(name, expr) \
void print_fs_##name(struct text_object *obj, char *p, int p_max_size) \ void print_fs_##name(struct text_object *obj, char *p, int p_max_size) { \
{ \
struct fs_stat *fs = (struct fs_stat *)obj->data.opaque; \ struct fs_stat *fs = (struct fs_stat *)obj->data.opaque; \
if (fs) \ if (fs) human_readable(expr, p, p_max_size); \
human_readable(expr, p, p_max_size); \
} }
HUMAN_PRINT_FS_GENERATOR(free, fs->avail) HUMAN_PRINT_FS_GENERATOR(free, fs->avail)
HUMAN_PRINT_FS_GENERATOR(size, fs->size) HUMAN_PRINT_FS_GENERATOR(size, fs->size)
HUMAN_PRINT_FS_GENERATOR(used, fs->size - fs->free) HUMAN_PRINT_FS_GENERATOR(used, fs->size - fs->free)
void print_fs_type(struct text_object *obj, char *p, int p_max_size) void print_fs_type(struct text_object *obj, char *p, int p_max_size) {
{
struct fs_stat *fs = (struct fs_stat *)obj->data.opaque; struct fs_stat *fs = (struct fs_stat *)obj->data.opaque;
if (fs) if (fs) snprintf(p, p_max_size, "%s", fs->type);
snprintf(p, p_max_size, "%s", fs->type);
} }

View File

@@ -1,5 +1,4 @@
/* -*- mode: c++; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*- /*
* vim: ts=4 sw=4 noet ai cindent syntax=cpp
* *
* Conky, a system monitor, based on torsmo * Conky, a system monitor, based on torsmo
* *
@@ -10,7 +9,7 @@
* Please see COPYING for details * Please see COPYING for details
* *
* Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen * Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
* Copyright (c) 2005-2012 Brenden Matthews, Philip Kovacs, et. al. * Copyright (c) 2005-2018 Brenden Matthews, Philip Kovacs, et. al.
* (see AUTHORS) * (see AUTHORS)
* All rights reserved. * All rights reserved.
* *

View File

@@ -1,5 +1,4 @@
/* -*- mode: c++; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*- /*
* vim: ts=4 sw=4 noet ai cindent syntax=cpp
* *
* Conky, a system monitor, based on torsmo * Conky, a system monitor, based on torsmo
* *
@@ -10,7 +9,7 @@
* Please see COPYING for details * Please see COPYING for details
* *
* Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen * Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
* Copyright (c) 2005-2012 Brenden Matthews, Philip Kovacs, et. al. * Copyright (c) 2005-2018 Brenden Matthews, Philip Kovacs, et. al.
* (see AUTHORS) * (see AUTHORS)
* All rights reserved. * All rights reserved.
* *
@@ -30,32 +29,27 @@
#include <OS.h> #include <OS.h>
#include "haiku.h"
#include "conky.h" #include "conky.h"
#include "haiku.h"
#include "net_stat.h" #include "net_stat.h"
#include "top.h" #include "top.h"
static short cpu_setup = 0; static short cpu_setup = 0;
void prepare_update() void prepare_update() {}
{
}
int update_uptime() int update_uptime() {
{
info.uptime = (double)system_time() / 1000000.0; info.uptime = (double)system_time() / 1000000.0;
return 0; return 0;
} }
int check_mount(struct text_object *obj) int check_mount(struct text_object *obj) {
{
/* stub */ /* stub */
(void)obj; (void)obj;
return 0; return 0;
} }
int update_meminfo() int update_meminfo() {
{
system_info si; system_info si;
if (get_system_info(&si) != B_OK) { if (get_system_info(&si) != B_OK) {
@@ -76,26 +70,22 @@ int update_meminfo()
return 0; return 0;
} }
int update_net_stats() int update_net_stats() {
{
// TODO // TODO
return 1; return 1;
} }
int update_total_processes() int update_total_processes() {
{
// TODO // TODO
return 1; return 1;
} }
int update_running_processes() int update_running_processes() {
{
// TODO // TODO
return 1; return 1;
} }
void get_cpu_count(void) void get_cpu_count(void) {
{
system_info si; system_info si;
if (get_system_info(&si) != B_OK) { if (get_system_info(&si) != B_OK) {
@@ -111,8 +101,7 @@ void get_cpu_count(void)
} }
} }
int update_cpu_usage() int update_cpu_usage() {
{
// TODO // TODO
static bigtime_t prev = 0; static bigtime_t prev = 0;
static cpu_info *prev_cpuinfo = NULL; static cpu_info *prev_cpuinfo = NULL;
@@ -149,8 +138,8 @@ int update_cpu_usage()
cpuinfo[0].active_time /= info.cpu_count; cpuinfo[0].active_time /= info.cpu_count;
for (int i = 0; i <= info.cpu_count; i++) { for (int i = 0; i <= info.cpu_count; i++) {
double period = (double)(now - prev); double period = (double)(now - prev);
info.cpu_usage[i] = ((double) info.cpu_usage[i] =
(cpuinfo[i].active_time - prev_cpuinfo[i].active_time)) / ((double)(cpuinfo[i].active_time - prev_cpuinfo[i].active_time)) /
period; period;
} }
} }
@@ -161,24 +150,18 @@ int update_cpu_usage()
return 1; return 1;
} }
int update_load_average() int update_load_average() {
{
// TODO // TODO
return 1; return 1;
} }
double get_acpi_temperature(int fd) double get_acpi_temperature(int fd) { return -1; }
{
return -1;
}
void get_battery_stuff(char *buf, unsigned int n, const char *bat, int item) void get_battery_stuff(char *buf, unsigned int n, const char *bat, int item) {
{
// TODO // TODO
} }
int get_battery_perct(const char *bat) int get_battery_perct(const char *bat) {
{
/* /*
int batcapacity; int batcapacity;
@@ -189,19 +172,15 @@ int get_battery_perct(const char *bat)
return 0; return 0;
} }
double get_battery_perct_bar(struct text_object *obj) double get_battery_perct_bar(struct text_object *obj) {
{
int batperct = get_battery_perct(obj->data.s); int batperct = get_battery_perct(obj->data.s);
return batperct; return batperct;
} }
int open_acpi_temperature(const char *name) int open_acpi_temperature(const char *name) { return -1; }
{
return -1;
}
void get_acpi_ac_adapter(char *p_client_buffer, size_t client_buffer_size, const char *adapter) void get_acpi_ac_adapter(char *p_client_buffer, size_t client_buffer_size,
{ const char *adapter) {
(void)adapter; // only linux uses this (void)adapter; // only linux uses this
if (!p_client_buffer || client_buffer_size <= 0) { if (!p_client_buffer || client_buffer_size <= 0) {
@@ -213,8 +192,7 @@ void get_acpi_ac_adapter(char *p_client_buffer, size_t client_buffer_size, const
} }
/* char *get_acpi_fan() */ /* char *get_acpi_fan() */
void get_acpi_fan(char *p_client_buffer, size_t client_buffer_size) void get_acpi_fan(char *p_client_buffer, size_t client_buffer_size) {
{
if (!p_client_buffer || client_buffer_size <= 0) { if (!p_client_buffer || client_buffer_size <= 0) {
return; return;
} }
@@ -224,14 +202,13 @@ void get_acpi_fan(char *p_client_buffer, size_t client_buffer_size)
} }
/* void */ /* void */
char get_freq(char *p_client_buffer, size_t client_buffer_size, const char *p_format, char get_freq(char *p_client_buffer, size_t client_buffer_size,
int divisor, unsigned int cpu) const char *p_format, int divisor, unsigned int cpu) {
{
int freq; int freq;
char *freq_sysctl; char *freq_sysctl;
if (!p_client_buffer || client_buffer_size <= 0 || !p_format if (!p_client_buffer || client_buffer_size <= 0 || !p_format ||
|| divisor <= 0) { divisor <= 0) {
return 0; return 0;
} }
return 0; return 0;
@@ -239,13 +216,9 @@ char get_freq(char *p_client_buffer, size_t client_buffer_size, const char *p_fo
// return 1; // return 1;
} }
int update_diskio(void) int update_diskio(void) { return 1; }
{
return 1;
}
void get_top_info(void) void get_top_info(void) {
{
int32 tmcookie = 0; int32 tmcookie = 0;
team_info tm; team_info tm;
struct process *proc; struct process *proc;
@@ -253,8 +226,7 @@ void get_top_info(void)
while (get_next_team_info(&tmcookie, &tm) == B_NO_ERROR) { while (get_next_team_info(&tmcookie, &tm) == B_NO_ERROR) {
team_usage_info ti; team_usage_info ti;
if (get_team_usage_info(tm.team, B_TEAM_USAGE_SELF, &ti) != B_OK) if (get_team_usage_info(tm.team, B_TEAM_USAGE_SELF, &ti) != B_OK) continue;
continue;
proc = get_process(tm.team); proc = get_process(tm.team);
@@ -270,17 +242,10 @@ void get_top_info(void)
} }
} }
void get_battery_short_status(char *buffer, unsigned int n, const char *bat) void get_battery_short_status(char *buffer, unsigned int n, const char *bat) {
{
// TODO // TODO
} }
int get_entropy_avail(unsigned int *val) int get_entropy_avail(unsigned int *val) { return 1; }
{
return 1;
}
int get_entropy_poolsize(unsigned int *val) int get_entropy_poolsize(unsigned int *val) { return 1; }
{
return 1;
}

View File

@@ -1,36 +1,34 @@
/* -*- mode: c; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*- */ /* */
#ifndef HAIKU_H_ #ifndef HAIKU_H_
#define HAIKU_H_ #define HAIKU_H_
#include <fcntl.h>
#include <time.h>
#include <unistd.h>
#include <err.h> #include <err.h>
#include <fcntl.h>
#include <limits.h> #include <limits.h>
#include <paths.h> #include <paths.h>
#include <time.h>
#include <unistd.h>
#include <sys/socket.h>
#include <sys/time.h> #include <sys/time.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/socket.h>
#include <net/if.h> #include <net/if.h>
#include <kernel/fs_info.h> #include <kernel/fs_info.h>
#include "conky.h"
#include "common.h" #include "common.h"
#include "conky.h"
int get_entropy_avail(unsigned int *); int get_entropy_avail(unsigned int *);
int get_entropy_poolsize(unsigned int *); int get_entropy_poolsize(unsigned int *);
/* let's just mimic statfs64 */ /* let's just mimic statfs64 */
struct statfs : public fs_info {}; struct statfs : public fs_info {};
inline int statfs(const char *path, struct statfs *buf) inline int statfs(const char *path, struct statfs *buf) {
{
return fs_stat_dev(dev_for_path(path), buf); return fs_stat_dev(dev_for_path(path), buf);
} }
@@ -40,5 +38,4 @@ inline int statfs(const char *path, struct statfs *buf)
#define f_bfree free_blocks #define f_bfree free_blocks
#define f_fstypename fsh_name #define f_fstypename fsh_name
#endif /*HAIKU_H_*/ #endif /*HAIKU_H_*/

View File

@@ -1,5 +1,4 @@
/* -*- mode: c++; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*- /*
* vim: ts=4 sw=4 noet ai cindent syntax=cpp
* *
* Conky, a system monitor, based on torsmo * Conky, a system monitor, based on torsmo
* *
@@ -10,7 +9,7 @@
* Please see COPYING for details * Please see COPYING for details
* *
* Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen * Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
* Copyright (c) 2005-2012 Brenden Matthews, Philip Kovacs, et. al. * Copyright (c) 2005-2018 Brenden Matthews, Philip Kovacs, et. al.
* (see AUTHORS) * (see AUTHORS)
* All rights reserved. * All rights reserved.
* *
@@ -28,22 +27,25 @@
* *
*/ */
#include <errno.h>
#include <fcntl.h>
#include <netdb.h>
#include <netinet/in.h>
#include <sys/select.h>
#include <sys/socket.h>
#include <unistd.h>
#include "conky.h" #include "conky.h"
#include "logging.h" #include "logging.h"
#include "temphelper.h" #include "temphelper.h"
#include "text_object.h" #include "text_object.h"
#include <errno.h>
#include <unistd.h>
#include <fcntl.h>
#include <netdb.h>
#include <sys/select.h>
#include <sys/socket.h>
#include <netinet/in.h>
#define BUFLEN 512 #define BUFLEN 512
static conky::simple_config_setting<std::string> hddtemp_host("hddtemp_host", "localhost", false); static conky::simple_config_setting<std::string> hddtemp_host("hddtemp_host",
static conky::simple_config_setting<std::string> hddtemp_port("hddtemp_port", "7634", false); "localhost",
false);
static conky::simple_config_setting<std::string> hddtemp_port("hddtemp_port",
"7634", false);
struct hdd_info { struct hdd_info {
hdd_info() : next(0) {} hdd_info() : next(0) {}
@@ -55,30 +57,24 @@ struct hdd_info {
struct hdd_info hdd_info_head; struct hdd_info hdd_info_head;
static void __free_hddtemp_info(struct hdd_info *hdi) static void __free_hddtemp_info(struct hdd_info *hdi) {
{ if (hdi->next) __free_hddtemp_info(hdi->next);
if (hdi->next)
__free_hddtemp_info(hdi->next);
free(hdi->dev); free(hdi->dev);
delete hdi; delete hdi;
} }
static void free_hddtemp_info(void) static void free_hddtemp_info(void) {
{
DBGP("free_hddtemp_info() called"); DBGP("free_hddtemp_info() called");
if (!hdd_info_head.next) if (!hdd_info_head.next) return;
return;
__free_hddtemp_info(hdd_info_head.next); __free_hddtemp_info(hdd_info_head.next);
hdd_info_head.next = NULL; hdd_info_head.next = NULL;
} }
static void add_hddtemp_info(char *dev, short temp, char unit) static void add_hddtemp_info(char *dev, short temp, char unit) {
{
struct hdd_info *hdi = &hdd_info_head; struct hdd_info *hdi = &hdd_info_head;
DBGP("add_hddtemp_info(%s, %d, %c) being called", dev, temp, unit); DBGP("add_hddtemp_info(%s, %d, %c) being called", dev, temp, unit);
while (hdi->next) while (hdi->next) hdi = hdi->next;
hdi = hdi->next;
hdi->next = new hdd_info; hdi->next = new hdd_info;
memset(hdi->next, 0, sizeof(struct hdd_info)); memset(hdi->next, 0, sizeof(struct hdd_info));
@@ -87,8 +83,7 @@ static void add_hddtemp_info(char *dev, short temp, char unit)
hdi->next->unit = unit; hdi->next->unit = unit;
} }
static char *fetch_hddtemp_output(void) static char *fetch_hddtemp_output(void) {
{
int sockfd; int sockfd;
char *buf = NULL; char *buf = NULL;
int buflen, offset = 0, rlen; int buflen, offset = 0, rlen;
@@ -107,10 +102,8 @@ static char *fetch_hddtemp_output(void)
for (rp = result; rp; rp = rp->ai_next) { for (rp = result; rp; rp = rp->ai_next) {
sockfd = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol); sockfd = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
if (sockfd == -1) if (sockfd == -1) continue;
continue; if (connect(sockfd, rp->ai_addr, rp->ai_addrlen) != -1) break;
if (connect(sockfd, rp->ai_addr, rp->ai_addrlen) != -1)
break;
close(sockfd); close(sockfd);
} }
if (!rp) { if (!rp) {
@@ -127,8 +120,7 @@ static char *fetch_hddtemp_output(void)
buf = (char *)realloc(buf, buflen); buf = (char *)realloc(buf, buflen);
} }
} }
if (rlen < 0) if (rlen < 0) perror("recv");
perror("recv");
buf[offset] = '\0'; buf[offset] = '\0';
@@ -144,8 +136,7 @@ GET_OUT:
* is not being freed! * is not being freed!
*/ */
static int read_hdd_val(const char *line, char **dev, short *val, char *unit, static int read_hdd_val(const char *line, char **dev, short *val, char *unit,
char **saveptr) char **saveptr) {
{
char *line_s, *cval, *endptr; char *line_s, *cval, *endptr;
static char *p = 0; static char *p = 0;
@@ -156,26 +147,21 @@ static int read_hdd_val(const char *line, char **dev, short *val, char *unit,
line_s = *saveptr; line_s = *saveptr;
again: again:
if(!*p) if (!*p) goto out_fail;
goto out_fail;
/* read the device */ /* read the device */
*dev = ++p; *dev = ++p;
if (!(p = strchr(p, line_s[0]))) if (!(p = strchr(p, line_s[0]))) goto out_fail;
goto out_fail;
*(p++) = '\0'; *(p++) = '\0';
/* jump over the devname */ /* jump over the devname */
if (!(p = strchr(p, line_s[0]))) if (!(p = strchr(p, line_s[0]))) goto out_fail;
goto out_fail;
/* read the value */ /* read the value */
cval = ++p; cval = ++p;
if (!(p = strchr(p, line_s[0]))) if (!(p = strchr(p, line_s[0]))) goto out_fail;
goto out_fail;
*(p++) = '\0'; *(p++) = '\0';
*unit = *(p++); *unit = *(p++);
*val = strtol(cval, &endptr, 10); *val = strtol(cval, &endptr, 10);
if (*endptr) { if (*endptr) {
if (!(p = strchr(p, line_s[0]))) if (!(p = strchr(p, line_s[0]))) goto out_fail;
goto out_fail;
p++; p++;
goto again; goto again;
@@ -196,14 +182,12 @@ int update_hddtemp(void) {
static double last_hddtemp_update = 0.0; static double last_hddtemp_update = 0.0;
/* limit tcp connection overhead */ /* limit tcp connection overhead */
if (current_update_time - last_hddtemp_update < 5) if (current_update_time - last_hddtemp_update < 5) return 0;
return 0;
last_hddtemp_update = current_update_time; last_hddtemp_update = current_update_time;
free_hddtemp_info(); free_hddtemp_info();
if (!(data = fetch_hddtemp_output())) if (!(data = fetch_hddtemp_output())) return 0;
return 0;
if (read_hdd_val(data, &dev, &val, &unit, &saveptr)) { if (read_hdd_val(data, &dev, &val, &unit, &saveptr)) {
free(data); free(data);
@@ -216,32 +200,27 @@ int update_hddtemp(void) {
return 0; return 0;
} }
void free_hddtemp(struct text_object *obj) void free_hddtemp(struct text_object *obj) {
{
free_hddtemp_info(); free_hddtemp_info();
free_and_zero(obj->data.s); free_and_zero(obj->data.s);
} }
static int get_hddtemp_info(const char *dev, short *val, char *unit) static int get_hddtemp_info(const char *dev, short *val, char *unit) {
{
struct hdd_info *hdi = hdd_info_head.next; struct hdd_info *hdi = hdd_info_head.next;
/* if no dev is given, just use hdd_info_head->next */ /* if no dev is given, just use hdd_info_head->next */
while (dev && hdi) { while (dev && hdi) {
if (!strcmp(dev, hdi->dev)) if (!strcmp(dev, hdi->dev)) break;
break;
hdi = hdi->next; hdi = hdi->next;
} }
if (!hdi) if (!hdi) return 1;
return 1;
*val = hdi->temp; *val = hdi->temp;
*unit = hdi->unit; *unit = hdi->unit;
return 0; return 0;
} }
void print_hddtemp(struct text_object *obj, char *p, int p_max_size) void print_hddtemp(struct text_object *obj, char *p, int p_max_size) {
{
short val; short val;
char unit; char unit;

View File

@@ -1,12 +1,11 @@
/* -*- mode: c++; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*- /*
* vim: ts=4 sw=4 noet ai cindent syntax=cpp
* *
* Conky, a system monitor, based on torsmo * Conky, a system monitor, based on torsmo
* *
* Please see COPYING for details * Please see COPYING for details
* *
* Copyright (c) 2007 Toni Spets * Copyright (c) 2007 Toni Spets
* Copyright (c) 2005-2012 Brenden Matthews, Philip Kovacs, et. al. * Copyright (c) 2005-2018 Brenden Matthews, Philip Kovacs, et. al.
* (see AUTHORS) * (see AUTHORS)
* All rights reserved. * All rights reserved.
* *

View File

@@ -1,11 +1,10 @@
/* -*- mode: c++; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*- /*
* vim: ts=4 sw=4 noet ai cindent syntax=cpp
* *
* Conky, a system monitor, based on torsmo * Conky, a system monitor, based on torsmo
* *
* Please see COPYING for details * Please see COPYING for details
* *
* Copyright (c) 2005-2012 Brenden Matthews, Philip Kovacs, et. al. * Copyright (c) 2005-2018 Brenden Matthews, Philip Kovacs, et. al.
* (see AUTHORS) * (see AUTHORS)
* All rights reserved. * All rights reserved.
* *

View File

@@ -1,5 +1,4 @@
/* -*- mode: c++; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*- /*
* vim: ts=4 sw=4 noet ai cindent syntax=cpp
* *
* Conky, a system monitor, based on torsmo * Conky, a system monitor, based on torsmo
* *
@@ -11,7 +10,7 @@
* *
* Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen * Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
* Copyright (c) 2007 Toni Spets * Copyright (c) 2007 Toni Spets
* Copyright (c) 2005-2012 Brenden Matthews, Philip Kovacs, et. al. * Copyright (c) 2005-2018 Brenden Matthews, Philip Kovacs, et. al.
* (see AUTHORS) * (see AUTHORS)
* All rights reserved. * All rights reserved.
* *
@@ -54,8 +53,7 @@ struct _i8k {
#define PROC_I8K "/proc/i8k" #define PROC_I8K "/proc/i8k"
#define I8K_DELIM " " #define I8K_DELIM " "
static char *i8k_procbuf = NULL; static char *i8k_procbuf = NULL;
int update_i8k(void) int update_i8k(void) {
{
FILE *fp; FILE *fp;
if (!i8k_procbuf) { if (!i8k_procbuf) {
@@ -63,9 +61,11 @@ int update_i8k(void)
} }
if ((fp = fopen(PROC_I8K, "r")) == NULL) { if ((fp = fopen(PROC_I8K, "r")) == NULL) {
free_and_zero(i8k_procbuf); free_and_zero(i8k_procbuf);
/*THREAD_CRIT_ERR(NULL, NULL, "/proc/i8k doesn't exist! use insmod to make sure the kernel " /*THREAD_CRIT_ERR(NULL, NULL, "/proc/i8k doesn't exist! use insmod to make
"driver is loaded...");*/ sure the kernel " "driver is loaded...");*/
NORM_ERR("/proc/i8k doesn't exist! use insmod to make sure the kernel driver is loaded..."); NORM_ERR(
"/proc/i8k doesn't exist! use insmod to make sure the kernel driver is "
"loaded...");
clean_up_without_threads(NULL, NULL); clean_up_without_threads(NULL, NULL);
return 1; return 1;
} }
@@ -92,25 +92,22 @@ int update_i8k(void)
return 0; return 0;
} }
static void print_i8k_fan_status(char *p, int p_max_size, const char *status) static void print_i8k_fan_status(char *p, int p_max_size, const char *status) {
{
static const char *status_arr[] = {"off", "low", "high", "error"}; static const char *status_arr[] = {"off", "low", "high", "error"};
int i = status ? atoi(status) : 3; int i = status ? atoi(status) : 3;
if(i < 0 || i > 3) if (i < 0 || i > 3) i = 3;
i = 3;
snprintf(p, p_max_size, "%s", status_arr[i]); snprintf(p, p_max_size, "%s", status_arr[i]);
} }
void print_i8k_left_fan_status(struct text_object *obj, char *p, int p_max_size) void print_i8k_left_fan_status(struct text_object *obj, char *p,
{ int p_max_size) {
(void)obj; (void)obj;
print_i8k_fan_status(p, p_max_size, i8k.left_fan_status); print_i8k_fan_status(p, p_max_size, i8k.left_fan_status);
} }
void print_i8k_cpu_temp(struct text_object *obj, char *p, int p_max_size) void print_i8k_cpu_temp(struct text_object *obj, char *p, int p_max_size) {
{
int cpu_temp; int cpu_temp;
(void)obj; (void)obj;
@@ -119,14 +116,13 @@ void print_i8k_cpu_temp(struct text_object *obj, char *p, int p_max_size)
temp_print(p, p_max_size, (double)cpu_temp, TEMP_CELSIUS); temp_print(p, p_max_size, (double)cpu_temp, TEMP_CELSIUS);
} }
void print_i8k_right_fan_status(struct text_object *obj, char *p, int p_max_size) void print_i8k_right_fan_status(struct text_object *obj, char *p,
{ int p_max_size) {
(void)obj; (void)obj;
print_i8k_fan_status(p, p_max_size, i8k.right_fan_status); print_i8k_fan_status(p, p_max_size, i8k.right_fan_status);
} }
void print_i8k_ac_status(struct text_object *obj, char *p, int p_max_size) void print_i8k_ac_status(struct text_object *obj, char *p, int p_max_size) {
{
int ac_status; int ac_status;
(void)obj; (void)obj;
@@ -144,8 +140,7 @@ void print_i8k_ac_status(struct text_object *obj, char *p, int p_max_size)
} }
#define I8K_PRINT_GENERATOR(name) \ #define I8K_PRINT_GENERATOR(name) \
void print_i8k_##name(struct text_object *obj, char *p, int p_max_size) \ void print_i8k_##name(struct text_object *obj, char *p, int p_max_size) { \
{ \
(void)obj; \ (void)obj; \
snprintf(p, p_max_size, "%s", i8k.name); \ snprintf(p, p_max_size, "%s", i8k.name); \
} }

View File

@@ -1,5 +1,4 @@
/* -*- mode: c++; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*- /*
* vim: ts=4 sw=4 noet ai cindent syntax=cpp
* *
* Conky, a system monitor, based on torsmo * Conky, a system monitor, based on torsmo
* *
@@ -11,7 +10,7 @@
* *
* Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen * Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
* Copyright (c) 2007 Toni Spets * Copyright (c) 2007 Toni Spets
* Copyright (c) 2005-2012 Brenden Matthews, Philip Kovacs, et. al. * Copyright (c) 2005-2018 Brenden Matthews, Philip Kovacs, et. al.
* (see AUTHORS) * (see AUTHORS)
* All rights reserved. * All rights reserved.
* *

View File

@@ -1,5 +1,4 @@
/* -*- mode: c++; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*- /*
* vim: ts=4 sw=4 noet ai cindent syntax=cpp
* *
* Conky, a system monitor, based on torsmo * Conky, a system monitor, based on torsmo
* *
@@ -11,7 +10,7 @@
* *
* Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen * Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
* Copyright (c) 2007 Toni Spets * Copyright (c) 2007 Toni Spets
* Copyright (c) 2005-2012 Brenden Matthews, Philip Kovacs, et. al. * Copyright (c) 2005-2018 Brenden Matthews, Philip Kovacs, et. al.
* (see AUTHORS) * (see AUTHORS)
* All rights reserved. * All rights reserved.
* *
@@ -29,16 +28,16 @@
* *
*/ */
#include "conky.h"
#include "config.h"
#include "ibm.h" #include "ibm.h"
#include <ctype.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "config.h"
#include "conky.h"
#include "logging.h" #include "logging.h"
#include "temphelper.h" #include "temphelper.h"
#include <ctype.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <stdlib.h>
static int ibm_acpi_temps[8]; static int ibm_acpi_temps[8];
@@ -73,8 +72,7 @@ speed: 2944
commands: enable, disable commands: enable, disable
* Peter Tarjan (ptarjan@citromail.hu) */ * Peter Tarjan (ptarjan@citromail.hu) */
void get_ibm_acpi_fan(struct text_object *obj, char *p, int p_max_size) void get_ibm_acpi_fan(struct text_object *obj, char *p, int p_max_size) {
{
FILE *fp; FILE *fp;
unsigned int speed = 0; unsigned int speed = 0;
char fan[128]; char fan[128];
@@ -100,8 +98,10 @@ void get_ibm_acpi_fan(struct text_object *obj, char *p, int p_max_size)
} }
} }
} else { } else {
CRIT_ERR(NULL, NULL, "can't open '%s': %s\nYou are not using the IBM ACPI. Remove " CRIT_ERR(NULL, NULL,
"ibm* from your " PACKAGE_NAME" config file.", fan, strerror(errno)); "can't open '%s': %s\nYou are not using the IBM ACPI. Remove "
"ibm* from your " PACKAGE_NAME " config file.",
fan, strerror(errno));
} }
fclose(fp); fclose(fp);
@@ -129,9 +129,7 @@ void get_ibm_acpi_fan(struct text_object *obj, char *p, int p_max_size)
temperatures: 41 43 31 46 33 -128 29 -128 temperatures: 41 43 31 46 33 -128 29 -128
* Peter Tarjan (ptarjan@citromail.hu) */ * Peter Tarjan (ptarjan@citromail.hu) */
int get_ibm_acpi_temps(void) int get_ibm_acpi_temps(void) {
{
FILE *fp; FILE *fp;
char thermal[128]; char thermal[128];
@@ -153,8 +151,10 @@ int get_ibm_acpi_temps(void)
} }
} }
} else { } else {
CRIT_ERR(NULL, NULL, "can't open '%s': %s\nYou are not using the IBM ACPI. Remove " CRIT_ERR(NULL, NULL,
"ibm* from your " PACKAGE_NAME" config file.", thermal, strerror(errno)); "can't open '%s': %s\nYou are not using the IBM ACPI. Remove "
"ibm* from your " PACKAGE_NAME " config file.",
thermal, strerror(errno));
} }
fclose(fp); fclose(fp);
@@ -171,8 +171,7 @@ commands: up, down, mute
commands: level <level> (<level> is 0-15) commands: level <level> (<level> is 0-15)
* Peter Tarjan (ptarjan@citromail.hu) */ * Peter Tarjan (ptarjan@citromail.hu) */
void get_ibm_acpi_volume(struct text_object *obj, char *p, int p_max_size) void get_ibm_acpi_volume(struct text_object *obj, char *p, int p_max_size) {
{
FILE *fp; FILE *fp;
char volume[128]; char volume[128];
unsigned int vol = -1; unsigned int vol = -1;
@@ -204,8 +203,10 @@ void get_ibm_acpi_volume(struct text_object *obj, char *p, int p_max_size)
} }
} }
} else { } else {
CRIT_ERR(NULL, NULL, "can't open '%s': %s\nYou are not using the IBM ACPI. Remove " CRIT_ERR(NULL, NULL,
"ibm* from your " PACKAGE_NAME" config file.", volume, strerror(errno)); "can't open '%s': %s\nYou are not using the IBM ACPI. Remove "
"ibm* from your " PACKAGE_NAME " config file.",
volume, strerror(errno));
} }
fclose(fp); fclose(fp);
@@ -225,8 +226,7 @@ commands: up, down
commands: level <level> (<level> is 0-7) commands: level <level> (<level> is 0-7)
* Peter Tarjan (ptarjan@citromail.hu) */ * Peter Tarjan (ptarjan@citromail.hu) */
void get_ibm_acpi_brightness(struct text_object *obj, char *p, int p_max_size) void get_ibm_acpi_brightness(struct text_object *obj, char *p, int p_max_size) {
{
FILE *fp; FILE *fp;
unsigned int brightness = 0; unsigned int brightness = 0;
char filename[128]; char filename[128];
@@ -252,8 +252,10 @@ void get_ibm_acpi_brightness(struct text_object *obj, char *p, int p_max_size)
} }
} }
} else { } else {
CRIT_ERR(NULL, NULL, "can't open '%s': %s\nYou are not using the IBM ACPI. Remove " CRIT_ERR(NULL, NULL,
"ibm* from your " PACKAGE_NAME" config file.", filename, strerror(errno)); "can't open '%s': %s\nYou are not using the IBM ACPI. Remove "
"ibm* from your " PACKAGE_NAME " config file.",
filename, strerror(errno));
} }
fclose(fp); fclose(fp);
@@ -269,8 +271,7 @@ commands: on, off
* get "unknown" for a few models that do not make the status available. * get "unknown" for a few models that do not make the status available.
* Lluis Esquerda (eskerda@gmail.com) */ * Lluis Esquerda (eskerda@gmail.com) */
void get_ibm_acpi_thinklight(struct text_object *obj, char *p, int p_max_size) void get_ibm_acpi_thinklight(struct text_object *obj, char *p, int p_max_size) {
{
FILE *fp; FILE *fp;
char thinklight[8]; char thinklight[8];
char filename[128]; char filename[128];
@@ -296,7 +297,8 @@ void get_ibm_acpi_thinklight(struct text_object *obj, char *p, int p_max_size)
} }
} }
} else { } else {
CRIT_ERR(NULL, NULL, "can't open '%s': %s\nYou are not using the IBM " CRIT_ERR(NULL, NULL,
"can't open '%s': %s\nYou are not using the IBM "
"ACPI. Remove ibm* from your " PACKAGE_NAME " config file.", "ACPI. Remove ibm* from your " PACKAGE_NAME " config file.",
filename, strerror(errno)); filename, strerror(errno));
} }
@@ -305,17 +307,16 @@ void get_ibm_acpi_thinklight(struct text_object *obj, char *p, int p_max_size)
snprintf(p, p_max_size, "%s", thinklight); snprintf(p, p_max_size, "%s", thinklight);
} }
void parse_ibm_temps_arg(struct text_object *obj, const char *arg) void parse_ibm_temps_arg(struct text_object *obj, const char *arg) {
{
if (!isdigit(arg[0]) || strlen(arg) > 1 || atoi(&arg[0]) >= 8) { if (!isdigit(arg[0]) || strlen(arg) > 1 || atoi(&arg[0]) >= 8) {
obj->data.l = 0; obj->data.l = 0;
NORM_ERR("Invalid temperature sensor! Sensor number must be 0 to 7. " NORM_ERR(
"Invalid temperature sensor! Sensor number must be 0 to 7. "
"Using 0 (CPU temp sensor)."); "Using 0 (CPU temp sensor).");
} else } else
obj->data.l = atoi(arg); obj->data.l = atoi(arg);
} }
void print_ibm_temps(struct text_object *obj, char *p, int p_max_size) void print_ibm_temps(struct text_object *obj, char *p, int p_max_size) {
{
temp_print(p, p_max_size, ibm_acpi_temps[obj->data.l], TEMP_CELSIUS); temp_print(p, p_max_size, ibm_acpi_temps[obj->data.l], TEMP_CELSIUS);
} }

View File

@@ -1,11 +1,10 @@
/* -*- mode: c++; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*- /*
* vim: ts=4 sw=4 noet ai cindent syntax=cpp
* *
* Conky, a system monitor, based on torsmo * Conky, a system monitor, based on torsmo
* *
* Please see COPYING for details * Please see COPYING for details
* *
* Copyright (c) 2005-2012 Brenden Matthews, Philip Kovacs, et. al. * Copyright (c) 2005-2018 Brenden Matthews, Philip Kovacs, et. al.
* (see AUTHORS) * (see AUTHORS)
* All rights reserved. * All rights reserved.
* *

View File

@@ -1,11 +1,10 @@
/* -*- mode: c++; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*- /*
* vim: ts=4 sw=4 noet ai cindent syntax=cpp
* *
* Conky, a system monitor, based on torsmo * Conky, a system monitor, based on torsmo
* *
* Please see COPYING for details * Please see COPYING for details
* *
* Copyright (c) 2005-2012 Brenden Matthews, Philip Kovacs, et. al. * Copyright (c) 2005-2018 Brenden Matthews, Philip Kovacs, et. al.
* (see AUTHORS) * (see AUTHORS)
* All rights reserved. * All rights reserved.
* *
@@ -44,25 +43,31 @@ char* read_stream(char *s, size_t size, void *d) {
return fgets(s, size, (FILE *)d); return fgets(s, size, (FILE *)d);
} }
struct ical_event *add_event(struct ical_event *listend, icalcomponent *new_ev) { struct ical_event *add_event(struct ical_event *listend,
icalcomponent *new_ev) {
struct ical_event *ev_new, *ev_cur; struct ical_event *ev_new, *ev_cur;
icaltimetype start; icaltimetype start;
start = icalcomponent_get_dtstart(new_ev); start = icalcomponent_get_dtstart(new_ev);
if(icaltime_compare(start, icaltime_from_timet_with_zone(time(NULL), 0, NULL)) <= 0) { if (icaltime_compare(
icalproperty *rrule = icalcomponent_get_first_property(new_ev, ICAL_RRULE_PROPERTY); start, icaltime_from_timet_with_zone(time(NULL), 0, NULL)) <= 0) {
icalproperty *rrule =
icalcomponent_get_first_property(new_ev, ICAL_RRULE_PROPERTY);
if (rrule) { if (rrule) {
icalrecur_iterator* ritr = icalrecur_iterator_new(icalproperty_get_rrule(rrule), start); icalrecur_iterator *ritr =
icalrecur_iterator_new(icalproperty_get_rrule(rrule), start);
icaltimetype nexttime = icalrecur_iterator_next(ritr); icaltimetype nexttime = icalrecur_iterator_next(ritr);
while (!icaltime_is_null_time(nexttime)) { while (!icaltime_is_null_time(nexttime)) {
if(icaltime_compare(nexttime, icaltime_from_timet_with_zone(time(NULL), 0, NULL)) > 0) { if (icaltime_compare(nexttime, icaltime_from_timet_with_zone(
time(NULL), 0, NULL)) > 0) {
start = nexttime; start = nexttime;
break; break;
} }
nexttime = icalrecur_iterator_next(ritr); nexttime = icalrecur_iterator_next(ritr);
} }
icalrecur_iterator_free(ritr); icalrecur_iterator_free(ritr);
} else return NULL; } else
return NULL;
} }
ev_new = (struct ical_event *)malloc(sizeof(struct ical_event)); ev_new = (struct ical_event *)malloc(sizeof(struct ical_event));
memset(ev_new, 0, sizeof(struct ical_event)); memset(ev_new, 0, sizeof(struct ical_event));
@@ -93,7 +98,8 @@ struct ical_event *add_event(struct ical_event *listend, icalcomponent *new_ev)
return ev_new; return ev_new;
} }
void parse_ical_args(struct text_object *obj, const char* arg, void *free_at_crash, void *free_at_crash2) { void parse_ical_args(struct text_object *obj, const char *arg,
void *free_at_crash, void *free_at_crash2) {
char *filename = strdup(arg); char *filename = strdup(arg);
FILE *file; FILE *file;
icalparser *parser; icalparser *parser;
@@ -105,7 +111,8 @@ void parse_ical_args(struct text_object *obj, const char* arg, void *free_at_cra
if (sscanf(arg, "%d %s", &num, filename) != 2) { if (sscanf(arg, "%d %s", &num, filename) != 2) {
free(filename); free(filename);
free(obj); free(obj);
CRIT_ERR(free_at_crash, free_at_crash2, "wrong number of arguments for $ical"); CRIT_ERR(free_at_crash, free_at_crash2,
"wrong number of arguments for $ical");
} }
file = fopen(filename, "r"); file = fopen(filename, "r");
if (!file) { if (!file) {
@@ -165,7 +172,9 @@ void print_ical(struct text_object *obj, char *p, int p_max_size) {
i++; i++;
} }
} }
snprintf(p, p_max_size, "%s", icalproperty_get_summary(icalcomponent_get_first_property(ll_current->event, ICAL_SUMMARY_PROPERTY))); snprintf(p, p_max_size, "%s",
icalproperty_get_summary(icalcomponent_get_first_property(
ll_current->event, ICAL_SUMMARY_PROPERTY)));
} }
void free_ical(struct text_object *obj) { void free_ical(struct text_object *obj) {
@@ -178,7 +187,8 @@ void free_ical(struct text_object *obj) {
if (ical_free_me->list->next) { if (ical_free_me->list->next) {
ical_free_me->list = ical_free_me->list->next; ical_free_me->list = ical_free_me->list->next;
free_and_zero(ical_free_me->list->prev); free_and_zero(ical_free_me->list->prev);
} else free_and_zero(ical_free_me->list); } else
free_and_zero(ical_free_me->list);
} }
free(obj->data.opaque); free(obj->data.opaque);
} }

View File

@@ -1,11 +1,10 @@
/* -*- mode: c++; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*- /*
* vim: ts=4 sw=4 noet ai cindent syntax=cpp
* *
* Conky, a system monitor, based on torsmo * Conky, a system monitor, based on torsmo
* *
* Please see COPYING for details * Please see COPYING for details
* *
* Copyright (c) 2005-2012 Brenden Matthews, Philip Kovacs, et. al. * Copyright (c) 2005-2018 Brenden Matthews, Philip Kovacs, et. al.
* (see AUTHORS) * (see AUTHORS)
* All rights reserved. * All rights reserved.
* *

View File

@@ -1,5 +1,4 @@
/* -*- mode: c++; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*- /*
* vim: ts=4 sw=4 noet ai cindent syntax=cpp
* *
* Conky, a system monitor, based on torsmo * Conky, a system monitor, based on torsmo
* *
@@ -10,7 +9,7 @@
* Please see COPYING for details * Please see COPYING for details
* *
* Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen * Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
* Copyright (c) 2005-2012 Brenden Matthews, Philip Kovacs, et. al. * Copyright (c) 2005-2018 Brenden Matthews, Philip Kovacs, et. al.
* (see AUTHORS) * (see AUTHORS)
* All rights reserved. * All rights reserved.
* *
@@ -28,13 +27,13 @@
* *
*/ */
#include "config.h"
#include "logging.h"
#include "text_object.h"
#include <iconv.h> #include <iconv.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "config.h"
#include "logging.h"
#include "text_object.h"
#define ICONV_CODEPAGE_LENGTH 20 #define ICONV_CODEPAGE_LENGTH 20
@@ -43,8 +42,7 @@ static long iconv_count = 0;
static char iconv_converting = 0; static char iconv_converting = 0;
static iconv_t **iconv_cd = 0; static iconv_t **iconv_cd = 0;
int register_iconv(iconv_t *new_iconv) int register_iconv(iconv_t *new_iconv) {
{
iconv_cd = (void ***)realloc(iconv_cd, sizeof(iconv_t *) * (iconv_count + 1)); iconv_cd = (void ***)realloc(iconv_cd, sizeof(iconv_t *) * (iconv_count + 1));
if (!iconv_cd) { if (!iconv_cd) {
CRIT_ERR(NULL, NULL, "Out of memory"); CRIT_ERR(NULL, NULL, "Out of memory");
@@ -58,14 +56,12 @@ int register_iconv(iconv_t *new_iconv)
return iconv_count; return iconv_count;
} }
void free_iconv(struct text_object *obj) void free_iconv(struct text_object *obj) {
{
long i; long i;
(void)obj; (void)obj;
if (!iconv_cd) if (!iconv_cd) return;
return;
for (i = 0; i < iconv_count; i++) { for (i = 0; i < iconv_count; i++) {
if (iconv_cd[i]) { if (iconv_cd[i]) {
@@ -77,8 +73,7 @@ void free_iconv(struct text_object *obj)
iconv_cd = 0; iconv_cd = 0;
} }
void iconv_convert(size_t *a, char *buff_in, char *p, size_t p_max_size) void iconv_convert(size_t *a, char *buff_in, char *p, size_t p_max_size) {
{
int bytes; int bytes;
size_t dummy1, dummy2; size_t dummy1, dummy2;
#if defined(__FreeBSD__) || defined(__DragonFly__) #if defined(__FreeBSD__) || defined(__DragonFly__)
@@ -88,8 +83,8 @@ void iconv_convert(size_t *a, char *buff_in, char *p, size_t p_max_size)
#endif #endif
char *outptr = p; char *outptr = p;
if (*a <= 0 || !iconv_converting || iconv_selected <= 0 if (*a <= 0 || !iconv_converting || iconv_selected <= 0 ||
|| iconv_cd[iconv_selected - 1] == (iconv_t) (-1)) iconv_cd[iconv_selected - 1] == (iconv_t)(-1))
return; return;
dummy1 = dummy2 = *a; dummy1 = dummy2 = *a;
@@ -98,8 +93,8 @@ void iconv_convert(size_t *a, char *buff_in, char *p, size_t p_max_size)
iconv(*iconv_cd[iconv_selected - 1], NULL, NULL, NULL, NULL); iconv(*iconv_cd[iconv_selected - 1], NULL, NULL, NULL, NULL);
while (dummy1 > 0) { while (dummy1 > 0) {
bytes = iconv(*iconv_cd[iconv_selected - 1], &ptr, &dummy1, bytes =
&outptr, &dummy2); iconv(*iconv_cd[iconv_selected - 1], &ptr, &dummy1, &outptr, &dummy2);
if (bytes == -1) { if (bytes == -1) {
NORM_ERR("Iconv codeset conversion failed"); NORM_ERR("Iconv codeset conversion failed");
break; break;
@@ -113,13 +108,14 @@ void iconv_convert(size_t *a, char *buff_in, char *p, size_t p_max_size)
(*a) = outptr - p; (*a) = outptr - p;
} }
void init_iconv_start(struct text_object *obj, void *free_at_crash, const char *arg) void init_iconv_start(struct text_object *obj, void *free_at_crash,
{ const char *arg) {
char iconv_from[ICONV_CODEPAGE_LENGTH]; char iconv_from[ICONV_CODEPAGE_LENGTH];
char iconv_to[ICONV_CODEPAGE_LENGTH]; char iconv_to[ICONV_CODEPAGE_LENGTH];
if (iconv_converting) { if (iconv_converting) {
CRIT_ERR(obj, free_at_crash, "You must stop your last iconv conversion before " CRIT_ERR(obj, free_at_crash,
"You must stop your last iconv conversion before "
"starting another"); "starting another");
} }
if (sscanf(arg, "%s %s", iconv_from, iconv_to) != 2) { if (sscanf(arg, "%s %s", iconv_from, iconv_to) != 2) {
@@ -137,13 +133,9 @@ void init_iconv_start(struct text_object *obj, void *free_at_crash, const char *
} }
} }
void init_iconv_stop(void) void init_iconv_stop(void) { iconv_converting = 0; }
{
iconv_converting = 0;
}
void print_iconv_start(struct text_object *obj, char *p, int p_max_size) void print_iconv_start(struct text_object *obj, char *p, int p_max_size) {
{
(void)p; (void)p;
(void)p_max_size; (void)p_max_size;
@@ -151,8 +143,7 @@ void print_iconv_start(struct text_object *obj, char *p, int p_max_size)
iconv_selected = obj->data.i; iconv_selected = obj->data.i;
} }
void print_iconv_stop(struct text_object *obj, char *p, int p_max_size) void print_iconv_stop(struct text_object *obj, char *p, int p_max_size) {
{
(void)obj; (void)obj;
(void)p; (void)p;
(void)p_max_size; (void)p_max_size;

View File

@@ -1,5 +1,4 @@
/* -*- mode: c; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*- /*
* vim: ts=4 sw=4 noet ai cindent syntax=c
* *
* Conky, a system monitor, based on torsmo * Conky, a system monitor, based on torsmo
* *
@@ -10,7 +9,7 @@
* Please see COPYING for details * Please see COPYING for details
* *
* Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen * Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
* Copyright (c) 2005-2012 Brenden Matthews, Philip Kovacs, et. al. * Copyright (c) 2005-2018 Brenden Matthews, Philip Kovacs, et. al.
* (see AUTHORS) * (see AUTHORS)
* All rights reserved. * All rights reserved.
* *

View File

@@ -1,11 +1,10 @@
/* -*- mode: c++; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*- /*
* vim: ts=4 sw=4 noet ai cindent syntax=cpp
* *
* Conky, a system monitor, based on torsmo * Conky, a system monitor, based on torsmo
* *
* Please see COPYING for details * Please see COPYING for details
* *
* Copyright (c) 2005-2012 Brenden Matthews, et. al. * Copyright (c) 2005-2018 Brenden Matthews, et. al.
* All rights reserved. * All rights reserved.
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
@@ -22,16 +21,16 @@
* *
*/ */
#include "imlib2.h"
#include "config.h" #include "config.h"
#include "conky.h" #include "conky.h"
#include "logging.h" #include "logging.h"
#include "text_object.h" #include "text_object.h"
#include "imlib2.h"
#include <Imlib2.h> #include <Imlib2.h>
#include <limits.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <limits.h>
#include <string.h> #include <string.h>
#include <time.h> #include <time.h>
@@ -58,15 +57,13 @@ namespace {
Imlib_Context context; Imlib_Context context;
conky::range_config_setting<unsigned int> imlib_cache_flush_interval( conky::range_config_setting<unsigned int> imlib_cache_flush_interval(
"imlib_cache_flush_interval", 0, "imlib_cache_flush_interval", 0, std::numeric_limits<unsigned int>::max(),
std::numeric_limits<unsigned int>::max(), 0, true 0, true);
);
unsigned int cimlib_cache_flush_last = 0; unsigned int cimlib_cache_flush_last = 0;
} } // namespace
void imlib_cache_size_setting::lua_setter(lua::state &l, bool init) void imlib_cache_size_setting::lua_setter(lua::state &l, bool init) {
{
lua::stack_sentry s(l, -2); lua::stack_sentry s(l, -2);
Base::lua_setter(l, init); Base::lua_setter(l, init);
@@ -90,8 +87,7 @@ void imlib_cache_size_setting::lua_setter(lua::state &l, bool init)
++s; ++s;
} }
void imlib_cache_size_setting::cleanup(lua::state &l) void imlib_cache_size_setting::cleanup(lua::state &l) {
{
lua::stack_sentry s(l, -1); lua::stack_sentry s(l, -1);
if (out_to_x.get(l)) { if (out_to_x.get(l)) {
@@ -102,8 +98,7 @@ void imlib_cache_size_setting::cleanup(lua::state &l)
} }
} }
void cimlib_cleanup(void) void cimlib_cleanup(void) {
{
struct image_list_s *cur = image_list_start, *last = NULL; struct image_list_s *cur = image_list_start, *last = NULL;
while (cur) { while (cur) {
last = cur; last = cur;
@@ -113,8 +108,7 @@ void cimlib_cleanup(void)
image_list_start = image_list_end = NULL; image_list_start = image_list_end = NULL;
} }
void cimlib_add_image(const char *args) void cimlib_add_image(const char *args) {
{
struct image_list_s *cur = NULL; struct image_list_s *cur = NULL;
const char *tmp; const char *tmp;
@@ -122,8 +116,10 @@ void cimlib_add_image(const char *args)
memset(cur, 0, sizeof(struct image_list_s)); memset(cur, 0, sizeof(struct image_list_s));
if (!sscanf(args, "%1023s", cur->name)) { if (!sscanf(args, "%1023s", cur->name)) {
NORM_ERR("Invalid args for $image. Format is: '<path to image> (-p" NORM_ERR(
"x,y) (-s WxH) (-n) (-f interval)' (got '%s')", args); "Invalid args for $image. Format is: '<path to image> (-p"
"x,y) (-s WxH) (-n) (-f interval)' (got '%s')",
args);
free(cur); free(cur);
return; return;
} }
@@ -169,9 +165,8 @@ void cimlib_add_image(const char *args)
} }
} }
static void cimlib_draw_image(struct image_list_s *cur, int *clip_x, int static void cimlib_draw_image(struct image_list_s *cur, int *clip_x,
*clip_y, int *clip_x2, int *clip_y2) int *clip_y, int *clip_x2, int *clip_y2) {
{
int w, h; int w, h;
time_t now = time(NULL); time_t now = time(NULL);
static int rep = 0; static int rep = 0;
@@ -180,20 +175,19 @@ static void cimlib_draw_image(struct image_list_s *cur, int *clip_x, int
imlib_context_set_drawable(window.drawable); imlib_context_set_drawable(window.drawable);
} }
image = imlib_load_image(cur->name); image = imlib_load_image(cur->name);
if (!image) { if (!image) {
if (!rep) if (!rep) NORM_ERR("Unable to load image '%s'", cur->name);
NORM_ERR("Unable to load image '%s'", cur->name);
rep = 1; rep = 1;
return; return;
} }
rep = 0; /* reset so disappearing images are reported */ rep = 0; /* reset so disappearing images are reported */
DBGP("Drawing image '%s' at (%i,%i) scaled to %ix%i, " DBGP(
"Drawing image '%s' at (%i,%i) scaled to %ix%i, "
"caching interval set to %i (with -n opt %i)", "caching interval set to %i (with -n opt %i)",
cur->name, cur->x, cur->y, cur->w, cur->h, cur->name, cur->x, cur->y, cur->w, cur->h, cur->flush_interval,
cur->flush_interval, cur->no_cache); cur->no_cache);
imlib_context_set_image(image); imlib_context_set_image(image);
/* turn alpha channel on */ /* turn alpha channel on */
@@ -205,11 +199,11 @@ static void cimlib_draw_image(struct image_list_s *cur, int *clip_x, int
cur->h = h; cur->h = h;
} }
imlib_context_set_image(buffer); imlib_context_set_image(buffer);
imlib_blend_image_onto_image(image, 1, 0, 0, w, h, imlib_blend_image_onto_image(image, 1, 0, 0, w, h, cur->x, cur->y, cur->w,
cur->x, cur->y, cur->w, cur->h); cur->h);
imlib_context_set_image(image); imlib_context_set_image(image);
if (cur->no_cache || (cur->flush_interval && if (cur->no_cache ||
now % cur->flush_interval == 0)) { (cur->flush_interval && now % cur->flush_interval == 0)) {
imlib_free_image_and_decache(); imlib_free_image_and_decache();
} else { } else {
imlib_free_image(); imlib_free_image();
@@ -220,8 +214,8 @@ static void cimlib_draw_image(struct image_list_s *cur, int *clip_x, int
if (cur->y + cur->h > *clip_y2) *clip_y2 = cur->y + cur->h; if (cur->y + cur->h > *clip_y2) *clip_y2 = cur->y + cur->h;
} }
static void cimlib_draw_all(int *clip_x, int *clip_y, int *clip_x2, int *clip_y2) static void cimlib_draw_all(int *clip_x, int *clip_y, int *clip_x2,
{ int *clip_y2) {
struct image_list_s *cur = image_list_start; struct image_list_s *cur = image_list_start;
while (cur) { while (cur) {
cimlib_draw_image(cur, clip_x, clip_y, clip_x2, clip_y2); cimlib_draw_image(cur, clip_x, clip_y, clip_x2, clip_y2);
@@ -229,8 +223,7 @@ static void cimlib_draw_all(int *clip_x, int *clip_y, int *clip_x2, int *clip_y2
} }
} }
void cimlib_render(int x, int y, int width, int height) void cimlib_render(int x, int y, int width, int height) {
{
int clip_x = INT_MAX, clip_y = INT_MAX; int clip_x = INT_MAX, clip_y = INT_MAX;
int clip_x2 = 0, clip_y2 = 0; int clip_x2 = 0, clip_y2 = 0;
time_t now; time_t now;
@@ -269,15 +262,14 @@ void cimlib_render(int x, int y, int width, int height)
if (clip_y == INT_MAX) clip_y = 0; if (clip_y == INT_MAX) clip_y = 0;
/* render the image at 0, 0 */ /* render the image at 0, 0 */
imlib_render_image_part_on_drawable_at_size(clip_x, clip_y, clip_x2 - clip_x, imlib_render_image_part_on_drawable_at_size(
clip_y2 - clip_y, x + clip_x, y + clip_y, clip_x2 - clip_x, clip_x, clip_y, clip_x2 - clip_x, clip_y2 - clip_y, x + clip_x,
clip_y2 - clip_y); y + clip_y, clip_x2 - clip_x, clip_y2 - clip_y);
/* don't need that temporary buffer image anymore */ /* don't need that temporary buffer image anymore */
imlib_free_image(); imlib_free_image();
} }
void print_image_callback(struct text_object *obj, char *p, int p_max_size) void print_image_callback(struct text_object *obj, char *p, int p_max_size) {
{
(void)p; (void)p;
(void)p_max_size; (void)p_max_size;

View File

@@ -1,11 +1,10 @@
/* -*- mode: c++; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*- /*
* vim: ts=4 sw=4 noet ai cindent syntax=cpp
* *
* Conky, a system monitor, based on torsmo * Conky, a system monitor, based on torsmo
* *
* Please see COPYING for details * Please see COPYING for details
* *
* Copyright (c) 2005-2012 Brenden Matthews, et. al. * Copyright (c) 2005-2018 Brenden Matthews, et. al.
* All rights reserved. * All rights reserved.
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
@@ -25,6 +24,8 @@
#ifndef _CONKY_IMBLI2_H_ #ifndef _CONKY_IMBLI2_H_
#define _CONKY_IMBLI2_H_ #define _CONKY_IMBLI2_H_
#include "conky.h"
#include <X11/Xlib.h> #include <X11/Xlib.h>
void cimlib_add_image(const char *name); void cimlib_add_image(const char *name);
@@ -35,7 +36,8 @@ void cimlib_cleanup(void);
void print_image_callback(struct text_object *, char *, int); void print_image_callback(struct text_object *, char *, int);
class imlib_cache_size_setting: public conky::range_config_setting<unsigned long> { class imlib_cache_size_setting
: public conky::range_config_setting<unsigned long> {
typedef conky::range_config_setting<unsigned long> Base; typedef conky::range_config_setting<unsigned long> Base;
protected: protected:
@@ -44,9 +46,8 @@ protected:
public: public:
imlib_cache_size_setting() imlib_cache_size_setting()
: Base("imlib_cache_size", 0, : Base("imlib_cache_size", 0, std::numeric_limits<unsigned long>::max(),
std::numeric_limits<unsigned long>::max(), 4096*1024, true) 4096 * 1024, true) {}
{}
}; };
#endif /* _CONKY_IMBLI2_H_ */ #endif /* _CONKY_IMBLI2_H_ */

View File

@@ -1,11 +1,10 @@
/* -*- mode: c++; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*- /*
* vim: ts=4 sw=4 noet ai cindent syntax=cpp
* *
* Conky, a system monitor, based on torsmo * Conky, a system monitor, based on torsmo
* *
* Please see COPYING for details * Please see COPYING for details
* *
* Copyright (c) 2005-2012 Brenden Matthews, Philip Kovacs, et. al. * Copyright (c) 2005-2018 Brenden Matthews, Philip Kovacs, et. al.
* (see AUTHORS) * (see AUTHORS)
* All rights reserved. * All rights reserved.
* *
@@ -23,13 +22,13 @@
* *
*/ */
#include "conky.h" #include <libircclient.h>
#include "logging.h"
#include <pthread.h> #include <pthread.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "conky.h"
#include "logging.h"
#include "text_object.h" #include "text_object.h"
#include <libircclient.h>
struct ll_text { struct ll_text {
char *text; char *text;
@@ -48,12 +47,14 @@ struct ctx {
struct ll_text *messages; struct ll_text *messages;
}; };
void ev_connected(irc_session_t *session, const char *event, const char *origin, const char **params, unsigned int count) { void ev_connected(irc_session_t *session, const char *event, const char *origin,
const char **params, unsigned int count) {
struct ctx *ctxptr = (struct ctx *)irc_get_ctx(session); struct ctx *ctxptr = (struct ctx *)irc_get_ctx(session);
if (irc_cmd_join(session, ctxptr->chan, NULL) != 0) { if (irc_cmd_join(session, ctxptr->chan, NULL) != 0) {
NORM_ERR("irc: %s", irc_strerror(irc_errno(session))); NORM_ERR("irc: %s", irc_strerror(irc_errno(session)));
} }
if(event || origin || params || count) {} //fix gcc warnings if (event || origin || params || count) {
} // fix gcc warnings
} }
void addmessage(struct ctx *ctxptr, char *nick, const char *text) { void addmessage(struct ctx *ctxptr, char *nick, const char *text) {
@@ -92,16 +93,20 @@ void addmessage(struct ctx *ctxptr, char *nick, const char *text) {
} }
} }
void ev_talkinchan(irc_session_t *session, const char *event, const char *origin, const char **params, unsigned int count) { void ev_talkinchan(irc_session_t *session, const char *event,
const char *origin, const char **params,
unsigned int count) {
char nickname[64]; char nickname[64];
struct ctx *ctxptr = (struct ctx *)irc_get_ctx(session); struct ctx *ctxptr = (struct ctx *)irc_get_ctx(session);
irc_target_get_nick(origin, nickname, sizeof(nickname)); irc_target_get_nick(origin, nickname, sizeof(nickname));
addmessage(ctxptr, nickname, params[1]); addmessage(ctxptr, nickname, params[1]);
if(session || event || count) {} //fix gcc warnings if (session || event || count) {
} // fix gcc warnings
} }
void ev_num(irc_session_t *session, unsigned int event, const char *origin, const char **params, unsigned int count) { void ev_num(irc_session_t *session, unsigned int event, const char *origin,
const char **params, unsigned int count) {
char attachment[4] = "_00"; char attachment[4] = "_00";
if (event == 433) { // nick in use if (event == 433) { // nick in use
@@ -113,10 +118,12 @@ void ev_num(irc_session_t *session, unsigned int event, const char *origin, cons
irc_cmd_nick(session, newnick); irc_cmd_nick(session, newnick);
free(newnick); free(newnick);
} }
if(origin || count) {} //fix gcc warnings if (origin || count) {
} // fix gcc warnings
} }
#define IRCSYNTAX "The correct syntax is ${irc server(:port) #channel (max_msg_lines)}" #define IRCSYNTAX \
"The correct syntax is ${irc server(:port) #channel (max_msg_lines)}"
#define IRCPORT 6667 #define IRCPORT 6667
#define IRCNICK "conky" #define IRCNICK "conky"
#define IRCSERVERPASS NULL #define IRCSERVERPASS NULL
@@ -152,18 +159,19 @@ void *ircclient(void *ptr) {
strport = strtok(NULL, ":"); strport = strtok(NULL, ":");
if (strport) { if (strport) {
port = strtol(strport, NULL, 10); port = strtol(strport, NULL, 10);
if(port < 1 || port > 65535) if (port < 1 || port > 65535) port = IRCPORT;
port = IRCPORT;
} else { } else {
port = IRCPORT; port = IRCPORT;
} }
int err = irc_connect(ircobj->session, server, port, IRCSERVERPASS, IRCNICK, IRCUSER, IRCREAL); int err = irc_connect(ircobj->session, server, port, IRCSERVERPASS, IRCNICK,
IRCUSER, IRCREAL);
if (err != 0) { if (err != 0) {
err = irc_errno(ircobj->session); err = irc_errno(ircobj->session);
} }
#ifdef BUILD_IPV6 #ifdef BUILD_IPV6
if (err == LIBIRC_ERR_RESOLV) { if (err == LIBIRC_ERR_RESOLV) {
err = irc_connect6(ircobj->session, server, port, IRCSERVERPASS, IRCNICK, IRCUSER, IRCREAL); err = irc_connect6(ircobj->session, server, port, IRCSERVERPASS, IRCNICK,
IRCUSER, IRCREAL);
if (err != 0) { if (err != 0) {
err = irc_errno(ircobj->session); err = irc_errno(ircobj->session);
} }

View File

@@ -1,11 +1,10 @@
/* -*- mode: c++; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*- /*
* vim: ts=4 sw=4 noet ai cindent syntax=cpp
* *
* Conky, a system monitor, based on torsmo * Conky, a system monitor, based on torsmo
* *
* Please see COPYING for details * Please see COPYING for details
* *
* Copyright (c) 2005-2012 Brenden Matthews, Philip Kovacs, et. al. * Copyright (c) 2005-2018 Brenden Matthews, Philip Kovacs, et. al.
* (see AUTHORS) * (see AUTHORS)
* All rights reserved. * All rights reserved.
* *

View File

@@ -1,5 +1,4 @@
/* -*- mode: c++; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*- /*
* vim: ts=4 sw=4 noet ai cindent syntax=cpp
* *
* Conky, a system monitor, based on torsmo * Conky, a system monitor, based on torsmo
* *
@@ -10,7 +9,7 @@
* Please see COPYING for details * Please see COPYING for details
* *
* Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen * Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
* Copyright (c) 2005-2012 Brenden Matthews, Philip Kovacs, et. al. * Copyright (c) 2005-2018 Brenden Matthews, Philip Kovacs, et. al.
* (see AUTHORS) * (see AUTHORS)
* All rights reserved. * All rights reserved.
* *
@@ -28,16 +27,16 @@
* *
*/ */
#include "conky.h"
#include "config.h"
#include "common.h"
#include "text_object.h"
#include "logging.h"
#include <ctype.h> #include <ctype.h>
#include <string.h> #include <string.h>
#include <systemd/sd-journal.h>
#include <unistd.h> #include <unistd.h>
#include <memory> #include <memory>
#include <systemd/sd-journal.h> #include "common.h"
#include "config.h"
#include "conky.h"
#include "logging.h"
#include "text_object.h"
#define MAX_JOURNAL_LINES 200 #define MAX_JOURNAL_LINES 200
@@ -45,20 +44,17 @@ struct journal {
int wantedlines; int wantedlines;
int flags; int flags;
journal() journal() : wantedlines(0), flags(SD_JOURNAL_LOCAL_ONLY) {}
: wantedlines(0), flags(SD_JOURNAL_LOCAL_ONLY)
{}
}; };
void free_journal(struct text_object *obj) void free_journal(struct text_object *obj) {
{
struct journal *j = (struct journal *)obj->data.opaque; struct journal *j = (struct journal *)obj->data.opaque;
obj->data.opaque = NULL; obj->data.opaque = NULL;
delete j; delete j;
} }
void init_journal(const char* type, const char* arg, struct text_object *obj, void* free_at_crash) { void init_journal(const char *type, const char *arg, struct text_object *obj,
void *free_at_crash) {
unsigned int args; unsigned int args;
struct journal *j = new journal; struct journal *j = new journal;
@@ -68,7 +64,10 @@ void init_journal(const char* type, const char* arg, struct text_object *obj, vo
args = sscanf(arg, "%d %6s", &j->wantedlines, tmp.get()); args = sscanf(arg, "%d %6s", &j->wantedlines, tmp.get());
if (args < 1 || args > 2) { if (args < 1 || args > 2) {
free_journal(obj); free_journal(obj);
CRIT_ERR(obj, free_at_crash, "%s a number of lines as 1st argument and optionally a journal type as 2nd argument", type); CRIT_ERR(obj, free_at_crash,
"%s a number of lines as 1st argument and optionally a journal "
"type as 2nd argument",
type);
} }
if (j->wantedlines > 0 && j->wantedlines <= MAX_JOURNAL_LINES) { if (j->wantedlines > 0 && j->wantedlines <= MAX_JOURNAL_LINES) {
if (args > 1) { if (args > 1) {
@@ -78,35 +77,36 @@ void init_journal(const char* type, const char* arg, struct text_object *obj, vo
j->flags |= SD_JOURNAL_CURRENT_USER; j->flags |= SD_JOURNAL_CURRENT_USER;
} else { } else {
free_journal(obj); free_journal(obj);
CRIT_ERR(obj, free_at_crash, "invalid arg for %s, type must be 'system' or 'user'", type); CRIT_ERR(obj, free_at_crash,
"invalid arg for %s, type must be 'system' or 'user'", type);
} }
} }
} else { } else {
free_journal(obj); free_journal(obj);
CRIT_ERR(obj, free_at_crash, "invalid arg for %s, number of lines must be between 1 and %d", type, MAX_JOURNAL_LINES); CRIT_ERR(obj, free_at_crash,
"invalid arg for %s, number of lines must be between 1 and %d",
type, MAX_JOURNAL_LINES);
} }
obj->data.opaque = j; obj->data.opaque = j;
} }
static int print_field(sd_journal *jh, const char *field, char spacer, size_t *read, char *p, int p_max_size) { static int print_field(sd_journal *jh, const char *field, char spacer,
size_t *read, char *p, int p_max_size) {
const void *get; const void *get;
size_t length; size_t length;
size_t fieldlen = strlen(field) + 1; size_t fieldlen = strlen(field) + 1;
int ret = sd_journal_get_data(jh, field, &get, &length); int ret = sd_journal_get_data(jh, field, &get, &length);
if(ret == -ENOENT) if (ret == -ENOENT) goto out;
goto out;
if(ret < 0 || length + *read > p_max_size) if (ret < 0 || length + *read > p_max_size) return -1;
return -1;
memcpy(p + *read, (const char *)get + fieldlen, length - fieldlen); memcpy(p + *read, (const char *)get + fieldlen, length - fieldlen);
*read += length - fieldlen; *read += length - fieldlen;
out: out:
if(spacer) if (spacer) p[(*read)++] = spacer;
p[(*read)++] = spacer;
return length ? length - fieldlen : 0; return length ? length - fieldlen : 0;
} }
@@ -123,11 +123,9 @@ void print_journal(struct text_object *obj, char *p, int p_max_size) {
NORM_ERR("unable to open journal"); NORM_ERR("unable to open journal");
goto out; goto out;
} }
if (!j) if (!j) return;
return;
if(sd_journal_seek_tail(jh) < 0) if (sd_journal_seek_tail(jh) < 0) {
{
NORM_ERR("unable to seek to end of journal"); NORM_ERR("unable to seek to end of journal");
goto out; goto out;
} }
@@ -137,35 +135,31 @@ void print_journal(struct text_object *obj, char *p, int p_max_size) {
} }
do { do {
if(sd_journal_get_realtime_usec(jh, &timestamp) < 0) if (sd_journal_get_realtime_usec(jh, &timestamp) < 0) break;
break;
time = timestamp / 1000000; time = timestamp / 1000000;
tm = localtime(&time); tm = localtime(&time);
if((length = strftime(p+read, p_max_size-read, "%b %d %H:%M:%S", tm)) <= 0) if ((length =
strftime(p + read, p_max_size - read, "%b %d %H:%M:%S", tm)) <= 0)
break; break;
read += length; read += length;
p[read++] = ' '; p[read++] = ' ';
if(print_field(jh, "_HOSTNAME", ' ', &read, p, p_max_size) < 0) if (print_field(jh, "_HOSTNAME", ' ', &read, p, p_max_size) < 0) break;
break;
if (print_field(jh, "SYSLOG_IDENTIFIER", '[', &read, p, p_max_size) < 0) if (print_field(jh, "SYSLOG_IDENTIFIER", '[', &read, p, p_max_size) < 0)
break; break;
if(print_field(jh, "_PID", ']', &read, p, p_max_size) < 0) if (print_field(jh, "_PID", ']', &read, p, p_max_size) < 0) break;
break;
p[read++] = ':'; p[read++] = ':';
p[read++] = ' '; p[read++] = ' ';
if(print_field(jh, "MESSAGE", '\n', &read, p, p_max_size) < 0) if (print_field(jh, "MESSAGE", '\n', &read, p, p_max_size) < 0) break;
break;
} while (sd_journal_next(jh)); } while (sd_journal_next(jh));
out: out:
if(jh) if (jh) sd_journal_close(jh);
sd_journal_close(jh);
p[read] = '\0'; p[read] = '\0';
return; return;
} }

View File

@@ -1,5 +1,4 @@
/* -*- mode: c++; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*- /*
* vim: ts=4 sw=4 noet ai cindent syntax=cpp
* *
* Conky, a system monitor, based on torsmo * Conky, a system monitor, based on torsmo
* *
@@ -10,7 +9,7 @@
* Please see COPYING for details * Please see COPYING for details
* *
* Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen * Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
* Copyright (c) 2005-2012 Brenden Matthews, Philip Kovacs, et. al. * Copyright (c) 2005-2018 Brenden Matthews, Philip Kovacs, et. al.
* (see AUTHORS) * (see AUTHORS)
* All rights reserved. * All rights reserved.
* *

File diff suppressed because it is too large Load Diff

View File

@@ -1,5 +1,4 @@
/* -*- mode: c; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*- /*
* vim: ts=4 sw=4 noet ai cindent syntax=c
* *
* libmpdclient * libmpdclient
* (c)2003-2006 by Warren Dukes (warren.dukes@gmail.com) * (c)2003-2006 by Warren Dukes (warren.dukes@gmail.com)
@@ -39,8 +38,8 @@
#define __W32API_USE_DLLIMPORT__ 1 #define __W32API_USE_DLLIMPORT__ 1
#endif #endif
#include <sys/time.h>
#include <stdarg.h> #include <stdarg.h>
#include <sys/time.h>
#define MPD_BUFFER_MAX_LENGTH 50000 #define MPD_BUFFER_MAX_LENGTH 50000
#define MPD_ERRORSTR_MAX_LENGTH 1000 #define MPD_ERRORSTR_MAX_LENGTH 1000
#define MPD_WELCOME_MESSAGE "OK MPD " #define MPD_WELCOME_MESSAGE "OK MPD "

View File

@@ -1,5 +1,4 @@
/* -*- mode: c++; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*- /*
* vim: ts=4 sw=4 noet ai cindent syntax=cpp
* *
* libtcp-portmon.c: tcp port monitoring library. * libtcp-portmon.c: tcp port monitoring library.
* *
@@ -30,8 +29,8 @@
#include <cstdio> #include <cstdio>
#include <cstring> #include <cstring>
#include <vector>
#include <unordered_map> #include <unordered_map>
#include <vector>
/* ------------------------------------------------------------------- /* -------------------------------------------------------------------
* IMPLEMENTATION INTERFACE * IMPLEMENTATION INTERFACE
@@ -55,8 +54,7 @@ namespace {
/* hash function for tcp connections */ /* hash function for tcp connections */
struct tcp_connection_hash { struct tcp_connection_hash {
size_t operator()(const tcp_connection_t &a) const size_t operator()(const tcp_connection_t &a) const {
{
size_t hash = 0; size_t hash = 0;
size_t i; size_t i;
@@ -72,11 +70,11 @@ namespace {
}; };
/* comparison function for tcp connections */ /* comparison function for tcp connections */
bool operator==(const tcp_connection_t &a, const tcp_connection_t &b) bool operator==(const tcp_connection_t &a, const tcp_connection_t &b) {
{
return a.local_port == b.local_port && a.remote_port == b.remote_port && return a.local_port == b.local_port && a.remote_port == b.remote_port &&
!std::memcmp(&a.local_addr, &b.local_addr, sizeof(a.local_addr)) && !std::memcmp(&a.local_addr, &b.local_addr, sizeof(a.local_addr)) &&
! std::memcmp(&a.remote_addr.s6_addr, &b.remote_addr, sizeof(a.remote_addr)); !std::memcmp(&a.remote_addr.s6_addr, &b.remote_addr,
sizeof(a.remote_addr));
} }
/* ------------------------------------------------------------------------ /* ------------------------------------------------------------------------
@@ -85,24 +83,24 @@ namespace {
* The second parameter provides the mechanism for removing connections if * The second parameter provides the mechanism for removing connections if
* they are not seen again in subsequent update cycles. * they are not seen again in subsequent update cycles.
* ------------------------------------------------------------------------ */ * ------------------------------------------------------------------------ */
typedef std::unordered_map<tcp_connection_t, int, tcp_connection_hash> connection_hash_t; typedef std::unordered_map<tcp_connection_t, int, tcp_connection_hash>
connection_hash_t;
/* start and end of port monitor range. Set start=end to monitor a single port */ /* start and end of port monitor range. Set start=end to monitor a single port
*/
typedef std::pair<in_port_t, in_port_t> port_range_t; typedef std::pair<in_port_t, in_port_t> port_range_t;
/* hash function for port ranges */ /* hash function for port ranges */
struct port_range_hash { struct port_range_hash {
size_t operator()(const port_range_t &a) const size_t operator()(const port_range_t &a) const {
{
return a.first * 47 + a.second; return a.first * 47 + a.second;
} }
}; };
typedef std::unordered_map<port_range_t, typedef std::unordered_map<port_range_t, tcp_port_monitor_t, port_range_hash>
tcp_port_monitor_t, monitor_hash_t;
port_range_hash> monitor_hash_t;
} } // namespace
/* -------------- /* --------------
* A port monitor * A port monitor
@@ -115,27 +113,29 @@ struct _tcp_port_monitor_t {
std::vector<const tcp_connection_t *> p_peek; std::vector<const tcp_connection_t *> p_peek;
_tcp_port_monitor_t(int max_connections) _tcp_port_monitor_t(int max_connections)
: hash(), p_peek(max_connections, static_cast<const tcp_connection_t *>(NULL)) : hash(),
{ } p_peek(max_connections, static_cast<const tcp_connection_t *>(NULL)) {}
_tcp_port_monitor_t(const _tcp_port_monitor_t &other) _tcp_port_monitor_t(const _tcp_port_monitor_t &other)
: hash(other.hash), p_peek(other.p_peek.size(), static_cast<const tcp_connection_t *>(NULL)) : hash(other.hash),
{ p_peek(other.p_peek.size(),
static_cast<const tcp_connection_t *>(NULL)) {
// we must rebuild the peek table because the pointers are no longer valid // we must rebuild the peek table because the pointers are no longer valid
rebuild_peek_table(); rebuild_peek_table();
} }
void rebuild_peek_table() void rebuild_peek_table() {
{
/* Run through the monitor's connections and rebuild the peek table of /* Run through the monitor's connections and rebuild the peek table of
* connection pointers. This is done so peeking into the monitor can be * connection pointers. This is done so peeking into the monitor can be
* done in O(1) time instead of O(n) time for each peek. */ * done in O(1) time instead of O(n) time for each peek. */
/* zero out the peek array */ /* zero out the peek array */
std::fill(p_peek.begin(), p_peek.end(), static_cast<tcp_connection_t *>(NULL)); std::fill(p_peek.begin(), p_peek.end(),
static_cast<tcp_connection_t *>(NULL));
size_t i = 0; size_t i = 0;
for (connection_hash_t::iterator j = hash.begin(); j != hash.end(); ++j, ++i ) { for (connection_hash_t::iterator j = hash.begin(); j != hash.end();
++j, ++i) {
p_peek[i] = &j->first; p_peek[i] = &j->first;
} }
} }
@@ -157,11 +157,10 @@ namespace {
/* --------------------------------------- /* ---------------------------------------
* A port monitor utility function typedef * A port monitor utility function typedef
* --------------------------------------- */ * --------------------------------------- */
typedef void (*tcp_port_monitor_function_ptr_t)(monitor_hash_t::value_type &monitor, typedef void (*tcp_port_monitor_function_ptr_t)(
void *p_void); monitor_hash_t::value_type &monitor, void *p_void);
void age_tcp_port_monitor(monitor_hash_t::value_type &monitor, void *p_void) void age_tcp_port_monitor(monitor_hash_t::value_type &monitor, void *p_void) {
{
/* Run through the monitor's connections and decrement the age variable. /* Run through the monitor's connections and decrement the age variable.
* If the age goes negative, we remove the connection from the monitor. * If the age goes negative, we remove the connection from the monitor.
* Function takes O(n) time on the number of connections. */ * Function takes O(n) time on the number of connections. */
@@ -172,7 +171,6 @@ namespace {
for (connection_hash_t::iterator i = monitor.second.hash.begin(); for (connection_hash_t::iterator i = monitor.second.hash.begin();
i != monitor.second.hash.end();) { i != monitor.second.hash.end();) {
if (--i->second >= 0) if (--i->second >= 0)
++i; ++i;
else { else {
@@ -184,8 +182,7 @@ namespace {
} }
void rebuild_tcp_port_monitor_peek_table(monitor_hash_t::value_type &monitor, void rebuild_tcp_port_monitor_peek_table(monitor_hash_t::value_type &monitor,
void *p_void) void *p_void) {
{
if (p_void) { /* p_void should be NULL in this context */ if (p_void) { /* p_void should be NULL in this context */
return; return;
} }
@@ -194,8 +191,7 @@ namespace {
} }
void show_connection_to_tcp_port_monitor(monitor_hash_t::value_type &monitor, void show_connection_to_tcp_port_monitor(monitor_hash_t::value_type &monitor,
void *p_void) void *p_void) {
{
/* The monitor gets to look at each connection to see if it falls within /* The monitor gets to look at each connection to see if it falls within
* the monitor's port range of interest. Connections of interest are first * the monitor's port range of interest. Connections of interest are first
* looked up in the hash to see if they are already there. If they are, we * looked up in the hash to see if they are already there. If they are, we
@@ -217,8 +213,8 @@ namespace {
/* inspect the local port number of the connection to see if we're /* inspect the local port number of the connection to see if we're
* interested. */ * interested. */
if ((monitor.first.first <= p_connection->local_port) if ((monitor.first.first <= p_connection->local_port) &&
&& (p_connection->local_port <= monitor.first.second)) { (p_connection->local_port <= monitor.first.second)) {
/* the connection is in the range of the monitor. */ /* the connection is in the range of the monitor. */
/* first check the hash to see if the connection is already there. */ /* first check the hash to see if the connection is already there. */
@@ -233,9 +229,8 @@ namespace {
/* Connection is not yet in the hash. /* Connection is not yet in the hash.
* Add it if max_connections not exceeded. */ * Add it if max_connections not exceeded. */
if (monitor.second.hash.size() < monitor.second.p_peek.size()) { if (monitor.second.hash.size() < monitor.second.p_peek.size()) {
monitor.second.hash.insert(connection_hash_t::value_type(
monitor.second.hash.insert(connection_hash_t::value_type(*p_connection, *p_connection, TCP_CONNECTION_STARTING_AGE));
TCP_CONNECTION_STARTING_AGE));
} }
} }
} }
@@ -246,8 +241,7 @@ namespace {
* ------------------------------------------------------------------------ */ * ------------------------------------------------------------------------ */
void for_each_tcp_port_monitor_in_collection( void for_each_tcp_port_monitor_in_collection(
tcp_port_monitor_collection_t *p_collection, tcp_port_monitor_collection_t *p_collection,
tcp_port_monitor_function_ptr_t p_function, void *p_function_args) tcp_port_monitor_function_ptr_t p_function, void *p_function_args) {
{
if (!p_collection || !p_function) { if (!p_collection || !p_function) {
return; return;
} }
@@ -260,11 +254,8 @@ namespace {
} }
} }
const unsigned char prefix_4on6[] = { const unsigned char prefix_4on6[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff};
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0xff, 0xff
};
union sockaddr_in46 { union sockaddr_in46 {
struct sockaddr_in sa4; struct sockaddr_in sa4;
@@ -273,15 +264,14 @@ namespace {
}; };
/* checks whether the address is a IPv4-mapped IPv6 address */ /* checks whether the address is a IPv4-mapped IPv6 address */
bool is_4on6(const struct in6_addr *addr) bool is_4on6(const struct in6_addr *addr) {
{
return !std::memcmp(&addr->s6_addr, prefix_4on6, sizeof(prefix_4on6)); return !std::memcmp(&addr->s6_addr, prefix_4on6, sizeof(prefix_4on6));
} }
/* converts the address to appropriate textual representation (IPv6, IPv4 or
/* converts the address to appropriate textual representation (IPv6, IPv4 or fqdn) */ * fqdn) */
void print_host(char *p_buffer, size_t buffer_size, const struct in6_addr *addr, int fqdn) void print_host(char *p_buffer, size_t buffer_size, const struct in6_addr *addr,
{ int fqdn) {
union sockaddr_in46 sa; union sockaddr_in46 sa;
socklen_t slen; socklen_t slen;
@@ -297,12 +287,13 @@ namespace {
slen = sizeof(sa.sa6); slen = sizeof(sa.sa6);
} }
getnameinfo(&sa.sa, slen, p_buffer, buffer_size, NULL, 0, fqdn?0:NI_NUMERICHOST); getnameinfo(&sa.sa, slen, p_buffer, buffer_size, NULL, 0,
fqdn ? 0 : NI_NUMERICHOST);
} }
/* converts the textual representation of an IPv4 or IPv6 address to struct in6_addr */ /* converts the textual representation of an IPv4 or IPv6 address to struct
void string_to_addr(struct in6_addr *addr, const char *p_buffer) * in6_addr */
{ void string_to_addr(struct in6_addr *addr, const char *p_buffer) {
size_t i; size_t i;
if (std::strlen(p_buffer) < 32) { // IPv4 address if (std::strlen(p_buffer) < 32) { // IPv4 address
@@ -318,8 +309,8 @@ namespace {
} }
/* adds connections from file to the collection */ /* adds connections from file to the collection */
void process_file(tcp_port_monitor_collection_t *p_collection, const char *file) void process_file(tcp_port_monitor_collection_t *p_collection,
{ const char *file) {
std::FILE *fp; std::FILE *fp;
char buf[256]; char buf[256];
char local_addr[40]; char local_addr[40];
@@ -339,13 +330,12 @@ namespace {
/* read all tcp connections */ /* read all tcp connections */
while (std::fgets(buf, sizeof(buf), fp) != NULL) { while (std::fgets(buf, sizeof(buf), fp) != NULL) {
if (std::sscanf(buf, if (std::sscanf(buf,
"%*d: %39[0-9a-fA-F]:%hx %39[0-9a-fA-F]:%hx %lx %*x:%*x %*x:%*x %*x %lu %*d %lu", "%*d: %39[0-9a-fA-F]:%hx %39[0-9a-fA-F]:%hx %lx %*x:%*x "
local_addr, &conn.local_port, "%*x:%*x %*x %lu %*d %lu",
remote_addr, &conn.remote_port, local_addr, &conn.local_port, remote_addr,
(unsigned long *) &state, (unsigned long *) &uid, &conn.remote_port, (unsigned long *)&state,
(unsigned long *) &inode) != 7) { (unsigned long *)&uid, (unsigned long *)&inode) != 7) {
std::fprintf(stderr, "%s: bad file format\n", file); std::fprintf(stderr, "%s: bad file format\n", file);
} }
/** TCP_ESTABLISHED equals 1, but is not (always??) included **/ /** TCP_ESTABLISHED equals 1, but is not (always??) included **/
@@ -358,13 +348,13 @@ namespace {
string_to_addr(&conn.remote_addr, remote_addr); string_to_addr(&conn.remote_addr, remote_addr);
/* show the connection to each port monitor. */ /* show the connection to each port monitor. */
for_each_tcp_port_monitor_in_collection(p_collection, for_each_tcp_port_monitor_in_collection(
&show_connection_to_tcp_port_monitor, (void *) &conn); p_collection, &show_connection_to_tcp_port_monitor, (void *)&conn);
} }
std::fclose(fp); std::fclose(fp);
} }
} } // namespace
/* ---------------------------------------------------------------------- /* ----------------------------------------------------------------------
* CLIENT INTERFACE * CLIENT INTERFACE
@@ -381,8 +371,8 @@ namespace {
* The requested monitor value is copied into a client-supplied char buffer. * The requested monitor value is copied into a client-supplied char buffer.
* Returns 0 on success, -1 otherwise. */ * Returns 0 on success, -1 otherwise. */
int peek_tcp_port_monitor(const tcp_port_monitor_t *p_monitor, int item, int peek_tcp_port_monitor(const tcp_port_monitor_t *p_monitor, int item,
int connection_index, char *p_buffer, size_t buffer_size) int connection_index, char *p_buffer,
{ size_t buffer_size) {
struct sockaddr_in sa; struct sockaddr_in sa;
if (!p_monitor || !p_buffer || connection_index < 0) { if (!p_monitor || !p_buffer || connection_index < 0) {
@@ -396,25 +386,28 @@ int peek_tcp_port_monitor(const tcp_port_monitor_t *p_monitor, int item,
/* if the connection index is out of range, we simply return with no error, /* if the connection index is out of range, we simply return with no error,
* having first cleared the client-supplied buffer. */ * having first cleared the client-supplied buffer. */
if ( (item != COUNT) && (connection_index >= ssize_t(p_monitor->hash.size())) ) { if ((item != COUNT) &&
(connection_index >= ssize_t(p_monitor->hash.size()))) {
return 0; return 0;
} }
switch (item) { switch (item) {
case COUNT: case COUNT:
std::snprintf(p_buffer, buffer_size, "%u", unsigned(p_monitor->hash.size())); std::snprintf(p_buffer, buffer_size, "%u",
unsigned(p_monitor->hash.size()));
break; break;
case REMOTEIP: case REMOTEIP:
print_host(p_buffer, buffer_size, &p_monitor->p_peek[connection_index]->remote_addr, 0); print_host(p_buffer, buffer_size,
&p_monitor->p_peek[connection_index]->remote_addr, 0);
break; break;
case REMOTEHOST: case REMOTEHOST:
print_host(p_buffer, buffer_size, &p_monitor->p_peek[connection_index]->remote_addr, 1); print_host(p_buffer, buffer_size,
&p_monitor->p_peek[connection_index]->remote_addr, 1);
break; break;
case REMOTEPORT: case REMOTEPORT:
@@ -426,17 +419,20 @@ int peek_tcp_port_monitor(const tcp_port_monitor_t *p_monitor, int item,
case REMOTESERVICE: case REMOTESERVICE:
sa.sin_port = htons(p_monitor->p_peek[connection_index]->remote_port); sa.sin_port = htons(p_monitor->p_peek[connection_index]->remote_port);
getnameinfo((struct sockaddr *) &sa, sizeof(struct sockaddr_in), NULL, 0, p_buffer, buffer_size, NI_NUMERICHOST); getnameinfo((struct sockaddr *)&sa, sizeof(struct sockaddr_in), NULL, 0,
p_buffer, buffer_size, NI_NUMERICHOST);
break; break;
case LOCALIP: case LOCALIP:
print_host(p_buffer, buffer_size, &p_monitor->p_peek[connection_index]->local_addr, 0); print_host(p_buffer, buffer_size,
&p_monitor->p_peek[connection_index]->local_addr, 0);
break; break;
case LOCALHOST: case LOCALHOST:
print_host(p_buffer, buffer_size, &p_monitor->p_peek[connection_index]->local_addr, 1); print_host(p_buffer, buffer_size,
&p_monitor->p_peek[connection_index]->local_addr, 1);
break; break;
case LOCALPORT: case LOCALPORT:
@@ -448,7 +444,8 @@ int peek_tcp_port_monitor(const tcp_port_monitor_t *p_monitor, int item,
case LOCALSERVICE: case LOCALSERVICE:
sa.sin_port = htons(p_monitor->p_peek[connection_index]->local_port); sa.sin_port = htons(p_monitor->p_peek[connection_index]->local_port);
getnameinfo((struct sockaddr *) &sa, sizeof(struct sockaddr_in), NULL, 0, p_buffer, buffer_size, NI_NUMERICHOST); getnameinfo((struct sockaddr *)&sa, sizeof(struct sockaddr_in), NULL, 0,
p_buffer, buffer_size, NI_NUMERICHOST);
break; break;
default: default:
@@ -463,23 +460,20 @@ int peek_tcp_port_monitor(const tcp_port_monitor_t *p_monitor, int item,
* -------------------------------- */ * -------------------------------- */
/* Create a monitor collection. Do this one first. */ /* Create a monitor collection. Do this one first. */
tcp_port_monitor_collection_t *create_tcp_port_monitor_collection(void) tcp_port_monitor_collection_t *create_tcp_port_monitor_collection(void) {
{
return new tcp_port_monitor_collection_t(); return new tcp_port_monitor_collection_t();
} }
/* Destroy the monitor collection (and the monitors inside). /* Destroy the monitor collection (and the monitors inside).
* Do this one last. */ * Do this one last. */
void destroy_tcp_port_monitor_collection( void destroy_tcp_port_monitor_collection(
tcp_port_monitor_collection_t *p_collection) tcp_port_monitor_collection_t *p_collection) {
{
delete p_collection; delete p_collection;
} }
/* Updates the tcp statistics for all monitors within a collection */ /* Updates the tcp statistics for all monitors within a collection */
void update_tcp_port_monitor_collection( void update_tcp_port_monitor_collection(
tcp_port_monitor_collection_t *p_collection) tcp_port_monitor_collection_t *p_collection) {
{
if (!p_collection) { if (!p_collection) {
return; return;
} }
@@ -488,45 +482,41 @@ void update_tcp_port_monitor_collection(
process_file(p_collection, "/proc/net/tcp6"); process_file(p_collection, "/proc/net/tcp6");
/* age the connections in all port monitors. */ /* age the connections in all port monitors. */
for_each_tcp_port_monitor_in_collection(p_collection, for_each_tcp_port_monitor_in_collection(p_collection, &age_tcp_port_monitor,
&age_tcp_port_monitor, NULL); NULL);
/* rebuild the connection peek tables of all monitors /* rebuild the connection peek tables of all monitors
* so clients can peek in O(1) time */ * so clients can peek in O(1) time */
for_each_tcp_port_monitor_in_collection(p_collection, for_each_tcp_port_monitor_in_collection(
&rebuild_tcp_port_monitor_peek_table, NULL); p_collection, &rebuild_tcp_port_monitor_peek_table, NULL);
} }
/* Creation of reduntant monitors is silently ignored */ /* Creation of reduntant monitors is silently ignored */
int insert_new_tcp_port_monitor_into_collection( int insert_new_tcp_port_monitor_into_collection(
tcp_port_monitor_collection_t *p_collection, in_port_t port_range_begin, tcp_port_monitor_collection_t *p_collection, in_port_t port_range_begin,
in_port_t port_range_end, tcp_port_monitor_args_t *p_creation_args) in_port_t port_range_end, tcp_port_monitor_args_t *p_creation_args) {
{
if (!p_collection) { if (!p_collection) {
return -1; return -1;
} }
p_collection->hash.insert(monitor_hash_t::value_type( p_collection->hash.insert(monitor_hash_t::value_type(
port_range_t(port_range_begin, port_range_end), port_range_t(port_range_begin, port_range_end),
tcp_port_monitor_t(p_creation_args->max_port_monitor_connections) tcp_port_monitor_t(p_creation_args->max_port_monitor_connections)));
) );
return 0; return 0;
} }
/* Clients need a way to find monitors */ /* Clients need a way to find monitors */
tcp_port_monitor_t *find_tcp_port_monitor( tcp_port_monitor_t *find_tcp_port_monitor(
tcp_port_monitor_collection_t *p_collection, tcp_port_monitor_collection_t *p_collection, in_port_t port_range_begin,
in_port_t port_range_begin, in_port_t port_range_end) in_port_t port_range_end) {
{
if (!p_collection) { if (!p_collection) {
return NULL; return NULL;
} }
/* is monitor in hash? */ /* is monitor in hash? */
monitor_hash_t::iterator i = p_collection->hash.find( monitor_hash_t::iterator i =
port_range_t(port_range_begin, port_range_end) ); p_collection->hash.find(port_range_t(port_range_begin, port_range_end));
return i == p_collection->hash.end() ? NULL : &i->second; return i == p_collection->hash.end() ? NULL : &i->second;
} }

View File

@@ -1,5 +1,4 @@
/* -*- mode: c++; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*- /*
* vim: ts=4 sw=4 noet ai cindent syntax=cpp
* *
* libtcp-portmon.h: tcp port monitoring library. * libtcp-portmon.h: tcp port monitoring library.
* *
@@ -23,8 +22,8 @@
#ifndef LIBTCP_PORTMON_H #ifndef LIBTCP_PORTMON_H
#define LIBTCP_PORTMON_H #define LIBTCP_PORTMON_H
#include <sys/types.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <sys/types.h>
#include <arpa/inet.h> #include <arpa/inet.h>
#include <netinet/in.h> #include <netinet/in.h>
@@ -94,7 +93,8 @@ typedef struct _tcp_port_monitor_args_t {
* the indicated port monitor. * the indicated port monitor.
* The requested monitor value is copied into a client-supplied char buffer. * The requested monitor value is copied into a client-supplied char buffer.
* Returns 0 on success, -1 otherwise. */ * Returns 0 on success, -1 otherwise. */
int peek_tcp_port_monitor(const tcp_port_monitor_t *p_monitor, int peek_tcp_port_monitor(
const tcp_port_monitor_t *p_monitor,
/* (item of interest, from tcp_port_monitor_peekables enum) */ /* (item of interest, from tcp_port_monitor_peekables enum) */
int item, int item,
/* (0 to number of connections in monitor - 1) */ /* (0 to number of connections in monitor - 1) */
@@ -128,7 +128,7 @@ int insert_new_tcp_port_monitor_into_collection(
/* Clients need a way to find monitors */ /* Clients need a way to find monitors */
tcp_port_monitor_t *find_tcp_port_monitor( tcp_port_monitor_t *find_tcp_port_monitor(
tcp_port_monitor_collection_t *p_collection, tcp_port_monitor_collection_t *p_collection, in_port_t port_range_begin,
in_port_t port_range_begin, in_port_t port_range_end); in_port_t port_range_end);
#endif #endif

File diff suppressed because it is too large Load Diff

View File

@@ -1,11 +1,10 @@
/* -*- mode: c++; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*- /*
* vim: ts=4 sw=4 noet ai cindent syntax=cpp
* *
* Conky, a system monitor, based on torsmo * Conky, a system monitor, based on torsmo
* *
* Please see COPYING for details * Please see COPYING for details
* *
* Copyright (c) 2005-2012 Brenden Matthews, Philip Kovacs, et. al. * Copyright (c) 2005-2018 Brenden Matthews, Philip Kovacs, et. al.
* (see AUTHORS) * (see AUTHORS)
* All rights reserved. * All rights reserved.
* *

Some files were not shown because too many files have changed in this diff Show More