204 static const char * alt_root = NULL;
205 static int alt_root_len = -1;
206
207 #define SA_ALTROOT "SA_ALTROOT"
208
209 static void init_alt_root() {
210 if (alt_root_len == -1) {
211 alt_root = getenv(SA_ALTROOT);
212 if (alt_root)
213 alt_root_len = strlen(alt_root);
214 else
215 alt_root_len = 0;
216 }
217 }
218
219 // This function is a complete substitute for the open system call
220 // since it's also used to override open calls from libproc to
221 // implement as a pathmap style facility for the SA. If libproc
222 // starts using other interfaces then this might have to extended to
223 // cover other calls.
224 extern "C" int libsaproc_open(const char * name, int oflag, ...) {
225 if (oflag == O_RDONLY) {
226 init_alt_root();
227
228 if (_libsaproc_debug) {
229 printf("libsaproc DEBUG: libsaproc_open %s\n", name);
230 }
231
232 if (alt_root_len > 0) {
233 int fd = -1;
234 char alt_path[PATH_MAX+1];
235
236 strcpy(alt_path, alt_root);
237 strcat(alt_path, name);
238 fd = open(alt_path, O_RDONLY);
239 if (fd >= 0) {
240 if (_libsaproc_debug) {
241 printf("libsaproc DEBUG: libsaproc_open substituted %s\n", alt_path);
242 }
243 return fd;
244 }
|
204 static const char * alt_root = NULL;
205 static int alt_root_len = -1;
206
207 #define SA_ALTROOT "SA_ALTROOT"
208
209 static void init_alt_root() {
210 if (alt_root_len == -1) {
211 alt_root = getenv(SA_ALTROOT);
212 if (alt_root)
213 alt_root_len = strlen(alt_root);
214 else
215 alt_root_len = 0;
216 }
217 }
218
219 // This function is a complete substitute for the open system call
220 // since it's also used to override open calls from libproc to
221 // implement as a pathmap style facility for the SA. If libproc
222 // starts using other interfaces then this might have to extended to
223 // cover other calls.
224 extern "C" JNIEXPORT int JNICALL
225 libsaproc_open(const char * name, int oflag, ...) {
226 if (oflag == O_RDONLY) {
227 init_alt_root();
228
229 if (_libsaproc_debug) {
230 printf("libsaproc DEBUG: libsaproc_open %s\n", name);
231 }
232
233 if (alt_root_len > 0) {
234 int fd = -1;
235 char alt_path[PATH_MAX+1];
236
237 strcpy(alt_path, alt_root);
238 strcat(alt_path, name);
239 fd = open(alt_path, O_RDONLY);
240 if (fd >= 0) {
241 if (_libsaproc_debug) {
242 printf("libsaproc DEBUG: libsaproc_open substituted %s\n", alt_path);
243 }
244 return fd;
245 }
|