예제 #1
0
파일: testfile.c 프로젝트: XianliangJ/mtcp
static void link_nonexisting(abts_case *tc, void *data)
{
    apr_status_t rv;

    rv = apr_file_link("data/does_not_exist.txt", "data/fake.txt");
    ABTS_ASSERT(tc, "", rv != APR_SUCCESS);
}
예제 #2
0
파일: testfile.c 프로젝트: XianliangJ/mtcp
static void link_existing(abts_case *tc, void *data)
{
    apr_status_t rv;

    rv = apr_file_link("data/file_datafile.txt", "data/file_datafile2.txt");
    apr_file_remove("data/file_datafile2.txt", p);
    ABTS_ASSERT(tc, "Couldn't create hardlink to file", rv == APR_SUCCESS);
}
예제 #3
0
파일: io_file.c 프로젝트: LuaDist/lua-apr
int lua_apr_file_link(lua_State *L)
{
  const char *source, *target;
  apr_status_t status;

  source = luaL_checkstring(L, 1);
  target = luaL_checkstring(L, 2);
  status = apr_file_link(source, target);

  return push_status(L, status);
}
void nx_expr_proc__xm_fileop_file_link(nx_expr_eval_ctx_t *eval_ctx,
				       nx_module_t *module,
				       nx_expr_arg_list_t *args)
{
#ifdef HAVE_APR_FILE_LINK
    nx_expr_arg_t *src, *dst;
    nx_value_t srcval, dstval;
    nx_exception_t e;
    apr_status_t rv;

    ASSERT(module != NULL);

    ASSERT(args != NULL);
    src = NX_DLIST_FIRST(args);
    ASSERT(src != NULL);
    ASSERT(src->expr != NULL);
    dst = NX_DLIST_NEXT(src, link);
    ASSERT(dst != NULL);
    ASSERT(dst->expr != NULL);

    nx_expr_evaluate(eval_ctx, &srcval, src->expr);

    if ( srcval.defined != TRUE )
    {
	throw_msg("'src' is undef");
    }
    if ( srcval.type != NX_VALUE_TYPE_STRING )
    {
	nx_value_kill(&srcval);
	throw_msg("string type required for 'src'");
    }

    try
    {
	nx_expr_evaluate(eval_ctx, &dstval, dst->expr);
    }
    catch(e)
    {
	nx_value_kill(&srcval);
	rethrow(e);
    }
    if ( dstval.defined != TRUE )
    {
	nx_value_kill(&srcval);
	throw_msg("'dst' is undef");
    }
    if ( dstval.type != NX_VALUE_TYPE_STRING )
    {
	nx_value_kill(&dstval);
	nx_value_kill(&srcval);
	throw_msg("string type required for 'dst'");
    }

    if ( (rv = apr_file_link(srcval.string->buf, dstval.string->buf)) != APR_SUCCESS )
    {
	log_aprerror(rv, "failed to link file from '%s' to '%s'", 
		     srcval.string->buf, dstval.string->buf);
    }
    nx_value_kill(&srcval);
    nx_value_kill(&dstval);
#else
    throw_msg("file_link() is not available because apr_file_link is not provided by the linked apr library. Recompile with a newer apr version");
#endif
}
/*
 * Handle post-rotate processing.
 */
static void post_rotate(apr_pool_t *pool, struct logfile *newlog,
                        rotate_config_t *config, rotate_status_t *status)
{
    apr_status_t rv;
    char error[120];
    apr_procattr_t *pattr;
    const char *argv[4];
    apr_proc_t proc;

    /* Handle link file, if configured. */
    if (config->linkfile) {
        apr_file_remove(config->linkfile, newlog->pool);
        if (config->verbose) {
            fprintf(stderr,"Linking %s to %s\n", newlog->name, config->linkfile);
        }
        rv = apr_file_link(newlog->name, config->linkfile);
        if (rv != APR_SUCCESS) {
            apr_strerror(rv, error, sizeof error);
            fprintf(stderr, "Error linking file %s to %s (%s)\n",
                    newlog->name, config->linkfile, error);
            exit(2);
        }
    }

    if (!config->postrotate_prog) {
        /* Nothing more to do. */
        return;
    }

    /* Collect any zombies from a previous run, but don't wait. */
    while (apr_proc_wait_all_procs(&proc, NULL, NULL, APR_NOWAIT, pool) == APR_CHILD_DONE)
        /* noop */;

    if ((rv = apr_procattr_create(&pattr, pool)) != APR_SUCCESS) {
        fprintf(stderr,
                "post_rotate: apr_procattr_create failed for '%s': %s\n",
                config->postrotate_prog,
                apr_strerror(rv, error, sizeof(error)));
        return;
    }

    rv = apr_procattr_error_check_set(pattr, 1);
    if (rv == APR_SUCCESS)
        rv = apr_procattr_cmdtype_set(pattr, APR_PROGRAM_ENV);

    if (rv != APR_SUCCESS) {
        fprintf(stderr,
                "post_rotate: could not set up process attributes for '%s': %s\n",
                config->postrotate_prog,
                apr_strerror(rv, error, sizeof(error)));
        return;
    }

    argv[0] = config->postrotate_prog;
    argv[1] = newlog->name;
    if (status->current.fd) {
        argv[2] = status->current.name;
        argv[3] = NULL;
    }
    else {
        argv[2] = NULL;
    }

    if (config->verbose)
        fprintf(stderr, "Calling post-rotate program: %s\n", argv[0]);

    rv = apr_proc_create(&proc, argv[0], argv, NULL, pattr, pool);
    if (rv != APR_SUCCESS) {
        fprintf(stderr, "Could not spawn post-rotate process '%s': %s\n",
                config->postrotate_prog,
                apr_strerror(rv, error, sizeof(error)));
        return;
    }
}