mirror of
https://github.com/Llewellynvdm/conky.git
synced 2024-12-24 11:55:43 +00:00
Make GitLab build work with clang checks.
This commit is contained in:
parent
0ea4559f30
commit
90673cf161
@ -17,7 +17,7 @@ AllowShortLoopsOnASingleLine: true
|
||||
AlwaysBreakAfterDefinitionReturnType: None
|
||||
AlwaysBreakAfterReturnType: None
|
||||
AlwaysBreakBeforeMultilineStrings: true
|
||||
AlwaysBreakTemplateDeclarations: true
|
||||
AlwaysBreakTemplateDeclarations: Yes
|
||||
BinPackArguments: true
|
||||
BinPackParameters: true
|
||||
BraceWrapping:
|
||||
@ -39,6 +39,7 @@ BraceWrapping:
|
||||
BreakBeforeBinaryOperators: None
|
||||
BreakBeforeBraces: Attach
|
||||
BreakBeforeInheritanceComma: false
|
||||
BreakInheritanceList: BeforeColon
|
||||
BreakBeforeTernaryOperators: true
|
||||
BreakConstructorInitializersBeforeComma: false
|
||||
BreakConstructorInitializers: BeforeColon
|
||||
@ -81,6 +82,7 @@ MacroBlockBegin: ''
|
||||
MacroBlockEnd: ''
|
||||
MaxEmptyLinesToKeep: 1
|
||||
NamespaceIndentation: None
|
||||
ObjCBinPackProtocolList: Never
|
||||
ObjCBlockIndentWidth: 2
|
||||
ObjCSpaceAfterProperty: false
|
||||
ObjCSpaceBeforeProtocolList: false
|
||||
@ -89,12 +91,37 @@ PenaltyBreakBeforeFirstCallParameter: 1
|
||||
PenaltyBreakComment: 300
|
||||
PenaltyBreakFirstLessLess: 120
|
||||
PenaltyBreakString: 1000
|
||||
PenaltyBreakTemplateDeclaration: 10
|
||||
PenaltyExcessCharacter: 1000000
|
||||
PenaltyReturnTypeOnItsOwnLine: 200
|
||||
PointerAlignment: Left
|
||||
RawStringFormats:
|
||||
- Delimiter: pb
|
||||
Language: TextProto
|
||||
- Language: Cpp
|
||||
Delimiters:
|
||||
- cc
|
||||
- CC
|
||||
- cpp
|
||||
- Cpp
|
||||
- CPP
|
||||
- 'c++'
|
||||
- 'C++'
|
||||
CanonicalDelimiter: ''
|
||||
BasedOnStyle: google
|
||||
- Language: TextProto
|
||||
Delimiters:
|
||||
- pb
|
||||
- PB
|
||||
- proto
|
||||
- PROTO
|
||||
EnclosingFunctions:
|
||||
- EqualsProto
|
||||
- EquivToProto
|
||||
- PARSE_PARTIAL_TEXT_PROTO
|
||||
- PARSE_TEST_PROTO
|
||||
- PARSE_TEXT_PROTO
|
||||
- ParseTextOrDie
|
||||
- ParseTextProtoOrDie
|
||||
CanonicalDelimiter: ''
|
||||
BasedOnStyle: google
|
||||
ReflowComments: true
|
||||
SortIncludes: true
|
||||
@ -102,7 +129,11 @@ SortUsingDeclarations: true
|
||||
SpaceAfterCStyleCast: false
|
||||
SpaceAfterTemplateKeyword: true
|
||||
SpaceBeforeAssignmentOperators: true
|
||||
SpaceBeforeCpp11BracedList: false
|
||||
SpaceBeforeCtorInitializerColon: true
|
||||
SpaceBeforeInheritanceColon: true
|
||||
SpaceBeforeParens: ControlStatements
|
||||
SpaceBeforeRangeBasedForLoopColon: true
|
||||
SpaceInEmptyParentheses: false
|
||||
SpacesBeforeTrailingComments: 2
|
||||
SpacesInAngles: false
|
||||
|
52
.clang-tidy
Normal file
52
.clang-tidy
Normal file
@ -0,0 +1,52 @@
|
||||
---
|
||||
Checks: 'clang-diagnostic-*,clang-analyzer-*,google-*'
|
||||
WarningsAsErrors: ''
|
||||
HeaderFilterRegex: ''
|
||||
AnalyzeTemporaryDtors: false
|
||||
FormatStyle: none
|
||||
User: brenden
|
||||
CheckOptions:
|
||||
- key: google-build-namespaces.HeaderFileExtensions
|
||||
value: ',h,hh,hpp,hxx'
|
||||
- key: google-global-names-in-headers.HeaderFileExtensions
|
||||
value: ',h,hh,hpp,hxx'
|
||||
- key: google-readability-braces-around-statements.ShortStatementLines
|
||||
value: '1'
|
||||
- key: google-readability-function-size.BranchThreshold
|
||||
value: '4294967295'
|
||||
- key: google-readability-function-size.LineThreshold
|
||||
value: '4294967295'
|
||||
- key: google-readability-function-size.NestingThreshold
|
||||
value: '4294967295'
|
||||
- key: google-readability-function-size.ParameterThreshold
|
||||
value: '4294967295'
|
||||
- key: google-readability-function-size.StatementThreshold
|
||||
value: '800'
|
||||
- key: google-readability-function-size.VariableThreshold
|
||||
value: '4294967295'
|
||||
- key: google-readability-namespace-comments.ShortNamespaceLines
|
||||
value: '10'
|
||||
- key: google-readability-namespace-comments.SpacesBeforeComments
|
||||
value: '2'
|
||||
- key: google-runtime-int.SignedTypePrefix
|
||||
value: int
|
||||
- key: google-runtime-int.TypeSuffix
|
||||
value: ''
|
||||
- key: google-runtime-int.UnsignedTypePrefix
|
||||
value: uint
|
||||
- key: google-runtime-references.WhiteListTypes
|
||||
value: ''
|
||||
- key: modernize-loop-convert.MaxCopySize
|
||||
value: '16'
|
||||
- key: modernize-loop-convert.MinConfidence
|
||||
value: reasonable
|
||||
- key: modernize-loop-convert.NamingStyle
|
||||
value: CamelCase
|
||||
- key: modernize-pass-by-value.IncludeStyle
|
||||
value: llvm
|
||||
- key: modernize-replace-auto-ptr.IncludeStyle
|
||||
value: llvm
|
||||
- key: modernize-use-nullptr.NullMacros
|
||||
value: 'NULL'
|
||||
...
|
||||
|
@ -1,27 +1,65 @@
|
||||
stages:
|
||||
- dependencies
|
||||
- build
|
||||
- test
|
||||
- lint
|
||||
|
||||
image: brndnmtthws/conky-builder:latest
|
||||
variables:
|
||||
CC: clang-7
|
||||
CXX: clang++-7
|
||||
DOCKER_DRIVER: overlay2
|
||||
DOCKER_HOST: tcp://localhost:2375/
|
||||
|
||||
docker_builder:
|
||||
stage: dependencies
|
||||
image: docker:stable
|
||||
only:
|
||||
changes:
|
||||
- Dockerfile.builder
|
||||
services:
|
||||
- docker:dind
|
||||
before_script:
|
||||
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
|
||||
script:
|
||||
- docker pull $CI_REGISTRY_IMAGE/builder:latest || true
|
||||
- docker build -f Dockerfile.builder --cache-from $CI_REGISTRY_IMAGE/builder:latest --tag $CI_REGISTRY_IMAGE/builder:$CI_COMMIT_SHA --tag $CI_REGISTRY_IMAGE/builder:latest .
|
||||
- docker push ${CI_REGISTRY_IMAGE}/builder:$CI_COMMIT_SHA
|
||||
- docker push ${CI_REGISTRY_IMAGE}/builder:latest
|
||||
|
||||
build:
|
||||
image: $CI_REGISTRY_IMAGE/builder:latest
|
||||
stage: build
|
||||
script:
|
||||
- mkdir build
|
||||
- cd build
|
||||
- cmake ..
|
||||
- cmake -DMAINTAINER_MODE=ON ..
|
||||
- make -j4
|
||||
artifacts:
|
||||
expire_in: 1 day
|
||||
paths:
|
||||
- build/
|
||||
|
||||
test:
|
||||
image: $CI_REGISTRY_IMAGE/builder:latest
|
||||
stage: test
|
||||
script:
|
||||
- cd build
|
||||
- make test
|
||||
- cmake -DCMAKE_SOURCE_DIR=$(dirname `pwd`) -DCMAKE_BINARY_DIR=`pwd` -DMAINTAINER_MODE=ON -DBUILD_TESTS=ON ..
|
||||
- make -j4
|
||||
- make -j4 test
|
||||
|
||||
lint:
|
||||
check-clang-tidy:
|
||||
image: $CI_REGISTRY_IMAGE/builder:latest
|
||||
stage: test
|
||||
script:
|
||||
- cd build
|
||||
- cmake -DCHECK_CODE_QUALITY=ON ..
|
||||
- make check
|
||||
- cmake -DCMAKE_SOURCE_DIR=$(dirname `pwd`) -DCMAKE_BINARY_DIR=`pwd` -DMAINTAINER_MODE=ON -DCHECK_CODE_QUALITY=ON ..
|
||||
- make -j4 check-clang-tidy
|
||||
|
||||
check-clang-format:
|
||||
image: $CI_REGISTRY_IMAGE/builder:latest
|
||||
stage: test
|
||||
script:
|
||||
- cd build
|
||||
- cmake -DCMAKE_SOURCE_DIR=$(dirname `pwd`) -DCMAKE_BINARY_DIR=`pwd` -DMAINTAINER_MODE=ON -DCHECK_CODE_QUALITY=ON ..
|
||||
- make -j4 check-clang-format
|
||||
|
@ -101,12 +101,6 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
|
||||
endif(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
|
||||
|
||||
if(CHECK_CODE_QUALITY)
|
||||
# Set up clang-tidy
|
||||
set(CLANG_TIDY_BIN_NAME
|
||||
clang-tidy
|
||||
clang-tidy-5.0
|
||||
clang-tidy-6.0
|
||||
clang-tidy-7.0)
|
||||
set(CLANG_TIDY_EXCLUDE_PATTERNS "build/" ${CMAKE_BINARY_DIR})
|
||||
find_package(ClangTidy)
|
||||
find_package(ClangFormat)
|
||||
endif(CHECK_CODE_QUALITY)
|
||||
|
@ -1,16 +1,11 @@
|
||||
FROM ubuntu:bionic
|
||||
|
||||
RUN apt-get update \
|
||||
&& DEBIAN_FRONTEND=noninteractive \
|
||||
apt-get install -qy --no-install-recommends \
|
||||
software-properties-common \
|
||||
wget \
|
||||
gpg-agent \
|
||||
&& wget -q https://apt.llvm.org/llvm-snapshot.gpg.key \
|
||||
&& apt-key add llvm-snapshot.gpg.key \
|
||||
&& add-apt-repository 'deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-7 main' \
|
||||
&& DEBIAN_FRONTEND=noninteractive \
|
||||
apt-get install -qy --no-install-recommends \
|
||||
software-properties-common \
|
||||
cmake \
|
||||
git \
|
||||
audacious-dev \
|
||||
@ -35,6 +30,16 @@ RUN apt-get update \
|
||||
libxmmsclient-dev \
|
||||
libxnvctrl-dev \
|
||||
ncurses-dev \
|
||||
lcov \
|
||||
docbook2x \
|
||||
man \
|
||||
less
|
||||
|
||||
RUN wget -q https://apt.llvm.org/llvm-snapshot.gpg.key \
|
||||
&& apt-key add llvm-snapshot.gpg.key \
|
||||
&& add-apt-repository 'deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-7 main' \
|
||||
&& DEBIAN_FRONTEND=noninteractive \
|
||||
apt-get install -qy --no-install-recommends \
|
||||
clang-7 \
|
||||
lldb-7 \
|
||||
lld-7 \
|
||||
|
326
bin/run-clang-format.py
Executable file
326
bin/run-clang-format.py
Executable file
@ -0,0 +1,326 @@
|
||||
#!/usr/bin/env python
|
||||
"""A wrapper script around clang-format, suitable for linting multiple files
|
||||
and to use for continuous integration.
|
||||
|
||||
This is an alternative API for the clang-format command line.
|
||||
It runs over multiple files and directories in parallel.
|
||||
A diff output is produced and a sensible exit code is returned.
|
||||
|
||||
Source: https://raw.githubusercontent.com/Sarcasm/run-clang-format/master/run-clang-format.py
|
||||
"""
|
||||
|
||||
from __future__ import print_function, unicode_literals
|
||||
|
||||
import argparse
|
||||
import codecs
|
||||
import difflib
|
||||
import fnmatch
|
||||
import io
|
||||
import multiprocessing
|
||||
import os
|
||||
import signal
|
||||
import subprocess
|
||||
import sys
|
||||
import traceback
|
||||
|
||||
from functools import partial
|
||||
|
||||
DEFAULT_EXTENSIONS = 'c,h,C,H,cpp,hpp,cc,hh,c++,h++,cxx,hxx'
|
||||
|
||||
|
||||
class ExitStatus:
|
||||
SUCCESS = 0
|
||||
DIFF = 1
|
||||
TROUBLE = 2
|
||||
|
||||
|
||||
def list_files(files, recursive=False, extensions=None, exclude=None):
|
||||
if extensions is None:
|
||||
extensions = []
|
||||
if exclude is None:
|
||||
exclude = []
|
||||
|
||||
out = []
|
||||
for file in files:
|
||||
if recursive and os.path.isdir(file):
|
||||
for dirpath, dnames, fnames in os.walk(file):
|
||||
fpaths = [os.path.join(dirpath, fname) for fname in fnames]
|
||||
for pattern in exclude:
|
||||
# os.walk() supports trimming down the dnames list
|
||||
# by modifying it in-place,
|
||||
# to avoid unnecessary directory listings.
|
||||
dnames[:] = [
|
||||
x for x in dnames
|
||||
if
|
||||
not fnmatch.fnmatch(os.path.join(dirpath, x), pattern)
|
||||
]
|
||||
fpaths = [
|
||||
x for x in fpaths if not fnmatch.fnmatch(x, pattern)
|
||||
]
|
||||
for f in fpaths:
|
||||
ext = os.path.splitext(f)[1][1:]
|
||||
if ext in extensions:
|
||||
out.append(f)
|
||||
else:
|
||||
out.append(file)
|
||||
return out
|
||||
|
||||
|
||||
def make_diff(file, original, reformatted):
|
||||
return list(
|
||||
difflib.unified_diff(
|
||||
original,
|
||||
reformatted,
|
||||
fromfile='{}\t(original)'.format(file),
|
||||
tofile='{}\t(reformatted)'.format(file),
|
||||
n=3))
|
||||
|
||||
|
||||
class DiffError(Exception):
|
||||
def __init__(self, message, errs=None):
|
||||
super(DiffError, self).__init__(message)
|
||||
self.errs = errs or []
|
||||
|
||||
|
||||
class UnexpectedError(Exception):
|
||||
def __init__(self, message, exc=None):
|
||||
super(UnexpectedError, self).__init__(message)
|
||||
self.formatted_traceback = traceback.format_exc()
|
||||
self.exc = exc
|
||||
|
||||
|
||||
def run_clang_format_diff_wrapper(args, file):
|
||||
try:
|
||||
ret = run_clang_format_diff(args, file)
|
||||
return ret
|
||||
except DiffError:
|
||||
raise
|
||||
except Exception as e:
|
||||
raise UnexpectedError('{}: {}: {}'.format(file, e.__class__.__name__,
|
||||
e), e)
|
||||
|
||||
|
||||
def run_clang_format_diff(args, file):
|
||||
try:
|
||||
with io.open(file, 'r', encoding='utf-8') as f:
|
||||
original = f.readlines()
|
||||
except IOError as exc:
|
||||
raise DiffError(str(exc))
|
||||
invocation = [args.clang_format_executable, file]
|
||||
|
||||
# Use of utf-8 to decode the process output.
|
||||
#
|
||||
# Hopefully, this is the correct thing to do.
|
||||
#
|
||||
# It's done due to the following assumptions (which may be incorrect):
|
||||
# - clang-format will returns the bytes read from the files as-is,
|
||||
# without conversion, and it is already assumed that the files use utf-8.
|
||||
# - if the diagnostics were internationalized, they would use utf-8:
|
||||
# > Adding Translations to Clang
|
||||
# >
|
||||
# > Not possible yet!
|
||||
# > Diagnostic strings should be written in UTF-8,
|
||||
# > the client can translate to the relevant code page if needed.
|
||||
# > Each translation completely replaces the format string
|
||||
# > for the diagnostic.
|
||||
# > -- http://clang.llvm.org/docs/InternalsManual.html#internals-diag-translation
|
||||
#
|
||||
# It's not pretty, due to Python 2 & 3 compatibility.
|
||||
encoding_py3 = {}
|
||||
if sys.version_info[0] >= 3:
|
||||
encoding_py3['encoding'] = 'utf-8'
|
||||
|
||||
try:
|
||||
proc = subprocess.Popen(
|
||||
invocation,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
universal_newlines=True,
|
||||
**encoding_py3)
|
||||
except OSError as exc:
|
||||
raise DiffError(str(exc))
|
||||
proc_stdout = proc.stdout
|
||||
proc_stderr = proc.stderr
|
||||
if sys.version_info[0] < 3:
|
||||
# make the pipes compatible with Python 3,
|
||||
# reading lines should output unicode
|
||||
encoding = 'utf-8'
|
||||
proc_stdout = codecs.getreader(encoding)(proc_stdout)
|
||||
proc_stderr = codecs.getreader(encoding)(proc_stderr)
|
||||
# hopefully the stderr pipe won't get full and block the process
|
||||
outs = list(proc_stdout.readlines())
|
||||
errs = list(proc_stderr.readlines())
|
||||
proc.wait()
|
||||
if proc.returncode:
|
||||
raise DiffError("clang-format exited with status {}: '{}'".format(
|
||||
proc.returncode, file), errs)
|
||||
return make_diff(file, original, outs), errs
|
||||
|
||||
|
||||
def bold_red(s):
|
||||
return '\x1b[1m\x1b[31m' + s + '\x1b[0m'
|
||||
|
||||
|
||||
def colorize(diff_lines):
|
||||
def bold(s):
|
||||
return '\x1b[1m' + s + '\x1b[0m'
|
||||
|
||||
def cyan(s):
|
||||
return '\x1b[36m' + s + '\x1b[0m'
|
||||
|
||||
def green(s):
|
||||
return '\x1b[32m' + s + '\x1b[0m'
|
||||
|
||||
def red(s):
|
||||
return '\x1b[31m' + s + '\x1b[0m'
|
||||
|
||||
for line in diff_lines:
|
||||
if line[:4] in ['--- ', '+++ ']:
|
||||
yield bold(line)
|
||||
elif line.startswith('@@ '):
|
||||
yield cyan(line)
|
||||
elif line.startswith('+'):
|
||||
yield green(line)
|
||||
elif line.startswith('-'):
|
||||
yield red(line)
|
||||
else:
|
||||
yield line
|
||||
|
||||
|
||||
def print_diff(diff_lines, use_color):
|
||||
if use_color:
|
||||
diff_lines = colorize(diff_lines)
|
||||
if sys.version_info[0] < 3:
|
||||
sys.stdout.writelines((l.encode('utf-8') for l in diff_lines))
|
||||
else:
|
||||
sys.stdout.writelines(diff_lines)
|
||||
|
||||
|
||||
def print_trouble(prog, message, use_colors):
|
||||
error_text = 'error:'
|
||||
if use_colors:
|
||||
error_text = bold_red(error_text)
|
||||
print("{}: {} {}".format(prog, error_text, message), file=sys.stderr)
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument(
|
||||
'--clang-format-executable',
|
||||
metavar='EXECUTABLE',
|
||||
help='path to the clang-format executable',
|
||||
default='clang-format')
|
||||
parser.add_argument(
|
||||
'--extensions',
|
||||
help='comma separated list of file extensions (default: {})'.format(
|
||||
DEFAULT_EXTENSIONS),
|
||||
default=DEFAULT_EXTENSIONS)
|
||||
parser.add_argument(
|
||||
'-r',
|
||||
'--recursive',
|
||||
action='store_true',
|
||||
help='run recursively over directories')
|
||||
parser.add_argument('files', metavar='file', nargs='+')
|
||||
parser.add_argument(
|
||||
'-q',
|
||||
'--quiet',
|
||||
action='store_true')
|
||||
parser.add_argument(
|
||||
'-j',
|
||||
metavar='N',
|
||||
type=int,
|
||||
default=0,
|
||||
help='run N clang-format jobs in parallel'
|
||||
' (default number of cpus + 1)')
|
||||
parser.add_argument(
|
||||
'--color',
|
||||
default='auto',
|
||||
choices=['auto', 'always', 'never'],
|
||||
help='show colored diff (default: auto)')
|
||||
parser.add_argument(
|
||||
'-e',
|
||||
'--exclude',
|
||||
metavar='PATTERN',
|
||||
action='append',
|
||||
default=[],
|
||||
help='exclude paths matching the given glob-like pattern(s)'
|
||||
' from recursive search')
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
# use default signal handling, like diff return SIGINT value on ^C
|
||||
# https://bugs.python.org/issue14229#msg156446
|
||||
signal.signal(signal.SIGINT, signal.SIG_DFL)
|
||||
try:
|
||||
signal.SIGPIPE
|
||||
except AttributeError:
|
||||
# compatibility, SIGPIPE does not exist on Windows
|
||||
pass
|
||||
else:
|
||||
signal.signal(signal.SIGPIPE, signal.SIG_DFL)
|
||||
|
||||
colored_stdout = False
|
||||
colored_stderr = False
|
||||
if args.color == 'always':
|
||||
colored_stdout = True
|
||||
colored_stderr = True
|
||||
elif args.color == 'auto':
|
||||
colored_stdout = sys.stdout.isatty()
|
||||
colored_stderr = sys.stderr.isatty()
|
||||
|
||||
retcode = ExitStatus.SUCCESS
|
||||
files = list_files(
|
||||
args.files,
|
||||
recursive=args.recursive,
|
||||
exclude=args.exclude,
|
||||
extensions=args.extensions.split(','))
|
||||
|
||||
if not files:
|
||||
return
|
||||
|
||||
njobs = args.j
|
||||
if njobs == 0:
|
||||
njobs = multiprocessing.cpu_count() + 1
|
||||
njobs = min(len(files), njobs)
|
||||
|
||||
if njobs == 1:
|
||||
# execute directly instead of in a pool,
|
||||
# less overhead, simpler stacktraces
|
||||
it = (run_clang_format_diff_wrapper(args, file) for file in files)
|
||||
pool = None
|
||||
else:
|
||||
pool = multiprocessing.Pool(njobs)
|
||||
it = pool.imap_unordered(
|
||||
partial(run_clang_format_diff_wrapper, args), files)
|
||||
while True:
|
||||
try:
|
||||
outs, errs = next(it)
|
||||
except StopIteration:
|
||||
break
|
||||
except DiffError as e:
|
||||
print_trouble(parser.prog, str(e), use_colors=colored_stderr)
|
||||
retcode = ExitStatus.TROUBLE
|
||||
sys.stderr.writelines(e.errs)
|
||||
except UnexpectedError as e:
|
||||
print_trouble(parser.prog, str(e), use_colors=colored_stderr)
|
||||
sys.stderr.write(e.formatted_traceback)
|
||||
retcode = ExitStatus.TROUBLE
|
||||
# stop at the first unexpected error,
|
||||
# something could be very wrong,
|
||||
# don't process all files unnecessarily
|
||||
if pool:
|
||||
pool.terminate()
|
||||
break
|
||||
else:
|
||||
sys.stderr.writelines(errs)
|
||||
if outs == []:
|
||||
continue
|
||||
if not args.quiet:
|
||||
print_diff(outs, use_color=colored_stdout)
|
||||
if retcode == ExitStatus.SUCCESS:
|
||||
retcode = ExitStatus.DIFF
|
||||
return retcode
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(main())
|
23
cmake/FindClangFormat.cmake
Normal file
23
cmake/FindClangFormat.cmake
Normal file
@ -0,0 +1,23 @@
|
||||
# Find Clang format
|
||||
#
|
||||
|
||||
set(CLANG_FORMAT_BIN_NAME
|
||||
clang-format
|
||||
clang-format-5.0
|
||||
clang-format-6.0
|
||||
clang-format-7)
|
||||
|
||||
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()
|
@ -1,17 +1,7 @@
|
||||
# Find Clang tidy
|
||||
#
|
||||
|
||||
if(NOT CLANG_TIDY_BIN_NAME)
|
||||
set(CLANG_TIDY_BIN_NAME clang-tidy)
|
||||
endif()
|
||||
|
||||
# if custom path check there first
|
||||
if(CLANG_TIDY_ROOT_DIR)
|
||||
find_program(CLANG_TIDY_BIN
|
||||
NAMES ${CLANG_TIDY_BIN_NAME}
|
||||
PATHS "${CLANG_TIDY_ROOT_DIR}"
|
||||
NO_DEFAULT_PATH)
|
||||
endif()
|
||||
set(CLANG_TIDY_BIN_NAME clang-tidy clang-tidy-5.0 clang-tidy-6.0 clang-tidy-7)
|
||||
|
||||
find_program(CLANG_TIDY_BIN NAMES ${CLANG_TIDY_BIN_NAME})
|
||||
|
||||
|
27
cmake/clang-format.cmake
Normal file
27
cmake/clang-format.cmake
Normal file
@ -0,0 +1,27 @@
|
||||
set(CLANG_FORMAT_CXX_FILE_EXTENSIONS
|
||||
${CLANG_FORMAT_CXX_FILE_EXTENSIONS}
|
||||
*.cpp
|
||||
*.h
|
||||
*.cxx
|
||||
*.hxx
|
||||
*.hpp
|
||||
*.cc
|
||||
*.hh
|
||||
*.ipp)
|
||||
|
||||
foreach(PATTERN ${CLANG_FORMAT_CXX_FILE_EXTENSIONS})
|
||||
list(APPEND CLANG_FORMAT_CXX_PATTERN ${CMAKE_SOURCE_DIR}/src/${PATTERN})
|
||||
list(APPEND CLANG_FORMAT_CXX_PATTERN ${CMAKE_SOURCE_DIR}/tests/${PATTERN})
|
||||
list(APPEND CLANG_FORMAT_CXX_PATTERN ${CMAKE_SOURCE_DIR}/lua/${PATTERN})
|
||||
endforeach()
|
||||
|
||||
file(GLOB_RECURSE CLANG_FORMAT_SRCS ${CLANG_FORMAT_CXX_PATTERN})
|
||||
|
||||
add_custom_target(clang-format
|
||||
COMMAND ${CLANG_FORMAT_BIN} -style=file -i
|
||||
${CLANG_FORMAT_SRCS})
|
||||
add_custom_target(check-clang-format
|
||||
COMMAND ${CMAKE_SOURCE_DIR}/bin/run-clang-format.py
|
||||
--color always
|
||||
--clang-format-executable ${CLANG_FORMAT_BIN}
|
||||
${CLANG_FORMAT_SRCS})
|
@ -1,15 +1,27 @@
|
||||
# Run clang-tidy
|
||||
get_target_property(CLANG_TIDY_SRCS_TMP conky SOURCES)
|
||||
get_target_property(conky_SRC_DIR conky SOURCE_DIR)
|
||||
|
||||
set(DO_CLANG_TIDY
|
||||
"${CLANG_TIDY_BIN}"
|
||||
-format-style='{BasedOnStyle:
|
||||
google,
|
||||
IndentWidth:
|
||||
2}'
|
||||
-checks=*,-clang-analyzer-alpha.*
|
||||
-fix
|
||||
-fix-errors)
|
||||
|
||||
if(CLANG_TIDY_BIN)
|
||||
set_target_properties(conky PROPERTIES CXX_CLANG_TIDY "${DO_CLANG_TIDY}")
|
||||
if(BUILD_TESTS)
|
||||
get_target_property(CLANG_TIDY_SRCS_TMP_CORE conky_core SOURCES)
|
||||
list(APPEND CLANG_TIDY_SRCS_TMP ${CLANG_TIDY_SRCS_TMP_CORE})
|
||||
endif()
|
||||
|
||||
foreach(TMP_SRC ${CLANG_TIDY_SRCS_TMP})
|
||||
if("${TMP_SRC}" MATCHES ".*\.cc|.*\.hh|.*\.[chi]pp|.*\.[chi]xx|.*\.ii")
|
||||
list(APPEND CLANG_TIDY_SRCS ${conky_SRC_DIR}/${TMP_SRC})
|
||||
endif()
|
||||
endforeach(TMP_SRC)
|
||||
|
||||
get_target_property(CLANG_INCLUDES_tmp conky INCLUDE_DIRECTORIES)
|
||||
foreach(TMP_INCLUDE ${CLANG_INCLUDES_tmp})
|
||||
list(APPEND CLANG_INCLUDES -I${TMP_INCLUDE})
|
||||
endforeach(TMP_INCLUDE)
|
||||
|
||||
add_custom_target(clang-tidy
|
||||
COMMAND ${CLANG_TIDY_BIN} -config='' -fix -format-style=file
|
||||
${CLANG_TIDY_SRCS}
|
||||
-- -std=c++17 -I${CMAKE_BINARY_DIR} ${CLANG_INCLUDES})
|
||||
add_custom_target(check-clang-tidy
|
||||
COMMAND ${CLANG_TIDY_BIN} -config='' -format-style=file
|
||||
${CLANG_TIDY_SRCS}
|
||||
-- -std=c++17 -I${CMAKE_BINARY_DIR} ${CLANG_INCLUDES})
|
||||
|
@ -47,9 +47,6 @@ void destroy_cairo_font_extents_t(cairo_font_extents_t *pointer) {
|
||||
free(pointer);
|
||||
}
|
||||
|
||||
void destroy_cairo_matrix_t(cairo_matrix_t *pointer) {
|
||||
free(pointer);
|
||||
}
|
||||
|
||||
void destroy_cairo_matrix_t(cairo_matrix_t *pointer) { free(pointer); }
|
||||
|
||||
#endif /* _LIBCAIRO_HELPER_H_ */
|
||||
|
@ -29,13 +29,16 @@ void print_audacious_title(struct text_object *, char *, unsigned int);
|
||||
void print_audacious_length(struct text_object *, char *, unsigned int);
|
||||
void print_audacious_length_seconds(struct text_object *, char *, unsigned int);
|
||||
void print_audacious_position(struct text_object *, char *, unsigned int);
|
||||
void print_audacious_position_seconds(struct text_object *, char *, unsigned int);
|
||||
void print_audacious_position_seconds(struct text_object *, char *,
|
||||
unsigned int);
|
||||
void print_audacious_bitrate(struct text_object *, char *, unsigned int);
|
||||
void print_audacious_frequency(struct text_object *, char *, unsigned int);
|
||||
void print_audacious_channels(struct text_object *, char *, unsigned int);
|
||||
void print_audacious_filename(struct text_object *, char *, unsigned int);
|
||||
void print_audacious_playlist_length(struct text_object *, char *, unsigned int);
|
||||
void print_audacious_playlist_position(struct text_object *, char *, unsigned int);
|
||||
void print_audacious_playlist_length(struct text_object *, char *,
|
||||
unsigned int);
|
||||
void print_audacious_playlist_position(struct text_object *, char *,
|
||||
unsigned int);
|
||||
void print_audacious_main_volume(struct text_object *, char *, unsigned int);
|
||||
double audacious_barval(struct text_object *);
|
||||
|
||||
|
@ -61,7 +61,8 @@ static int apm_getinfo(int fd, apm_info_t aip) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void print_apm_adapter(struct text_object *obj, char *p, unsigned int p_max_size) {
|
||||
void print_apm_adapter(struct text_object *obj, char *p,
|
||||
unsigned int p_max_size) {
|
||||
int fd;
|
||||
const char *out;
|
||||
#ifdef __OpenBSD__
|
||||
@ -109,7 +110,8 @@ void print_apm_adapter(struct text_object *obj, char *p, unsigned int p_max_size
|
||||
snprintf(p, p_max_size, "%s", out);
|
||||
}
|
||||
|
||||
void print_apm_battery_life(struct text_object *obj, char *p, unsigned int p_max_size) {
|
||||
void print_apm_battery_life(struct text_object *obj, char *p,
|
||||
unsigned int p_max_size) {
|
||||
int fd;
|
||||
u_int batt_life;
|
||||
const char *out;
|
||||
@ -150,7 +152,8 @@ void print_apm_battery_life(struct text_object *obj, char *p, unsigned int p_max
|
||||
snprintf(p, p_max_size, "%s", out);
|
||||
}
|
||||
|
||||
void print_apm_battery_time(struct text_object *obj, char *p, unsigned int p_max_size) {
|
||||
void print_apm_battery_time(struct text_object *obj, char *p,
|
||||
unsigned int p_max_size) {
|
||||
int fd;
|
||||
int batt_time;
|
||||
#ifdef __OpenBSD__
|
||||
|
@ -24,8 +24,8 @@
|
||||
|
||||
#include "c++wrap.hh"
|
||||
|
||||
#include <cstdio>
|
||||
#include <unistd.h>
|
||||
#include <cstdio>
|
||||
|
||||
/* force use of POSIX strerror_r instead of non-portable GNU specific */
|
||||
#ifdef _GNU_SOURCE
|
||||
@ -42,9 +42,7 @@
|
||||
|
||||
namespace {
|
||||
int pipe2_emulate(int pipefd[2], int flags) {
|
||||
if (pipe(pipefd) == -1) {
|
||||
return -1;
|
||||
}
|
||||
if (pipe(pipefd) == -1) { return -1; }
|
||||
|
||||
if ((flags & O_CLOEXEC) != 0) {
|
||||
// we emulate O_CLOEXEC if the system does not have it
|
||||
@ -52,13 +50,9 @@ int pipe2_emulate(int pipefd[2], int flags) {
|
||||
|
||||
for (int i = 0; i < 2; ++i) {
|
||||
int r = fcntl(pipefd[i], F_GETFD);
|
||||
if (r == -1) {
|
||||
return -1;
|
||||
}
|
||||
if (r == -1) { return -1; }
|
||||
|
||||
if (fcntl(pipefd[i], F_SETFD, r | FD_CLOEXEC) == -1) {
|
||||
return -1;
|
||||
}
|
||||
if (fcntl(pipefd[i], F_SETFD, r | FD_CLOEXEC) == -1) { return -1; }
|
||||
}
|
||||
}
|
||||
|
||||
@ -81,8 +75,6 @@ std::string strerror_r(int errnum) {
|
||||
|
||||
std::pair<int, int> pipe2(int flags) {
|
||||
int fd[2];
|
||||
if (pipe2_ptr(fd, flags) == -1) {
|
||||
throw errno_error("pipe2");
|
||||
}
|
||||
if (pipe2_ptr(fd, flags) == -1) { throw errno_error("pipe2"); }
|
||||
{ return std::pair<int, int>(fd[0], fd[1]); }
|
||||
}
|
||||
|
11
src/cmus.cc
11
src/cmus.cc
@ -138,7 +138,7 @@ void cmus_cb::work() {
|
||||
|
||||
#define CMUS_PRINT_GENERATOR(type, alt) \
|
||||
void print_cmus_##type(struct text_object *obj, char *p, \
|
||||
unsigned int p_max_size) { \
|
||||
unsigned int p_max_size) { \
|
||||
(void)obj; \
|
||||
uint32_t period = std::max( \
|
||||
lround(music_player_interval.get(*state) / active_update_interval()), \
|
||||
@ -179,7 +179,8 @@ double cmus_progress(struct text_object *obj) {
|
||||
return (double)cmus.progress;
|
||||
}
|
||||
|
||||
void print_cmus_totaltime(struct text_object *obj, char *p, unsigned int p_max_size) {
|
||||
void print_cmus_totaltime(struct text_object *obj, char *p,
|
||||
unsigned int p_max_size) {
|
||||
(void)obj;
|
||||
uint32_t period = std::max(
|
||||
lround(music_player_interval.get(*state) / active_update_interval()), 1l);
|
||||
@ -188,7 +189,8 @@ void print_cmus_totaltime(struct text_object *obj, char *p, unsigned int p_max_s
|
||||
format_seconds_short(p, p_max_size, atol(cmus.totaltime.c_str()));
|
||||
}
|
||||
|
||||
void print_cmus_timeleft(struct text_object *obj, char *p, unsigned int p_max_size) {
|
||||
void print_cmus_timeleft(struct text_object *obj, char *p,
|
||||
unsigned int p_max_size) {
|
||||
(void)obj;
|
||||
uint32_t period = std::max(
|
||||
lround(music_player_interval.get(*state) / active_update_interval()), 1l);
|
||||
@ -198,7 +200,8 @@ void print_cmus_timeleft(struct text_object *obj, char *p, unsigned int p_max_si
|
||||
format_seconds_short(p, p_max_size, (long)cmus.timeleft);
|
||||
}
|
||||
|
||||
void print_cmus_curtime(struct text_object *obj, char *p, unsigned int p_max_size) {
|
||||
void print_cmus_curtime(struct text_object *obj, char *p,
|
||||
unsigned int p_max_size) {
|
||||
(void)obj;
|
||||
uint32_t period = std::max(
|
||||
lround(music_player_interval.get(*state) / active_update_interval()), 1l);
|
||||
|
@ -63,9 +63,7 @@ static void set_up_gradient() {
|
||||
greenmask |= 1 << i;
|
||||
bluemask |= 1 << i;
|
||||
}
|
||||
if (colour_depth % 3 == 1) {
|
||||
greenmask |= 1 << (colour_depth / 3);
|
||||
}
|
||||
if (colour_depth % 3 == 1) { greenmask |= 1 << (colour_depth / 3); }
|
||||
redmask = redmask << (2 * colour_depth / 3 + colour_depth % 3);
|
||||
greenmask = greenmask << (colour_depth / 3);
|
||||
}
|
||||
@ -74,9 +72,7 @@ static void set_up_gradient() {
|
||||
unsigned int adjust_colours(unsigned int colour) {
|
||||
double r, g, b;
|
||||
|
||||
if (colour_depth == 0) {
|
||||
set_up_gradient();
|
||||
}
|
||||
if (colour_depth == 0) { set_up_gradient(); }
|
||||
if (colour_depth == 16) {
|
||||
r = (colour & 0xff0000) >> 16;
|
||||
g = (colour & 0xff00) >> 8;
|
||||
@ -100,9 +96,7 @@ unsigned long *do_gradient(int width, unsigned long first_colour,
|
||||
static_cast<unsigned long *>(malloc(width * sizeof(unsigned long)));
|
||||
int i;
|
||||
|
||||
if (colour_depth == 0) {
|
||||
set_up_gradient();
|
||||
}
|
||||
if (colour_depth == 0) { set_up_gradient(); }
|
||||
red1 = (first_colour & redmask) >> redshift;
|
||||
green1 = (first_colour & greenmask) >> greenshift;
|
||||
blue1 = first_colour & bluemask;
|
||||
@ -139,24 +133,12 @@ unsigned long *do_gradient(int width, unsigned long first_colour,
|
||||
red3 += red1;
|
||||
green3 += green1;
|
||||
blue3 += blue1;
|
||||
if (red3 < 0) {
|
||||
red3 = 0;
|
||||
}
|
||||
if (green3 < 0) {
|
||||
green3 = 0;
|
||||
}
|
||||
if (blue3 < 0) {
|
||||
blue3 = 0;
|
||||
}
|
||||
if (red3 > bluemask) {
|
||||
red3 = bluemask;
|
||||
}
|
||||
if (green3 > bluemask) {
|
||||
green3 = bluemask;
|
||||
}
|
||||
if (blue3 > bluemask) {
|
||||
blue3 = bluemask;
|
||||
}
|
||||
if (red3 < 0) { red3 = 0; }
|
||||
if (green3 < 0) { green3 = 0; }
|
||||
if (blue3 < 0) { blue3 = 0; }
|
||||
if (red3 > bluemask) { red3 = bluemask; }
|
||||
if (green3 > bluemask) { green3 = bluemask; }
|
||||
if (blue3 > bluemask) { blue3 = bluemask; }
|
||||
colours[i] = (red3 << redshift) | (green3 << greenshift) | blue3;
|
||||
}
|
||||
return colours;
|
||||
|
@ -54,7 +54,8 @@ int get_entropy_poolsize(const unsigned int *);
|
||||
|
||||
/* System Integrity Protection */
|
||||
int get_sip_status(void);
|
||||
void print_sip_status(struct text_object *obj, char *p, unsigned int p_max_size);
|
||||
void print_sip_status(struct text_object *obj, char *p,
|
||||
unsigned int p_max_size);
|
||||
|
||||
void deallocate_cpu_sample(struct text_object *obj);
|
||||
|
||||
|
@ -62,9 +62,7 @@ struct diskio_stat *prepare_diskio_stat(const char *s) {
|
||||
char *rpbuf;
|
||||
char rpbuf2[256];
|
||||
|
||||
if (s == nullptr) {
|
||||
return &stats;
|
||||
}
|
||||
if (s == nullptr) { return &stats; }
|
||||
|
||||
if (strncmp(s, "label:", 6) == 0) {
|
||||
snprintf(&(device_name[0]), text_buffer_size.get(*state),
|
||||
@ -101,13 +99,13 @@ struct diskio_stat *prepare_diskio_stat(const char *s) {
|
||||
|
||||
if (strncmp(s, "label:", 6) == 0) {
|
||||
snprintf(&(stat_name[0]), text_buffer_size.get(*state), "/dev/%s",
|
||||
&(device_name[0]));
|
||||
&(device_name[0]));
|
||||
if ((stat(&(stat_name[0]), &sb) != 0) || !S_ISBLK(sb.st_mode)) {
|
||||
NORM_ERR("diskio device '%s' does not exist", &device_s[0]);
|
||||
}
|
||||
} else if ((0 == (strncmp(s, "partuuid:", 9))) &&
|
||||
((stat(rpbuf2, &sb) != 0) || !S_ISBLK(sb.st_mode))) {
|
||||
NORM_ERR("diskio device '%s' does not exist", &device_s[0]);
|
||||
((stat(rpbuf2, &sb) != 0) || !S_ISBLK(sb.st_mode))) {
|
||||
NORM_ERR("diskio device '%s' does not exist", &device_s[0]);
|
||||
}
|
||||
|
||||
#endif
|
||||
@ -115,9 +113,7 @@ struct diskio_stat *prepare_diskio_stat(const char *s) {
|
||||
/* lookup existing */
|
||||
while (cur->next != nullptr) {
|
||||
cur = cur->next;
|
||||
if (strcmp(cur->dev, &(device_name[0])) == 0) {
|
||||
return cur;
|
||||
}
|
||||
if (strcmp(cur->dev, &(device_name[0])) == 0) { return cur; }
|
||||
}
|
||||
|
||||
/* no existing found, make a new one */
|
||||
@ -145,9 +141,7 @@ static void print_diskio_dir(struct text_object *obj, int dir, char *p,
|
||||
auto *diskio = static_cast<struct diskio_stat *>(obj->data.opaque);
|
||||
double val;
|
||||
|
||||
if (diskio == nullptr) {
|
||||
return;
|
||||
}
|
||||
if (diskio == nullptr) { return; }
|
||||
|
||||
if (dir < 0) {
|
||||
val = diskio->current_read;
|
||||
@ -166,11 +160,13 @@ void print_diskio(struct text_object *obj, char *p, unsigned int p_max_size) {
|
||||
print_diskio_dir(obj, 0, p, p_max_size);
|
||||
}
|
||||
|
||||
void print_diskio_read(struct text_object *obj, char *p, unsigned int p_max_size) {
|
||||
void print_diskio_read(struct text_object *obj, char *p,
|
||||
unsigned int p_max_size) {
|
||||
print_diskio_dir(obj, -1, p, p_max_size);
|
||||
}
|
||||
|
||||
void print_diskio_write(struct text_object *obj, char *p, unsigned int p_max_size) {
|
||||
void print_diskio_write(struct text_object *obj, char *p,
|
||||
unsigned int p_max_size) {
|
||||
print_diskio_dir(obj, 1, p, p_max_size);
|
||||
}
|
||||
|
||||
|
@ -347,7 +347,8 @@ int update_cpu_usage(void) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void free_cpu(struct text_object *) { /* no-op */ }
|
||||
void free_cpu(struct text_object *) { /* no-op */
|
||||
}
|
||||
|
||||
int update_load_average(void) {
|
||||
double v[3];
|
||||
|
@ -27,11 +27,11 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <time.h>
|
||||
#include "config.h"
|
||||
#include "conky.h"
|
||||
#include "text_object.h"
|
||||
#include <inttypes.h>
|
||||
#include <time.h>
|
||||
|
||||
/* check for OS and include appropriate headers */
|
||||
#if defined(__linux__)
|
||||
@ -64,7 +64,8 @@ int update_entropy() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void print_entropy_avail(struct text_object *obj, char *p, unsigned int p_max_size) {
|
||||
void print_entropy_avail(struct text_object *obj, char *p,
|
||||
unsigned int p_max_size) {
|
||||
(void)obj;
|
||||
snprintf(p, p_max_size, "%u", entropy.avail);
|
||||
}
|
||||
@ -75,7 +76,8 @@ uint8_t entropy_percentage(struct text_object *obj) {
|
||||
static_cast<double>(entropy.poolsize));
|
||||
}
|
||||
|
||||
void print_entropy_poolsize(struct text_object *obj, char *p, unsigned int p_max_size) {
|
||||
void print_entropy_poolsize(struct text_object *obj, char *p,
|
||||
unsigned int p_max_size) {
|
||||
(void)obj;
|
||||
snprintf(p, p_max_size, "%u", entropy.poolsize);
|
||||
}
|
||||
@ -88,18 +90,16 @@ double entropy_barval(struct text_object *obj) {
|
||||
|
||||
void print_password(struct text_object *obj, char *p, unsigned int p_max_size) {
|
||||
time_t t;
|
||||
static const char letters[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789~!@#$%^&*()_";
|
||||
static const char letters[] =
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789~!@#$%^&*("
|
||||
")_";
|
||||
static const int len = (int)sizeof(letters) - 1;
|
||||
uintmax_t x = strtoumax(obj->data.s, (char **)NULL, 10);
|
||||
uintmax_t z = 0;
|
||||
|
||||
if (-1 == (t = time(NULL))) {
|
||||
return;
|
||||
}
|
||||
if (-1 == (t = time(NULL))) { return; }
|
||||
srandom((unsigned int)t);
|
||||
|
||||
for (; z < x && p_max_size-1 > z; z++) {
|
||||
*p++ = letters[random() % len];
|
||||
}
|
||||
for (; z < x && p_max_size - 1 > z; z++) { *p++ = letters[random() % len]; }
|
||||
*p = '\0';
|
||||
}
|
||||
|
@ -27,6 +27,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "exec.h"
|
||||
#include <fcntl.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
@ -36,7 +37,6 @@
|
||||
#include <mutex>
|
||||
#include "conky.h"
|
||||
#include "core.h"
|
||||
#include "exec.h"
|
||||
#include "logging.h"
|
||||
#include "specials.h"
|
||||
#include "text_object.h"
|
||||
@ -68,7 +68,7 @@ static char *remove_excess_quotes(const char *command) {
|
||||
}
|
||||
|
||||
for (; *command_ptr; command_ptr++) {
|
||||
if ('\0' == *(command_ptr+1) && 1 == skip &&
|
||||
if ('\0' == *(command_ptr + 1) && 1 == skip &&
|
||||
(*command_ptr == '"' || *command_ptr == '\'')) {
|
||||
continue;
|
||||
}
|
||||
@ -122,7 +122,8 @@ static FILE *pid_popen(const char *command, const char *mode, pid_t *child) {
|
||||
if (fcntl(childend, F_DUPFD, 0) == -1) { perror("fcntl()"); }
|
||||
close(childend);
|
||||
|
||||
execl("/bin/sh", "sh", "-c", remove_excess_quotes(command), (char *)nullptr);
|
||||
execl("/bin/sh", "sh", "-c", remove_excess_quotes(command),
|
||||
(char *)nullptr);
|
||||
_exit(EXIT_FAILURE); // child should die here, (normally execl will take
|
||||
// care of this but it can fail)
|
||||
}
|
||||
|
32
src/i8k.cc
32
src/i8k.cc
@ -56,13 +56,11 @@ static char *i8k_procbuf = nullptr;
|
||||
int update_i8k(void) {
|
||||
FILE *fp;
|
||||
|
||||
if (!i8k_procbuf) {
|
||||
i8k_procbuf = (char *)malloc(128 * sizeof(char));
|
||||
}
|
||||
if (!i8k_procbuf) { i8k_procbuf = (char *)malloc(128 * sizeof(char)); }
|
||||
if ((fp = fopen(PROC_I8K, "r")) == nullptr) {
|
||||
free_and_zero(i8k_procbuf);
|
||||
/*THREAD_CRIT_ERR(nullptr, NULL, "/proc/i8k doesn't exist! use insmod to make
|
||||
sure the kernel " "driver is loaded...");*/
|
||||
/*THREAD_CRIT_ERR(nullptr, NULL, "/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...");
|
||||
@ -107,7 +105,8 @@ void print_i8k_left_fan_status(struct text_object *obj, char *p,
|
||||
print_i8k_fan_status(p, p_max_size, i8k.left_fan_status);
|
||||
}
|
||||
|
||||
void print_i8k_cpu_temp(struct text_object *obj, char *p, unsigned int p_max_size) {
|
||||
void print_i8k_cpu_temp(struct text_object *obj, char *p,
|
||||
unsigned int p_max_size) {
|
||||
int cpu_temp;
|
||||
|
||||
(void)obj;
|
||||
@ -122,7 +121,8 @@ void print_i8k_right_fan_status(struct text_object *obj, char *p,
|
||||
print_i8k_fan_status(p, p_max_size, i8k.right_fan_status);
|
||||
}
|
||||
|
||||
void print_i8k_ac_status(struct text_object *obj, char *p, unsigned int p_max_size) {
|
||||
void print_i8k_ac_status(struct text_object *obj, char *p,
|
||||
unsigned int p_max_size) {
|
||||
int ac_status;
|
||||
|
||||
(void)obj;
|
||||
@ -131,19 +131,15 @@ void print_i8k_ac_status(struct text_object *obj, char *p, unsigned int p_max_si
|
||||
if (ac_status == -1) {
|
||||
snprintf(p, p_max_size, "%s", "disabled (read i8k docs)");
|
||||
}
|
||||
if (ac_status == 0) {
|
||||
snprintf(p, p_max_size, "%s", "off");
|
||||
}
|
||||
if (ac_status == 1) {
|
||||
snprintf(p, p_max_size, "%s", "on");
|
||||
}
|
||||
if (ac_status == 0) { snprintf(p, p_max_size, "%s", "off"); }
|
||||
if (ac_status == 1) { snprintf(p, p_max_size, "%s", "on"); }
|
||||
}
|
||||
|
||||
#define I8K_PRINT_GENERATOR(name) \
|
||||
void print_i8k_##name(struct text_object *obj, char *p, \
|
||||
unsigned int p_max_size) { \
|
||||
(void)obj; \
|
||||
snprintf(p, p_max_size, "%s", i8k.name); \
|
||||
#define I8K_PRINT_GENERATOR(name) \
|
||||
void print_i8k_##name(struct text_object *obj, char *p, \
|
||||
unsigned int p_max_size) { \
|
||||
(void)obj; \
|
||||
snprintf(p, p_max_size, "%s", i8k.name); \
|
||||
}
|
||||
|
||||
I8K_PRINT_GENERATOR(version)
|
||||
|
67
src/ibm.cc
67
src/ibm.cc
@ -72,16 +72,15 @@ speed: 2944
|
||||
commands: enable, disable
|
||||
* Peter Tarjan (ptarjan@citromail.hu) */
|
||||
|
||||
void get_ibm_acpi_fan(struct text_object *obj, char *p, unsigned int p_max_size) {
|
||||
void get_ibm_acpi_fan(struct text_object *obj, char *p,
|
||||
unsigned int p_max_size) {
|
||||
FILE *fp;
|
||||
unsigned int speed = 0;
|
||||
char fan[128];
|
||||
|
||||
(void)obj;
|
||||
|
||||
if (!p || p_max_size <= 0) {
|
||||
return;
|
||||
}
|
||||
if (!p || p_max_size <= 0) { return; }
|
||||
|
||||
snprintf(fan, 127, "%s/fan", IBM_ACPI_DIR);
|
||||
|
||||
@ -90,12 +89,8 @@ void get_ibm_acpi_fan(struct text_object *obj, char *p, unsigned int p_max_size)
|
||||
while (!feof(fp)) {
|
||||
char line[256];
|
||||
|
||||
if (fgets(line, 255, fp) == nullptr) {
|
||||
break;
|
||||
}
|
||||
if (sscanf(line, "speed: %u", &speed)) {
|
||||
break;
|
||||
}
|
||||
if (fgets(line, 255, fp) == nullptr) { break; }
|
||||
if (sscanf(line, "speed: %u", &speed)) { break; }
|
||||
}
|
||||
} else {
|
||||
CRIT_ERR(nullptr, NULL,
|
||||
@ -140,9 +135,7 @@ int get_ibm_acpi_temps(void) {
|
||||
while (!feof(fp)) {
|
||||
char line[256];
|
||||
|
||||
if (fgets(line, 255, fp) == nullptr) {
|
||||
break;
|
||||
}
|
||||
if (fgets(line, 255, fp) == nullptr) { break; }
|
||||
if (sscanf(line, "temperatures: %d %d %d %d %d %d %d %d",
|
||||
&ibm_acpi_temps[0], &ibm_acpi_temps[1], &ibm_acpi_temps[2],
|
||||
&ibm_acpi_temps[3], &ibm_acpi_temps[4], &ibm_acpi_temps[5],
|
||||
@ -171,7 +164,8 @@ commands: up, down, mute
|
||||
commands: level <level> (<level> is 0-15)
|
||||
* Peter Tarjan (ptarjan@citromail.hu) */
|
||||
|
||||
void get_ibm_acpi_volume(struct text_object *obj, char *p, unsigned int p_max_size) {
|
||||
void get_ibm_acpi_volume(struct text_object *obj, char *p,
|
||||
unsigned int p_max_size) {
|
||||
FILE *fp;
|
||||
char volume[128];
|
||||
unsigned int vol = -1;
|
||||
@ -179,9 +173,7 @@ void get_ibm_acpi_volume(struct text_object *obj, char *p, unsigned int p_max_si
|
||||
|
||||
(void)obj;
|
||||
|
||||
if (!p || p_max_size <= 0) {
|
||||
return;
|
||||
}
|
||||
if (!p || p_max_size <= 0) { return; }
|
||||
|
||||
snprintf(volume, 127, "%s/volume", IBM_ACPI_DIR);
|
||||
|
||||
@ -191,16 +183,12 @@ void get_ibm_acpi_volume(struct text_object *obj, char *p, unsigned int p_max_si
|
||||
char line[256];
|
||||
unsigned int read_vol = -1;
|
||||
|
||||
if (fgets(line, 255, fp) == nullptr) {
|
||||
break;
|
||||
}
|
||||
if (fgets(line, 255, fp) == nullptr) { break; }
|
||||
if (sscanf(line, "level: %u", &read_vol)) {
|
||||
vol = read_vol;
|
||||
continue;
|
||||
}
|
||||
if (sscanf(line, "mute: %s", mute)) {
|
||||
break;
|
||||
}
|
||||
if (sscanf(line, "mute: %s", mute)) { break; }
|
||||
}
|
||||
} else {
|
||||
CRIT_ERR(nullptr, NULL,
|
||||
@ -226,16 +214,15 @@ commands: up, down
|
||||
commands: level <level> (<level> is 0-7)
|
||||
* Peter Tarjan (ptarjan@citromail.hu) */
|
||||
|
||||
void get_ibm_acpi_brightness(struct text_object *obj, char *p, unsigned int p_max_size) {
|
||||
void get_ibm_acpi_brightness(struct text_object *obj, char *p,
|
||||
unsigned int p_max_size) {
|
||||
FILE *fp;
|
||||
unsigned int brightness = 0;
|
||||
char filename[128];
|
||||
|
||||
(void)obj;
|
||||
|
||||
if (!p || p_max_size <= 0) {
|
||||
return;
|
||||
}
|
||||
if (!p || p_max_size <= 0) { return; }
|
||||
|
||||
snprintf(filename, 127, "%s/brightness", IBM_ACPI_DIR);
|
||||
|
||||
@ -244,12 +231,8 @@ void get_ibm_acpi_brightness(struct text_object *obj, char *p, unsigned int p_ma
|
||||
while (!feof(fp)) {
|
||||
char line[256];
|
||||
|
||||
if (fgets(line, 255, fp) == nullptr) {
|
||||
break;
|
||||
}
|
||||
if (sscanf(line, "level: %u", &brightness)) {
|
||||
break;
|
||||
}
|
||||
if (fgets(line, 255, fp) == nullptr) { break; }
|
||||
if (sscanf(line, "level: %u", &brightness)) { break; }
|
||||
}
|
||||
} else {
|
||||
CRIT_ERR(nullptr, NULL,
|
||||
@ -271,16 +254,15 @@ commands: on, off
|
||||
* get "unknown" for a few models that do not make the status available.
|
||||
* Lluis Esquerda (eskerda@gmail.com) */
|
||||
|
||||
void get_ibm_acpi_thinklight(struct text_object *obj, char *p, unsigned int p_max_size) {
|
||||
void get_ibm_acpi_thinklight(struct text_object *obj, char *p,
|
||||
unsigned int p_max_size) {
|
||||
FILE *fp;
|
||||
char thinklight[8];
|
||||
char filename[128];
|
||||
|
||||
(void)obj;
|
||||
|
||||
if (!p || p_max_size <= 0) {
|
||||
return;
|
||||
}
|
||||
if (!p || p_max_size <= 0) { return; }
|
||||
|
||||
snprintf(filename, 127, "%s/light", IBM_ACPI_DIR);
|
||||
|
||||
@ -289,12 +271,8 @@ void get_ibm_acpi_thinklight(struct text_object *obj, char *p, unsigned int p_ma
|
||||
while (!feof(fp)) {
|
||||
char line[256];
|
||||
|
||||
if (fgets(line, 255, fp) == nullptr) {
|
||||
break;
|
||||
}
|
||||
if (sscanf(line, "status: %s", thinklight)) {
|
||||
break;
|
||||
}
|
||||
if (fgets(line, 255, fp) == nullptr) { break; }
|
||||
if (sscanf(line, "status: %s", thinklight)) { break; }
|
||||
}
|
||||
} else {
|
||||
CRIT_ERR(nullptr, NULL,
|
||||
@ -317,6 +295,7 @@ void parse_ibm_temps_arg(struct text_object *obj, const char *arg) {
|
||||
obj->data.l = atoi(arg);
|
||||
}
|
||||
|
||||
void print_ibm_temps(struct text_object *obj, char *p, unsigned int p_max_size) {
|
||||
void print_ibm_temps(struct text_object *obj, char *p,
|
||||
unsigned int p_max_size) {
|
||||
temp_print(p, p_max_size, ibm_acpi_temps[obj->data.l], TEMP_CELSIUS, 1);
|
||||
}
|
||||
|
@ -44,13 +44,9 @@ static iconv_t **iconv_cd = 0;
|
||||
|
||||
int register_iconv(iconv_t *new_iconv) {
|
||||
iconv_cd = (void ***)realloc(iconv_cd, sizeof(iconv_t *) * (iconv_count + 1));
|
||||
if (!iconv_cd) {
|
||||
CRIT_ERR(nullptr, NULL, "Out of memory");
|
||||
}
|
||||
if (!iconv_cd) { CRIT_ERR(nullptr, NULL, "Out of memory"); }
|
||||
iconv_cd[iconv_count] = (void **)malloc(sizeof(iconv_t));
|
||||
if (!iconv_cd[iconv_count]) {
|
||||
CRIT_ERR(nullptr, NULL, "Out of memory");
|
||||
}
|
||||
if (!iconv_cd[iconv_count]) { CRIT_ERR(nullptr, NULL, "Out of memory"); }
|
||||
memcpy(iconv_cd[iconv_count], new_iconv, sizeof(iconv_t));
|
||||
iconv_count++;
|
||||
return iconv_count;
|
||||
@ -135,7 +131,8 @@ void init_iconv_start(struct text_object *obj, void *free_at_crash,
|
||||
|
||||
void init_iconv_stop(void) { iconv_converting = 0; }
|
||||
|
||||
void print_iconv_start(struct text_object *obj, char *p, unsigned int p_max_size) {
|
||||
void print_iconv_start(struct text_object *obj, char *p,
|
||||
unsigned int p_max_size) {
|
||||
(void)p;
|
||||
(void)p_max_size;
|
||||
|
||||
@ -143,7 +140,8 @@ void print_iconv_start(struct text_object *obj, char *p, unsigned int p_max_size
|
||||
iconv_selected = obj->data.i;
|
||||
}
|
||||
|
||||
void print_iconv_stop(struct text_object *obj, char *p, unsigned int p_max_size) {
|
||||
void print_iconv_stop(struct text_object *obj, char *p,
|
||||
unsigned int p_max_size) {
|
||||
(void)obj;
|
||||
(void)p;
|
||||
(void)p_max_size;
|
||||
|
@ -62,8 +62,7 @@ conky::range_config_setting<unsigned int> imlib_cache_flush_interval(
|
||||
|
||||
unsigned int cimlib_cache_flush_last = 0;
|
||||
|
||||
conky::simple_config_setting<bool> draw_blended(
|
||||
"draw_blended", true, true);
|
||||
conky::simple_config_setting<bool> draw_blended("draw_blended", true, true);
|
||||
} // namespace
|
||||
|
||||
void imlib_cache_size_setting::lua_setter(lua::state &l, bool init) {
|
||||
@ -123,7 +122,7 @@ void cimlib_add_image(const char *args) {
|
||||
"Invalid args for $image. Format is: '<path to image> (-p"
|
||||
"x,y) (-s WxH) (-n) (-f interval)' (got '%s')",
|
||||
args);
|
||||
delete [] cur;
|
||||
delete[] cur;
|
||||
return;
|
||||
}
|
||||
strncpy(cur->name, to_real_path(cur->name).c_str(), 1024);
|
||||
@ -138,22 +137,16 @@ void cimlib_add_image(const char *args) {
|
||||
tmp = strstr(args, "-s ");
|
||||
if (tmp != nullptr) {
|
||||
tmp += 3;
|
||||
if (sscanf(tmp, "%ix%i", &cur->w, &cur->h) != 0) {
|
||||
cur->wh_set = 1;
|
||||
}
|
||||
if (sscanf(tmp, "%ix%i", &cur->w, &cur->h) != 0) { cur->wh_set = 1; }
|
||||
}
|
||||
|
||||
tmp = strstr(args, "-n");
|
||||
if (tmp != nullptr) {
|
||||
cur->no_cache = 1;
|
||||
}
|
||||
if (tmp != nullptr) { cur->no_cache = 1; }
|
||||
|
||||
tmp = strstr(args, "-f ");
|
||||
if (tmp != nullptr) {
|
||||
tmp += 3;
|
||||
if (sscanf(tmp, "%d", &cur->flush_interval) != 0) {
|
||||
cur->no_cache = 0;
|
||||
}
|
||||
if (sscanf(tmp, "%d", &cur->flush_interval) != 0) { cur->no_cache = 0; }
|
||||
}
|
||||
if (cur->flush_interval < 0) {
|
||||
NORM_ERR("Imlib2: flush interval should be >= 0");
|
||||
@ -180,9 +173,7 @@ static void cimlib_draw_image(struct image_list_s *cur, int *clip_x,
|
||||
|
||||
image = imlib_load_image(cur->name);
|
||||
if (image == nullptr) {
|
||||
if (rep == 0) {
|
||||
NORM_ERR("Unable to load image '%s'", cur->name);
|
||||
}
|
||||
if (rep == 0) { NORM_ERR("Unable to load image '%s'", cur->name); }
|
||||
rep = 1;
|
||||
return;
|
||||
}
|
||||
@ -213,18 +204,10 @@ static void cimlib_draw_image(struct image_list_s *cur, int *clip_x,
|
||||
} else {
|
||||
imlib_free_image();
|
||||
}
|
||||
if (cur->x < *clip_x) {
|
||||
*clip_x = cur->x;
|
||||
}
|
||||
if (cur->y < *clip_y) {
|
||||
*clip_y = cur->y;
|
||||
}
|
||||
if (cur->x + cur->w > *clip_x2) {
|
||||
*clip_x2 = cur->x + cur->w;
|
||||
}
|
||||
if (cur->y + cur->h > *clip_y2) {
|
||||
*clip_y2 = cur->y + cur->h;
|
||||
}
|
||||
if (cur->x < *clip_x) { *clip_x = cur->x; }
|
||||
if (cur->y < *clip_y) { *clip_y = cur->y; }
|
||||
if (cur->x + cur->w > *clip_x2) { *clip_x2 = cur->x + cur->w; }
|
||||
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,
|
||||
@ -280,12 +263,8 @@ void cimlib_render(int x, int y, int width, int height) {
|
||||
imlib_context_set_image(buffer);
|
||||
|
||||
/* setup our clip rect */
|
||||
if (clip_x == INT_MAX) {
|
||||
clip_x = 0;
|
||||
}
|
||||
if (clip_y == INT_MAX) {
|
||||
clip_y = 0;
|
||||
}
|
||||
if (clip_x == INT_MAX) { clip_x = 0; }
|
||||
if (clip_y == INT_MAX) { clip_y = 0; }
|
||||
|
||||
/* render the image at 0, 0 */
|
||||
imlib_render_image_part_on_drawable_at_size(
|
||||
@ -295,7 +274,6 @@ void cimlib_render(int x, int y, int width, int height) {
|
||||
imlib_free_image();
|
||||
}
|
||||
|
||||
void print_image_callback(struct text_object *obj, char *,
|
||||
unsigned int) {
|
||||
void print_image_callback(struct text_object *obj, char *, unsigned int) {
|
||||
cimlib_add_image(obj->data.s);
|
||||
}
|
||||
|
@ -114,7 +114,8 @@ struct _tcp_port_monitor_t {
|
||||
|
||||
_tcp_port_monitor_t(int max_connections)
|
||||
: hash(),
|
||||
p_peek(max_connections, static_cast<const tcp_connection_t *>(nullptr)) {}
|
||||
p_peek(max_connections,
|
||||
static_cast<const tcp_connection_t *>(nullptr)) {}
|
||||
|
||||
_tcp_port_monitor_t(const _tcp_port_monitor_t &other)
|
||||
: hash(other.hash),
|
||||
@ -202,9 +203,7 @@ void show_connection_to_tcp_port_monitor(monitor_hash_t::value_type &monitor,
|
||||
|
||||
tcp_connection_t *p_connection;
|
||||
|
||||
if (!p_void) {
|
||||
return;
|
||||
}
|
||||
if (!p_void) { return; }
|
||||
|
||||
/* This p_connection is on caller's stack and not the heap.
|
||||
* If we are interested, we will create a copy of the connection
|
||||
@ -242,9 +241,7 @@ void show_connection_to_tcp_port_monitor(monitor_hash_t::value_type &monitor,
|
||||
void for_each_tcp_port_monitor_in_collection(
|
||||
tcp_port_monitor_collection_t *p_collection,
|
||||
tcp_port_monitor_function_ptr_t p_function, void *p_function_args) {
|
||||
if (!p_collection || !p_function) {
|
||||
return;
|
||||
}
|
||||
if (!p_collection || !p_function) { return; }
|
||||
|
||||
/* for each monitor in the collection */
|
||||
for (monitor_hash_t::iterator i = p_collection->hash.begin();
|
||||
@ -318,9 +315,7 @@ void process_file(tcp_port_monitor_collection_t *p_collection,
|
||||
tcp_connection_t conn;
|
||||
unsigned long inode, uid, state;
|
||||
|
||||
if ((fp = std::fopen(file, "r")) == nullptr) {
|
||||
return;
|
||||
}
|
||||
if ((fp = std::fopen(file, "r")) == nullptr) { return; }
|
||||
|
||||
/* ignore field name line */
|
||||
if (std::fgets(buf, 255, fp) == nullptr) {
|
||||
@ -340,9 +335,7 @@ void process_file(tcp_port_monitor_collection_t *p_collection,
|
||||
}
|
||||
/** TCP_ESTABLISHED equals 1, but is not (always??) included **/
|
||||
// if ((inode == 0) || (state != TCP_ESTABLISHED)) {
|
||||
if ((inode == 0) || (state != 1)) {
|
||||
continue;
|
||||
}
|
||||
if ((inode == 0) || (state != 1)) { continue; }
|
||||
|
||||
string_to_addr(&conn.local_addr, local_addr);
|
||||
string_to_addr(&conn.remote_addr, remote_addr);
|
||||
@ -375,9 +368,7 @@ int peek_tcp_port_monitor(const tcp_port_monitor_t *p_monitor, int item,
|
||||
size_t buffer_size) {
|
||||
struct sockaddr_in sa;
|
||||
|
||||
if (!p_monitor || !p_buffer || connection_index < 0) {
|
||||
return -1;
|
||||
}
|
||||
if (!p_monitor || !p_buffer || connection_index < 0) { return -1; }
|
||||
|
||||
std::memset(p_buffer, 0, buffer_size);
|
||||
std::memset(&sa, 0, sizeof(sa));
|
||||
@ -419,8 +410,8 @@ int peek_tcp_port_monitor(const tcp_port_monitor_t *p_monitor, int item,
|
||||
case REMOTESERVICE:
|
||||
|
||||
sa.sin_port = htons(p_monitor->p_peek[connection_index]->remote_port);
|
||||
getnameinfo((struct sockaddr *)&sa, sizeof(struct sockaddr_in), nullptr, 0,
|
||||
p_buffer, buffer_size, NI_NUMERICHOST);
|
||||
getnameinfo((struct sockaddr *)&sa, sizeof(struct sockaddr_in), nullptr,
|
||||
0, p_buffer, buffer_size, NI_NUMERICHOST);
|
||||
break;
|
||||
|
||||
case LOCALIP:
|
||||
@ -444,8 +435,8 @@ int peek_tcp_port_monitor(const tcp_port_monitor_t *p_monitor, int item,
|
||||
case LOCALSERVICE:
|
||||
|
||||
sa.sin_port = htons(p_monitor->p_peek[connection_index]->local_port);
|
||||
getnameinfo((struct sockaddr *)&sa, sizeof(struct sockaddr_in), nullptr, 0,
|
||||
p_buffer, buffer_size, NI_NUMERICHOST);
|
||||
getnameinfo((struct sockaddr *)&sa, sizeof(struct sockaddr_in), nullptr,
|
||||
0, p_buffer, buffer_size, NI_NUMERICHOST);
|
||||
break;
|
||||
|
||||
default:
|
||||
@ -474,9 +465,7 @@ void destroy_tcp_port_monitor_collection(
|
||||
/* Updates the tcp statistics for all monitors within a collection */
|
||||
void update_tcp_port_monitor_collection(
|
||||
tcp_port_monitor_collection_t *p_collection) {
|
||||
if (!p_collection) {
|
||||
return;
|
||||
}
|
||||
if (!p_collection) { return; }
|
||||
|
||||
process_file(p_collection, "/proc/net/tcp");
|
||||
process_file(p_collection, "/proc/net/tcp6");
|
||||
@ -495,9 +484,7 @@ void update_tcp_port_monitor_collection(
|
||||
int insert_new_tcp_port_monitor_into_collection(
|
||||
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) {
|
||||
if (!p_collection) {
|
||||
return -1;
|
||||
}
|
||||
if (!p_collection) { return -1; }
|
||||
|
||||
p_collection->hash.insert(monitor_hash_t::value_type(
|
||||
port_range_t(port_range_begin, port_range_end),
|
||||
@ -510,9 +497,7 @@ int insert_new_tcp_port_monitor_into_collection(
|
||||
tcp_port_monitor_t *find_tcp_port_monitor(
|
||||
tcp_port_monitor_collection_t *p_collection, in_port_t port_range_begin,
|
||||
in_port_t port_range_end) {
|
||||
if (!p_collection) {
|
||||
return nullptr;
|
||||
}
|
||||
if (!p_collection) { return nullptr; }
|
||||
|
||||
/* is monitor in hash? */
|
||||
monitor_hash_t::iterator i =
|
||||
|
18
src/linux.cc
18
src/linux.cc
@ -1126,8 +1126,7 @@ static int get_first_file_in_a_directory(const char *dir, char *s, int *rep) {
|
||||
/*
|
||||
* Convert @dev "0" (hwmon number) or "k10temp" (hwmon name) to "hwmon2/device"
|
||||
*/
|
||||
static void get_dev_path(const char *dir, const char *dev, char *out_buf)
|
||||
{
|
||||
static void get_dev_path(const char *dir, const char *dev, char *out_buf) {
|
||||
struct dirent **namelist;
|
||||
char path[256] = {'\0'};
|
||||
char name[256] = {'\0'};
|
||||
@ -1151,18 +1150,15 @@ static void get_dev_path(const char *dir, const char *dev, char *out_buf)
|
||||
NORM_ERR("scandir for %s: %s", dir, strerror(errno));
|
||||
goto not_found;
|
||||
}
|
||||
if (n == 0)
|
||||
goto not_found;
|
||||
if (n == 0) goto not_found;
|
||||
|
||||
/* Search each hwmon%s/name */
|
||||
for (i = 0; i < n; i++) {
|
||||
if (found)
|
||||
continue;
|
||||
if (found) continue;
|
||||
|
||||
snprintf(path, 256, "%s%s/name", dir, namelist[i]->d_name);
|
||||
name_fd = open(path, O_RDONLY);
|
||||
if (name_fd < 0)
|
||||
continue;
|
||||
if (name_fd < 0) continue;
|
||||
size = read(name_fd, name, strlen(dev));
|
||||
if (size < strlen(dev)) {
|
||||
close(name_fd);
|
||||
@ -1177,11 +1173,9 @@ static void get_dev_path(const char *dir, const char *dev, char *out_buf)
|
||||
}
|
||||
|
||||
/* cleanup */
|
||||
for (i = 0; i < n; i++)
|
||||
free(namelist[i]);
|
||||
for (i = 0; i < n; i++) free(namelist[i]);
|
||||
free(namelist);
|
||||
if (found)
|
||||
return;
|
||||
if (found) return;
|
||||
|
||||
not_found:
|
||||
out_buf[0] = '\0';
|
||||
|
64
src/luamm.cc
64
src/luamm.cc
@ -49,14 +49,12 @@ const char this_cpp_object[] = "lua::this_cpp_object";
|
||||
|
||||
// converts C++ exceptions to strings, so lua can do something with them
|
||||
int exception_to_string(lua_State *l) {
|
||||
auto *ptr = static_cast<std::exception_ptr *>(lua_touserdata(l, -1));
|
||||
assert(ptr);
|
||||
try {
|
||||
std::rethrow_exception(*ptr);
|
||||
} catch (std::exception &e) {
|
||||
lua_pushstring(l, e.what());
|
||||
} catch (...) {
|
||||
lua_pushstring(l, typeid(*ptr).name());
|
||||
auto *ptr = static_cast<std::exception_ptr *>(lua_touserdata(l, -1));
|
||||
assert(ptr);
|
||||
try {
|
||||
std::rethrow_exception(*ptr);
|
||||
} catch (std::exception &e) { lua_pushstring(l, e.what()); } catch (...) {
|
||||
lua_pushstring(l, typeid(*ptr).name());
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
@ -68,12 +66,9 @@ int absindex(lua_State *l, int index) {
|
||||
|
||||
// Just like getfield(), only without calling metamethods (or throwing random
|
||||
// exceptions)
|
||||
inline void rawgetfield(lua_State *l, int index,
|
||||
const char *k) {
|
||||
inline void rawgetfield(lua_State *l, int index, const char *k) {
|
||||
index = absindex(l, index);
|
||||
if (lua_checkstack(l, 1) == 0) {
|
||||
throw std::bad_alloc();
|
||||
}
|
||||
if (lua_checkstack(l, 1) == 0) { throw std::bad_alloc(); }
|
||||
|
||||
lua_pushstring(l, k);
|
||||
lua_rawget(l, index);
|
||||
@ -81,12 +76,9 @@ inline void rawgetfield(lua_State *l, int index,
|
||||
|
||||
// Just like setfield(), only without calling metamethods (or throwing random
|
||||
// exceptions)
|
||||
inline void rawsetfield(lua_State *l, int index,
|
||||
const char *k) {
|
||||
inline void rawsetfield(lua_State *l, int index, const char *k) {
|
||||
index = absindex(l, index);
|
||||
if (lua_checkstack(l, 2) == 0) {
|
||||
throw std::bad_alloc();
|
||||
}
|
||||
if (lua_checkstack(l, 2) == 0) { throw std::bad_alloc(); }
|
||||
|
||||
lua_pushstring(l, k);
|
||||
lua_insert(l, -2);
|
||||
@ -130,9 +122,7 @@ int closure_trampoline(lua_State *l) {
|
||||
* execute everything in protected mode).
|
||||
*/
|
||||
int panic_throw(lua_State *l) {
|
||||
if (lua_checkstack(l, 1) == 0) {
|
||||
throw std::bad_alloc();
|
||||
}
|
||||
if (lua_checkstack(l, 1) == 0) { throw std::bad_alloc(); }
|
||||
|
||||
rawgetfield(l, REGISTRYINDEX, this_cpp_object);
|
||||
assert(lua_islightuserdata(l, -1));
|
||||
@ -191,9 +181,7 @@ std::string exception::get_error_msg(state *L) {
|
||||
|
||||
try {
|
||||
return L->tostring(-1);
|
||||
} catch (not_string_error &e) {
|
||||
return default_msg;
|
||||
}
|
||||
} catch (not_string_error &e) { return default_msg; }
|
||||
}
|
||||
|
||||
exception::exception(state *l) : std::runtime_error(get_error_msg(l)), L(l) {
|
||||
@ -206,9 +194,7 @@ exception::exception(state *l) : std::runtime_error(get_error_msg(l)), L(l) {
|
||||
}
|
||||
|
||||
exception::~exception() {
|
||||
if (L == nullptr) {
|
||||
return;
|
||||
}
|
||||
if (L == nullptr) { return; }
|
||||
L->checkstack(1);
|
||||
|
||||
L->rawgetfield(REGISTRYINDEX, lua_exception_namespace);
|
||||
@ -272,9 +258,7 @@ state::state() {
|
||||
|
||||
void state::call(int nargs, int nresults, int errfunc) {
|
||||
int r = lua_pcall(cobj.get(), nargs, nresults, errfunc);
|
||||
if (r == 0) {
|
||||
return;
|
||||
}
|
||||
if (r == 0) { return; }
|
||||
|
||||
if (r == LUA_ERRMEM) {
|
||||
// memory allocation error, cross your fingers
|
||||
@ -301,16 +285,12 @@ void state::call(int nargs, int nresults, int errfunc) {
|
||||
pop(2);
|
||||
}
|
||||
// it's a lua exception, wrap it
|
||||
if (r == LUA_ERRERR) {
|
||||
throw lua::errfunc_error(this);
|
||||
}
|
||||
if (r == LUA_ERRERR) { throw lua::errfunc_error(this); }
|
||||
{ throw lua::exception(this); }
|
||||
}
|
||||
|
||||
void state::checkstack(int extra) {
|
||||
if (lua_checkstack(cobj.get(), extra) == 0) {
|
||||
throw std::bad_alloc();
|
||||
}
|
||||
if (lua_checkstack(cobj.get(), extra) == 0) { throw std::bad_alloc(); }
|
||||
}
|
||||
|
||||
void state::concat(int n) {
|
||||
@ -323,9 +303,7 @@ void state::concat(int n) {
|
||||
|
||||
bool state::equal(int index1, int index2) {
|
||||
// avoid pcall overhead in trivial cases
|
||||
if (rawequal(index1, index2)) {
|
||||
return true;
|
||||
}
|
||||
if (rawequal(index1, index2)) { return true; }
|
||||
|
||||
return safe_compare(&safe_compare_trampoline<lua_equal>, index1, index2);
|
||||
}
|
||||
@ -438,9 +416,7 @@ void state::rawsetfield(int index, const char *k) {
|
||||
|
||||
bool state::safe_compare(lua_CFunction trampoline, int index1, int index2) {
|
||||
// if one of the indexes is invalid, return false
|
||||
if (isnone(index1) || isnone(index2)) {
|
||||
return false;
|
||||
}
|
||||
if (isnone(index1) || isnone(index2)) { return false; }
|
||||
|
||||
// convert relative indexes into absolute
|
||||
index1 = absindex(index1);
|
||||
@ -491,9 +467,7 @@ void state::settable(int index) {
|
||||
std::string state::tostring(int index) {
|
||||
size_t len;
|
||||
const char *str = lua_tolstring(cobj.get(), index, &len);
|
||||
if (str == nullptr) {
|
||||
throw not_string_error();
|
||||
}
|
||||
if (str == nullptr) { throw not_string_error(); }
|
||||
return std::string(str, len);
|
||||
}
|
||||
} // namespace lua
|
||||
|
12
src/luamm.hh
12
src/luamm.hh
@ -152,8 +152,7 @@ class state : private std::mutex {
|
||||
// throwing exceptions in destructors is a bad idea
|
||||
// but we catch (and ignore) them, just in case
|
||||
ptr->~T();
|
||||
} catch (...) {
|
||||
}
|
||||
} catch (...) {}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -305,9 +304,9 @@ class state : private std::mutex {
|
||||
void setfield(int index, const char *k);
|
||||
void setglobal(const char *name);
|
||||
void settable(int index);
|
||||
// lua_tostring uses nullptr to indicate conversion error, since there is no such
|
||||
// thing as a nullptr std::string, we throw an exception. Returned value may
|
||||
// contain '\0'
|
||||
// lua_tostring uses nullptr to indicate conversion error, since there is no
|
||||
// such thing as a nullptr std::string, we throw an exception. Returned value
|
||||
// may contain '\0'
|
||||
std::string tostring(int index);
|
||||
// allocate a new lua userdata of appropriate size, and create a object in it
|
||||
// pushes the userdata on stack and returns the pointer
|
||||
@ -343,8 +342,7 @@ class stack_sentry {
|
||||
const stack_sentry &operator=(const stack_sentry &) = delete;
|
||||
|
||||
public:
|
||||
explicit stack_sentry(state &l, int n_ = 0)
|
||||
: L(&l), n(l.gettop() + n_) {
|
||||
explicit stack_sentry(state &l, int n_ = 0) : L(&l), n(l.gettop() + n_) {
|
||||
assert(n >= 0);
|
||||
}
|
||||
|
||||
|
@ -181,8 +181,8 @@ static void print_version() {
|
||||
<< _(" * Own window\n")
|
||||
#endif
|
||||
#endif /* BUILD_X11 */
|
||||
#if defined BUILD_AUDACIOUS || defined BUILD_CMUS || \
|
||||
defined BUILD_MPD || defined BUILD_MOC || defined BUILD_XMMS2
|
||||
#if defined BUILD_AUDACIOUS || defined BUILD_CMUS || defined BUILD_MPD || \
|
||||
defined BUILD_MOC || defined BUILD_XMMS2
|
||||
<< _("\n Music detection:\n")
|
||||
#endif
|
||||
#ifdef BUILD_AUDACIOUS
|
||||
|
@ -86,9 +86,7 @@ static void mbox_scan(char *args, char *output, size_t max_len) {
|
||||
} else {
|
||||
print_num_mails = PRINT_MAILS;
|
||||
}
|
||||
if (print_num_mails < 1) {
|
||||
print_num_mails = 1;
|
||||
}
|
||||
if (print_num_mails < 1) { print_num_mails = 1; }
|
||||
|
||||
substr = strstr(args, "-t");
|
||||
if (substr != nullptr) {
|
||||
@ -131,9 +129,7 @@ static void mbox_scan(char *args, char *output, size_t max_len) {
|
||||
|
||||
while (tmp != nullptr) {
|
||||
tmp = strtok(nullptr, " ");
|
||||
if (tmp != nullptr) {
|
||||
start = tmp;
|
||||
}
|
||||
if (tmp != nullptr) { start = tmp; }
|
||||
}
|
||||
strncpy(mbox_mail_spool, start, DEFAULT_TEXT_BUFFER_SIZE);
|
||||
free(copy_args);
|
||||
@ -189,9 +185,7 @@ static void mbox_scan(char *args, char *output, size_t max_len) {
|
||||
curr->from[0] = '\0';
|
||||
curr->subject[0] = '\0';
|
||||
|
||||
if (i == 0) {
|
||||
startlist = curr;
|
||||
}
|
||||
if (i == 0) { startlist = curr; }
|
||||
if (i > 0) {
|
||||
curr->previous = prev;
|
||||
prev->next = curr;
|
||||
@ -199,34 +193,26 @@ static void mbox_scan(char *args, char *output, size_t max_len) {
|
||||
prev = curr;
|
||||
}
|
||||
|
||||
if (startlist == nullptr) {
|
||||
return;
|
||||
}
|
||||
if (startlist == nullptr) { return; }
|
||||
/* connect end to start for an endless loop-ring */
|
||||
startlist->previous = curr;
|
||||
curr->next = startlist;
|
||||
|
||||
/* mbox */
|
||||
fp = fopen(mbox_mail_spool, "re");
|
||||
if (fp == nullptr) {
|
||||
return;
|
||||
}
|
||||
if (fp == nullptr) { return; }
|
||||
|
||||
/* first find a "From " to set it to 0 for header-sarchings */
|
||||
flag = 1;
|
||||
while (feof(fp) == 0) {
|
||||
if (fgets(buf, text_buffer_size.get(*state), fp) == nullptr) {
|
||||
break;
|
||||
}
|
||||
if (fgets(buf, text_buffer_size.get(*state), fp) == nullptr) { break; }
|
||||
|
||||
if (strncmp(buf, "From ", 5) == 0) {
|
||||
curr = curr->next;
|
||||
|
||||
/* skip until \n */
|
||||
while (strchr(buf, '\n') == nullptr && (feof(fp) == 0)) {
|
||||
if (fgets(buf, text_buffer_size.get(*state), fp) == nullptr) {
|
||||
break;
|
||||
}
|
||||
if (fgets(buf, text_buffer_size.get(*state), fp) == nullptr) { break; }
|
||||
}
|
||||
|
||||
flag = 0; /* in the headers now */
|
||||
@ -242,9 +228,7 @@ static void mbox_scan(char *args, char *output, size_t max_len) {
|
||||
/* then search for new mail ("From ") */
|
||||
|
||||
while (strchr(buf, '\n') == nullptr && (feof(fp) == 0)) {
|
||||
if (fgets(buf, text_buffer_size.get(*state), fp) == nullptr) {
|
||||
break;
|
||||
}
|
||||
if (fgets(buf, text_buffer_size.get(*state), fp) == nullptr) { break; }
|
||||
}
|
||||
flag = 1; /* in the body now */
|
||||
continue;
|
||||
@ -260,9 +244,7 @@ static void mbox_scan(char *args, char *output, size_t max_len) {
|
||||
curr = curr->previous;
|
||||
/* Skip until \n */
|
||||
while (strchr(buf, '\n') == nullptr && (feof(fp) == 0)) {
|
||||
if (fgets(buf, text_buffer_size.get(*state), fp) == nullptr) {
|
||||
break;
|
||||
}
|
||||
if (fgets(buf, text_buffer_size.get(*state), fp) == nullptr) { break; }
|
||||
}
|
||||
continue;
|
||||
}
|
||||
@ -398,9 +380,7 @@ void parse_mboxscan_arg(struct text_object *obj, const char *arg) {
|
||||
void print_mboxscan(struct text_object *obj, char *p, unsigned int p_max_size) {
|
||||
auto *msd = static_cast<mboxscan_data *>(obj->data.opaque);
|
||||
|
||||
if (msd == nullptr) {
|
||||
return;
|
||||
}
|
||||
if (msd == nullptr) { return; }
|
||||
|
||||
mbox_scan(msd->args, msd->output, text_buffer_size.get(*state));
|
||||
snprintf(p, p_max_size, "%s", msd->output);
|
||||
@ -409,9 +389,7 @@ void print_mboxscan(struct text_object *obj, char *p, unsigned int p_max_size) {
|
||||
void free_mboxscan(struct text_object *obj) {
|
||||
auto *msd = static_cast<mboxscan_data *>(obj->data.opaque);
|
||||
|
||||
if (msd == nullptr) {
|
||||
return;
|
||||
}
|
||||
if (msd == nullptr) { return; }
|
||||
free_and_zero(msd->args);
|
||||
free_and_zero(msd->output);
|
||||
free_and_zero(obj->data.opaque);
|
||||
|
12
src/mixer.cc
12
src/mixer.cc
@ -59,9 +59,7 @@ static const char *devs[] = SOUND_DEVICE_NAMES;
|
||||
int mixer_init(const char *name) {
|
||||
unsigned int i;
|
||||
|
||||
if (name == 0 || name[0] == '\0') {
|
||||
name = "vol";
|
||||
}
|
||||
if (name == 0 || name[0] == '\0') { name = "vol"; }
|
||||
|
||||
/* open mixer */
|
||||
if (mixer_fd <= 0) {
|
||||
@ -73,9 +71,7 @@ int mixer_init(const char *name) {
|
||||
}
|
||||
|
||||
for (i = 0; i < sizeof(devs) / sizeof(const char *); i++) {
|
||||
if (strcasecmp(devs[i], name) == 0) {
|
||||
return i;
|
||||
}
|
||||
if (strcasecmp(devs[i], name) == 0) { return i; }
|
||||
}
|
||||
|
||||
return -1;
|
||||
@ -86,9 +82,7 @@ static int mixer_get(int i) {
|
||||
int val = -1;
|
||||
|
||||
if (ioctl(mixer_fd, MIXER_READ(i), &val) == -1) {
|
||||
if (!rep) {
|
||||
NORM_ERR("mixer ioctl: %s", strerror(errno));
|
||||
}
|
||||
if (!rep) { NORM_ERR("mixer ioctl: %s", strerror(errno)); }
|
||||
rep = 1;
|
||||
return 0;
|
||||
}
|
||||
|
10
src/moc.cc
10
src/moc.cc
@ -70,12 +70,8 @@ void moc_cb::work() {
|
||||
char *p;
|
||||
|
||||
/* Read a line from the pipe and strip the possible '\n'. */
|
||||
if (fgets(line, 100, fp) == nullptr) {
|
||||
break;
|
||||
}
|
||||
if ((p = strrchr(line, '\n')) != nullptr) {
|
||||
*p = '\0';
|
||||
}
|
||||
if (fgets(line, 100, fp) == nullptr) { break; }
|
||||
if ((p = strrchr(line, '\n')) != nullptr) { *p = '\0'; }
|
||||
|
||||
/* Parse infos. */
|
||||
if (strncmp(line, "State:", 6) == 0) {
|
||||
@ -113,7 +109,7 @@ void moc_cb::work() {
|
||||
|
||||
#define MOC_PRINT_GENERATOR(type, alt) \
|
||||
void print_moc_##type(struct text_object *obj, char *p, \
|
||||
unsigned int p_max_size) { \
|
||||
unsigned int p_max_size) { \
|
||||
(void)obj; \
|
||||
uint32_t period = std::max( \
|
||||
lround(music_player_interval.get(*state) / active_update_interval()), \
|
||||
|
42
src/mpd.cc
42
src/mpd.cc
@ -27,13 +27,13 @@
|
||||
*/
|
||||
|
||||
#include "mpd.h"
|
||||
#include <cmath>
|
||||
#include <mutex>
|
||||
#include "conky.h"
|
||||
#include "libmpdclient.h"
|
||||
#include "logging.h"
|
||||
#include "timeinfo.h"
|
||||
#include "update-cb.hh"
|
||||
#include <cmath>
|
||||
#include <mutex>
|
||||
|
||||
namespace {
|
||||
|
||||
@ -61,9 +61,7 @@ void mpd_host_setting::lua_setter(lua::state &l, bool init) {
|
||||
l.checkstack(1);
|
||||
const char *h = strchr(t, '@');
|
||||
if (h != nullptr) {
|
||||
if (h[1] != 0) {
|
||||
l.pushstring(h + 1);
|
||||
}
|
||||
if (h[1] != 0) { l.pushstring(h + 1); }
|
||||
} else {
|
||||
l.pushstring(t);
|
||||
}
|
||||
@ -147,9 +145,7 @@ class mpd_cb : public conky::callback<mpd_result> {
|
||||
: Base(period, false, Tuple()), conn(nullptr) {}
|
||||
|
||||
~mpd_cb() override {
|
||||
if (conn != nullptr) {
|
||||
mpd_closeConnection(conn);
|
||||
}
|
||||
if (conn != nullptr) { mpd_closeConnection(conn); }
|
||||
}
|
||||
};
|
||||
|
||||
@ -234,9 +230,9 @@ void mpd_cb::work() {
|
||||
mpd_info.is_playing = 1;
|
||||
mpd_info.bitrate = status->bitRate;
|
||||
mpd_info.progress =
|
||||
((0 != status->totalTime) ?
|
||||
static_cast<float>(status->elapsedTime) / status->totalTime
|
||||
: 0.0);
|
||||
((0 != status->totalTime)
|
||||
? static_cast<float>(status->elapsedTime) / status->totalTime
|
||||
: 0.0);
|
||||
mpd_info.elapsed = status->elapsedTime;
|
||||
mpd_info.length = status->totalTime;
|
||||
} else {
|
||||
@ -335,12 +331,14 @@ static inline void format_media_player_time(char *buf, const int size,
|
||||
}
|
||||
}
|
||||
|
||||
void print_mpd_elapsed(struct text_object *obj, char *p, unsigned int p_max_size) {
|
||||
void print_mpd_elapsed(struct text_object *obj, char *p,
|
||||
unsigned int p_max_size) {
|
||||
(void)obj;
|
||||
format_media_player_time(p, p_max_size, get_mpd().elapsed);
|
||||
}
|
||||
|
||||
void print_mpd_length(struct text_object *obj, char *p, unsigned int p_max_size) {
|
||||
void print_mpd_length(struct text_object *obj, char *p,
|
||||
unsigned int p_max_size) {
|
||||
(void)obj;
|
||||
format_media_player_time(p, p_max_size, get_mpd().length);
|
||||
}
|
||||
@ -355,12 +353,11 @@ double mpd_barval(struct text_object *obj) {
|
||||
return get_mpd().progress;
|
||||
}
|
||||
|
||||
void print_mpd_smart(struct text_object *obj, char *p, unsigned int p_max_size) {
|
||||
void print_mpd_smart(struct text_object *obj, char *p,
|
||||
unsigned int p_max_size) {
|
||||
const mpd_result &mpd_info = get_mpd();
|
||||
int len = obj->data.i;
|
||||
if (len == 0 || (unsigned int) len > p_max_size) {
|
||||
len = p_max_size;
|
||||
}
|
||||
if (len == 0 || (unsigned int)len > p_max_size) { len = p_max_size; }
|
||||
|
||||
memset(p, 0, p_max_size);
|
||||
if ((static_cast<unsigned int>(!mpd_info.artist.empty()) != 0u) &&
|
||||
@ -383,11 +380,12 @@ int check_mpd_playing(struct text_object *obj) {
|
||||
return get_mpd().is_playing;
|
||||
}
|
||||
|
||||
#define MPD_PRINT_GENERATOR(name, fmt, acc) \
|
||||
void print_mpd_##name(struct text_object *obj, char *p, \
|
||||
unsigned int p_max_size) { \
|
||||
if (obj->data.i && (unsigned int) obj->data.i < p_max_size) p_max_size = obj->data.i; \
|
||||
snprintf(p, p_max_size, fmt, get_mpd().name acc); \
|
||||
#define MPD_PRINT_GENERATOR(name, fmt, acc) \
|
||||
void print_mpd_##name(struct text_object *obj, char *p, \
|
||||
unsigned int p_max_size) { \
|
||||
if (obj->data.i && (unsigned int)obj->data.i < p_max_size) \
|
||||
p_max_size = obj->data.i; \
|
||||
snprintf(p, p_max_size, fmt, get_mpd().name acc); \
|
||||
}
|
||||
|
||||
MPD_PRINT_GENERATOR(title, "%s", .c_str())
|
||||
|
@ -26,9 +26,9 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "mysql.h"
|
||||
#include "conky.h"
|
||||
#include "logging.h"
|
||||
#include "mysql.h"
|
||||
|
||||
#include <mysql.h>
|
||||
|
||||
|
@ -52,9 +52,7 @@ void out_to_ncurses_setting::lua_setter(lua::state &l, bool init) {
|
||||
void out_to_ncurses_setting::cleanup(lua::state &l) {
|
||||
lua::stack_sentry s(l, -1);
|
||||
|
||||
if (do_convert(l, -1).first) {
|
||||
endwin();
|
||||
}
|
||||
if (do_convert(l, -1).first) { endwin(); }
|
||||
|
||||
l.pop();
|
||||
}
|
||||
|
@ -31,7 +31,7 @@
|
||||
#define NVIDIA_CONKY_H
|
||||
|
||||
int set_nvidia_query(struct text_object *, const char *, unsigned int);
|
||||
void print_nvidia_value(struct text_object *, char *,unsigned int);
|
||||
void print_nvidia_value(struct text_object *, char *, unsigned int);
|
||||
double get_nvidia_barval(struct text_object *);
|
||||
void free_nvidia(struct text_object *);
|
||||
|
||||
|
@ -84,21 +84,15 @@ struct prio_queue *init_prio_queue() {
|
||||
|
||||
void pq_set_compare(struct prio_queue *queue,
|
||||
int (*pqcompare)(void *a, void *b)) {
|
||||
if (pqcompare != nullptr) {
|
||||
queue->compare = pqcompare;
|
||||
}
|
||||
if (pqcompare != nullptr) { queue->compare = pqcompare; }
|
||||
}
|
||||
|
||||
void pq_set_free(struct prio_queue *queue, void (*pqfree)(void *a)) {
|
||||
if (pqfree != nullptr) {
|
||||
queue->free = pqfree;
|
||||
}
|
||||
if (pqfree != nullptr) { queue->free = pqfree; }
|
||||
}
|
||||
|
||||
void pq_set_max_size(struct prio_queue *queue, int max_size) {
|
||||
if (max_size >= 0) {
|
||||
queue->max_size = max_size;
|
||||
}
|
||||
if (max_size >= 0) { queue->max_size = max_size; }
|
||||
}
|
||||
|
||||
int pq_get_cur_size(struct prio_queue *queue) { return queue->cur_size; }
|
||||
@ -117,9 +111,7 @@ void insert_prio_elem(struct prio_queue *queue, void *data) {
|
||||
struct prio_elem *cur;
|
||||
|
||||
/* queue->compare is a must-have */
|
||||
if (queue->compare == nullptr) {
|
||||
return;
|
||||
}
|
||||
if (queue->compare == nullptr) { return; }
|
||||
|
||||
/* empty queue, insert the first item */
|
||||
if (queue->cur_size == 0) {
|
||||
@ -176,9 +168,7 @@ void *pop_prio_elem(struct prio_queue *queue) {
|
||||
struct prio_elem *tmp;
|
||||
void *data;
|
||||
|
||||
if (queue->cur_size <= 0) {
|
||||
return nullptr;
|
||||
}
|
||||
if (queue->cur_size <= 0) { return nullptr; }
|
||||
|
||||
tmp = queue->head;
|
||||
data = tmp->data;
|
||||
@ -197,8 +187,6 @@ void *pop_prio_elem(struct prio_queue *queue) {
|
||||
|
||||
void free_prio_queue(struct prio_queue *queue) {
|
||||
void *data;
|
||||
while ((data = pop_prio_elem(queue)) != nullptr) {
|
||||
(*queue->free)(data);
|
||||
}
|
||||
while ((data = pop_prio_elem(queue)) != nullptr) { (*queue->free)(data); }
|
||||
free(queue);
|
||||
}
|
||||
|
367
src/proc.cc
367
src/proc.cc
@ -32,10 +32,10 @@
|
||||
#include <unistd.h>
|
||||
#include <cctype>
|
||||
#include <memory>
|
||||
#include <sstream>
|
||||
#include "conky.h"
|
||||
#include "core.h"
|
||||
#include "logging.h"
|
||||
#include <sstream>
|
||||
|
||||
char *readfile(const char *filename, int *total_read, char showerror) {
|
||||
FILE *file;
|
||||
@ -79,18 +79,14 @@ struct ll_string *addnode(struct ll_string *end, char *string) {
|
||||
static_cast<struct ll_string *>(malloc(sizeof(struct ll_string)));
|
||||
current->string = strdup(string);
|
||||
current->next = nullptr;
|
||||
if (end != nullptr) {
|
||||
end->next = current;
|
||||
}
|
||||
if (end != nullptr) { end->next = current; }
|
||||
return current;
|
||||
}
|
||||
|
||||
void freelist(struct ll_string *front) {
|
||||
if (front != nullptr) {
|
||||
free(front->string);
|
||||
if (front->next != nullptr) {
|
||||
freelist(front->next);
|
||||
}
|
||||
if (front->next != nullptr) { freelist(front->next); }
|
||||
free(front);
|
||||
}
|
||||
}
|
||||
@ -99,23 +95,23 @@ int inlist(struct ll_string *front, char *string) {
|
||||
struct ll_string *current;
|
||||
|
||||
for (current = front; current != nullptr; current = current->next) {
|
||||
if (strcmp(current->string, string) == 0) {
|
||||
return 1;
|
||||
}
|
||||
if (strcmp(current->string, string) == 0) { return 1; }
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void print_pid_chroot(struct text_object *obj, char *p, unsigned int p_max_size) {
|
||||
void print_pid_chroot(struct text_object *obj, char *p,
|
||||
unsigned int p_max_size) {
|
||||
std::ostringstream pathstream;
|
||||
std::unique_ptr<char[]> buf(new char[max_user_text.get(*state)]);
|
||||
|
||||
generate_text_internal(buf.get(), max_user_text.get(*state), *obj->sub);
|
||||
pathstream << PROCDIR "/" << buf.get() << "/root";
|
||||
pathstream << PROCDIR "/" << buf.get() << "/root";
|
||||
pid_readlink(pathstream.str().c_str(), p, p_max_size);
|
||||
}
|
||||
|
||||
void print_pid_cmdline(struct text_object *obj, char *p, unsigned int p_max_size) {
|
||||
void print_pid_cmdline(struct text_object *obj, char *p,
|
||||
unsigned int p_max_size) {
|
||||
char *buf;
|
||||
int i, bytes_read;
|
||||
std::ostringstream pathstream;
|
||||
@ -124,13 +120,11 @@ void print_pid_cmdline(struct text_object *obj, char *p, unsigned int p_max_size
|
||||
generate_text_internal(objbuf.get(), max_user_text.get(*state), *obj->sub);
|
||||
|
||||
if (*(objbuf.get()) != 0) {
|
||||
pathstream << PROCDIR "/" << objbuf.get() << "/cmdline";
|
||||
pathstream << PROCDIR "/" << objbuf.get() << "/cmdline";
|
||||
buf = readfile(pathstream.str().c_str(), &bytes_read, 1);
|
||||
if (buf != nullptr) {
|
||||
for (i = 0; i < bytes_read - 1; i++) {
|
||||
if (buf[i] == 0) {
|
||||
buf[i] = ' ';
|
||||
}
|
||||
if (buf[i] == 0) { buf[i] = ' '; }
|
||||
}
|
||||
snprintf(p, p_max_size, "%s", buf);
|
||||
free(buf);
|
||||
@ -147,7 +141,7 @@ void print_pid_cwd(struct text_object *obj, char *p, unsigned int p_max_size) {
|
||||
std::unique_ptr<char[]> objbuf(new char[max_user_text.get(*state)]);
|
||||
|
||||
generate_text_internal(objbuf.get(), max_user_text.get(*state), *obj->sub);
|
||||
pathstream << PROCDIR "/" << objbuf.get() << "/cwd";
|
||||
pathstream << PROCDIR "/" << objbuf.get() << "/cwd";
|
||||
bytes_read = readlink(pathstream.str().c_str(), buf.get(), p_max_size);
|
||||
if (bytes_read != -1) {
|
||||
buf[bytes_read] = 0;
|
||||
@ -157,7 +151,8 @@ void print_pid_cwd(struct text_object *obj, char *p, unsigned int p_max_size) {
|
||||
}
|
||||
}
|
||||
|
||||
void print_pid_environ(struct text_object *obj, char *p, unsigned int p_max_size) {
|
||||
void print_pid_environ(struct text_object *obj, char *p,
|
||||
unsigned int p_max_size) {
|
||||
int i, total_read;
|
||||
pid_t pid;
|
||||
std::ostringstream pathstream;
|
||||
@ -167,10 +162,8 @@ void print_pid_environ(struct text_object *obj, char *p, unsigned int p_max_size
|
||||
|
||||
generate_text_internal(objbuf.get(), max_user_text.get(*state), *obj->sub);
|
||||
if (sscanf(objbuf.get(), "%d %s", &pid, var) == 2) {
|
||||
for (i = 0; var[i] != 0; i++) {
|
||||
var[i] = toupper((unsigned char)var[i]);
|
||||
}
|
||||
pathstream << PROCDIR "/" << pid << "/cwd";
|
||||
for (i = 0; var[i] != 0; i++) { var[i] = toupper((unsigned char)var[i]); }
|
||||
pathstream << PROCDIR "/" << pid << "/cwd";
|
||||
buf = readfile(pathstream.str().c_str(), &total_read, 1);
|
||||
if (buf != nullptr) {
|
||||
for (i = 0; i < total_read; i += strlen(buf + i) + 1) {
|
||||
@ -189,7 +182,8 @@ void print_pid_environ(struct text_object *obj, char *p, unsigned int p_max_size
|
||||
free(var);
|
||||
}
|
||||
|
||||
void print_pid_environ_list(struct text_object *obj, char *p, unsigned int p_max_size) {
|
||||
void print_pid_environ_list(struct text_object *obj, char *p,
|
||||
unsigned int p_max_size) {
|
||||
char *buf = nullptr;
|
||||
char *buf2;
|
||||
int bytes_read, total_read;
|
||||
@ -198,7 +192,7 @@ void print_pid_environ_list(struct text_object *obj, char *p, unsigned int p_max
|
||||
std::unique_ptr<char[]> objbuf(new char[max_user_text.get(*state)]);
|
||||
|
||||
generate_text_internal(objbuf.get(), max_user_text.get(*state), *obj->sub);
|
||||
pathstream << PROCDIR "/" << objbuf.get() << "/environ";
|
||||
pathstream << PROCDIR "/" << objbuf.get() << "/environ";
|
||||
|
||||
buf = readfile(pathstream.str().c_str(), &total_read, 1);
|
||||
if (buf != nullptr) {
|
||||
@ -220,7 +214,7 @@ void print_pid_exe(struct text_object *obj, char *p, unsigned int p_max_size) {
|
||||
std::unique_ptr<char[]> objbuf(new char[max_user_text.get(*state)]);
|
||||
|
||||
generate_text_internal(objbuf.get(), max_user_text.get(*state), *obj->sub);
|
||||
pathstream << PROCDIR "/" << objbuf.get() << "/exe";
|
||||
pathstream << PROCDIR "/" << objbuf.get() << "/exe";
|
||||
pid_readlink(pathstream.str().c_str(), p, p_max_size);
|
||||
}
|
||||
|
||||
@ -234,7 +228,7 @@ void print_pid_nice(struct text_object *obj, char *p, unsigned int p_max_size) {
|
||||
generate_text_internal(objbuf.get(), max_user_text.get(*state), *obj->sub);
|
||||
|
||||
if (!obj->data.s) {
|
||||
pathstream << PROCDIR "/" << objbuf.get() << "/stat";
|
||||
pathstream << PROCDIR "/" << objbuf.get() << "/stat";
|
||||
buf = readfile(pathstream.str().c_str(), &bytes_read, 1);
|
||||
if (buf != nullptr) {
|
||||
sscanf(buf,
|
||||
@ -249,7 +243,8 @@ void print_pid_nice(struct text_object *obj, char *p, unsigned int p_max_size) {
|
||||
}
|
||||
}
|
||||
|
||||
void print_pid_openfiles(struct text_object *obj, char *p, unsigned int p_max_size) {
|
||||
void print_pid_openfiles(struct text_object *obj, char *p,
|
||||
unsigned int p_max_size) {
|
||||
DIR *dir;
|
||||
struct dirent *entry;
|
||||
std::unique_ptr<char[]> buf(new char[p_max_size]);
|
||||
@ -273,9 +268,7 @@ void print_pid_openfiles(struct text_object *obj, char *p, unsigned int p_max_si
|
||||
buf.get());
|
||||
totallength += length + strlen("; ");
|
||||
}
|
||||
if (files_front == nullptr) {
|
||||
files_front = files_back;
|
||||
}
|
||||
if (files_front == nullptr) { files_front = files_back; }
|
||||
}
|
||||
}
|
||||
closedir(dir);
|
||||
@ -286,7 +279,8 @@ void print_pid_openfiles(struct text_object *obj, char *p, unsigned int p_max_si
|
||||
}
|
||||
}
|
||||
|
||||
void print_pid_parent(struct text_object *obj, char *p, unsigned int p_max_size) {
|
||||
void print_pid_parent(struct text_object *obj, char *p,
|
||||
unsigned int p_max_size) {
|
||||
#define PARENT_ENTRY "PPid:\t"
|
||||
#define PARENTNOTFOUND "Can't find the process parent in '%s'"
|
||||
char *begin, *end, *buf = nullptr;
|
||||
@ -295,7 +289,7 @@ void print_pid_parent(struct text_object *obj, char *p, unsigned int p_max_size)
|
||||
std::unique_ptr<char[]> objbuf(new char[max_user_text.get(*state)]);
|
||||
|
||||
generate_text_internal(objbuf.get(), max_user_text.get(*state), *obj->sub);
|
||||
pathstream << PROCDIR "/" << objbuf.get() << "/status";
|
||||
pathstream << PROCDIR "/" << objbuf.get() << "/status";
|
||||
|
||||
buf = readfile(pathstream.str().c_str(), &bytes_read, 1);
|
||||
if (buf != nullptr) {
|
||||
@ -303,9 +297,7 @@ void print_pid_parent(struct text_object *obj, char *p, unsigned int p_max_size)
|
||||
if (begin != nullptr) {
|
||||
begin += strlen(PARENT_ENTRY);
|
||||
end = strchr(begin, '\n');
|
||||
if (end != nullptr) {
|
||||
*(end) = 0;
|
||||
}
|
||||
if (end != nullptr) { *(end) = 0; }
|
||||
snprintf(p, p_max_size, "%s", begin);
|
||||
} else {
|
||||
NORM_ERR(PARENTNOTFOUND, pathstream.str().c_str());
|
||||
@ -314,7 +306,8 @@ void print_pid_parent(struct text_object *obj, char *p, unsigned int p_max_size)
|
||||
}
|
||||
}
|
||||
|
||||
void print_pid_priority(struct text_object *obj, char *p, unsigned int p_max_size) {
|
||||
void print_pid_priority(struct text_object *obj, char *p,
|
||||
unsigned int p_max_size) {
|
||||
char *buf = nullptr;
|
||||
int bytes_read;
|
||||
long int priority;
|
||||
@ -324,7 +317,7 @@ void print_pid_priority(struct text_object *obj, char *p, unsigned int p_max_siz
|
||||
generate_text_internal(objbuf.get(), max_user_text.get(*state), *obj->sub);
|
||||
|
||||
if (*(objbuf.get()) != 0) {
|
||||
pathstream << PROCDIR "/" << objbuf.get() << "/stat";
|
||||
pathstream << PROCDIR "/" << objbuf.get() << "/stat";
|
||||
buf = readfile(pathstream.str().c_str(), &bytes_read, 1);
|
||||
if (buf != nullptr) {
|
||||
sscanf(buf,
|
||||
@ -339,7 +332,8 @@ void print_pid_priority(struct text_object *obj, char *p, unsigned int p_max_siz
|
||||
}
|
||||
}
|
||||
|
||||
void print_pid_state(struct text_object *obj, char *p, unsigned int p_max_size) {
|
||||
void print_pid_state(struct text_object *obj, char *p,
|
||||
unsigned int p_max_size) {
|
||||
#define STATE_ENTRY "State:\t"
|
||||
#define STATENOTFOUND "Can't find the process state in '%s'"
|
||||
char *begin, *end, *buf = nullptr;
|
||||
@ -348,7 +342,7 @@ void print_pid_state(struct text_object *obj, char *p, unsigned int p_max_size)
|
||||
std::unique_ptr<char[]> objbuf(new char[max_user_text.get(*state)]);
|
||||
|
||||
generate_text_internal(objbuf.get(), max_user_text.get(*state), *obj->sub);
|
||||
pathstream << PROCDIR "/" << objbuf.get() << "/status";
|
||||
pathstream << PROCDIR "/" << objbuf.get() << "/status";
|
||||
|
||||
buf = readfile(pathstream.str().c_str(), &bytes_read, 1);
|
||||
if (buf != nullptr) {
|
||||
@ -369,7 +363,8 @@ void print_pid_state(struct text_object *obj, char *p, unsigned int p_max_size)
|
||||
}
|
||||
}
|
||||
|
||||
void print_pid_state_short(struct text_object *obj, char *p, unsigned int p_max_size) {
|
||||
void print_pid_state_short(struct text_object *obj, char *p,
|
||||
unsigned int p_max_size) {
|
||||
char *begin, *buf = nullptr;
|
||||
int bytes_read;
|
||||
std::ostringstream pathstream;
|
||||
@ -377,7 +372,7 @@ void print_pid_state_short(struct text_object *obj, char *p, unsigned int p_max_
|
||||
|
||||
generate_text_internal(objbuf.get(), max_user_text.get(*state), *obj->sub);
|
||||
|
||||
pathstream << PROCDIR "/" << objbuf.get() << "/status";
|
||||
pathstream << PROCDIR "/" << objbuf.get() << "/status";
|
||||
|
||||
buf = readfile(pathstream.str().c_str(), &bytes_read, 1);
|
||||
if (buf != nullptr) {
|
||||
@ -391,27 +386,30 @@ void print_pid_state_short(struct text_object *obj, char *p, unsigned int p_max_
|
||||
}
|
||||
}
|
||||
|
||||
void print_pid_stderr(struct text_object *obj, char *p, unsigned int p_max_size) {
|
||||
void print_pid_stderr(struct text_object *obj, char *p,
|
||||
unsigned int p_max_size) {
|
||||
std::ostringstream pathstream;
|
||||
std::unique_ptr<char[]> objbuf(new char[max_user_text.get(*state)]);
|
||||
|
||||
generate_text_internal(objbuf.get(), max_user_text.get(*state), *obj->sub);
|
||||
|
||||
pathstream << PROCDIR "/" << objbuf.get() << "/fd/2";
|
||||
pathstream << PROCDIR "/" << objbuf.get() << "/fd/2";
|
||||
pid_readlink(pathstream.str().c_str(), p, p_max_size);
|
||||
}
|
||||
|
||||
void print_pid_stdin(struct text_object *obj, char *p, unsigned int p_max_size) {
|
||||
void print_pid_stdin(struct text_object *obj, char *p,
|
||||
unsigned int p_max_size) {
|
||||
std::unique_ptr<char[]> objbuf(new char[max_user_text.get(*state)]);
|
||||
std::ostringstream pathstream;
|
||||
|
||||
generate_text_internal(objbuf.get(), max_user_text.get(*state), *obj->sub);
|
||||
|
||||
pathstream << PROCDIR "/" << objbuf.get() << "/fd/0";
|
||||
pathstream << PROCDIR "/" << objbuf.get() << "/fd/0";
|
||||
pid_readlink(pathstream.str().c_str(), p, p_max_size);
|
||||
}
|
||||
|
||||
void print_pid_stdout(struct text_object *obj, char *p, unsigned int p_max_size) {
|
||||
void print_pid_stdout(struct text_object *obj, char *p,
|
||||
unsigned int p_max_size) {
|
||||
std::ostringstream pathstream;
|
||||
std::unique_ptr<char[]> objbuf(new char[max_user_text.get(*state)]);
|
||||
|
||||
@ -437,15 +435,14 @@ void scan_cmdline_to_pid_arg(struct text_object *obj, const char *arg,
|
||||
strlen(obj->data.s + i + 1) + 1);
|
||||
}
|
||||
}
|
||||
if (obj->data.s[i - 1] == ' ') {
|
||||
obj->data.s[i - 1] = 0;
|
||||
}
|
||||
if (obj->data.s[i - 1] == ' ') { obj->data.s[i - 1] = 0; }
|
||||
} else {
|
||||
CRIT_ERR(obj, free_at_crash, "${cmdline_to_pid commandline}");
|
||||
}
|
||||
}
|
||||
|
||||
void print_cmdline_to_pid(struct text_object *obj, char *p, unsigned int p_max_size) {
|
||||
void print_cmdline_to_pid(struct text_object *obj, char *p,
|
||||
unsigned int p_max_size) {
|
||||
DIR *dir;
|
||||
struct dirent *entry;
|
||||
char *buf;
|
||||
@ -460,9 +457,7 @@ void print_cmdline_to_pid(struct text_object *obj, char *p, unsigned int p_max_s
|
||||
buf = readfile(pathstream.str().c_str(), &bytes_read, 0);
|
||||
if (buf != nullptr) {
|
||||
for (i = 0; i < bytes_read - 1; i++) {
|
||||
if (buf[i] == 0) {
|
||||
buf[i] = ' ';
|
||||
}
|
||||
if (buf[i] == 0) { buf[i] = ' '; }
|
||||
}
|
||||
if (strstr(buf, obj->data.s) != nullptr) {
|
||||
snprintf(p, p_max_size, "%s", entry->d_name);
|
||||
@ -479,7 +474,8 @@ void print_cmdline_to_pid(struct text_object *obj, char *p, unsigned int p_max_s
|
||||
}
|
||||
}
|
||||
|
||||
void print_pid_threads(struct text_object *obj, char *p, unsigned int p_max_size) {
|
||||
void print_pid_threads(struct text_object *obj, char *p,
|
||||
unsigned int p_max_size) {
|
||||
#define THREADS_ENTRY "Threads:\t"
|
||||
#define THREADSNOTFOUND \
|
||||
"Can't find the number of the threads of the process in '%s'"
|
||||
@ -497,9 +493,7 @@ void print_pid_threads(struct text_object *obj, char *p, unsigned int p_max_size
|
||||
if (begin != nullptr) {
|
||||
begin += strlen(THREADS_ENTRY);
|
||||
end = strchr(begin, '\n');
|
||||
if (end != nullptr) {
|
||||
*(end) = 0;
|
||||
}
|
||||
if (end != nullptr) { *(end) = 0; }
|
||||
snprintf(p, p_max_size, "%s", begin);
|
||||
} else {
|
||||
NORM_ERR(THREADSNOTFOUND, pathstream.str().c_str());
|
||||
@ -508,7 +502,8 @@ void print_pid_threads(struct text_object *obj, char *p, unsigned int p_max_size
|
||||
}
|
||||
}
|
||||
|
||||
void print_pid_thread_list(struct text_object *obj, char *p, unsigned int p_max_size) {
|
||||
void print_pid_thread_list(struct text_object *obj, char *p,
|
||||
unsigned int p_max_size) {
|
||||
DIR *dir;
|
||||
struct dirent *entry;
|
||||
int totallength = 0;
|
||||
@ -528,9 +523,7 @@ void print_pid_thread_list(struct text_object *obj, char *p, unsigned int p_max_
|
||||
}
|
||||
}
|
||||
closedir(dir);
|
||||
if (p[totallength - 1] == ',') {
|
||||
p[totallength - 1] = 0;
|
||||
}
|
||||
if (p[totallength - 1] == ',') { p[totallength - 1] = 0; }
|
||||
} else {
|
||||
p[0] = 0;
|
||||
}
|
||||
@ -560,7 +553,8 @@ void print_pid_time_kernelmode(struct text_object *obj, char *p,
|
||||
}
|
||||
}
|
||||
|
||||
void print_pid_time_usermode(struct text_object *obj, char *p, unsigned int p_max_size) {
|
||||
void print_pid_time_usermode(struct text_object *obj, char *p,
|
||||
unsigned int p_max_size) {
|
||||
char *buf = nullptr;
|
||||
int bytes_read;
|
||||
unsigned long int kmtime;
|
||||
@ -607,9 +601,10 @@ void print_pid_time(struct text_object *obj, char *p, unsigned int p_max_size) {
|
||||
}
|
||||
}
|
||||
|
||||
enum idtype {egid, euid, fsgid, fsuid, gid, sgid, suid, uid};
|
||||
enum idtype { egid, euid, fsgid, fsuid, gid, sgid, suid, uid };
|
||||
|
||||
void print_pid_Xid(struct text_object *obj, char *p, int p_max_size, idtype type) {
|
||||
void print_pid_Xid(struct text_object *obj, char *p, int p_max_size,
|
||||
idtype type) {
|
||||
char *begin, *end, *buf = nullptr;
|
||||
int bytes_read;
|
||||
std::ostringstream pathstream;
|
||||
@ -621,106 +616,107 @@ void print_pid_Xid(struct text_object *obj, char *p, int p_max_size, idtype type
|
||||
|
||||
buf = readfile(pathstream.str().c_str(), &bytes_read, 1);
|
||||
if (buf != nullptr) {
|
||||
switch(type) {
|
||||
case egid:
|
||||
begin = strstr(buf, "Gid:\t");
|
||||
break;
|
||||
case euid:
|
||||
begin = strstr(buf, "Uid:\t");
|
||||
break;
|
||||
case fsgid:
|
||||
begin = strstr(buf, "Gid:\t");
|
||||
break;
|
||||
case fsuid:
|
||||
begin = strstr(buf, "Uid:\t");
|
||||
break;
|
||||
case gid:
|
||||
begin = strstr(buf, "Gid:\t");
|
||||
break;
|
||||
case sgid:
|
||||
begin = strstr(buf, "Gid:\t");
|
||||
break;
|
||||
case suid:
|
||||
begin = strstr(buf, "Uid:\t");
|
||||
break;
|
||||
case uid:
|
||||
begin = strstr(buf, "Uid:\t");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (begin != nullptr) {
|
||||
switch(type) {
|
||||
case gid:
|
||||
begin += strlen("Gid:\t");
|
||||
break;
|
||||
case uid:
|
||||
begin += strlen("Uid:\t");
|
||||
break;
|
||||
switch (type) {
|
||||
case egid:
|
||||
case euid:
|
||||
begin = strchr(begin, '\t');
|
||||
begin++;
|
||||
begin = strchr(begin, '\t');
|
||||
begin++;
|
||||
begin = strstr(buf, "Gid:\t");
|
||||
break;
|
||||
case sgid:
|
||||
case suid:
|
||||
begin = strchr(begin, '\t');
|
||||
begin++;
|
||||
begin = strchr(begin, '\t');
|
||||
begin++;
|
||||
begin = strchr(begin, '\t');
|
||||
begin++;
|
||||
case euid:
|
||||
begin = strstr(buf, "Uid:\t");
|
||||
break;
|
||||
case fsgid:
|
||||
begin = strstr(buf, "Gid:\t");
|
||||
break;
|
||||
case fsuid:
|
||||
begin = strchr(begin, '\t');
|
||||
begin++;
|
||||
begin = strchr(begin, '\t');
|
||||
begin++;
|
||||
begin = strchr(begin, '\t');
|
||||
begin++;
|
||||
begin = strchr(begin, '\t');
|
||||
begin++;
|
||||
break;
|
||||
begin = strstr(buf, "Uid:\t");
|
||||
break;
|
||||
case gid:
|
||||
begin = strstr(buf, "Gid:\t");
|
||||
break;
|
||||
case sgid:
|
||||
begin = strstr(buf, "Gid:\t");
|
||||
break;
|
||||
case suid:
|
||||
begin = strstr(buf, "Uid:\t");
|
||||
break;
|
||||
case uid:
|
||||
begin = strstr(buf, "Uid:\t");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (begin != nullptr) {
|
||||
switch (type) {
|
||||
case gid:
|
||||
begin += strlen("Gid:\t");
|
||||
break;
|
||||
case uid:
|
||||
begin += strlen("Uid:\t");
|
||||
break;
|
||||
case egid:
|
||||
case euid:
|
||||
begin = strchr(begin, '\t');
|
||||
begin++;
|
||||
begin = strchr(begin, '\t');
|
||||
begin++;
|
||||
break;
|
||||
case sgid:
|
||||
case suid:
|
||||
begin = strchr(begin, '\t');
|
||||
begin++;
|
||||
begin = strchr(begin, '\t');
|
||||
begin++;
|
||||
begin = strchr(begin, '\t');
|
||||
begin++;
|
||||
break;
|
||||
case fsgid:
|
||||
case fsuid:
|
||||
begin = strchr(begin, '\t');
|
||||
begin++;
|
||||
begin = strchr(begin, '\t');
|
||||
begin++;
|
||||
begin = strchr(begin, '\t');
|
||||
begin++;
|
||||
begin = strchr(begin, '\t');
|
||||
begin++;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if(type == fsgid || type == fsuid) end = strchr(begin, '\n'); else end = strchr(begin, '\t');
|
||||
if (end != nullptr) {
|
||||
*(end) = 0;
|
||||
}
|
||||
if (type == fsgid || type == fsuid)
|
||||
end = strchr(begin, '\n');
|
||||
else
|
||||
end = strchr(begin, '\t');
|
||||
if (end != nullptr) { *(end) = 0; }
|
||||
snprintf(p, p_max_size, "%s", begin);
|
||||
} else {
|
||||
errorstring = "Can't find the process ";
|
||||
switch(type) {
|
||||
case egid:
|
||||
errorstring.append("effective gid");
|
||||
break;
|
||||
case euid:
|
||||
errorstring.append("effective uid");
|
||||
break;
|
||||
case fsgid:
|
||||
errorstring.append("process file system gid");
|
||||
break;
|
||||
case fsuid:
|
||||
errorstring.append("process file system uid");
|
||||
break;
|
||||
case gid:
|
||||
errorstring.append("real gid");
|
||||
break;
|
||||
case sgid:
|
||||
errorstring.append("saved set gid");
|
||||
break;
|
||||
case suid:
|
||||
errorstring.append("saved set uid");
|
||||
break;
|
||||
case uid:
|
||||
errorstring.append("real uid");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
switch (type) {
|
||||
case egid:
|
||||
errorstring.append("effective gid");
|
||||
break;
|
||||
case euid:
|
||||
errorstring.append("effective uid");
|
||||
break;
|
||||
case fsgid:
|
||||
errorstring.append("process file system gid");
|
||||
break;
|
||||
case fsuid:
|
||||
errorstring.append("process file system uid");
|
||||
break;
|
||||
case gid:
|
||||
errorstring.append("real gid");
|
||||
break;
|
||||
case sgid:
|
||||
errorstring.append("saved set gid");
|
||||
break;
|
||||
case suid:
|
||||
errorstring.append("saved set uid");
|
||||
break;
|
||||
case uid:
|
||||
errorstring.append("real uid");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
errorstring.append(" in '%s'");
|
||||
NORM_ERR(errorstring.c_str(), pathstream.str().c_str());
|
||||
@ -730,23 +726,25 @@ void print_pid_Xid(struct text_object *obj, char *p, int p_max_size, idtype type
|
||||
}
|
||||
|
||||
void print_pid_egid(struct text_object *obj, char *p, unsigned int p_max_size) {
|
||||
print_pid_Xid(obj, p, p_max_size, egid);
|
||||
print_pid_Xid(obj, p, p_max_size, egid);
|
||||
}
|
||||
|
||||
void print_pid_euid(struct text_object *obj, char *p, unsigned int p_max_size) {
|
||||
print_pid_Xid(obj, p, p_max_size, euid);
|
||||
}
|
||||
|
||||
void print_pid_fsgid(struct text_object *obj, char *p, unsigned int p_max_size) {
|
||||
void print_pid_fsgid(struct text_object *obj, char *p,
|
||||
unsigned int p_max_size) {
|
||||
print_pid_Xid(obj, p, p_max_size, fsgid);
|
||||
}
|
||||
|
||||
void print_pid_fsuid(struct text_object *obj, char *p, unsigned int p_max_size) {
|
||||
print_pid_Xid(obj, p, p_max_size, fsuid);
|
||||
void print_pid_fsuid(struct text_object *obj, char *p,
|
||||
unsigned int p_max_size) {
|
||||
print_pid_Xid(obj, p, p_max_size, fsuid);
|
||||
}
|
||||
|
||||
void print_pid_gid(struct text_object *obj, char *p, unsigned int p_max_size) {
|
||||
print_pid_Xid(obj, p, p_max_size, gid);
|
||||
print_pid_Xid(obj, p, p_max_size, gid);
|
||||
}
|
||||
|
||||
void print_pid_sgid(struct text_object *obj, char *p, unsigned int p_max_size) {
|
||||
@ -754,7 +752,7 @@ void print_pid_sgid(struct text_object *obj, char *p, unsigned int p_max_size) {
|
||||
}
|
||||
|
||||
void print_pid_suid(struct text_object *obj, char *p, unsigned int p_max_size) {
|
||||
print_pid_Xid(obj, p, p_max_size, suid);
|
||||
print_pid_Xid(obj, p, p_max_size, suid);
|
||||
}
|
||||
|
||||
void print_pid_uid(struct text_object *obj, char *p, unsigned int p_max_size) {
|
||||
@ -776,13 +774,9 @@ void internal_print_pid_vm(struct text_object *obj, char *p, int p_max_size,
|
||||
begin = strstr(buf, entry);
|
||||
if (begin != nullptr) {
|
||||
begin += strlen(entry);
|
||||
while (*begin == '\t' || *begin == ' ') {
|
||||
begin++;
|
||||
}
|
||||
while (*begin == '\t' || *begin == ' ') { begin++; }
|
||||
end = strchr(begin, '\n');
|
||||
if (end != nullptr) {
|
||||
*(end) = 0;
|
||||
}
|
||||
if (end != nullptr) { *(end) = 0; }
|
||||
snprintf(p, p_max_size, "%s", begin);
|
||||
} else {
|
||||
NORM_ERR(errorstring, pathstream.str().c_str());
|
||||
@ -791,55 +785,65 @@ void internal_print_pid_vm(struct text_object *obj, char *p, int p_max_size,
|
||||
}
|
||||
}
|
||||
|
||||
void print_pid_vmpeak(struct text_object *obj, char *p, unsigned int p_max_size) {
|
||||
void print_pid_vmpeak(struct text_object *obj, char *p,
|
||||
unsigned int p_max_size) {
|
||||
internal_print_pid_vm(
|
||||
obj, p, p_max_size, "VmPeak:\t",
|
||||
"Can't find the process peak virtual memory size in '%s'");
|
||||
}
|
||||
|
||||
void print_pid_vmsize(struct text_object *obj, char *p, unsigned int p_max_size) {
|
||||
void print_pid_vmsize(struct text_object *obj, char *p,
|
||||
unsigned int p_max_size) {
|
||||
internal_print_pid_vm(obj, p, p_max_size, "VmSize:\t",
|
||||
"Can't find the process virtual memory size in '%s'");
|
||||
}
|
||||
|
||||
void print_pid_vmlck(struct text_object *obj, char *p, unsigned int p_max_size) {
|
||||
void print_pid_vmlck(struct text_object *obj, char *p,
|
||||
unsigned int p_max_size) {
|
||||
internal_print_pid_vm(obj, p, p_max_size, "VmLck:\t",
|
||||
"Can't find the process locked memory size in '%s'");
|
||||
}
|
||||
|
||||
void print_pid_vmhwm(struct text_object *obj, char *p, unsigned int p_max_size) {
|
||||
void print_pid_vmhwm(struct text_object *obj, char *p,
|
||||
unsigned int p_max_size) {
|
||||
internal_print_pid_vm(
|
||||
obj, p, p_max_size, "VmHWM:\t",
|
||||
"Can't find the process peak resident set size in '%s'");
|
||||
}
|
||||
|
||||
void print_pid_vmrss(struct text_object *obj, char *p, unsigned int p_max_size) {
|
||||
void print_pid_vmrss(struct text_object *obj, char *p,
|
||||
unsigned int p_max_size) {
|
||||
internal_print_pid_vm(obj, p, p_max_size, "VmHWM:\t",
|
||||
"Can't find the process resident set size in '%s'");
|
||||
}
|
||||
|
||||
void print_pid_vmdata(struct text_object *obj, char *p, unsigned int p_max_size) {
|
||||
void print_pid_vmdata(struct text_object *obj, char *p,
|
||||
unsigned int p_max_size) {
|
||||
internal_print_pid_vm(obj, p, p_max_size, "VmData:\t",
|
||||
"Can't find the process data segment size in '%s'");
|
||||
}
|
||||
|
||||
void print_pid_vmstk(struct text_object *obj, char *p, unsigned int p_max_size) {
|
||||
void print_pid_vmstk(struct text_object *obj, char *p,
|
||||
unsigned int p_max_size) {
|
||||
internal_print_pid_vm(obj, p, p_max_size, "VmData:\t",
|
||||
"Can't find the process stack segment size in '%s'");
|
||||
}
|
||||
|
||||
void print_pid_vmexe(struct text_object *obj, char *p, unsigned int p_max_size) {
|
||||
void print_pid_vmexe(struct text_object *obj, char *p,
|
||||
unsigned int p_max_size) {
|
||||
internal_print_pid_vm(obj, p, p_max_size, "VmData:\t",
|
||||
"Can't find the process text segment size in '%s'");
|
||||
}
|
||||
|
||||
void print_pid_vmlib(struct text_object *obj, char *p, unsigned int p_max_size) {
|
||||
void print_pid_vmlib(struct text_object *obj, char *p,
|
||||
unsigned int p_max_size) {
|
||||
internal_print_pid_vm(
|
||||
obj, p, p_max_size, "VmLib:\t",
|
||||
"Can't find the process shared library code size in '%s'");
|
||||
}
|
||||
|
||||
void print_pid_vmpte(struct text_object *obj, char *p, unsigned int p_max_size) {
|
||||
void print_pid_vmpte(struct text_object *obj, char *p,
|
||||
unsigned int p_max_size) {
|
||||
internal_print_pid_vm(
|
||||
obj, p, p_max_size, "VmPTE:\t",
|
||||
"Can't find the process page table entries size in '%s'");
|
||||
@ -861,9 +865,7 @@ void print_pid_read(struct text_object *obj, char *p, unsigned int p_max_size) {
|
||||
begin = strstr(buf, READ_ENTRY);
|
||||
if (begin != nullptr) {
|
||||
end = strchr(begin, '\n');
|
||||
if (end != nullptr) {
|
||||
*(end) = 0;
|
||||
}
|
||||
if (end != nullptr) { *(end) = 0; }
|
||||
snprintf(p, p_max_size, "%s", begin);
|
||||
} else {
|
||||
NORM_ERR(READNOTFOUND, pathstream.str().c_str());
|
||||
@ -874,7 +876,8 @@ void print_pid_read(struct text_object *obj, char *p, unsigned int p_max_size) {
|
||||
|
||||
#define WRITE_ENTRY "write_bytes: "
|
||||
#define WRITENOTFOUND "Can't find the amount of bytes written in '%s'"
|
||||
void print_pid_write(struct text_object *obj, char *p, unsigned int p_max_size) {
|
||||
void print_pid_write(struct text_object *obj, char *p,
|
||||
unsigned int p_max_size) {
|
||||
char *begin, *end, *buf = nullptr;
|
||||
int bytes_read;
|
||||
std::ostringstream pathstream;
|
||||
@ -888,9 +891,7 @@ void print_pid_write(struct text_object *obj, char *p, unsigned int p_max_size)
|
||||
begin = strstr(buf, WRITE_ENTRY);
|
||||
if (begin != nullptr) {
|
||||
end = strchr(begin, '\n');
|
||||
if (end != nullptr) {
|
||||
*(end) = 0;
|
||||
}
|
||||
if (end != nullptr) { *(end) = 0; }
|
||||
snprintf(p, p_max_size, "%s", begin);
|
||||
} else {
|
||||
NORM_ERR(WRITENOTFOUND, pathstream.str().c_str());
|
||||
|
51
src/proc.h
51
src/proc.h
@ -34,26 +34,39 @@
|
||||
#define READERR "Can't read '%s'"
|
||||
#define READSIZE 128
|
||||
|
||||
void print_pid_chroot(struct text_object *obj, char *p, unsigned int p_max_size);
|
||||
void print_pid_cmdline(struct text_object *obj, char *p, unsigned int p_max_size);
|
||||
void print_pid_chroot(struct text_object *obj, char *p,
|
||||
unsigned int p_max_size);
|
||||
void print_pid_cmdline(struct text_object *obj, char *p,
|
||||
unsigned int p_max_size);
|
||||
void print_pid_cwd(struct text_object *obj, char *p, unsigned int p_max_size);
|
||||
void print_pid_environ(struct text_object *obj, char *p, unsigned int p_max_size);
|
||||
void print_pid_environ_list(struct text_object *obj, char *p, unsigned int p_max_size);
|
||||
void print_pid_environ(struct text_object *obj, char *p,
|
||||
unsigned int p_max_size);
|
||||
void print_pid_environ_list(struct text_object *obj, char *p,
|
||||
unsigned int p_max_size);
|
||||
void print_pid_exe(struct text_object *obj, char *p, unsigned int p_max_size);
|
||||
void print_pid_nice(struct text_object *obj, char *p, unsigned int p_max_size);
|
||||
void print_pid_openfiles(struct text_object *obj, char *p, unsigned int p_max_size);
|
||||
void print_pid_parent(struct text_object *obj, char *p, unsigned int p_max_size);
|
||||
void print_pid_priority(struct text_object *obj, char *p, unsigned int p_max_size);
|
||||
void print_pid_openfiles(struct text_object *obj, char *p,
|
||||
unsigned int p_max_size);
|
||||
void print_pid_parent(struct text_object *obj, char *p,
|
||||
unsigned int p_max_size);
|
||||
void print_pid_priority(struct text_object *obj, char *p,
|
||||
unsigned int p_max_size);
|
||||
void print_pid_state(struct text_object *obj, char *p, unsigned int p_max_size);
|
||||
void print_pid_state_short(struct text_object *obj, char *p, unsigned int p_max_size);
|
||||
void print_pid_stderr(struct text_object *obj, char *p, unsigned int p_max_size);
|
||||
void print_pid_state_short(struct text_object *obj, char *p,
|
||||
unsigned int p_max_size);
|
||||
void print_pid_stderr(struct text_object *obj, char *p,
|
||||
unsigned int p_max_size);
|
||||
void print_pid_stdin(struct text_object *obj, char *p, unsigned int p_max_size);
|
||||
void print_pid_stdout(struct text_object *obj, char *p, unsigned int p_max_size);
|
||||
void print_pid_threads(struct text_object *obj, char *p, unsigned int p_max_size);
|
||||
void print_pid_thread_list(struct text_object *obj, char *p, unsigned int p_max_size);
|
||||
void print_pid_stdout(struct text_object *obj, char *p,
|
||||
unsigned int p_max_size);
|
||||
void print_pid_threads(struct text_object *obj, char *p,
|
||||
unsigned int p_max_size);
|
||||
void print_pid_thread_list(struct text_object *obj, char *p,
|
||||
unsigned int p_max_size);
|
||||
void print_pid_time_kernelmode(struct text_object *obj, char *p,
|
||||
unsigned int p_max_size);
|
||||
void print_pid_time_usermode(struct text_object *obj, char *p, unsigned int p_max_size);
|
||||
void print_pid_time_usermode(struct text_object *obj, char *p,
|
||||
unsigned int p_max_size);
|
||||
void print_pid_time(struct text_object *obj, char *p, unsigned int p_max_size);
|
||||
void print_pid_uid(struct text_object *obj, char *p, unsigned int p_max_size);
|
||||
void print_pid_euid(struct text_object *obj, char *p, unsigned int p_max_size);
|
||||
@ -64,12 +77,15 @@ void print_pid_egid(struct text_object *obj, char *p, unsigned int p_max_size);
|
||||
void print_pid_sgid(struct text_object *obj, char *p, unsigned int p_max_size);
|
||||
void print_pid_fsgid(struct text_object *obj, char *p, unsigned int p_max_size);
|
||||
void print_pid_read(struct text_object *obj, char *p, unsigned int p_max_size);
|
||||
void print_pid_vmpeak(struct text_object *obj, char *p, unsigned int p_max_size);
|
||||
void print_pid_vmsize(struct text_object *obj, char *p, unsigned int p_max_size);
|
||||
void print_pid_vmpeak(struct text_object *obj, char *p,
|
||||
unsigned int p_max_size);
|
||||
void print_pid_vmsize(struct text_object *obj, char *p,
|
||||
unsigned int p_max_size);
|
||||
void print_pid_vmlck(struct text_object *obj, char *p, unsigned int p_max_size);
|
||||
void print_pid_vmhwm(struct text_object *obj, char *p, unsigned int p_max_size);
|
||||
void print_pid_vmrss(struct text_object *obj, char *p, unsigned int p_max_size);
|
||||
void print_pid_vmdata(struct text_object *obj, char *p, unsigned int p_max_size);
|
||||
void print_pid_vmdata(struct text_object *obj, char *p,
|
||||
unsigned int p_max_size);
|
||||
void print_pid_vmstk(struct text_object *obj, char *p, unsigned int p_max_size);
|
||||
void print_pid_vmexe(struct text_object *obj, char *p, unsigned int p_max_size);
|
||||
void print_pid_vmlib(struct text_object *obj, char *p, unsigned int p_max_size);
|
||||
@ -78,6 +94,7 @@ void print_pid_write(struct text_object *obj, char *p, unsigned int p_max_size);
|
||||
|
||||
void scan_cmdline_to_pid_arg(struct text_object *obj, const char *arg,
|
||||
void *free_at_crash);
|
||||
void print_cmdline_to_pid(struct text_object *obj, char *p, unsigned int p_max_size);
|
||||
void print_cmdline_to_pid(struct text_object *obj, char *p,
|
||||
unsigned int p_max_size);
|
||||
|
||||
#endif /* CONKY_PROC_H */
|
||||
|
28
src/prss.cc
28
src/prss.cc
@ -101,14 +101,10 @@ static inline void read_item(PRSS_Item *res, xmlNodePtr data) {
|
||||
for (; data; data = data->next) {
|
||||
xmlNodePtr child;
|
||||
|
||||
if (data->type != XML_ELEMENT_NODE) {
|
||||
continue;
|
||||
}
|
||||
if (data->type != XML_ELEMENT_NODE) { continue; }
|
||||
child = data->children;
|
||||
|
||||
if (!child) {
|
||||
continue;
|
||||
}
|
||||
if (!child) { continue; }
|
||||
|
||||
#define ASSIGN(a) \
|
||||
if (strcasecmp((const char *)data->name, #a) == EQUAL) { \
|
||||
@ -128,14 +124,10 @@ static inline void read_item(PRSS_Item *res, xmlNodePtr data) {
|
||||
static inline void read_element(PRSS *res, xmlNodePtr n) {
|
||||
xmlNodePtr child;
|
||||
|
||||
if (n->type != XML_ELEMENT_NODE) {
|
||||
return;
|
||||
}
|
||||
if (n->type != XML_ELEMENT_NODE) { return; }
|
||||
child = n->children;
|
||||
|
||||
if (!child) {
|
||||
return;
|
||||
}
|
||||
if (!child) { return; }
|
||||
|
||||
#define ASSIGN(a) \
|
||||
if (strcasecmp((const char *)n->name, #a) == EQUAL) { \
|
||||
@ -172,9 +164,7 @@ static inline int parse_rss_2_0(PRSS *res, xmlNodePtr root) {
|
||||
strcmp((const char *)channel->name, "channel"))) {
|
||||
channel = channel->next;
|
||||
}
|
||||
if (!channel) {
|
||||
return 0;
|
||||
}
|
||||
if (!channel) { return 0; }
|
||||
|
||||
for (n = channel->children; n; n = n->next) {
|
||||
if (n->type == XML_ELEMENT_NODE && !strcmp((const char *)n->name, "item")) {
|
||||
@ -188,9 +178,7 @@ static inline int parse_rss_2_0(PRSS *res, xmlNodePtr root) {
|
||||
res->items = (PRSS_Item *)malloc(items * sizeof(PRSS_Item));
|
||||
res->item_count = 0;
|
||||
|
||||
for (n = channel->children; n; n = n->next) {
|
||||
read_element(res, n);
|
||||
}
|
||||
for (n = channel->children; n; n = n->next) { read_element(res, n); }
|
||||
|
||||
return 1;
|
||||
}
|
||||
@ -207,9 +195,7 @@ static inline int parse_rss_1_0(PRSS *res, xmlNodePtr root) {
|
||||
} else if (!strcmp((const char *)n->name, "channel")) {
|
||||
xmlNodePtr i;
|
||||
|
||||
for (i = n->children; i; i = i->next) {
|
||||
read_element(res, i);
|
||||
}
|
||||
for (i = n->children; i; i = i->next) { read_element(res, i); }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -36,11 +36,16 @@
|
||||
void init_pulseaudio(struct text_object *obj);
|
||||
void free_pulseaudio(struct text_object *obj);
|
||||
uint8_t puau_vol(struct text_object *); // preserve pa_* for libpulse
|
||||
void print_puau_sink_description(struct text_object *obj, char *p, unsigned int p_max_size);
|
||||
void print_puau_sink_active_port_name(struct text_object *obj, char *p, unsigned int p_max_size);
|
||||
void print_puau_sink_active_port_description(struct text_object *obj, char *p, unsigned int p_max_size);
|
||||
void print_puau_card_name(struct text_object *obj, char *p, unsigned int p_max_size);
|
||||
void print_puau_card_active_profile(struct text_object *obj, char *p, unsigned int p_max_size);
|
||||
void print_puau_sink_description(struct text_object *obj, char *p,
|
||||
unsigned int p_max_size);
|
||||
void print_puau_sink_active_port_name(struct text_object *obj, char *p,
|
||||
unsigned int p_max_size);
|
||||
void print_puau_sink_active_port_description(struct text_object *obj, char *p,
|
||||
unsigned int p_max_size);
|
||||
void print_puau_card_name(struct text_object *obj, char *p,
|
||||
unsigned int p_max_size);
|
||||
void print_puau_card_active_profile(struct text_object *obj, char *p,
|
||||
unsigned int p_max_size);
|
||||
double puau_volumebarval(struct text_object *obj);
|
||||
int puau_muted(struct text_object *obj);
|
||||
|
||||
|
20
src/rss.cc
20
src/rss.cc
@ -52,9 +52,7 @@ class rss_cb : public curl_callback<std::shared_ptr<PRSS>> {
|
||||
|
||||
std::unique_lock<std::mutex> lock(Base::result_mutex);
|
||||
Base::result = tmp;
|
||||
} catch (std::runtime_error &e) {
|
||||
NORM_ERR("%s", e.what());
|
||||
}
|
||||
} catch (std::runtime_error &e) { NORM_ERR("%s", e.what()); }
|
||||
}
|
||||
|
||||
public:
|
||||
@ -87,9 +85,7 @@ static void rss_process_info(char *p, int p_max_size, const std::string &uri,
|
||||
str = data->title;
|
||||
if (str && strlen(str) > 0) {
|
||||
// remove trailing new line if one exists
|
||||
if (str[strlen(str) - 1] == '\n') {
|
||||
str[strlen(str) - 1] = 0;
|
||||
}
|
||||
if (str[strlen(str) - 1] == '\n') { str[strlen(str) - 1] = 0; }
|
||||
snprintf(p, p_max_size, "%s", str);
|
||||
}
|
||||
} else if (strcmp(action, "item_title") == EQUAL) {
|
||||
@ -97,9 +93,7 @@ static void rss_process_info(char *p, int p_max_size, const std::string &uri,
|
||||
str = data->items[act_par].title;
|
||||
// remove trailing new line if one exists
|
||||
if (str && strlen(str) > 0) {
|
||||
if (str[strlen(str) - 1] == '\n') {
|
||||
str[strlen(str) - 1] = 0;
|
||||
}
|
||||
if (str[strlen(str) - 1] == '\n') { str[strlen(str) - 1] = 0; }
|
||||
snprintf(p, p_max_size, "%s", str);
|
||||
}
|
||||
}
|
||||
@ -108,9 +102,7 @@ static void rss_process_info(char *p, int p_max_size, const std::string &uri,
|
||||
str = data->items[act_par].description;
|
||||
// remove trailing new line if one exists
|
||||
if (str && strlen(str) > 0) {
|
||||
if (str[strlen(str) - 1] == '\n') {
|
||||
str[strlen(str) - 1] = 0;
|
||||
}
|
||||
if (str[strlen(str) - 1] == '\n') { str[strlen(str) - 1] = 0; }
|
||||
snprintf(p, p_max_size, "%s", str);
|
||||
}
|
||||
}
|
||||
@ -135,9 +127,7 @@ static void rss_process_info(char *p, int p_max_size, const std::string &uri,
|
||||
str = item->title;
|
||||
if (str) {
|
||||
// don't add new line before first item
|
||||
if (itmp > 0) {
|
||||
strncat(p, "\n", p_max_size);
|
||||
}
|
||||
if (itmp > 0) { strncat(p, "\n", p_max_size); }
|
||||
/* remove trailing new line if one exists,
|
||||
* we have our own */
|
||||
if (strlen(str) > 0 && str[strlen(str) - 1] == '\n') {
|
||||
|
@ -71,9 +71,7 @@ settings_vector make_settings_vector() {
|
||||
settings_vector ret;
|
||||
ret.reserve(settings->size());
|
||||
|
||||
for (auto &setting : *settings) {
|
||||
ret.push_back(setting.second);
|
||||
}
|
||||
for (auto &setting : *settings) { ret.push_back(setting.second); }
|
||||
sort(ret.begin(), ret.end(), &priv::config_setting_base::seq_compare);
|
||||
|
||||
return ret;
|
||||
@ -131,9 +129,7 @@ void config_setting_base::process_setting(lua::state &l, bool init) {
|
||||
lua::stack_sentry s(l, -3);
|
||||
|
||||
config_setting_base *ptr = get_setting(l, -3);
|
||||
if (ptr == nullptr) {
|
||||
return;
|
||||
}
|
||||
if (ptr == nullptr) { return; }
|
||||
|
||||
ptr->lua_setter(l, init);
|
||||
l.pushvalue(-2);
|
||||
|
10
src/smapi.cc
10
src/smapi.cc
@ -132,7 +132,8 @@ uint8_t smapi_bat_percentage(struct text_object *obj) {
|
||||
return val;
|
||||
}
|
||||
|
||||
void print_smapi_bat_temp(struct text_object *obj, char *p, unsigned int p_max_size) {
|
||||
void print_smapi_bat_temp(struct text_object *obj, char *p,
|
||||
unsigned int p_max_size) {
|
||||
int idx, val;
|
||||
if (obj->data.s && sscanf(obj->data.s, "%i", &idx) == 1) {
|
||||
val = smapi_bat_installed_internal(idx)
|
||||
@ -144,7 +145,8 @@ void print_smapi_bat_temp(struct text_object *obj, char *p, unsigned int p_max_s
|
||||
NORM_ERR("argument to smapi_bat_temp must be an integer");
|
||||
}
|
||||
|
||||
void print_smapi_bat_power(struct text_object *obj, char *p, unsigned int p_max_size) {
|
||||
void print_smapi_bat_power(struct text_object *obj, char *p,
|
||||
unsigned int p_max_size) {
|
||||
int idx, val;
|
||||
if (obj->data.s && sscanf(obj->data.s, "%i", &idx) == 1) {
|
||||
val = smapi_bat_installed_internal(idx)
|
||||
@ -165,9 +167,7 @@ double smapi_bat_barval(struct text_object *obj) {
|
||||
int smapi_bat_installed(struct text_object *obj) {
|
||||
int idx;
|
||||
if (obj->data.s && sscanf(obj->data.s, "%i", &idx) == 1) {
|
||||
if (!smapi_bat_installed_internal(idx)) {
|
||||
return 0;
|
||||
}
|
||||
if (!smapi_bat_installed_internal(idx)) { return 0; }
|
||||
} else
|
||||
NORM_ERR("argument to if_smapi_bat_installed must be an integer");
|
||||
return 1;
|
||||
|
12
src/sony.cc
12
src/sony.cc
@ -51,9 +51,7 @@ void get_sony_fanspeed(struct text_object *obj, char *p_client_buffer,
|
||||
|
||||
(void)obj;
|
||||
|
||||
if (!p_client_buffer || client_buffer_size <= 0) {
|
||||
return;
|
||||
}
|
||||
if (!p_client_buffer || client_buffer_size <= 0) { return; }
|
||||
|
||||
snprintf(fan, 127, "%s/fanspeed", SONY_LAPTOP_DIR);
|
||||
|
||||
@ -62,12 +60,8 @@ void get_sony_fanspeed(struct text_object *obj, char *p_client_buffer,
|
||||
while (!feof(fp)) {
|
||||
char line[256];
|
||||
|
||||
if (fgets(line, 255, fp) == nullptr) {
|
||||
break;
|
||||
}
|
||||
if (sscanf(line, "%u", &speed)) {
|
||||
break;
|
||||
}
|
||||
if (fgets(line, 255, fp) == nullptr) { break; }
|
||||
if (sscanf(line, "%u", &speed)) { break; }
|
||||
}
|
||||
} else {
|
||||
CRIT_ERR(nullptr, NULL,
|
||||
|
@ -65,13 +65,9 @@ static void tailstring(char *string, int endofstring, int wantedlines) {
|
||||
string[endofstring - 1] = 0;
|
||||
}
|
||||
for (i = endofstring - 1; i >= 0 && linescounted < wantedlines; i--) {
|
||||
if (string[i] == '\n') {
|
||||
linescounted++;
|
||||
}
|
||||
}
|
||||
if (i > 0) {
|
||||
strfold(string, i + 2);
|
||||
if (string[i] == '\n') { linescounted++; }
|
||||
}
|
||||
if (i > 0) { strfold(string, i + 2); }
|
||||
}
|
||||
}
|
||||
|
||||
@ -124,9 +120,7 @@ static void print_tailhead(const char *type, struct text_object *obj, char *p,
|
||||
struct stat st {};
|
||||
auto *ht = static_cast<struct headtail *>(obj->data.opaque);
|
||||
|
||||
if (ht == nullptr) {
|
||||
return;
|
||||
}
|
||||
if (ht == nullptr) { return; }
|
||||
|
||||
// empty the buffer and reset the counter if we used it the max number of
|
||||
// times
|
||||
@ -145,12 +139,8 @@ static void print_tailhead(const char *type, struct text_object *obj, char *p,
|
||||
if (fd != -1) {
|
||||
if (strcmp(type, "head") == 0) {
|
||||
for (i = 0; linescounted < ht->wantedlines; i++) {
|
||||
if (read(fd, p + i, 1) <= 0) {
|
||||
break;
|
||||
}
|
||||
if (p[i] == '\n') {
|
||||
linescounted++;
|
||||
}
|
||||
if (read(fd, p + i, 1) <= 0) { break; }
|
||||
if (p[i] == '\n') { linescounted++; }
|
||||
}
|
||||
p[i] = 0;
|
||||
} else if (strcmp(type, "tail") == 0) {
|
||||
@ -175,7 +165,7 @@ static void print_tailhead(const char *type, struct text_object *obj, char *p,
|
||||
endofstring = strlen(p);
|
||||
}
|
||||
} else if (strcmp(type, "tail") == 0) {
|
||||
fseek(fp, - (long) p_max_size, SEEK_END);
|
||||
fseek(fp, -(long)p_max_size, SEEK_END);
|
||||
i = fread(p, 1, p_max_size - 1, fp);
|
||||
tailstring(p, i, ht->wantedlines);
|
||||
} else {
|
||||
@ -219,9 +209,7 @@ void print_lines(struct text_object *obj, char *p, unsigned int p_max_size) {
|
||||
lines = 0;
|
||||
while (fgets(buf, BUFSZ, fp) != nullptr) {
|
||||
for (j = 0; buf[j] != 0; j++) {
|
||||
if (buf[j] == '\n') {
|
||||
lines++;
|
||||
}
|
||||
if (buf[j] == '\n') { lines++; }
|
||||
}
|
||||
}
|
||||
snprintf(p, p_max_size, "%d", lines);
|
||||
|
@ -17,10 +17,10 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#include "tcp-portmon.h"
|
||||
#include "conky.h"
|
||||
#include "libtcp-portmon.h"
|
||||
#include "logging.h"
|
||||
#include "tcp-portmon.h"
|
||||
#include "text_object.h"
|
||||
|
||||
static tcp_port_monitor_collection_t *pmc = nullptr;
|
||||
@ -122,7 +122,8 @@ int tcp_portmon_init(struct text_object *obj, const char *arg) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void tcp_portmon_action(struct text_object *obj, char *p, unsigned int p_max_size) {
|
||||
void tcp_portmon_action(struct text_object *obj, char *p,
|
||||
unsigned int p_max_size) {
|
||||
struct tcp_port_monitor_data *pmd = (tcp_port_monitor_data *)obj->data.opaque;
|
||||
tcp_port_monitor_t *p_monitor;
|
||||
|
||||
|
@ -41,9 +41,7 @@ static double fahrenheit_to_celsius(double n) { return ((n - 32) * 5 / 9); }
|
||||
static double celsius_to_fahrenheit(double n) { return ((n * 9 / 5) + 32); }
|
||||
|
||||
static double convert_temp_output(double n, enum TEMP_UNIT input_unit) {
|
||||
if (input_unit == output_unit.get(*state)) {
|
||||
return n;
|
||||
}
|
||||
if (input_unit == output_unit.get(*state)) { return n; }
|
||||
|
||||
switch (output_unit.get(*state)) {
|
||||
case TEMP_CELSIUS:
|
||||
@ -55,8 +53,8 @@ static double convert_temp_output(double n, enum TEMP_UNIT input_unit) {
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
int temp_print(char *p, size_t p_max_size, double n,
|
||||
enum TEMP_UNIT input_unit, int to_int) {
|
||||
int temp_print(char *p, size_t p_max_size, double n, enum TEMP_UNIT input_unit,
|
||||
int to_int) {
|
||||
int i_out = 0;
|
||||
float f_out = 0.0;
|
||||
size_t plen = 0;
|
||||
|
@ -184,7 +184,10 @@ char *find_and_replace_templates(const char *inbuf) {
|
||||
if (*(p + 1) == '{') {
|
||||
p += 2;
|
||||
templ = p;
|
||||
while ((*p != 0) && (isspace((unsigned char)*p) == 0) && *p != '{' && *p != '}') { p++; }
|
||||
while ((*p != 0) && (isspace((unsigned char)*p) == 0) && *p != '{' &&
|
||||
*p != '}') {
|
||||
p++;
|
||||
}
|
||||
if (*p == '}') {
|
||||
args = nullptr;
|
||||
} else {
|
||||
|
@ -44,7 +44,8 @@ void scan_tztime(struct text_object *, const char *);
|
||||
void print_time(struct text_object *, char *, unsigned int);
|
||||
void print_utime(struct text_object *, char *, unsigned int);
|
||||
void print_tztime(struct text_object *, char *, unsigned int);
|
||||
void print_format_time(struct text_object *obj, char *p, unsigned int p_max_size);
|
||||
void print_format_time(struct text_object *obj, char *p,
|
||||
unsigned int p_max_size);
|
||||
|
||||
/* free object data */
|
||||
void free_time(struct text_object *);
|
||||
|
@ -22,6 +22,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "weather.h"
|
||||
#include <ctype.h>
|
||||
#include <time.h>
|
||||
#include <array>
|
||||
@ -34,9 +35,8 @@
|
||||
#include "logging.h"
|
||||
#include "temphelper.h"
|
||||
#include "text_object.h"
|
||||
#include "weather.h"
|
||||
|
||||
void print_weather(struct text_object *obj, char *p, unsigned int p_max_size) {
|
||||
(void) obj;
|
||||
strncpy(p ,"TODO...", p_max_size);
|
||||
(void)obj;
|
||||
strncpy(p, "TODO...", p_max_size);
|
||||
}
|
||||
|
26
src/xmms2.cc
26
src/xmms2.cc
@ -289,9 +289,7 @@ int update_xmms2(void) {
|
||||
|
||||
/* initialize connection */
|
||||
if (current_info->xmms2.conn_state == CONN_INIT) {
|
||||
if (xmms2_conn == nullptr) {
|
||||
xmms2_conn = xmmsc_init(PACKAGE_NAME);
|
||||
}
|
||||
if (xmms2_conn == nullptr) { xmms2_conn = xmmsc_init(PACKAGE_NAME); }
|
||||
|
||||
/* did init fail? */
|
||||
if (xmms2_conn == nullptr) {
|
||||
@ -351,20 +349,23 @@ int update_xmms2(void) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void print_xmms2_tracknr(struct text_object *obj, char *p, unsigned int p_max_size) {
|
||||
void print_xmms2_tracknr(struct text_object *obj, char *p,
|
||||
unsigned int p_max_size) {
|
||||
(void)obj;
|
||||
if (info.xmms2.tracknr != -1) {
|
||||
snprintf(p, p_max_size, "%i", info.xmms2.tracknr);
|
||||
}
|
||||
}
|
||||
|
||||
void print_xmms2_elapsed(struct text_object *obj, char *p, unsigned int p_max_size) {
|
||||
void print_xmms2_elapsed(struct text_object *obj, char *p,
|
||||
unsigned int p_max_size) {
|
||||
(void)obj;
|
||||
snprintf(p, p_max_size, "%02d:%02d", info.xmms2.elapsed / 60000,
|
||||
(info.xmms2.elapsed / 1000) % 60);
|
||||
}
|
||||
|
||||
void print_xmms2_duration(struct text_object *obj, char *p, unsigned int p_max_size) {
|
||||
void print_xmms2_duration(struct text_object *obj, char *p,
|
||||
unsigned int p_max_size) {
|
||||
(void)obj;
|
||||
snprintf(p, p_max_size, "%02d:%02d", info.xmms2.duration / 60000,
|
||||
(info.xmms2.duration / 1000) % 60);
|
||||
@ -376,7 +377,8 @@ double xmms2_barval(struct text_object *obj) {
|
||||
return info.xmms2.progress;
|
||||
}
|
||||
|
||||
void print_xmms2_smart(struct text_object *obj, char *p, unsigned int p_max_size) {
|
||||
void print_xmms2_smart(struct text_object *obj, char *p,
|
||||
unsigned int p_max_size) {
|
||||
(void)obj;
|
||||
int artist_len = strlen(info.xmms2.artist);
|
||||
int title_len = strlen(info.xmms2.title);
|
||||
@ -389,11 +391,11 @@ void print_xmms2_smart(struct text_object *obj, char *p, unsigned int p_max_size
|
||||
}
|
||||
}
|
||||
|
||||
#define XMMS2_PRINT_GENERATOR(name, fmt) \
|
||||
void print_xmms2_##name(struct text_object *obj, char *p, \
|
||||
unsigned int p_max_size) { \
|
||||
(void)obj; \
|
||||
snprintf(p, p_max_size, fmt, info.xmms2.name); \
|
||||
#define XMMS2_PRINT_GENERATOR(name, fmt) \
|
||||
void print_xmms2_##name(struct text_object *obj, char *p, \
|
||||
unsigned int p_max_size) { \
|
||||
(void)obj; \
|
||||
snprintf(p, p_max_size, fmt, info.xmms2.name); \
|
||||
}
|
||||
|
||||
XMMS2_PRINT_GENERATOR(artist, "%s")
|
||||
|
21367
tests/catch2/catch.hpp
21367
tests/catch2/catch.hpp
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user