changeset 1032:f8b1844a4fc7

check fgets() and write() results
author Johannes Hofmann <Johannes.Hofmann@gmx.de>
date Sat, 28 Mar 2009 16:08:04 +0100
parents b06377790b00
children 70bac0031b1c
files src/IO/dpi.c
diffstat 1 files changed, 13 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/src/IO/dpi.c	Thu Mar 26 23:18:02 2009 +0000
+++ b/src/IO/dpi.c	Sat Mar 28 16:08:04 2009 +0100
@@ -371,7 +371,7 @@
 {
    FILE *in;
    char *saved_name_filename;    /*  :)  */
-   char dpid_uds_dir[256], *p = NULL;
+   char buf[256], *dpid_uds_dir, *p = NULL, *nl;
 
    saved_name_filename =
       dStrconcat(dGethomedir(), "/.dillo/dpi_socket_dir", NULL);
@@ -379,14 +379,16 @@
    dFree(saved_name_filename);
 
    if (in != NULL) {
-      fgets(dpid_uds_dir, 256, in);
+      dpid_uds_dir = fgets(buf, sizeof(buf), in);
       fclose(in);
-      if ((p = strchr(dpid_uds_dir, '\n'))) {
-         *p = 0;
-      }
-      if (access(dpid_uds_dir, F_OK) == 0) {
-         p = dStrdup(dpid_uds_dir);
-         _MSG("Dpi_get_dpid_uds_dir:: %s\n", p);
+      if (dpid_uds_dir) {
+         if ((nl = strchr(dpid_uds_dir, '\n'))) {
+            *nl = 0;
+         }
+         if (access(dpid_uds_dir, F_OK) == 0) {
+            p = dStrdup(dpid_uds_dir);
+            _MSG("Dpi_get_dpid_uds_dir:: %s\n", p);
+         }
       }
    }
 
@@ -730,7 +732,9 @@
       MSG("%s\n", sa.sun_path);
    }
    DpiBye_cmd = a_Dpip_build_cmd("cmd=%s", "DpiBye");
-   (void) write(new_socket, DpiBye_cmd, strlen(DpiBye_cmd));
+   if (write(new_socket, DpiBye_cmd, strlen(DpiBye_cmd)) !=
+       (ssize_t) strlen(DpiBye_cmd))
+      MSG_WARN("Failed to send DpiBye\n");
    dFree(DpiBye_cmd);
    Dpi_close_fd(new_socket);
 }