Skip to content

qgs: add -m=MODE parameter for UNIX socket mode #451

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 32 additions & 3 deletions QuoteGeneration/quote_wrapper/qgs/server_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,10 @@ int main(int argc, const char* argv[])
bool no_daemon = false;
unsigned long int port = 0;
unsigned long int num_threads = 0;
unsigned long int mode = 0;
char *endptr = NULL;
if (argc > 4) {
cout << "Usage: " << argv[0] << "[--no-daemon] [-p=port_number] [-n=number_threads]"
cout << "Usage: " << argv[0] << "[--no-daemon] [-p=port_number] [-m=unix_socket_mode] [-n=number_threads]"
<< endl;
exit(1);
}
Expand All @@ -100,6 +101,19 @@ int main(int argc, const char* argv[])
}
cout << "port number [" << port << "] found in cmdline" << endl;
continue;
} else if (strncmp(argv[i], "-m=", 3 ) == 0) {
if (strspn(argv[i] + 3, "0123456789") != strlen(argv[i] + 3)) {
cout << "Please input valid socket mode" << endl;
exit(1);
}
errno = 0;
mode = strtoul(argv[i] + 3, &endptr, 8);
if (errno || strlen(endptr) || (mode > UINT_MAX) ) {
cout << "Please input valid socket mode" << endl;
exit(1);
}
cout << "socket mode [0" << oct << mode << dec << "] found in cmdline" << endl;
continue;
} else if (strncmp(argv[i], "-n=", 3) == 0) {
if (strspn(argv[i] + 3, "0123456789") != strlen(argv[i] + 3)) {
cout << "Please input valid thread number" << endl;
Expand All @@ -114,7 +128,7 @@ int main(int argc, const char* argv[])
cout << "thread number [" << num_threads << "] found in cmdline" << endl;
continue;
} else {
cout << "Usage: " << argv[0] << "[--no-daemon] [-p=port_number] [-n=number_threads]"
cout << "Usage: " << argv[0] << "[--no-daemon] [-p=port_number] [-m=unix_socket_mode] [-n=number_threads]"
<< endl;
exit(1);
}
Expand All @@ -123,7 +137,7 @@ int main(int argc, const char* argv[])

// Use the port number in QGS_CONFIG_FILE if no valid port number on
// command line
if (port == 0 || num_threads == 0) {
if (port == 0 || num_threads == 0 || mode == 0) {
ifstream config_file(QGS_CONFIG_FILE);
if (config_file.is_open()) {
string line;
Expand Down Expand Up @@ -155,6 +169,15 @@ int main(int argc, const char* argv[])
<< QGS_CONFIG_FILE << endl;
exit(1);
}
} else if (!mode && name.compare("socket_mode") == 0) {
errno = 0;
endptr = NULL;
mode = strtoul(value, &endptr, 8);
if (errno || strlen(endptr) || (mode > UINT_MAX)) {
cout << "Please input valid socket mode in "
<< QGS_CONFIG_FILE << endl;
exit(1);
}
} else if (!num_threads && name.compare("number_threads") == 0) {
errno = 0;
endptr = NULL;
Expand Down Expand Up @@ -206,6 +229,12 @@ int main(int argc, const char* argv[])
}
QGS_LOG_INFO("About to create QgsServer with num_thread = %d\n", (uint8_t)num_threads);
server = new QgsServer(io_service, ep, (uint8_t)num_threads);
/* Allow mode to be determined by umask by default,
* overriding only if an explicit mode is requested
*/
if (!port && mode != 0) {
chmod(QGS_UNIX_SOCKET_FILE, mode);
}
QGS_LOG_INFO("About to start main loop\n");
io_service.run();
QGS_LOG_INFO("Quit main loop\n");
Expand Down