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

Contents of /trunk/libsbutil/sbutil.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 314 - (show annotations) (download) (as text)
Sun Jul 9 20:33:52 2006 UTC (8 years ago) by azarah
File MIME type: text/x-csrc
File size: 3489 byte(s)
Remove file_length(), and rather use rc_get_size().

1 /*
2 * sbutil.c
3 *
4 * Util functions.
5 *
6 * Copyright 1999-2006 Gentoo Foundation
7 *
8 *
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the
11 * Free Software Foundation version 2 of the License.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 675 Mass Ave, Cambridge, MA 02139, USA.
21 *
22 * Some parts might have Copyright:
23 *
24 * Copyright (C) 2002 Brad House <brad@mainstreetsoftworks.com>
25 *
26 * $Header$
27 */
28
29
30 #include <errno.h>
31 #include <stdio.h>
32 #include <stdlib.h>
33 #include <limits.h>
34 #include <string.h>
35 #include <sys/stat.h>
36 #include <unistd.h>
37 #include <fcntl.h>
38 #include <libgen.h>
39
40 #include "sbutil.h"
41
42 void get_sandbox_lib(char *path)
43 {
44 #ifdef SB_HAVE_MULTILIB
45 snprintf(path, SB_PATH_MAX, "%s", LIB_NAME);
46 #else
47 snprintf(path, SB_PATH_MAX, "%s/%s", LIBSANDBOX_PATH, LIB_NAME);
48 if (!rc_file_exists(path)) {
49 snprintf(path, SB_PATH_MAX, "%s", LIB_NAME);
50 }
51 #endif
52 }
53
54 void get_sandbox_rc(char *path)
55 {
56 snprintf(path, SB_PATH_MAX, "%s/%s", SANDBOX_BASHRC_PATH, BASHRC_NAME);
57 }
58
59 void get_sandbox_log(char *path)
60 {
61 char *sandbox_log_env = NULL;
62
63 sandbox_log_env = getenv(ENV_SANDBOX_LOG);
64
65 /* THIS CHUNK BREAK THINGS BY DOING THIS:
66 * SANDBOX_LOG=/tmp/sandbox-app-admin/superadduser-1.0.7-11063.log
67 */
68 if ((NULL != sandbox_log_env) &&
69 (NULL != strchr(sandbox_log_env, '/')))
70 sandbox_log_env = NULL;
71
72 snprintf(path, SB_PATH_MAX, "%s%s%s%s%d%s",
73 SANDBOX_LOG_LOCATION, LOG_FILE_PREFIX,
74 (sandbox_log_env == NULL ? "" : sandbox_log_env),
75 (sandbox_log_env == NULL ? "" : "-"),
76 getpid(), LOG_FILE_EXT);
77 }
78
79 void get_sandbox_debug_log(char *path)
80 {
81 char *sandbox_debug_log_env = NULL;
82
83 sandbox_debug_log_env = getenv(ENV_SANDBOX_DEBUG_LOG);
84
85 /* THIS CHUNK BREAK THINGS BY DOING THIS:
86 * SANDBOX_DEBUG_LOG=/tmp/sandbox-app-admin/superadduser-1.0.7-11063.log
87 */
88 if ((NULL != sandbox_debug_log_env) &&
89 (NULL != strchr(sandbox_debug_log_env, '/')))
90 sandbox_debug_log_env = NULL;
91
92 snprintf(path, SB_PATH_MAX, "%s%s%s%s%d%s",
93 SANDBOX_LOG_LOCATION, DEBUG_LOG_FILE_PREFIX,
94 (sandbox_debug_log_env == NULL ? "" : sandbox_debug_log_env),
95 (sandbox_debug_log_env == NULL ? "" : "-"),
96 getpid(), LOG_FILE_EXT);
97 }
98
99 int get_tmp_dir(char *path)
100 {
101 if (NULL == realpath(getenv(ENV_TMPDIR) ? getenv(ENV_TMPDIR)
102 : TMPDIR,
103 path)) {
104 if (NULL == realpath(TMPDIR, path))
105 return -1;
106 }
107
108 /* Reset errno in case realpath set it */
109 errno = 0;
110
111 return 0;
112 }
113
114 bool is_env_on (const char *env)
115 {
116 if ((NULL != env) && (NULL != getenv(env)) &&
117 ((0 == strncasecmp(getenv(env), "1", 1)) ||
118 (0 == strncasecmp(getenv(env), "true", 4)) ||
119 (0 == strncasecmp(getenv(env), "yes", 3))))
120 return TRUE;
121
122 return FALSE;
123 }
124
125 bool is_env_off (const char *env)
126 {
127 if ((NULL != env) && (NULL != getenv(env)) &&
128 ((0 == strncasecmp(getenv(env), "0", 1)) ||
129 (0 == strncasecmp(getenv(env), "false", 5)) ||
130 (0 == strncasecmp(getenv(env), "no", 2))))
131 return TRUE;
132
133 return FALSE;
134 }
135
136
137 // vim:noexpandtab noai:cindent ai

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.20