/** http://issues.apache.org/bugzilla/show_bug.cgi?id=40764 */ static void test_emptyenv(abts_case *tc, void *data) { char *value; apr_status_t rv; if (!(have_env_set && have_env_get)) { ABTS_NOT_IMPL(tc, "apr_env_set (skip test_emptyenv)"); return; } /** Set empty string and test that rv != ENOENT) */ rv = apr_env_set(TEST_ENVVAR_NAME, "", p); APR_ASSERT_SUCCESS(tc, "set environment variable", rv); rv = apr_env_get(&value, TEST_ENVVAR_NAME, p); APR_ASSERT_SUCCESS(tc, "get environment variable", rv); ABTS_STR_EQUAL(tc, "", value); if (!have_env_del) { ABTS_NOT_IMPL(tc, "apr_env_del (skip recycle test_emptyenv)"); return; } /** Delete and retest */ rv = apr_env_delete(TEST_ENVVAR_NAME, p); APR_ASSERT_SUCCESS(tc, "delete environment variable", rv); rv = apr_env_get(&value, TEST_ENVVAR_NAME, p); ABTS_INT_EQUAL(tc, APR_ENOENT, rv); /** Set second variable + test*/ rv = apr_env_set(TEST_ENVVAR2_NAME, TEST_ENVVAR_VALUE, p); APR_ASSERT_SUCCESS(tc, "set second environment variable", rv); rv = apr_env_get(&value, TEST_ENVVAR2_NAME, p); APR_ASSERT_SUCCESS(tc, "get second environment variable", rv); ABTS_STR_EQUAL(tc, TEST_ENVVAR_VALUE, value); /** Finally, test ENOENT (first variable) followed by second != ENOENT) */ rv = apr_env_get(&value, TEST_ENVVAR_NAME, p); ABTS_INT_EQUAL(tc, APR_ENOENT, rv); rv = apr_env_get(&value, TEST_ENVVAR2_NAME, p); APR_ASSERT_SUCCESS(tc, "verify second environment variable", rv); ABTS_STR_EQUAL(tc, TEST_ENVVAR_VALUE, value); /** Cleanup */ apr_env_delete(TEST_ENVVAR2_NAME, p); }
/** http://issues.apache.org/bugzilla/show_bug.cgi?id=40764 */ static void test_emptyenv(CuTest *tc) { char *value; apr_status_t rv; if (!(have_env_set && have_env_get)) { CuNotImpl(tc, "apr_env_set (skip test_emptyenv)"); return; } /** Set empty string and test that rv != ENOENT) */ rv = apr_env_set(TEST_ENVVAR_NAME, "", p); apr_assert_success(tc, "set environment variable", rv); rv = apr_env_get(&value, TEST_ENVVAR_NAME, p); apr_assert_success(tc, "get environment variable", rv); CuAssertStrEquals(tc, "", value); if (!have_env_del) { CuNotImpl(tc, "apr_env_del (skip recycle test_emptyenv)"); return; } /** Delete and retest */ rv = apr_env_delete(TEST_ENVVAR_NAME, p); apr_assert_success(tc, "delete environment variable", rv); rv = apr_env_get(&value, TEST_ENVVAR_NAME, p); CuAssertIntEquals(tc, APR_ENOENT, rv); /** Set second variable + test*/ rv = apr_env_set(TEST_ENVVAR2_NAME, TEST_ENVVAR_VALUE, p); apr_assert_success(tc, "set second environment variable", rv); rv = apr_env_get(&value, TEST_ENVVAR2_NAME, p); apr_assert_success(tc, "get second environment variable", rv); CuAssertStrEquals(tc, TEST_ENVVAR_VALUE, value); /** Finally, test ENOENT (first variable) followed by second != ENOENT) */ rv = apr_env_get(&value, TEST_ENVVAR_NAME, p); CuAssertIntEquals(tc, APR_ENOENT, rv); rv = apr_env_get(&value, TEST_ENVVAR2_NAME, p); apr_assert_success(tc, "verify second environment variable", rv); CuAssertStrEquals(tc, TEST_ENVVAR_VALUE, value); /** Cleanup */ apr_env_delete(TEST_ENVVAR2_NAME, p); }
apr_status_t exec_self( int argc, const char *argv[] ) { apr_status_t rv = APR_SUCCESS; apr_array_header_t *dpaths = get_property_array( "hashdot.vm.libpath" ); if( dpaths == NULL ) return rv; char * ldpenv = NULL; apr_env_get( &ldpenv, LIB_PATH_VAR, _mp ); apr_array_header_t *newpaths = apr_array_make( _mp, 8, sizeof( const char* ) ); int i; for( i = 0; i < dpaths->nelts; i++ ) { const char *path = ((const char **) dpaths->elts )[i]; if( !ldpenv || !strstr( ldpenv, path ) ) { *( (const char **) apr_array_push( newpaths ) ) = path; DEBUG( "New path to add: %s", path ); } } // Need to set LD_LIBRARY_PATH, new paths found. if( newpaths->nelts > 0 ) { if( ldpenv ) { *( (const char **) apr_array_push( newpaths ) ) = ldpenv; } ldpenv = apr_array_pstrcat( _mp, newpaths, ':' ); DEBUG( "New %s = [%s]", LIB_PATH_VAR, ldpenv ); rv = apr_env_set( LIB_PATH_VAR, ldpenv, _mp ); const char *exe_name = NULL; if( rv == APR_SUCCESS ) { rv = find_self_exe( &exe_name ); } // Exec using linux(-only?) /proc/self/exe link to self, // instead of argv[0], since the later will not specify a path // when initial call is made via PATH, and since execve won't // itself look at PATH. // Note: Can't use apr_proc_create for this, since it always // forks first. if( rv == APR_SUCCESS ) { DEBUG( "Exec'ing self as %s", argv[0] ); execv( exe_name, (char * const *) argv ); rv = APR_FROM_OS_ERROR( errno ); //shouldn't return from execv call } } return rv; }
static void test_setenv(CuTest *tc) { apr_status_t rv; rv = apr_env_set(TEST_ENVVAR_NAME, TEST_ENVVAR_VALUE, p); have_env_set = (rv != APR_ENOTIMPL); if (!have_env_set) { CuNotImpl(tc, "apr_env_set"); return; } apr_assert_success(tc, "set environment variable", rv); }
static void test_setenv(abts_case *tc, void *data) { apr_status_t rv; rv = apr_env_set(TEST_ENVVAR_NAME, TEST_ENVVAR_VALUE, p); have_env_set = (rv != APR_ENOTIMPL); if (!have_env_set) { ABTS_NOT_IMPL(tc, "apr_env_set"); } else { APR_ASSERT_SUCCESS(tc, "set environment variable", rv); } }
int lua_apr_env_set(lua_State *L) { const char *name, *value; apr_pool_t *memory_pool; apr_status_t status; memory_pool = to_pool(L); name = luaL_checkstring(L, 1); value = luaL_checkstring(L, 2); status = apr_env_set(name, value, memory_pool); return push_status(L, status); }
/* set environment variable */ void MVM_proc_setenv(MVMThreadContext *tc, MVMString *var, MVMString *value) { apr_status_t rv; char *varstring = MVM_string_utf8_encode_C_string(tc, var); char *valuestring = MVM_string_utf8_encode_C_string(tc, value); apr_pool_t *tmp_pool; /* need a temporary pool */ if ((rv = apr_pool_create(&tmp_pool, POOL(tc))) != APR_SUCCESS) { MVM_exception_throw_apr_error(tc, rv, "Failed to set env variable: "); } if ((rv = apr_env_set((const char *)varstring, (const char *)valuestring, tmp_pool)) != APR_SUCCESS) { free(varstring); free(valuestring); apr_pool_destroy(tmp_pool); MVM_exception_throw_apr_error(tc, rv, "Failed to set env variable: "); } free(varstring); free(valuestring); apr_pool_destroy(tmp_pool); }
/* Standard svn test program */ int main(int argc, const char *argv[]) { const char *prog_name; int i; svn_boolean_t got_error = FALSE; apr_pool_t *pool, *test_pool; svn_boolean_t ran_a_test = FALSE; svn_boolean_t list_mode = FALSE; int opt_id; apr_status_t apr_err; apr_getopt_t *os; svn_error_t *err; char errmsg[200]; /* How many tests are there? */ int array_size = get_array_size(); svn_test_opts_t opts = { NULL }; opts.fs_type = DEFAULT_FS_TYPE; /* Initialize APR (Apache pools) */ if (apr_initialize() != APR_SUCCESS) { printf("apr_initialize() failed.\n"); exit(1); } /* set up the global pool. Use a separate allocator to limit memory * usage but make it thread-safe to allow for multi-threaded tests. */ pool = apr_allocator_owner_get(svn_pool_create_allocator(TRUE)); /* Remember the command line */ test_argc = argc; test_argv = argv; err = svn_cmdline__getopt_init(&os, argc, argv, pool); os->interleave = TRUE; /* Let options and arguments be interleaved */ /* Strip off any leading path components from the program name. */ prog_name = strrchr(argv[0], '/'); if (prog_name) prog_name++; else { /* Just check if this is that weird platform that uses \ instead of / for the path separator. */ prog_name = strrchr(argv[0], '\\'); if (prog_name) prog_name++; else prog_name = argv[0]; } if (err) return svn_cmdline_handle_exit_error(err, pool, prog_name); while (1) { const char *opt_arg; /* Parse the next option. */ apr_err = apr_getopt_long(os, cl_options, &opt_id, &opt_arg); if (APR_STATUS_IS_EOF(apr_err)) break; else if (apr_err && (apr_err != APR_BADCH)) { /* Ignore invalid option error to allow passing arbitary options */ fprintf(stderr, "apr_getopt_long failed : [%d] %s\n", apr_err, apr_strerror(apr_err, errmsg, sizeof(errmsg))); exit(1); } switch (opt_id) { case cleanup_opt: cleanup_mode = TRUE; break; case config_opt: opts.config_file = apr_pstrdup(pool, opt_arg); break; case fstype_opt: opts.fs_type = apr_pstrdup(pool, opt_arg); break; case list_opt: list_mode = TRUE; break; case mode_filter_opt: if (svn_cstring_casecmp(opt_arg, "PASS") == 0) mode_filter = svn_test_pass; else if (svn_cstring_casecmp(opt_arg, "XFAIL") == 0) mode_filter = svn_test_xfail; else if (svn_cstring_casecmp(opt_arg, "SKIP") == 0) mode_filter = svn_test_skip; else if (svn_cstring_casecmp(opt_arg, "ALL") == 0) mode_filter = svn_test_all; else { fprintf(stderr, "FAIL: Invalid --mode-filter option. Try "); fprintf(stderr, " PASS, XFAIL, SKIP or ALL.\n"); exit(1); } break; case verbose_opt: verbose_mode = TRUE; break; case quiet_opt: quiet_mode = TRUE; break; case allow_segfault_opt: allow_segfaults = TRUE; break; case server_minor_version_opt: { char *end; opts.server_minor_version = (int) strtol(opt_arg, &end, 10); if (end == opt_arg || *end != '\0') { fprintf(stderr, "FAIL: Non-numeric minor version given\n"); exit(1); } if ((opts.server_minor_version < 3) || (opts.server_minor_version > 6)) { fprintf(stderr, "FAIL: Invalid minor version given\n"); exit(1); } } } } /* Disable sleeping for timestamps, to speed up the tests. */ apr_env_set( "SVN_I_LOVE_CORRUPTED_WORKING_COPIES_SO_DISABLE_SLEEP_FOR_TIMESTAMPS", "yes", pool); /* You can't be both quiet and verbose. */ if (quiet_mode && verbose_mode) { fprintf(stderr, "FAIL: --verbose and --quiet are mutually exclusive\n"); exit(1); } /* Create an iteration pool for the tests */ cleanup_pool = svn_pool_create(pool); test_pool = svn_pool_create(pool); if (!allow_segfaults) svn_error_set_malfunction_handler(svn_error_raise_on_malfunction); if (argc >= 2) /* notice command-line arguments */ { if (! strcmp(argv[1], "list") || list_mode) { const char *header_msg; ran_a_test = TRUE; /* run all tests with MSG_ONLY set to TRUE */ header_msg = "Test # Mode Test Description\n" "------ ----- ----------------\n"; for (i = 1; i <= array_size; i++) { if (do_test_num(prog_name, i, TRUE, &opts, &header_msg, test_pool)) got_error = TRUE; /* Clear the per-function pool */ svn_pool_clear(test_pool); svn_pool_clear(cleanup_pool); } } else { for (i = 1; i < argc; i++) { if (svn_ctype_isdigit(argv[i][0]) || argv[i][0] == '-') { int test_num = atoi(argv[i]); if (test_num == 0) /* A --option argument, most likely. */ continue; ran_a_test = TRUE; if (do_test_num(prog_name, test_num, FALSE, &opts, NULL, test_pool)) got_error = TRUE; /* Clear the per-function pool */ svn_pool_clear(test_pool); svn_pool_clear(cleanup_pool); } } } } if (! ran_a_test) { /* just run all tests */ for (i = 1; i <= array_size; i++) { if (do_test_num(prog_name, i, FALSE, &opts, NULL, test_pool)) got_error = TRUE; /* Clear the per-function pool */ svn_pool_clear(test_pool); svn_pool_clear(cleanup_pool); } } /* Clean up APR */ svn_pool_destroy(pool); /* takes test_pool with it */ apr_terminate(); return got_error; }
static int ape_env_set( lua_State* L ) { char const* name = luaL_checkstring( L, 1 ); char const* value = luaL_checkstring( L, 2 ); apr_pool_t** pool = ape_opt_pool( L, 3 ); return ape_status( L, -1, apr_env_set( name, value, *pool ) ); }
LIB_INTERNAL void run_bg_cmd(LOGMANAGER *mp, const char *cmd , const char *file_path, TIMESTAMP t) { char buf[32]; DECLARE_TPOOL; apr_procattr_t *attr; apr_proc_t proc; const char *args[2]; apr_status_t status; char errbuf[1024]; NORMALIZE_TIMESTAMP(t); if (!cmd) return; /* Security */ DEBUG1(mp,1,"Running background command : %s",cmd); /* Set environment variables */ (void)apr_env_set("LOGMANAGER_FILE_PATH",(file_path ? file_path : "") ,CHECK_TPOOL()); (void)apr_env_set("LOGMANAGER_BASE_PATH",mp->base_path,CHECK_TPOOL()); (void)apr_env_set("LOGMANAGER_BASE_DIR",mp->base_dir,CHECK_TPOOL()); (void)apr_env_set("LOGMANAGER_LOG_PATH",mp->log_path,CHECK_TPOOL()); (void)apr_env_set("LOGMANAGER_LOG_DIR",mp->log_dir,CHECK_TPOOL()); (void)apr_env_set("LOGMANAGER_COMPRESSION" ,mp->compress.handler->suffix,CHECK_TPOOL()); (void)apr_env_set("LOGMANAGER_VERSION",PACKAGE_VERSION,CHECK_TPOOL()); (void)apr_snprintf(buf,sizeof(buf),"%" TIMESTAMP_FMT,t); (void)apr_env_set("LOGMANAGER_TIME",buf,CHECK_TPOOL()); /* Run background process */ (void)apr_procattr_create(&attr,CHECK_TPOOL()); /* APR_NO_FILE is defined in APR 1.3.0 and higher */ #ifdef APR_NO_FILE #define LMGR_IO_ATTR APR_NO_FILE #else #define LMGR_IO_ATTR 0 #endif /*(void)apr_procattr_io_set(attr,LMGR_IO_ATTR,LMGR_IO_ATTR,LMGR_IO_ATTR);*/ (void)apr_procattr_cmdtype_set(attr,APR_PROGRAM_ENV); (void)apr_procattr_detach_set(attr,1); (void)apr_procattr_error_check_set(attr,1); (void)apr_procattr_child_errfn_set(attr,_proc_create_error_callback); args[0]=cmd; args[1]=NULL; status=apr_proc_create(&proc,cmd,args,NULL, attr,CHECK_TPOOL()); if (status != APR_SUCCESS) { _proc_create_error(mp,CHECK_TPOOL(),status ,apr_strerror(status,errbuf,sizeof(errbuf))); } /* The background process lives its own life. Don't care about it anymore */ FREE_TPOOL(); return; }