diff --git a/Android.bp b/Android.bp index deebb8e..354f521 100644 --- a/Android.bp +++ b/Android.bp @@ -13,7 +13,7 @@ cc_defaults { cc_binary { name: "lmkd", - srcs: ["lmkd.c"], + srcs: ["lmkd.cpp"], shared_libs: [ "libcutils", "liblog", @@ -33,7 +33,7 @@ cc_binary { cc_library_static { name: "libstatslogc", - srcs: ["statslog.c"], + srcs: ["statslog.cpp"], cflags: [ "-Wall", "-Werror", @@ -47,7 +47,7 @@ cc_library_static { cc_library_static { name: "liblmkd_utils", - srcs: ["liblmkd_utils.c"], + srcs: ["liblmkd_utils.cpp"], recovery_available: true, shared_libs: [ "libcutils", diff --git a/liblmkd_utils.c b/liblmkd_utils.cpp similarity index 100% rename from liblmkd_utils.c rename to liblmkd_utils.cpp diff --git a/libpsi/Android.bp b/libpsi/Android.bp index 8a97094..da0da08 100644 --- a/libpsi/Android.bp +++ b/libpsi/Android.bp @@ -5,7 +5,7 @@ cc_library_headers { cc_library { name: "libpsi", - srcs: ["psi.c"], + srcs: ["psi.cpp"], shared_libs: [ "liblog" ], diff --git a/libpsi/psi.c b/libpsi/psi.cpp similarity index 100% rename from libpsi/psi.c rename to libpsi/psi.cpp diff --git a/lmkd.c b/lmkd.cpp similarity index 99% rename from lmkd.c rename to lmkd.cpp index 1f94e57..389a2de 100644 --- a/lmkd.c +++ b/lmkd.cpp @@ -600,7 +600,7 @@ static char *reread_file(struct reread_data *data) { if (data->fd == -1) { /* First-time buffer initialization */ - if (!buf && (buf = malloc(buf_size)) == NULL) { + if (!buf && (buf = static_cast(malloc(buf_size))) == nullptr) { return NULL; } @@ -626,7 +626,7 @@ static char *reread_file(struct reread_data *data) { * Since we are reading /proc files we can't use fstat to find out * the real size of the file. Double the buffer size and keep retrying. */ - if ((new_buf = realloc(buf, buf_size * 2)) == NULL) { + if ((new_buf = static_cast(realloc(buf, buf_size * 2))) == nullptr) { errno = ENOMEM; return NULL; } @@ -818,13 +818,13 @@ static struct proc *pid_lookup(int pid) { return procp; } -static void adjslot_insert(struct adjslot_list *head, struct adjslot_list *new) +static void adjslot_insert(struct adjslot_list *head, struct adjslot_list *new_element) { struct adjslot_list *next = head->next; - new->prev = head; - new->next = next; - next->prev = new; - head->next = new; + new_element->prev = head; + new_element->next = next; + next->prev = new_element; + head->next = new_element; } static void adjslot_remove(struct adjslot_list *old) @@ -1123,7 +1123,7 @@ static void cmd_procprio(LMKD_CTRL_PACKET packet, int field_count, struct ucred } } - procp = calloc(1, sizeof(struct proc)); + procp = static_cast(calloc(1, sizeof(struct proc))); if (!procp) { // Oh, the irony. May need to rebuild our state. return; @@ -2415,7 +2415,6 @@ static void mp_event_common(int data, uint32_t events, struct polling_params *po unsigned long long evcount; int64_t mem_usage, memsw_usage; int64_t mem_pressure; - enum vmpressure_level lvl; union meminfo mi; struct zoneinfo zi; struct timespec curr_tm; @@ -2443,12 +2442,12 @@ static void mp_event_common(int data, uint32_t events, struct polling_params *po * and upgrade to the highest priority one. By reading * eventfd we also reset the event counters. */ - for (lvl = VMPRESS_LEVEL_LOW; lvl < VMPRESS_LEVEL_COUNT; lvl++) { + for (int lvl = VMPRESS_LEVEL_LOW; lvl < VMPRESS_LEVEL_COUNT; lvl++) { if (mpevfd[lvl] != -1 && TEMP_FAILURE_RETRY(read(mpevfd[lvl], &evcount, sizeof(evcount))) > 0 && evcount > 0 && lvl > level) { - level = lvl; + level = static_cast(lvl); } } } diff --git a/statslog.c b/statslog.cpp similarity index 98% rename from statslog.c rename to statslog.cpp index 428ffb5..f46900f 100644 --- a/statslog.c +++ b/statslog.cpp @@ -292,7 +292,7 @@ struct memory_stat *stats_read_memory_stat(bool per_app_memcg, int pid, uid_t ui static void proc_insert(struct proc* procp) { if (!pidhash) { - pidhash = calloc(PIDHASH_SZ, sizeof(*pidhash)); + pidhash = static_cast(calloc(PIDHASH_SZ, sizeof(*pidhash))); } int hval = pid_hashfn(procp->pid); @@ -336,7 +336,7 @@ void stats_store_taskname(int pid, const char* taskname) { } stats_remove_taskname(pid); } - procp = malloc(sizeof(struct proc)); + procp = static_cast(malloc(sizeof(struct proc))); procp->pid = pid; strncpy(procp->taskname, taskname, LINE_MAX - 1); procp->taskname[LINE_MAX - 1] = '\0';