]> granicus.if.org Git - fcron/commitdiff
fcrondyn -x no longer print null characters at the end of the command output
authorThibault Godouet <fcron@free.fr>
Sun, 13 Apr 2014 16:54:05 +0000 (17:54 +0100)
committerThibault Godouet <fcron@free.fr>
Sun, 13 Apr 2014 16:54:05 +0000 (17:54 +0100)
doc/en/changes.sgml
fcrondyn.c

index 2f38dd4433c1bc8753ab79fc2cf88dd847b8757c..a2f8b5e13c61f7e0114a1d40a7294c1fb98177a5 100644 (file)
@@ -20,6 +20,9 @@ A copy of the license is included in gfdl.sgml.
            <listitem>
               <para>Fixed bug where LONG_MAX could potentially be used in functions like localtime(), which is too big for localtime().  This was unlikely to happen unless there was another problem in the first place.</para>
            </listitem>
+           <listitem>
+              <para>fcrondyn -x no longer adds null characters at the end of the output.  This would cause problems if the output was piped to something as grep.  Thanks Dimitri Semitsoglou-Tsiapos for pointing this out.</para>
+           </listitem>
       </itemizedlist>
 
       <itemizedlist>
index d6cbb47337bfe2410aef0913a684847882242af8..294768f6297bc7c19d17d6fb9e6ce4a4bbd89779 100644 (file)
@@ -143,8 +143,7 @@ usage(void)
             "  -d         set up debug mode.\n"
             "  -h         display this help message.\n"
             "  -V         display version & infos about fcrondyn.\n" "\n"
-            "To list the available commands, run:\n"
-            "  fcrondyn -x help\n");
+            "To list the available commands, run:\n" "  fcrondyn -x help\n");
 
     exit(EXIT_ERR);
 }
@@ -578,8 +577,10 @@ talk_fcron(char *cmd_str, int fd)
         return ERR;
     }
 
-    while ((read_len = (size_t) recv(fd, buf, sizeof(buf), 0)) >= 0
+
+    while ((read_len = (size_t) recv(fd, buf, sizeof(buf) - 1, 0)) >= 0
            || errno == EINTR) {
+
         if (errno == EINTR && debug_opt)
             fprintf(stderr, "got EINTR ...\n");
         else if (read_len > sizeof(buf)) {
@@ -595,16 +596,20 @@ talk_fcron(char *cmd_str, int fd)
             return ERR;
         }
         else {
-            if (write(STDOUT_FILENO, buf, read_len) < 0)
-                error_e("unable to write() to STDOUT_FILENO");
+            /* ensure the string is terminated by a '\0' for when we'll printf() it */
+            buf[read_len] = '\0';
+            printf("%s", buf);
+
+            /* check for the end of command output marker */
             if (read_len >= sizeof(END_STR) &&
                 strncmp(&buf[read_len - sizeof(END_STR)], END_STR,
                         sizeof(END_STR)) == 0)
                 break;
         }
     }
-    if (read_len < 0)
+    if (read_len < 0) {
         error_e("error in recv()");
+    }
 
     if (!existing_connection)
         xclose_check(&fd, "unix socket");