Skip to content
Snippets Groups Projects
Commit 595229c9 authored by Paul's avatar Paul :turtle:
Browse files

errorhandling for nsupdate

parent a37ffbe4
No related branches found
No related tags found
No related merge requests found
Pipeline #4562 passed with warnings
......@@ -34,6 +34,11 @@ pub enum Error {
RecordTypeNotMatching,
}
impl From<String> for Error {
fn from(foo: String) -> Self {
Self::UpdateError(foo)
}
}
impl Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
......@@ -85,7 +90,7 @@ impl Service {
nsup.add_command(nsupdate::nsupdate::UpdateCommand::delete(&update.domain));
nsup.add_command(nsupdate::nsupdate::UpdateCommand::add(&update.domain, update.addr));
nsupdate::run_nsupdate(nsup);
nsupdate::run_nsupdate(nsup)?;
Ok(())
}
......
#![feature(proc_macro_hygiene, decl_macro)]
#![feature(proc_macro_hygiene, decl_macro, exit_status_error)]
mod config;
mod db;
......
......@@ -6,37 +6,35 @@ use std::process::Stdio;
use std::io::Write;
use nsupdate::UpdateMessage;
use log::{warn, info, debug};
use std::io::Read;
use std::thread;
pub fn run_nsupdate(msg: UpdateMessage) {
pub fn run_nsupdate(msg: UpdateMessage) -> Result<(),String>{
let mut child = Command::new(NSUPDATE_BIN)
.stdout(Stdio::null())
.stdin(Stdio::piped())
// .arg("--launch=remote")
// .arg("--no-config")
// .arg("--daemon=no")
// .arg("--log-dns-queries=yes")
// .arg("--loglevel=5")
// .arg("--disable-syslog")
// .arg(format!("--socket-dir={}", CTRL_SOCKET))
// .arg(format!("--local-port={}", self.dns_port))
// .arg(format!("--local-address={}", self.dns_address))
// .arg(format!("--remote-connection-string={}", REMOTE_API_URL))
.stderr(Stdio::piped())
.spawn()
.expect("cannot start pdns_server");
let mut stdin = child.stdin.take().expect("stdin for nsupdate process is not available");
let mut stderr = child.stderr.take().expect("stderr for nsupdate process is not available");
let updatestring = msg.finalize();
debug!("sending to nsupdate: {}", updatestring);
warn!("writing to nsupdate");
stdin.write_all(updatestring.as_bytes()).expect("cannot write to nsupdate process");
// finish input
stdin.write(b"\n").unwrap();
stdin.write(&[0x4]).unwrap();
stdin.flush().unwrap();
warn!("wating for nsupdate to exit");
// child.wait().unwrap();
warn!("nsupdate exited");
let stdin_thread = thread::spawn(move || {
stdin.write_all(updatestring.as_bytes()).expect("cannot write to nsupdate process");
// finish input
stdin.flush().unwrap();
drop(stdin);
});
let mut error = String::new();
stderr.read_to_string(&mut error).unwrap();
let rcode = child.wait().unwrap();
info!("nsupdate returned {}", rcode);
stdin_thread.join().unwrap();
rcode.exit_ok().map_err(|_| {error})
}
......@@ -5,7 +5,7 @@ use crate::DNSTTL;
// server 127.0.0.1
// update delete a.dyn.example.com A
// update delete a.dyn.example.com
// update add a.dyn.example.com 60 A 123.23.123.1
// send
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment