]> git.ipfire.org Git - thirdparty/squid.git/blobdiff - tools/cachemgr.cc
SourceFormat: enforcement
[thirdparty/squid.git] / tools / cachemgr.cc
index 211a29c899e1df53f98e3e0d0feb3a3329289643..d36e9935c7e73c9b517417e9c5761f925beb3129 100644 (file)
 #include <sys/select.h>
 #endif
 #if HAVE_FNMATCH_H
-extern "C"
-{
+extern "C" {
 #include <fnmatch.h>
 }
 #endif
@@ -871,13 +870,17 @@ 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);
 }
 
 int
-main(int argc, char *argv[]) {
+main(int argc, char *argv[])
+{
     char *s;
     cachemgr_request *req;
 
@@ -909,7 +912,8 @@ main(int argc, char *argv[]) {
 }
 
 static char *
-read_post_request(void) {
+read_post_request(void)
+{
     char *s;
     char *buf;
     int len;
@@ -928,7 +932,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';
 
@@ -936,7 +941,8 @@ read_post_request(void) {
 }
 
 static char *
-read_get_request(void) {
+read_get_request(void)
+{
     char *s;
 
     if ((s = getenv("QUERY_STRING")) == NULL)
@@ -946,7 +952,8 @@ read_get_request(void) {
 }
 
 static cachemgr_request *
-read_request(void) {
+read_request(void)
+{
     char *buf;
 
     cachemgr_request *req;
@@ -1025,7 +1032,8 @@ read_request(void) {
  * Currently no powerful encryption is used.
  */
 static void
-make_pub_auth(cachemgr_request * req) {
+make_pub_auth(cachemgr_request * req)
+{
     static char buf[1024];
     safe_free(req->pub_auth);
     debug(3) fprintf(stderr, "cmgr: encoding for pub...\n");
@@ -1048,7 +1056,8 @@ make_pub_auth(cachemgr_request * req) {
 }
 
 static void
-decode_pub_auth(cachemgr_request * req) {
+decode_pub_auth(cachemgr_request * req)
+{
     char *buf;
     const char *host_name;
     const char *time_str;
@@ -1106,13 +1115,15 @@ decode_pub_auth(cachemgr_request * req) {
 }
 
 static void
-reset_auth(cachemgr_request * req) {
+reset_auth(cachemgr_request * req)
+{
     safe_free(req->passwd);
     safe_free(req->pub_auth);
 }
 
 static const char *
-make_auth_header(const cachemgr_request * req) {
+make_auth_header(const cachemgr_request * req)
+{
     static char buf[1024];
     size_t stringLength = 0;
     const char *str64;
@@ -1137,7 +1148,8 @@ make_auth_header(const cachemgr_request * req) {
 }
 
 static int
-check_target_acl(const char *hostname, int port) {
+check_target_acl(const char *hostname, int port)
+{
     char config_line[BUFSIZ];
     FILE *fp = NULL;
     int ret = 0;