@cryptotaxi247 / netdata-1 / commits / fc1008b7c

apps.plugin fixes (#4267)

Costa Tsaousis committed Sep 23, 2018 at 21:14 UTC fc1008b7cc6d8fe6a5252bf0e7444b94d861ff81
1 file changed +10 -7
src/apps_plugin.c
+10 -7
@@ -895,9 +895,11 @@ static inline int read_proc_pid_cmdline(struct pid_stat *p) {
895 #endif
896
897 cmdline[bytes] = '\0';
898 - for(i = 0; i < bytes ; i++)
898 + for(i = 0; i < bytes ; i++) {
899 if(unlikely(!cmdline[i])) cmdline[i] = ' ';
900 + }
901
902 + if(p->cmdline) freez(p->cmdline);
903 p->cmdline = strdupz(cmdline);
904
905 debug_log("Read file '%s' contents: %s", p->cmdline_filename, p->cmdline);
@@ -906,6 +908,7 @@ static inline int read_proc_pid_cmdline(struct pid_stat *p) {
908
909 cleanup:
910 // copy the command to the command line
911 + if(p->cmdline) freez(p->cmdline);
912 p->cmdline = strdupz(p->comm);
913 return 0;
914 }
@@ -1808,10 +1811,10 @@ static inline int read_pid_file_descriptors(struct pid_stat *p, void *ptr) {
1811 p->fds_size = (size_t)fdid + MAX_SPARE_FDS;
1812 }
1813
1811 - if(unlikely(p->fds[fdid].fd != 0 && de->d_ino != p->fds[fdid].inode)) {
1814 + if(unlikely(p->fds[fdid].fd < 0 && de->d_ino != p->fds[fdid].inode)) {
1815 // inodes do not match, clear the previous entry
1816 inodes_changed_counter++;
1814 - file_descriptor_not_used(p->fds[fdid].fd);
1817 + file_descriptor_not_used(-p->fds[fdid].fd);
1818 clear_pid_fd(&p->fds[fdid]);
1819 }
1820
@@ -1836,8 +1839,8 @@ static inline int read_pid_file_descriptors(struct pid_stat *p, void *ptr) {
1839 if(debug_enabled || (p->target && p->target->debug_enabled))
1840 error("Cannot read link %s", p->fds[fdid].filename);
1841
1839 - if(unlikely(p->fds[fdid].fd)) {
1840 - file_descriptor_not_used(p->fds[fdid].fd);
1842 + if(unlikely(p->fds[fdid].fd < 0)) {
1843 + file_descriptor_not_used(-p->fds[fdid].fd);
1844 clear_pid_fd(&p->fds[fdid]);
1845 }
1846
@@ -1848,10 +1851,10 @@ static inline int read_pid_file_descriptors(struct pid_stat *p, void *ptr) {
1851
1852 uint32_t link_hash = simple_hash(linkname);
1853
1851 - if(unlikely(p->fds[fdid].fd && p->fds[fdid].link_hash != link_hash)) {
1854 + if(unlikely(p->fds[fdid].fd < 0 && p->fds[fdid].link_hash != link_hash)) {
1855 // the link changed
1856 links_changed_counter++;
1854 - file_descriptor_not_used(p->fds[fdid].fd);
1857 + file_descriptor_not_used(-p->fds[fdid].fd);
1858 clear_pid_fd(&p->fds[fdid]);
1859 }
1860