summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRoland Reichwein <mail@reichwein.it>2023-02-12 18:54:34 +0100
committerRoland Reichwein <mail@reichwein.it>2023-02-12 18:54:34 +0100
commitaa79e8701d39de2a24b2de7b97d3fc137e87b27b (patch)
tree88af00d49ee97f2d113baed3ecbd17e0305b775d
parent3282755c3798b695177c961a5745267cda6c21c4 (diff)
Enable multiple arguments for FCGI app when run via webapp-runner
-rw-r--r--debian/changelog1
-rw-r--r--plugins/fcgi/fastcgiprocess.cpp13
-rw-r--r--plugins/fcgi/fastcgiprocess.h4
-rw-r--r--plugins/fcgi/webapp-runner.cpp6
4 files changed, 13 insertions, 11 deletions
diff --git a/debian/changelog b/debian/changelog
index 5a3e9a8..82e19e2 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -2,6 +2,7 @@ webserver (1.21) UNRELEASED; urgency=medium
* Separated out weblog
* Completed FCGI environment variables
+ * Enable multiple arguments for FCGI app when run via webapp-runner
-- Roland Reichwein <mail@reichwein.it> Sat, 11 Feb 2023 11:01:48 +0100
diff --git a/plugins/fcgi/fastcgiprocess.cpp b/plugins/fcgi/fastcgiprocess.cpp
index d43fa75..017cab6 100644
--- a/plugins/fcgi/fastcgiprocess.cpp
+++ b/plugins/fcgi/fastcgiprocess.cpp
@@ -61,7 +61,7 @@ FastCGIProcess::~FastCGIProcess()
stop();
}
-void run_fcgi_app(const std::string& command, const std::string& host, unsigned short port)
+void run_fcgi_app(const std::string& command, const std::string& host, unsigned short port, int arg, char* argv[])
{
boost::asio::io_context ioc;
boost::asio::ip::tcp::resolver resolver(ioc);
@@ -81,10 +81,10 @@ void run_fcgi_app(const std::string& command, const std::string& host, unsigned
close(fd);
}
- execl(command.c_str(), command.c_str(), (const char*)nullptr);
+ execv(command.c_str(), argv);
}
-void run_fcgi_app(const std::string& command, const std::filesystem::path& socket_path)
+void run_fcgi_app(const std::string& command, const std::filesystem::path& socket_path, int arg, char* argv[])
{
boost::asio::io_context ioc;
boost::asio::local::stream_protocol::acceptor file_acceptor(ioc);
@@ -103,7 +103,7 @@ void run_fcgi_app(const std::string& command, const std::filesystem::path& socke
close(fd);
}
- execl(command.c_str(), command.c_str(), (const char*)nullptr);
+ execv(command.c_str(), argv);
}
void FastCGIProcess::start()
@@ -116,11 +116,12 @@ void FastCGIProcess::start()
throw std::runtime_error("Fork unsuccessful.");
if (m_pid == 0) { // child process branch
+ char* argv[] {m_command.data(), nullptr};
try {
if (m_socket_path.empty())
- run_fcgi_app(m_command, m_host, m_port);
+ run_fcgi_app(m_command, m_host, m_port, 2, argv);
else
- run_fcgi_app(m_command, m_socket_path);
+ run_fcgi_app(m_command, m_socket_path, 2, argv);
} catch (const std::exception& ex) {
std::cout << "FastCGI process error: " << ex.what() << std::endl;
}
diff --git a/plugins/fcgi/fastcgiprocess.h b/plugins/fcgi/fastcgiprocess.h
index 18a5d5b..4c01609 100644
--- a/plugins/fcgi/fastcgiprocess.h
+++ b/plugins/fcgi/fastcgiprocess.h
@@ -10,8 +10,8 @@
#include <sys/mman.h>
#include <sys/types.h>
-void run_fcgi_app(const std::string& command, const std::string& host, unsigned short port);
-void run_fcgi_app(const std::string& command, const std::filesystem::path& socket_path);
+void run_fcgi_app(const std::string& command, const std::string& host, unsigned short port, int arg, char* argv[]);
+void run_fcgi_app(const std::string& command, const std::filesystem::path& socket_path, int arg, char* argv[]);
class FastCGIProcess
{
diff --git a/plugins/fcgi/webapp-runner.cpp b/plugins/fcgi/webapp-runner.cpp
index 64268f3..ad8c396 100644
--- a/plugins/fcgi/webapp-runner.cpp
+++ b/plugins/fcgi/webapp-runner.cpp
@@ -30,16 +30,16 @@ webapp-runner fcgi-socket0 ./fcgi1
int main(int argc, char* argv[])
{
try {
- if (argc == 3) {
+ if (argc >= 3) {
std::string address{argv[1]};
std::string command{argv[2]};
if (auto pos{address.find_last_of(':')}; pos != std::string::npos) {
std::string host{address.substr(0, pos)};
unsigned short port{static_cast<unsigned short>(std::stoul(address.substr(pos + 1)))};
- run_fcgi_app(command, host, port);
+ run_fcgi_app(command, host, port, argc - 2, &argv[2]);
} else {
- run_fcgi_app(command, address);
+ run_fcgi_app(command, address, argc - 2, &argv[2]);
}
} else {
usage();