/[path-sandbox]/trunk/sandbox_futils.c
Gentoo

Contents of /trunk/sandbox_futils.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 142 - (show annotations) (download) (as text)
Thu Jul 7 22:14:57 2005 UTC (13 years ago) by azarah
File MIME type: text/x-csrc
File size: 3237 byte(s)
Remove unused includes and variables.
1 /*
2 * Copyright (C) 2002 Brad House <brad@mainstreetsoftworks.com>
3 * Distributed under the terms of the GNU General Public License, v2 or later
4 * Author: Brad House <brad@mainstreetsoftworks.com>
5 *
6 * $Header$
7 *
8 */
9
10 #include <errno.h>
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <limits.h>
14 #include <string.h>
15 #include <sys/stat.h>
16 #include <unistd.h>
17 #include <fcntl.h>
18 #include <libgen.h>
19
20 #include "sandbox.h"
21 #include "config.h"
22
23 /* glibc modified getcwd() functions */
24 SB_STATIC char *egetcwd(char *, size_t);
25
26 SB_STATIC void get_sandbox_lib(char *path)
27 {
28 #ifdef SB_HAVE_64BIT_ARCH
29 snprintf(path, SB_PATH_MAX, "%s", LIB_NAME);
30 #else
31 snprintf(path, SB_PATH_MAX, "%s/%s", LIBSANDBOX_PATH, LIB_NAME);
32 if (0 >= exists(path)) {
33 snprintf(path, SB_PATH_MAX, "%s", LIB_NAME);
34 }
35 #endif
36 }
37
38 SB_STATIC void get_sandbox_rc(char *path)
39 {
40 snprintf(path, SB_PATH_MAX, "%s/%s", SANDBOX_BASHRC_PATH, BASHRC_NAME);
41 if (0 >= exists(path)) {
42 perror(">>> cannot open bashrc");
43 exit(EXIT_FAILURE);
44 }
45 }
46
47 SB_STATIC void get_sandbox_log(char *path)
48 {
49 char *sandbox_log_env = NULL;
50
51 sandbox_log_env = getenv(ENV_SANDBOX_LOG);
52
53 /* THIS CHUNK BREAK THINGS BY DOING THIS:
54 * SANDBOX_LOG=/tmp/sandbox-app-admin/superadduser-1.0.7-11063.log
55 */
56 if ((NULL != sandbox_log_env) &&
57 (NULL != strchr(sandbox_log_env, '/')))
58 sandbox_log_env = NULL;
59
60 snprintf(path, SB_PATH_MAX, "%s%s%s%s%d%s",
61 SANDBOX_LOG_LOCATION, LOG_FILE_PREFIX,
62 (sandbox_log_env == NULL ? "" : sandbox_log_env),
63 (sandbox_log_env == NULL ? "" : "-"),
64 getpid(), LOG_FILE_EXT);
65 }
66
67 SB_STATIC void get_sandbox_debug_log(char *path)
68 {
69 char *sandbox_debug_log_env = NULL;
70
71 sandbox_debug_log_env = getenv(ENV_SANDBOX_DEBUG_LOG);
72
73 /* THIS CHUNK BREAK THINGS BY DOING THIS:
74 * SANDBOX_DEBUG_LOG=/tmp/sandbox-app-admin/superadduser-1.0.7-11063.log
75 */
76 if ((NULL != sandbox_debug_log_env) &&
77 (NULL != strchr(sandbox_debug_log_env, '/')))
78 sandbox_debug_log_env = NULL;
79
80 snprintf(path, SB_PATH_MAX, "%s%s%s%s%d%s",
81 SANDBOX_LOG_LOCATION, DEBUG_LOG_FILE_PREFIX,
82 (sandbox_debug_log_env == NULL ? "" : sandbox_debug_log_env),
83 (sandbox_debug_log_env == NULL ? "" : "-"),
84 getpid(), LOG_FILE_EXT);
85 }
86
87 SB_STATIC int get_tmp_dir(char *path)
88 {
89 if (NULL == realpath(getenv(ENV_TMPDIR) ? getenv(ENV_TMPDIR)
90 : TMPDIR,
91 path)) {
92 if (NULL == realpath(TMPDIR, path))
93 return -1;
94 }
95
96 return 0;
97 }
98
99 SB_STATIC int exists(const char *pathname)
100 {
101 struct stat buf;
102 int retval;
103
104 if ((NULL == pathname) || (0 == strlen(pathname)))
105 return 0;
106
107 retval = lstat(pathname, &buf);
108 if (-1 != retval)
109 return 1;
110 /* Some or other error occurred */
111 if (ENOENT != errno)
112 return -1;
113
114 return 0;
115 }
116
117 SB_STATIC int is_file(const char *pathname)
118 {
119 struct stat buf;
120 int retval;
121
122 if ((NULL == pathname) || (0 == strlen(pathname)))
123 return 0;
124
125 retval = lstat(pathname, &buf);
126 if ((-1 != retval) && (S_ISREG(buf.st_mode)))
127 return 1;
128 /* Some or other error occurred */
129 if ((-1 == retval) && (ENOENT != errno))
130 return -1;
131
132 return 0;
133 }
134
135 SB_STATIC long file_length(int fd)
136 {
137 long pos, len;
138
139 pos = lseek(fd, 0L, SEEK_CUR);
140 len = lseek(fd, 0L, SEEK_END);
141 lseek(fd, pos, SEEK_SET);
142
143 return (len);
144 }
145
146
147 // 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