From 38a60755c7fa8e90b08273c6f2a0563ffc433f75 Mon Sep 17 00:00:00 2001 From: Timo Weingärtner Date: Sat, 10 May 2014 00:48:36 +0200 Subject: also replace custom fatal errors with exceptions --- ssh-agent-filter.C | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/ssh-agent-filter.C b/ssh-agent-filter.C index e2777c7..ed0d7a7 100644 --- a/ssh-agent-filter.C +++ b/ssh-agent-filter.C @@ -47,6 +47,8 @@ using std::flush; #include using std::runtime_error; +using std::length_error; +using std::invalid_argument; #include using std::system_error; @@ -131,10 +133,8 @@ int make_upstream_agent_conn () { int sock; struct sockaddr_un addr; - if (!(path = getenv("SSH_AUTH_SOCK"))) { - clog << "no $SSH_AUTH_SOCK" << endl; - exit(EX_UNAVAILABLE); - } + if (!(path = getenv("SSH_AUTH_SOCK"))) + throw invalid_argument("no $SSH_AUTH_SOCK"); if ((sock = socket(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0)) == -1) throw system_error(errno, system_category(), "socket"); @@ -142,10 +142,8 @@ int make_upstream_agent_conn () { addr.sun_family = AF_UNIX; - if (strlen(path) >= sizeof(addr.sun_path)) { - clog << "$SSH_AUTH_SOCK too long" << endl; - exit(EX_UNAVAILABLE); - } + if (strlen(path) >= sizeof(addr.sun_path)) + throw length_error("$SSH_AUTH_SOCK too long"); strcpy(addr.sun_path, path); @@ -165,10 +163,8 @@ int make_listen_sock () { addr.sun_family = AF_UNIX; - if (path.native().length() >= sizeof(addr.sun_path)) { - clog << "path for listen socket too long" << endl; - exit(EX_UNAVAILABLE); - } + if (path.native().length() >= sizeof(addr.sun_path)) + throw length_error("path for listen socket too long"); strcpy(addr.sun_path, path.c_str()); -- cgit v1.2.3