@@ -375,17 +375,48 @@ void Process_makeCommandStr(Process* this, const Settings* settings) {
375
375
return ;
376
376
}
377
377
378
+ int commLen = 0 ;
379
+
378
380
bool haveCommInExe = false;
379
381
if (procExe && procComm && (!Process_isUserlandThread (this ) || showThreadNames )) {
380
382
haveCommInExe = strncmp (procExe + exeBasenameOffset , procComm , TASK_COMM_LEN - 1 ) == 0 ;
381
383
}
384
+ if (haveCommInExe ) {
385
+ commLen = exeBasenameLen ;
386
+ }
387
+
388
+ bool haveCommInCmdline = false;
389
+ int commStart = 0 ;
390
+
391
+ if (!haveCommInExe && this -> cmdline && procComm && searchCommInCmdline && (!Process_isUserlandThread (this ) || showThreadNames )) {
392
+ haveCommInCmdline = findCommInCmdline (procComm , cmdline , cmdlineBasenameStart , & commStart , & commLen );
393
+ }
394
+
395
+ if (!stripExeFromCmdline ) {
396
+ matchLen = 0 ;
397
+ }
398
+ if (matchLen ) {
399
+ /* strip the matched exe prefix */
400
+ cmdline += matchLen ;
401
+
402
+ if (haveCommInCmdline ) {
403
+ if (commStart == cmdlineBasenameStart ) {
404
+ haveCommInExe = true;
405
+ haveCommInCmdline = false;
406
+ commStart = 0 ;
407
+ } else {
408
+ assert (commStart >= matchLen );
409
+ commStart -= matchLen ;
410
+ }
411
+ }
412
+ }
382
413
383
414
/* Start with copying exe */
384
415
if (showProgramPath ) {
385
416
if (shadowDistPathPrefix )
386
417
CHECK_AND_MARK_DIST_PATH_PREFIXES (procExe );
387
418
if (haveCommInExe )
388
- WRITE_HIGHLIGHT (exeBasenameOffset , exeBasenameLen , commAttr , CMDLINE_HIGHLIGHT_FLAG_COMM );
419
+ WRITE_HIGHLIGHT (exeBasenameOffset , commLen , commAttr , CMDLINE_HIGHLIGHT_FLAG_COMM );
389
420
WRITE_HIGHLIGHT (exeBasenameOffset , exeBasenameLen , baseAttr , CMDLINE_HIGHLIGHT_FLAG_BASENAME );
390
421
if (this -> procExeDeleted )
391
422
WRITE_HIGHLIGHT (exeBasenameOffset , exeBasenameLen , delExeAttr , CMDLINE_HIGHLIGHT_FLAG_DELETED );
@@ -394,7 +425,7 @@ void Process_makeCommandStr(Process* this, const Settings* settings) {
394
425
str = stpcpy (str , procExe );
395
426
} else {
396
427
if (haveCommInExe )
397
- WRITE_HIGHLIGHT (0 , exeBasenameLen , commAttr , CMDLINE_HIGHLIGHT_FLAG_COMM );
428
+ WRITE_HIGHLIGHT (0 , commLen , commAttr , CMDLINE_HIGHLIGHT_FLAG_COMM );
398
429
WRITE_HIGHLIGHT (0 , exeBasenameLen , baseAttr , CMDLINE_HIGHLIGHT_FLAG_BASENAME );
399
430
if (this -> procExeDeleted )
400
431
WRITE_HIGHLIGHT (0 , exeBasenameLen , delExeAttr , CMDLINE_HIGHLIGHT_FLAG_DELETED );
@@ -403,16 +434,6 @@ void Process_makeCommandStr(Process* this, const Settings* settings) {
403
434
str = stpcpy (str , procExe + exeBasenameOffset );
404
435
}
405
436
406
- bool haveCommInCmdline = false;
407
- int commStart = 0 ;
408
- int commLen = 0 ;
409
-
410
- /* Try to match procComm with procExe's basename: This is reliable (predictable) */
411
- if (searchCommInCmdline ) {
412
- /* commStart/commLen will be adjusted later along with cmdline */
413
- haveCommInCmdline = (!Process_isUserlandThread (this ) || showThreadNames ) && findCommInCmdline (procComm , cmdline , cmdlineBasenameStart , & commStart , & commLen );
414
- }
415
-
416
437
bool haveCommField = false;
417
438
418
439
if (!haveCommInExe && !haveCommInCmdline && procComm && (!Process_isUserlandThread (this ) || showThreadNames )) {
@@ -422,17 +443,6 @@ void Process_makeCommandStr(Process* this, const Settings* settings) {
422
443
haveCommField = true;
423
444
}
424
445
425
- if (matchLen ) {
426
- if (stripExeFromCmdline ) {
427
- /* strip the matched exe prefix */
428
- cmdline += matchLen ;
429
-
430
- commStart -= matchLen ;
431
- } else {
432
- matchLen = 0 ;
433
- }
434
- }
435
-
436
446
if (!matchLen || (haveCommField && * cmdline )) {
437
447
/* cmdline will be a separate field */
438
448
WRITE_SEPARATOR ;
0 commit comments