]> git.itanic.dy.fi Git - rrdd/log
rrdd
7 years agoprocess: Remove fork based concurrenct management
Timo Kokkonen [Sat, 9 Jul 2016 14:47:30 +0000 (17:47 +0300)]
process: Remove fork based concurrenct management

The thread based concurrency system replaces the fork based
system. Remove all deprecated code out of the way.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
7 years agorun_work_on_queue: Remove excess debug print
Timo Kokkonen [Sat, 9 Jul 2016 11:15:06 +0000 (14:15 +0300)]
run_work_on_queue: Remove excess debug print

If the thread goes to sleep, the queues must be empty. No need to have
an explicit print for it.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
7 years agoinit_job_control: Suppress compiler warning
Timo Kokkonen [Sat, 9 Jul 2016 11:12:54 +0000 (14:12 +0300)]
init_job_control: Suppress compiler warning

On 64 bit arch casting an int to (void *) causes a warning about
different word sizes. Use long int so that the variables have same
length.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
7 years agoprocess: Remove signal handler completely
Timo Kokkonen [Sat, 9 Jul 2016 11:09:40 +0000 (14:09 +0300)]
process: Remove signal handler completely

There is no need for this at all any more. This was only used for
reaping the childs on the fork based concurrency management. Now that
threads are doing forking on the same namespace, threads that are
expecting signals might get confused when the main thread handles the
sigchld signal on behalf of the thread. Remove the handler completely
to avoid any confusion.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
7 years agodo_rrdtool_update_data: Initialize data buffer
Timo Kokkonen [Sat, 9 Jul 2016 10:22:28 +0000 (13:22 +0300)]
do_rrdtool_update_data: Initialize data buffer

Make sure the data buffer is zeroed completely before use. This
silences a walgrind warning of uninitialzed data usage.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
7 years agorrdtool: Remove unused variables
Timo Kokkonen [Sat, 9 Jul 2016 10:21:15 +0000 (13:21 +0300)]
rrdtool: Remove unused variables

These are leftovers from making the run() function synchronous.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
7 years agorrdtool_draw_image: Remove excess strlen() call
Timo Kokkonen [Sat, 9 Jul 2016 10:19:02 +0000 (13:19 +0300)]
rrdtool_draw_image: Remove excess strlen() call

strncat is already good enough ensuring target buffer will not
overflow. There is no need to use strlen at all.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
7 years agobuilt_in_parsers: Strenghten string handling
Timo Kokkonen [Sat, 9 Jul 2016 10:13:33 +0000 (13:13 +0300)]
built_in_parsers: Strenghten string handling

Replace all hard coded string lengths with sizeof(). Make sure data is
null terminated on script_parser().

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
7 years agoMerge branch 'master' of /home/git/rrdd
Timo Kokkonen [Sat, 9 Jul 2016 07:05:36 +0000 (10:05 +0300)]
Merge branch 'master' of /home/git/rrdd

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
7 years agoprocess: Make run() execute synchronously
Timo Kokkonen [Sat, 9 Jul 2016 06:50:07 +0000 (09:50 +0300)]
process: Make run() execute synchronously

Currently there are no need for running the process asynchronously on
background, so we might just make it run synchronously instead. This
simplifies the calling convention and also removes completely the need
to fork and possibly race in glibc functions.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
7 years agoConvert rrdtool to use work queues instead of forks
Timo Kokkonen [Sat, 9 Jul 2016 06:44:51 +0000 (09:44 +0300)]
Convert rrdtool to use work queues instead of forks

Switch to the work queue model. Change is somewhat trivial. The
database update timestamp update is now done before the actual
update. We don't have a mean to distinguis from the fact that we have
initiated an update but not done it yet, so we mark it as "done" and
then queue the update. Without this change the main thread will keep
on queueing the update indefinitely as the worker thread takes too
long to actually mark the update as done.

To ensure the queues work properly, we also need to disable sigchld
handler from the process controller so that it does not get confused
when threads are reaping the childs them selves. This is different
from the previous model where each process required to handle their
own child reaping after fork(). Now we are sharing the signals with
the parent. This is a major simplification on how this works.

The magic sleep on job control init can be removed as well as there
are less forks going on now.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
7 years agoprocess.c: Introduce work queues
Timo Kokkonen [Fri, 8 Jul 2016 19:44:39 +0000 (22:44 +0300)]
process.c: Introduce work queues

Work queues are a way to execute function calls asynchronously. Each
work is placed on a fifo queue where worker threads pick them up one
by one.

Priority levels are also supported, right now two levels are
available. All high priority works are executed before workers pick up
low priority works.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
7 years agodebug: Print thread name on debug prints
Timo Kokkonen [Fri, 8 Jul 2016 19:17:09 +0000 (22:17 +0300)]
debug: Print thread name on debug prints

Many different threads might be calling the same functions
concurrently. Add the name of the thread so that it becomes more
obvious which thread is emitting the given print.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
7 years agoprocess: Add debug wrappers for pthread mutex operations
Timo Kokkonen [Fri, 8 Jul 2016 19:42:42 +0000 (22:42 +0300)]
process: Add debug wrappers for pthread mutex operations

This is the beginning of the work to convert the concurrency model
from fork-bomb based model to pthreads.

To get started, add a wrapper functions to handle locking. Namely,
these wrappers will log where the lock was acquired and will print out
who is holding it in case of contention.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
7 years agoprocess.c: Trivial white space cleanup
Timo Kokkonen [Fri, 8 Jul 2016 09:39:30 +0000 (12:39 +0300)]
process.c: Trivial white space cleanup

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
9 years agoprocess: run: Fix bug with multi-line prints
Timo Kokkonen [Tue, 28 Oct 2014 19:25:40 +0000 (21:25 +0200)]
process: run: Fix bug with multi-line prints

Once newlines are replaces with NULLs for printing, we must start the
next line after the NULL. Without this all extra printout lines are
zero in length.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
9 years agorrdtool: Add support for post_draw_cmd
Timo Kokkonen [Tue, 28 Oct 2014 19:16:21 +0000 (21:16 +0200)]
rrdtool: Add support for post_draw_cmd

Just like pre_draw_cmd, post_draw_cmd is a command that gets to be
executed after graphs are drawn. This is useful for example
transferring generated graphs into final location once rendering is
complete.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
9 years agoMerge remote-tracking branch 'origin/master'
Timo Kokkonen [Sun, 26 Oct 2014 15:35:34 +0000 (17:35 +0200)]
Merge remote-tracking branch 'origin/master'

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
9 years agorrdtool.c: Null terminate process argument list in add_arg
Timo Kokkonen [Sun, 26 Oct 2014 15:12:34 +0000 (17:12 +0200)]
rrdtool.c: Null terminate process argument list in add_arg

add_arg macro was not null teriminating argument list. Null
termination was left as an responsibility for the caller. This is
error prone as this requirement is not clear.

Add null termination in the add_arg macro so that caller does not need
to care about it.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
9 years agoprocess.c: Reduce maximum number of parallel jobs on UP machines
Timo Kokkonen [Tue, 9 Sep 2014 19:17:37 +0000 (22:17 +0300)]
process.c: Reduce maximum number of parallel jobs on UP machines

We generally don't see sinlge-cpu systems any more in other than
embedded devices, where chances of being very low in RAM is a very
real possibility. If the maximum number of parallel jobs is too large
there, is is quite possible that we run out of memory on such systems.

Reducing the number of jobs makes such devies much less likely to
exceed their memory capacity.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
9 years agoonewire_parser: Make sensor readin more robust on noisy 1-wire networks
Timo Kokkonen [Wed, 20 Aug 2014 19:07:05 +0000 (22:07 +0300)]
onewire_parser: Make sensor readin more robust on noisy 1-wire networks

On noisy environment there may be transient read failures with some
1-wire sensors. The sensors might "come and go" and also read results
might fail with "85 degree results".

Try to work around the issue by retrying a sensor read with uncached
data. This helps in cases where there was a error during 1-wire scan
and some sensors were not detected. This also helps when sensor
responds but reading the result produces "85" degree result.

Reading should be significantly more reliable with this change.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
11 years agoAdd support for data logging
Timo Kokkonen [Sun, 6 Jan 2013 13:49:14 +0000 (15:49 +0200)]
Add support for data logging

Add new configuration parameters "logfile" and
"logfile_timestamp_fmt". Both of them are fed through strftime. The
first one is used for creating log file name, the second one is the
time stamp format in the beginning of each line.

Neither of the options are mandatory. If no file name is given, no
logging will be done. If no time stamp format is given, default of
"%Y.%m.%d %H:%M " is used.

Each line in the log file contains all the data elements given to
rrdtool during updating the database. The format is altered
slightly. The beginning of the line has got the time stamp, the
beginning "N:" part is removed and all ':' characters are replaced
with white space. Each entry is padded up to 12 characters with white
space in order to make the log file entries nicely human readable.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
11 years agoRemove excess debug prints from default trace level
Timo Kokkonen [Fri, 30 Nov 2012 16:49:50 +0000 (18:49 +0200)]
Remove excess debug prints from default trace level

Now that we have debug print macro, move some of the most chatty
messages to the debug level from cluttering normal output.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
11 years agoUser arguments: Add support for adjusting tracing level
Timo Kokkonen [Fri, 30 Nov 2012 16:47:03 +0000 (18:47 +0200)]
User arguments: Add support for adjusting tracing level

--verbose or -v increase verbosity
--quiet or -q decreases verbosity

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
11 years agodebug: Improve debugging macros
Timo Kokkonen [Fri, 30 Nov 2012 16:34:54 +0000 (18:34 +0200)]
debug: Improve debugging macros

Define different debug levels in one enum list instead of hard coding
with magic numbers.

Add two new debugging macros, one intended for warning messages and
another for pure debugging messages.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
11 years agoMakefile: Adjust default targets
Timo Kokkonen [Fri, 30 Nov 2012 16:13:53 +0000 (18:13 +0200)]
Makefile: Adjust default targets

The "all" target will now build all parsers in addition to the main
executable. The "default" target builds only the main executable, thus
default setup will not have libownet build requirement.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
11 years agodebug: Add support for log files
Timo Kokkonen [Fri, 30 Nov 2012 16:11:01 +0000 (18:11 +0200)]
debug: Add support for log files

A new command line argument --logfile or -l is now supported for
logging purposes.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
11 years agoMakefile: Fix typo in object list
Timo Kokkonen [Tue, 20 Nov 2012 20:08:07 +0000 (22:08 +0200)]
Makefile: Fix typo in object list

The ONEWIRE_PARSER_OBJS was written incorrectly. This causes ALL_OBJS
list to miss the parser object, which in turn causes the dependency
file to be missing from the ALL_DEBS list. That was causing make to
not detect that onewire_parser.c depends on version.h, and not rebuild
the library when version.h was changed.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
11 years agoplugins: Add version checking
Timo Kokkonen [Tue, 20 Nov 2012 19:16:01 +0000 (21:16 +0200)]
plugins: Add version checking

Ensure that plugin is always built from the same version as the main
rrdd executable. If the version numbers don't match, don't load the
plugin.

This will ensure there are no strange bugs that appear when plugin
code is not built against the same source as the main executable.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
11 years agoAdd automatic versioning and compiler checks
Timo Kokkonen [Tue, 20 Nov 2012 16:32:28 +0000 (18:32 +0200)]
Add automatic versioning and compiler checks

Generate a version string from the git HEAD commit. This makes it
possible to distinguish different versions of rrdd from each others.

Also add compiler string check. If compiler changes, rebuild
everything.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
11 years agoonewire_parser: Convert to a plugin
Timo Kokkonen [Mon, 19 Nov 2012 20:12:09 +0000 (22:12 +0200)]
onewire_parser: Convert to a plugin

Onewire parser is the only piece of code here that depends on libownet
and requires linking against it. This is cumbersome whenever we wish
to build rrdd and we are not interested in having support for onewire
at all.

Converting the parser to a plugin solves the issue: We can now build
main rrdd without libownet dependency. Even if we have built the
onewire parser, we don't need to load it unless we are actually using
it.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
11 years agoparser: Try loading a parser from a plugin in case no parser is found
Timo Kokkonen [Mon, 19 Nov 2012 19:59:00 +0000 (21:59 +0200)]
parser: Try loading a parser from a plugin in case no parser is found

When a parser is queried and one is not found within the ones that we
have already registered, try loading a plugin with that name. If
parser plugins are available, the parser might be available after the
plugin has been loaded.

The project is now fully compatible with having parsers as plugins.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
11 years agoplugin_manager: Load parser plugins by name
Timo Kokkonen [Mon, 19 Nov 2012 19:45:39 +0000 (21:45 +0200)]
plugin_manager: Load parser plugins by name

A parser plugin is a plugin that has name "%s_parser.so", where "%s"
is the name of the parser. Implement a function that will try to find
a parser plugin by a name. If we can't find such plugin from the
global library path, try some other places as well, such as current
working directory and executable path.

In order to know the executable path, the plugin manager needs to be
initialized with the executable path. We are now doing it in the
beginning of the main function.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
11 years agoUpdate .gitignore
Timo Kokkonen [Mon, 19 Nov 2012 19:43:30 +0000 (21:43 +0200)]
Update .gitignore

Add some entries that clutter the working tree often

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
11 years agomain.c: Consider default argument as a config file
Timo Kokkonen [Mon, 19 Nov 2012 18:44:06 +0000 (20:44 +0200)]
main.c: Consider default argument as a config file

If one does not specify any option, just gives an argument, it is a
good assumption that one is giving a config file.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
11 years agoParsers: Implement framework for registering and querying parsers
Timo Kokkonen [Mon, 19 Nov 2012 18:43:52 +0000 (20:43 +0200)]
Parsers: Implement framework for registering and querying parsers

This framework can be used to register parsers and get parsers by a
string name. This allows all need for hard coding string and parser
function names together.

All existing parsers are converted to use the new framework.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
11 years agoRemove database.h
Timo Kokkonen [Mon, 19 Nov 2012 16:48:38 +0000 (18:48 +0200)]
Remove database.h

Instead of having a database built in the software, have one being
provided with a config file instead. Keeping the database header file
is becoming a maintenance burden.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
11 years agoAdd utils.h
Timo Kokkonen [Mon, 19 Nov 2012 16:40:29 +0000 (18:40 +0200)]
Add utils.h

Collect all random utilities in one header file available to all
users.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
11 years agoIntroduce plugin manager
Timo Kokkonen [Mon, 19 Nov 2012 15:31:18 +0000 (17:31 +0200)]
Introduce plugin manager

Plugin manager can load plugins at run time from libraries. It expects
the plugin to contain one symbol, which contains plugin_info structure
defined in plugin.h file. The .init function is executed from within
the structure.

Add -rdynamic compiler flag in order to make the existing symbols
become visible to the dynamically loaded libraries.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
11 years agorrdtool: Add pre_draw_cmd
Timo Kokkonen [Sat, 10 Nov 2012 11:35:29 +0000 (13:35 +0200)]
rrdtool: Add pre_draw_cmd

This is a configurable command that can be executed before drawing
images.

Right now only "shell" command is supported. This takes a set of
string arguments that are executed via execv.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
11 years agojobcontrol: Fork bomb prevental
Timo Kokkonen [Sun, 28 Oct 2012 16:12:08 +0000 (18:12 +0200)]
jobcontrol: Fork bomb prevental

If something happens that prevents existing jobs from terminating, it
is generally bad practice to keep on forking more processes
indefinitely. To alleviate the problem, implement a somewhat trivial
process limitation feature. This will define a limit of maximum number
for the processes pending execution. If the number exceeds the global
limit, new processes are to be terminate itself immediately.

This however prevents only "limited forks" for creating too many
processes for waiting execution. Normal forks still have no
limit. This should still make the system to stay alive longer during
situations where something prevents (temporarily) executing processes
to finish in time.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
11 years agorrd images: Make the timestamp string configurable
Timo Kokkonen [Sun, 28 Oct 2012 10:45:01 +0000 (12:45 +0200)]
rrd images: Make the timestamp string configurable

Make it possible to replace the "Last update ..." string with
something that fits better for the needs of the end user. The string
is passed through strftime so one can use arbitrary timestamp formats.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
11 years agoconfig: Fix copy paste errors in error messages
Timo Kokkonen [Sun, 28 Oct 2012 10:41:48 +0000 (12:41 +0200)]
config: Fix copy paste errors in error messages

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
11 years agoprocess: Implement event handling infrastructure
Timo Kokkonen [Thu, 11 Oct 2012 18:30:20 +0000 (21:30 +0300)]
process: Implement event handling infrastructure

Implement proper event registration infrastucture for handling the
events coming in through the file descriptors. This makes it possible
to expand the polling code to arbitrary number of file descriptors.

All current users of the epoll have been converted to the new
infra. Some functions were moved higher in the file in order to make
it possible to reference them in the init_jobcontrol() function.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
11 years agoprocess: request_fork: Ensure function parameter is always signed
Timo Kokkonen [Mon, 1 Oct 2012 14:45:52 +0000 (17:45 +0300)]
process: request_fork: Ensure function parameter is always signed

Some architectures, such as armv6, treat char as an unsigned integer
instead of signed. Basically it makes no sense to use char type with
the variable. When it is changed to an int there is no confusion about
the type and it will work better with all architectures.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
11 years agorrdtool_update_data: Print out the input data
Timo Kokkonen [Sat, 29 Sep 2012 17:09:56 +0000 (20:09 +0300)]
rrdtool_update_data: Print out the input data

It appears that it is quite often useful to see what is the actual
data that is being put into the rrd database. Therefore, print out the
data always.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
11 years agoRemove extra space from debug prints
Timo Kokkonen [Tue, 17 Jul 2012 11:32:36 +0000 (14:32 +0300)]
Remove extra space from debug prints

Concatenating the two strings caused on extra space to appear on all
debug prints. Remove the extra space to make prints more pretty.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
11 years agoMerge scheduler.c into rrdtool.c
Timo Kokkonen [Tue, 17 Jul 2012 11:26:22 +0000 (14:26 +0300)]
Merge scheduler.c into rrdtool.c

The schedule calculations were all very much dependent on the rrdtool
code and not something independent. It doesn't make sense to keep it
separate from the rrdtool code.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
11 years agoonewire_parser: Add support for temperature offsets
Timo Kokkonen [Mon, 2 Jul 2012 18:55:24 +0000 (21:55 +0300)]
onewire_parser: Add support for temperature offsets

Some temperature sensors may have a significant systematic error
offset on their readings. This patch makes it possible to define an
offset value that is added to the raw value before the result is
stored in the rrd database.

From now on it is assumed that each onewire path never contains white
space. If there is a white space within the server path, it is
expected that each string that is separated with white space contains
an option that is used to control the readout of the values returned
or available from the server.

At the moment only one option is supported; temperature offset. The
option string must contain "offset=" following a decimal number. The
offset value is added to the number read from the server.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
11 years agoscheduler: Give the name of the next db to be updated
Timo Kokkonen [Thu, 28 Jun 2012 07:55:41 +0000 (10:55 +0300)]
scheduler: Give the name of the next db to be updated

This is somewhat useful in debugging as the user will be able to know
which database will be updated next, so he can anticipate what kind of
output there is to be expected soon.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
11 years agorrdtool: Ensure data read by the parser is always NULL terminated
Timo Kokkonen [Wed, 27 Jun 2012 19:06:07 +0000 (22:06 +0300)]
rrdtool: Ensure data read by the parser is always NULL terminated

To seal out any possible denial of service attacs, do not expect the
parsers to return data that is NULL terminated.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
11 years agoscript_parser: Fix fread to return number of bytes read
Timo Kokkonen [Wed, 27 Jun 2012 19:00:50 +0000 (22:00 +0300)]
script_parser: Fix fread to return number of bytes read

From fread man page:

The function fread() reads nmemb elements of data, each size bytes
long, from the stream pointed to by stream, storing them at the
location given by ptr.

If size is something else than 1, the return value is not number of
bytes read. The intention here is to have it return number of bytes so
that the debug print can print it correctly.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
11 years agoprocess: Print process output through the debug macros
Timo Kokkonen [Wed, 27 Jun 2012 15:35:50 +0000 (18:35 +0300)]
process: Print process output through the debug macros

As we are appending our own prefixes to all process prints, we might
aswell use the normal debug macros to unify the prints with the rest
of the debug output.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
11 years agoparser: Remove old debug print
Timo Kokkonen [Wed, 27 Jun 2012 15:29:14 +0000 (18:29 +0300)]
parser: Remove old debug print

All debug prints should use the pr_* variants instead of printf
directly. This one print in question is not very useful, so it can be
removed altogether.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
11 years agoprocess: Fix bug with child processes stuck forever when parent segfaults
Timo Kokkonen [Wed, 27 Jun 2012 15:18:19 +0000 (18:18 +0300)]
process: Fix bug with child processes stuck forever when parent segfaults

After a fork() the child needs to close the unused end of the process
control pipes. Failing to do so will prevent EOF and EPIPE signals
from being delivered correctly back to the child when the parent
closes its end of the pipe.

Furthermore, the code's assumption about the behaviour of the pipe
with one writer and multiple readers was wrong. When there are
multiple readers, only one will be woken up and the rest will be left
blocking the read in case there was nothing left to read. If read
returns zero, that means EOF, eg. the job control parent has closed
its end of the pipe.

These fixes applied there should be no more problem with a lot of
child processes stuck in waiting the parent to give them a permission
to go. They will either fail with SIGPIPE when they request the
permission to run or they will read zero bytes from the pipe and
continue executing instantly.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
11 years agomain: Print out the time when next even it expected
Timo Kokkonen [Tue, 26 Jun 2012 19:17:30 +0000 (22:17 +0300)]
main: Print out the time when next even it expected

This is useful during debugging and we want to know when the next
event begins.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
11 years agodebug: Reintroduce message colouring
Timo Kokkonen [Tue, 26 Jun 2012 13:40:58 +0000 (16:40 +0300)]
debug: Reintroduce message colouring

When the debug macros were refactored into a separate function, all
messages were printed with green color. Change it to use the desired
color instead.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
11 years agodebug.c: Remove indentation from the prints
Timo Kokkonen [Tue, 26 Jun 2012 13:33:14 +0000 (16:33 +0300)]
debug.c: Remove indentation from the prints

The child-depth indentation is not really that useful. In fact, it
makes actually harder to read similar debug print lines with different
indentation. The numerical level of the child generation gives
sufficient information.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
11 years agodebug: Rework debugging
Timo Kokkonen [Sun, 24 Jun 2012 19:59:23 +0000 (22:59 +0300)]
debug: Rework debugging

Instead of having a huge debug macro that gets expanded every time a
debug print is needed, separate the debugging facilities into
debu.c. This will reduce excess code duplication a lot.

A concept of debugging level is also introduced. This makes it
possible to add debug prints with different priority level and have
some of the prints to be silenced when user is not interested about
them.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
11 years agoAdd missing headers
Timo Kokkonen [Sun, 24 Jun 2012 19:57:25 +0000 (22:57 +0300)]
Add missing headers

These files were depending on headers from debug.h. The debug.h is
going to be cleaned up and these files no longer compile without these
headers.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
11 years agoAdd onewire parser
Timo Kokkonen [Sun, 24 Jun 2012 08:47:25 +0000 (11:47 +0300)]
Add onewire parser

This parser will parse data from onewire server. It will use the
network protocol to query the data, thus it is capable of fetching the
data over any network location supported by the ownet library.

The first parser_data string must containt the server address:ip. The
rest of the strings are used to query data entries from the server. If
one wishes to leave blank entries to some of the data, a "U" string is
passed as is to the rrd_data.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
11 years agoAdd MIN() macro
Timo Kokkonen [Sun, 24 Jun 2012 08:54:35 +0000 (11:54 +0300)]
Add MIN() macro

As we don't have yet any header for random useful macros, add this
here so that parsers can utilize it.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
11 years agorrdtool.c: Improve data sanitization
Timo Kokkonen [Sun, 24 Jun 2012 08:29:27 +0000 (11:29 +0300)]
rrdtool.c: Improve data sanitization

The code is doing rather complex string manipulation. Without
sufficient commentation it is hard to understand what it really
does. Better documentation is now included.

Non-numerical data is also now marked as undefined, if there are no
numbers at all in the input data. Completely empty entries are also
marked as undefined.

Finally, santitized string output is NULL terminated even if also the
last entry was undefined.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
11 years agoChange parser parameter type
Timo Kokkonen [Sat, 23 Jun 2012 12:17:25 +0000 (15:17 +0300)]
Change parser parameter type

As the parser parameter is coming from the config file now and it is
defined as a list of strings there, the type of the parameter on the
parser function type should match it.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
11 years agoconfig.c: Fix macro variable usage
Timo Kokkonen [Sat, 23 Jun 2012 10:46:05 +0000 (13:46 +0300)]
config.c: Fix macro variable usage

The variable name was missing an underscore, thus it was using the
variable outside of its parameter list.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
11 years agoEnable database reading and writing, if requested from command line
Timo Kokkonen [Wed, 20 Jun 2012 19:59:27 +0000 (22:59 +0300)]
Enable database reading and writing, if requested from command line

If no command line arguments are given, continue using the old built
in database config. But if appropriate config is given as a command
line argument, read the entries from the file. If the user does not
have a database config file to get started with, make it possible for
the default database to be created as a starting point.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
11 years agoAdd Initial version of config file handling
Timo Kokkonen [Wed, 20 Jun 2012 19:55:42 +0000 (22:55 +0300)]
Add Initial version of config file handling

Support for reading and writing database entries from and to config
files. Can handle most of the normal cases.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
11 years agoRename the built in database to default_rrds
Timo Kokkonen [Wed, 20 Jun 2012 19:50:34 +0000 (22:50 +0300)]
Rename the built in database to default_rrds

In future this is not going to be the database in use, but the default
one that contains the data that can be used to dump the default
database list. Thus the change in the name.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
11 years agorrdtool.c: Improve error handling during database creation
Timo Kokkonen [Wed, 20 Jun 2012 19:22:23 +0000 (22:22 +0300)]
rrdtool.c: Improve error handling during database creation

The case of filename pointer being NULL was not handled. The logic for
testing whether the database file existed at all should not return
true in case the file name is zero. As this function can't return
failure code, the error of NULL filename pointer is handled later when
the database is being created.

As many missing databases are created as possible. In case of errors
we will continue hoping that we will be able to update at least
something.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
11 years agonetstats_parser: Fix crash when network device names are undefined
Timo Kokkonen [Wed, 20 Jun 2012 19:19:25 +0000 (22:19 +0300)]
netstats_parser: Fix crash when network device names are undefined

There is absolutely nothing this parser can do without the network
names. If the pointer happens to be zero, all we can do is to bail out
with a error print. Not handling this situation will lead to a crash.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
11 years agorrdtool.h: Constify string constants
Timo Kokkonen [Mon, 4 Jun 2012 15:42:58 +0000 (18:42 +0300)]
rrdtool.h: Constify string constants

String constants are being stored to these fields, so they should be
constants. Relacant casts and other changes are made within all users
of these structures.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
11 years agomain: Add NULL terminator to option array
Timo Kokkonen [Sat, 19 May 2012 18:06:49 +0000 (21:06 +0300)]
main: Add NULL terminator to option array

getopt_long() requires the struct option array to be terminated with
an element that is filled with zeroes.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
11 years agoprocess: Replace racy SIGCHLD handler with signalfd
Timo Kokkonen [Tue, 15 May 2012 19:13:25 +0000 (22:13 +0300)]
process: Replace racy SIGCHLD handler with signalfd

Having an asynchronous signal handler for SIGCHLD handling is quite
racy. We would like to be able to print debug messages when reaping
children, but we cannot use printf or other signal unsafe function
calls.

Signalfd is the solution that works. As we already have event loop
with epoll, we can extend it to read the signals via the
descriptor. And there is also one place less for causing potential
race conditions.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
11 years agoprocess: Improve harvest_zombies
Timo Kokkonen [Tue, 15 May 2012 19:07:18 +0000 (22:07 +0300)]
process: Improve harvest_zombies

Use wait4 instead of waitpid. This makes it possible to get resource
usage information from the child that exited. The user and system time
is printed out for curious developer to inspect.

If a child happens to be stopped or continued, we are now ignoring
those state changes. This prevents zombie processes to be left in case
something special happens to the child.

Further improvement is that it is possible to tell whether the child
was killed with some signal or if it exited with a code.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
11 years agoprocess.c: Factor out job request handling
Timo Kokkonen [Sun, 13 May 2012 15:06:45 +0000 (18:06 +0300)]
process.c: Factor out job request handling

Separate the epoll_wait handling and the actual file descriptor
handling. This is preparation for signald_fd handling.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
11 years agomain: Exit on init_jobcontrol failure
Timo Kokkonen [Sat, 12 May 2012 19:41:43 +0000 (22:41 +0300)]
main: Exit on init_jobcontrol failure

If we fail to initialize critical structures, there is no point in
proceeding any further.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
11 years agoprocess.c: Move epoll initialization into init_jobcontrol()
Timo Kokkonen [Sat, 12 May 2012 19:17:40 +0000 (22:17 +0300)]
process.c: Move epoll initialization into init_jobcontrol()

This is where the rest of the job control structures are initialized,
this should be initialized there too.

The missing epoll_ctl error handling is also now in.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
11 years agoRename init_max_jobs() to init_jobcontrol()
Timo Kokkonen [Sat, 12 May 2012 19:14:00 +0000 (22:14 +0300)]
Rename init_max_jobs() to init_jobcontrol()

This describes better what the function does; it initializes the
entire jobcontrol into functional state. That is more than setting the
number of maximum jobs.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
12 years agomain: Implement command line parsing
Timo Kokkonen [Wed, 25 Apr 2012 15:22:34 +0000 (18:22 +0300)]
main: Implement command line parsing

The first command line option we support is the number of jobs to run
in parallel.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
12 years agorrdtool: Set up the correct executable name when running processes
Timo Kokkonen [Sun, 22 Apr 2012 18:46:42 +0000 (21:46 +0300)]
rrdtool: Set up the correct executable name when running processes

The first argument, the name of the executable, should be set properly
prior running execv(). This ensures the process knows properly how it
was called. There might be a difference in case the process implements
multiple personalities based on the name it was called.

This does not appear to be the case with rrdtool as it was working
even if the executable name was left blank.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
12 years agoprocess: sigchild_handler: Only call waitpid()
Timo Kokkonen [Sun, 15 Apr 2012 19:03:21 +0000 (22:03 +0300)]
process: sigchild_handler: Only call waitpid()

Calling any *printf* functions from a signal handler is unsafe. If the
interrupted process happened to be in the middle of a printf call
during the arrival of the signal, the signal handler can freeze
silently.

To avoid this, the sigchild handler will no longer call
harvest_zombies() to clear out the zombie processes. This hides the
exit status of the process, but that is not that significant
information.

An alternative way would be to simply do nothing in the signal handler
except set some flag indicating the death of a child. The signal would
cause the epoll_wait to fail with EINTR error that can be used to
trigger waitpid.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
12 years agodebug: Flush debug prints out immedeatly
Timo Kokkonen [Sun, 15 Apr 2012 18:21:37 +0000 (21:21 +0300)]
debug: Flush debug prints out immedeatly

This should ensure log output is free of possible corruptions due to
stdio buffering.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
12 years agorrdtool_draw_image: Draw images in parallel
Timo Kokkonen [Sun, 15 Apr 2012 18:20:35 +0000 (21:20 +0300)]
rrdtool_draw_image: Draw images in parallel

Use the do_fork_limited() to draw images in parallel while avoiding to
draw too many images at the same time.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
12 years agomain.c: Enable job control
Timo Kokkonen [Sun, 15 Apr 2012 18:18:39 +0000 (21:18 +0300)]
main.c: Enable job control

Start using the new job control feature. No need to sleep any more
fixed sleeps. The job scheduler will use epoll_wait timeout for
sleeping instead.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
12 years agoprocess.c: Implement support for limiting number of active processes
Timo Kokkonen [Sun, 15 Apr 2012 18:08:26 +0000 (21:08 +0300)]
process.c: Implement support for limiting number of active processes

This will make it possible to have only limited number of active job
processes runnint at given time. These can be requested by calling
do_fork_limited(), which works otherwise similarly to do_fork() but
the child process will not start running until the main parent has
given the child permission to run.

The job controlling is implemented via pipes between the parent and
the children. The child which wish to limit the number of processes
will send its pid to the parent. The master parent will keep count of
all the processes running. If the number of active processes grows too
high, no new jobs are granted until fewer processes are running. Once
the parent decides that a new job can become active, it will write one
byte to a pipe. The child which reads the byte out is the one who has
the right to execute. Other children reading the same pipe are left
waiting for their turn.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
12 years agoprocess.c: Remove the rest of the printf() calls
Timo Kokkonen [Sun, 15 Apr 2012 17:31:07 +0000 (20:31 +0300)]
process.c: Remove the rest of the printf() calls

No reason to not unify the prints whenever possible.

However, the process stdout and stderr prints are special. They do not
come from rrdd, but from the process that was execv'd by rrdd. That
why they should begin with the name of the binary. Those prints should
be printed to stderr too to unify the debug output.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
12 years agoprocess: Remove get_sibling_count()
Timo Kokkonen [Sun, 15 Apr 2012 17:26:02 +0000 (20:26 +0300)]
process: Remove get_sibling_count()

This function does not really provide any useful information. It was
used only in the debug prints, where it was printed after the pid
number. However, it is much more useful to print the parent count
instead to see how deep we are in the fork chain.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
12 years agorrdtool: Improve debug prints
Timo Kokkonen [Sat, 14 Apr 2012 17:39:19 +0000 (20:39 +0300)]
rrdtool: Improve debug prints

Use the debug macro for printing. Also remove the unimportant message
indicating the job is done. It is obvious that all is done when other
prints start coming out.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
12 years agorrdtool: Rename rrdtool_check_databases() to rrdtool_create_missing_databases()
Timo Kokkonen [Sat, 14 Apr 2012 17:38:05 +0000 (20:38 +0300)]
rrdtool: Rename rrdtool_check_databases() to rrdtool_create_missing_databases()

This name is more descriptive with respect to what the function
actually does.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
12 years agoscheduler: Rename check_update_need() to get_outdated_db()
Timo Kokkonen [Sat, 14 Apr 2012 17:32:34 +0000 (20:32 +0300)]
scheduler: Rename check_update_need() to get_outdated_db()

The new name is more descriptive with respect what the function
actually does.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
12 years agoRemove redundant strerror usage
Timo Kokkonen [Sat, 14 Apr 2012 12:06:52 +0000 (15:06 +0300)]
Remove redundant strerror usage

It is preferred to use '%m' with printf instead.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
12 years agoprocess: Improve error handling
Timo Kokkonen [Sat, 14 Apr 2012 12:01:19 +0000 (15:01 +0300)]
process: Improve error handling

Check the error message from select(). If error, bail out.

Also close all file descriptors in the end. If select happends to fail
and we go to waitpid() and the process is writing content, it might
eventually block because nobody is reading the file descriptor. By
closing the file we ensure the process will not hang and there will be
no deadlock.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
12 years agorrdtool: Reduce excess parallelism
Timo Kokkonen [Thu, 12 Apr 2012 18:52:09 +0000 (21:52 +0300)]
rrdtool: Reduce excess parallelism

Right now all commands are run "as parallel as possible", up to the
point images are being drawn while the databases are still
updated. This leads to problems where the image drawing finishes
before databases are read, thus the image contains always the
information from the last update instead of current.

This patch modifies the behavior so that when the database is being
updated, the drawing does not beging before the update has
succeeded.

Furthermore, image drawings are not done fully parallel. If they were,
the temporary file would be always renamed before there was any chance
that the actual image rendering was finished. Instead, rename is
synchronized with the image drawing.

As a consequence total parallelism is greatly reduced. This obviously
slows down update and image drawing process greatly on machines that
have many CPUs, that would otherwise benefit greatly from being able
to all actions in parallel. The maximum number of parallel actions is
practically limited to the number of databases that are being operated
with. The correctness of the operations is however more important than
maximising parallelism.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
12 years agodebug.h: Add timestamps to debug prints
Timo Kokkonen [Thu, 12 Apr 2012 18:47:24 +0000 (21:47 +0300)]
debug.h: Add timestamps to debug prints

This is useful when someone needs to run rrdd for long time and debug
the behavior from logs. Especially timing issues become easier to
understand once the timestamps are visible.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
12 years agorrdtool_draw_image: Avoid corrupting image files
Timo Kokkonen [Wed, 11 Apr 2012 17:46:29 +0000 (20:46 +0300)]
rrdtool_draw_image: Avoid corrupting image files

As rrdtool is creating the image file it does appear to modify always
the contents of the existing file. This leads to a potential race
condition where someone is reading the current image contents and then
rrdtool changes the contents while the reader is still in the process
of the reading the old contents. If that happens, the image file
appears to be corrupted due to the fact that it contains a mixture of
the old and new image data.

Fix the issue by creating a temporary file where the image is created
and then replacing the target file with the temp file only after
rrdtool has finished drawing all of the image. This ensures reader
will be accessing either the old or new image contents, newer
something that is a mixture of those two.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
12 years agoAdd "other" memory counter
Timo Kokkonen [Wed, 22 Feb 2012 20:09:33 +0000 (22:09 +0200)]
Add "other" memory counter

The current memory counters taken from proc/meminfo don't add up
taking the entire usable physical memory. There is always a little bit
of memory left out from the equation that doesn't sum up. In some
situations that can be actualyl quite significant. Now this "Other"
memory has its own counter and the total amount of height of the
memory graph stays constant over time.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
12 years agoscript_parser: Print number of read bytes in the info message
Timo Kokkonen [Wed, 22 Feb 2012 20:07:20 +0000 (22:07 +0200)]
script_parser: Print number of read bytes in the info message

This is not strictly necessary, but might be useful. It also hides the
compiler warning about setting a variable but not reading it ever that
has become visible since gcc-4.6.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
12 years agomem_parser: Replace zero pointer with NULL
Timo Kokkonen [Wed, 22 Feb 2012 20:04:13 +0000 (22:04 +0200)]
mem_parser: Replace zero pointer with NULL

This is more grammatically correc.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
12 years agostring.c: Use existing string helpers
Timo Kokkonen [Wed, 22 Feb 2012 20:02:02 +0000 (22:02 +0200)]
string.c: Use existing string helpers

Since we have those fancy helpers, why not use them? Also, add one
extra for skipping float nubers for extra handiness.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
12 years agostring.h: Use defintions from ctype.h when applicable
Timo Kokkonen [Wed, 22 Feb 2012 19:59:49 +0000 (21:59 +0200)]
string.h: Use defintions from ctype.h when applicable

This improves code readability and maintainability without costing
anything.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>