From bdcd85c36c1373c6ba80618405bcfe36d1ae9601 Mon Sep 17 00:00:00 2001 From: Amos Jeffries Date: Tue, 28 Apr 2009 00:05:38 +1200 Subject: [PATCH] Handle several IO errors cleanly. --- helpers/ntlm_auth/smb_lm/ntlm_smb_lm_auth.c | 6 ++++-- tools/cachemgr.cc | 9 ++++++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/helpers/ntlm_auth/smb_lm/ntlm_smb_lm_auth.c b/helpers/ntlm_auth/smb_lm/ntlm_smb_lm_auth.c index b06eadb8ae..80a9c3008c 100644 --- a/helpers/ntlm_auth/smb_lm/ntlm_smb_lm_auth.c +++ b/helpers/ntlm_auth/smb_lm/ntlm_smb_lm_auth.c @@ -461,11 +461,13 @@ manage_request() int main(int argc, char *argv[]) { - debug("ntlm_auth build " __DATE__ ", " __TIME__ " starting up...\n"); #ifdef DEBUG debug("changing dir to /tmp\n"); - chdir("/tmp"); + if (chdir("/tmp") != 0) { + debug("ERROR: (%d) failed.\n",errno); + return 2; + } #endif my_program_name = argv[0]; diff --git a/tools/cachemgr.cc b/tools/cachemgr.cc index 211a29c899..b9569cf501 100644 --- a/tools/cachemgr.cc +++ b/tools/cachemgr.cc @@ -871,8 +871,10 @@ process_request(cachemgr_request * req) req->hostname, req->action, make_auth_header(req)); - write(s, buf, l); - debug(1) fprintf(stderr, "wrote request: '%s'\n", buf); + if (write(s, buf, l) <0 ) + debug(1) fprintf(stderr, "ERROR: (%d) writing request: '%s'\n", errno, buf); + else + debug(1) fprintf(stderr, "wrote request: '%s'\n", buf); return read_reply(s, req); } @@ -928,7 +930,8 @@ read_post_request(void) { buf = (char *)xmalloc(len + 1); - fread(buf, len, 1, stdin); + if (fread(buf, len, 1, stdin) == 0) + return NULL; buf[len] = '\0'; -- 2.47.3