Skip to content

RDKEMW-16851: Increase Process name buffer length from 16 to 64#322

Merged
shibu-kv merged 21 commits intosupport/1.8from
copilot/sub-pr-306
Apr 13, 2026
Merged

RDKEMW-16851: Increase Process name buffer length from 16 to 64#322
shibu-kv merged 21 commits intosupport/1.8from
copilot/sub-pr-306

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 10, 2026

  • Fetch support/1.8 branch
  • Verify dcaproc.c is identical between support/1.8.5 and support/1.8
  • Merge support/1.8 into branch to align history
  • Verify diff against support/1.8 shows only dcaproc.c changes (1 file, 21 insertions, 20 deletions)
  • Push changes to remote
  • Action needed: Please retarget PR RDKEMW-16851: Increase Process name buffer length from 16 to 64 #322 base from topic/BES1-941 to support/1.8 in GitHub UI (Edit → Base branch)

shibu-kv and others added 18 commits March 31, 2026 08:03
#305)

* RDKEMW-15927 ,RDKEMW-15007 : [APACA/Xione DE] rbus self-deadlock in XConf privacy mode fetch causing ~188s T2 init delay

Reason for change: When UserSettings sets privacy mode to DO_NOT_SHARE during boot,
the rbus SET handler (t2PropertyDataSetHandler) runs synchronously
on the single rbus callback thread — executing deleteAllProfiles()
with pthread_join, disk I/O, and XConf client restart.

The restarted XConf thread calls appendRequestParams() which uses
getParameterValue(PRIVACYMODES_RFC) to fetch privacy mode. This
issues rbus_get() on T2's own bus handle, requiring the same rbus
callback thread that is already blocked processing the SET handler.
This creates a self-deadlock with a 15s rbus timeout per attempt,
compounded by XCONF_RETRY_TIMEOUT (180s), stalling T2 initialization.

Cascading effect: While T2 is stalled, external callers (e.g.
WPEFramework SystemServices plugin) invoking t2_event_s() block
15s each on rbus_getUint(Telemetry.OperationalStatus), delaying
the dispatch thread by ~188s and blocking sendNotify() for
EVT_ONSYSTEMPOWERSTATECHANGED.

Fix:
- xconfclient.c: Replace getParameterValue(PRIVACYMODES_RFC) with
  direct getPrivacyMode() call from privacycontrol library. The
  platform implementation (provided via meta layer bbappend) reads
  from a local in-memory cache (PRIVACY_STATE), with fallback to
  Thunder JSON-RPC (local HTTP) and persistent storage — none of
  which use rbus, eliminating the self-deadlock.
`
- xconf-client/Makefile.am: Add privacycontrol include path and
  build dependency when IS_PRIVACYCONTROL_ENABLED is set.

- telemetry_busmessage_sender.c: Add fast-fail file marker check
  (T2_COMPONENT_READY) before rbus_getUint() in isCachingRequired()
  to avoid 15s blocking timeout when T2 is not yet ready.
Test Procedure: please refer the ticket comments
Risks: Medium
Signed-off-by: Thamim Razith <ThamimRazith_AbbasAli@comcast.com>

* Addressed the L1 Test cases failure

* RDKEMW-15927, RDKEMW-15007 : [APACA/Xione DE] Fix RBUS handler starvation and race condition on privacyModeVal

Reason for change: When UserSettings sets privacy mode to DO_NOT_SHARE during boot,
the rbus SET handler (t2PropertyDataSetHandler) runs synchronously
on the single rbus callback thread — executing deleteAllProfiles()
with pthread_join, disk I/O, and XConf client restart.

The restarted XConf thread calls appendRequestParams() which uses
getParameterValue(PRIVACYMODES_RFC) to fetch privacy mode. This
issues rbus_get() on T2's own bus handle, requiring the same rbus
callback thread that is already blocked processing the SET handler.
This creates a self-deadlock with a 15s rbus timeout per attempt,
compounded by XCONF_RETRY_TIMEOUT (180s), stalling T2 initialization.

Additionally, privacyModeVal global pointer has no mutex protection,
allowing use-after-free and NULL dereference under concurrent
SET/GET operations during stress scenarios.

Cascading effect: While T2 is stalled, external callers (e.g.
WPEFramework SystemServices plugin) invoking t2_event_s() block
15s each on rbus_getUint(Telemetry.OperationalStatus), delaying
the dispatch thread by ~188s and blocking sendNotify() for
EVT_ONSYSTEMPOWERSTATECHANGED. Under concurrent privacy mode
toggling, PROVIDER_NOT_RESPONDING with 26+ messages queued and
dropped, telemetry events fall back to file caching.

Fix:
- rbusInterface.c: Add privacyModeMutex (PTHREAD_MUTEX_INITIALIZER)
  to serialize all reads/writes of privacyModeVal in SET and GET
  handlers, preventing use-after-free and NULL dereference.

- rbusInterface.c: Add privacyModeCallbackWorker() detached thread.
  The SET handler now validates input, updates privacyModeVal under
  mutex, calls setPrivacyMode() for persistence, then dispatches
  heavy callbacks (mprofilesDeleteCallBack, privacyModesDoNotShareCallBack)
  to the worker thread. RBUS handler returns immediately, preventing
  handler thread starvation and cascading 180s timeout loops.

- xconfclient.c: Replace getParameterValue(PRIVACYMODES_RFC) with
  direct getPrivacyMode() call from privacycontrol library. The
  platform implementation (provided via meta layer bbappend) reads
  from a local in-memory cache (PRIVACY_STATE), with fallback to
  Thunder JSON-RPC (local HTTP) and persistent storage — none of
  which use rbus, eliminating the self-deadlock.

- xconf-client/Makefile.am: Add privacycontrol include path and
  build dependency when IS_PRIVACYCONTROL_ENABLED is set. Add else
  branch for libxconfclient_la_CFLAGS to define the variable in all
  automake conditions, fixing autoreconf failure.

- telemetry_busmessage_sender.c: Add fast-fail file marker check
  (T2_COMPONENT_READY) before rbus_getUint() in isCachingRequired()
  to avoid blocking on rbus timeout when T2 is not ready.

- persistence.c: Change rm -f to rm -rf in clearPersistenceFolder()
  non-LIBSYSWRAPPER path. PRIVACYMODE_PATH is a directory, not a
  file; rm -f fails silently leaving stale persistence data.

Test Procedure: Concurrent stress test with multiple privacy mode toggles
(SHARE/DO_NOT_SHARE via curl JSON-RPC), telemetry marker submissions
(telemetry2_0_client), rbuscli reads, and SIGUSR1 signal — all
running simultaneously in background.
Risks: Medium
Signed-off-by: Thamim Razith <ThamimRazith_AbbasAli@comcast.com>

* Addressed the shibu review comments

* Addressed the empty check on path  on fetchLocalConfigs and clearPersistenceFolder

* Apply suggestion from @Copilot

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Apply suggestion from @Copilot

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Removed the extra space for addressed the style formatting

* Addressed the astyle format issue

* Fix dangling pointer in rbusInterface.c GET handler: call rbusValue_SetString after ownership transfer

Agent-Logs-Url: https://github.com/rdkcentral/telemetry/sessions/d5b743ff-3289-4141-b51a-399971064c4c

Co-authored-by: shibu-kv <89052442+shibu-kv@users.noreply.github.com>

---------

Signed-off-by: Thamim Razith <ThamimRazith_AbbasAli@comcast.com>
Co-authored-by: tabbas651 <thamimrazith_abbasali@comcast.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Signed-off-by: Yogeswaran K <yogeswaransky@gmail.com>
Copilot AI changed the title [WIP] [RDKEMW-16851] Increase process name buffer length from 16 to 64 RDKEMW-16851: Increase Process name buffer length from 16 to 64 Apr 10, 2026
Copilot AI requested a review from yogeswaransky April 10, 2026 09:02
…-306

# Conflicts:
#	CHANGELOG.md

Co-authored-by: yogeswaransky <166126056+yogeswaransky@users.noreply.github.com>
@yogeswaransky yogeswaransky changed the base branch from topic/BES1-941 to support/1.8 April 10, 2026 10:13
Copy link
Copy Markdown
Contributor

@yogeswaransky yogeswaransky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@yogeswaransky yogeswaransky marked this pull request as ready for review April 10, 2026 10:14
@yogeswaransky yogeswaransky requested a review from a team as a code owner April 10, 2026 10:14
Copilot AI review requested due to automatic review settings April 10, 2026 10:14
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the DCA process-usage collection logic to better handle longer process names and to make CPU/memory extraction from top output more robust.

Changes:

  • Replace unbounded memcpy(..., strlen()+1) with a bounded copy into pInfo.processName.
  • Clear existing marker->cpuValue / marker->memValue before repopulating them.
  • Update top | grep ... command construction to try matching either by process name or by PID, and make an existing debug log reachable by moving a return.

Comment thread source/dcautil/dcaproc.c
Comment on lines +97 to +98
strncpy(pInfo.processName, processName, BUF_LEN - 1);
pInfo.processName[BUF_LEN - 1] = '\0';
Copy link

Copilot AI Apr 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR title/description says the process name buffer is increased from 16 to 64, but this change still writes into pInfo.processName sized by BUF_LEN (which is currently 16 in source/dcautil/dcautil.h). As a result, longer process names will still be truncated here. If the intent is truly a 64-byte process name, the buffer size needs to be updated at the type/define level (or introduce a dedicated PROC_NAME_BUF_LEN) and ensure all related code uses that size consistently.

Copilot uses AI. Check for mistakes.
Comment thread source/dcautil/dcaproc.c Outdated
Comment on lines 562 to 565
inFp = v_secure_popen("r", "top -n 1 -c | grep -v grep | { grep -i '%s' || grep -E '^[[:space:]]*%d[[:space:]]'; }", pInfo->processName, pInfo->pid[0]);
#else
sprintf(command, "top -n 1 -c | grep -v grep |grep -i '%s'", pInfo->processName);
snprintf(command, CMD_LEN, "top -n 1 -c | grep -v grep | { grep -i '%s' || grep -E '^[[:space:]]*%d[[:space:]]'; }", pInfo->processName, pInfo->pid[0]);
inFp = popen(command, "r");
Copy link

Copilot AI Apr 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The { grep -i ... || grep -E ...; } fallback in a pipeline won’t work as intended: the first grep consumes all stdin even when it finds no matches, so the second grep runs with EOF and cannot match by PID. If you need a name-or-PID match from a single top output stream, use a single filter (e.g., a single grep -E with alternation, or awk matching either $1==pid or the command column contains the name).

Copilot uses AI. Check for mistakes.
Comment thread source/dcautil/dcaproc.c Outdated
Comment thread source/dcautil/dcaproc.c Outdated
Comment thread source/dcautil/dcaproc.c Outdated
{
#ifdef LIBSYSWRAPPER_BUILD
inFp = v_secure_popen("r", "top -n 1 -c | grep -v grep |grep -i '%s'", pInfo->processName);
inFp = v_secure_popen("r", "top -n 1 -c | grep -v grep | { grep -i '%s' || grep -E '^[[:space:]]*%d[[:space:]]'; }", pInfo->processName, pInfo->pid[0]);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This adds more advanced regex capabilities which is more oriented towards bash. This may not work on all limited busy box provided shell capabilities.

Comment thread source/dcautil/dcaproc.c Outdated
Comment thread source/dcautil/dcaproc.c Outdated
Comment thread source/dcautil/dcaproc.c Outdated
Copy link
Copy Markdown
Contributor

@shibu-kv shibu-kv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please refer to comments from previous review submission

Signed-off-by: Yogeswaran K <yogeswaransky@gmail.com>
Signed-off-by: Yogeswaran K <yogeswaransky@gmail.com>
Copilot AI review requested due to automatic review settings April 13, 2026 12:23
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 3 comments.

Comment thread source/dcautil/dcaproc.c
Comment thread source/dcautil/dcaproc.c
Comment thread source/dcautil/dcaproc.c
Comment on lines +598 to +602
/* match by process name (case-insensitive), PID as fallback */
if(strcasestr(top_op, pInfo->processName) == NULL)
{
int line_pid = 0;
if(sscanf(top_op, "%d", &line_pid) != 1 || line_pid != pInfo->pid[0])
Copy link

Copilot AI Apr 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new matching/parsing logic (case-insensitive name match with PID fallback, plus the direct-file read path) isn’t covered by existing unit tests (current tests only exercise the NULL-pInfo case for getCPUInfo). Adding gtest coverage for these new branches would help prevent regressions across different top output formats and ensure the fallback behavior works as intended.

Copilot generated this review using guidance from repository custom instructions.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot Create a separate pull request with adding additional L1 test cases .

Comment thread source/dcautil/dcaproc.c
Comment on lines +598 to +602
/* match by process name (case-insensitive), PID as fallback */
if(strcasestr(top_op, pInfo->processName) == NULL)
{
int line_pid = 0;
if(sscanf(top_op, "%d", &line_pid) != 1 || line_pid != pInfo->pid[0])
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot Create a separate pull request with adding additional L1 test cases .

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 13, 2026

@shibu-kv I've opened a new pull request, #325, to work on those changes. Once the pull request is ready, I'll request review from you.

@shibu-kv shibu-kv merged commit e6c65e5 into support/1.8 Apr 13, 2026
8 checks passed
@shibu-kv shibu-kv deleted the copilot/sub-pr-306 branch April 13, 2026 13:13
@github-actions github-actions bot locked and limited conversation to collaborators Apr 13, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants