Skip to content

Commit e0108f7

Browse files
author
Yasuo Ohgaki
committed
MFH
- Fixed CGI (or other SAPI) start up failure when mm save handler is used # More fixes will be merged when I commit session & output control patch
1 parent d28453a commit e0108f7

File tree

2 files changed

+41
-11
lines changed

2 files changed

+41
-11
lines changed

ext/session/mod_mm.c

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/*
22
+----------------------------------------------------------------------+
3-
| PHP version 4.0 |
3+
| PHP Version 4 |
44
+----------------------------------------------------------------------+
5-
| Copyright (c) 1997-2001 The PHP Group |
5+
| Copyright (c) 1997-2002 The PHP Group |
66
+----------------------------------------------------------------------+
77
| This source file is subject to version 2.02 of the PHP license, |
88
| that is bundled with this package in the file LICENSE, and is |
@@ -22,6 +22,7 @@
2222

2323
#ifdef HAVE_LIBMM
2424

25+
#include <unistd.h>
2526
#include <mm.h>
2627
#include <time.h>
2728
#include <sys/stat.h>
@@ -30,12 +31,13 @@
3031

3132
#include "php_session.h"
3233
#include "mod_mm.h"
34+
#include "SAPI.h"
3335

3436
#ifdef ZTS
3537
# error mm is not thread-safe
3638
#endif
3739

38-
#define PS_MM_PATH "/tmp/session_mm"
40+
#define PS_MM_FILE "session_mm_"
3941

4042
/* For php_uint32 */
4143
#include "ext/standard/basic_functions.h"
@@ -247,8 +249,36 @@ static void ps_mm_destroy(ps_mm *data)
247249

248250
PHP_MINIT_FUNCTION(ps_mm)
249251
{
252+
int save_path_len = strlen(PS(save_path));
253+
int mod_name_len = strlen(sapi_module.name);
254+
char *ps_mm_path, euid[30];
255+
int ret;
256+
250257
ps_mm_instance = calloc(sizeof(*ps_mm_instance), 1);
251-
if (ps_mm_initialize(ps_mm_instance, PS_MM_PATH) != SUCCESS) {
258+
if (!ps_mm_instance)
259+
return FAILURE;
260+
261+
if (!sprintf(euid,"%d", geteuid()))
262+
return FAILURE;
263+
264+
/* Directory + '/' + File + Module Name + Effective UID + \0 */
265+
ps_mm_path = do_alloca(save_path_len+1+sizeof(PS_MM_FILE)+mod_name_len+strlen(euid)+1);
266+
267+
memcpy(ps_mm_path, PS(save_path), save_path_len + 1);
268+
if (save_path_len > 0 && ps_mm_path[save_path_len - 1] != DEFAULT_SLASH) {
269+
ps_mm_path[save_path_len] = DEFAULT_SLASH;
270+
ps_mm_path[save_path_len+1] = '\0';
271+
}
272+
strcat(ps_mm_path, PS_MM_FILE);
273+
strcat(ps_mm_path, sapi_module.name);
274+
strcat(ps_mm_path, euid);
275+
276+
ret = ps_mm_initialize(ps_mm_instance, ps_mm_path);
277+
278+
free_alloca(ps_mm_path);
279+
280+
if (ret != SUCCESS) {
281+
free(ps_mm_instance);
252282
ps_mm_instance = NULL;
253283
return FAILURE;
254284
}
@@ -289,7 +319,6 @@ PS_READ_FUNC(mm)
289319
{
290320
PS_MM_DATA;
291321
ps_sd *sd;
292-
int ret = FAILURE;
293322

294323
mm_lock(data->mm, MM_LOCK_RD);
295324

@@ -299,12 +328,13 @@ PS_READ_FUNC(mm)
299328
*val = emalloc(sd->datalen + 1);
300329
memcpy(*val, sd->data, sd->datalen);
301330
(*val)[sd->datalen] = '\0';
302-
ret = SUCCESS;
303331
}
304-
332+
else {
333+
*val = estrdup("");
334+
}
305335
mm_unlock(data->mm);
306336

307-
return ret;
337+
return SUCCESS;
308338
}
309339

310340
PS_WRITE_FUNC(mm)
@@ -411,6 +441,6 @@ zend_module_entry php_session_mm_module = {
411441
* tab-width: 4
412442
* c-basic-offset: 4
413443
* End:
414-
* vim600: sw=4 ts=4 tw=78 fdm=marker
415-
* vim<600: sw=4 ts=4 tw=78
444+
* vim600: sw=4 ts=4 fdm=marker
445+
* vim<600: sw=4 ts=4
416446
*/

ext/session/session.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ static void php_session_track_init(TSRMLS_D)
437437
MAKE_STD_ZVAL(PS(http_session_vars));
438438
array_init(PS(http_session_vars));
439439
ZEND_SET_GLOBAL_VAR_WITH_LENGTH("HTTP_SESSION_VARS", sizeof("HTTP_SESSION_VARS"), PS(http_session_vars), 1, 0);
440-
ZEND_SET_GLOBAL_VAR_WITH_LENGTH("_SESSION", sizeof("_SESSION"), PS(http_session_vars), 2, 0);
440+
ZEND_SET_GLOBAL_VAR_WITH_LENGTH("_SESSION", sizeof("_SESSION"), PS(http_session_vars), 1, 0);
441441
}
442442
}
443443

0 commit comments

Comments
 (0)