Skip to content

DRAFT: Ports command line argument handling for proxy and handler to Rust #48232

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 16 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 15 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
101 changes: 74 additions & 27 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ zmq = "0.9"
[dev-dependencies]
criterion = "0.5"
env_logger = { version = "0.9", default-features = false }
tempfile = "3.20.0"
test-log = "0.2"

[build-dependencies]
Expand Down Expand Up @@ -82,7 +83,7 @@ bench = false

[[bin]]
name = "pushpin-handler"
test = false
test = true
bench = false

[[bin]]
Expand Down
6 changes: 5 additions & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,11 @@ fn get_qt_lib_prefix(lib_dir: &Path, version_maj: u16) -> Result<String, Box<dyn
}

fn find_boost_include_dir() -> Result<PathBuf, Box<dyn Error>> {
let paths = ["/usr/local/include", "/usr/include"];
let paths = [
"/usr/local/include",
"/usr/include",
"/opt/homebrew/include",
];
let version_filename = "boost/version.hpp";

for path in paths {
Expand Down
Empty file added log.txt
Empty file.
7 changes: 5 additions & 2 deletions src/bin/pushpin-handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,18 @@
* limitations under the License.
*/

use clap::Parser;
use pushpin::core::call_c_main;
use pushpin::core::ccliargs::CCliArgs;
use pushpin::import_cpp;
use std::env;
use std::process::ExitCode;

import_cpp! {
fn handler_main(argc: libc::c_int, argv: *const *const libc::c_char) -> libc::c_int;
}

fn main() -> ExitCode {
unsafe { ExitCode::from(call_c_main(handler_main, env::args_os())) }
let c_cli_args = CCliArgs::parse().verify();

unsafe { ExitCode::from(call_c_main(handler_main, c_cli_args.into_osstring_vec())) }
}
7 changes: 5 additions & 2 deletions src/bin/pushpin-proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,18 @@
* limitations under the License.
*/

use clap::Parser;
use pushpin::core::call_c_main;
use pushpin::core::ccliargs::CCliArgs;
use pushpin::import_cpp;
use std::env;
use std::process::ExitCode;

import_cpp! {
fn proxy_main(argc: libc::c_int, argv: *const *const libc::c_char) -> libc::c_int;
}

fn main() -> ExitCode {
unsafe { ExitCode::from(call_c_main(proxy_main, env::args_os())) }
let c_cli_args = CCliArgs::parse().verify();

unsafe { ExitCode::from(call_c_main(proxy_main, c_cli_args.into_osstring_vec())) }
}
88 changes: 88 additions & 0 deletions src/core/argsdata.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
* Copyright (C) 2015-2022 Fanout, Inc.
* Copyright (C) 2024-2025 Fastly, Inc.
*
* This file is part of Pushpin.
*
* $FANOUT_BEGIN_LICENSE:APACHE2$
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* $FANOUT_END_LICENSE$
*/

#include "argsdata.h"
#include "settings.h"
#include "config.h"
#include "log.h"
#include <QCoreApplication>
#include <QFile>


Settings ArgsData::loadIntoSettings()
{
Settings settings(configFile);

if(!ipcPrefix.isEmpty())
settings.setIpcPrefix(ipcPrefix);

if(portOffset != -1)
settings.setPortOffset(portOffset);

return settings;
}

ArgsData::ArgsData(QStringList &extArgs)
{
if(extArgs.isEmpty())
{
log_error("Error processing arguments. Use --help for usage.");
throw std::exception();
}

configFile = extArgs[0];
logFile = !extArgs[1].isEmpty() ? extArgs[1] : QString();
logLevel = extArgs[2].toInt();
ipcPrefix = extArgs[3];
portOffset = !extArgs[4].isEmpty() ? extArgs[4].toInt() : -1;
routeLines = extArgs[5].isEmpty() ? QStringList() : extArgs[5].split(',');
quietCheck = extArgs[6] == "true" ? true : false;

// Set the log level
if(logLevel != -1)
log_setOutputLevel(logLevel);
else
log_setOutputLevel(LOG_LEVEL_INFO);

// Set the log file if specified
if(!logFile.isEmpty())
{
if(!log_setFile(logFile))
{
log_error("failed to open log file: %s", qPrintable(logFile));
throw std::exception();
}
}

log_debug("starting...");

// QSettings doesn't inform us if the config file can't be opened, so do that ourselves
{
QFile file(configFile);
if(!file.open(QIODevice::ReadOnly))
{
log_error("failed to open %s", qPrintable(configFile));
throw std::exception();
}
}
}
Loading