]> git.itanic.dy.fi Git - rrdd/commitdiff
process: Print process output through the debug macros
authorTimo Kokkonen <timo.t.kokkonen@iki.fi>
Wed, 27 Jun 2012 15:35:50 +0000 (18:35 +0300)
committerTimo Kokkonen <timo.t.kokkonen@iki.fi>
Wed, 27 Jun 2012 19:43:07 +0000 (22:43 +0300)
As we are appending our own prefixes to all process prints, we might
aswell use the normal debug macros to unify the prints with the rest
of the debug output.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
process.c

index 1e5b0b755a3673f94a0e007461a76519f8f5db52..a471ab826137d3f974fa05f745e5ca312e8d0121 100644 (file)
--- a/process.c
+++ b/process.c
@@ -550,16 +550,11 @@ int run(const char *cmd, char *const argv[])
        fd_set rfds;
        int maxfd;
        int eof = 0;
-       char stdoutstr[32], stderrstr[32], indent[16] = { "                " };
 
-       indent[get_parent_count() + 1] = 0;
-               
        if ((child = do_fork()))
            return child;
 
        child = run_piped(cmd, argv, NULL, &ofd, &efd);
-       snprintf(stdoutstr, 32, "%sstdout", green_color);
-       snprintf(stderrstr, 32, "%sstderr", red_color);
 
        FD_ZERO(&rfds);
        FD_SET(ofd, &rfds);
@@ -569,7 +564,7 @@ int run(const char *cmd, char *const argv[])
                char *sptr , *eptr;
                char rbuf[BUF_SIZE];
                int bytes;
-               char *typestr;
+               int is_stderr = 0;
 
                maxfd = max(ofd, efd);
                error = select(maxfd, &rfds, NULL, NULL, NULL);
@@ -580,13 +575,12 @@ int run(const char *cmd, char *const argv[])
                }
 
                if (FD_ISSET(ofd, &rfds)) {
-                       typestr = stdoutstr;
                        bytes = read(ofd, rbuf, BUF_SIZE);
                        goto print;
                }
 
                if (FD_ISSET(efd, &rfds)) {
-                       typestr = stderrstr;
+                       is_stderr = 1;
                        bytes = read(efd, rbuf, BUF_SIZE);
                        goto print;
                }
@@ -609,7 +603,7 @@ print:
                 */
                if (bytes == 0) {
                        bytes = read(efd, rbuf, BUF_SIZE);
-                       typestr = stderrstr;
+                       is_stderr = 1;
                        eof = 1;
                }
 
@@ -617,8 +611,12 @@ print:
                while(bytes--) {
                        if (*eptr == '\n') {
                                *eptr = 0;
-                               fprintf(stderr, "%s[%5d %s] %s: %s%s\n", indent,
-                                      child, cmd, typestr, sptr, normal_color);
+                               if (is_stderr)
+                                       pr_err("%s: stderr: %s\n",
+                                               cmd, sptr);
+                               else
+                                       pr_info("%s: stdout: %s\n",
+                                               cmd, sptr);
                                sptr = eptr;
                        }
                        eptr++;