Debian Codegraph @

tapset/linux/context-envvar.stp

raw
1 // context-envvar tapset
2 // Copyright (C) 2010 Pixar Inc. and/or Lars R. Damerow
3 //
4 // This file is part of systemtap, and is free software. You can
5 // redistribute it and/or modify it under the terms of the GNU General
6 // Public License (GPL); either version 2, or (at your option) any
7 // later version.
8 // <tapsetdescription>
9 // Context functions provide additional information about where an event occurred. These functions can
10 //provide information such as a backtrace to where the event occurred and the current register values for the
11 //processor.
12 // </tapsetdescription>
13
14 /**
15 * sfunction env_var - Fetch environment variable from current process
16 * @name: Name of the environment variable to fetch
17 *
18 * Description: Returns the contents of the specified environment value
19 * for the current process. If the variable isn't set an empty string
20 * is returned.
21 */
22 function env_var:string(name:string)
23 {
24 if (name == "")
25 return ""
26
27 env_value = "";
28 mm = @task(task_current())->mm;
29 if (mm)
30 {
31 env_start = @mm(mm)->env_start;
32 env_end = @mm(mm)->env_end;
33 if (env_start != 0 && env_end != 0)
34 {
35 len = env_end - env_start;
36 cur = user_string(env_start, "");
37 env_name = tokenize(cur, "=");
38 while (env_name != name && len > 0)
39 {
40 env_len = strlen(cur);
41 env_start += env_len + 1;
42 len -= env_len + 1;
43 if (len > 0)
44 {
45 cur = user_string(env_start, "");
46 env_name = tokenize(cur, "=");
47 }
48 else
49 env_name = "";
50 }
51
52 if (len > 0)
53 env_value = tokenize("", "");
54 }
55 }
56 return env_value;
57 }