From 5a3f1ba26d09349a610d84547a076d619b2539bd Mon Sep 17 00:00:00 2001 From: hlp_00667687 Date: Thu, 25 Apr 2024 17:21:15 +0800 Subject: [PATCH] avoid use ato* --- src/common/histogram.c | 2 +- src/lib/probe/extend_probe.c | 2 +- src/lib/probe/snooper.c | 4 ++-- src/probes/extends/ebpf.probe/src/ioprobe/ioprobe.c | 2 +- src/probes/extends/ebpf.probe/src/lib/conntrack.c | 8 ++++---- src/probes/extends/ebpf.probe/src/lib/java_support.c | 8 ++++---- src/probes/extends/ebpf.probe/src/lib/tcp.c | 2 +- src/probes/extends/ebpf.probe/src/pgsliprobe/pgsliprobe.c | 2 +- src/probes/system_infos.probe/system_cpu.c | 4 ++-- src/probes/system_infos.probe/system_disk.c | 2 +- src/probes/system_infos.probe/system_os.c | 4 ++-- src/probes/system_infos.probe/system_procs.c | 6 +++--- src/probes/virtualized_infos.probe/virt_proc.c | 4 ++-- 13 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/common/histogram.c b/src/common/histogram.c index cf79899..40ef2ef 100644 --- a/src/common/histogram.c +++ b/src/common/histogram.c @@ -209,7 +209,7 @@ static int resolve_bucket_size(char *buf, char **new_buf) } *pos = '\0'; - ret = atoi(buf); + ret = strtol(buf, NULL, 10); if (ret <= 0) { return -1; } diff --git a/src/lib/probe/extend_probe.c b/src/lib/probe/extend_probe.c index 5580ddb..bb40867 100644 --- a/src/lib/probe/extend_probe.c +++ b/src/lib/probe/extend_probe.c @@ -60,7 +60,7 @@ static int lkup_and_set_probe_pid(struct probe_s *probe) if (exec_cmd((const char *)cmd, pid_str, INT_LEN) < 0) { return -1; } - pid = atoi(pid_str); + pid = strtol(pid_str, NULL, 10); (void)pthread_rwlock_wrlock(&probe->rwlock); probe->pid = pid; (void)pthread_rwlock_unlock(&probe->rwlock); diff --git a/src/lib/probe/snooper.c b/src/lib/probe/snooper.c index 053e80a..917d1f1 100644 --- a/src/lib/probe/snooper.c +++ b/src/lib/probe/snooper.c @@ -1176,7 +1176,7 @@ static int gen_snooper_by_procname(struct probe_s *probe) } } // Well matched - (void)add_snooper_obj_procid(probe, (u32)atoi(entry->d_name)); + (void)add_snooper_obj_procid(probe, strtoul(entry->d_name, NULL, 10)); break; } cmdline_obtained = 0; @@ -1233,7 +1233,7 @@ static int __gen_snooper_by_container(struct probe_s *probe, con_id_element *con LL_FOREACH_SAFE(con_id_list, con_info_elem, tmp) { if (strcmp((const char *)container_id, con_info_elem->con_id) == 0) { // Well matched - (void)add_snooper_obj_procid(probe, (u32)atoi(entry->d_name)); + (void)add_snooper_obj_procid(probe, strtoul(entry->d_name, NULL, 10)); break; } } diff --git a/src/probes/extends/ebpf.probe/src/ioprobe/ioprobe.c b/src/probes/extends/ebpf.probe/src/ioprobe/ioprobe.c index cc75ef4..272a264 100644 --- a/src/probes/extends/ebpf.probe/src/ioprobe/ioprobe.c +++ b/src/probes/extends/ebpf.probe/src/ioprobe/ioprobe.c @@ -599,7 +599,7 @@ static char is_load_probe(char *probe_name) return 0; } - count = atoi((const char *)count_str); + count = strtol(count_str, NULL, 10); return (count > 0) ? 1 : 0; } diff --git a/src/probes/extends/ebpf.probe/src/lib/conntrack.c b/src/probes/extends/ebpf.probe/src/lib/conntrack.c index db56071..d1f7391 100644 --- a/src/probes/extends/ebpf.probe/src/lib/conntrack.c +++ b/src/probes/extends/ebpf.probe/src/lib/conntrack.c @@ -134,7 +134,7 @@ static struct tcp_conntrack_s *parse_conntrack_tcp(const char *s) if (__get_sub_str((const char *)p, "sport=", " ", sub_str, INET6_ADDRSTRLEN)) { goto err; } - conn_tcp->sport = atoi(sub_str); + conn_tcp->sport = strtol(sub_str, NULL, 10); // parse conntrack tcp dst port p = strstr((const char *)p, "dport="); @@ -145,7 +145,7 @@ static struct tcp_conntrack_s *parse_conntrack_tcp(const char *s) if (__get_sub_str((const char *)p, "dport=", " ", sub_str, INET6_ADDRSTRLEN)) { goto err; } - conn_tcp->dport = atoi(sub_str); + conn_tcp->dport = strtol(sub_str, NULL, 10); // parse conntrack tcp reply src ip address p = strstr((const char *)p, "src="); @@ -178,7 +178,7 @@ static struct tcp_conntrack_s *parse_conntrack_tcp(const char *s) if (__get_sub_str((const char *)p, "sport=", " ", sub_str, INET6_ADDRSTRLEN)) { goto err; } - conn_tcp->reply_sport = atoi(sub_str); + conn_tcp->reply_sport = strtol(sub_str, NULL, 10); // parse conntrack tcp reply dst port p = strstr((const char *)p, "dport="); @@ -189,7 +189,7 @@ static struct tcp_conntrack_s *parse_conntrack_tcp(const char *s) if (__get_sub_str((const char *)p, "dport=", " ", sub_str, INET6_ADDRSTRLEN)) { goto err; } - conn_tcp->reply_dport = atoi(sub_str); + conn_tcp->reply_dport = strtol(sub_str, NULL, 10); return conn_tcp; diff --git a/src/probes/extends/ebpf.probe/src/lib/java_support.c b/src/probes/extends/ebpf.probe/src/lib/java_support.c index 0456db2..f8cc134 100644 --- a/src/probes/extends/ebpf.probe/src/lib/java_support.c +++ b/src/probes/extends/ebpf.probe/src/lib/java_support.c @@ -76,13 +76,13 @@ static int _set_effective_id(int pid, struct jvm_process_info *v) size_t size; while (getline(&line, &size, status_file) != -1) { if (strncmp(line, "Uid:", 4) == 0 && strtok(line + 4, "\t ") != NULL) { - eUid = (uid_t)atoi(strtok(NULL, "\t ")); + eUid = strtoul(strtok(NULL, "\t "), NULL, 10); } else if (strncmp(line, "Gid:", 4) == 0 && strtok(line + 4, "\t ") != NULL) { - eGid = (gid_t)atoi(strtok(NULL, "\t ")); + eGid = strtoul(strtok(NULL, "\t "), NULL, 10); } else if (strncmp(line, "NStgid:", 7) == 0) { char* s; for (s = strtok(line + 7, "\t "); s != NULL; s = strtok(NULL, "\t ")) { - nspid = atoi(s); + nspid = strtol(s, NULL, 10); } nspid_found = 1; } @@ -247,7 +247,7 @@ static int _exe_attach_cmd(char *cmd) while(fgets(result_buf, sizeof(result_buf), f) != NULL) { DEBUG("%s\n", result_buf); /* 判断load指令执行返回结果,非0表示失败 */ - if (isdigit(result_buf[0]) && atoi(result_buf) != 0) { + if (isdigit(result_buf[0]) && strtol(result_buf, NULL, 10) != 0) { ERROR("[JAVA_SUPPORT]: attach failed, cmd: %s, ret code: %s\n", cmd, result_buf); (void)pclose(f); return -1; diff --git a/src/probes/extends/ebpf.probe/src/lib/tcp.c b/src/probes/extends/ebpf.probe/src/lib/tcp.c index 572c3e5..664b9f7 100644 --- a/src/probes/extends/ebpf.probe/src/lib/tcp.c +++ b/src/probes/extends/ebpf.probe/src/lib/tcp.c @@ -652,7 +652,7 @@ int get_listen_sock_inode(struct tcp_listen_port *tlp, unsigned long *ino) return -1; } SPLIT_NEWLINE_SYMBOL(line); - *ino = atoi(line); + *ino = strtol(line, NULL, 10); (void)pclose(f); return 0; diff --git a/src/probes/extends/ebpf.probe/src/pgsliprobe/pgsliprobe.c b/src/probes/extends/ebpf.probe/src/pgsliprobe/pgsliprobe.c index c7a680e..a3faacf 100644 --- a/src/probes/extends/ebpf.probe/src/pgsliprobe/pgsliprobe.c +++ b/src/probes/extends/ebpf.probe/src/pgsliprobe/pgsliprobe.c @@ -299,7 +299,7 @@ static int add_bpf_link_by_search_pids() if (fgets(line, LINE_BUF_LEN, f) == NULL) { continue; } - pid = (unsigned int)atoi(line); + pid = strtoul(line, NULL, 10); if (pid <= 0) { continue; } diff --git a/src/probes/system_infos.probe/system_cpu.c b/src/probes/system_infos.probe/system_cpu.c index f90592f..7c1a25f 100644 --- a/src/probes/system_infos.probe/system_cpu.c +++ b/src/probes/system_infos.probe/system_cpu.c @@ -66,7 +66,7 @@ static void get_cpu_time_in_jiff(char *cpu_total_line, u64 *time_total, u64 *tim while (i++ < PROC_STAT_COL_NUM) { retrieved_time = __strtok_r(NULL, " ", &save); - time = atoll(retrieved_time); + time = strtoll(retrieved_time, NULL, 10); *time_total += time; @@ -256,7 +256,7 @@ static int get_cpu_mhz_info(void) token = strtok(NULL, ":"); } if (last_token != NULL && index < cpus_num) { - cur_cpus[index]->mhz = atof(last_token); + cur_cpus[index]->mhz = strtod(last_token, NULL); index++; } } diff --git a/src/probes/system_infos.probe/system_disk.c b/src/probes/system_infos.probe/system_disk.c index f3fc32e..6465697 100644 --- a/src/probes/system_infos.probe/system_disk.c +++ b/src/probes/system_infos.probe/system_disk.c @@ -468,7 +468,7 @@ static int get_diskdev_num(int *num) return -1; } SPLIT_NEWLINE_SYMBOL(line); - *num = atoi(line); + *num = strtol(line, NULL, 10); (void)pclose(f); return 0; } diff --git a/src/probes/system_infos.probe/system_os.c b/src/probes/system_infos.probe/system_os.c index ceb8398..6a7088a 100644 --- a/src/probes/system_infos.probe/system_os.c +++ b/src/probes/system_infos.probe/system_os.c @@ -139,7 +139,7 @@ static int parse_netmask(char *ip_addr) if (colon == NULL) { return 32; } - return (atoi(colon + 1) > 32) ? 0 : atoi(colon + 1); + return (strtol(colon + 1, NULL, 10) > 32) ? 0 : strtol(colon + 1, NULL, 10); } /* 检查IP是否在某网段内 */ @@ -281,7 +281,7 @@ static int get_resource_info(struct node_infos *infos) infos->clock_ticks = (u64)sysconf(_SC_CLK_TCK); sys_btime[0] = 0; (void)get_system_btime(sys_btime); - infos->os_btime = (u64)atoll(sys_btime); + infos->os_btime = strtoull(sys_btime, NULL, 10); return 0; } diff --git a/src/probes/system_infos.probe/system_procs.c b/src/probes/system_infos.probe/system_procs.c index 5a10fc3..f8dd1a3 100644 --- a/src/probes/system_infos.probe/system_procs.c +++ b/src/probes/system_infos.probe/system_procs.c @@ -50,7 +50,7 @@ static proc_hash_t *hash_find_proc(u32 pid, const char *stime) proc_hash_t temp = {0}; temp.key.pid = pid; - temp.key.start_time = (u64)atoll(stime); + temp.key.start_time = strtoull(stime, NULL, 10); HASH_FIND(hh, g_procmap, &temp.key, sizeof(proc_key_t), p); return p; @@ -236,7 +236,7 @@ static int get_proc_fdcnt(u32 pid, proc_info_t *proc_info) static void do_set_proc_stat(proc_info_t *proc_info, char *buf, int index) { - u64 value = (u64)atoll(buf); + u64 value = strtoull(buf, NULL, 10); switch (index) { case PROC_STAT_MIN_FLT: @@ -557,7 +557,7 @@ static proc_hash_t* init_one_proc(u32 pid, char *stime, char *comm) (void)memset(item, 0, sizeof(proc_hash_t)); item->key.pid = pid; - item->key.start_time = (u64)atoll(stime); + item->key.start_time = strtoull(stime, NULL, 10); (void)snprintf(item->info.comm, sizeof(item->info.comm), "%s", comm); item->flag = PROC_IN_PROBE_RANGE; diff --git a/src/probes/virtualized_infos.probe/virt_proc.c b/src/probes/virtualized_infos.probe/virt_proc.c index cbdb6e0..7a6848b 100644 --- a/src/probes/virtualized_infos.probe/virt_proc.c +++ b/src/probes/virtualized_infos.probe/virt_proc.c @@ -110,7 +110,7 @@ static int get_qemu_proc_tgid(struct proc_infos *one_proc) ERROR("[VIRT_PROC] get uuid(%s)'s tgid failed.\n", one_proc->uuid); return -1; } - one_proc->tgid = atoi(line); + one_proc->tgid = strtol(line, NULL, 10); output_proc_infos(one_proc); @@ -147,7 +147,7 @@ static int get_vhost_proc_tgid(struct proc_infos *one_proc) return -1; } SPLIT_NEWLINE_SYMBOL(line); - tmp.tgid = atoi(line); + tmp.tgid = strtol(line, NULL, 10); output_proc_infos(&tmp); } -- 2.28.0.windows.1