From: Davin McCall Date: Mon, 19 Jun 2017 09:02:39 +0000 (+0100) Subject: dinitctl: clean up a TODO. X-Git-Tag: v0.06~50 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=9e4907551c8c56efe149f07d7f8537008ba6904e;p=oweals%2Fdinit.git dinitctl: clean up a TODO. --- diff --git a/src/dinitctl.cc b/src/dinitctl.cc index e8c5daa..d431ac8 100644 --- a/src/dinitctl.cc +++ b/src/dinitctl.cc @@ -454,16 +454,13 @@ static int startStopService(int socknum, const char *service_name, Command comma // a response. Returns 1 on failure (with error logged), 0 on success. static int issueLoadService(int socknum, const char *service_name) { - using namespace std; - // Build buffer; uint16_t sname_len = strlen(service_name); int bufsize = 3 + sname_len; int r; - { - // TODO: new: catch exception - unique_ptr ubuf(new char[bufsize]); + try { + std::unique_ptr ubuf(new char[bufsize]); auto buf = ubuf.get(); buf[0] = DINIT_CP_LOADSERVICE; @@ -472,6 +469,10 @@ static int issueLoadService(int socknum, const char *service_name) r = write_all(socknum, buf, bufsize); } + catch (std::bad_alloc &badalloc) { + std::cerr << "dinitctl: " << badalloc.what() << std::endl; + return 1; + } if (r == -1) { perror("dinitctl: write");