pythonprobe: don't use inotify

Don't wait for new payload via inotify, let systemd path unit
detect any new payloads in /usr/lib/telemetry/python and start
the pythonprobe service.
Also set the sticky bit for the above folder, preventing users to
modify permissions.

Signed-off-by: Juro Bystricky <juro.bystricky@intel.com>
This commit is contained in:
Juro Bystricky
2019-01-23 20:56:21 -08:00
committed by ajch
parent e20e572fad
commit 57db31a2c8
5 changed files with 17 additions and 70 deletions
+1 -1
View File
@@ -6,7 +6,7 @@ declare -a SPECIAL_UNITS=(
telempostd.path
klogscanner.service
journal-probe.service
python-probe.service
python-probe.path
)
declare -a SERVICES=(
+6
View File
@@ -17,6 +17,7 @@ EXTRA_DIST += \
%D%/bert-probe.service.in \
%D%/journal-probe.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 \
@@ -54,6 +55,7 @@ systemdunit_DATA = \
%D%/bert-probe.service \
%D%/journal-probe.service \
%D%/python-probe.service \
%D%/python-probe.path \
%D%/pstore-probe.service \
%D%/klogscanner.service \
%D%/pstore-clean.service \
@@ -90,6 +92,9 @@ systemdunit_DATA = \
%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) < $< > $@
@@ -114,6 +119,7 @@ clean-local:
%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 \
+9
View File
@@ -0,0 +1,9 @@
[Unit]
Description=Python Probe Daemon Staging
ConditionPathExists=!/etc/telemetrics/opt-out
[Path]
DirectoryNotEmpty=@localstatedir@/lib/telemetry/python
[Install]
WantedBy=multi-user.target
+1 -1
View File
@@ -1,5 +1,5 @@
d @localstatedir@/lib/telemetry 0755 telemetry telemetry -
d @localstatedir@/lib/telemetry/python 0777 telemetry telemetry -
d @localstatedir@/lib/telemetry/python 01777 telemetry telemetry -
d @localstatedir@/spool/telemetry 0750 telemetry telemetry -
d @localstatedir@/log/telemetry 0750 telemetry telemetry -
d @localstatedir@/log/telemetry/records 0750 telemetry telemetry -
-68
View File
@@ -221,71 +221,6 @@ static void drop_privs(void)
assert(getegid() == pw->pw_gid);
}
static 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_MOVED_TO) {
if (event->mask & IN_ISDIR) {
return;
}
#ifdef DEBUG
telem_log(LOG_DEBUG, "New file moved to the monitored location: %s\n", event->name);
#endif
deliver_payload(event->name);
}
}
static void wait_for_payload(void)
{
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, PYTHON_TELEMETRY_DIR, IN_MOVED_TO) == -1) {
telem_perror("Error adding watch to the inotify instance");
}
while (true) {
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;
}
/* 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);
}
}
}
static void print_usage(char *prog)
{
printf("%s: Usage\n", prog);
@@ -354,8 +289,5 @@ int main(int argc, char **argv)
}
closedir(dir);
/* Wait for any new python exception files to appear */
wait_for_payload();
exit(EXIT_SUCCESS);
}