Skip to content

Commit ae1497d

Browse files
committed
src: allow missing process title in metrics update
If uv_get_process_title fails, ProcessMetrics::Update continues and leaves the title field empty instead of returning early. This prevents metrics collection from failing due to a missing process title, improving robustness in edge cases. PR-URL: #364 Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com> Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
1 parent bd5af31 commit ae1497d

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

src/nsolid.cc

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,14 +211,18 @@ int ProcessMetrics::Update() {
211211
char title_buf[512];
212212
size_t rss;
213213
int er;
214+
// uv_get_process_title() may fail. Leave `title` empty and continue.
215+
std::string title;
214216
// uv_os_get_passwd() may fail (e.g., nameless system user). Leave `user`
215217
// empty and continue.
216218
std::string user;
217219

218220
uv_loadavg(load_avgs);
219221
er = uv_get_process_title(title_buf, sizeof(title_buf));
220-
if (er)
221-
return er;
222+
if (er == 0) {
223+
title = title_buf;
224+
}
225+
222226
er = uv_resident_set_memory(&rss);
223227
if (er)
224228
return er;
@@ -244,7 +248,7 @@ int ProcessMetrics::Update() {
244248
cpu_percent[2] = (cpu[2] - cpu_prev_[2]) * 100.0 * 1000.0 / elapsed;
245249

246250
uv_mutex_lock(&stor_lock_);
247-
stor_.title = title_buf;
251+
stor_.title = title;
248252
stor_.user = user;
249253
stor_.timestamp = duration_cast<milliseconds>(
250254
system_clock::now().time_since_epoch()).count();

0 commit comments

Comments
 (0)