{
#define MIN_SMAP_BLOCKLINE 50
+ int ret_val = -1;
char path_smaps[PROCPATH_MAX];
mapinfo_section_t map;
FILE* fp;
bool ret = save_request_to_tmpfile(path_smaps, tmp_path, tmp_suffixlen);
if (!ret) {
LOGE("Cannot save smaps to tmpfile\n");
- return -1;
+ goto out;
}
fp = fopen(tmp_path, "r");
if(fp == NULL){
- LOGE("Open '%s'\n", tmp_path);
- remove(tmp_path);
- return -1;
+ LOGE("Cannot open '%s'\n", tmp_path);
+ goto remove_tmp_path;
}
while (read_mapinfo_section(fp, &map) == 0) {
P->sh_mem_clean *= 1024;
P->sh_mem_dirty *= 1024;
- fclose(fp);
- remove(tmp_path);
+ if (fclose(fp))
+ LOGE("Cannot close a temporary file, path=%s, errno=%d\n",
+ tmp_path, errno);
- return 0;
+ ret_val = 0;
+
+remove_tmp_path:
+ if (-1 == remove(tmp_path))
+ LOGE("Cannot remove a temporary file, path=%s, errno=%d\n",
+ tmp_path, errno);
+out:
+ return ret_val;
}
// return 0 for normal case
snprintf(buf, sizeof(buf), "/proc/%d/cmdline", gpid);
f = fopen(buf, "r");
if (f != NULL) {
- fscanf(f, "%" TOSTRING(MAX_PATH_LENGTH) "s", buf);
+ int n = fscanf(f, "%" TOSTRING(MAX_PATH_LENGTH) "s", buf);
fclose(f);
- if (strlen(buf) == strlen(manager_name) &&
+ if (n == 1 && strlen(buf) == strlen(manager_name) &&
strncmp(buf, manager_name, sizeof(manager_name)) == 0) {
PRINTMSG("App termination: EXIT(0)");
exit(0);
if (uihv_data_send_to_socket(path))
PRINTERR("Cannot send uihv_data");
}
- remove(path);
+
+ if (-1 == remove(path))
+ PRINTERR("Cannot remove a temporary file, path=%s, errno=%d",
+ path, errno);
set_hierarchy_status(HIERARCHY_NOT_RUNNING);
}