/[path-sandbox]/trunk/libsbutil/get_sandbox_lib.c
Gentoo

Diff of /trunk/libsbutil/get_sandbox_lib.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 139 Revision 140
32#include "config.h" 32#include "config.h"
33 33
34/* glibc modified getcwd() functions */ 34/* glibc modified getcwd() functions */
35SB_STATIC char *egetcwd(char *, size_t); 35SB_STATIC char *egetcwd(char *, size_t);
36 36
37SB_STATIC char *get_sandbox_path(char *argv0) 37SB_STATIC void get_sandbox_path(char *argv0, char *path)
38{ 38{
39 char path[SB_PATH_MAX];
40
41 memset(path, 0, sizeof(path)); 39 memset(path, 0, sizeof(path));
42 /* ARGV[0] specifies full path */ 40 /* ARGV[0] specifies full path */
43 if (argv0[0] == '/') { 41 if ((NULL != argv0) && (argv0[0] == '/')) {
44 snprintf(path, SB_PATH_MAX, "%s", argv0); 42 snprintf(path, SB_PATH_MAX, "%s", argv0);
45 43
46 /* ARGV[0] specifies relative path */ 44 /* ARGV[0] specifies relative path */
47 } else { 45 } else {
48 if (-1 != readlink("/proc/self/exe", path, sizeof(path))) 46 if (-1 != readlink("/proc/self/exe", path, SB_PATH_MAX))
49 path[sizeof(path) - 1] = '\0'; 47 path[SB_PATH_MAX - 1] = '\0';
50 else 48 else
51 path[0] = '\0'; 49 path[0] = '\0';
52 } 50 }
53 51
54 /* Return just directory */ 52 /* Return just directory */
55 return (dirname(path)); 53 dirname(path);
56} 54}
57 55
58SB_STATIC char *get_sandbox_lib(char *sb_path) 56SB_STATIC void get_sandbox_lib(char *path)
59{ 57{
60 char path[SB_PATH_MAX];
61
62#ifdef SB_HAVE_64BIT_ARCH 58#ifdef SB_HAVE_64BIT_ARCH
63 snprintf(path, sizeof(path), "%s", LIB_NAME); 59 snprintf(path, SB_PATH_MAX, "%s", LIB_NAME);
64#else 60#else
65 snprintf(path, sizeof(path), "%s/%s", LIBSANDBOX_PATH, LIB_NAME); 61 snprintf(path, SB_PATH_MAX, "%s/%s", LIBSANDBOX_PATH, LIB_NAME);
66 if (0 >= exists(path)) { 62 if (0 >= exists(path)) {
67 snprintf(path, sizeof(path), "%s%s", sb_path, LIB_NAME); 63 snprintf(path, SB_PATH_MAX, "%s", LIB_NAME);
68 } 64 }
69#endif 65#endif
70 return (strdup(path));
71} 66}
72 67
73SB_STATIC char *get_sandbox_rc(char *sb_path) 68SB_STATIC void get_sandbox_rc(char *path)
74{ 69{
75 char path[SB_PATH_MAX]; 70 char sb_path[SB_PATH_MAX];
76 71
77 snprintf(path, sizeof(path), "%s/%s", SANDBOX_BASHRC_PATH, BASHRC_NAME); 72 snprintf(path, SB_PATH_MAX, "%s/%s", SANDBOX_BASHRC_PATH, BASHRC_NAME);
78 if (0 >= exists(path)) { 73 if (0 >= exists(path)) {
74 get_sandbox_path(NULL, sb_path);
79 snprintf(path, sizeof(path), "%s%s", sb_path, BASHRC_NAME); 75 snprintf(path, SB_PATH_MAX, "%s%s", sb_path, BASHRC_NAME);
80 } 76 }
81 return (strdup(path));
82} 77}
83 78
84SB_STATIC char *get_sandbox_log() 79SB_STATIC void get_sandbox_log(char *path)
85{ 80{
86 char path[SB_PATH_MAX];
87 char *sandbox_log_env = NULL; 81 char *sandbox_log_env = NULL;
88 82
89 sandbox_log_env = getenv(ENV_SANDBOX_LOG); 83 sandbox_log_env = getenv(ENV_SANDBOX_LOG);
90 84
91 /* THIS CHUNK BREAK THINGS BY DOING THIS: 85 /* THIS CHUNK BREAK THINGS BY DOING THIS:
93 */ 87 */
94 if ((NULL != sandbox_log_env) && 88 if ((NULL != sandbox_log_env) &&
95 (NULL != strchr(sandbox_log_env, '/'))) 89 (NULL != strchr(sandbox_log_env, '/')))
96 sandbox_log_env = NULL; 90 sandbox_log_env = NULL;
97 91
98 snprintf(path, sizeof(path) - 1, "%s%s%s%s%d%s", 92 snprintf(path, SB_PATH_MAX, "%s%s%s%s%d%s",
99 SANDBOX_LOG_LOCATION, LOG_FILE_PREFIX, 93 SANDBOX_LOG_LOCATION, LOG_FILE_PREFIX,
100 (sandbox_log_env == NULL ? "" : sandbox_log_env), 94 (sandbox_log_env == NULL ? "" : sandbox_log_env),
101 (sandbox_log_env == NULL ? "" : "-"), 95 (sandbox_log_env == NULL ? "" : "-"),
102 getpid(), LOG_FILE_EXT); 96 getpid(), LOG_FILE_EXT);
103 return (strdup(path));
104} 97}
105 98
106SB_STATIC char *get_sandbox_debug_log() 99SB_STATIC void get_sandbox_debug_log(char *path)
107{ 100{
108 char path[SB_PATH_MAX];
109 char *sandbox_debug_log_env = NULL; 101 char *sandbox_debug_log_env = NULL;
110 102
111 sandbox_debug_log_env = getenv(ENV_SANDBOX_DEBUG_LOG); 103 sandbox_debug_log_env = getenv(ENV_SANDBOX_DEBUG_LOG);
112 104
113 /* THIS CHUNK BREAK THINGS BY DOING THIS: 105 /* THIS CHUNK BREAK THINGS BY DOING THIS:
115 */ 107 */
116 if ((NULL != sandbox_debug_log_env) && 108 if ((NULL != sandbox_debug_log_env) &&
117 (NULL != strchr(sandbox_debug_log_env, '/'))) 109 (NULL != strchr(sandbox_debug_log_env, '/')))
118 sandbox_debug_log_env = NULL; 110 sandbox_debug_log_env = NULL;
119 111
120 snprintf(path, sizeof(path) - 1, "%s%s%s%s%d%s", 112 snprintf(path, SB_PATH_MAX, "%s%s%s%s%d%s",
121 SANDBOX_LOG_LOCATION, DEBUG_LOG_FILE_PREFIX, 113 SANDBOX_LOG_LOCATION, DEBUG_LOG_FILE_PREFIX,
122 (sandbox_debug_log_env == NULL ? "" : sandbox_debug_log_env), 114 (sandbox_debug_log_env == NULL ? "" : sandbox_debug_log_env),
123 (sandbox_debug_log_env == NULL ? "" : "-"), 115 (sandbox_debug_log_env == NULL ? "" : "-"),
124 getpid(), LOG_FILE_EXT); 116 getpid(), LOG_FILE_EXT);
125 return (strdup(path));
126} 117}
127 118
128SB_STATIC int get_tmp_dir(char *tmp_dir) 119SB_STATIC int get_tmp_dir(char *path)
129{ 120{
130 if (NULL == realpath(getenv(ENV_TMPDIR) ? getenv(ENV_TMPDIR) 121 if (NULL == realpath(getenv(ENV_TMPDIR) ? getenv(ENV_TMPDIR)
131 : TMPDIR, 122 : TMPDIR,
132 tmp_dir)) { 123 path)) {
133 if (NULL == realpath(TMPDIR, tmp_dir)) 124 if (NULL == realpath(TMPDIR, path))
134 return -1; 125 return -1;
135 } 126 }
136 127
137 return 0; 128 return 0;
138} 129}

Legend:
Removed from v.139  
changed lines
  Added in v.140

  ViewVC Help
Powered by ViewVC 1.1.20