From 57db31a2c8659d91b19352c76fe91fadf66fb914 Mon Sep 17 00:00:00 2001 From: Juro Bystricky Date: Tue, 22 Jan 2019 17:39:56 -0800 Subject: [PATCH] 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 --- scripts/telemctl | 2 +- src/data/local.mk | 6 +++ src/data/python-probe.path.in | 9 ++++ src/data/telemetrics-dirs.conf.in | 2 +- src/probes/python-probe.c | 68 ------------------------------- 5 files changed, 17 insertions(+), 70 deletions(-) create mode 100644 src/data/python-probe.path.in diff --git a/scripts/telemctl b/scripts/telemctl index 08b5c99..d49bd1c 100755 --- a/scripts/telemctl +++ b/scripts/telemctl @@ -6,7 +6,7 @@ declare -a SPECIAL_UNITS=( telempostd.path klogscanner.service journal-probe.service - python-probe.service + python-probe.path ) declare -a SERVICES=( diff --git a/src/data/local.mk b/src/data/local.mk index 5de993c..2912bda 100644 --- a/src/data/local.mk +++ b/src/data/local.mk @@ -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 \ diff --git a/src/data/python-probe.path.in b/src/data/python-probe.path.in new file mode 100644 index 0000000..30fa344 --- /dev/null +++ b/src/data/python-probe.path.in @@ -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 diff --git a/src/data/telemetrics-dirs.conf.in b/src/data/telemetrics-dirs.conf.in index 922b51f..7b87454 100644 --- a/src/data/telemetrics-dirs.conf.in +++ b/src/data/telemetrics-dirs.conf.in @@ -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 - diff --git a/src/probes/python-probe.c b/src/probes/python-probe.c index c9f14a4..2330972 100644 --- a/src/probes/python-probe.c +++ b/src/probes/python-probe.c @@ -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); }