diff options
author | thiagoftsm <thiagoftsm@gmail.com> | 2023-07-06 15:46:48 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-07-06 15:46:48 +0000 |
commit | e0f388c43f3144abb871cce2a7b44e85a36de48f (patch) | |
tree | cf41e5ae11ae7d0ad5ec0b49f5f4ac4531189eb3 /collectors/apps.plugin | |
parent | 3cc220ff5e38ef5cd96a64596c7e0c370d0fa074 (diff) |
Rename generic `error` function (#15296)
Diffstat (limited to 'collectors/apps.plugin')
-rw-r--r-- | collectors/apps.plugin/apps_plugin.c | 97 |
1 files changed, 51 insertions, 46 deletions
diff --git a/collectors/apps.plugin/apps_plugin.c b/collectors/apps.plugin/apps_plugin.c index 15c779ebde..ce7e24c113 100644 --- a/collectors/apps.plugin/apps_plugin.c +++ b/collectors/apps.plugin/apps_plugin.c @@ -666,7 +666,7 @@ int read_user_or_group_ids(struct user_or_group_ids *ids, struct timespec *last_ } else { if(unlikely(avl_insert(&ids->index, (avl_t *) user_or_group_id) != (void *) user_or_group_id)) { - error("INTERNAL ERROR: duplicate indexing of id during realloc"); + netdata_log_error("INTERNAL ERROR: duplicate indexing of id during realloc"); }; user_or_group_id->next = ids->root; @@ -682,7 +682,7 @@ int read_user_or_group_ids(struct user_or_group_ids *ids, struct timespec *last_ while(user_or_group_id) { if(unlikely(!user_or_group_id->updated)) { if(unlikely((struct user_or_group_id *)avl_remove(&ids->index, (avl_t *) user_or_group_id) != user_or_group_id)) - error("INTERNAL ERROR: removal of unused id from index, removed a different id"); + netdata_log_error("INTERNAL ERROR: removal of unused id from index, removed a different id"); if(prev_user_id) prev_user_id->next = user_or_group_id->next; @@ -947,7 +947,7 @@ static int read_apps_groups_conf(const char *path, const char *file) // add this target struct target *n = get_apps_groups_target(s, w, name); if(!n) { - error("Cannot create target '%s' (line %zu, word %zu)", s, line, word); + netdata_log_error("Cannot create target '%s' (line %zu, word %zu)", s, line, word); continue; } @@ -997,7 +997,7 @@ static inline void del_pid_entry(pid_t pid) { struct pid_stat *p = all_pids[pid]; if(unlikely(!p)) { - error("attempted to free pid %d that is not allocated.", pid); + netdata_log_error("attempted to free pid %d that is not allocated.", pid); return; } @@ -1035,7 +1035,7 @@ static inline void del_pid_entry(pid_t pid) { static inline int managed_log(struct pid_stat *p, uint32_t log, int status) { if(unlikely(!status)) { - // error("command failed log %u, errno %d", log, errno); + // netdata_log_error("command failed log %u, errno %d", log, errno); if(unlikely(debug_enabled || errno != ENOENT)) { if(unlikely(debug_enabled || !(p->log_thrown & log))) { @@ -1043,33 +1043,33 @@ static inline int managed_log(struct pid_stat *p, uint32_t log, int status) { switch(log) { case PID_LOG_IO: #ifdef __FreeBSD__ - error("Cannot fetch process %d I/O info (command '%s')", p->pid, p->comm); + netdata_log_error("Cannot fetch process %d I/O info (command '%s')", p->pid, p->comm); #else - error("Cannot process %s/proc/%d/io (command '%s')", netdata_configured_host_prefix, p->pid, p->comm); + netdata_log_error("Cannot process %s/proc/%d/io (command '%s')", netdata_configured_host_prefix, p->pid, p->comm); #endif break; case PID_LOG_STATUS: #ifdef __FreeBSD__ - error("Cannot fetch process %d status info (command '%s')", p->pid, p->comm); + netdata_log_error("Cannot fetch process %d status info (command '%s')", p->pid, p->comm); #else - error("Cannot process %s/proc/%d/status (command '%s')", netdata_configured_host_prefix, p->pid, p->comm); + netdata_log_error("Cannot process %s/proc/%d/status (command '%s')", netdata_configured_host_prefix, p->pid, p->comm); #endif break; case PID_LOG_CMDLINE: #ifdef __FreeBSD__ - error("Cannot fetch process %d command line (command '%s')", p->pid, p->comm); + netdata_log_error("Cannot fetch process %d command line (command '%s')", p->pid, p->comm); #else - error("Cannot process %s/proc/%d/cmdline (command '%s')", netdata_configured_host_prefix, p->pid, p->comm); + netdata_log_error("Cannot process %s/proc/%d/cmdline (command '%s')", netdata_configured_host_prefix, p->pid, p->comm); #endif break; case PID_LOG_FDS: #ifdef __FreeBSD__ - error("Cannot fetch process %d files (command '%s')", p->pid, p->comm); + netdata_log_error("Cannot fetch process %d files (command '%s')", p->pid, p->comm); #else - error("Cannot process entries in %s/proc/%d/fd (command '%s')", netdata_configured_host_prefix, p->pid, p->comm); + netdata_log_error("Cannot process entries in %s/proc/%d/fd (command '%s')", netdata_configured_host_prefix, p->pid, p->comm); #endif break; @@ -1077,7 +1077,7 @@ static inline int managed_log(struct pid_stat *p, uint32_t log, int status) { break; default: - error("unhandled error for pid %d, command '%s'", p->pid, p->comm); + netdata_log_error("unhandled error for pid %d, command '%s'", p->pid, p->comm); break; } } @@ -1085,7 +1085,7 @@ static inline int managed_log(struct pid_stat *p, uint32_t log, int status) { errno = 0; } else if(unlikely(p->log_thrown & log)) { - // error("unsetting log %u on pid %d", log, p->pid); + // netdata_log_error("unsetting log %u on pid %d", log, p->pid); p->log_thrown &= ~log; } @@ -1733,7 +1733,7 @@ cleanup: int file_descriptor_compare(void* a, void* b) { #ifdef NETDATA_INTERNAL_CHECKS if(((struct file_descriptor *)a)->magic != 0x0BADCAFE || ((struct file_descriptor *)b)->magic != 0x0BADCAFE) - error("Corrupted index data detected. Please report this."); + netdata_log_error("Corrupted index data detected. Please report this."); #endif /* NETDATA_INTERNAL_CHECKS */ if(((struct file_descriptor *)a)->hash < ((struct file_descriptor *)b)->hash) @@ -1777,7 +1777,7 @@ static inline void file_descriptor_not_used(int id) #ifdef NETDATA_INTERNAL_CHECKS if(all_files[id].magic != 0x0BADCAFE) { - error("Ignoring request to remove empty file id %d.", id); + netdata_log_error("Ignoring request to remove empty file id %d.", id); return; } #endif /* NETDATA_INTERNAL_CHECKS */ @@ -1791,7 +1791,7 @@ static inline void file_descriptor_not_used(int id) debug_log(" >> slot %d is empty.", id); if(unlikely(file_descriptor_remove(&all_files[id]) != (void *)&all_files[id])) - error("INTERNAL ERROR: removal of unused fd from index, removed a different fd"); + netdata_log_error("INTERNAL ERROR: removal of unused fd from index, removed a different fd"); #ifdef NETDATA_INTERNAL_CHECKS all_files[id].magic = 0x00000000; @@ -1800,9 +1800,14 @@ static inline void file_descriptor_not_used(int id) } } else - error("Request to decrease counter of fd %d (%s), while the use counter is 0", id, all_files[id].name); + netdata_log_error("Request to decrease counter of fd %d (%s), while the use counter is 0", + id, + all_files[id].name); } - else error("Request to decrease counter of fd %d, which is outside the array size (1 to %d)", id, all_files_size); + else + netdata_log_error("Request to decrease counter of fd %d, which is outside the array size (1 to %d)", + id, + all_files_size); } static inline void all_files_grow() { @@ -1824,7 +1829,7 @@ static inline void all_files_grow() { for(i = 0; i < all_files_size; i++) { if(!all_files[i].count) continue; if(unlikely(file_descriptor_add(&all_files[i]) != (void *)&all_files[i])) - error("INTERNAL ERROR: duplicate indexing of fd during realloc."); + netdata_log_error("INTERNAL ERROR: duplicate indexing of fd during realloc."); } debug_log(" >> re-indexing done."); @@ -1865,7 +1870,7 @@ static inline int file_descriptor_set_on_empty_slot(const char *name, uint32_t h #ifdef NETDATA_INTERNAL_CHECKS if(all_files[c].magic == 0x0BADCAFE && all_files[c].name && file_descriptor_find(all_files[c].name, all_files[c].hash)) - error("fd on position %d is not cleared properly. It still has %s in it.", c, all_files[c].name); + netdata_log_error("fd on position %d is not cleared properly. It still has %s in it.", c, all_files[c].name); #endif /* NETDATA_INTERNAL_CHECKS */ debug_log(" >> %s fd position %d for %s (last name: %s)", all_files[c].name?"re-using":"using", c, name, all_files[c].name); @@ -1896,7 +1901,7 @@ static inline int file_descriptor_set_on_empty_slot(const char *name, uint32_t h all_files[c].magic = 0x0BADCAFE; #endif /* NETDATA_INTERNAL_CHECKS */ if(unlikely(file_descriptor_add(&all_files[c]) != (void *)&all_files[c])) - error("INTERNAL ERROR: duplicate indexing of fd."); + netdata_log_error("INTERNAL ERROR: duplicate indexing of fd."); debug_log("using fd position %d (name: %s)", c, all_files[c].name); @@ -2014,13 +2019,13 @@ static inline int read_pid_file_descriptors(struct pid_stat *p, void *ptr) { mib[3] = p->pid; if (unlikely(sysctl(mib, 4, NULL, &size, NULL, 0))) { - error("sysctl error: Can't get file descriptors data size for pid %d", p->pid); + netdata_log_error("sysctl error: Can't get file descriptors data size for pid %d", p->pid); return 0; } if (likely(size > 0)) fdsbuf = reallocz(fdsbuf, size); if (unlikely(sysctl(mib, 4, fdsbuf, &size, NULL, 0))) { - error("sysctl error: Can't get file descriptors data for pid %d", p->pid); + netdata_log_error("sysctl error: Can't get file descriptors data for pid %d", p->pid); return 0; } @@ -2193,7 +2198,7 @@ static inline int read_pid_file_descriptors(struct pid_stat *p, void *ptr) { // cannot read the link if(debug_enabled || (p->target && p->target->debug_enabled)) - error("Cannot read link %s", p->fds[fdid].filename); + netdata_log_error("Cannot read link %s", p->fds[fdid].filename); if(unlikely(p->fds[fdid].fd < 0)) { file_descriptor_not_used(-p->fds[fdid].fd); @@ -2524,7 +2529,7 @@ static inline void link_all_processes_to_their_parents(void) { } else { p->parent = NULL; - error("pid %d %s states parent %d, but the later does not exist.", p->pid, p->comm, p->ppid); + netdata_log_error("pid %d %s states parent %d, but the later does not exist.", p->pid, p->comm, p->ppid); } } } @@ -2562,7 +2567,7 @@ static int compar_pid(const void *pid1, const void *pid2) { static inline int collect_data_for_pid(pid_t pid, void *ptr) { if(unlikely(pid < 0 || pid > pid_max)) { - error("Invalid pid %d read (expected %d to %d). Ignoring process.", pid, 0, pid_max); + netdata_log_error("Invalid pid %d read (expected %d to %d). Ignoring process.", pid, 0, pid_max); return 0; } @@ -2581,7 +2586,7 @@ static inline int collect_data_for_pid(pid_t pid, void *ptr) { // check its parent pid if(unlikely(p->ppid < 0 || p->ppid > pid_max)) { - error("Pid %d (command '%s') states invalid parent pid %d. Using 0.", pid, p->comm, p->ppid); + netdata_log_error("Pid %d (command '%s') states invalid parent pid %d. Using 0.", pid, p->comm, p->ppid); p->ppid = 0; } @@ -2633,7 +2638,7 @@ static int collect_data_for_all_processes(void) { int mib[3] = { CTL_KERN, KERN_PROC, KERN_PROC_PROC }; if (unlikely(sysctl(mib, 3, NULL, &new_procbase_size, NULL, 0))) { - error("sysctl error: Can't get processes data size"); + netdata_log_error("sysctl error: Can't get processes data size"); return 0; } @@ -2653,7 +2658,7 @@ static int collect_data_for_all_processes(void) { // get the processes from the system if (unlikely(sysctl(mib, 3, procbase, &new_procbase_size, NULL, 0))) { - error("sysctl error: Can't get processes data"); + netdata_log_error("sysctl error: Can't get processes data"); return 0; } @@ -2681,7 +2686,7 @@ static int collect_data_for_all_processes(void) { #if (ALL_PIDS_ARE_READ_INSTANTLY == 0) if(unlikely(slc != all_pids_count)) { - error("Internal error: I was thinking I had %zu processes in my arrays, but it seems there are %zu.", all_pids_count, slc); + netdata_log_error("Internal error: I was thinking I had %zu processes in my arrays, but it seems there are %zu.", all_pids_count, slc); all_pids_count = slc; } @@ -3105,7 +3110,7 @@ static inline void aggregate_pid_on_target(struct target *w, struct pid_stat *p, } if(unlikely(!w)) { - error("pid %d %s was left without a target!", p->pid, p->comm); + netdata_log_error("pid %d %s was left without a target!", p->pid, p->comm); return; } @@ -4187,7 +4192,7 @@ static void parse_args(int argc, char **argv) exit(1); } - error("Cannot understand option %s", argv[i]); + netdata_log_error("Cannot understand option %s", argv[i]); exit(1); } @@ -4197,7 +4202,7 @@ static void parse_args(int argc, char **argv) netdata_log_info("Cannot read process groups configuration file '%s/apps_groups.conf'. Will try '%s/apps_groups.conf'", user_config_dir, stock_config_dir); if(read_apps_groups_conf(stock_config_dir, "groups")) { - error("Cannot read process groups '%s/apps_groups.conf'. There are no internal defaults. Failing.", stock_config_dir); + netdata_log_error("Cannot read process groups '%s/apps_groups.conf'. There are no internal defaults. Failing.", stock_config_dir); exit(1); } else @@ -4223,7 +4228,7 @@ static int am_i_running_as_root() { static int check_capabilities() { cap_t caps = cap_get_proc(); if(!caps) { - error("Cannot get current capabilities."); + netdata_log_error("Cannot get current capabilities."); return 0; } else if(debug_enabled) @@ -4233,12 +4238,12 @@ static int check_capabilities() { cap_flag_value_t cfv = CAP_CLEAR; if(cap_get_flag(caps, CAP_DAC_READ_SEARCH, CAP_EFFECTIVE, &cfv) == -1) { - error("Cannot find if CAP_DAC_READ_SEARCH is effective."); + netdata_log_error("Cannot find if CAP_DAC_READ_SEARCH is effective."); ret = 0; } else { if(cfv != CAP_SET) { - error("apps.plugin should run with CAP_DAC_READ_SEARCH."); + netdata_log_error("apps.plugin should run with CAP_DAC_READ_SEARCH."); ret = 0; } else if(debug_enabled) @@ -4247,12 +4252,12 @@ static int check_capabilities() { cfv = CAP_CLEAR; if(cap_get_flag(caps, CAP_SYS_PTRACE, CAP_EFFECTIVE, &cfv) == -1) { - error("Cannot find if CAP_SYS_PTRACE is effective."); + netdata_log_error("Cannot find if CAP_SYS_PTRACE is effective."); ret = 0; } else { if(cfv != CAP_SET) { - error("apps.plugin should run with CAP_SYS_PTRACE."); + netdata_log_error("apps.plugin should run with CAP_SYS_PTRACE."); ret = 0; } else if(debug_enabled) @@ -5240,7 +5245,7 @@ void *reader_main(void *arg __maybe_unused) { char *function = get_word(words, num_words, 3); if(!transaction || !*transaction || !timeout_s || !*timeout_s || !function || !*function) { - error("Received incomplete %s (transaction = '%s', timeout = '%s', function = '%s'). Ignoring it.", + netdata_log_error("Received incomplete %s (transaction = '%s', timeout = '%s', function = '%s'). Ignoring it.", keyword, transaction?transaction:"(unset)", timeout_s?timeout_s:"(unset)", @@ -5266,12 +5271,12 @@ void *reader_main(void *arg __maybe_unused) { } } else - error("Received unknown command: %s", keyword?keyword:"(unset)"); + netdata_log_error("Received unknown command: %s", keyword?keyword:"(unset)"); } if(!s || feof(stdin) || ferror(stdin)) { apps_plugin_exit = true; - error("Received error on stdin."); + netdata_log_error("Received error on stdin."); } exit(1); @@ -5351,14 +5356,14 @@ int main(int argc, char **argv) { if(!check_capabilities() && !am_i_running_as_root() && !check_proc_1_io()) { uid_t uid = getuid(), euid = geteuid(); #ifdef HAVE_CAPABILITY - error("apps.plugin should either run as root (now running with uid %u, euid %u) or have special capabilities. " + netdata_log_error("apps.plugin should either run as root (now running with uid %u, euid %u) or have special capabilities. " "Without these, apps.plugin cannot report disk I/O utilization of other processes. " "To enable capabilities run: sudo setcap cap_dac_read_search,cap_sys_ptrace+ep %s; " "To enable setuid to root run: sudo chown root:netdata %s; sudo chmod 4750 %s; " , uid, euid, argv[0], argv[0], argv[0] ); #else - error("apps.plugin should either run as root (now running with uid %u, euid %u) or have special capabilities. " + netdata_log_error("apps.plugin should either run as root (now running with uid %u, euid %u) or have special capabilities. " "Without these, apps.plugin cannot report disk I/O utilization of other processes. " "Your system does not support capabilities. " "To enable setuid to root run: sudo chown root:netdata %s; sudo chmod 4750 %s; " @@ -5419,7 +5424,7 @@ int main(int argc, char **argv) { get_MemTotal(); if(!collect_data_for_all_processes()) { - error("Cannot collect /proc data for running processes. Disabling apps.plugin..."); + netdata_log_error("Cannot collect /proc data for running processes. Disabling apps.plugin..."); printf("DISABLE\n"); netdata_mutex_unlock(&mutex); netdata_thread_cancel(reader_thread); |