[Mesa-dev] [PATCH 1/3] gallium/os: add os_get_process_cmd_line

Jan Vesely jan.vesely at rutgers.edu
Sat Jul 30 21:50:40 UTC 2016


On Sat, 2016-07-30 at 23:40 +0200, Marek Olšák wrote:
> On Sat, Jul 30, 2016 at 8:33 PM, Grazvydas Ignotas <notasas at gmail.com
> > wrote:
> > 
> > On Sat, Jul 30, 2016 at 6:22 PM, Marek Olšák <maraeo at gmail.com>
> > wrote:
> > > 
> > > From: Marek Olšák <marek.olsak at amd.com>
> > > 
> > > for debugging
> > > ---
> > >  src/gallium/auxiliary/os/os_process.c | 37
> > > +++++++++++++++++++++++++++++++++++
> > >  src/gallium/auxiliary/os/os_process.h |  2 ++
> > >  2 files changed, 39 insertions(+)
> > > 
> > > diff --git a/src/gallium/auxiliary/os/os_process.c
> > > b/src/gallium/auxiliary/os/os_process.c
> > > index 332e195..3ee30b1 100644
> > > --- a/src/gallium/auxiliary/os/os_process.c
> > > +++ b/src/gallium/auxiliary/os/os_process.c
> > > @@ -30,6 +30,10 @@
> > >  #include "os/os_process.h"
> > >  #include "util/u_memory.h"
> > > 
> > > +#if defined(PIPE_OS_UNIX)
> > > +#include <stdio.h>
> > > +#endif
> > > +
> > >  #if defined(PIPE_SUBSYSTEM_WINDOWS_USER)
> > >  #  include <windows.h>
> > >  #elif defined(__GLIBC__) || defined(__CYGWIN__)
> > > @@ -108,3 +112,36 @@ os_get_process_name(char *procname, size_t
> > > size)
> > >        return FALSE;
> > >     }
> > >  }
> > > +
> > > +bool
> > > +os_get_process_cmd_line(char *result, size_t size)
> > > +{
> > > +#if defined(PIPE_OS_UNIX)
> > > +   char ps[256];
> > > +   int len;
> > > +   FILE *p;
> > > +
> > > +   /* Execute the ps command. */
> > > +   snprintf(ps, sizeof(ps), "ps --pid %i -o args --no-headers",
> > > getpid());
> > > +
> > > +   p = popen(ps, "r");
> > 
> > What about just reading /proc/self/cmdline ? To exec ps, the
> > current
> > process will have to fork which will fail if there is not enough
> > free
> > RAM for the forked copy, which is not that unlikely with games as
> > they
> > tend to be resource heavy.
> 
> Are you sure it makes a copy of the current process? The affected
> code
> already uses popen to read dmesg. This series only adds a second
> popen
> call.

it not just forks the current process, it execs shell first, before
execing the requested program:
"The  popen()  function opens a process by creating a pipe, forking,
and invoking the shell."

Jan

> 
> Marek
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev
-- 
Jan Vesely <jan.vesely at rutgers.edu>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: This is a digitally signed message part
URL: <https://lists.freedesktop.org/archives/mesa-dev/attachments/20160730/c09327f8/attachment-0001.sig>


More information about the mesa-dev mailing list