From 5c65e22e05b108c28140738836ad316a0addf78e Mon Sep 17 00:00:00 2001 From: Marat Omarov Date: Thu, 18 Jul 2024 01:24:35 +0300 Subject: [PATCH] Add check on NULL in getenv, update Build.yml --- .github/workflows/Build.yml | 14 +++++++++----- docs/session_test.php | 15 +++++++++++++-- runtime/sessions.cpp | 6 +++--- 3 files changed, 25 insertions(+), 10 deletions(-) diff --git a/.github/workflows/Build.yml b/.github/workflows/Build.yml index 1ab566a303..a1d217d2fb 100644 --- a/.github/workflows/Build.yml +++ b/.github/workflows/Build.yml @@ -124,23 +124,27 @@ jobs: - name: Copy the session_test file run: docker exec kphp-build-container-${{matrix.os}} bash -c - "su kitten -c 'cp ${{env.session_php_script}} ${{env.kphp_snippets_dir}}/JobWorkers/'" + "cp ${{env.session_php_script}} ${{env.kphp_snippets_dir}}/JobWorkers/" - name: Compile the session_test project run: docker exec kphp-build-container-${{matrix.os}} bash -c - "su kitten -c 'cd ${{env.kphp_snippets_dir}}/JobWorkers/ && ${{env.kphp_root_dir}}/objs/bin/kphp2cpp --cxx ${{matrix.compiler}} session_test.php -I .. -M server'" + "cd ${{env.kphp_snippets_dir}}/JobWorkers/ && ${{env.kphp_root_dir}}/objs/bin/kphp2cpp --cxx ${{matrix.compiler}} session_test.php -I .. -M server" - name: Start the server run: docker exec kphp-build-container-${{matrix.os}} bash -c - "su kitten -c 'cd ${{env.kphp_snippets_dir}}/JobWorkers/ && ./kphp_out/server -f 2 --http-port 8080 --job-workers-ratio 0.5 --sql-port 5555 &> log.txt &'" + "cd ${{env.kphp_snippets_dir}}/JobWorkers/ && ./kphp_out/server -f 2 --http-port 8080 --job-workers-ratio 0.5 --sql-port 5555 --user kitten &> log.txt &" + + - name: Install curl + run: docker exec kphp-build-container-${{matrix.os}} bash -c + "apt update && apt install curl" - name: Send a request to the server run: docker exec kphp-build-container-${{matrix.os}} bash -c "curl 'http://localhost:8080'" - - name: Read lgos + - name: Read logs run: docker exec kphp-build-container-${{matrix.os}} bash -c - "su kitten -c 'cd ${{env.kphp_snippets_dir}}/JobWorkers/ && tail -f logs.txt'" + "cd ${{env.kphp_snippets_dir}}/JobWorkers/ && cat log.txt" # - name: Remove docker container # run: docker rm -f kphp-build-container-${{matrix.os}} diff --git a/docs/session_test.php b/docs/session_test.php index b82e8cab7e..1ec390ae2b 100644 --- a/docs/session_test.php +++ b/docs/session_test.php @@ -105,7 +105,6 @@ function handleHttpRequest() { $timeout = 0.5; $to_write = ["first_message" => "hello"]; - // ["save_path" => "/Users/marat/Desktop/sessions/"] $main_request = new MyRequest([], $to_write, false, false); $main_job_id = \JobWorkers\JobLauncher::start($main_request, $timeout); @@ -126,9 +125,13 @@ function handleHttpRequest() { $main_request = new MyRequest([], ["second_message" => "world"], $session_id, true); $main_job_id = \JobWorkers\JobLauncher::start($main_request, $timeout); - $new_request = new MyRequest([], ["third_message" => "buy"], $session_id, false); + $additional_to_main_request = new MyRequest([], ["third_message" => "buy"], $session_id, false); + $additional_to_main_job_id = \JobWorkers\JobLauncher::start($additional_to_main_request, $timeout); + + $new_request = new MyRequest([], ["new_message" => "hi"], false, false); $new_job_id = \JobWorkers\JobLauncher::start($new_request, $timeout); + $additional_to_main_response = wait($additional_to_main_job_id); $new_response = wait($new_job_id); $main_response = wait($main_job_id); @@ -140,6 +143,14 @@ function handleHttpRequest() { echo "

"; } + if ($additional_to_main_response instanceof MyResponse) { + echo "
Opened session:
"; + var_dump($additional_to_main_response->session_status); + var_dump($additional_to_main_response->session_id); + var_dump($additional_to_main_response->session_array); + echo "

"; + } + if ($new_response instanceof MyResponse) { echo "
Opened session:
"; var_dump($new_response->session_status); diff --git a/runtime/sessions.cpp b/runtime/sessions.cpp index 89fa3a51cf..d577d1f429 100644 --- a/runtime/sessions.cpp +++ b/runtime/sessions.cpp @@ -59,7 +59,7 @@ constexpr static auto C_HTTPONLY = "cookie_httponly"; // TO-DO: reconsider it const auto skeys = vk::to_array>({ {S_READ_CLOSE, false}, - {S_DIR, string(getenv("TMPDIR")).append("sessions/")}, + {S_DIR, string((getenv("TMPDIR") != NULL) ? getenv("TMPDIR") : "/tmp/").append("sessions/")}, {S_NAME, string("PHPSESSID")}, {S_LIFETIME, 1440}, {S_PROBABILITY, 1}, @@ -209,7 +209,7 @@ static bool session_open() { bool is_new = (!f$file_exists(get_sparam(S_PATH).to_string())) ? 1 : 0; fprintf(stderr, "[%d]\tOpening the session file %s\n", getpid(), get_sparam(S_PATH).to_string().c_str()); - set_sparam(S_FD, open_safe(get_sparam(S_PATH).to_string().c_str(), O_RDWR | O_CREAT, 0777)); + set_sparam(S_FD, open_safe(get_sparam(S_PATH).to_string().c_str(), O_RDWR | O_CREAT, 0666)); if (get_sparam(S_FD).to_int() < 0) { php_warning("Failed to open the file %s", get_sparam(S_PATH).to_string().c_str()); @@ -323,7 +323,7 @@ static bool session_write() { fprintf(stderr, "[%d]\t(rewinding) Closed the file\n", getpid()); fprintf(stderr, "[%d]\t(rewinding) Opening the file\n", getpid()); - set_sparam(S_FD, open_safe(get_sparam(S_PATH).to_string().c_str(), O_RDWR, 0777)); + set_sparam(S_FD, open_safe(get_sparam(S_PATH).to_string().c_str(), O_RDWR, 0666)); fprintf(stderr, "[%d]\t(rewinding) Opened the file\n", getpid()); lock.l_type = F_WRLCK; fprintf(stderr, "[%d]\t(rewinding) Locking the file\n", getpid());