Example #1
0
atf_error_t
atf_env_set(const char *name, const char *val)
{
    atf_error_t err;

#if defined(HAVE_SETENV)
    if (setenv(name, val, 1) == -1)
        err = atf_libc_error(errno, "Cannot set environment variable "
                             "'%s' to '%s'", name, val);
    else
        err = atf_no_error();
#elif defined(HAVE_PUTENV)
    char *buf;

    err = atf_text_format(&buf, "%s=%s", name, val);
    if (!atf_is_error(err)) {
        if (putenv(buf) == -1)
            err = atf_libc_error(errno, "Cannot set environment variable "
                                 "'%s' to '%s'", name, val);
        free(buf);
    }
#else
#   error "Don't know how to set an environment variable."
#endif

    return err;
}
Example #2
0
ATF_TC_BODY (cleanup_sigterm, tc)
{
    char *nofile;

    touch (atf_tc_get_config_var (tc, "tmpfile"));
    kill (getpid (), SIGTERM);

    RE (atf_text_format (&nofile, "%s.no", atf_tc_get_config_var (tc, "tmpfile")));
    touch (nofile);
    free (nofile);
}
Example #3
0
ATF_TC_BODY(set, tc)
{
    char *oldval;

    ATF_REQUIRE(atf_env_has("PATH"));
    RE(atf_text_format(&oldval, "%s", atf_env_get("PATH")));
    RE(atf_env_set("PATH", "foo-bar"));
    ATF_REQUIRE(strcmp(atf_env_get("PATH"), oldval) != 0);
    ATF_REQUIRE(strcmp(atf_env_get("PATH"), "foo-bar") == 0);
    free(oldval);

    ATF_REQUIRE(!atf_env_has("_UNDEFINED_VARIABLE_"));
    RE(atf_env_set("_UNDEFINED_VARIABLE_", "foo2-bar2"));
    ATF_REQUIRE(strcmp(atf_env_get("_UNDEFINED_VARIABLE_"),
                     "foo2-bar2") == 0);
}