Skip to content

Commit

Permalink
git-svn-id: svn://cherokee-project.com/cherokee/trunk@2741 5dc97367-9…
Browse files Browse the repository at this point in the history
…7f1-0310-9951-d761b3857238
  • Loading branch information
alobbs committed Jan 22, 2009
1 parent f35186f commit 3dc0304
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 8 deletions.
15 changes: 15 additions & 0 deletions ChangeLog
@@ -1,3 +1,18 @@
2009-01-22 Alvaro Lopez Ortega <alvaro@octality.com>

* cherokee/init.h, cherokee/init.c, cherokee/post.c: Removes a
"/tmp" directory hardcoded path. From now on a global
cherokee_tmp_dir buffer is available with the temporal directory
path.

* cherokee/util.c (cherokee_tmp_dir_copy): A new utility function
has been added. It figures the temporal directory that Cherokee
ought to use. The first choice is the directory pointed by the
CHEROKEE_TMPDIR environment variable. In case it were empty it'd
try to read the TMPDIR environment variable (or TEMP on Windows).
Finally, if it failed as well, a hardcoded "/tmp" value would be
used.

2009-01-21 Taher Shihadeh <taher@unixwars.com>

* doc/modules_handlers_cgi.txt: added example as requested in
Expand Down
15 changes: 11 additions & 4 deletions cherokee/init.c
Expand Up @@ -34,10 +34,10 @@
# include "threading.h"
#endif

cuint_t cherokee_cacheline_size;
cint_t cherokee_cpu_number;
cuint_t cherokee_fdlimit;

cuint_t cherokee_cacheline_size;
cint_t cherokee_cpu_number;
cuint_t cherokee_fdlimit;
cherokee_buffer_t cherokee_tmp_dir;

static cherokee_boolean_t _cherokee_init = false;

Expand Down Expand Up @@ -86,13 +86,20 @@ cherokee_init (void)
return ret;
}

/* Temp directory
*/
cherokee_buffer_init (&cherokee_tmp_dir);
cherokee_tmp_dir_copy (&cherokee_tmp_dir);

_cherokee_init = true;
return ret_ok;
}

ret_t
cherokee_mrproper (void)
{
cherokee_buffer_mrproper (&cherokee_tmp_dir);

cherokee_bogotime_free();
cherokee_threading_free();

Expand Down
8 changes: 5 additions & 3 deletions cherokee/init.h
Expand Up @@ -30,6 +30,7 @@
#define CHEROKEE_INIT_H

#include <cherokee/common.h>
#include <cherokee/buffer.h>

CHEROKEE_BEGIN_DECLS

Expand All @@ -40,9 +41,10 @@ ret_t cherokee_mrproper (void);

/* Globals
*/
extern cuint_t cherokee_cacheline_size;
extern cint_t cherokee_cpu_number;
extern cuint_t cherokee_fdlimit;
extern cuint_t cherokee_cacheline_size;
extern cint_t cherokee_cpu_number;
extern cuint_t cherokee_fdlimit;
extern cherokee_buffer_t cherokee_tmp_dir;

CHEROKEE_END_DECLS

Expand Down
4 changes: 3 additions & 1 deletion cherokee/post.c
Expand Up @@ -25,6 +25,7 @@
#include "common-internal.h"
#include "post.h"
#include "util.h"
#include "init.h"

#include <stdlib.h>
#include <unistd.h>
Expand Down Expand Up @@ -90,7 +91,8 @@ cherokee_post_set_len (cherokee_post_t *post, off_t len)
TRACE(ENTRIES, "len=%d type=%d\n", len, post->type);

if (post->type == post_in_tmp_file) {
cherokee_buffer_add_str (&post->tmp_file, "/tmp/cherokee_post_XXXXXX");
cherokee_buffer_add_buffer (&post->tmp_file, &cherokee_tmp_dir);
cherokee_buffer_add_str (&post->tmp_file, "/cherokee_post_XXXXXX");

/* Generate a unique name
*/
Expand Down
32 changes: 32 additions & 0 deletions cherokee/util.c
Expand Up @@ -1640,3 +1640,35 @@ cherokee_ntop (int family, struct sockaddr *addr, char *dst, size_t cnt)
dst[0] = '\0';
return ret_error;
}


ret_t
cherokee_tmp_dir_copy (cherokee_buffer_t *buffer)
{
char *p;

/* Read a custom Cherokee variable
*/
p = getenv("CHEROKEE_TMPDIR");
if (p != NULL) {
cherokee_buffer_add (buffer, p, strlen(p));
return ret_ok;
}

/* Read the system variable
*/
#ifdef _WIN32
p = getenv("TEMP");
#else
p = getenv("TMPDIR");
#endif
if (p != NULL) {
cherokee_buffer_add (buffer, p, strlen(p));
return ret_ok;
}

/* Since everything has failed, let's go for /tmp
*/
cherokee_buffer_add_str (buffer, "/tmp");
return ret_ok;
}
1 change: 1 addition & 0 deletions cherokee/util.h
Expand Up @@ -144,6 +144,7 @@ ret_t cherokee_sys_fdlimit_get (cuint_t *limit);
ret_t cherokee_sys_fdlimit_set (cuint_t limit);
ret_t cherokee_get_shell (const char **shell, const char **binary);
void cherokee_print_wrapped (cherokee_buffer_t *buffer);
ret_t cherokee_tmp_dir_copy (cherokee_buffer_t *buffer);

/* IO vectors
*/
Expand Down

0 comments on commit 3dc0304

Please sign in to comment.