[Darshan-commits] [Git][darshan/darshan][master] 4 commits: get exe and args from /proc/self/cmdline

Shane Snyder xgitlab at cels.anl.gov
Fri Dec 16 11:10:29 CST 2016


Shane Snyder pushed to branch master at darshan / darshan


Commits:
489977f7 by Cristian Simarro at 2016-12-12T16:05:59+00:00
get exe and args from /proc/self/cmdline

- - - - -
db57199f by Cristian Simarro at 2016-12-15T16:50:49+00:00
moved fclose to avoid free a null pointer

- - - - -
16217667 by Cristian Simarro at 2016-12-16T08:02:07+00:00
added __programme_full and tidy up declarations

- - - - -
45c766b9 by Shane Snyder at 2016-12-16T11:10:25-06:00
Merge branch 'master' into 'master'

Get Fortran executable arguments

We usually work with Fortran programs and it is always useful to have the arguments of the executable in the Darshan log. This feature allows Drshan to get the executable name and the arguments from /proc/self/cmdline if the program is Fortran (argc==0)

See merge request !3
- - - - -


1 changed file:

- darshan-runtime/lib/darshan-core.c


Changes:

=====================================
darshan-runtime/lib/darshan-core.c
=====================================
--- a/darshan-runtime/lib/darshan-core.c
+++ b/darshan-runtime/lib/darshan-core.c
@@ -1024,7 +1024,9 @@ static void darshan_get_exe_and_mounts(struct darshan_core_runtime *core,
     char* truncate_string = "<TRUNCATED>";
     int truncate_offset;
     int space_left = DARSHAN_EXE_LEN;
-    int i;
+    FILE *fh;
+    int i, ii;
+    char cmdl[DARSHAN_EXE_LEN];
     int tmp_index = 0;
     int skip = 0;
 
@@ -1063,9 +1065,28 @@ static void darshan_get_exe_and_mounts(struct darshan_core_runtime *core,
      */
     if(argc == 0)
     {
-        strncat(core->log_exemnt_p, __progname_full, space_left);
-        space_left = DARSHAN_EXE_LEN-strlen(core->log_exemnt_p);
-        strncat(core->log_exemnt_p, " <unknown args>", space_left);
+        /* get the name of the executable and the arguments from 
+           /proc/self/cmdline */
+
+        cmdl[0] = '\0';
+        fh = fopen("/proc/self/cmdline","r");
+        if(fh) {
+            ii = 0;
+            fgets(cmdl,DARSHAN_EXE_LEN,fh);
+            for(i=1;i<DARSHAN_EXE_LEN;i++)  {
+                if(cmdl[i]==0 && ii == 0) {
+                  cmdl[i]=' '; ii = 1;
+                } else if(cmdl[i]==0 && ii == 1) {
+                  break;
+                } else {
+                  ii = 0;
+                }
+            }
+            fclose(fh);
+        } else {
+           sprintf(cmdl, "%s <unknown args>", __progname_full);
+        }
+        strncat(core->log_exemnt_p, cmdl, space_left);
         space_left = DARSHAN_EXE_LEN-strlen(core->log_exemnt_p);
     }
 



View it on GitLab: https://xgitlab.cels.anl.gov/darshan/darshan/compare/55960ccffb4596dc35621b6fd3c8bfc85b5f8131...45c766b95295c80913251f6450d8d6df3eff99b6
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/darshan-commits/attachments/20161216/f6ecc18a/attachment-0001.html>


More information about the Darshan-commits mailing list