Commit Graph

30 Commits

Author SHA1 Message Date
Chrissie Caulfield
49641930d8
log: Fix threading races (#396)
It's possible that cs->filename or cs->format could be read
in the 'fast' path while the 'slow' path is still constructing
the object. So we need to lock arr_next_lock before copying them
out for the caller.

Also wthread_should_exit was unprotected.
2020-06-01 15:41:26 +01:00
Chrissie Caulfield
7556204b27 Add the option of hi-res (millisecond) timestamps (#329)
* log: Add high-resolution timestamp option for log files

This adds the %T option to the log format for millisecond timestamps. There's a feature test macro QB_FEATURE_LOG_HIRES_TIMESTAMPS so that applications know that they are available.

Because this changes the internal logging API, applications that use custom loggers will also need to change their custom logging destinations to take a struct timespec instead of a time_t. The above feature test macro will help in deciding which is appropriate.
2018-11-09 09:56:44 +00:00
Chrissie Caulfield
6032d210d1
log: Add option to re-open a log file (#326)
As this patch also brought up some locking issues with re-configuring the logging while threaded logging was enabled, it also includes locking around qb_log_ctl2() and conversion of in_logger to an atomic.
2018-10-16 08:12:06 +01:00
Jan Pokorný
ca710b2505
Refactor: log_thread: fix and diminish inferior comments 2016-10-21 09:42:48 +02:00
Jan Pokorný
07542cf693
Med: log_thread: logt_wthread_lock is vital for logging thread
This fixes issue with would-fail-if-applied-to-thread-right-away
qb_log_thread_priority_set invocation when logging thread doesn't
exist yet, which will arrange for calling itself at the time of
thread's birth that is the moment it will actually fail.
In this + lock-could-not-have-been-initialized corner cases, the
already running thread would proceed as allowed by error condition
handling in the main thread, trying to dereference uninitialized
(or outdated) pointer to the lock at hand, resulting in segfault.

Also include the test that would have been caught that (we use the
fact that it doesn't matter whether setting of the scheduler parameters
fails due to bad input or just because of lack of privileges as it's
the failure at the right moment that is of our interest).

See also:
https://github.com/ClusterLabs/libqb/issues/229
2016-10-21 09:42:16 +02:00
Christine Caulfield
0d6a698931 log: Remove check for HAVE_SCHED_GET_PRIORITY_MAX
it doesn't exist

Signed-off-by: Christine Caulfield <ccaulfie@redhat.com>
2016-10-20 09:50:12 +01:00
Christine Caulfield
e77383897e Merge branch 'Svante-Signell-Hurd' of https://github.com/jnpkrn/libqb into jnpkrn-Svante-Signell-Hurd 2016-10-11 15:24:50 +01:00
Jan Pokorný
db7dcd1411
Build: configure: do not check for unused "sched" functions
Do not compile-time-conditionalize based on one of them being available,
either.
2016-09-30 14:24:46 +02:00
Svante Signell
6bd3f0865a Add Hurd support
* configure.ac: Define QB_GNU.
  Add a check for a working clock_getres for the CLOCK_MONOTONIC
  option defining HAVE_CLOCK_GETRES_MONOTONIC.

  * lib/log_thread.c: Replace second argument of
  qb_log_thread_priority_set(): logt_sched_param.sched_priority by 0
  when not supported by the OS.

  * lib/util.c: Use the CLOCK_REALTIME option in clock_getres() if
  HAVE_CLOCK_GETRES_MONOTONIC os not defined.
2016-03-17 13:47:16 +01:00
David Vossel
c73f2aa5cc Fixes sem leak 2013-07-22 18:21:23 -05:00
Takeshi MIZUTA
4d1a98ad76 Unify to QB_TRUE/QB_FALSE a boolean value 2013-01-11 02:01:06 +09:00
Takeshi MIZUTA
96e504f305 Unify the list processing with qb_list function 2013-01-09 02:04:20 +09:00
miz-take
d365310882 Fix return code which is an error occurred at pthread function 2013-01-06 03:08:33 +09:00
Angus Salkeld
248259f12b LOG: Make sure the semaphores are initialized.
Signed-off-by: Angus Salkeld <asalkeld@redhat.com>
2012-08-27 19:16:04 +10:00
Jan Friesse
77787d49e5 Use SCHED_BATCH only on platforms where available
Signed-off-by: Jan Friesse <jfriesse@redhat.com>
Signed-off-by: Angus Salkeld <asalkeld@redhat.com>
2012-03-28 09:28:42 +11:00
Angus Salkeld
943e6b301d Remove dead code
Signed-off-by: Angus Salkeld <asalkeld@redhat.com>
2012-02-08 22:00:49 +11:00
Angus Salkeld
ad4efc2005 LOG: pass the result of qb_log_thread_start() back to the user
Signed-off-by: Angus Salkeld <asalkeld@redhat.com>
2012-02-03 14:37:37 +11:00
Andrew Beekhof
61d166abbc Support compilation on Mac OSX
Signed-off-by: Angus Salkeld <asalkeld@redhat.com>
2011-12-19 22:16:30 +11:00
Angus Salkeld
fdf418abf5 LOG: clean up mem better when qb_log_fini is called
Signed-off-by: Angus Salkeld <asalkeld@redhat.com>
2011-11-10 21:28:14 +11:00
Angus Salkeld
ba95aafbf7 LOG: check for SCHED_IDLE
Signed-off-by: Angus Salkeld <asalkeld@redhat.com>
2011-10-23 13:36:07 +11:00
Angus Salkeld
bca6380eba Log: move the lock to below the sem_wait
(coverity ordering warning)

Signed-off-by: Angus Salkeld <asalkeld@redhat.com>
2011-10-18 14:02:29 +11:00
Angus Salkeld
ea8dfea7a0 LOG: allow the thread priority to be set.
Signed-off-by: Angus Salkeld <asalkeld@redhat.com>
2011-08-07 22:37:42 +10:00
Angus Salkeld
98493d9ae8 Change Lindent options to break the procedure type.
so change:
int foo(void)

to

int
foo(void)

Signed-off-by: Angus Salkeld <asalkeld@redhat.com>
2011-06-22 14:19:14 +10:00
Angus Salkeld
c97d98f7f7 LOG: general cleanup (indentation, NULL checks, etc...) 2011-04-01 15:32:44 +11:00
Angus Salkeld
7f0d983f49 LOG: add a qb_log_fini() to cleanup
This replaces qb_log_thread_stop() but also release shared mem

Signed-off-by: Angus Salkeld <asalkeld@redhat.com>
2011-04-01 14:50:51 +11:00
Angus Salkeld
34c96d57e5 LOG: deal better with timestamps
1) use gettimeofday() - suprisingly faster than clock_gettime(MONOTONIC)
2) don't format the time until it is needed
3) insert time_t into the blackbox (not a formatted string)

This improves performance and tidies the code up.
It also requires less space in the blackbox.

Signed-off-by: Angus Salkeld <asalkeld@redhat.com>
2011-03-31 21:30:12 +11:00
Angus Salkeld
32817adb15 LOG: re-work the API to be easier to use.
Signed-off-by: Angus Salkeld <asalkeld@redhat.com>
2011-03-30 11:46:36 +11:00
Angus Salkeld
2956f9ef29 LOG: add a timestamp to the log handler
This makes sure that the timestamp is correct at the time
the call to qb_log() was called.

Signed-off-by: Angus Salkeld <asalkeld@redhat.com>
2011-03-27 22:57:58 +11:00
Angus Salkeld
a215e856d8 LOG: fix splint warnings
Signed-off-by: Angus Salkeld <asalkeld@redhat.com>
2011-03-27 21:01:11 +11:00
Angus Salkeld
5bddb0fe68 LOG: add threaded logging (non-blocking)
Signed-off-by: Angus Salkeld <asalkeld@redhat.com>
2011-03-25 23:35:35 +11:00