@@ -241,8 +241,35 @@ void ffProcessGetInfoLinux(pid_t pid, FFstrbuf* processName, FFstrbuf* exe, cons
241
241
242
242
if (ffReadFileBuffer (filePath , exe ))
243
243
{
244
- ffStrbufRecalculateLength (exe ); //Trim the arguments
245
- ffStrbufTrimRightSpace (exe );
244
+ // Interpreter. Try to find the real script path in the arguments
245
+ const char * p = exe -> chars ;
246
+ uint32_t len = (uint32_t ) strlen (p );
247
+
248
+ if (len + 1 < exe -> length )
249
+ {
250
+ const char * name = memrchr (p , '/' , len );
251
+ if (name ) name ++ ; else name = p ;
252
+
253
+ if (ffStrStartsWith (name , "python" )
254
+ #ifndef __ANDROID__
255
+ || ffStrEquals (name , "guile" ) // for shepherd
256
+ #endif
257
+ )
258
+ {
259
+ // `cmdline` always ends with a trailing '\0', and ffReadFileBuffer appends another \0
260
+ // So `exe->chars` is always double '\0' terminated
261
+ for (p = p + len + 1 ; * p && * p == '-' ; p += strlen (p ) + 1 ) // Skip argumets
262
+ assert (p - exe -> chars < exe -> allocated );
263
+ if (* p )
264
+ {
265
+ len = (uint32_t ) strlen (p );
266
+ memmove (exe -> chars , p , len + 1 );
267
+ }
268
+ }
269
+ }
270
+
271
+ assert (len < exe -> allocated );
272
+ exe -> length = len ;
246
273
ffStrbufTrimLeft (exe , '-' ); //Login shells start with a dash
247
274
}
248
275
@@ -463,6 +490,8 @@ const char* ffProcessGetBasicInfoLinux(pid_t pid, FFstrbuf* name, pid_t* ppid, i
463
490
return "memrchr(stat, ')') failed" ;
464
491
ffStrbufSetNS (name , (uint32_t ) (end - start ), start );
465
492
ffStrbufTrimRightSpace (name );
493
+ if (name -> chars [0 ] == '\0' )
494
+ return "process name is empty" ;
466
495
pState = end + 2 ; // skip ") "
467
496
}
468
497
@@ -471,10 +500,7 @@ const char* ffProcessGetBasicInfoLinux(pid_t pid, FFstrbuf* name, pid_t* ppid, i
471
500
#endif
472
501
{
473
502
int ppid_ , tty_ ;
474
- if (
475
- sscanf (pState + 2 , "%d %*d %*d %d" , & ppid_ , & tty_ ) < 2 ||
476
- name -> chars [0 ] == '\0'
477
- )
503
+ if (sscanf (pState + 2 , "%d %*d %*d %d" , & ppid_ , & tty_ ) < 2 )
478
504
return "sscanf(stat) failed" ;
479
505
480
506
if (ppid )
0 commit comments