mirror of
https://github.com/clearlinux/telemetrics-client.git
synced 2026-09-01 11:15:51 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
afb7572adf | ||
|
|
3337c45b08 | ||
|
|
672e741e5d | ||
|
|
e19e72a5b3 | ||
|
|
9a25115d8e | ||
|
|
11c5808fd9 | ||
|
|
9f67a1ca8a | ||
|
|
781d9382d0 | ||
|
|
2a29191c5f | ||
|
|
c264cd044c | ||
|
|
ad4dde288b | ||
|
|
48527a343b | ||
|
|
d13073ff25 | ||
|
|
43c506382a | ||
|
|
aca23d1c54 | ||
|
|
2639e4d042 | ||
|
|
cc70c3ffba | ||
|
|
ba62496248 | ||
|
|
d873c4e067 | ||
|
|
335ed440bc | ||
|
|
297e59fe5b | ||
|
|
4a2cfd99ad | ||
|
|
46f2e0c8cb | ||
|
|
ffc0554346 | ||
|
|
191d91e8e3 | ||
|
|
4b777f71f7 | ||
|
|
e27051d1a2 | ||
|
|
b7cdf9255d | ||
|
|
35b5d98c66 | ||
|
|
29917fb464 | ||
|
|
264f53dd47 | ||
|
|
0705f89533 | ||
|
|
57db31a2c8 | ||
|
|
e20e572fad | ||
|
|
6b44aa21c7 | ||
|
|
dce6e0ee1d | ||
|
|
d7c1603d12 | ||
|
|
bb6a08378c | ||
|
|
196721b0a1 | ||
|
|
fbc52d01bf | ||
|
|
452c4d6ef5 | ||
|
|
5488d4f75a | ||
|
|
30fe6b9de1 | ||
|
|
a7db38d500 | ||
|
|
4524205238 | ||
|
|
a6ab9fab7e | ||
|
|
d8d3cdee49 | ||
|
|
839ee5c126 |
+5
-1
@@ -42,9 +42,9 @@ hprobe
|
||||
bertprobe
|
||||
crashprobe
|
||||
journalprobe
|
||||
pythonprobe
|
||||
telem-record-gen
|
||||
klogscanner
|
||||
oopsprobe
|
||||
pstoreclean
|
||||
pstoreprobe
|
||||
telem_journal
|
||||
@@ -56,7 +56,11 @@ src/gcc.out
|
||||
tests/demo
|
||||
tests/check_config
|
||||
tests/check_daemon
|
||||
tests/check_journal
|
||||
tests/check_libtelemetry
|
||||
tests/check_ncb64
|
||||
tests/check_postd
|
||||
tests/check_probd
|
||||
tests/check_probes
|
||||
src/data/*.path
|
||||
src/data/*.service
|
||||
|
||||
@@ -3,3 +3,6 @@ Patrick McCarty <patrick.mccarty@intel.com>
|
||||
Rob Nesius <robert.a.nesius@intel.com>
|
||||
Gabrielle N. Beyer <gabrielle.n.beyer@intel.com>
|
||||
Pam Leonard <pam.leonard@intel.com>
|
||||
Alex V. Jaramillo <alex.v.jaramillo@intel.com>
|
||||
California Sullivan <california.l.sullivan@intel.com>
|
||||
Juro Bystricky <juro.bystricky@intel.com>
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
[](https://travis-ci.org/clearlinux/telemetrics-client)
|
||||
|
||||
Telemetrics-client
|
||||
==================
|
||||
|
||||
@@ -321,3 +323,8 @@ $ sudo telemctl journal --record_id a19a0d41ba16788881e274b19b8a1be4 --include_r
|
||||
$ org.clearlinux/hello/world Mon 2018-04-02 17:48:01 UTC a19a0d41ba16788881e274b19b8a1be4 5de9de8d5f3c6a7d445d75ba01cc3322 60c014cd-4693-40f1-b334-548cd932949b
|
||||
$ hello
|
||||
```
|
||||
|
||||
## Security Disclosures
|
||||
|
||||
To report a security issue or receive security advisories please follow procedures
|
||||
in this [link](https://01.org/security).
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
Build
|
||||
=====
|
||||
- make sure our AM_CFLAGS do not break older compilers, e.g. compilers
|
||||
that do not support -fstack-protector-strong
|
||||
|
||||
Probes
|
||||
======
|
||||
- add pstore probe (Archana)
|
||||
- journal probe: detect kernel oopses (Patrick)
|
||||
- crash probe: add function/register value info to crash payloads (Patrick)
|
||||
- crash probe: if some symbols are missing from backtraces, attempt the
|
||||
debuginfo lookup again after a certain timeout (Patrick)
|
||||
- crash probe: for non-debug builds, ensure that we are invoked by the kernel,
|
||||
and write tests to verify that attempts to run the crash probe for non-debug
|
||||
builds fail. (Patrick)
|
||||
|
||||
Library
|
||||
=======
|
||||
- add API for structured payloads
|
||||
|
||||
Other
|
||||
=====
|
||||
- set fixed size for system-wide core file ulimit, and afterward notify QA team
|
||||
to update the BAT test that checks for the ulimit value.
|
||||
@@ -12,7 +12,10 @@ AM_CFLAGS = \
|
||||
-Wunreachable-code \
|
||||
-funsigned-char \
|
||||
-fPIE \
|
||||
-fPIC
|
||||
-fPIC \
|
||||
-fno-strict-overflow \
|
||||
-fno-delete-null-pointer-checks \
|
||||
-fwrapv
|
||||
|
||||
AM_CPPFLAGS = \
|
||||
-D_FORTIFY_SOURCE=2 \
|
||||
@@ -24,8 +27,8 @@ AM_CPPFLAGS = \
|
||||
-DABSTOPSRCDIR=\"$(abs_top_srcdir)\" \
|
||||
-DDATADIR=\"$(datadir)\" \
|
||||
-DLOCALSTATEDIR=\"$(localstatedir)\" \
|
||||
-DKERNELOOPSDIR=\"$(localstatedir)/cache/telemetry/oops\" \
|
||||
-DPSTOREDIR=\"$(localstatedir)/cache/telemetry/pstore\" \
|
||||
-DTESTOOPSDIR=\"$(top_srcdir)/tests/oops_test_files\"
|
||||
-DTESTOOPSDIR=\"$(top_srcdir)/tests/oops_test_files\" \
|
||||
-DBACKEND_ADDR=\"$(BACKEND_ADDR)\"
|
||||
|
||||
# vim: filetype=automake tabstop=8 shiftwidth=8 noexpandtab
|
||||
|
||||
+6
-1
@@ -2,7 +2,7 @@
|
||||
# Process this file with autoconf to produce a configure script.
|
||||
|
||||
AC_PREREQ([2.69])
|
||||
AC_INIT([telemetrics-client], [2.0.0], [https://clearlinux.org/])
|
||||
AC_INIT([telemetrics-client], [2.2.1], [https://clearlinux.org/])
|
||||
AC_CONFIG_AUX_DIR([build-aux])
|
||||
AM_INIT_AUTOMAKE([1.14 -Wall -Werror -Wno-extra-portability foreign subdir-objects])
|
||||
AM_SILENT_RULES([yes])
|
||||
@@ -119,6 +119,11 @@ AC_ARG_WITH([loglevel], AS_HELP_STRING([--with-loglevel=NUM],
|
||||
[loglevel=5])
|
||||
AC_DEFINE_UNQUOTED([MAX_LOG_LEVEL], [${loglevel}], [Maximum log level for binaries])
|
||||
|
||||
AC_ARG_WITH([backendserveraddr], AS_HELP_STRING([--with-backendserveraddr=URI],
|
||||
[uri to telemetrics backend server @<:@default=https://clr.telemetry.intel.com/v2/collector@:>@]), [backendaddr=${withval}])
|
||||
test -z "${backendaddr}" && backendaddr=https://clr.telemetry.intel.com/v2/collector
|
||||
AC_SUBST(BACKEND_ADDR, [${backendaddr}])
|
||||
|
||||
AC_ARG_ENABLE([logtype], AS_HELP_STRING([--enable-logtype],
|
||||
[Vector for logging: stderr (default), syslog, systemd]),
|
||||
[case ${enableval} in
|
||||
|
||||
+3
-3
@@ -1,9 +1,9 @@
|
||||
|
||||
## Notes on manual pages
|
||||
|
||||
The manual pages are generated using `ronn(1)`. To recreate them,
|
||||
run `make manpages` in the toplevel folder. If you want to edit
|
||||
the documentation for upstream changes, make sure to edit the `*.md`
|
||||
The manual pages are generated using `rst2man.py`. To recreate them,
|
||||
run `make manpages` in the toplevel folder. If you want to edit
|
||||
the documentation for upstream changes, make sure to edit the `*.rst`
|
||||
files and not the shipped nroff output files.
|
||||
|
||||
|
||||
|
||||
@@ -35,10 +35,10 @@ level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]
|
||||
\fBtelem\-record\-gen\fP <options>
|
||||
.SH DESCRIPTION
|
||||
.sp
|
||||
Generate and attempt to send a telemetry record to \fBtelemd\fP(1). This
|
||||
Generate and attempt to send a telemetry record to \fBtelemprobd\fP(1). This
|
||||
program can be used to create a telemetry record from a shell script
|
||||
or from another program using e.g. \fBsystem()\fP\&. The program connects
|
||||
to a local \fBtelemd\fP(1) daemon to spool the record for delivery to
|
||||
to a local \fBtelemprobd\fP(1) daemon to spool the record for delivery to
|
||||
the actual collection service.
|
||||
.sp
|
||||
The payload can be provided as standard input, as a file with the
|
||||
@@ -79,7 +79,7 @@ File to read payload from.
|
||||
Version number for format of payload (default 1).
|
||||
.IP \(bu 2
|
||||
\fB\-e\fP, \fB\-\-event\-id\fP <version>:
|
||||
Event id to use in the record. If not provided a ramdonly generated id will be assigned to record.
|
||||
Event id to use in the record. If not provided a randomly generated id will be assigned to record.
|
||||
.UNINDENT
|
||||
.UNINDENT
|
||||
.UNINDENT
|
||||
@@ -89,7 +89,7 @@ Event id to use in the record. If not provided a ramdonly generated id will be a
|
||||
.SH SEE ALSO
|
||||
.INDENT 0.0
|
||||
.IP \(bu 2
|
||||
\fBtelemd\fP(1)
|
||||
\fBtelemprobd\fP(1)
|
||||
.IP \(bu 2
|
||||
\fI\%https://github.com/clearlinux/telemetrics\-client\fP
|
||||
.IP \(bu 2
|
||||
|
||||
@@ -19,10 +19,10 @@ SYNOPSIS
|
||||
DESCRIPTION
|
||||
===========
|
||||
|
||||
Generate and attempt to send a telemetry record to ``telemd``\(1). This
|
||||
Generate and attempt to send a telemetry record to ``telemprobd``\(1). This
|
||||
program can be used to create a telemetry record from a shell script
|
||||
or from another program using e.g. ``system()``. The program connects
|
||||
to a local ``telemd``\(1) daemon to spool the record for delivery to
|
||||
to a local ``telemprobd``\(1) daemon to spool the record for delivery to
|
||||
the actual collection service.
|
||||
|
||||
The payload can be provided as standard input, as a file with the
|
||||
@@ -76,7 +76,6 @@ RETURN VALUES
|
||||
SEE ALSO
|
||||
========
|
||||
|
||||
* ``telemd``\(1)
|
||||
* ``telemprobd``\(1)
|
||||
* https://github.com/clearlinux/telemetrics-client
|
||||
* https://clearlinux.org/documentation/
|
||||
|
||||
|
||||
+2
-3
@@ -38,8 +38,7 @@ level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]
|
||||
.SH DESCRIPTION
|
||||
.sp
|
||||
Control actions for telemetry services. The command can be used to start,
|
||||
restart, or stop \fBtelemd\fP(1), or to opt\-in or opt\-out of telemetry delivery
|
||||
of records to a central telemetry service.
|
||||
restart, or stop \fBtelemprobd\fP(1) and \fBtelempostd\fP(1), or to opt\-in or opt\-out of telemetry delivery of records to a central telemetry service.
|
||||
.SH OPTIONS
|
||||
.INDENT 0.0
|
||||
.INDENT 3.5
|
||||
@@ -67,7 +66,7 @@ Checks if telemetry client daemons are active (telemprobd and telempostd).
|
||||
.SH SEE ALSO
|
||||
.INDENT 0.0
|
||||
.IP \(bu 2
|
||||
\fBtelemd\fP(1)
|
||||
\fBtelemprobd\fP(1)
|
||||
.IP \(bu 2
|
||||
\fI\%https://github.com/clearlinux/telemetrics\-client\fP
|
||||
.IP \(bu 2
|
||||
|
||||
@@ -22,8 +22,7 @@ DESCRIPTION
|
||||
===========
|
||||
|
||||
Control actions for telemetry services. The command can be used to start,
|
||||
restart, or stop ``telemd``\(1), or to opt-in or opt-out of telemetry delivery
|
||||
of records to a central telemetry service.
|
||||
restart, or stop ``telemprobd``\(1) and ``telempostd``\(1), or to opt-in or opt-out of telemetry delivery of records to a central telemetry service.
|
||||
|
||||
|
||||
OPTIONS
|
||||
@@ -32,11 +31,11 @@ OPTIONS
|
||||
* ``start``|``stop``|``restart``:
|
||||
Starts, stops or restarts all running telemetry services.
|
||||
|
||||
* ``opt-in``:
|
||||
* ``opt-in``:
|
||||
Opts in to telemetry, and starts telemetry services. The opt-out file
|
||||
``/etc/telemetrics/opt-out`` is removed.
|
||||
|
||||
* ``opt-out``:
|
||||
* ``opt-out``:
|
||||
Opts out of telemetry, and stops telemetry services. The opt-out file
|
||||
``/etc/telemetrics/opt-out`` is created.
|
||||
|
||||
@@ -53,7 +52,6 @@ RETURN VALUES
|
||||
SEE ALSO
|
||||
========
|
||||
|
||||
* ``telemd``\(1)
|
||||
* ``telemprobd``\(1)
|
||||
* https://github.com/clearlinux/telemetrics-client
|
||||
* https://clearlinux.org/documentation/
|
||||
|
||||
|
||||
@@ -37,8 +37,7 @@ level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]
|
||||
\fB/usr/share/defaults/telemetrics/telemetrics.conf\fP
|
||||
.SH DESCRIPTION
|
||||
.sp
|
||||
This file contains configuration parameters for the \fBtelemd\fP(1) telemetry
|
||||
service daemon. The daemon reads this file at startup if it exists.
|
||||
This file contains configuration parameters for the \fBtelemprobd\fP(1) and \fBtelempostd\fP(1) telemetry service daemons. The daemon reads this file at startup if it exists.
|
||||
.SH SYNTAX
|
||||
.sp
|
||||
The configuration file contains \fBkey=value\fP pairs, formatted as plain
|
||||
@@ -54,7 +53,7 @@ Server URL including protocol designator.
|
||||
.IP \(bu 2
|
||||
\fBsocket_path=<path>\fP
|
||||
.sp
|
||||
Path to the socket that \fItelemd\fP will listen on.
|
||||
Path to the socket that \fItelemprobd\fP will listen on.
|
||||
.IP \(bu 2
|
||||
\fBcainfo=<path>\fP
|
||||
.sp
|
||||
@@ -82,7 +81,7 @@ and not the actual size of the record itself.
|
||||
.IP \(bu 2
|
||||
\fBspool_process_time=<seconds>\fP
|
||||
.sp
|
||||
Time in seconds for processing spool. Valid range: 120..3600. Values
|
||||
Time in seconds for processing spool. Valid range: 120..300. Values
|
||||
outside this range are clamped.
|
||||
.IP \(bu 2
|
||||
\fBrate_limit_enabled=<true|false>\fP
|
||||
@@ -114,7 +113,9 @@ delivery over network. Valid stategies: \fBspool\fP, \fBdrop\fP\&.
|
||||
.SH SEE ALSO
|
||||
.INDENT 0.0
|
||||
.IP \(bu 2
|
||||
\fBtelemd\fP(1)
|
||||
\fBtelemprobd\fP(1)
|
||||
.IP \(bu 2
|
||||
\fBtelempostd\fP(1)
|
||||
.IP \(bu 2
|
||||
\fI\%https://github.com/clearlinux/telemetrics\-client\fP
|
||||
.IP \(bu 2
|
||||
|
||||
@@ -21,8 +21,7 @@ SYNOPSIS
|
||||
DESCRIPTION
|
||||
===========
|
||||
|
||||
This file contains configuration parameters for the ``telemd``\(1) telemetry
|
||||
service daemon. The daemon reads this file at startup if it exists.
|
||||
This file contains configuration parameters for the ``telemprobd``\(1) and ``telempostd``\(1) telemetry service daemons. The daemon reads this file at startup if it exists.
|
||||
|
||||
|
||||
SYNTAX
|
||||
@@ -43,7 +42,7 @@ OPTIONS
|
||||
|
||||
- ``socket_path=<path>``
|
||||
|
||||
Path to the socket that `telemd` will listen on.
|
||||
Path to the socket that `telemprobd` will listen on.
|
||||
|
||||
- ``cainfo=<path>``
|
||||
|
||||
@@ -71,7 +70,7 @@ OPTIONS
|
||||
|
||||
- ``spool_process_time=<seconds>``
|
||||
|
||||
Time in seconds for processing spool. Valid range: 120..3600. Values
|
||||
Time in seconds for processing spool. Valid range: 120..300. Values
|
||||
outside this range are clamped.
|
||||
|
||||
- ``rate_limit_enabled=<true|false>``
|
||||
@@ -104,7 +103,7 @@ OPTIONS
|
||||
SEE ALSO
|
||||
========
|
||||
|
||||
* ``telemd``\(1)
|
||||
* ``telemprobd``\(1)
|
||||
* ``telempostd``\(1)
|
||||
* https://github.com/clearlinux/telemetrics-client
|
||||
* https://clearlinux.org/documentation/
|
||||
|
||||
|
||||
@@ -44,11 +44,11 @@ level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]
|
||||
.sp
|
||||
\fBvoid tm_free_record(struct telem_ref *t_ref)\fP
|
||||
.sp
|
||||
\fBvoid tm_set_config_file(char *c_file)\fP
|
||||
\fBint tm_set_config_file(const char *c_file)\fP
|
||||
.SH DESCRIPTION
|
||||
.sp
|
||||
The functions in the telemetry library facilitate the delivery of
|
||||
telemetry data to the \fBtelemd\fP(1) service.
|
||||
telemetry data to the \fBtelemprobd\fP(1) service.
|
||||
.sp
|
||||
The function \fBtm_create_record()\fP initializes a telemetry record and
|
||||
sets the severity and classification of that record, as well as the
|
||||
@@ -60,19 +60,19 @@ The function \fBtm_set_payload()\fP attaches the provided telemetry record
|
||||
data to the telemetry record. The current maximum payload size is 8192b.
|
||||
.sp
|
||||
The function \fBtm_send_record()\fP delivers the record to the local
|
||||
\fBtelemd\fP(1) service.
|
||||
\fBtelemprobd\fP(1) service.
|
||||
.sp
|
||||
The function \fBtm_set_config_file()\fP can be used to provide an alternate
|
||||
configuration path to the telemetry library.
|
||||
.SH RETURN VALUES
|
||||
.sp
|
||||
All these functions return \fB0\fP on success, or a non\-zero return value
|
||||
if an error occurred. The functions \fBtm_free_record()\fP and \fBtm_set_config_file()\fP
|
||||
do not return any values.
|
||||
if an error occurred. The function \fBtm_free_record()\fP does not return
|
||||
any value.
|
||||
.SH SEE ALSO
|
||||
.INDENT 0.0
|
||||
.IP \(bu 2
|
||||
\fBtelemd\fP(1)
|
||||
\fBtelemprobd\fP(1)
|
||||
.IP \(bu 2
|
||||
\fI\%https://github.com/clearlinux/telemetrics\-client\fP
|
||||
.IP \(bu 2
|
||||
|
||||
@@ -14,9 +14,9 @@ SYNOPSIS
|
||||
========
|
||||
|
||||
``#include "telemetry.h"``
|
||||
|
||||
|
||||
``struct telem_ref { struct telem_record *record; };``
|
||||
|
||||
|
||||
``int tm_create_record(struct telem_ref **t_ref, uint32_t severity, char *classification, uint32_t payload_version)``
|
||||
|
||||
``int tm_set_payload(struct telem_ref *t_ref, char *payload)``
|
||||
@@ -25,14 +25,14 @@ SYNOPSIS
|
||||
|
||||
``void tm_free_record(struct telem_ref *t_ref)``
|
||||
|
||||
``void tm_set_config_file(char *c_file)``
|
||||
``int tm_set_config_file(const char *c_file)``
|
||||
|
||||
|
||||
DESCRIPTION
|
||||
===========
|
||||
|
||||
The functions in the telemetry library facilitate the delivery of
|
||||
telemetry data to the ``telemd``\(1) service.
|
||||
telemetry data to the ``telemprobd``\(1) service.
|
||||
|
||||
The function ``tm_create_record()`` initializes a telemetry record and
|
||||
sets the severity and classification of that record, as well as the
|
||||
@@ -44,7 +44,7 @@ The function ``tm_set_payload()`` attaches the provided telemetry record
|
||||
data to the telemetry record. The current maximum payload size is 8192b.
|
||||
|
||||
The function ``tm_send_record()`` delivers the record to the local
|
||||
``telemd``\(1) service.
|
||||
``telemprobd``\(1) service.
|
||||
|
||||
The function ``tm_set_config_file()`` can be used to provide an alternate
|
||||
configuration path to the telemetry library.
|
||||
@@ -54,14 +54,13 @@ RETURN VALUES
|
||||
=============
|
||||
|
||||
All these functions return ``0`` on success, or a non-zero return value
|
||||
if an error occurred. The functions ``tm_free_record()`` and ``tm_set_config_file()``
|
||||
do not return any values.
|
||||
if an error occurred. The function ``tm_free_record()`` does not return
|
||||
any value.
|
||||
|
||||
|
||||
SEE ALSO
|
||||
========
|
||||
|
||||
* ``telemd``\(1)
|
||||
* ``telemprobd``\(1)
|
||||
* https://github.com/clearlinux/telemetrics-client
|
||||
* https://clearlinux.org/documentation/
|
||||
|
||||
|
||||
@@ -49,7 +49,7 @@ telemetry service. Telemetry data can be in any format, and is relayed as\-is.
|
||||
.INDENT 0.0
|
||||
.IP \(bu 2
|
||||
\fB\-f\fP, \fB\-\-config_file\fP [<file>]:
|
||||
Configuration file. This overides the other parameters.
|
||||
Configuration file. This overrides the other parameters.
|
||||
.IP \(bu 2
|
||||
\fB\-h\fP, \fB\-\-help\fP:
|
||||
Display this help message.
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
.\" Man page generated from reStructuredText.
|
||||
.
|
||||
.TH TELEMD 1 "" "" ""
|
||||
.TH TELEMPROBD 1 "" "" ""
|
||||
.SH NAME
|
||||
telemd \- Telemetry client service
|
||||
telemprobd \- Telemetry probes service
|
||||
.
|
||||
.nr rst2man-indent-level 0
|
||||
.
|
||||
@@ -32,7 +32,7 @@ level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]
|
||||
..
|
||||
.SH SYNOPSIS
|
||||
.sp
|
||||
\fBtelemd\fP <flags>
|
||||
\fBtelemprobd\fP <flags>
|
||||
.sp
|
||||
\fB/etc/telemetrics/telemetrics.conf\fP
|
||||
.sp
|
||||
@@ -41,7 +41,7 @@ level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]
|
||||
\fB/etc/telemetrics/opt\-in\-static\-machine\-id\fP
|
||||
.SH DESCRIPTION
|
||||
.sp
|
||||
The \fBtelemd\fP program handles communication between telemetry client and telemetry
|
||||
The \fBtelemprobd\fP program handles communication between telemetry client and telemetry
|
||||
probes.
|
||||
.SH OPTIONS
|
||||
.INDENT 0.0
|
||||
@@ -65,7 +65,7 @@ Print the program version.
|
||||
\fB/usr/share/defaults/telemetrics/telemetrics.conf\fP
|
||||
.INDENT 2.0
|
||||
.INDENT 3.5
|
||||
If no custom configuration file is found, \fBtelemd\fP uses the
|
||||
If no custom configuration file is found, \fBtelemprobd\fP uses the
|
||||
settings in this file.
|
||||
.UNINDENT
|
||||
.UNINDENT
|
||||
@@ -73,7 +73,7 @@ settings in this file.
|
||||
\fB/etc/telemetrics/telemetrics.conf\fP
|
||||
.INDENT 2.0
|
||||
.INDENT 3.5
|
||||
Custom configuration file that \fBtelemd\fP reads. See \fBtelemetrics.conf\fP(5).
|
||||
Custom configuration file that \fBtelemprobd\fP reads. See \fBtelemetrics.conf\fP(5).
|
||||
.UNINDENT
|
||||
.UNINDENT
|
||||
.IP \(bu 2
|
||||
|
||||
+4
-3
@@ -4,16 +4,17 @@ declare -a SPECIAL_UNITS=(
|
||||
hprobe.timer
|
||||
telemprobd.socket
|
||||
telempostd.path
|
||||
klogscanner.service
|
||||
journal-probe-tail.service
|
||||
python-probe.path
|
||||
)
|
||||
|
||||
declare -a SERVICES=(
|
||||
hprobe.service
|
||||
journal-probe.service
|
||||
oops-probe.service
|
||||
pstore-probe.service
|
||||
klogscanner.service
|
||||
telemprobd.service
|
||||
telempostd.service
|
||||
journal-probe.service
|
||||
)
|
||||
|
||||
SCRIPT="$0"
|
||||
|
||||
+10
-7
@@ -78,7 +78,7 @@ static const uint32_t RECORD_FORMAT_VERSION = 4;
|
||||
#define TM_OPT_OUT_FILE "/etc/telemetrics/opt-out"
|
||||
|
||||
/* Currently max supported payload size is 8kb */
|
||||
#define MAX_PAYLOAD_SIZE 8192
|
||||
#define MAX_PAYLOAD_LENGTH 8192
|
||||
|
||||
/* Maximum size for a category string is 122 bytes */
|
||||
#define MAX_CLASS_LENGTH 122
|
||||
@@ -86,12 +86,12 @@ static const uint32_t RECORD_FORMAT_VERSION = 4;
|
||||
/* Maximum size for a sub category 40 bytes */
|
||||
#define MAX_SUBCAT_LENGTH 40
|
||||
|
||||
/* Max Payload size is 8 kibabytes (8192) */
|
||||
#define MAX_PAYLOAD_LENGTH 8192
|
||||
/* Exit daemon after idle for this duration in seconds */
|
||||
#define TM_DAEMON_EXIT_TIME (5 * 60)
|
||||
|
||||
/* SPOOL DEFINES */
|
||||
/* Spooling should run every TM_SPOOL_RUN_MAX atleast */
|
||||
#define TM_SPOOL_RUN_MAX (60 /*min*/ * 60 /*sec*/)
|
||||
/* Spooling should run at least every TM_SPOOL_RUN_MAX */
|
||||
#define TM_SPOOL_RUN_MAX TM_DAEMON_EXIT_TIME
|
||||
|
||||
/* Spooling should not run more often than TM_SPOOL_RUN_MIN */
|
||||
#define TM_SPOOL_RUN_MIN (2 /*min*/ * 60 /*sec*/)
|
||||
@@ -102,8 +102,10 @@ static const uint32_t RECORD_FORMAT_VERSION = 4;
|
||||
/* Maximum records that can be processed in a single spool run loop*/
|
||||
#define TM_SPOOL_MAX_PROCESS_RECORDS 60
|
||||
|
||||
/* Time to check to exit from the daemon */
|
||||
#define TM_DAEMON_EXIT_TIME (2 /*h*/ * 60 /*m*/ * 60 /*sec*/)
|
||||
/* Definitions for config file override */
|
||||
#define CFG_PREFIX "CFG:"
|
||||
#define CFG_PREFIX_LENGTH 4
|
||||
#define CFG_PREFIX_32BIT 0x3a474643
|
||||
|
||||
/* Very simple structure. Array of header strings and a payload. Calling
|
||||
* program is reponsible for passing in the payload as a simple string.
|
||||
@@ -117,4 +119,5 @@ struct telem_record {
|
||||
|
||||
const char *get_header_name(int ind);
|
||||
|
||||
|
||||
/* vi: set ts=8 sw=8 sts=4 et tw=80 cino=(0: */
|
||||
|
||||
+126
-66
@@ -28,6 +28,7 @@
|
||||
#include "configuration.h"
|
||||
#include "util.h"
|
||||
#include "common.h"
|
||||
#include "log.h"
|
||||
|
||||
#include "nica/inifile.h"
|
||||
|
||||
@@ -38,21 +39,50 @@ static NcHashmap *keyfile = NULL;
|
||||
static bool cmd_line_cfg = false;
|
||||
|
||||
/* Conf strings, integers, and booleans expected in the conf file */
|
||||
const char *config_key_str[] = { NULL, "server", "socket_path", "spool_dir",
|
||||
"rate_limit_strategy", "cainfo",
|
||||
"tidheader", NULL };
|
||||
static const char *config_key_str[] = { "server",
|
||||
"socket_path",
|
||||
"spool_dir",
|
||||
"rate_limit_strategy",
|
||||
"cainfo",
|
||||
"tidheader"};
|
||||
|
||||
const char *config_key_int[] = { NULL, "record_expiry", "spool_max_size",
|
||||
"spool_process_time", "record_window_length",
|
||||
"byte_window_length", "record_burst_limit",
|
||||
"byte_burst_limit", NULL };
|
||||
static const char *config_key_int[] = { "record_expiry",
|
||||
"spool_max_size",
|
||||
"spool_process_time",
|
||||
"record_window_length",
|
||||
"byte_window_length",
|
||||
"record_burst_limit",
|
||||
"byte_burst_limit" };
|
||||
|
||||
static const char *config_key_bool[] = { "rate_limit_enabled",
|
||||
"daemon_recycling_enabled",
|
||||
"record_retention_enabled",
|
||||
"record_server_delivery_enabled" };
|
||||
|
||||
static const char *config_str_default[] = { DEFAULT_SERVER_ADDR,
|
||||
DEFAULT_SOCKET_PATH,
|
||||
DEFAULT_SPOOL_DIR,
|
||||
DEFAULT_RATE_LIMIT_STRATEGY,
|
||||
DEFAULT_CAINFO,
|
||||
DEFAULT_TIDHEADER };
|
||||
|
||||
static const bool config_bool_default[] = { DEFAULT_RATE_LIMIT_ENABLED,
|
||||
DEFAULT_DAEMON_RECYCLING_ENABLED,
|
||||
DEFAULT_RECORD_RETENTION_ENABLED,
|
||||
DEFAULT_RECORD_SERVER_DELIVERY_ENABLED };
|
||||
|
||||
static const int config_int_default[] = { DEFAULT_RECORD_EXPIRY,
|
||||
DEFAULT_SPOOL_MAX_SIZE,
|
||||
DEFAULT_SPOOL_PROCESS_TIME,
|
||||
DEFAULT_RECORD_WINDOW_LENGTH,
|
||||
DEFAULT_BYTE_WINDOW_LENGTH,
|
||||
DEFAULT_RECORD_BURST_LIMIT,
|
||||
DEFAULT_BYTE_BURST_LIMIT };
|
||||
|
||||
const char *config_key_bool[] = { NULL, "rate_limit_enabled", "daemon_recycling_enabled",
|
||||
"record_retention_enabled", "record_server_delivery_enabled", NULL };
|
||||
|
||||
static struct configuration config = { { 0 }, { 0 }, { 0 }, false, NULL };
|
||||
|
||||
int validate_config_file(char *f)
|
||||
static int validate_config_file(const char *f)
|
||||
{
|
||||
struct stat sbuf;
|
||||
|
||||
@@ -60,26 +90,66 @@ int validate_config_file(char *f)
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
/* check if the file exists and is a regular file */
|
||||
if (stat(f, &sbuf) != 0) {
|
||||
return -errno;
|
||||
}
|
||||
|
||||
if (!S_ISREG(sbuf.st_mode)) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
void set_config_file(char *filename)
|
||||
const char *get_config_file(void)
|
||||
{
|
||||
return config_file;
|
||||
}
|
||||
|
||||
/* TODO: This should return a status, but that will require coordinating
|
||||
* an API change. For now, config-entries referencing a null config
|
||||
* file will fail, so the end result still works. */
|
||||
const char *get_cmd_line_config_file(void)
|
||||
{
|
||||
if (cmd_line_cfg == true) {
|
||||
return config_file;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (validate_config_file(filename) == 0) {
|
||||
config_file = strdup(filename);
|
||||
cmd_line_cfg = true;
|
||||
int set_config_file(const char *filename)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if ((ret = validate_config_file(filename)) == 0) {
|
||||
char *filename1 = strdup(filename);
|
||||
if (filename1 == NULL) {
|
||||
ret = -errno;
|
||||
} else {
|
||||
config_file = filename1;
|
||||
cmd_line_cfg = true;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool set_default_config_values(struct configuration *config)
|
||||
{
|
||||
for (int i = 0; i < CONF_STR_MAX; i++) {
|
||||
config->strValues[i] = strdup(config_str_default[i]);
|
||||
if (config->strValues[i] == NULL) {
|
||||
telem_log(LOG_ERR, "Could not set config item %s: %s\n",
|
||||
config_key_str[i], strerror(errno));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < CONF_INT_MAX; i++) {
|
||||
config->intValues[i] = config_int_default[i];
|
||||
}
|
||||
for (int i = 0; i < CONF_BOOL_MAX; i++) {
|
||||
config->boolValues[i] = config_bool_default[i];
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool read_config_from_file(char *config_file, struct configuration *config)
|
||||
@@ -90,73 +160,64 @@ bool read_config_from_file(char *config_file, struct configuration *config)
|
||||
|
||||
keyfile = nc_ini_file_parse(config_file);
|
||||
if (!keyfile) {
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "ERR: Failed to read config file\n");
|
||||
#endif
|
||||
telem_log(LOG_ERR, "Failed to read config file\n");
|
||||
return false;
|
||||
} else {
|
||||
for (int i = CONF_STR_MIN + 1; i < CONF_STR_MAX; i++) {
|
||||
for (int i = 0; i < CONF_STR_MAX; i++) {
|
||||
char *ptr;
|
||||
ptr = nc_hashmap_get(nc_hashmap_get(keyfile, "settings"), config_key_str[i]);
|
||||
if (ptr) {
|
||||
config->strValues[i] = strdup(ptr);
|
||||
if (config->strValues[i] == NULL) {
|
||||
telem_log(LOG_ERR, "Could not set config item %s: %s\n",
|
||||
config_key_str[i], strerror(errno));
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
fprintf(stderr, "ERR: missing key with string value: %s\n", config_key_str[i]);
|
||||
return false;
|
||||
config->strValues[i] = strdup(config_str_default[i]);
|
||||
}
|
||||
|
||||
}
|
||||
for (int i = CONF_INT_MIN + 1; i < CONF_INT_MAX; i++) {
|
||||
|
||||
for (int i = 0; i < CONF_INT_MAX; i++) {
|
||||
char *ptr;
|
||||
ptr = nc_hashmap_get(nc_hashmap_get(keyfile, "settings"), config_key_int[i]);
|
||||
if (ptr) {
|
||||
errno = 0;
|
||||
config->intValues[i] = strtoll(ptr, NULL, 10);
|
||||
if (errno != 0) {
|
||||
telem_log(LOG_ERR, "Error while parsing value of option %s: %s\n",
|
||||
config_key_int[i], strerror(errno));
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
fprintf(stderr, "ERR: missing key with integer value: %s\n", config_key_int[i]);
|
||||
return false;
|
||||
config->intValues[i] = config_int_default[i];
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = CONF_BOOL_MIN + 1; i < CONF_BOOL_MAX; i++) {
|
||||
for (int i = 0; i < CONF_BOOL_MAX; i++) {
|
||||
char *ptr;
|
||||
ptr = nc_hashmap_get(nc_hashmap_get(keyfile, "settings"), config_key_bool[i]);
|
||||
config->boolValues[i] = false;
|
||||
|
||||
if (ptr) {
|
||||
if (strcasecmp(ptr, "TRUE") == 0) {
|
||||
if ((strcasecmp(ptr, "TRUE") == 0) || (strcmp(ptr, "1") == 0)) {
|
||||
config->boolValues[i] = true;
|
||||
}
|
||||
if (strcasecmp(ptr, "1") == 0) {
|
||||
config->boolValues[i] = true;
|
||||
}
|
||||
} else {
|
||||
/* New configuration keys, CONF_RECORD_RETENTION_ENABLED and CONF_RECORD_SERVER_DELIVERY_ENABLED
|
||||
* default values, otherwise update will require changes in custom configurations */
|
||||
if (i == CONF_RECORD_RETENTION_ENABLED) {
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "WARN: missing boolean optional key: %s\n", config_key_bool[i]);
|
||||
#endif
|
||||
config->boolValues[i] = RECORD_RETENTION_ENABLED_DEFAULT;
|
||||
} else if (i == CONF_RECORD_SERVER_DELIVERY_ENABLED) {
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "WARN: missing boolean optional key: %s\n", config_key_bool[i]);
|
||||
#endif
|
||||
config->boolValues[i] = RECORD_SERVER_DELIVERY_ENABLED_DEFAULT;
|
||||
} else if ((strcasecmp(ptr, "FALSE") == 0) || (strcmp(ptr, "0") == 0)) {
|
||||
config->boolValues[i] = false;
|
||||
} else {
|
||||
fprintf(stderr, "ERR: missing key with boolean value: %s\n", config_key_bool[i]);
|
||||
telem_log(LOG_ERR, "Configuration item '%s' requires a boolean value\n",
|
||||
config_key_bool[i]);
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
config->boolValues[i] = config_bool_default[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
config->initialized = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
void initialize_config(void)
|
||||
static void initialize_config(void)
|
||||
{
|
||||
if (config.initialized) {
|
||||
return;
|
||||
@@ -167,26 +228,25 @@ void initialize_config(void)
|
||||
if (access(etc_config_file, R_OK) == 0) {
|
||||
config_file = etc_config_file;
|
||||
} else {
|
||||
if (access(default_config_file,
|
||||
R_OK) == 0) {
|
||||
if (access(default_config_file, R_OK) == 0) {
|
||||
config_file = default_config_file;
|
||||
} else {
|
||||
/* If there is no default config, exit with failure */
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "ERR: No configuration file"
|
||||
" found, exiting\n");
|
||||
#endif
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!read_config_from_file(config_file, &config)) {
|
||||
/* Error while parsing file */
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "ERR: Error while parsing configuration file\n");
|
||||
#endif
|
||||
exit(EXIT_FAILURE);
|
||||
|
||||
if (config_file) {
|
||||
if (!read_config_from_file(config_file, &config)) {
|
||||
/* Error while parsing file */
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (!set_default_config_values(&config)) {
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
config.initialized = true;
|
||||
}
|
||||
|
||||
void reload_config(void)
|
||||
@@ -206,7 +266,7 @@ void free_configuration(void)
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = CONF_STR_MIN + 1; i < CONF_STR_MAX; i++) {
|
||||
for (int i = 0; i < CONF_STR_MAX; i++) {
|
||||
free(config.strValues[i]);
|
||||
}
|
||||
|
||||
|
||||
+34
-9
@@ -18,13 +18,31 @@
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
/* Default configuration settings */
|
||||
#define DEFAULT_SERVER_ADDR BACKEND_ADDR
|
||||
#define DEFAULT_SOCKET_PATH "/run/telem-0"
|
||||
#define DEFAULT_SPOOL_DIR LOCALSTATEDIR "/spool/telemetry"
|
||||
#define DEFAULT_RATE_LIMIT_STRATEGY "spool"
|
||||
#define DEFAULT_CAINFO ""
|
||||
#define DEFAULT_TIDHEADER "X-Telemetry-TID: 6907c830-eed9-4ce9-81ae-76daf8d88f0f"
|
||||
|
||||
#define DEFAULT_RECORD_EXPIRY 1200
|
||||
#define DEFAULT_SPOOL_MAX_SIZE 5120
|
||||
#define DEFAULT_SPOOL_PROCESS_TIME 120
|
||||
#define DEFAULT_RECORD_WINDOW_LENGTH 15
|
||||
#define DEFAULT_BYTE_WINDOW_LENGTH 20
|
||||
#define DEFAULT_RECORD_BURST_LIMIT 1000
|
||||
#define DEFAULT_BYTE_BURST_LIMIT -1
|
||||
|
||||
#define DEFAULT_RATE_LIMIT_ENABLED true
|
||||
#define DEFAULT_DAEMON_RECYCLING_ENABLED true
|
||||
#define DEFAULT_RECORD_RETENTION_ENABLED false
|
||||
#define DEFAULT_RECORD_SERVER_DELIVERY_ENABLED true
|
||||
|
||||
#define TM_MAX_WINDOW_LENGTH (1 /*h*/ * 60 /*m*/)
|
||||
#define RECORD_RETENTION_ENABLED_DEFAULT false
|
||||
#define RECORD_SERVER_DELIVERY_ENABLED_DEFAULT true
|
||||
|
||||
enum config_str_keys {
|
||||
CONF_STR_MIN = 0,
|
||||
CONF_SERVER_ADDR,
|
||||
CONF_SERVER_ADDR = 0,
|
||||
CONF_SOCKET_PATH,
|
||||
CONF_SPOOL_DIR,
|
||||
CONF_RATE_LIMIT_STRATEGY,
|
||||
@@ -34,8 +52,7 @@ enum config_str_keys {
|
||||
};
|
||||
|
||||
enum config_int_keys {
|
||||
CONF_INT_MIN = 0,
|
||||
CONF_RECORD_EXPIRY,
|
||||
CONF_RECORD_EXPIRY = 0,
|
||||
CONF_SPOOL_MAX_SIZE,
|
||||
CONF_SPOOL_PROCESS_TIME,
|
||||
CONF_RECORD_WINDOW_LENGTH,
|
||||
@@ -46,8 +63,7 @@ enum config_int_keys {
|
||||
};
|
||||
|
||||
enum config_bool_keys {
|
||||
CONF_BOOL_MIN = 0,
|
||||
CONF_RATE_LIMIT_ENABLED,
|
||||
CONF_RATE_LIMIT_ENABLED = 0,
|
||||
CONF_DAEMON_RECYCLING_ENABLED,
|
||||
CONF_RECORD_RETENTION_ENABLED,
|
||||
CONF_RECORD_SERVER_DELIVERY_ENABLED,
|
||||
@@ -63,7 +79,16 @@ typedef struct configuration {
|
||||
} configuration;
|
||||
|
||||
/* Sets the configuration file to be used later */
|
||||
void set_config_file(char *filename);
|
||||
int set_config_file(const char *filename);
|
||||
|
||||
/* Gets the configuration currently in use */
|
||||
const char *get_config_file(void);
|
||||
|
||||
/* Gets the configuration specified via command line or NULL */
|
||||
const char *get_cmd_line_config_file(void);
|
||||
|
||||
/* Sets all default configuration values to a given config */
|
||||
bool set_default_config_values(struct configuration *config);
|
||||
|
||||
/* Parses the ini format config file */
|
||||
bool read_config_from_file(char *filename, struct configuration *config);
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
[settings]
|
||||
server=http://127.0.0.1
|
||||
|
||||
cainfo=/tmp/cacert.crt
|
||||
@@ -16,7 +16,7 @@ spool_dir=/tmp/spool
|
||||
spool_max_size=1024
|
||||
|
||||
#time in seconds for processing spool
|
||||
spool_process_time=900
|
||||
spool_process_time=180
|
||||
|
||||
#rate limiting record burst limit
|
||||
record_burst_limit=100
|
||||
|
||||
@@ -5,7 +5,7 @@ After=telemprobd.socket
|
||||
ConditionPathExists=!/etc/telemetrics/opt-out
|
||||
|
||||
[Service]
|
||||
ExecStart=@bindir@/hprobe -H
|
||||
ExecStart=@bindir@/hprobe -Hlu
|
||||
User=telemetry
|
||||
|
||||
[Install]
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
[Unit]
|
||||
Description=Telemetrics Systemd Journal Probe
|
||||
Requires=telemprobd.socket
|
||||
After=telemprobd.socket
|
||||
ConditionPathExists=!/etc/telemetrics/opt-out
|
||||
|
||||
[Service]
|
||||
ExecStart=@bindir@/journalprobe -t
|
||||
User=telemetry
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
@@ -1,7 +1,7 @@
|
||||
[Unit]
|
||||
Description=Telemetrics Kernel Log Scanner
|
||||
Requires=telemprobd.socket
|
||||
After=telemprobd.socket oops-probe.service
|
||||
After=telemprobd.socket
|
||||
|
||||
[Service]
|
||||
ExecStart=@bindir@/klogscanner
|
||||
|
||||
+19
-5
@@ -5,18 +5,22 @@ pathfix = @sed \
|
||||
-e 's|@localstatedir[@]|$(localstatedir)|g' \
|
||||
-e 's|@PACKAGE_VERSION[@]|$(PACKAGE_VERSION)|g' \
|
||||
-e 's|@SOCKETDIR[@]|$(SOCKETDIR)|g' \
|
||||
-e 's|@systemctldir[@]|$(SYSTEMD_SYSTEMCTLDIR)|g'
|
||||
-e 's|@systemctldir[@]|$(SYSTEMD_SYSTEMCTLDIR)|g' \
|
||||
-e 's|@BACKEND_ADDR[@]|$(BACKEND_ADDR)|g'
|
||||
|
||||
EXTRA_DIST += \
|
||||
%D%/40-core-ulimit.conf \
|
||||
%D%/40-crash-probe.conf.in \
|
||||
%D%/example.conf \
|
||||
%D%/example.1.conf \
|
||||
%D%/example.2.conf \
|
||||
%D%/hprobe.service.in \
|
||||
%D%/hprobe.timer \
|
||||
%D%/bert-probe.service.in \
|
||||
%D%/journal-probe.service.in \
|
||||
%D%/oops-probe.service.in \
|
||||
%D%/journal-probe-tail.service.in \
|
||||
%D%/python-probe.service.in \
|
||||
%D%/python-probe.path.in \
|
||||
%D%/pstore-probe.service.in \
|
||||
%D%/klogscanner.service.in \
|
||||
%D%/pstore-clean.service.in \
|
||||
@@ -53,7 +57,9 @@ systemdunit_DATA = \
|
||||
%D%/hprobe.timer \
|
||||
%D%/bert-probe.service \
|
||||
%D%/journal-probe.service \
|
||||
%D%/oops-probe.service \
|
||||
%D%/journal-probe-tail.service \
|
||||
%D%/python-probe.service \
|
||||
%D%/python-probe.path \
|
||||
%D%/pstore-probe.service \
|
||||
%D%/klogscanner.service \
|
||||
%D%/pstore-clean.service \
|
||||
@@ -72,7 +78,7 @@ systemdunit_DATA = \
|
||||
%D%/journal-probe.service: %D%/journal-probe.service.in
|
||||
$(pathfix) < $< > $@
|
||||
|
||||
%D%/oops-probe.service: %D%/oops-probe.service.in
|
||||
%D%/journal-probe-tail.service: %D%/journal-probe-tail.service.in
|
||||
$(pathfix) < $< > $@
|
||||
|
||||
%D%/pstore-probe.service: %D%/pstore-probe.service.in
|
||||
@@ -90,6 +96,12 @@ systemdunit_DATA = \
|
||||
%D%/telempostd.service: %D%/telempostd.service.in
|
||||
$(pathfix) < $< > $@
|
||||
|
||||
%D%/python-probe.service: %D%/python-probe.service.in
|
||||
$(pathfix) < $< > $@
|
||||
|
||||
%D%/python-probe.path: %D%/python-probe.path.in
|
||||
$(pathfix) < $< > $@
|
||||
|
||||
%D%/telemprobd.service: %D%/telemprobd.service.in
|
||||
$(pathfix) < $< > $@
|
||||
|
||||
@@ -113,13 +125,15 @@ clean-local:
|
||||
%D%/telemprobd.socket \
|
||||
%D%/telempostd.service \
|
||||
%D%/telempostd.path \
|
||||
%D%/python-probe.service \
|
||||
%D%/python-probe.path \
|
||||
%D%/telemprobd-update-trigger.service \
|
||||
%D%/telemetrics.conf \
|
||||
%D%/telemetrics-dirs.conf \
|
||||
%D%/libtelemetry.pc \
|
||||
%D%/40-crash-probe.conf \
|
||||
%D%/journal-probe.service \
|
||||
%D%/oops-probe.service \
|
||||
%D%/journal-probe-tail.service \
|
||||
%D%/pstore-probe.service \
|
||||
%D%/klogscanner.service \
|
||||
%D%/pstore-clean.service \
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
[Unit]
|
||||
Description=Python Probe Daemon Staging
|
||||
ConditionPathExists=!/etc/telemetrics/opt-out
|
||||
|
||||
[Path]
|
||||
DirectoryNotEmpty=/var/lib/telemetry/python
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
@@ -1,11 +1,13 @@
|
||||
[Unit]
|
||||
Description=Telemetrics Kernel Oops Probe
|
||||
Description=Telemetrics Python Probe
|
||||
Requires=telemprobd.socket
|
||||
After=telemprobd.socket
|
||||
ConditionPathExists=!/etc/telemetrics/opt-out
|
||||
|
||||
[Service]
|
||||
ExecStart=@bindir@/oopsprobe
|
||||
User=telemetry
|
||||
ExecStart=@bindir@/pythonprobe
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
|
||||
@@ -3,5 +3,6 @@ d @localstatedir@/spool/telemetry 0750 telemetry telemetry -
|
||||
d @localstatedir@/log/telemetry 0750 telemetry telemetry -
|
||||
d @localstatedir@/log/telemetry/records 0750 telemetry telemetry -
|
||||
d @localstatedir@/cache/telemetry 0750 telemetry telemetry -
|
||||
d @localstatedir@/cache/telemetry/oops 0750 telemetry telemetry -
|
||||
d @localstatedir@/cache/telemetry/pstore 0750 telemetry telemetry -
|
||||
d /var/lib/telemetry/python 01777 telemetry telemetry -
|
||||
d /var/tmp/telemetry 01777 telemetry telemetry -
|
||||
|
||||
@@ -1,67 +1,69 @@
|
||||
# values represent their default state
|
||||
# copy to /etc/telemetrics/telemetrics.conf and modify for user config
|
||||
[settings]
|
||||
# ip address of destination server for record delivery
|
||||
server=https://clr.telemetry.intel.com/v2/collector
|
||||
#server=@BACKEND_ADDR@
|
||||
|
||||
socket_path=@SOCKETDIR@/telem-0
|
||||
#socket_path=@SOCKETDIR@/telem-0
|
||||
|
||||
# certificate file to use to validate ssl endpoint
|
||||
cainfo=
|
||||
#cainfo=
|
||||
|
||||
# Telemetry id - post header used to group records in ingestion service,
|
||||
# which may be ingesting for more than one set of clients. Can be set
|
||||
# to any string.
|
||||
tidheader=X-Telemetry-TID:\s6907c830-eed9-4ce9-81ae-76daf8d88f0f
|
||||
#tidheader=X-Telemetry-TID:\s6907c830-eed9-4ce9-81ae-76daf8d88f0f
|
||||
|
||||
# record expiry time in minutes
|
||||
record_expiry=1200
|
||||
#record_expiry=1200
|
||||
|
||||
spool_dir=@localstatedir@/spool/telemetry
|
||||
#spool_dir=@localstatedir@/spool/telemetry
|
||||
|
||||
# maximum size of the spool directory in KB, -1 = quota disabled.
|
||||
# The block size of the files in this directory is considered,
|
||||
# and not the actual size of the record itself.
|
||||
spool_max_size=5120
|
||||
#spool_max_size=5120
|
||||
|
||||
# time in seconds for processing spool
|
||||
# Valid range: 120..3600. Values outside this range are clamped.
|
||||
spool_process_time=900
|
||||
# Valid range: 120..300. Values outside this range are clamped.
|
||||
#spool_process_time=120
|
||||
|
||||
# rate limit enabled - if this is set to false then all rate-limiting disabled.
|
||||
# It is possible to disable each rate-limit individually below.
|
||||
rate_limit_enabled=true
|
||||
#rate_limit_enabled=true
|
||||
|
||||
# rate limiting record burst limit
|
||||
# Valid Range: 0..INT_MAX, -1 = disabled.
|
||||
record_burst_limit=1000
|
||||
#record_burst_limit=1000
|
||||
|
||||
# rate limiting record window length in minutes
|
||||
# Valid Range: 0..59
|
||||
record_window_length=15
|
||||
#record_window_length=15
|
||||
|
||||
# rate limiting byte burst limit
|
||||
# Valid Range: 0..INT_MAX, -1 = disabled.
|
||||
byte_burst_limit=-1
|
||||
#byte_burst_limit=-1
|
||||
|
||||
# rate limiting byte window length in minutes
|
||||
# Valid Range: 0..59
|
||||
byte_window_length=20
|
||||
#byte_window_length=20
|
||||
|
||||
# rate limit strategy - what to do with record if rate-limiting prevents
|
||||
# delivery over network
|
||||
# Valid stategies: spool, drop
|
||||
rate_limit_strategy=spool
|
||||
#rate_limit_strategy=spool
|
||||
|
||||
# daemon recycling enabled - if daemon has been running for a while (2 hours),
|
||||
# has not any client nor spool data, then it exits.
|
||||
# this is to ensure that latest code runs.
|
||||
daemon_recycling_enabled=true
|
||||
#daemon_recycling_enabled=true
|
||||
|
||||
# record server delivery enabled - when enabled records will be delivered
|
||||
# to server otherwise records will be ignored. This configuration can be used
|
||||
# with 'record_retention_enable' configuration value to keep records local only.
|
||||
record_server_delivery_enabled=true
|
||||
#record_server_delivery_enabled=true
|
||||
|
||||
# record retention enabled - when enabled a copy of reported telemetry records
|
||||
# will be kept locally. This configuration combined with 'record_server_delivery_enabled'
|
||||
# value can be used to keep records local only.
|
||||
record_retention_enabled=false
|
||||
#record_retention_enabled=false
|
||||
|
||||
+34
-50
@@ -41,62 +41,20 @@ bool _fgets(char *s, int n, FILE *stream)
|
||||
return true;
|
||||
}
|
||||
|
||||
void stage_record(char *filepath, char *headers[], char *body)
|
||||
{
|
||||
int tmpfd;
|
||||
FILE *tmpfile = NULL;
|
||||
|
||||
// Use default path if not provided
|
||||
if (filepath == NULL) {
|
||||
telem_log(LOG_ERR, "filepath value must be provided, aborting\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
tmpfd = mkstemp(filepath);
|
||||
if (!tmpfd) {
|
||||
telem_perror("Error opening staging file");
|
||||
close(tmpfd);
|
||||
if (unlink(filepath)) {
|
||||
telem_perror("Error deleting staging file");
|
||||
}
|
||||
goto clean_exit;
|
||||
}
|
||||
|
||||
// open file
|
||||
tmpfile = fdopen(tmpfd, "a");
|
||||
if (!tmpfile) {
|
||||
telem_perror("Error opening temp stage file");
|
||||
close(tmpfd);
|
||||
if (unlink(filepath)) {
|
||||
telem_perror("Error deleting temp stage file");
|
||||
}
|
||||
goto clean_exit;
|
||||
}
|
||||
|
||||
// write headers
|
||||
for (int i = 0; i < NUM_HEADERS; i++) {
|
||||
fprintf(tmpfile, "%s\n", headers[i]);
|
||||
}
|
||||
|
||||
//write body
|
||||
fprintf(tmpfile, "%s\n", body);
|
||||
fflush(tmpfile);
|
||||
fclose(tmpfile);
|
||||
|
||||
clean_exit:
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
bool read_record(char *fullpath, char *headers[], char **body)
|
||||
bool read_record(char *fullpath, char *headers[], char **body, char **cfg_file)
|
||||
{
|
||||
int i, ret = 0;
|
||||
bool result = false;
|
||||
FILE *fp = NULL;
|
||||
long offset;
|
||||
char line[LINE_MAX] = { 0 };
|
||||
#if (LINE_MAX > PATH_MAX)
|
||||
char line[LINE_MAX+1] = { 0 };
|
||||
#else
|
||||
char line[PATH_MAX+1] = { 0 };
|
||||
#endif
|
||||
struct stat buf;
|
||||
long size;
|
||||
uint32_t cfg_prefix = 0;
|
||||
|
||||
ret = stat(fullpath, &buf);
|
||||
if (ret == -1) {
|
||||
@@ -111,9 +69,35 @@ bool read_record(char *fullpath, char *headers[], char **body)
|
||||
return false;
|
||||
}
|
||||
|
||||
// First line may contain configuration file path
|
||||
if (fread(&cfg_prefix, CFG_PREFIX_LENGTH, 1, fp) != 1) {
|
||||
telem_log(LOG_ERR, "Error while parsing staged record configuration info.\n");
|
||||
goto read_error;
|
||||
}
|
||||
|
||||
if (cfg_prefix == CFG_PREFIX_32BIT) {
|
||||
if (!_fgets(line, sizeof(line), fp)) {
|
||||
telem_log(LOG_ERR, "Error while parsing staged record [%x]\n", cfg_prefix);
|
||||
goto read_error;
|
||||
}
|
||||
|
||||
size_t pathlen = strlen(line);
|
||||
*cfg_file = malloc(pathlen + 1);
|
||||
if (cfg_file == NULL) {
|
||||
telem_log(LOG_ERR, "Could not allocate memory for config file path\n");
|
||||
goto read_error;
|
||||
}
|
||||
strcpy (*cfg_file, line);
|
||||
telem_debug("DEBUG: cfg_file specified: %s\n", *cfg_file);
|
||||
} else {
|
||||
telem_debug("DEBUG: no user cfg file specified, cfg_prefix: %08x\n", cfg_prefix);
|
||||
*cfg_file = NULL;
|
||||
rewind(fp);
|
||||
}
|
||||
|
||||
for (i = 0; i < NUM_HEADERS; i++) {
|
||||
const char *header_name = get_header_name(i);
|
||||
if (!_fgets(line, LINE_MAX, fp)) {
|
||||
if (!_fgets(line, sizeof(line), fp)) {
|
||||
telem_log(LOG_ERR, "Error while parsing staged record\n");
|
||||
fclose(fp);
|
||||
return false;
|
||||
|
||||
+1
-11
@@ -16,16 +16,6 @@
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
/**
|
||||
* Save a telemetry record to disk
|
||||
*
|
||||
* @param path pointer to a directory to save record
|
||||
* @param headers pointer to array of headers and values
|
||||
* @param body record message content
|
||||
*
|
||||
*/
|
||||
void stage_record(char *path, char *headers[], char *body);
|
||||
|
||||
/**
|
||||
* Reads a telemetry record
|
||||
*
|
||||
@@ -35,4 +25,4 @@ void stage_record(char *path, char *headers[], char *body);
|
||||
*
|
||||
* @return true if successful otherwise false
|
||||
*/
|
||||
bool read_record(char *fullpath, char *headers[], char **body);
|
||||
bool read_record(char *fullpath, char *headers[], char **body, char **cfg);
|
||||
|
||||
+12
-9
@@ -24,14 +24,18 @@
|
||||
#include "common.h"
|
||||
#include "journal.h"
|
||||
|
||||
void print_usage(void)
|
||||
static void print_usage(void)
|
||||
{
|
||||
printf(" Usage\n");
|
||||
printf("Usage:\n");
|
||||
printf(" telem_journal [-Vi] [-r <record_id>] [-e <event_id>] [-c <classification>] [-b <boot_id>]\n\n");
|
||||
printf("Where:\n");
|
||||
printf(" -r, --record_id Print record with specific record_id\n");
|
||||
printf(" -e, --event_id Print records with specific event_id\n");
|
||||
printf(" -c, --classification Print records with specific classification\n");
|
||||
printf(" -b, --boot_id Print records with specific boot_id\n");
|
||||
printf(" -i, --include_record Include record content\n");
|
||||
printf(" -i, --include_record Include record content if available.\n");
|
||||
printf(" Content only available when telemetry is configured\n");
|
||||
printf(" with \"record_retention_enabled=true\"\n");
|
||||
printf(" -V, --verbose Verbose output\n");
|
||||
printf(" -h, --help Display this help message\n");
|
||||
}
|
||||
@@ -41,8 +45,8 @@ int main(int argc, char **argv)
|
||||
|
||||
int rc = EXIT_SUCCESS;
|
||||
int count = 0;
|
||||
int verbose_output = 0;
|
||||
int record = 0;
|
||||
bool verbose_output = false;
|
||||
bool record = false;
|
||||
char *boot_id = NULL;
|
||||
char *record_id = NULL;
|
||||
char *event_id = NULL;
|
||||
@@ -78,16 +82,15 @@ int main(int argc, char **argv)
|
||||
boot_id = optarg;
|
||||
break;
|
||||
case 'V':
|
||||
verbose_output = 1;
|
||||
verbose_output = true;
|
||||
break;
|
||||
case 'i':
|
||||
record = 1;
|
||||
record = true;
|
||||
break;
|
||||
case 'h':
|
||||
print_usage();
|
||||
exit(EXIT_SUCCESS);
|
||||
case '?':
|
||||
/** default */
|
||||
default:
|
||||
print_usage();
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
+22
-58
@@ -58,9 +58,7 @@ static int serialize_journal_entry(struct JournalEntry *entry, char **buff)
|
||||
|
||||
if (asprintf(buff, "%s\036%lld\036%s\036%s\036%s", entry->record_id, (long long int)entry->timestamp,
|
||||
entry->classification, entry->event_id, entry->boot_id) < 0) {
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "Error: unable to serialize data in buff\n");
|
||||
#endif
|
||||
telem_log(LOG_ERR, "Error: Unable to serialize data in buff\n");
|
||||
rc = -1;
|
||||
}
|
||||
|
||||
@@ -204,9 +202,7 @@ static int save_entry(FILE *fptr, struct JournalEntry *entry)
|
||||
}
|
||||
|
||||
if ((rc = serialize_journal_entry(entry, &serialized_data)) == 0) {
|
||||
#ifdef DEBUG
|
||||
printf("Saving: %s\n", serialized_data);
|
||||
#endif
|
||||
telem_debug("DEBUG: Saving: %s\n", serialized_data);
|
||||
fprintf(fptr, "%s\n", serialized_data);
|
||||
fflush(fptr);
|
||||
free(serialized_data);
|
||||
@@ -229,9 +225,7 @@ static int read_boot_id(char buff[])
|
||||
|
||||
fs = fopen(BOOTID_FILE, "r");
|
||||
if (!fs) {
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "Unable to open %s for reading: %d\n", BOOTID_FILE, errno);
|
||||
#endif
|
||||
telem_log(LOG_ERR, "Error: Unable to open %s for reading: %d\n", BOOTID_FILE, errno);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -264,9 +258,7 @@ static int skip_n_lines(int n, FILE *fptr, int (*found_record)(char *))
|
||||
struct JournalEntry *entry = NULL;
|
||||
|
||||
if (fptr == NULL) {
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "fptr argument to skip_n_lines is invalid\n");
|
||||
#endif
|
||||
telem_log(LOG_ERR, "fptr argument to skip_n_lines is invalid\n");
|
||||
// File descriptor in bad state
|
||||
return EBADFD;
|
||||
}
|
||||
@@ -327,9 +319,7 @@ static int copy_to_tmp(FILE *fptr, char *tmp_path)
|
||||
|
||||
if (fclose(fptr_tmp) != 0) {
|
||||
rc = errno;
|
||||
#ifdef DEBUG
|
||||
perror("Error: ");
|
||||
#endif
|
||||
telem_perror("Error");
|
||||
}
|
||||
free(line);
|
||||
|
||||
@@ -350,22 +340,18 @@ TelemJournal *open_journal(const char *journal_file)
|
||||
fptr = fopen(journal_file, "a+");
|
||||
}
|
||||
if (fptr == NULL) {
|
||||
#ifdef DEBUG
|
||||
perror("Error while opening journal file: ");
|
||||
#endif
|
||||
telem_perror("Error while opening journal file");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (read_boot_id(boot_id) != 0) {
|
||||
#ifdef DEBUG
|
||||
perror("Error while reading boot_id: ");
|
||||
#endif
|
||||
telem_perror("Error while reading boot_id");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
telem_journal = malloc(sizeof(struct TelemJournal));
|
||||
if (!telem_journal) {
|
||||
fprintf(stderr, "Unable to allocate more memory\n");
|
||||
telem_log(LOG_CRIT, "CRIT: Unable to allocate memory\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -379,9 +365,7 @@ TelemJournal *open_journal(const char *journal_file)
|
||||
telem_journal->latest_record_id = NULL;
|
||||
telem_journal->prune_entry_callback = NULL;
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("Records in db: %d\n", telem_journal->record_count);
|
||||
#endif
|
||||
telem_debug("Records in db: %d\n", telem_journal->record_count);
|
||||
|
||||
return telem_journal;
|
||||
}
|
||||
@@ -433,7 +417,7 @@ static void print_record(char *record_id)
|
||||
|
||||
recordfp = fopen(filepath, "r");
|
||||
if (!recordfp) {
|
||||
telem_perror("Error when opening a record to print");
|
||||
telem_log(LOG_INFO, "Could not open record %s: %s\n", record_id, strerror(errno));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -476,7 +460,7 @@ int print_journal(TelemJournal *telem_journal, char *classification,
|
||||
if (rc == -1) {
|
||||
return rc;
|
||||
} else if (rc != 0) {
|
||||
fprintf(stderr, "An error occurred while advancing journal file: %s\n", strerror(rc));
|
||||
telem_log(LOG_ERR, "An error occurred while advancing journal file: %s\n", strerror(rc));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -563,9 +547,7 @@ int new_journal_entry(TelemJournal *telem_journal, char *classification,
|
||||
struct JournalEntry *entry = NULL;
|
||||
|
||||
if (telem_journal == NULL) {
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "Error: telem_journal was not initialized\n");
|
||||
#endif
|
||||
telem_log(LOG_ERR, "telem_journal was not initialized\n");
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -579,7 +561,7 @@ int new_journal_entry(TelemJournal *telem_journal, char *classification,
|
||||
|
||||
entry = malloc(sizeof(struct JournalEntry));
|
||||
if (!entry) {
|
||||
fprintf(stderr, "Error: unable to allocate more memory\n");
|
||||
telem_log(LOG_CRIT, "CRIT: unable to allocate memory\n");
|
||||
return rc;
|
||||
}
|
||||
entry->classification = NULL;
|
||||
@@ -588,16 +570,12 @@ int new_journal_entry(TelemJournal *telem_journal, char *classification,
|
||||
entry->boot_id = NULL;
|
||||
|
||||
if (get_random_id(&record_id) != 0) {
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "Error: unable to generate random id\n");
|
||||
#endif
|
||||
telem_log(LOG_ERR, "Erorr: Unable to generate random id\n");
|
||||
goto quit;
|
||||
}
|
||||
|
||||
if (read_boot_id(boot_id) != 0) {
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "Error: unable to read boot_id\n");
|
||||
#endif
|
||||
telem_log(LOG_ERR, "Error: Unable to read boot_id\n");
|
||||
goto quit;
|
||||
}
|
||||
|
||||
@@ -615,9 +593,7 @@ int new_journal_entry(TelemJournal *telem_journal, char *classification,
|
||||
|
||||
if ((rc = save_entry(telem_journal->fptr, entry)) == 0) {
|
||||
telem_journal->record_count = telem_journal->record_count + 1;
|
||||
#ifdef DEBUG
|
||||
fprintf(stdout, "%d records in journal\n", telem_journal->record_count);
|
||||
#endif
|
||||
telem_debug("DEBUG: %d records in journal\n", telem_journal->record_count);
|
||||
}
|
||||
|
||||
free(telem_journal->latest_record_id);
|
||||
@@ -647,9 +623,7 @@ int prune_journal(struct TelemJournal *telem_journal, char *tmp_dir)
|
||||
|
||||
// jump to line# count
|
||||
if ((rc = skip_n_lines(count, telem_journal->fptr, telem_journal->prune_entry_callback)) != 0) {
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "Error: skipping %d journal lines\n", count);
|
||||
#endif
|
||||
telem_log(LOG_ERR, "Error skipping %d journal lines\n", count);
|
||||
// if rc == -1 (n > #lines in file, change to errno style)
|
||||
return (rc == -1) ? EADDRNOTAVAIL : rc;
|
||||
}
|
||||
@@ -665,38 +639,28 @@ int prune_journal(struct TelemJournal *telem_journal, char *tmp_dir)
|
||||
}
|
||||
// create new file with rest of file
|
||||
if ((rc = copy_to_tmp(telem_journal->fptr, tmp_file_path)) != 0) {
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "Error: copying partial journal to temp journal file\n");
|
||||
#endif
|
||||
telem_log(LOG_ERR, "Error copying partial journal to temp journal file\n");
|
||||
goto quit;
|
||||
}
|
||||
// close file handler
|
||||
if ((rc = fclose(telem_journal->fptr)) != 0) {
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "Error: closing journal file handler\n");
|
||||
#endif
|
||||
telem_log(LOG_ERR, "Error closing journal file handler\n");
|
||||
goto quit;
|
||||
}
|
||||
// overwrite file
|
||||
if ((rc = rename(tmp_file_path, telem_journal->journal_file)) != 0) {
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "Error: while overwriting journal file\n");
|
||||
#endif
|
||||
telem_log(LOG_ERR, "Error while overwriting journal file\n");
|
||||
goto quit;
|
||||
}
|
||||
// reopen file handler
|
||||
telem_journal->fptr = fopen(telem_journal->journal_file, "a+");
|
||||
if (!telem_journal->fptr) {
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "Error: re-opening journal file\n");
|
||||
#endif
|
||||
telem_log(LOG_ERR, "Error re-opening journal file\n");
|
||||
return rc;
|
||||
}
|
||||
// update record count
|
||||
telem_journal->record_count = telem_journal->record_count - count;
|
||||
#ifdef DEBUG
|
||||
fprintf(stdout, "record_count: %d\n", telem_journal->record_count);
|
||||
#endif
|
||||
telem_debug("DEBUG: record_count: %d\n", telem_journal->record_count);
|
||||
}
|
||||
rc = 0;
|
||||
|
||||
|
||||
@@ -5,5 +5,11 @@ bin_PROGRAMS += \
|
||||
%D%/journal.c \
|
||||
src/util.c \
|
||||
src/common.c
|
||||
%C%_telem_journal_CFLAGS = \
|
||||
$(AM_CFLAGS)
|
||||
|
||||
if LOG_SYSTEMD
|
||||
%C%_telem_journal_CFLAGS += $(SYSTEMD_JOURNAL_CFLAGS)
|
||||
%C%_telem_journal_LDADD = $(SYSTEMD_JOURNAL_LIBS)
|
||||
endif
|
||||
# vim: filetype=automake tabstop=8 shiftwidth=8 noexpandtab
|
||||
|
||||
+4
-3
@@ -6,12 +6,12 @@ bin_PROGRAMS = \
|
||||
%D%/probe.c \
|
||||
%D%/telemdaemon.c \
|
||||
%D%/telemdaemon.h \
|
||||
%D%/iorecord.c \
|
||||
%D%/journal/journal.c \
|
||||
%D%/journal/journal.h
|
||||
|
||||
%C%_telemprobd_LDADD = $(CURL_LIBS) \
|
||||
%D%/libtelem-shared.la
|
||||
%D%/libtelem-shared.la \
|
||||
%D%/libtelemetry.la
|
||||
|
||||
%C%_telemprobd_CFLAGS = \
|
||||
$(AM_CFLAGS)
|
||||
@@ -51,7 +51,8 @@ endif
|
||||
%D%/iorecord.h
|
||||
|
||||
%C%_telempostd_LDADD = $(CURL_LIBS) \
|
||||
%D%/libtelem-shared.la
|
||||
%D%/libtelem-shared.la \
|
||||
%D%/libtelemetry.la
|
||||
|
||||
%C%_telempostd_CFLAGS = \
|
||||
$(AM_CFLAGS)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* This program is part of the Clear Linux Project
|
||||
*
|
||||
* Copyright 2015 Intel Corporation
|
||||
* Copyright 2019 Intel Corporation
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under
|
||||
* the terms and conditions of the GNU Lesser General Public License, as
|
||||
@@ -17,6 +17,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "config.h"
|
||||
|
||||
@@ -35,15 +36,14 @@
|
||||
#include <systemd/sd-journal.h>
|
||||
#endif
|
||||
#else
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <syslog.h>
|
||||
#endif
|
||||
|
||||
#ifdef DEBUG
|
||||
#define telem_debug(...) do { \
|
||||
(telem_log(LOG_DEBUG, "%s():[%d]", __func__, __LINE__), \
|
||||
telem_log(LOG_DEBUG, __VA_ARGS__)); \
|
||||
telem_log(LOG_DEBUG, "%s():[%d] ", __func__, __LINE__); \
|
||||
telem_log(LOG_DEBUG, __VA_ARGS__); \
|
||||
} while (0);
|
||||
#else
|
||||
#define telem_debug(...) do {} while (0);
|
||||
|
||||
+12
-13
@@ -21,12 +21,19 @@
|
||||
#include <stdbool.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include "telemetry.h"
|
||||
#include "log.h"
|
||||
#include "spool.h"
|
||||
#include "configuration.h"
|
||||
#include "telempostdaemon.h"
|
||||
|
||||
bool (*post_record_ptr)(char *[], char *) = post_record_http;
|
||||
/*
|
||||
* Using a function pointer for unit testing to isolate the call to actual post function.
|
||||
* The call to post the record to the server is stubbed out in the unit tests
|
||||
* using pointer to a fake function.
|
||||
*/
|
||||
|
||||
bool (*post_record_ptr)(char *[], char *, char *) = post_record_http;
|
||||
|
||||
void print_usage(char *prog)
|
||||
{
|
||||
@@ -40,9 +47,7 @@ int main(int argc, char **argv)
|
||||
{
|
||||
|
||||
int c;
|
||||
int ret = 0;
|
||||
int opt_index = 0;
|
||||
char *config_file = NULL;
|
||||
TelemPostDaemon daemon;
|
||||
|
||||
struct option opts[] = {
|
||||
@@ -55,17 +60,11 @@ int main(int argc, char **argv)
|
||||
while ((c = getopt_long(argc, argv, "f:hV", opts, &opt_index)) != -1) {
|
||||
switch (c) {
|
||||
case 'f':
|
||||
config_file = optarg;
|
||||
struct stat buf;
|
||||
ret = stat(config_file, &buf);
|
||||
|
||||
/* check if the file exists and is a regular file */
|
||||
if (ret == -1 || !S_ISREG(buf.st_mode)) {
|
||||
telem_log(LOG_ERR, "Configuration file"
|
||||
if (tm_set_config_file(optarg) != 0) {
|
||||
telem_log(LOG_ERR, "Configuration file"
|
||||
" path not valid\n");
|
||||
exit(EXIT_FAILURE);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
set_config_file(config_file);
|
||||
break;
|
||||
case 'V':
|
||||
printf(PACKAGE_VERSION "\n");
|
||||
@@ -79,7 +78,7 @@ int main(int argc, char **argv)
|
||||
}
|
||||
}
|
||||
|
||||
initialize_daemon(&daemon);
|
||||
initialize_post_daemon(&daemon);
|
||||
|
||||
daemon.current_spool_size = get_spool_dir_size();
|
||||
|
||||
|
||||
+11
-22
@@ -31,6 +31,7 @@
|
||||
#include <signal.h>
|
||||
#include <malloc.h>
|
||||
|
||||
#include "telemetry.h"
|
||||
#include "config.h"
|
||||
#include "common.h"
|
||||
#ifdef HAVE_SYSTEMD_SD_DAEMON_H
|
||||
@@ -50,12 +51,6 @@
|
||||
#include "telemdaemon.h"
|
||||
#include "configuration.h"
|
||||
|
||||
/*
|
||||
* Using a function pointer for unit testing to isolate the call to actual post function.
|
||||
* The call to post the record to the server is stubbed out in the unit tests
|
||||
* using pointer to a fake function.
|
||||
*/
|
||||
|
||||
void print_usage(char *prog)
|
||||
{
|
||||
printf("%s: Usage\n", prog);
|
||||
@@ -74,7 +69,6 @@ int main(int argc, char **argv)
|
||||
client *cl = NULL;
|
||||
client *current_client = NULL;
|
||||
int c;
|
||||
char *config_file = NULL;
|
||||
int opt_index = 0;
|
||||
sigset_t mask;
|
||||
//bool interrupted = false;
|
||||
@@ -92,18 +86,12 @@ int main(int argc, char **argv)
|
||||
|
||||
while ((c = getopt_long(argc, argv, "f:hV", opts, &opt_index)) != -1) {
|
||||
switch (c) {
|
||||
case 'f':
|
||||
config_file = optarg;
|
||||
struct stat buf;
|
||||
ret = stat(config_file, &buf);
|
||||
|
||||
/* check if the file exists and is a regular file */
|
||||
if (ret == -1 || !S_ISREG(buf.st_mode)) {
|
||||
telem_log(LOG_ERR, "Configuration file"
|
||||
case 'f':
|
||||
if (tm_set_config_file(optarg) != 0) {
|
||||
telem_log(LOG_ERR, "Configuration file"
|
||||
" path not valid\n");
|
||||
exit(EXIT_FAILURE);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
set_config_file(config_file);
|
||||
break;
|
||||
case 'h':
|
||||
print_usage(argv[0]);
|
||||
@@ -117,7 +105,7 @@ int main(int argc, char **argv)
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
initialize_daemon(&daemon);
|
||||
initialize_probe_daemon(&daemon);
|
||||
|
||||
sigemptyset(&mask);
|
||||
|
||||
@@ -220,7 +208,7 @@ int main(int argc, char **argv)
|
||||
|
||||
bool daemon_recycling_enabled = daemon_recycling_enabled_config();
|
||||
int spool_process_time = spool_process_time_config();
|
||||
time_t last_daemon_start_time = time(NULL);
|
||||
time_t last_record_received = time(NULL);
|
||||
|
||||
ret = update_machine_id();
|
||||
if (ret == -1) {
|
||||
@@ -255,8 +243,8 @@ int main(int argc, char **argv)
|
||||
}
|
||||
|
||||
if (fdsi.ssi_signo == SIGTERM || fdsi.ssi_signo == SIGINT) {
|
||||
telem_log(LOG_INFO, "Received either a \
|
||||
SIGINT/SIGTERM signal\n");
|
||||
telem_log(LOG_INFO, "Received either a "
|
||||
"SIGINT/SIGTERM signal\n");
|
||||
goto clean_exit;
|
||||
}
|
||||
|
||||
@@ -315,13 +303,14 @@ int main(int argc, char **argv)
|
||||
}
|
||||
assert(current_client);
|
||||
handle_client(&daemon, i, current_client);
|
||||
last_record_received = time(NULL);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
time_t now = time(NULL);
|
||||
/* time to recycle the daemon has elapsed*/
|
||||
if (daemon_recycling_enabled &&
|
||||
difftime(now, last_daemon_start_time) >= TM_DAEMON_EXIT_TIME) {
|
||||
difftime(now, last_record_received) >= TM_DAEMON_EXIT_TIME) {
|
||||
/* Exit */
|
||||
telem_log(LOG_INFO, "Daemon exiting for recycling\n");
|
||||
goto clean_exit;
|
||||
|
||||
@@ -14,11 +14,13 @@ The default probes provided along the telemetry client code are:
|
||||
* journalprobe: a probe that monitors the systemd journal for log messages
|
||||
from failed services.
|
||||
|
||||
* oopsprobe: a probe to collect 'oops messages' when the kernel detects a
|
||||
* klogscanner: a probe to collect 'oops messages' when the kernel detects a
|
||||
problem.
|
||||
|
||||
* pstoreprobe: probe to collect messages left on pstore filesystem.
|
||||
|
||||
* pythonprobe: a probe that monitors Python generated traceback files.
|
||||
|
||||
* telem-record-gen: this is a "general-purpose probe" for sending custom
|
||||
records on-the-fly. This tool can be used stand alone or as a part of a
|
||||
script to implement a probe.
|
||||
|
||||
+20
-45
@@ -25,6 +25,7 @@
|
||||
#include "nica/b64enc.h"
|
||||
|
||||
#include "config.h"
|
||||
#include "log.h"
|
||||
|
||||
static const char bert_record_file[] = "/sys/firmware/acpi/tables/data/BERT";
|
||||
static const char telem_record_class[] = "org.clearlinux/bert/debug";
|
||||
@@ -39,35 +40,16 @@ void print_usage(char *prog)
|
||||
printf(" -V, --version Print the program version\n");
|
||||
}
|
||||
|
||||
static int allocate_payload_buffer(char **payload)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
*payload = (char *)malloc(MAX_PAYLOAD_SIZE);
|
||||
|
||||
if (*payload == NULL) {
|
||||
goto out;
|
||||
}
|
||||
|
||||
*payload = memset(*payload, 0, MAX_PAYLOAD_SIZE);
|
||||
ret = 1;
|
||||
|
||||
out:
|
||||
return ret;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
struct telem_ref *tm_handle = NULL;
|
||||
char *classification = (char *)telem_record_class;
|
||||
char *payload = NULL;
|
||||
char *payload;
|
||||
int ret;
|
||||
|
||||
// Following vars are for arg parsing.
|
||||
int c;
|
||||
char *cfile = NULL;
|
||||
int opt_index = 0;
|
||||
int ret = 0;
|
||||
|
||||
struct option opts[] = {
|
||||
{ "config_file", 1, NULL, 'f' },
|
||||
{ "help", 0, NULL, 'h' },
|
||||
@@ -75,22 +57,14 @@ int main(int argc, char **argv)
|
||||
{ NULL, 0, NULL, 0 }
|
||||
};
|
||||
|
||||
while ((c = getopt_long(argc, argv, "f:hHV", opts, &opt_index)) != -1) {
|
||||
while ((c = getopt_long(argc, argv, "f:hV", opts, &opt_index)) != -1) {
|
||||
switch (c) {
|
||||
case 'f':
|
||||
if (asprintf(&cfile, "%s", (char *)optarg) < 0) {
|
||||
exit(EXIT_FAILURE);
|
||||
if (tm_set_config_file(optarg) != 0) {
|
||||
telem_log(LOG_ERR, "Configuration file"
|
||||
" path not valid\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
struct stat buf;
|
||||
ret = stat(cfile, &buf);
|
||||
|
||||
/* check if the file exists and is a regular file */
|
||||
if (ret == -1 || !S_ISREG(buf.st_mode)) {
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
tm_set_config_file(cfile);
|
||||
break;
|
||||
case 'h':
|
||||
print_usage(argv[0]);
|
||||
@@ -103,36 +77,37 @@ int main(int argc, char **argv)
|
||||
}
|
||||
}
|
||||
|
||||
if (!(ret = allocate_payload_buffer(&payload))) {
|
||||
payload = calloc(sizeof(char), MAX_PAYLOAD_LENGTH);
|
||||
if (!payload) {
|
||||
printf("Unable to allocate more memory.\n");
|
||||
goto fail;
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
if (!(ret = nc_b64enc_filename(bert_record_file, payload, MAX_PAYLOAD_SIZE))) {
|
||||
if (!(ret = nc_b64enc_filename(bert_record_file, payload, MAX_PAYLOAD_LENGTH))) {
|
||||
printf("Failed to read payload from: %s\n", bert_record_file);
|
||||
goto fail;
|
||||
ret = EXIT_FAILURE;
|
||||
goto done;
|
||||
}
|
||||
|
||||
if ((ret = tm_create_record(&tm_handle, severity, classification,
|
||||
payload_version)) < 0) {
|
||||
printf("Failed to create record: %s\n", strerror(-ret));
|
||||
goto fail;
|
||||
goto done;
|
||||
}
|
||||
|
||||
if ((ret = tm_set_payload(tm_handle, payload)) < 0) {
|
||||
printf("Failed to set record payload: %s\n", strerror(-ret));
|
||||
goto fail;
|
||||
goto done;
|
||||
}
|
||||
|
||||
free(payload);
|
||||
|
||||
if ((ret = tm_send_record(tm_handle)) < 0) {
|
||||
printf("Failed to send record to daemon: %s\n", strerror(-ret));
|
||||
goto fail;
|
||||
goto done;
|
||||
}
|
||||
|
||||
fail:
|
||||
free(cfile);
|
||||
ret = EXIT_SUCCESS;
|
||||
done:
|
||||
free(payload);
|
||||
tm_free_record(tm_handle);
|
||||
tm_handle = NULL;
|
||||
|
||||
|
||||
+27
-15
@@ -41,6 +41,8 @@
|
||||
#include "probe.h"
|
||||
#include "telemetry.h"
|
||||
|
||||
#define FRAMES_MAX 64
|
||||
|
||||
static Dwfl *d_core = NULL;
|
||||
|
||||
/*
|
||||
@@ -69,7 +71,6 @@ static char error_class[30] = "org.clearlinux/crash/error";
|
||||
static char unknown_class[30] = "org.clearlinux/crash/unknown";
|
||||
|
||||
static char temp_core[] = "/tmp/corefile-XXXXXX";
|
||||
static bool keep_core = false;
|
||||
|
||||
static const Dwfl_Callbacks cb =
|
||||
{
|
||||
@@ -299,6 +300,12 @@ static int frame_cb(Dwfl_Frame *frame, void *userdata)
|
||||
}
|
||||
}
|
||||
nc_string_append_printf(*bt, "\n");
|
||||
|
||||
if (frame_counter >= FRAMES_MAX) {
|
||||
errorstr = NULL;
|
||||
return DWARF_CB_ABORT;
|
||||
}
|
||||
|
||||
return DWARF_CB_OK;
|
||||
}
|
||||
|
||||
@@ -391,6 +398,12 @@ static int process_corefile(nc_string **backtrace)
|
||||
*backtrace = nc_string_dup("");
|
||||
|
||||
if (dwfl_getthreads(d_core, thread_cb, backtrace) != DWARF_CB_OK) {
|
||||
/* We aborted unwinding, due to too many frames.
|
||||
* We don't consider this as an error.
|
||||
*/
|
||||
if (frame_counter >= FRAMES_MAX) {
|
||||
return 0;
|
||||
}
|
||||
/* When errors occur during the unwinding, we reach this point.
|
||||
* If an error string is set for the particular error, send an
|
||||
* "error" record to capture at least a partial backtrace if
|
||||
@@ -463,7 +476,6 @@ static bool is_banned_path(char *fullpath)
|
||||
return false;
|
||||
}
|
||||
|
||||
static char *config_file = NULL;
|
||||
static char *core_file = NULL;
|
||||
static char *proc_path = NULL;
|
||||
static long int signal_num = -1;
|
||||
@@ -490,7 +502,7 @@ static void print_help(void)
|
||||
printf(" -h, --help Show help options\n");
|
||||
printf("\n");
|
||||
printf("Application Options:\n");
|
||||
printf(" -f, --config-file Path to configuration file (not implemented yet)\n");
|
||||
printf(" -f, --config_file Specify a configuration file other than default\n");
|
||||
printf(" -c, --core-file Path to core file to process\n");
|
||||
printf(" -p, --process-name Name of process for crash report (required)\n");
|
||||
printf(" -E, --process-path Absolute path of crashed process, with ! or / delimiters\n");
|
||||
@@ -532,7 +544,11 @@ int main(int argc, char **argv)
|
||||
printf(PACKAGE_VERSION "\n");
|
||||
goto success;
|
||||
case 'f':
|
||||
config_file = strdup(optarg);
|
||||
if (tm_set_config_file(optarg) != 0) {
|
||||
telem_log(LOG_ERR, "Configuration file"
|
||||
" path not valid\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
break;
|
||||
case 'c':
|
||||
core_file = strdup(optarg);
|
||||
@@ -606,8 +622,6 @@ int main(int argc, char **argv)
|
||||
|
||||
backtrace = nc_string_dup("Crash from Clear package build\n");
|
||||
|
||||
keep_core = true;
|
||||
|
||||
if (!send_data(&backtrace, unknown_severity, clr_build_class)) {
|
||||
goto fail;
|
||||
}
|
||||
@@ -619,8 +633,6 @@ int main(int argc, char **argv)
|
||||
|
||||
backtrace = nc_string_dup("Crash from third party\n");
|
||||
|
||||
keep_core = true;
|
||||
|
||||
if (!send_data(&backtrace, unknown_severity, unknown_class)) {
|
||||
goto fail;
|
||||
}
|
||||
@@ -658,6 +670,11 @@ int main(int argc, char **argv)
|
||||
}
|
||||
}
|
||||
|
||||
if (frame_counter >= FRAMES_MAX) {
|
||||
telem_log(LOG_ERR, "Too many frames. Backtrace truncated.\n");
|
||||
nc_string_append_printf(header, "Too many frames. Backtrace truncated.\n");
|
||||
}
|
||||
|
||||
nc_string_prepend(backtrace, header->str);
|
||||
|
||||
if (!send_data(&backtrace, default_severity, clr_class)) {
|
||||
@@ -673,11 +690,6 @@ success:
|
||||
|
||||
ret = EXIT_SUCCESS;
|
||||
fail:
|
||||
// Do not remove the core file if any errors occur
|
||||
if (ret == EXIT_FAILURE) {
|
||||
keep_core = true;
|
||||
}
|
||||
|
||||
free(core_file);
|
||||
free(proc_name);
|
||||
free(proc_path);
|
||||
@@ -707,8 +719,8 @@ fail:
|
||||
}
|
||||
|
||||
// Remove the core file by default, except when the --core-file option
|
||||
// is specified, or when keep_core is overridden to true.
|
||||
if (!core_file && !keep_core) {
|
||||
// is specified.
|
||||
if (!core_file) {
|
||||
unlink(temp_core);
|
||||
}
|
||||
|
||||
|
||||
+131
-33
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* This program is part of the Clear Linux Project
|
||||
*
|
||||
* Copyright 2015 Intel Corporation
|
||||
* Copyright 2015-2019 Intel Corporation
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under
|
||||
* the terms and conditions of the GNU Lesser General Public License, as
|
||||
@@ -20,63 +20,156 @@
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include <getopt.h>
|
||||
#include <locale.h>
|
||||
#include <sys/sysinfo.h>
|
||||
#include <dirent.h>
|
||||
#include "common.h"
|
||||
#include "telemetry.h"
|
||||
|
||||
#include "config.h"
|
||||
#include "log.h"
|
||||
|
||||
void print_usage(char *prog)
|
||||
#define PAYLOAD_LOCALE 0x01
|
||||
#define PAYLOAD_UPTIME 0x02
|
||||
#define PAYLOAD_BUNDLES 0x04
|
||||
|
||||
static void print_usage(char *prog)
|
||||
{
|
||||
printf("%s: Usage\n", prog);
|
||||
printf(" -f, --config_file Configuration file. This overides the other parameters\n");
|
||||
printf(" -H, --heartbeat Create a \"heartbeat\" record instead\n");
|
||||
printf(" -h, --help Display this help message\n");
|
||||
printf(" -l, --locale Include locale in the record\n");
|
||||
printf(" -u, --uptime Include uptime in the record\n");
|
||||
printf(" -b, --bundles Include installed bundles in the record\n");
|
||||
printf(" -V, --version Print the program version\n");
|
||||
}
|
||||
|
||||
static long get_uptime(void)
|
||||
{
|
||||
struct sysinfo s_info;
|
||||
if (sysinfo(&s_info) == 0) {
|
||||
return s_info.uptime;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int nodots(const struct dirent *dp)
|
||||
{
|
||||
return (dp->d_name[0] != '.');
|
||||
}
|
||||
|
||||
static char *create_payload(unsigned options)
|
||||
{
|
||||
int n, buflen;
|
||||
char *ppos, *payload;
|
||||
|
||||
payload = calloc(sizeof(char), MAX_PAYLOAD_LENGTH);
|
||||
if (payload == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ppos = payload;
|
||||
buflen = MAX_PAYLOAD_LENGTH;
|
||||
|
||||
n = snprintf(ppos, (size_t)buflen, "hello\n");
|
||||
buflen -= n, ppos += n;
|
||||
|
||||
if (options & PAYLOAD_LOCALE) {
|
||||
n = snprintf(ppos, (size_t)buflen, "LC_ALL: %s\n", setlocale(LC_ALL, NULL));
|
||||
buflen -= n, ppos += n;
|
||||
}
|
||||
|
||||
if (options & PAYLOAD_UPTIME) {
|
||||
n = snprintf(ppos, (size_t)buflen, "uptime: %ld\n", get_uptime());
|
||||
buflen -= n, ppos += n;
|
||||
}
|
||||
|
||||
if (options & PAYLOAD_BUNDLES) {
|
||||
int num_bundles, i;
|
||||
struct dirent **entries;
|
||||
|
||||
num_bundles = scandir("/usr/share/clear/bundles", &entries, nodots, alphasort);
|
||||
if (num_bundles < 0) {
|
||||
telem_perror("scandir failed");
|
||||
free(payload);
|
||||
return NULL;
|
||||
}
|
||||
n = snprintf(ppos, (size_t)buflen, "\nBundles (%d):\n", num_bundles);
|
||||
buflen -= n, ppos += n;
|
||||
|
||||
for (i = 0; i < num_bundles; i++) {
|
||||
n = snprintf(ppos, (size_t)buflen, "%s\n", entries[i]->d_name);
|
||||
/* Test if truncated output */
|
||||
if (n >= buflen) {
|
||||
int lastix = MAX_PAYLOAD_LENGTH-1;
|
||||
payload[lastix] = '\0';
|
||||
payload[lastix-1] = '.';
|
||||
payload[lastix-2] = '.';
|
||||
payload[lastix-3] = '.';
|
||||
payload[lastix-4] = '\n';
|
||||
break;
|
||||
}
|
||||
buflen -= n, ppos += n;
|
||||
}
|
||||
|
||||
for (i= 0; i < num_bundles; i++) {
|
||||
free(entries[i]);
|
||||
}
|
||||
|
||||
free(entries);
|
||||
}
|
||||
|
||||
return payload;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
uint32_t severity = 1;
|
||||
uint32_t payload_version = 1;
|
||||
char classification[30] = "org.clearlinux/hello/world";
|
||||
struct telem_ref *tm_handle = NULL;
|
||||
char *payload2;
|
||||
char *payload;
|
||||
char *str;
|
||||
int ret;
|
||||
unsigned payload_options = 0;
|
||||
|
||||
// Following vars are for arg parsing.
|
||||
int c;
|
||||
char *cfile = NULL;
|
||||
int opt_index = 0;
|
||||
int ret = 0;
|
||||
|
||||
struct option opts[] = {
|
||||
{ "config_file", 1, NULL, 'f' },
|
||||
{ "heartbeat", 0, NULL, 'H' },
|
||||
{ "help", 0, NULL, 'h' },
|
||||
{ "version", 0, NULL, 'V' },
|
||||
{ "locale", 0, NULL, 'l' },
|
||||
{ "uptime", 0, NULL, 'u' },
|
||||
{ "bundles", 0, NULL, 'b' },
|
||||
{ NULL, 0, NULL, 0 }
|
||||
};
|
||||
|
||||
while ((c = getopt_long(argc, argv, "f:hHV", opts, &opt_index)) != -1) {
|
||||
while ((c = getopt_long(argc, argv, "f:hHVlub", opts, &opt_index)) != -1) {
|
||||
switch (c) {
|
||||
case 'f':
|
||||
if (asprintf(&cfile, "%s", (char *)optarg) < 0) {
|
||||
exit(EXIT_FAILURE);
|
||||
if (tm_set_config_file(optarg) != 0) {
|
||||
telem_log(LOG_ERR, "Configuration file"
|
||||
" path not valid\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
struct stat buf;
|
||||
ret = stat(cfile, &buf);
|
||||
|
||||
/* check if the file exists and is a regular file */
|
||||
if (ret == -1 || !S_ISREG(buf.st_mode)) {
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
tm_set_config_file(cfile);
|
||||
break;
|
||||
case 'H':
|
||||
str = "org.clearlinux/heartbeat/ping";
|
||||
memcpy(classification, str, strlen(str));
|
||||
break;
|
||||
case 'l':
|
||||
payload_options |= PAYLOAD_LOCALE;
|
||||
break;
|
||||
case 'u':
|
||||
payload_options |= PAYLOAD_UPTIME;
|
||||
break;
|
||||
case 'b':
|
||||
payload_options |= PAYLOAD_BUNDLES;
|
||||
break;
|
||||
case 'h':
|
||||
print_usage(argv[0]);
|
||||
exit(EXIT_SUCCESS);
|
||||
@@ -88,34 +181,39 @@ int main(int argc, char **argv)
|
||||
}
|
||||
}
|
||||
|
||||
if (asprintf(&payload2, "hello\n") < 0) {
|
||||
setlocale(LC_ALL, "");
|
||||
payload = create_payload(payload_options);
|
||||
if (payload == NULL) {
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if ((ret = tm_create_record(&tm_handle, severity, classification,
|
||||
payload_version)) < 0) {
|
||||
printf("Failed to create record: %s\n", strerror(-ret));
|
||||
ret = 1;
|
||||
goto fail;
|
||||
telem_log(LOG_ERR, "Failed to create record: %s\n",
|
||||
strerror(-ret));
|
||||
ret = EXIT_FAILURE;
|
||||
goto done;
|
||||
}
|
||||
|
||||
if ((ret = tm_set_payload(tm_handle, payload2)) < 0) {
|
||||
printf("Failed to set record payload: %s\n", strerror(-ret));
|
||||
ret = 1;
|
||||
goto fail;
|
||||
if ((ret = tm_set_payload(tm_handle, payload)) < 0) {
|
||||
telem_log(LOG_ERR, "Failed to set record payload: %s\n",
|
||||
strerror(-ret));
|
||||
ret = EXIT_FAILURE;
|
||||
goto done;
|
||||
}
|
||||
|
||||
free(payload2);
|
||||
free(payload);
|
||||
|
||||
if ((ret = tm_send_record(tm_handle)) < 0) {
|
||||
printf("Failed to send record to daemon: %s\n", strerror(-ret));
|
||||
ret = 1;
|
||||
goto fail;
|
||||
telem_log(LOG_ERR, "Failed to send record to daemon: %s\n",
|
||||
strerror(-ret));
|
||||
ret = EXIT_FAILURE;
|
||||
goto done;
|
||||
} else {
|
||||
printf("Successfully sent record to daemon.\n");
|
||||
ret = 0;
|
||||
ret = EXIT_SUCCESS;
|
||||
}
|
||||
fail:
|
||||
done:
|
||||
tm_free_record(tm_handle);
|
||||
tm_handle = NULL;
|
||||
|
||||
|
||||
+23
-16
@@ -265,7 +265,7 @@ static bool add_filters(sd_journal *journal)
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool process_journal(void)
|
||||
static bool process_journal(bool process_existing)
|
||||
{
|
||||
int r;
|
||||
|
||||
@@ -279,8 +279,14 @@ static bool process_journal(void)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!process_existing_entries(journal)) {
|
||||
return false;
|
||||
if (process_existing) {
|
||||
if (!process_existing_entries(journal)) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if ((sd_journal_seek_tail(journal) < 0) || (sd_journal_previous(journal) < 0)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
struct pollfd pfd;
|
||||
@@ -312,12 +318,11 @@ static bool process_journal(void)
|
||||
}
|
||||
}
|
||||
|
||||
static char *config_file = NULL;
|
||||
|
||||
static const struct option prog_opts[] = {
|
||||
{ "help", no_argument, 0, 'h' },
|
||||
{ "config-file", required_argument, 0, 'f' },
|
||||
{ "version", no_argument, 0, 'V' },
|
||||
{ "tail", no_argument, 0, 't' },
|
||||
{ 0, 0, 0, 0 }
|
||||
};
|
||||
|
||||
@@ -330,22 +335,19 @@ static void print_help(void)
|
||||
printf(" -h, --help Show help options\n");
|
||||
printf("\n");
|
||||
printf("Application Options:\n");
|
||||
printf(" -f, --config-file Path to configuration file (not implemented yet)\n");
|
||||
printf(" -f, --config_file Specify a configuration file other than default\n");
|
||||
printf(" -t, --tail Don't process entries already in the journal\n");
|
||||
printf(" -V, --version Print the program version\n");
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
static void free_strings(void)
|
||||
{
|
||||
free(config_file);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int ret = EXIT_FAILURE;
|
||||
int opt;
|
||||
bool process_existing = true;
|
||||
|
||||
while ((opt = getopt_long(argc, argv, "hf:V", prog_opts, NULL)) != -1) {
|
||||
while ((opt = getopt_long(argc, argv, "hf:Vt", prog_opts, NULL)) != -1) {
|
||||
switch (opt) {
|
||||
case 'h':
|
||||
print_help();
|
||||
@@ -354,20 +356,25 @@ int main(int argc, char **argv)
|
||||
printf(PACKAGE_VERSION "\n");
|
||||
goto success;
|
||||
case 'f':
|
||||
config_file = strdup(optarg);
|
||||
if (tm_set_config_file(optarg) != 0) {
|
||||
telem_log(LOG_ERR, "Configuration file"
|
||||
" path not valid\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
break;
|
||||
case 't':
|
||||
process_existing = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!process_journal()) {
|
||||
if (!process_journal(process_existing)) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
success:
|
||||
ret = EXIT_SUCCESS;
|
||||
fail:
|
||||
free_strings();
|
||||
|
||||
if (journal) {
|
||||
sd_journal_close(journal);
|
||||
}
|
||||
|
||||
+49
-40
@@ -1,9 +1,24 @@
|
||||
/*
|
||||
* This program is part of the Clear Linux Project
|
||||
*
|
||||
* Copyright © 2015-2019 Intel Corporation
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under
|
||||
* the terms and conditions of the GNU Lesser General Public License, as
|
||||
* published by the Free Software Foundation; either version 2.1 of the License,
|
||||
* or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT ANY
|
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
||||
* A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||
* details.
|
||||
*/
|
||||
|
||||
#define _GNU_SOURCE
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/klog.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <malloc.h>
|
||||
@@ -22,54 +37,48 @@ int main(void)
|
||||
int log_size = 0;
|
||||
char *bufp = NULL;
|
||||
size_t buflen = 0;
|
||||
int bytes = 0;
|
||||
|
||||
oops_parser_init(write_oops_to_file);
|
||||
oops_parser_init(klog_process_oops_msgs);
|
||||
|
||||
// Allocate space to write the oops file to
|
||||
if (allocate_filespace() < 0) {
|
||||
telem_log(LOG_ERR, "%s\n", strerror(errno));
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Signal Handling to close and unlink empty files
|
||||
if (signal (SIGINT, signal_handler) == SIG_ERR) {
|
||||
// Signal Handling to terminate the probe.
|
||||
if (signal (SIGINT, signal_handler_fail) == SIG_ERR) {
|
||||
telem_log(LOG_ERR, "Error handling interrupt signal\n");
|
||||
}
|
||||
if (signal (SIGTERM, signal_handler) == SIG_ERR) {
|
||||
if (signal (SIGTERM, signal_handler_success) == SIG_ERR) {
|
||||
telem_log(LOG_ERR, "Error handling terminating signal\n");
|
||||
}
|
||||
|
||||
while (1) {
|
||||
// Gets the size of the kernel ring buffer
|
||||
log_size = klogctl(SYSLOG_ACTION_SIZE_BUFFER, NULL, 0);
|
||||
if (log_size < 0) {
|
||||
telem_log(LOG_ERR, "Cannot read size of kernel ring buffer: %s\n", strerror(errno));
|
||||
return 1;
|
||||
}
|
||||
|
||||
buflen = (size_t)log_size;
|
||||
|
||||
if (buflen > MAX_BUF) {
|
||||
buflen = MAX_BUF;
|
||||
}
|
||||
|
||||
// Gets the contents of the kernel ring buffer
|
||||
bufp = (char *)calloc(buflen, sizeof(char));
|
||||
|
||||
malloc_trim(0);
|
||||
bytes = klogctl(SYSLOG_ACTION_READ, bufp, (int)buflen);
|
||||
if (bytes < 0) {
|
||||
telem_log(LOG_ERR, "Cannot read contents of kernel ring buffer: %s\n", strerror(errno));
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Splits the buffer into separate lines with /0 terminating
|
||||
split_buf_by_line(bufp, (size_t)bytes);
|
||||
|
||||
free(bufp);
|
||||
// Gets the size of the kernel ring buffer
|
||||
log_size = klogctl(SYSLOG_ACTION_SIZE_BUFFER, NULL, 0);
|
||||
if (log_size < 0) {
|
||||
telem_perror("Cannot read size of kernel ring buffer");
|
||||
return 1;
|
||||
}
|
||||
|
||||
buflen = (size_t)log_size;
|
||||
if (buflen > MAX_BUF) {
|
||||
buflen = MAX_BUF;
|
||||
}
|
||||
|
||||
// Gets the contents of the kernel ring buffer
|
||||
bufp = (char *)malloc(buflen);
|
||||
|
||||
while (1) {
|
||||
int bytes_read;
|
||||
|
||||
malloc_trim(0);
|
||||
memset(bufp, 0, buflen);
|
||||
bytes_read = klogctl(SYSLOG_ACTION_READ, bufp, (int)buflen);
|
||||
if (bytes_read < 0) {
|
||||
telem_perror("Cannot read contents of kernel ring buffer");
|
||||
return 1;
|
||||
}
|
||||
|
||||
klog_process_buffer(bufp, (size_t)bytes_read);
|
||||
}
|
||||
|
||||
// Not reached
|
||||
free(bufp);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
+92
-69
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* This program is part of the Clear Linux Project
|
||||
*
|
||||
* Copyright 2015 Intel Corporation
|
||||
* Copyright © 2015-2019 Intel Corporation
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under
|
||||
* the terms and conditions of the GNU Lesser General Public License, as
|
||||
@@ -15,11 +15,10 @@
|
||||
*/
|
||||
|
||||
#define _GNU_SOURCE
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/klog.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/stat.h>
|
||||
@@ -27,20 +26,54 @@
|
||||
#include "log.h"
|
||||
#include "oops_parser.h"
|
||||
#include "klog_scanner.h"
|
||||
#include "telemetry.h"
|
||||
#include "nica/nc-string.h"
|
||||
|
||||
#define MAX_OOPS_MSG_LENGTH 1024
|
||||
#define FILE_PATH KERNELOOPSDIR "/kerneloopsXXXXXX"
|
||||
static bool oops_processed = false;
|
||||
|
||||
static int fd;
|
||||
char filename[] = FILE_PATH;
|
||||
int last_line_length;
|
||||
static uint32_t version = 1;
|
||||
|
||||
static bool send_data(char *backtrace, char *class, uint32_t severity)
|
||||
{
|
||||
struct telem_ref *handle = NULL;
|
||||
int ret;
|
||||
|
||||
if ((ret = tm_create_record(&handle, severity, class, version)) < 0) {
|
||||
telem_log(LOG_ERR, "Failed to create record: %s",
|
||||
strerror(-ret));
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((ret = tm_set_payload(handle, backtrace)) < 0) {
|
||||
telem_log(LOG_ERR, "Failed to set payload: %s", strerror(-ret));
|
||||
tm_free_record(handle);
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((ret = tm_send_record(handle)) < 0) {
|
||||
telem_log(LOG_ERR, "Failed to send record: %s", strerror(-ret));
|
||||
tm_free_record(handle);
|
||||
return false;
|
||||
}
|
||||
|
||||
tm_free_record(handle);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int klog_process_buffer(char *bufp, int bytes)
|
||||
{
|
||||
// Splits the buffer into separate lines with /0 terminating
|
||||
split_buf_by_line(bufp, (size_t)bytes);
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool oops_written = false;
|
||||
void split_buf_by_line(char *bufp, int bytes)
|
||||
{
|
||||
char *start;
|
||||
char *eol;
|
||||
size_t linelength = 0;
|
||||
oops_processed = false;
|
||||
|
||||
while (bytes > 0) {
|
||||
eol = memchr(bufp, '\n', (size_t)bytes);
|
||||
@@ -57,87 +90,77 @@ void split_buf_by_line(char *bufp, int bytes)
|
||||
if (bytes >= 0) {
|
||||
start[linelength] = '\0';
|
||||
parse_single_line(start, linelength);
|
||||
if (oops_processed == true) {
|
||||
telem_debug("oops_processed detected !\n");
|
||||
break;
|
||||
}
|
||||
linelength = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int allocate_filespace()
|
||||
void klog_process_oops_msgs(struct oops_log_msg *msg)
|
||||
{
|
||||
int allocate_disk = 0;
|
||||
strcpy(filename, FILE_PATH);
|
||||
|
||||
fd = mkstemp(filename);
|
||||
if (fchmod(fd, 0644) == -1) {
|
||||
telem_log(LOG_ERR, "Error while changing permissions for file %s: %s\n",
|
||||
filename, strerror(errno));
|
||||
}
|
||||
|
||||
if (fd == -1) {
|
||||
telem_log(LOG_ERR, "fd error: %s\n", strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Allocates disk space to write kernel oops to
|
||||
allocate_disk = fallocate(fd, 0, 0, MAX_OOPS_MSG_LENGTH);
|
||||
if (allocate_disk != 0) {
|
||||
telem_log(LOG_ERR, "Error allocating disk space: %s\n", strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void write_oops_to_file(struct oops_log_msg *msg)
|
||||
{
|
||||
ssize_t writer;
|
||||
size_t linelength;
|
||||
size_t linelength, size;
|
||||
char *line;
|
||||
char *contents = NULL;
|
||||
nc_string *payload;
|
||||
|
||||
// pass 1: calculate buffer size
|
||||
size = 0;
|
||||
for (int i = 0; i < msg->length; i++) {
|
||||
size += strlen(msg->lines[i]) + 1;
|
||||
}
|
||||
|
||||
contents = malloc(size);
|
||||
if (!contents) {
|
||||
telem_log(LOG_ERR, "Call to malloc failed");
|
||||
oops_processed = true;
|
||||
return;
|
||||
}
|
||||
|
||||
// pass 2: copy strings into the buffer
|
||||
size_t done = 0;
|
||||
char *bp = contents;
|
||||
for (int i = 0; i < msg->length; i++) {
|
||||
//Add the newline character to the end of each line
|
||||
line = msg->lines[i];
|
||||
linelength = strlen(line);
|
||||
line[linelength] = '\n';
|
||||
linelength++;
|
||||
// Copy the line (without the terminating NULL)
|
||||
memcpy(bp, line, linelength);
|
||||
bp[linelength] = '\n';
|
||||
done += linelength + 1;
|
||||
bp = contents + done;
|
||||
}
|
||||
|
||||
// Write each line of oops to file
|
||||
writer = write(fd, line, linelength);
|
||||
if (writer == -1) {
|
||||
telem_log(LOG_ERR, "Error writing buffer to file: %s\n", strerror(errno));
|
||||
exit(EXIT_FAILURE);
|
||||
struct oops_log_msg oops_msg;
|
||||
if (handle_entire_oops(contents, (long)size, &oops_msg)) {
|
||||
#ifdef DEBUG
|
||||
telem_debug("DEBUG: Raw oops message:\n");
|
||||
for (int i = 0; i < oops_msg.length; i++) {
|
||||
telem_log(LOG_DEBUG, "%s\n", oops_msg.lines[i]);
|
||||
}
|
||||
#endif
|
||||
payload = parse_payload(&oops_msg);
|
||||
telem_debug("DEBUG: Payload Parsed :%s\n", payload->str);
|
||||
oops_msg_cleanup(&oops_msg);
|
||||
send_data(payload->str, (char *)oops_msg.pattern->classification, (uint32_t)oops_msg.pattern->severity);
|
||||
nc_string_free(payload);
|
||||
} else {
|
||||
/* File does no contain an oops! */
|
||||
telem_log(LOG_ERR, "Did not find an oops in the oops directory\n");
|
||||
}
|
||||
|
||||
telem_log(LOG_INFO, "Oops written to file\n");
|
||||
oops_written = true;
|
||||
close(fd);
|
||||
|
||||
// Allocate more space to prepare for another oops
|
||||
if (allocate_filespace() < 0) {
|
||||
telem_log(LOG_ERR, "%s\n", strerror(errno));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
free(contents);
|
||||
oops_processed = true;
|
||||
}
|
||||
|
||||
bool get_oops_written(void)
|
||||
void signal_handler_success(int signum)
|
||||
{
|
||||
return oops_written;
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
char *get_file_name(void)
|
||||
{
|
||||
return filename;
|
||||
}
|
||||
|
||||
__attribute__((destructor))
|
||||
void clean_up(void)
|
||||
{
|
||||
// Unlink empty file and close any open file
|
||||
unlink(filename);
|
||||
close(fd);
|
||||
}
|
||||
|
||||
void signal_handler(int signum)
|
||||
void signal_handler_fail(int signum)
|
||||
{
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
+17
-21
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* This program is part of the Clear Linux Project
|
||||
*
|
||||
* Copyright 2015 Intel Corporation
|
||||
* Copyright © 2015-2019 Intel Corporation
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under
|
||||
* the terms and conditions of the GNU Lesser General Public License, as
|
||||
@@ -17,45 +17,41 @@
|
||||
#pragma once
|
||||
#include "oops_parser.h"
|
||||
|
||||
/**
|
||||
* Process the buffer and send it to the backend
|
||||
*
|
||||
* @param *bufp A pointer to a buffer containing the bytes read
|
||||
* from the kernel ring buffer
|
||||
* @param bytes Number of bytes read from ring buffer into bufp
|
||||
*
|
||||
* @return 0 on succes, -1 on failure
|
||||
*
|
||||
*/
|
||||
int klog_process_buffer(char *bufp, int bytes);
|
||||
/**
|
||||
* Splits the buffer into individual lines
|
||||
*
|
||||
* @param *bufp A pointer to a buffer containing the bytes read
|
||||
* from the kernel ring buffer
|
||||
* @param bytes Bytes read from ring buffer into bufp
|
||||
* @param bytes Number of bytes read from ring buffer into bufp
|
||||
*
|
||||
*/
|
||||
void split_buf_by_line(char *bufp, int bytes);
|
||||
|
||||
/**
|
||||
* Allocates memory for oops message to write to file
|
||||
*
|
||||
* @return 0 on succes, -1 on failure
|
||||
*/
|
||||
int allocate_filespace(void);
|
||||
|
||||
/**
|
||||
* Writes the oops message to tmp file
|
||||
* Process the oops message and send it to the backend
|
||||
*
|
||||
* @param msg Struct that contains oops message lines and linecount
|
||||
*
|
||||
*/
|
||||
void write_oops_to_file(struct oops_log_msg *msg);
|
||||
|
||||
void klog_process_oops_msgs(struct oops_log_msg *msg);
|
||||
/**
|
||||
* Signal handler for cleanup purposes
|
||||
*
|
||||
* @param signum An integer for the signal type
|
||||
*
|
||||
*/
|
||||
void signal_handler(int signum);
|
||||
|
||||
/**
|
||||
* For Unit Tests Purposes
|
||||
* Determines whether an oops has been written to a file
|
||||
*
|
||||
* @return true if oops is written, false if not
|
||||
*/
|
||||
bool get_oops_written(void);
|
||||
void signal_handler_fail(int signum);
|
||||
void signal_handler_success(int signum);
|
||||
|
||||
/* vi: set ts=8 sw=8 sts=4 et tw=80 cino=(0: */
|
||||
|
||||
+43
-27
@@ -4,23 +4,53 @@ bin_PROGRAMS += \
|
||||
%D%/telem-record-gen \
|
||||
%D%/klogscanner \
|
||||
%D%/pstoreprobe \
|
||||
%D%/oopsprobe \
|
||||
%D%/pythonprobe \
|
||||
%D%/pstoreclean \
|
||||
%D%/bertprobe
|
||||
|
||||
%C%_pythonprobe_SOURCES = %D%/python-probe.c
|
||||
%C%_pythonprobe_CFLAGS = $(AM_CFLAGS)
|
||||
%C%_pythonprobe_LDADD = $(top_builddir)/src/libtelemetry.la
|
||||
%C%_pythonprobe_LDFLAGS = \
|
||||
$(AM_LDFLAGS) \
|
||||
-pie
|
||||
|
||||
if LOG_SYSTEMD
|
||||
if HAVE_SYSTEMD_JOURNAL
|
||||
%C%_pythonprobe_CFLAGS += $(SYSTEMD_JOURNAL_CFLAGS)
|
||||
%C%_pythonprobe_LDADD += $(SYSTEMD_JOURNAL_LIBS)
|
||||
endif
|
||||
endif
|
||||
|
||||
%C%_hprobe_SOURCES = %D%/hello.c
|
||||
%C%_hprobe_LDADD = $(top_builddir)/src/libtelemetry.la
|
||||
%C%_hprobe_CFLAGS = $(AM_CFLAGS)
|
||||
%C%_hprobe_LDFLAGS = \
|
||||
$(AM_LDFLAGS) \
|
||||
-pie
|
||||
|
||||
if LOG_SYSTEMD
|
||||
if HAVE_SYSTEMD_JOURNAL
|
||||
%C%_hprobe_CFLAGS += $(SYSTEMD_JOURNAL_CFLAGS)
|
||||
%C%_hprobe_LDADD += $(SYSTEMD_JOURNAL_LIBS)
|
||||
endif
|
||||
endif
|
||||
|
||||
%C%_bertprobe_SOURCES = %D%/bert_probe.c \
|
||||
src/nica/b64enc.c
|
||||
%C%_bertprobe_CFLAGS = $(AM_CFLAGS)
|
||||
%C%_bertprobe_LDADD = $(top_builddir)/src/libtelemetry.la
|
||||
%C%_bertprobe_LDFLAGS = \
|
||||
$(AM_LDFLAGS) \
|
||||
-pie
|
||||
|
||||
if LOG_SYSTEMD
|
||||
if HAVE_SYSTEMD_JOURNAL
|
||||
%C%_bertprobe_CFLAGS += $(SYSTEMD_JOURNAL_CFLAGS)
|
||||
%C%_bertprobe_LDADD += $(SYSTEMD_JOURNAL_LIBS)
|
||||
endif
|
||||
endif
|
||||
|
||||
%C%_telem_record_gen_SOURCES = %D%/telem_record_gen.c
|
||||
%C%_telem_record_gen_CFLAGS = \
|
||||
$(AM_CFLAGS)
|
||||
@@ -29,6 +59,14 @@ bin_PROGRAMS += \
|
||||
$(AM_LDFLAGS) \
|
||||
-pie
|
||||
|
||||
if LOG_SYSTEMD
|
||||
if HAVE_SYSTEMD_JOURNAL
|
||||
%C%_telem_record_gen_CFLAGS += $(SYSTEMD_JOURNAL_CFLAGS)
|
||||
%C%_telem_record_gen_LDADD += $(SYSTEMD_JOURNAL_LIBS)
|
||||
endif
|
||||
endif
|
||||
|
||||
|
||||
%C%_pstoreclean_SOURCES = %D%/pstore_clean.c
|
||||
%C%_pstoreclean_CFLAGS = \
|
||||
$(AM_CFLAGS)
|
||||
@@ -107,13 +145,6 @@ endif
|
||||
-pie
|
||||
|
||||
if LOG_SYSTEMD
|
||||
if HAVE_SYSTEMD_JOURNAL
|
||||
%C%_klogscanner_CFLAGS += \
|
||||
$(SYSTEMD_JOURNAL_CFLAGS)
|
||||
%C%_klogscanner_LDADD += \
|
||||
$(SYSTEMD_JOURNAL_LIBS)
|
||||
endif
|
||||
|
||||
if HAVE_SYSTEMD_JOURNAL
|
||||
%C%_klogscanner_CFLAGS += \
|
||||
$(SYSTEMD_JOURNAL_CFLAGS)
|
||||
@@ -122,25 +153,6 @@ if HAVE_SYSTEMD_JOURNAL
|
||||
endif
|
||||
endif
|
||||
|
||||
%C%_oopsprobe_SOURCES = \
|
||||
%D%/oops_probe.c \
|
||||
%D%/oops_parser.c \
|
||||
src/nica/nc-string.c \
|
||||
%D%/probe.h
|
||||
%C%_oopsprobe_CFLAGS = \
|
||||
$(AM_CFLAGS)
|
||||
%C%_oopsprobe_LDADD = \
|
||||
$(top_builddir)/src/libtelemetry.la \
|
||||
$(top_builddir)/src/libtelem-shared.la
|
||||
|
||||
if LOG_SYSTEMD
|
||||
if HAVE_SYSTEMD_JOURNAL
|
||||
%C%_oopsprobe_CFLAGS += \
|
||||
$(SYSTEMD_JOURNAL_CFLAGS)
|
||||
%C%_oopsprobe_LDADD += \
|
||||
$(SYSTEMD_JOURNAL_LIBS)
|
||||
endif
|
||||
endif
|
||||
|
||||
if HAVE_SYSTEMD_JOURNAL
|
||||
if HAVE_SYSTEMD_ID128
|
||||
@@ -162,6 +174,10 @@ bin_PROGRAMS += \
|
||||
%C%_journalprobe_LDFLAGS = \
|
||||
$(AM_LDFLAGS) \
|
||||
-pie
|
||||
if LOG_SYSTEMD
|
||||
%C%_journalprobe_CFLAGS += $(SYSTEMD_JOURNAL_CFLAGS)
|
||||
%C%_journalprobe_LDADD += $(SYSTEMD_JOURNAL_LIBS)
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
||||
|
||||
+18
-21
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* This program is part of the Clear Linux Project
|
||||
*
|
||||
* Copyright 2015 Intel Corporation
|
||||
* Copyright 2015-2019 Intel Corporation
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under
|
||||
* the terms and conditions of the GNU Lesser General Public License, as
|
||||
@@ -152,9 +152,9 @@ struct oops_pattern oops_patterns_arr[] = {
|
||||
},
|
||||
};
|
||||
|
||||
int oops_patterns_cnt = sizeof(oops_patterns_arr) / sizeof(struct oops_pattern);
|
||||
static int oops_patterns_cnt = sizeof(oops_patterns_arr) / sizeof(struct oops_pattern);
|
||||
|
||||
char *skip_log_level(char *line)
|
||||
static char *skip_log_level(char *line)
|
||||
{
|
||||
char *start = line;
|
||||
|
||||
@@ -169,7 +169,7 @@ char *skip_log_level(char *line)
|
||||
return start;
|
||||
}
|
||||
|
||||
char *skip_timestamp(char *line)
|
||||
static char *skip_timestamp(char *line)
|
||||
{
|
||||
char *start = line;
|
||||
|
||||
@@ -184,7 +184,7 @@ char *skip_timestamp(char *line)
|
||||
return start;
|
||||
}
|
||||
|
||||
char *skip_space(char *line)
|
||||
static char *skip_space(char *line)
|
||||
{
|
||||
char *start = line;
|
||||
|
||||
@@ -194,7 +194,7 @@ char *skip_space(char *line)
|
||||
return start;
|
||||
}
|
||||
|
||||
char *skip_spaces(char *line)
|
||||
static char *skip_spaces(char *line)
|
||||
{
|
||||
char *start = line;
|
||||
|
||||
@@ -204,7 +204,7 @@ char *skip_spaces(char *line)
|
||||
return start;
|
||||
}
|
||||
|
||||
bool starts_with(const char *line, const char *line_end, const char *substr)
|
||||
static bool starts_with(const char *line, const char *line_end, const char *substr)
|
||||
{
|
||||
size_t substrlen = strlen(substr);
|
||||
|
||||
@@ -214,7 +214,7 @@ bool starts_with(const char *line, const char *line_end, const char *substr)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool str_starts_with_casei(const char *line, const char *substr)
|
||||
static bool str_starts_with_casei(const char *line, const char *substr)
|
||||
{
|
||||
size_t len = strlen(substr);
|
||||
|
||||
@@ -224,7 +224,7 @@ bool str_starts_with_casei(const char *line, const char *substr)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool pattern_matches(char *line, char *line_end, struct oops_pattern *pattern)
|
||||
static bool pattern_matches(char *line, char *line_end, struct oops_pattern *pattern)
|
||||
{
|
||||
if (pattern->is_regex) {
|
||||
return (regexec(&(pattern->regex), line, 0, NULL, 0) == 0);
|
||||
@@ -233,7 +233,7 @@ bool pattern_matches(char *line, char *line_end, struct oops_pattern *pattern)
|
||||
}
|
||||
}
|
||||
|
||||
void init_pattern_regex(void)
|
||||
static void init_pattern_regex(void)
|
||||
{
|
||||
for (int i = 0; i < oops_patterns_cnt; i++) {
|
||||
struct oops_pattern *pattern = &oops_patterns_arr[i];
|
||||
@@ -244,7 +244,7 @@ void init_pattern_regex(void)
|
||||
}
|
||||
}
|
||||
|
||||
void free_pattern_regex(void)
|
||||
static void free_pattern_regex(void)
|
||||
{
|
||||
for (int i = 0; i < oops_patterns_cnt; i++) {
|
||||
struct oops_pattern *pattern = &oops_patterns_arr[i];
|
||||
@@ -261,7 +261,6 @@ bool handle_entire_oops(char *buf, long size, struct oops_log_msg *msg)
|
||||
int i;
|
||||
|
||||
msg->length = 0;
|
||||
init_pattern_regex();
|
||||
|
||||
line_end = memchr(buf, '\n', (size_t)size);
|
||||
if (line_end == NULL) {
|
||||
@@ -318,7 +317,6 @@ void oops_msg_cleanup(struct oops_log_msg *msg)
|
||||
free(msg->lines[i]);
|
||||
}
|
||||
msg->length = 0;
|
||||
free_pattern_regex();
|
||||
}
|
||||
|
||||
static struct oops_log_msg oops_msg;
|
||||
@@ -333,7 +331,7 @@ void oops_parser_init(oops_handler_t handler)
|
||||
init_pattern_regex();
|
||||
}
|
||||
|
||||
void handle_msg_end(void)
|
||||
static void handle_msg_end(void)
|
||||
{
|
||||
for (int i = 0; i < oops_msg.length; i++) {
|
||||
free(oops_msg.lines[i]);
|
||||
@@ -426,7 +424,6 @@ void parse_single_line(char *line, size_t size)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
struct stack_frame {
|
||||
@@ -437,7 +434,7 @@ struct stack_frame {
|
||||
struct stack_frame *next;
|
||||
};
|
||||
|
||||
void stack_frame_append(struct stack_frame **head, struct stack_frame **tail, char *start)
|
||||
static void stack_frame_append(struct stack_frame **head, struct stack_frame **tail, char *start)
|
||||
{
|
||||
/*
|
||||
* Format is:
|
||||
@@ -536,7 +533,7 @@ void stack_frame_append(struct stack_frame **head, struct stack_frame **tail, ch
|
||||
frame->module = "kernel";
|
||||
}
|
||||
|
||||
void stack_frame_free(struct stack_frame **head)
|
||||
static void stack_frame_free(struct stack_frame **head)
|
||||
{
|
||||
struct stack_frame *frame;
|
||||
|
||||
@@ -553,7 +550,7 @@ void stack_frame_free(struct stack_frame **head)
|
||||
* CPU: 2 PID: 0 Comm: swapper/2 Not tainted 3.10.4-100.fc18.x86_64 #1
|
||||
* CPU: 3 PID: 0 Comm: swapper/3 Not tainted 4.0.5-300.fc22.x86_64 #1
|
||||
*/
|
||||
void parse_kernel_cpu_line(char *line, char **kernel_version, char **tainted)
|
||||
static void parse_kernel_cpu_line(char *line, char **kernel_version, char **tainted)
|
||||
{
|
||||
char *end = NULL;
|
||||
|
||||
@@ -626,7 +623,7 @@ static struct reg_s *reg_head = NULL;
|
||||
*
|
||||
*/
|
||||
|
||||
void parse_registers(char *line)
|
||||
static void parse_registers(char *line)
|
||||
{
|
||||
uint64_t value;
|
||||
struct reg_s *reg_entry = NULL;
|
||||
@@ -739,7 +736,7 @@ void parse_registers(char *line)
|
||||
|
||||
}
|
||||
|
||||
void append_registers_to_bt(nc_string **backtrace)
|
||||
static void append_registers_to_bt(nc_string **backtrace)
|
||||
{
|
||||
struct reg_s *reg_entry = reg_head;
|
||||
|
||||
@@ -762,7 +759,7 @@ void append_registers_to_bt(nc_string **backtrace)
|
||||
}
|
||||
}
|
||||
|
||||
nc_string *parse_backtrace(struct oops_log_msg *msg)
|
||||
static nc_string *parse_backtrace(struct oops_log_msg *msg)
|
||||
{
|
||||
struct stack_frame *head = NULL, *tail = NULL, *elem = NULL;
|
||||
//int in_stack_dump = 0;
|
||||
|
||||
@@ -1,229 +0,0 @@
|
||||
/*
|
||||
* This program is part of the Clear Linux Project
|
||||
*
|
||||
* Copyright 2015 Intel Corporation
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under
|
||||
* the terms and conditions of the GNU Lesser General Public License, as
|
||||
* published by the Free Software Foundation; either version 2.1 of the License,
|
||||
* or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT ANY
|
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
||||
* A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||
* details.
|
||||
*/
|
||||
|
||||
#define _GNU_SOURCE
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <sys/inotify.h>
|
||||
#include <poll.h>
|
||||
|
||||
#include "oops_parser.h"
|
||||
#include "log.h"
|
||||
#include "telemetry.h"
|
||||
|
||||
#include "nica/nc-string.h"
|
||||
|
||||
char *oops_dir_path = KERNELOOPSDIR;
|
||||
|
||||
static uint32_t version = 1;
|
||||
|
||||
static bool send_data(char *backtrace, char *class, uint32_t severity)
|
||||
{
|
||||
struct telem_ref *handle = NULL;
|
||||
int ret;
|
||||
|
||||
if ((ret = tm_create_record(&handle, severity, class, version)) < 0) {
|
||||
telem_log(LOG_ERR, "Failed to create record: %s",
|
||||
strerror(-ret));
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((ret = tm_set_payload(handle, backtrace)) < 0) {
|
||||
telem_log(LOG_ERR, "Failed to set payload: %s", strerror(-ret));
|
||||
tm_free_record(handle);
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((ret = tm_send_record(handle)) < 0) {
|
||||
telem_log(LOG_ERR, "Failed to send record: %s", strerror(-ret));
|
||||
tm_free_record(handle);
|
||||
return false;
|
||||
}
|
||||
|
||||
tm_free_record(handle);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void handle_oops_file(const char *fname)
|
||||
{
|
||||
int ret;
|
||||
FILE *fp = NULL;
|
||||
char *filename = NULL, *contents = NULL;
|
||||
long sz;
|
||||
size_t size, bytes_read;
|
||||
nc_string *payload;
|
||||
|
||||
ret = asprintf(&filename, "%s/%s", oops_dir_path, fname);
|
||||
if (ret == -1) {
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("File to be handled: %s\n", filename);
|
||||
#endif
|
||||
|
||||
fp = fopen(filename, "r");
|
||||
if (fp == NULL) {
|
||||
telem_log(LOG_ERR, "Failed to open oops log file %s: %s", fname, strerror(errno));
|
||||
goto file_end;
|
||||
}
|
||||
|
||||
if (fseek(fp, 0, SEEK_END) == -1) {
|
||||
telem_log(LOG_ERR, "Failed to seek file %s: %s\n", fname, strerror(errno));
|
||||
goto file_end;
|
||||
}
|
||||
|
||||
sz = ftell(fp);
|
||||
if (sz == -1L) {
|
||||
telem_perror("ftell failed");
|
||||
goto file_end;
|
||||
}
|
||||
|
||||
/* If file is empty */
|
||||
if (sz == 0L) {
|
||||
telem_perror("File is empty\n");
|
||||
goto file_end;
|
||||
}
|
||||
|
||||
if (fseek(fp, 0, SEEK_SET) < 0) {
|
||||
telem_log(LOG_ERR, "Fseek failed for file %s:%s\n", fname, strerror(errno));
|
||||
goto file_end;
|
||||
}
|
||||
|
||||
size = (size_t)sz;
|
||||
contents = malloc(size);
|
||||
if (!contents) {
|
||||
telem_log(LOG_ERR, "Call to malloc failed");
|
||||
goto file_end;
|
||||
}
|
||||
memset(contents, 0, size);
|
||||
|
||||
bytes_read = fread(contents, sizeof(char), size, fp);
|
||||
|
||||
if (bytes_read < size) {
|
||||
telem_log(LOG_ERR, "Error while reading file %s:%s\n", fname, strerror(errno));
|
||||
goto file_end;
|
||||
}
|
||||
|
||||
struct oops_log_msg oops_msg;
|
||||
if (handle_entire_oops(contents, (long)size, &oops_msg)) {
|
||||
#ifdef DEBUG
|
||||
printf("Raw message:\n");
|
||||
for (int i = 0; i < oops_msg.length; i++) {
|
||||
printf("%s\n", oops_msg.lines[i]);
|
||||
}
|
||||
#endif
|
||||
|
||||
payload = parse_payload(&oops_msg);
|
||||
#ifdef DEBUG
|
||||
printf("Payload Parsed :%s\n", payload->str);
|
||||
#endif
|
||||
|
||||
oops_msg_cleanup(&oops_msg);
|
||||
send_data(payload->str, (char *)oops_msg.pattern->classification, (uint32_t)oops_msg.pattern->severity);
|
||||
nc_string_free(payload);
|
||||
} else {
|
||||
/* File does no contain an oops! */
|
||||
telem_log(LOG_ERR, "Did not find an oops in the oops directort\n");
|
||||
}
|
||||
file_end:
|
||||
if (contents) {
|
||||
free(contents);
|
||||
}
|
||||
if (fp) {
|
||||
fclose(fp);
|
||||
}
|
||||
if (unlink(filename) == -1) {
|
||||
telem_log(LOG_ERR, "Failed to unlink %s: %s\n", filename, strerror(errno));
|
||||
}
|
||||
free(filename);
|
||||
}
|
||||
|
||||
void handle_inotify_event(const struct inotify_event *event)
|
||||
{
|
||||
|
||||
if (!event) {
|
||||
telem_perror("Null event received");
|
||||
return;
|
||||
}
|
||||
|
||||
if (event->len == 0) {
|
||||
telem_perror("inotify event received with no file.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (event->mask & IN_CLOSE_WRITE) {
|
||||
if (event->mask & IN_ISDIR) {
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
telem_log(LOG_DEBUG, "New file written to the oops location: %s\n", event->name);
|
||||
#endif
|
||||
handle_oops_file(event->name);
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int inotify_fd;
|
||||
char buf[4096];
|
||||
char *ptr = NULL;
|
||||
ssize_t len;
|
||||
const struct inotify_event *event;
|
||||
|
||||
inotify_fd = inotify_init();
|
||||
if (inotify_fd == -1) {
|
||||
telem_log(LOG_ERR, "Failed to create inotify instance: %s\n", strerror(errno));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (inotify_add_watch(inotify_fd, oops_dir_path, IN_CLOSE_WRITE) == -1) {
|
||||
telem_perror("Error adding watch to the inotify instance");
|
||||
}
|
||||
|
||||
while (1) {
|
||||
len = read(inotify_fd, buf, sizeof buf);
|
||||
if (len <= 0) {
|
||||
telem_perror("error reading event");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (len < sizeof(struct inotify_event)) {
|
||||
telem_perror("Incomplete event received");
|
||||
continue;
|
||||
}
|
||||
|
||||
telem_log(LOG_INFO, "Got inotify event/s\n");
|
||||
|
||||
/* Loop over all events in the buffer */
|
||||
for (ptr = buf; ptr < buf + len;
|
||||
ptr += sizeof(struct inotify_event) + event->len) {
|
||||
|
||||
event = (const struct inotify_event *)ptr;
|
||||
/* handle the event */
|
||||
handle_inotify_event(event);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* vi: set ts=8 sw=8 sts=4 et tw=80 cino=(0: */
|
||||
@@ -132,7 +132,7 @@ int main(int argc, char **argv)
|
||||
if (mkdir(MOUNT, 0755) < 0) {
|
||||
//If there is an error other than an existing directory
|
||||
if (errno != EEXIST) {
|
||||
telem_log(LOG_ERR, "Error creating directory /dev/pstore : %s\n", strerror(errno));
|
||||
telem_perror("Error creating directory /dev/pstore");
|
||||
//bail out?
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
@@ -65,14 +65,12 @@ void handle_complete_oops_message(struct oops_log_msg *msg)
|
||||
|
||||
#ifdef DEBUG
|
||||
for (int i = 0; i < msg->length; i++) {
|
||||
printf("%s\n", msg->lines[i]);
|
||||
telem_debug("DEBUG: %s\n", msg->lines[i]);
|
||||
}
|
||||
#endif
|
||||
payload = parse_payload(msg);
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("Payload Parsed :%s\n", payload->str);
|
||||
#endif
|
||||
telem_debug("DEBUG: Payload Parsed :%s\n", payload->str);
|
||||
send_data(payload->str, (char *)msg->pattern->classification, (uint32_t)msg->pattern->severity);
|
||||
nc_string_free(payload);
|
||||
}
|
||||
@@ -232,9 +230,7 @@ int main(int argc, char **argv)
|
||||
// Look for only dmesg logs. Ignore other types of pstore dumps for now.
|
||||
if (sscanf(entry->d_name, "dmesg-efi-%" PRIu64, &id) == 1) {
|
||||
parse_id(id, &count, &part);
|
||||
#ifdef DEBUG
|
||||
printf("Extracted count :%d, part : %d\n", count, part);
|
||||
#endif
|
||||
telem_debug("DEBUG: Extracted count :%d, part : %d\n", count, part);
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
@@ -262,9 +258,7 @@ int main(int argc, char **argv)
|
||||
|
||||
nc_hashmap_iter_init(hash, &iter);
|
||||
while (nc_hashmap_iter_next(&iter, (void **)&key, (void **)&value)) {
|
||||
#ifdef DEBUG
|
||||
printf("Count in the hash: %d\n", NC_UNHASH_KEY(key));
|
||||
#endif
|
||||
telem_debug("DEBUG: Count in the hash: %d\n", NC_UNHASH_KEY(key));
|
||||
|
||||
head = (struct chunk_list *)value;
|
||||
elem = head;
|
||||
|
||||
@@ -0,0 +1,293 @@
|
||||
/*
|
||||
* This program is part of the Clear Linux Project
|
||||
*
|
||||
* Copyright 2019 Intel Corporation
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#define _GNU_SOURCE
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/inotify.h>
|
||||
#include <fcntl.h>
|
||||
#include <dirent.h>
|
||||
#include <pwd.h>
|
||||
#include <grp.h>
|
||||
#include <getopt.h>
|
||||
|
||||
#include "log.h"
|
||||
#include "telemetry.h"
|
||||
|
||||
#define PYTHON_TELEMETRY_DIR "/var/lib/telemetry/python"
|
||||
|
||||
/* We expect something like: 1.python-exception.3.N2Qy24 */
|
||||
static bool validate_file_name(const char *filename, uint32_t *severity,
|
||||
char** class, uint32_t *version)
|
||||
{
|
||||
unsigned int ver, sev;
|
||||
char cls[PATH_MAX] = { 0 };
|
||||
char rnd[PATH_MAX] = { 0 };
|
||||
char *filename_base = basename(filename);
|
||||
char *str_class = NULL;
|
||||
|
||||
if (!filename_base) {
|
||||
telem_perror("basename failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (sscanf(filename_base,"%u.%[^]0-9.].%u.%s", &ver, cls, &sev, rnd) == 4) {
|
||||
if (asprintf(&str_class, "org.clearlinux/python/%s", cls) < 29) {
|
||||
telem_log(LOG_ERR, "%s: invalid telemetry classification\n",
|
||||
str_class);
|
||||
return false;
|
||||
}
|
||||
*class = str_class;
|
||||
*version = ver;
|
||||
*severity = sev;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static char *read_file_into_buffer(const char *filename)
|
||||
{
|
||||
FILE *fp = NULL;
|
||||
char *contents = NULL;
|
||||
long sz;
|
||||
size_t size, bytes_read;
|
||||
|
||||
fp = fopen(filename, "r");
|
||||
if (fp == NULL) {
|
||||
telem_log(LOG_ERR, "Failed to open Python telemetry file %s: %s\n",
|
||||
filename, strerror(errno));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (fseek(fp, 0, SEEK_END) == -1) {
|
||||
telem_log(LOG_ERR, "Failed to seek file %s: %s\n", filename,
|
||||
strerror(errno));
|
||||
goto error_end;
|
||||
}
|
||||
|
||||
sz = ftell(fp);
|
||||
if (sz == -1L) {
|
||||
telem_perror("ftell failed");
|
||||
goto error_end;
|
||||
}
|
||||
|
||||
if (sz == 0L) {
|
||||
telem_perror("File is empty\n");
|
||||
goto error_end;
|
||||
}
|
||||
|
||||
if (fseek(fp, 0, SEEK_SET) < 0) {
|
||||
telem_log(LOG_ERR, "fseek failed for file %s:%s\n", filename,
|
||||
strerror(errno));
|
||||
goto error_end;
|
||||
}
|
||||
|
||||
size = (size_t)sz;
|
||||
contents = calloc(sizeof(char), size);
|
||||
if (!contents) {
|
||||
telem_log(LOG_ERR, "Call to calloc failed\n");
|
||||
goto error_end;
|
||||
}
|
||||
|
||||
bytes_read = fread(contents, sizeof(char), size, fp);
|
||||
|
||||
if (bytes_read < size) {
|
||||
telem_log(LOG_ERR, "Error while reading file %s:%s\n", filename,
|
||||
strerror(errno));
|
||||
goto error_end;
|
||||
}
|
||||
|
||||
fclose(fp);
|
||||
return contents;
|
||||
|
||||
error_end:
|
||||
fclose(fp);
|
||||
if (contents) {
|
||||
free(contents);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void send_data(char *contents, uint32_t severity, char *class,
|
||||
uint32_t version)
|
||||
{
|
||||
struct telem_ref *handle = NULL;
|
||||
int ret;
|
||||
|
||||
if ((ret = tm_create_record(&handle, severity, class, version)) < 0) {
|
||||
telem_log(LOG_ERR, "Failed to create record: %s\n",
|
||||
strerror(-ret));
|
||||
return;
|
||||
}
|
||||
|
||||
if ((ret = tm_set_payload(handle, contents)) < 0) {
|
||||
telem_log(LOG_ERR, "Failed to set payload: %s\n",
|
||||
strerror(-ret));
|
||||
tm_free_record(handle);
|
||||
return;
|
||||
}
|
||||
|
||||
if ((ret = tm_send_record(handle)) < 0) {
|
||||
telem_log(LOG_ERR, "Failed to send record: %s\n",
|
||||
strerror(-ret));
|
||||
}
|
||||
|
||||
tm_free_record(handle);
|
||||
}
|
||||
|
||||
/* Send a valid file to the backend. */
|
||||
static void deliver_payload(const char *filename)
|
||||
{
|
||||
uint32_t severity;
|
||||
uint32_t version;
|
||||
char *class = NULL;
|
||||
char *contents = NULL;
|
||||
|
||||
if (validate_file_name(filename, &severity, &class, &version)) {
|
||||
if ((contents = read_file_into_buffer(filename)) != NULL) {
|
||||
send_data(contents, severity, class, version);
|
||||
free(contents);
|
||||
}
|
||||
|
||||
free(class);
|
||||
}
|
||||
|
||||
/* Keep PYTHON_TELEMETRY_DIR empty. Delete the file. */
|
||||
if (unlink(filename) != 0) {
|
||||
telem_log(LOG_ERR, "Failed to unlink %s: %s\n", filename,
|
||||
strerror(errno));
|
||||
}
|
||||
}
|
||||
|
||||
static void drop_privs(void)
|
||||
{
|
||||
uid_t euid;
|
||||
|
||||
euid = geteuid();
|
||||
if (euid != 0) {
|
||||
telem_log(LOG_DEBUG, "Not root; skipping privilege drop\n");
|
||||
return;
|
||||
}
|
||||
|
||||
struct passwd *pw;
|
||||
|
||||
pw = getpwnam("telemetry");
|
||||
if (!pw) {
|
||||
telem_log(LOG_ERR, "telemetry user not found\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
// The order is important here:
|
||||
// change supplemental groups, our gid, and then our uid
|
||||
if (initgroups(pw->pw_name, pw->pw_gid) != 0) {
|
||||
telem_perror("Failed to set supplemental group list");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if (setgid(pw->pw_gid) != 0) {
|
||||
telem_perror("Failed to set GID");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if (setuid(pw->pw_uid) != 0) {
|
||||
telem_perror("Failed to set UID");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
assert(getuid() == pw->pw_uid);
|
||||
assert(geteuid() == pw->pw_uid);
|
||||
assert(getgid() == pw->pw_gid);
|
||||
assert(getegid() == pw->pw_gid);
|
||||
}
|
||||
|
||||
static void print_usage(char *prog)
|
||||
{
|
||||
printf("%s: Usage\n", prog);
|
||||
printf(" -f, --config_file Specify a configuration file other than default\n");
|
||||
printf(" -h, --help Display this help message\n");
|
||||
printf(" -V, --version Print the program version\n");
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
DIR *dir;
|
||||
struct dirent *entry;
|
||||
int c;
|
||||
int opt_index = 0;
|
||||
|
||||
struct option opts[] = {
|
||||
{ "config_file", 1, NULL, 'f' },
|
||||
{ "help", 0, NULL, 'h' },
|
||||
{ "version", 0, NULL, 'V' },
|
||||
{ NULL, 0, NULL, 0 }
|
||||
};
|
||||
|
||||
drop_privs();
|
||||
|
||||
while ((c = getopt_long(argc, argv, "f:hV", opts, &opt_index)) != -1) {
|
||||
switch (c) {
|
||||
case 'f':
|
||||
if (tm_set_config_file(optarg) != 0) {
|
||||
telem_log(LOG_ERR, "Configuration file"
|
||||
" path not valid\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
break;
|
||||
case 'h':
|
||||
print_usage(argv[0]);
|
||||
exit(EXIT_SUCCESS);
|
||||
case 'V':
|
||||
printf(PACKAGE_VERSION "\n");
|
||||
exit(EXIT_SUCCESS);
|
||||
case '?':
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
if (chdir(PYTHON_TELEMETRY_DIR)) {
|
||||
perror(PYTHON_TELEMETRY_DIR);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
/* Process all existing files */
|
||||
dir = opendir(PYTHON_TELEMETRY_DIR);
|
||||
if (!dir) {
|
||||
perror(PYTHON_TELEMETRY_DIR);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
while (true) {
|
||||
entry = readdir(dir);
|
||||
if (!entry) {
|
||||
break;
|
||||
}
|
||||
if (entry->d_name[0] == '.') {
|
||||
continue;
|
||||
}
|
||||
deliver_payload(entry->d_name);
|
||||
}
|
||||
|
||||
closedir(dir);
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* This program is part of the Clear Linux Project
|
||||
*
|
||||
* Copyright 2015 Intel Corporation
|
||||
* Copyright 2019 Intel Corporation
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under
|
||||
* the terms and conditions of the GNU Lesser General Public License, as
|
||||
@@ -32,7 +32,6 @@
|
||||
#include "common.h"
|
||||
#include "telemetry.h"
|
||||
|
||||
static char *config_file = NULL;
|
||||
static uint32_t severity = 1;
|
||||
static char *opt_class = NULL;
|
||||
static char *opt_payload = NULL;
|
||||
@@ -53,6 +52,7 @@ static const struct option prog_opts[] = {
|
||||
{ "payload-file", required_argument, 0, 'P' },
|
||||
{ "record-version", required_argument, 0, 'R' },
|
||||
{ "event-id", required_argument, 0, 'e' },
|
||||
{ "config-file", required_argument, 0, 'f' },
|
||||
{ 0, 0, 0, 0 }
|
||||
};
|
||||
|
||||
@@ -74,31 +74,18 @@ static void print_help(void)
|
||||
printf(" -e, --event-id Event id to use in the record\n");
|
||||
printf(" -o, --echo Echo record to stdout\n");
|
||||
printf(" -n, --no-post Do not post record just print\n");
|
||||
printf(" -f, --config_file Specify a configuration file other than default\n");
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
const unsigned int count_chars(const char *check, const char character)
|
||||
static bool parse_options(int argc, char **argv)
|
||||
{
|
||||
unsigned int count = 0U;
|
||||
if (check == NULL) {
|
||||
return count;
|
||||
}
|
||||
for (; *check != '\0'; ++check) {
|
||||
if (*check == character) {
|
||||
++count;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
int parse_options(int argc, char **argv)
|
||||
{
|
||||
int ret = 0;
|
||||
bool ret = false;
|
||||
char *endptr = NULL;
|
||||
long unsigned int tmp = 0;
|
||||
|
||||
int opt;
|
||||
while ((opt = getopt_long(argc, argv, "hc:Vs:c:p:P:R:e:on", prog_opts, NULL)) != -1) {
|
||||
while ((opt = getopt_long(argc, argv, "hc:Vs:c:p:P:R:e:onf:", prog_opts, NULL)) != -1) {
|
||||
switch (opt) {
|
||||
case 'h':
|
||||
print_help();
|
||||
@@ -159,31 +146,38 @@ int parse_options(int argc, char **argv)
|
||||
case 'n':
|
||||
opt_nopost = true;
|
||||
break;
|
||||
case 'f':
|
||||
if (tm_set_config_file(optarg) != 0) {
|
||||
telem_log(LOG_ERR, "Configuration file path not valid\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ret = 1;
|
||||
ret = true;
|
||||
fail:
|
||||
return ret;
|
||||
}
|
||||
|
||||
int validate_opts(void)
|
||||
static bool validate_opts(void)
|
||||
{
|
||||
size_t len;
|
||||
int ret = 0;
|
||||
size_t i, len;
|
||||
int x, slashes = 0;
|
||||
const char alphab[] = EVENT_ID_ALPHAB;
|
||||
bool ret = false;
|
||||
|
||||
/* classification */
|
||||
if (opt_class == NULL) {
|
||||
fprintf(stderr, "Error: Classification required. See --help.\n");
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
len = strlen(opt_class);
|
||||
|
||||
if ((len == 0) || (len > 120)) {
|
||||
if ((len == 0) || (len > MAX_CLASS_LENGTH)) {
|
||||
fprintf(stderr, "Error: Valid size for classification "
|
||||
"is 1-120 chars\n");
|
||||
"is 1-%d chars\n", MAX_CLASS_LENGTH);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -195,12 +189,27 @@ int validate_opts(void)
|
||||
}
|
||||
}
|
||||
|
||||
if (count_chars(opt_class, '/') != 2) {
|
||||
for (i = 0, x = 0; i <= (len - 1); i++, x++) {
|
||||
if (opt_class[i] == '/') {
|
||||
slashes++;
|
||||
x = 0;
|
||||
} else {
|
||||
if (x > MAX_SUBCAT_LENGTH) {
|
||||
fprintf(stderr, "Error: Classification strings"
|
||||
" between slashes should have at most"
|
||||
" %d chars\n", MAX_SUBCAT_LENGTH);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (slashes != 2) {
|
||||
fprintf(stderr, "Error: Classification needs to be in "
|
||||
"most/to/least specific format, 2 \'/\' required.\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/* Severity */
|
||||
if ((severity) < 1 || (severity > 4)) {
|
||||
fprintf(stderr, "Error: Valid range for severity is 1-4\n");
|
||||
@@ -221,29 +230,12 @@ int validate_opts(void)
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
int allocate_payload_buffer(char **payload)
|
||||
static bool get_payload_from_file(char **payload)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
*payload = (char *)malloc(MAX_PAYLOAD_SIZE);
|
||||
|
||||
if (*payload == NULL) {
|
||||
goto out1;
|
||||
}
|
||||
|
||||
*payload = memset(*payload, 0, MAX_PAYLOAD_SIZE);
|
||||
ret = 1;
|
||||
|
||||
out1:
|
||||
return ret;
|
||||
}
|
||||
|
||||
int get_payload_from_file(char **payload)
|
||||
{
|
||||
int ret = 1;
|
||||
bool ret = false;
|
||||
FILE *fp = NULL;
|
||||
size_t bytes_in = 0;
|
||||
|
||||
@@ -256,14 +248,14 @@ int get_payload_from_file(char **payload)
|
||||
}
|
||||
|
||||
bytes_in = fread(*payload, 1,
|
||||
MAX_PAYLOAD_SIZE - 1, fp);
|
||||
MAX_PAYLOAD_LENGTH - 1, fp);
|
||||
|
||||
/* if fread fails */
|
||||
if (bytes_in == 0 && ferror(fp) != 0) {
|
||||
ret = 0;
|
||||
goto out;
|
||||
}
|
||||
|
||||
ret = true;
|
||||
out:
|
||||
if (fp) {
|
||||
fclose(fp);
|
||||
@@ -272,25 +264,27 @@ out:
|
||||
|
||||
}
|
||||
|
||||
void get_payload_from_opt(char **payload)
|
||||
static void get_payload_from_opt(char **payload)
|
||||
{
|
||||
size_t len = 0;
|
||||
|
||||
len = strlen(opt_payload);
|
||||
if (len >= MAX_PAYLOAD_SIZE) {
|
||||
len = MAX_PAYLOAD_SIZE - 1;
|
||||
if (len >= MAX_PAYLOAD_LENGTH) {
|
||||
len = MAX_PAYLOAD_LENGTH - 1;
|
||||
}
|
||||
strncpy(*payload, opt_payload, len);
|
||||
|
||||
/* "payload" is pre-allocated zeroed buffer of MAX_PAYLOAD_LENGTH */
|
||||
memcpy(*payload, opt_payload, len);
|
||||
}
|
||||
|
||||
void get_payload_from_stdin(char **payload)
|
||||
static void get_payload_from_stdin(char **payload)
|
||||
{
|
||||
size_t bytes_in = 0;
|
||||
int c;
|
||||
|
||||
bytes_in = fread(*payload, 1, MAX_PAYLOAD_SIZE - 1, stdin);
|
||||
bytes_in = fread(*payload, 1, MAX_PAYLOAD_LENGTH - 1, stdin);
|
||||
|
||||
if (bytes_in == MAX_PAYLOAD_SIZE - 1) {
|
||||
if (bytes_in == MAX_PAYLOAD_LENGTH - 1) {
|
||||
/* Throw away the rest of stdin */
|
||||
while (EOF != (c = fgetc(stdin))) {
|
||||
continue;
|
||||
@@ -299,40 +293,40 @@ void get_payload_from_stdin(char **payload)
|
||||
|
||||
}
|
||||
|
||||
int get_payload(char **payload)
|
||||
static bool get_payload(char **payload)
|
||||
{
|
||||
int ret = 0;
|
||||
bool ret = false;
|
||||
|
||||
if (!allocate_payload_buffer(payload)) {
|
||||
goto out1;
|
||||
}
|
||||
*payload = (char *)calloc(sizeof(char), MAX_PAYLOAD_LENGTH);
|
||||
|
||||
if (*payload == NULL)
|
||||
return false;
|
||||
|
||||
if (opt_payload_file) {
|
||||
|
||||
if (get_payload_from_file(payload)) {
|
||||
ret = 1;
|
||||
ret = true;
|
||||
}
|
||||
|
||||
} else if (opt_payload) {
|
||||
|
||||
get_payload_from_opt(payload);
|
||||
ret = 1;
|
||||
ret = true;
|
||||
|
||||
} else {
|
||||
get_payload_from_stdin(payload);
|
||||
ret = 1;
|
||||
ret = true;
|
||||
}
|
||||
|
||||
if (ret == 0) {
|
||||
if (ret == false) {
|
||||
free(*payload);
|
||||
*payload = NULL;
|
||||
}
|
||||
|
||||
out1:
|
||||
return ret;
|
||||
}
|
||||
|
||||
int instanciate_record(struct telem_ref **t_ref, char *payload)
|
||||
static int instanciate_record(struct telem_ref **t_ref, char *payload)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
@@ -352,7 +346,7 @@ out1:
|
||||
return ret;
|
||||
}
|
||||
|
||||
int send_record(char *payload)
|
||||
static int send_record(char *payload)
|
||||
{
|
||||
struct telem_ref *t_ref = NULL;
|
||||
int ret = 0;
|
||||
@@ -371,13 +365,13 @@ out:
|
||||
return ret;
|
||||
}
|
||||
|
||||
int print_record(char *payload)
|
||||
static int print_record(char *payload)
|
||||
{
|
||||
struct telem_ref *t_ref = NULL;
|
||||
int ret = 0;
|
||||
int i = 0;
|
||||
|
||||
if ((ret = instanciate_record(&t_ref, payload)) != -1) {
|
||||
if ((ret = instanciate_record(&t_ref, payload)) == 0) {
|
||||
for (i = 0; i < NUM_HEADERS; i++) {
|
||||
fprintf(stdout, "%s", t_ref->record->headers[i]);
|
||||
}
|
||||
@@ -415,7 +409,6 @@ int main(int argc, char **argv)
|
||||
|
||||
ret = EXIT_SUCCESS;
|
||||
fail:
|
||||
free(config_file);
|
||||
free(opt_class);
|
||||
free(opt_payload);
|
||||
free(opt_event_id);
|
||||
|
||||
+52
-12
@@ -202,9 +202,15 @@ void transmit_spooled_record(char *record_path, bool *post_succeeded, long size)
|
||||
FILE *fp = NULL;
|
||||
char *headers[NUM_HEADERS];
|
||||
char *payload = NULL;
|
||||
int i, k;
|
||||
char line[LINE_MAX] = { 0 };
|
||||
int num_headers = 0, k;
|
||||
#if (LINE_MAX > PATH_MAX)
|
||||
char line[LINE_MAX+1] = { 0 };
|
||||
#else
|
||||
char line[PATH_MAX+1] = { 0 };
|
||||
#endif
|
||||
long offset;
|
||||
char *cfg_file = NULL;
|
||||
uint32_t cfg_prefix = 0;
|
||||
|
||||
fp = fopen(record_path, "r");
|
||||
if (fp == NULL) {
|
||||
@@ -212,16 +218,47 @@ void transmit_spooled_record(char *record_path, bool *post_succeeded, long size)
|
||||
return;
|
||||
}
|
||||
|
||||
for (i = 0; i < NUM_HEADERS; i++) {
|
||||
const char *header_name = get_header_name(i);
|
||||
if (!fgets(line, LINE_MAX, fp)) {
|
||||
// First line optionally contains configuration file path
|
||||
if (fread(&cfg_prefix, CFG_PREFIX_LENGTH, 1, fp) != 1) {
|
||||
telem_log(LOG_ERR, "Error while parsing spooled record configuration info.\n");
|
||||
goto read_error;
|
||||
}
|
||||
|
||||
if (cfg_prefix == CFG_PREFIX_32BIT) {
|
||||
size_t pathlen;
|
||||
char *nl;
|
||||
|
||||
if (!fgets(line, sizeof(line), fp)) {
|
||||
telem_log(LOG_ERR, "Error while parsing record file\n");
|
||||
fclose(fp);
|
||||
return;
|
||||
goto read_error;
|
||||
}
|
||||
|
||||
if ((nl = strchr(line, '\n')) != NULL) {
|
||||
*nl = '\0';
|
||||
}
|
||||
|
||||
pathlen = strlen(line);
|
||||
cfg_file = malloc(pathlen + 1);
|
||||
if (cfg_file == NULL) {
|
||||
telem_log(LOG_ERR, "Could not allocate memory for config file path\n");
|
||||
goto read_error;
|
||||
}
|
||||
strcpy (cfg_file, line);
|
||||
telem_debug("DEBUG: cfg_file: %s\n", cfg_file);
|
||||
} else {
|
||||
cfg_file = NULL;
|
||||
rewind(fp);
|
||||
}
|
||||
|
||||
for (num_headers = 0; num_headers < NUM_HEADERS; num_headers++) {
|
||||
const char *header_name = get_header_name(num_headers);
|
||||
if (!fgets(line, sizeof(line), fp)) {
|
||||
telem_log(LOG_ERR, "Error while parsing record file\n");
|
||||
goto read_error;
|
||||
}
|
||||
//Get rid of trailing newline
|
||||
strtok(line, "\n");
|
||||
if (get_header(line, header_name, &headers[i])) {
|
||||
if (get_header(line, header_name, &headers[num_headers])) {
|
||||
continue;
|
||||
} else {
|
||||
telem_log(LOG_ERR, "transmit_spooled_record: Incorrect"
|
||||
@@ -242,8 +279,7 @@ void transmit_spooled_record(char *record_path, bool *post_succeeded, long size)
|
||||
|
||||
if (!payload) {
|
||||
telem_log(LOG_ERR, "Could not allocate memory for payload\n");
|
||||
fclose(fp);
|
||||
return;
|
||||
goto read_error;
|
||||
}
|
||||
memset(payload, 0, (size_t)size);
|
||||
|
||||
@@ -254,7 +290,7 @@ void transmit_spooled_record(char *record_path, bool *post_succeeded, long size)
|
||||
goto read_error;
|
||||
}
|
||||
|
||||
*post_succeeded = post_record_http(headers, payload);
|
||||
*post_succeeded = post_record_http(headers, payload, cfg_file);
|
||||
if (*post_succeeded) {
|
||||
unlink(record_path);
|
||||
}
|
||||
@@ -267,9 +303,13 @@ read_error:
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
for (k = 0; k < i; k++) {
|
||||
for (k = 0; k < num_headers; k++) {
|
||||
free(headers[k]);
|
||||
}
|
||||
|
||||
if (cfg_file) {
|
||||
free(cfg_file);
|
||||
}
|
||||
}
|
||||
|
||||
int spool_record_compare(const void *entrya, const void *entryb, void *path)
|
||||
|
||||
+80
-6
@@ -36,7 +36,7 @@
|
||||
#include "log.h"
|
||||
#include "configuration.h"
|
||||
|
||||
void initialize_daemon(TelemDaemon *daemon)
|
||||
void initialize_probe_daemon(TelemDaemon *daemon)
|
||||
{
|
||||
client_list_head head;
|
||||
LIST_INIT(&head);
|
||||
@@ -165,7 +165,7 @@ bool handle_client(TelemDaemon *daemon, nfds_t ind, client *cl)
|
||||
cl->offset = 0;
|
||||
cl->size = RECORD_SIZE_LEN;
|
||||
processed = true;
|
||||
telem_log(LOG_DEBUG, "Record processed for client %d\n", cl->fd);
|
||||
telem_debug("DEBUG: Record processed for client %d\n", cl->fd);
|
||||
break;
|
||||
}
|
||||
} while (len > 0);
|
||||
@@ -247,6 +247,61 @@ void machine_id_replace(char **machine_header, char *machine_id_override)
|
||||
free(old_header);
|
||||
}
|
||||
|
||||
static void stage_record(char *filepath, char *headers[], char *body, char *cfg_file)
|
||||
{
|
||||
int tmpfd;
|
||||
FILE *tmpfile = NULL;
|
||||
|
||||
telem_debug("DEBUG: filepath:%s\n", filepath);
|
||||
telem_debug("DEBUG: body:%s\n", body);
|
||||
telem_debug("DEBUG: cfg:%s\n", cfg_file);
|
||||
// Use default path if not provided
|
||||
if (filepath == NULL) {
|
||||
telem_log(LOG_ERR, "filepath value must be provided, aborting\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
tmpfd = mkstemp(filepath);
|
||||
if (!tmpfd) {
|
||||
telem_perror("Error opening staging file");
|
||||
close(tmpfd);
|
||||
if (unlink(filepath)) {
|
||||
telem_perror("Error deleting staging file");
|
||||
}
|
||||
goto clean_exit;
|
||||
}
|
||||
|
||||
// open file
|
||||
tmpfile = fdopen(tmpfd, "a");
|
||||
if (!tmpfile) {
|
||||
telem_perror("Error opening temp stage file");
|
||||
close(tmpfd);
|
||||
if (unlink(filepath)) {
|
||||
telem_perror("Error deleting temp stage file");
|
||||
}
|
||||
goto clean_exit;
|
||||
}
|
||||
|
||||
// write cfg info if exists
|
||||
if (cfg_file != NULL) {
|
||||
fprintf(tmpfile, "%s%s\n", CFG_PREFIX, cfg_file);
|
||||
}
|
||||
|
||||
// write headers
|
||||
for (int i = 0; i < NUM_HEADERS; i++) {
|
||||
fprintf(tmpfile, "%s\n", headers[i]);
|
||||
}
|
||||
|
||||
//write body
|
||||
fprintf(tmpfile, "%s\n", body);
|
||||
fflush(tmpfile);
|
||||
fclose(tmpfile);
|
||||
|
||||
clean_exit:
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void process_record(TelemDaemon *daemon, client *cl)
|
||||
{
|
||||
int i = 0;
|
||||
@@ -259,11 +314,30 @@ void process_record(TelemDaemon *daemon, client *cl)
|
||||
char *msg;
|
||||
char *body;
|
||||
char *recordpath = NULL;
|
||||
char *cfg_file = NULL;;
|
||||
size_t cfg_info_size = 0;
|
||||
uint8_t *buf;
|
||||
|
||||
header_size = *(uint32_t *)cl->buf;
|
||||
message_size = cl->size - header_size;
|
||||
buf = cl->buf;
|
||||
|
||||
/* Check for an optional CFG_PREFIX in the first 32 bits */
|
||||
if (*(uint32_t *)buf == CFG_PREFIX_32BIT) {
|
||||
char *cfg = (char *)cl->buf;
|
||||
|
||||
cfg_file = cfg + CFG_PREFIX_LENGTH;
|
||||
cfg_info_size = CFG_PREFIX_LENGTH + strlen(cfg_file) + 1;
|
||||
telem_debug("DEBUG: cfg_file: %s\n", cfg_file);
|
||||
}
|
||||
|
||||
buf += cfg_info_size;
|
||||
header_size = *(uint32_t *)buf;
|
||||
message_size = cl->size - (cfg_info_size + header_size);
|
||||
telem_debug("DEBUG: cl->size: %zu\n", cl->size);
|
||||
telem_debug("DEBUG: header_size: %zu\n", header_size);
|
||||
telem_debug("DEBUG: message_size: %zu\n", message_size);
|
||||
telem_debug("DEBUG: cfg_info_size: %zu\n", cfg_info_size);
|
||||
assert(message_size > 0); //TODO:Check for min and max limits
|
||||
msg = (char *)cl->buf + sizeof(uint32_t);
|
||||
msg = (char *)buf + sizeof(uint32_t);
|
||||
|
||||
/* Copying the headers as strtok modifies the orginal buffer */
|
||||
temp_headers = strndup(msg, header_size);
|
||||
@@ -293,7 +367,7 @@ void process_record(TelemDaemon *daemon, client *cl)
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
stage_record(recordpath, headers, body);
|
||||
stage_record(recordpath, headers, body, cfg_file);
|
||||
free(recordpath);
|
||||
end:
|
||||
free(temp_headers);
|
||||
|
||||
+1
-1
@@ -62,7 +62,7 @@ typedef struct TelemDaemon {
|
||||
*
|
||||
* @param daemon A pointer to the daemon structure.
|
||||
*/
|
||||
void initialize_daemon(TelemDaemon *daemon);
|
||||
void initialize_probe_daemon(TelemDaemon *daemon);
|
||||
|
||||
/**
|
||||
* Add poll fd struct to the array of pollfds.
|
||||
|
||||
+90
-95
@@ -35,6 +35,7 @@
|
||||
#include "common.h"
|
||||
#include "configuration.h"
|
||||
#include "telemetry.h"
|
||||
#include "log.h"
|
||||
|
||||
/**
|
||||
* Return a file descriptor to either site's version file
|
||||
@@ -76,9 +77,7 @@ static int set_header(char **dest, const char *prefix, char *value, size_t *head
|
||||
rc = asprintf(dest, "%s: %s\n", prefix, value);
|
||||
|
||||
if (rc < 0) {
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "CRIT: Out of memory\n");
|
||||
#endif
|
||||
telem_log(LOG_CRIT, "CRIT: Out of memory\n");
|
||||
return -ENOMEM;
|
||||
} else {
|
||||
*header_size += (size_t)rc;
|
||||
@@ -233,35 +232,49 @@ static int set_system_name_header(struct telem_ref *t_ref)
|
||||
int fd;
|
||||
char buf[SMALL_LINE_BUF] = { 0 };
|
||||
char name[SMALL_LINE_BUF] = { 0 };
|
||||
char variant[SMALL_LINE_BUF] = { 0 };
|
||||
|
||||
fd = version_file();
|
||||
if (fd == -1) {
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "WARNING: Cannot find os-release file\n");
|
||||
#endif
|
||||
telem_log(LOG_WARNING, "WARNING: Cannot find os-release file\n");
|
||||
sprintf(name, "unknown");
|
||||
} else {
|
||||
fs = fdopen(fd, "r");
|
||||
while (fgets(buf, SMALL_LINE_BUF, fs)) {
|
||||
if (sscanf(buf, "ID=%s", name) < 1) {
|
||||
continue;
|
||||
} else {
|
||||
if (sscanf(buf, "ID=%s", name) > 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
rewind(fs);
|
||||
while (fgets(buf, SMALL_LINE_BUF, fs)) {
|
||||
if (sscanf(buf, "VARIANT_ID=%s", variant) > 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
fclose(fs);
|
||||
|
||||
if (strlen(name) == 0) {
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "WARNING: Cannot find os-release field: ID\n");
|
||||
#endif
|
||||
telem_log(LOG_WARNING, "WARNING: Cannot find os-release field: ID\n");
|
||||
sprintf(name, "unknown");
|
||||
}
|
||||
|
||||
fclose(fs);
|
||||
if (strlen(variant) == 0) {
|
||||
snprintf(buf, sizeof(buf), "%s", name);
|
||||
} else {
|
||||
/* We do not want the header to be greater than 80 characters, allow truncation */
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wformat-truncation"
|
||||
if (snprintf(buf, sizeof(buf), "%s_%s", name, variant) > sizeof(buf)) {
|
||||
telem_log(LOG_WARNING, "WARNING: truncating system name header to 80 characters\n");
|
||||
}
|
||||
telem_debug("DEBUG: Found variant OS information: %s\n", variant);
|
||||
#pragma GCC diagnostic pop
|
||||
}
|
||||
}
|
||||
|
||||
return set_header(&(t_ref->record->headers[TM_SYSTEM_NAME]),
|
||||
TM_SYSTEM_NAME_STR, name,
|
||||
TM_SYSTEM_NAME_STR, buf,
|
||||
&(t_ref->record->header_size));
|
||||
|
||||
}
|
||||
@@ -285,9 +298,7 @@ static int set_system_build_header(struct telem_ref *t_ref)
|
||||
|
||||
fd = version_file();
|
||||
if (fd == -1) {
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "WARNING: Cannot find build version file\n");
|
||||
#endif
|
||||
telem_log(LOG_WARNING, "WARNING: Cannot find build version file\n");
|
||||
sprintf(version, "0");
|
||||
} else {
|
||||
fs = fdopen(fd, "r");
|
||||
@@ -300,9 +311,7 @@ static int set_system_build_header(struct telem_ref *t_ref)
|
||||
}
|
||||
|
||||
if (strlen(version) == 0) {
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "WARNING: Cannot find build version number\n");
|
||||
#endif
|
||||
telem_log(LOG_WARNING, "WARNING: Cannot find build version number\n");
|
||||
sprintf(version, "0");
|
||||
}
|
||||
|
||||
@@ -416,7 +425,7 @@ static int set_cpu_model_header(struct telem_ref *t_ref)
|
||||
}
|
||||
} else {
|
||||
model_name = "blank";
|
||||
fprintf(stderr, "NOTICE: Unable to find attribute:%s\n", attr_name);
|
||||
telem_log(LOG_NOTICE, "NOTICE: Unable to find attribute:%s\n", attr_name);
|
||||
}
|
||||
|
||||
status = set_header(
|
||||
@@ -425,9 +434,7 @@ static int set_cpu_model_header(struct telem_ref *t_ref)
|
||||
&(t_ref->record->header_size));
|
||||
|
||||
} else {
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "NOTICE: Unable to open /proc/cpuinfo\n");
|
||||
#endif
|
||||
telem_log(LOG_NOTICE, "NOTICE: Unable to open /proc/cpuinfo\n");
|
||||
status = -1;
|
||||
}
|
||||
|
||||
@@ -461,9 +468,7 @@ static int get_dmi_value(const char *source, const char *key, char **buf)
|
||||
*buf = (char *)malloc(sizeof(char) * SMALL_LINE_BUF);
|
||||
|
||||
if (*buf == NULL) {
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "CRIT: Out of memory\n");
|
||||
#endif
|
||||
telem_log(LOG_CRIT, "CRIT: Out of memory\n");
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
@@ -486,9 +491,7 @@ static int get_dmi_value(const char *source, const char *key, char **buf)
|
||||
if (new_size == 0) {
|
||||
old_value = *buf;
|
||||
if (asprintf(buf, "blank") < 0) {
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "CRIT: Out of memory\n");
|
||||
#endif
|
||||
telem_log(LOG_CRIT, "CRIT: Out of memory\n");
|
||||
ret = -ENOMEM;
|
||||
}
|
||||
free(old_value);
|
||||
@@ -505,24 +508,18 @@ static int get_dmi_value(const char *source, const char *key, char **buf)
|
||||
if (j == new_size) {
|
||||
old_value = *buf;
|
||||
if (asprintf(buf, "blank") < 0) {
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "CRIT: Out of memory\n");
|
||||
#endif
|
||||
telem_log(LOG_CRIT, "CRIT: Out of memory\n");
|
||||
ret = -ENOMEM;
|
||||
}
|
||||
free(old_value);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "NOTICE: Dmi file %s does not exist\n", source);
|
||||
#endif
|
||||
telem_debug("DEBUG: Dmi file %s does not exist\n", source);
|
||||
|
||||
old_value = *buf;
|
||||
if (asprintf(buf, "no_%s_file", key) < 0) {
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "CRIT: Out of memory\n");
|
||||
#endif
|
||||
telem_log(LOG_CRIT, "CRIT: Out of memory\n");
|
||||
ret = -ENOMEM;
|
||||
}
|
||||
free(old_value);
|
||||
@@ -777,9 +774,9 @@ static int set_payload_format_header(struct telem_ref *t_ref, uint32_t payload_v
|
||||
return status;
|
||||
}
|
||||
|
||||
void tm_set_config_file(char *c_file)
|
||||
int tm_set_config_file(const char *c_file)
|
||||
{
|
||||
set_config_file(c_file);
|
||||
return set_config_file(c_file);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -927,17 +924,13 @@ int tm_create_record(struct telem_ref **t_ref, uint32_t severity,
|
||||
|
||||
*t_ref = (struct telem_ref *)malloc(sizeof(struct telem_ref));
|
||||
if (*t_ref == NULL) {
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "CRIT: Out of memory\n");
|
||||
#endif
|
||||
telem_log(LOG_CRIT, "CRIT: Out of memory\n");
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
(*t_ref)->record = (struct telem_record *)malloc(sizeof(struct telem_record));
|
||||
if ((*t_ref)->record == NULL) {
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "CRIT: Out of memory\n");
|
||||
#endif
|
||||
telem_log(LOG_CRIT, "CRIT: Out of memory\n");
|
||||
free(*t_ref);
|
||||
return -ENOMEM;
|
||||
}
|
||||
@@ -1010,19 +1003,13 @@ int tm_set_payload(struct telem_ref *t_ref, char *payload)
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
t_ref->record->payload = (char *)malloc(sizeof(char) * payload_len + 1);
|
||||
t_ref->record->payload = strdup(payload);
|
||||
|
||||
if (!t_ref->record->payload) {
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "CRIT: Out of memory\n");
|
||||
#endif
|
||||
telem_log(LOG_CRIT, "CRIT: Out of memory\n");
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
memset(t_ref->record->payload, 0, sizeof(char) * payload_len + 1);
|
||||
|
||||
strncpy((char *)(t_ref->record->payload), (char *)payload, payload_len);
|
||||
|
||||
t_ref->record->payload_size = payload_len;
|
||||
|
||||
return ret;
|
||||
@@ -1102,10 +1089,7 @@ static int tm_write_socket(int fd, char *buf, size_t nbytes)
|
||||
|
||||
if (b == -1 && errno != EAGAIN) {
|
||||
ret = -errno;
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "ERR: Write to daemon socket with"
|
||||
" system error: %s\n", strerror(errno));
|
||||
#endif
|
||||
telem_perror("Error writing to daemon socket");
|
||||
return ret;
|
||||
} else if (b == -1 &&
|
||||
(errno == EAGAIN || errno == EWOULDBLOCK)) {
|
||||
@@ -1145,10 +1129,7 @@ static int tm_get_socket(void)
|
||||
|
||||
if (sfd == -1) {
|
||||
ret = -errno;
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "ERR: Attempt to allocate socket fd failed:"
|
||||
" %s\n", strerror(errno));
|
||||
#endif
|
||||
telem_perror("Attempt to allocate socket fd failed");
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -1159,10 +1140,7 @@ static int tm_get_socket(void)
|
||||
if (setsockopt(sfd, SOL_SOCKET, SO_RCVTIMEO, &tv,
|
||||
sizeof(tv)) < 0) {
|
||||
ret = -errno;
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "ERR: Failed to set socket timeout:"
|
||||
" %s\n", strerror(errno));
|
||||
#endif
|
||||
telem_perror("Failed to set socket timeout");
|
||||
goto out1;
|
||||
}
|
||||
|
||||
@@ -1218,9 +1196,7 @@ static int tm_get_socket(void)
|
||||
// Set non-blocking after the connect() succeeded
|
||||
if ((sflags = fcntl(sfd, F_GETFL, NULL)) < 0) {
|
||||
ret = -errno;
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "ERR: Failed to get socket flags\n");
|
||||
#endif
|
||||
telem_log(LOG_ERR, "Failed to get socket flags\n");
|
||||
goto out1;
|
||||
}
|
||||
|
||||
@@ -1228,9 +1204,7 @@ static int tm_get_socket(void)
|
||||
|
||||
if (fcntl(sfd, F_SETFL, sflags) < 0) {
|
||||
ret = -errno;
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "ERR: Failed to set socket flags\n");
|
||||
#endif
|
||||
telem_log(LOG_ERR, "Failed to set socket flags\n");
|
||||
goto out1;
|
||||
}
|
||||
|
||||
@@ -1252,6 +1226,8 @@ int tm_send_record(struct telem_ref *t_ref)
|
||||
int ret = 0;
|
||||
int k = 0;
|
||||
struct stat unused;
|
||||
size_t cfg_file_name_size = 0;
|
||||
const char *cfg_file_name = NULL;
|
||||
|
||||
k = stat(TM_OPT_OUT_FILE, &unused);
|
||||
if (k == 0) {
|
||||
@@ -1262,24 +1238,44 @@ int tm_send_record(struct telem_ref *t_ref)
|
||||
sfd = tm_get_socket();
|
||||
|
||||
if (sfd < 0) {
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "ERR: Failed to get socket fd: %s\n",
|
||||
strerror(-sfd));
|
||||
#endif
|
||||
telem_log(LOG_ERR, "Failed to get socket fd: %s\n",
|
||||
strerror(-sfd));
|
||||
return sfd;
|
||||
}
|
||||
|
||||
total_size = t_ref->record->header_size + t_ref->record->payload_size;
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "DEBUG: Header size : %zu\n", t_ref->record->header_size);
|
||||
fprintf(stderr, "DEBUG: Payload size : %zu\n", t_ref->record->payload_size);
|
||||
|
||||
fprintf(stderr, "DEBUG: Total size : %zu\n", total_size);
|
||||
#endif
|
||||
/*
|
||||
* The user may want to use a custom (cmd line specified) config file.
|
||||
* If that is the case, we need to include the absolute path in the data packet.
|
||||
* We optionally add the string CFG:<absolute path> as the first string
|
||||
* in the data. If the receiving end sees this in the data, it should
|
||||
* use the config file specified to override any default telemetrics.conf
|
||||
* files.
|
||||
*/
|
||||
|
||||
cfg_file_name = get_cmd_line_config_file();
|
||||
if (cfg_file_name != NULL) {
|
||||
cfg_file_name_size = strlen(cfg_file_name) + 1;
|
||||
total_size += (cfg_file_name_size + CFG_PREFIX_LENGTH);
|
||||
}
|
||||
|
||||
if (cfg_file_name != NULL) {
|
||||
telem_debug("DEBUG: CFG field size : %zu\n", cfg_file_name_size + CFG_PREFIX_LENGTH);
|
||||
telem_debug("DEBUG: CFG file name : %s\n", cfg_file_name);
|
||||
}
|
||||
|
||||
telem_debug("DEBUG: Header size : %zu\n", t_ref->record->header_size);
|
||||
telem_debug("DEBUG: Payload size : %zu\n", t_ref->record->payload_size);
|
||||
|
||||
telem_debug("DEBUG: Total size : %zu\n", total_size);
|
||||
|
||||
/*
|
||||
* Allocating buffer for what we intend to send. Buffer layout is:
|
||||
* <uint32_t total_size><uint32_t header_size><headers + Payload>
|
||||
* <uint32_t total_size> : so recv knows how much to read
|
||||
* <custom cfg file field> : optional
|
||||
* <uint32_t header_size>
|
||||
* <headers + Payload>
|
||||
* <null-byte>
|
||||
* The additional char at the end ensures null termination
|
||||
*/
|
||||
@@ -1287,9 +1283,7 @@ int tm_send_record(struct telem_ref *t_ref)
|
||||
|
||||
data = malloc(record_size);
|
||||
if (!data) {
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "CRIT: Out of memory\n");
|
||||
#endif
|
||||
telem_log(LOG_CRIT, "CRIT: Out of memory\n");
|
||||
close(sfd);
|
||||
return -ENOMEM;
|
||||
}
|
||||
@@ -1299,6 +1293,13 @@ int tm_send_record(struct telem_ref *t_ref)
|
||||
memcpy(data, &total_size, sizeof(uint32_t));
|
||||
offset += sizeof(uint32_t);
|
||||
|
||||
if (cfg_file_name != NULL) {
|
||||
memcpy(data + offset, CFG_PREFIX, CFG_PREFIX_LENGTH);
|
||||
offset += CFG_PREFIX_LENGTH;
|
||||
memcpy(data + offset, cfg_file_name, cfg_file_name_size);
|
||||
offset += cfg_file_name_size;
|
||||
}
|
||||
|
||||
memcpy(data + offset, &t_ref->record->header_size, sizeof(uint32_t));
|
||||
offset += sizeof(uint32_t);
|
||||
|
||||
@@ -1311,17 +1312,11 @@ int tm_send_record(struct telem_ref *t_ref)
|
||||
|
||||
memcpy(data + offset, t_ref->record->payload, t_ref->record->payload_size);
|
||||
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "DEBUG: Data to be sent :\n\n%s\n", data + 2 * sizeof(uint32_t));
|
||||
#endif
|
||||
telem_debug("DEBUG: Data to be sent :\n\n%s\n", data + 2 * sizeof(uint32_t));
|
||||
if ((ret = tm_write_socket(sfd, data, record_size)) == 0) {
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "INFO: Successfully sent record over the socket\n");
|
||||
#endif
|
||||
telem_log(LOG_INFO, "INFO: Successfully sent record over the socket\n");
|
||||
} else {
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "ERR: Error while writing data to socket\n");
|
||||
#endif
|
||||
telem_log(LOG_ERR, "Error while writing data to socket\n");
|
||||
}
|
||||
|
||||
close(sfd);
|
||||
|
||||
+4
-4
@@ -58,11 +58,11 @@ struct telem_ref {
|
||||
/**
|
||||
* Set the configuration file name to use
|
||||
*
|
||||
* @param c_file Absolute file name of the configuration file. If the path name
|
||||
* provided is not an absolute path, or the path given cannot be successfuly
|
||||
* stat'd, then the effective configuration file is left unchanged.
|
||||
* @param c_file Absolute file name of the configuration file.
|
||||
* @return 0 on success, or a negative errno-style value on error. In case of
|
||||
* an error return the effective configuration file is left unchanged.
|
||||
*/
|
||||
void tm_set_config_file(char *c_file);
|
||||
int tm_set_config_file(const char *c_file);
|
||||
|
||||
/**
|
||||
* Create a new telemetrics record
|
||||
|
||||
+103
-36
@@ -37,7 +37,7 @@
|
||||
/* spool window check */
|
||||
static bool inside_direct_spool_window(TelemPostDaemon *daemon, time_t current_time)
|
||||
{
|
||||
return (current_time < daemon->bypass_http_post_ts + 1800) ? true : false;
|
||||
return (current_time < daemon->bypass_http_post_ts + NETWORK_BYPASS_DURATION) ? true : false;
|
||||
}
|
||||
|
||||
/* set http bypass */
|
||||
@@ -178,7 +178,7 @@ static void initialize_record_delivery(TelemPostDaemon *daemon)
|
||||
daemon->record_server_delivery_enabled = record_server_delivery_enabled_config();
|
||||
}
|
||||
|
||||
void initialize_daemon(TelemPostDaemon *daemon)
|
||||
void initialize_post_daemon(TelemPostDaemon *daemon)
|
||||
{
|
||||
assert(daemon);
|
||||
|
||||
@@ -210,7 +210,7 @@ size_t write_callback(char *ptr, size_t size, size_t nmemb, void *userdata)
|
||||
return size * nmemb;
|
||||
}
|
||||
|
||||
bool post_record_http(char *headers[], char *body)
|
||||
bool post_record_http(char *headers[], char *body, char *cfg)
|
||||
{
|
||||
CURL *curl;
|
||||
int res = 0;
|
||||
@@ -220,6 +220,22 @@ bool post_record_http(char *headers[], char *body)
|
||||
long http_response = 0;
|
||||
const char *cert_file = get_cainfo_config();
|
||||
const char *tid_header = get_tidheader_config();
|
||||
const char *saved_config_file = NULL;
|
||||
|
||||
if (cfg != NULL) {
|
||||
saved_config_file = get_config_file();
|
||||
if (set_config_file(cfg) != 0) {
|
||||
telem_log(LOG_ERR, "set-config_file(): Failed to set %s\n", cfg);
|
||||
// If we fail to load the specified config file, do not send the
|
||||
// record out. We don't want to send the record out with different
|
||||
// settings than explicitly requested.
|
||||
// However, report success so the record gets deleted.
|
||||
res = 0;
|
||||
goto Done;
|
||||
}
|
||||
reload_config();
|
||||
telem_debug("DEBUG: override server_addr:%s\n", server_addr_config());
|
||||
}
|
||||
|
||||
// Initialize the libcurl global environment once per POST. This lets us
|
||||
// clean up the environment after each POST so that when the daemon is
|
||||
@@ -275,10 +291,10 @@ bool post_record_http(char *headers[], char *body)
|
||||
if (res) {
|
||||
size_t len = strlen(errorbuf);
|
||||
if (len) {
|
||||
telem_log(LOG_ERR, "Failed sending record: %s%s", errorbuf,
|
||||
telem_log(LOG_DEBUG, "Failed sending record: %s%s", errorbuf,
|
||||
((errorbuf[len - 1] != '\n') ? "\n" : ""));
|
||||
} else {
|
||||
telem_log(LOG_ERR, "Failed sending record: %s\n",
|
||||
telem_log(LOG_DEBUG, "Failed sending record: %s\n",
|
||||
curl_easy_strerror(res));
|
||||
}
|
||||
} else if (http_response != 201 && http_response != 200) {
|
||||
@@ -298,6 +314,17 @@ bool post_record_http(char *headers[], char *body)
|
||||
|
||||
curl_global_cleanup();
|
||||
|
||||
Done:
|
||||
if (saved_config_file != NULL) {
|
||||
if (set_config_file(saved_config_file) != 0) {
|
||||
telem_log(LOG_ERR, "set-config_file(): Failed to set %s",
|
||||
saved_config_file);
|
||||
res = 1;
|
||||
}
|
||||
reload_config();
|
||||
telem_debug("DEBUG: restored server_addr:%s\n", server_addr_config());
|
||||
}
|
||||
|
||||
return res ? false : true;
|
||||
}
|
||||
|
||||
@@ -396,12 +423,8 @@ static void rate_limit_checks(TelemPostDaemon *daemon, bool *record_check_passed
|
||||
}
|
||||
|
||||
/* Wrapper for save local copy */
|
||||
static void apply_retention_policies(TelemPostDaemon *daemon, char *headers[], char *body)
|
||||
static void apply_retention_policies(TelemPostDaemon *daemon, char *body)
|
||||
{
|
||||
time_t temp = time(NULL);
|
||||
|
||||
save_entry_to_journal(daemon, temp, headers);
|
||||
|
||||
if (daemon->record_retention_enabled) {
|
||||
save_local_copy(daemon, body);
|
||||
}
|
||||
@@ -409,7 +432,7 @@ static void apply_retention_policies(TelemPostDaemon *daemon, char *headers[], c
|
||||
|
||||
/* Deliver record to backend if rate limiting policies are met otherwise
|
||||
* spool record for future delivery */
|
||||
static bool deliver_record(TelemPostDaemon *daemon, char *headers[], char *body)
|
||||
static bool deliver_record(TelemPostDaemon *daemon, char *headers[], char *body, char* cfg_file)
|
||||
{
|
||||
|
||||
bool ret = false;
|
||||
@@ -431,7 +454,7 @@ static bool deliver_record(TelemPostDaemon *daemon, char *headers[], char *body)
|
||||
/* Sends record if rate limiting is disabled, or all checks passed */
|
||||
if (!daemon->rate_limit_enabled || (record_check_passed && byte_check_passed)) {
|
||||
/* Send the record as https post */
|
||||
record_sent = post_record_ptr(headers, body);
|
||||
record_sent = post_record_ptr(headers, body, cfg_file);
|
||||
/**
|
||||
* This is the only point where an error condition could be returned
|
||||
* if the record was not sent
|
||||
@@ -467,7 +490,7 @@ static bool deliver_record(TelemPostDaemon *daemon, char *headers[], char *body)
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool process_staged_record(char *filename, TelemPostDaemon *daemon)
|
||||
bool process_staged_record(char *filename, bool is_retry, TelemPostDaemon *daemon)
|
||||
{
|
||||
int k;
|
||||
bool ret = false;
|
||||
@@ -476,13 +499,14 @@ bool process_staged_record(char *filename, TelemPostDaemon *daemon)
|
||||
struct stat buf;
|
||||
time_t current_time = time(NULL);
|
||||
int64_t max_spool_size = 0;
|
||||
char *cfg_file = NULL;
|
||||
|
||||
for (k = 0; k < NUM_HEADERS; k++) {
|
||||
headers[k] = NULL;
|
||||
}
|
||||
|
||||
/** Load record **/
|
||||
if ((ret = read_record(filename, headers, &body)) == false) {
|
||||
if ((ret = read_record(filename, headers, &body, &cfg_file)) == false) {
|
||||
telem_log(LOG_WARNING, "unable to read record\n");
|
||||
ret = true; // Record corrupted? true will remove record
|
||||
goto end_processing_file;
|
||||
@@ -506,14 +530,17 @@ bool process_staged_record(char *filename, TelemPostDaemon *daemon)
|
||||
goto end_processing_file;
|
||||
}
|
||||
|
||||
/** Record retention **/
|
||||
apply_retention_policies(daemon, headers, body);
|
||||
/* Retries should not be recorded */
|
||||
if (is_retry == false) {
|
||||
/** Journal entry **/
|
||||
save_entry_to_journal(daemon, current_time, headers);
|
||||
/** Record retention **/
|
||||
apply_retention_policies(daemon, body);
|
||||
}
|
||||
|
||||
/** Record delivery **/
|
||||
if (!daemon->record_server_delivery_enabled) {
|
||||
#ifdef DEBUG
|
||||
telem_log(LOG_WARNING, "record server delivery disabled\n");
|
||||
#endif
|
||||
telem_log(LOG_INFO, "record server delivery disabled\n");
|
||||
// Not an error condition
|
||||
ret = true;
|
||||
goto end_processing_file;
|
||||
@@ -521,9 +548,7 @@ bool process_staged_record(char *filename, TelemPostDaemon *daemon)
|
||||
|
||||
/** Spool policies **/
|
||||
if (inside_direct_spool_window(daemon, time(NULL))) {
|
||||
#ifdef DEBUG
|
||||
telem_log(LOG_INFO, "process_record: delivering directly to spool\n");
|
||||
#endif
|
||||
/* Check spool max size conf */
|
||||
max_spool_size = spool_max_size_config();
|
||||
if (max_spool_size != -1 &&
|
||||
@@ -544,7 +569,7 @@ bool process_staged_record(char *filename, TelemPostDaemon *daemon)
|
||||
}
|
||||
|
||||
/** Deliver or spool **/
|
||||
ret = deliver_record(daemon, headers, body);
|
||||
ret = deliver_record(daemon, headers, body, cfg_file);
|
||||
|
||||
end_processing_file:
|
||||
/** Update spool size if record will be removed **/
|
||||
@@ -558,6 +583,9 @@ end_processing_file:
|
||||
free(headers[k]);
|
||||
}
|
||||
|
||||
if (cfg_file != NULL) {
|
||||
free(cfg_file);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -570,20 +598,22 @@ static int directory_dot_filter(const struct dirent *entry)
|
||||
}
|
||||
}
|
||||
|
||||
void staging_records_loop(TelemPostDaemon *daemon)
|
||||
int staging_records_loop(TelemPostDaemon *daemon)
|
||||
{
|
||||
int ret;
|
||||
int processed;
|
||||
int numentries;
|
||||
struct dirent **namelist;
|
||||
|
||||
numentries = scandir(spool_dir_config(), &namelist, directory_dot_filter, NULL);
|
||||
processed = 0;
|
||||
|
||||
if (numentries == 0) {
|
||||
telem_log(LOG_DEBUG, "No entries in staging\n");
|
||||
return;
|
||||
return numentries;
|
||||
} else if (numentries < 0) {
|
||||
telem_perror("Error while scanning staging");
|
||||
return;
|
||||
return numentries;
|
||||
}
|
||||
|
||||
for (int i = 0; i < numentries; i++) {
|
||||
@@ -595,8 +625,9 @@ void staging_records_loop(TelemPostDaemon *daemon)
|
||||
telem_log(LOG_ERR, "Failed to allocate memory for staging record full path\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if (process_staged_record(record_path, daemon)) {
|
||||
if (process_staged_record(record_path, true, daemon)) {
|
||||
unlink(record_path);
|
||||
processed++;
|
||||
}
|
||||
free(record_path);
|
||||
}
|
||||
@@ -605,24 +636,43 @@ void staging_records_loop(TelemPostDaemon *daemon)
|
||||
free(namelist[i]);
|
||||
}
|
||||
free(namelist);
|
||||
|
||||
return numentries - processed;
|
||||
}
|
||||
|
||||
void run_daemon(TelemPostDaemon *daemon)
|
||||
{
|
||||
int ret;
|
||||
/* retry_attempt of zero indicates we don't need to retry */
|
||||
int retry_attempt = 0;
|
||||
int spool_process_time = spool_process_time_config();
|
||||
bool daemon_recycling_enabled = daemon_recycling_enabled_config();
|
||||
time_t last_spool_run_time = time(NULL);
|
||||
time_t last_daemon_start_time = time(NULL);
|
||||
time_t last_record_received = time(NULL);
|
||||
|
||||
assert(daemon);
|
||||
assert(daemon->pollfds);
|
||||
assert(daemon->pollfds[signlfd].fd);
|
||||
assert(daemon->pollfds[watchfd].fd);
|
||||
|
||||
/* If we failed to send spooled records, indicate we need to retry */
|
||||
if (daemon->bypass_http_post_ts != 0) {
|
||||
retry_attempt = 1;
|
||||
}
|
||||
|
||||
while (1) {
|
||||
int retry_delay = spool_process_time;
|
||||
malloc_trim(0);
|
||||
ret = poll(daemon->pollfds, NFDS, spool_process_time * 1000);
|
||||
|
||||
/* check if we need to retry sending spooled records */
|
||||
if (retry_attempt > 0) {
|
||||
retry_delay = retry_attempt * retry_attempt;
|
||||
daemon->bypass_http_post_ts = 0;
|
||||
telem_log(LOG_INFO, "Record delivery failed will retry in %d seconds",
|
||||
retry_delay);
|
||||
}
|
||||
|
||||
ret = poll(daemon->pollfds, NFDS, retry_delay * 1000);
|
||||
if (ret == -1) {
|
||||
telem_perror("Failed to poll daemon file descriptors");
|
||||
break;
|
||||
@@ -671,10 +721,11 @@ void run_daemon(TelemPostDaemon *daemon)
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
/* Process inotify event */
|
||||
if (process_staged_record(record_name, daemon)) {
|
||||
if (process_staged_record(record_name, false, daemon)) {
|
||||
unlink(record_name);
|
||||
}
|
||||
free(record_name);
|
||||
last_record_received = time(NULL);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -685,19 +736,35 @@ void run_daemon(TelemPostDaemon *daemon)
|
||||
time_t now = time(NULL);
|
||||
/* time to recycle the daemon has elapsed*/
|
||||
if (daemon_recycling_enabled &&
|
||||
difftime(now, last_daemon_start_time) >= TM_DAEMON_EXIT_TIME) {
|
||||
difftime(now, last_record_received) >= TM_DAEMON_EXIT_TIME) {
|
||||
/* Exit */
|
||||
telem_log(LOG_INFO, "Telemetry post daemon exiting for recycling\n");
|
||||
break;
|
||||
}
|
||||
|
||||
/* Check if this was a retry attempt */
|
||||
if (retry_attempt > 0) {
|
||||
/* Stop attempting retries if successful, increment counter if not */
|
||||
if (staging_records_loop(daemon) == 0) {
|
||||
retry_attempt = 0;
|
||||
} else {
|
||||
retry_attempt++;
|
||||
}
|
||||
/* Give up if counter reaches MAX_RETRY_ATTEMPTS */
|
||||
if (retry_attempt == MAX_RETRY_ATTEMPTS) {
|
||||
telem_log(LOG_ERR, "Record deliver failed after %d attempts",
|
||||
MAX_RETRY_ATTEMPTS);
|
||||
retry_attempt = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* Check spool */
|
||||
if (difftime(now, last_spool_run_time) >= spool_process_time) {
|
||||
spool_records_loop(&(daemon->current_spool_size));
|
||||
last_spool_run_time = time(NULL);
|
||||
}
|
||||
}
|
||||
|
||||
/* Check spool */
|
||||
time_t now = time(NULL);
|
||||
if (difftime(now, last_spool_run_time) >= spool_process_time) {
|
||||
spool_records_loop(&(daemon->current_spool_size));
|
||||
last_spool_run_time = time(NULL);
|
||||
}
|
||||
/* Check journal records and prune if needed */
|
||||
ret = prune_journal(daemon->record_journal, JOURNAL_TMPDIR);
|
||||
if (ret != 0) {
|
||||
|
||||
+12
-5
@@ -19,6 +19,8 @@
|
||||
#define NFDS 2
|
||||
#define TM_RATE_LIMIT_SLOTS (1 /*h*/ * 60 /*m*/)
|
||||
#define TM_RECORD_COUNTER (1)
|
||||
#define MAX_RETRY_ATTEMPTS 8
|
||||
#define NETWORK_BYPASS_DURATION TM_DAEMON_EXIT_TIME
|
||||
|
||||
#include <poll.h>
|
||||
#include <stdbool.h>
|
||||
@@ -63,7 +65,7 @@ typedef struct TelemPostDaemon {
|
||||
*
|
||||
* @param daemon a pointer to telemetry post daemon
|
||||
*/
|
||||
void initialize_daemon(TelemPostDaemon *daemon);
|
||||
void initialize_post_daemon(TelemPostDaemon *daemon);
|
||||
|
||||
/**
|
||||
* Starts daemon
|
||||
@@ -83,25 +85,30 @@ void close_daemon(TelemPostDaemon *daemon);
|
||||
* Processed record written on disk
|
||||
*
|
||||
* @param filename a pointor to record on disk
|
||||
* @param is_retry a boolean value that indicates if
|
||||
* the record has been previously processed.
|
||||
* @param daemon post to telemetry post daemon
|
||||
*/
|
||||
bool process_staged_record(char *filename, TelemPostDaemon *daemon);
|
||||
bool process_staged_record(char *filename, bool is_retry, TelemPostDaemon *daemon);
|
||||
|
||||
/**
|
||||
* Scans staging directory to process files that were
|
||||
* missed by file watcher
|
||||
*
|
||||
* @param daemon a pointer to telemetry post daemon
|
||||
* @return the number of records that were removed from spool
|
||||
*/
|
||||
void staging_records_loop(TelemPostDaemon *daemon);
|
||||
int staging_records_loop(TelemPostDaemon *daemon);
|
||||
|
||||
/**
|
||||
* Posts a record to backend
|
||||
*
|
||||
* @param headers a pointer to an array with keys and values
|
||||
* @param body a pointer to the payload
|
||||
* @param cfg_file a pointer to a non-default configuration
|
||||
* file to be used.
|
||||
*/
|
||||
bool post_record_http(char *headers[], char *body);
|
||||
bool post_record_http(char *headers[], char *body, char *cfg_file);
|
||||
|
||||
/**
|
||||
* Pointer to function to isolate backend call during
|
||||
@@ -110,7 +117,7 @@ bool post_record_http(char *headers[], char *body);
|
||||
* @param headers pointer to array of keys
|
||||
* @param body a pinter to payload
|
||||
* */
|
||||
extern bool (*post_record_ptr)(char *headers[], char *body);
|
||||
extern bool (*post_record_ptr)(char *headers[], char *body, char *cfg_file);
|
||||
|
||||
/** Helper functions **/
|
||||
/* rate limit check */
|
||||
|
||||
+5
-13
@@ -33,6 +33,7 @@
|
||||
|
||||
#include "common.h"
|
||||
#include "util.h"
|
||||
#include "log.h"
|
||||
|
||||
bool get_header(const char *haystack, const char *needle, char **line)
|
||||
{
|
||||
@@ -100,10 +101,7 @@ long get_directory_size(const char *dir_path)
|
||||
dir = opendir(dir_path);
|
||||
if (!dir) {
|
||||
ret = -errno;
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "ERR: Error opening spool dir: %s\n",
|
||||
strerror(errno));
|
||||
#endif
|
||||
telem_perror("Error opening spool dir");
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -113,19 +111,15 @@ long get_directory_size(const char *dir_path)
|
||||
}
|
||||
ret = asprintf(&file_path, "%s/%s", dir_path, de->d_name);
|
||||
if (ret < 0) {
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "CRIT: Cannot allocate memory\n");
|
||||
#endif
|
||||
telem_log(LOG_CRIT, "CRIT: Cannot allocate memory\n");
|
||||
closedir(dir);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
ret = lstat(file_path, &buf);
|
||||
if (ret < 0) {
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "ERR: Could not stat file %s: %s\n",
|
||||
telem_log(LOG_ERR, "Could not stat file %s: %s\n",
|
||||
file_path, strerror(errno));
|
||||
#endif
|
||||
} else {
|
||||
total_size += (buf.st_blocks * 512);
|
||||
}
|
||||
@@ -204,9 +198,7 @@ int validate_classification(char *classification)
|
||||
}
|
||||
|
||||
if (slashes != 2) {
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "ERR: Classification string should have two /s.\n");
|
||||
#endif
|
||||
telem_log(LOG_ERR, "Classification string should have two /s.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
+53
-9
@@ -40,7 +40,7 @@ START_TEST(check_read_valid_config)
|
||||
ck_assert_str_eq(config.strValues[CONF_SPOOL_DIR], "/tmp/spool");
|
||||
ck_assert_int_eq(config.intValues[CONF_RECORD_EXPIRY], 1200);
|
||||
ck_assert_int_eq(config.intValues[CONF_SPOOL_MAX_SIZE], 1024);
|
||||
ck_assert_int_eq(config.intValues[CONF_SPOOL_PROCESS_TIME], 900);
|
||||
ck_assert_int_eq(config.intValues[CONF_SPOOL_PROCESS_TIME], 180);
|
||||
ck_assert_int_eq(config.intValues[CONF_RECORD_BURST_LIMIT], 100);
|
||||
ck_assert_int_eq(config.intValues[CONF_RECORD_WINDOW_LENGTH], 15);
|
||||
ck_assert_int_eq(config.intValues[CONF_BYTE_BURST_LIMIT], 1000);
|
||||
@@ -55,18 +55,61 @@ START_TEST(check_read_valid_config)
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST(check_read_valid_config_defaults)
|
||||
START_TEST(check_default_config)
|
||||
{
|
||||
char *config_file = TOPSRCDIR "/src/data/example.conf";
|
||||
configuration config = { { 0 }, { 0 }, { 0 }, false, NULL };
|
||||
int ret = set_default_config_values(&config);
|
||||
ck_assert(ret == true);
|
||||
|
||||
ck_assert_str_eq(config.strValues[CONF_SERVER_ADDR], DEFAULT_SERVER_ADDR);
|
||||
ck_assert_str_eq(config.strValues[CONF_SOCKET_PATH], DEFAULT_SOCKET_PATH);
|
||||
ck_assert_str_eq(config.strValues[CONF_SPOOL_DIR], DEFAULT_SPOOL_DIR);
|
||||
ck_assert_str_eq(config.strValues[CONF_RATE_LIMIT_STRATEGY], DEFAULT_RATE_LIMIT_STRATEGY);
|
||||
ck_assert_str_eq(config.strValues[CONF_CAINFO], DEFAULT_CAINFO);
|
||||
ck_assert_str_eq(config.strValues[CONF_TIDHEADER], DEFAULT_TIDHEADER);
|
||||
|
||||
ck_assert_int_eq(config.intValues[CONF_RECORD_EXPIRY], DEFAULT_RECORD_EXPIRY);
|
||||
ck_assert_int_eq(config.intValues[CONF_SPOOL_MAX_SIZE], DEFAULT_SPOOL_MAX_SIZE);
|
||||
ck_assert_int_eq(config.intValues[CONF_SPOOL_PROCESS_TIME], DEFAULT_SPOOL_PROCESS_TIME);
|
||||
ck_assert_int_eq(config.intValues[CONF_RECORD_WINDOW_LENGTH], DEFAULT_RECORD_WINDOW_LENGTH);
|
||||
ck_assert_int_eq(config.intValues[CONF_BYTE_WINDOW_LENGTH], DEFAULT_BYTE_WINDOW_LENGTH);
|
||||
ck_assert_int_eq(config.intValues[CONF_RECORD_BURST_LIMIT], DEFAULT_RECORD_BURST_LIMIT);
|
||||
ck_assert_int_eq(config.intValues[CONF_BYTE_BURST_LIMIT], DEFAULT_BYTE_BURST_LIMIT);
|
||||
|
||||
ck_assert(config.boolValues[CONF_RATE_LIMIT_ENABLED] == DEFAULT_RATE_LIMIT_ENABLED);
|
||||
ck_assert(config.boolValues[CONF_DAEMON_RECYCLING_ENABLED] == DEFAULT_DAEMON_RECYCLING_ENABLED);
|
||||
ck_assert(config.boolValues[CONF_RECORD_RETENTION_ENABLED] == DEFAULT_RECORD_RETENTION_ENABLED);
|
||||
ck_assert(config.boolValues[CONF_RECORD_SERVER_DELIVERY_ENABLED] == DEFAULT_RECORD_SERVER_DELIVERY_ENABLED);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST(check_layered_config)
|
||||
{
|
||||
char *config_file = TOPSRCDIR "/src/data/example.2.conf";
|
||||
configuration config = { { 0 }, { 0 }, { 0 }, false, NULL };
|
||||
|
||||
int ret = read_config_from_file(config_file, &config);
|
||||
ck_assert(ret == true);
|
||||
|
||||
// RECORD_RETENTION_ENABLED_DEFAULT = false
|
||||
ck_assert(config.boolValues[CONF_RECORD_RETENTION_ENABLED] == RECORD_RETENTION_ENABLED_DEFAULT);
|
||||
// RECORD_SERVER_DELIVERY_ENABLED_DEFAULT = true
|
||||
ck_assert(config.boolValues[CONF_RECORD_SERVER_DELIVERY_ENABLED] == RECORD_SERVER_DELIVERY_ENABLED_DEFAULT);
|
||||
ck_assert_str_eq(config.strValues[CONF_SERVER_ADDR], "http://127.0.0.1");
|
||||
ck_assert_str_eq(config.strValues[CONF_SOCKET_PATH], DEFAULT_SOCKET_PATH);
|
||||
ck_assert_str_eq(config.strValues[CONF_SPOOL_DIR], DEFAULT_SPOOL_DIR);
|
||||
ck_assert_str_eq(config.strValues[CONF_RATE_LIMIT_STRATEGY], DEFAULT_RATE_LIMIT_STRATEGY);
|
||||
ck_assert_str_eq(config.strValues[CONF_CAINFO], "/tmp/cacert.crt");
|
||||
ck_assert_str_eq(config.strValues[CONF_TIDHEADER], DEFAULT_TIDHEADER);
|
||||
|
||||
ck_assert_int_eq(config.intValues[CONF_RECORD_EXPIRY], DEFAULT_RECORD_EXPIRY);
|
||||
ck_assert_int_eq(config.intValues[CONF_SPOOL_MAX_SIZE], DEFAULT_SPOOL_MAX_SIZE);
|
||||
ck_assert_int_eq(config.intValues[CONF_SPOOL_PROCESS_TIME], DEFAULT_SPOOL_PROCESS_TIME);
|
||||
ck_assert_int_eq(config.intValues[CONF_RECORD_WINDOW_LENGTH], DEFAULT_RECORD_WINDOW_LENGTH);
|
||||
ck_assert_int_eq(config.intValues[CONF_BYTE_WINDOW_LENGTH], DEFAULT_BYTE_WINDOW_LENGTH);
|
||||
ck_assert_int_eq(config.intValues[CONF_RECORD_BURST_LIMIT], DEFAULT_RECORD_BURST_LIMIT);
|
||||
ck_assert_int_eq(config.intValues[CONF_BYTE_BURST_LIMIT], DEFAULT_BYTE_BURST_LIMIT);
|
||||
|
||||
ck_assert(config.boolValues[CONF_RATE_LIMIT_ENABLED] == DEFAULT_RATE_LIMIT_ENABLED);
|
||||
ck_assert(config.boolValues[CONF_DAEMON_RECYCLING_ENABLED] == DEFAULT_DAEMON_RECYCLING_ENABLED);
|
||||
ck_assert(config.boolValues[CONF_RECORD_RETENTION_ENABLED] == DEFAULT_RECORD_RETENTION_ENABLED);
|
||||
ck_assert(config.boolValues[CONF_RECORD_SERVER_DELIVERY_ENABLED] == DEFAULT_RECORD_SERVER_DELIVERY_ENABLED);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
@@ -94,7 +137,7 @@ START_TEST(check_config_initialised)
|
||||
ck_assert_str_eq(spool_dir_config(), "/tmp/spool");
|
||||
ck_assert_int_eq(record_expiry_config(), 1200);
|
||||
ck_assert_int_eq(spool_max_size_config(), 1024);
|
||||
ck_assert_int_eq(spool_process_time_config(), 900);
|
||||
ck_assert_int_eq(spool_process_time_config(), 180);
|
||||
ck_assert_int_eq(record_burst_limit_config(), 100);
|
||||
ck_assert_int_eq(record_window_length_config(), 15);
|
||||
ck_assert_int_eq(byte_burst_limit_config(), 1000);
|
||||
@@ -117,7 +160,8 @@ Suite *config_suite(void)
|
||||
TCase *t = tcase_create("config");
|
||||
tcase_add_test(t, check_read_config_for_invalid_file);
|
||||
tcase_add_test(t, check_read_valid_config);
|
||||
tcase_add_test(t, check_read_valid_config_defaults);
|
||||
tcase_add_test(t, check_default_config);
|
||||
tcase_add_test(t, check_layered_config);
|
||||
tcase_add_test(t, check_read_valid_config_record_retention_delivery);
|
||||
tcase_add_test(t, check_config_initialised);
|
||||
|
||||
|
||||
+7
-7
@@ -27,19 +27,19 @@
|
||||
|
||||
TelemPostDaemon tdaemon;
|
||||
|
||||
bool dummy_post(char *headers[], char *body)
|
||||
bool dummy_post(char *headers[], char *body, char *cfg_file)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool (*post_record_ptr)(char *headers[], char *body) = dummy_post;
|
||||
bool (*post_record_ptr)(char *headers[], char *body, char *cfg_file) = dummy_post;
|
||||
|
||||
void setup(void)
|
||||
{
|
||||
char *config_file = ABSTOPSRCDIR "/src/data/example.conf";
|
||||
set_config_file(config_file);
|
||||
|
||||
initialize_daemon(&tdaemon);
|
||||
initialize_post_daemon(&tdaemon);
|
||||
}
|
||||
|
||||
START_TEST(check_daemon_is_initialized)
|
||||
@@ -62,7 +62,7 @@ START_TEST(check_handle_client_with_no_data)
|
||||
bool success;
|
||||
char *filename = ABSTOPSRCDIR "/tests/telempostd/empty_message";
|
||||
|
||||
success = process_staged_record(filename, &tdaemon);
|
||||
success = process_staged_record(filename, false, &tdaemon);
|
||||
// Return true to remove corrupted record
|
||||
ck_assert(success == true);
|
||||
}
|
||||
@@ -75,7 +75,7 @@ START_TEST(check_handle_client_with_incorrect_data)
|
||||
bool success;
|
||||
char *filename = ABSTOPSRCDIR "/tests/telempostd/incorrect_message";
|
||||
|
||||
success = process_staged_record(filename, &tdaemon);
|
||||
success = process_staged_record(filename, false, &tdaemon);
|
||||
// Return true to remove corrupted record
|
||||
ck_assert(success == true);
|
||||
}
|
||||
@@ -88,7 +88,7 @@ START_TEST(check_process_record_with_correct_size_and_data)
|
||||
bool success;
|
||||
char *filename = ABSTOPSRCDIR "/tests/telempostd/correct_message";
|
||||
|
||||
success = process_staged_record(filename, &tdaemon);
|
||||
success = process_staged_record(filename, false, &tdaemon);
|
||||
ck_assert(success == true);
|
||||
}
|
||||
END_TEST
|
||||
@@ -100,7 +100,7 @@ START_TEST(check_process_record_with_incorrect_headers)
|
||||
bool success;
|
||||
char *filename = ABSTOPSRCDIR "/tests/telempostd/incorrect_headers";
|
||||
|
||||
success = process_staged_record(filename, &tdaemon);
|
||||
success = process_staged_record(filename, false, &tdaemon);
|
||||
// Return true to remove corrupted record
|
||||
ck_assert(success == true);
|
||||
}
|
||||
|
||||
+1
-1
@@ -58,7 +58,7 @@ void setup(void)
|
||||
char *config_file = ABSTOPSRCDIR "/src/data/example.conf";
|
||||
set_config_file(config_file);
|
||||
|
||||
initialize_daemon(&tdaemon);
|
||||
initialize_probe_daemon(&tdaemon);
|
||||
}
|
||||
|
||||
START_TEST(check_daemon_is_initialized)
|
||||
|
||||
+8
-26
@@ -29,36 +29,18 @@
|
||||
#include "src/probes/klog_scanner.h"
|
||||
#include "src/probes/oops_parser.h"
|
||||
|
||||
char reason[1024];
|
||||
nc_string *bt;
|
||||
nc_string *pl;
|
||||
static char reason[1024];
|
||||
static nc_string *pl;
|
||||
|
||||
void callback_func(struct oops_log_msg *msg)
|
||||
{
|
||||
strncpy(reason, msg->lines[0], strlen(msg->lines[0]) + 1);
|
||||
|
||||
pl = parse_payload(msg);
|
||||
}
|
||||
|
||||
void setup(char *oopsfile)
|
||||
{
|
||||
char *buf = NULL;
|
||||
int buflen = 0;
|
||||
|
||||
oops_parser_cleanup();
|
||||
|
||||
buf = readfile(oopsfile);
|
||||
buflen = (int)getbuflen();
|
||||
|
||||
oops_parser_init(write_oops_to_file);
|
||||
|
||||
// Allocate space to write the oops file to
|
||||
if (allocate_filespace() < 0) {
|
||||
telem_log(LOG_ERR, "%s\n", strerror(errno));
|
||||
exit(EXIT_FAILURE);
|
||||
size_t len = strlen(msg->lines[0]) + 1;
|
||||
if (len > sizeof(reason)) {
|
||||
len = sizeof(reason);
|
||||
}
|
||||
|
||||
split_buf_by_line(buf, buflen);
|
||||
memcpy(reason, msg->lines[0], len);
|
||||
reason[sizeof(reason) - 1] = 0;
|
||||
pl = parse_payload(msg);
|
||||
}
|
||||
|
||||
void setup_payload(char *oopsfile)
|
||||
|
||||
@@ -33,6 +33,13 @@ dist_check_SCRIPTS = \
|
||||
@CHECK_LIBS@ \
|
||||
$(top_builddir)/src/libtelem-shared.la
|
||||
|
||||
if HAVE_SYSTEMD_JOURNAL
|
||||
if LOG_SYSTEMD
|
||||
%C%_check_config_CFLAGS += $(SYSTEMD_JOURNAL_CFLAGS)
|
||||
%C%_check_config_LDADD += $(SYSTEMD_JOURNAL_LIBS)
|
||||
endif
|
||||
endif
|
||||
|
||||
%C%_check_probd_SOURCES = \
|
||||
%D%/check_probd.c \
|
||||
src/telemdaemon.c \
|
||||
@@ -136,6 +143,7 @@ EXTRA_DIST += \
|
||||
@CHECK_CFLAGS@
|
||||
%C%_check_probes_LDADD = \
|
||||
@CHECK_LIBS@ \
|
||||
$(top_builddir)/src/libtelemetry.la \
|
||||
$(top_builddir)/src/libtelem-shared.la
|
||||
|
||||
if LOG_SYSTEMD
|
||||
@@ -179,6 +187,13 @@ EXTRA_DIST += \
|
||||
%C%_check_journal_LDADD = \
|
||||
@CHECK_LIBS@
|
||||
|
||||
if HAVE_SYSTEMD_JOURNAL
|
||||
if LOG_SYSTEMD
|
||||
%C%_check_journal_CFLAGS += $(SYSTEMD_JOURNAL_CFLAGS)
|
||||
%C%_check_journal_LDADD += $(SYSTEMD_JOURNAL_LIBS)
|
||||
endif
|
||||
endif
|
||||
|
||||
%C%_check_libtelemetry_SOURCES = \
|
||||
%D%/check_libtelemetry.c \
|
||||
src/configuration.h \
|
||||
@@ -194,4 +209,11 @@ EXTRA_DIST += \
|
||||
$(top_builddir)/src/libtelemetry.la \
|
||||
$(top_builddir)/src/libtelem-shared.la
|
||||
|
||||
if HAVE_SYSTEMD_JOURNAL
|
||||
if LOG_SYSTEMD
|
||||
%C%_check_libtelemetry_CFLAGS += $(SYSTEMD_JOURNAL_CFLAGS)
|
||||
%C%_check_libtelemetry_LDADD += $(SYSTEMD_JOURNAL_LIBS)
|
||||
endif
|
||||
endif
|
||||
|
||||
# vim: filetype=automake tabstop=8 shiftwidth=8 noexpandtab
|
||||
|
||||
Reference in New Issue
Block a user