hush: add support for special vars in braces
[oweals/busybox.git] / printutils / lpd.c
index 953324452d7c8b3e7c1b3e80804965b4725c93ee..43c22948ff868020ced54365edd8df401b348b40 100644 (file)
@@ -95,7 +95,7 @@ static char *xmalloc_read_stdin(void)
 }
 
 int lpd_main(int argc, char *argv[]) MAIN_EXTERNALLY_VISIBLE;
-int lpd_main(int argc ATTRIBUTE_UNUSED, char *argv[])
+int lpd_main(int argc UNUSED_PARAM, char *argv[])
 {
        int spooling = spooling; // for compiler
        char *s, *queue;
@@ -160,7 +160,7 @@ int lpd_main(int argc ATTRIBUTE_UNUSED, char *argv[])
                        // (we exit 127 if helper cannot be executed)
                        var[1] = '\0';
                        // read and delete ctrlfile
-                       q = xmalloc_open_read_close(filenames[0], NULL);
+                       q = xmalloc_xopen_read_close(filenames[0], NULL);
                        unlink(filenames[0]);
                        // provide datafile name
                        // we can use leaky setenv since we are about to exec or exit
@@ -236,6 +236,9 @@ int lpd_main(int argc ATTRIBUTE_UNUSED, char *argv[])
                                fd = xopen(queue, O_RDWR | O_APPEND);
                }
 
+               // signal OK
+               safe_write(STDOUT_FILENO, "", 1);
+
                // copy the file
                real_len = bb_copyfd_size(STDIN_FILENO, fd, expected_len);
                if (real_len != expected_len) {
@@ -243,7 +246,7 @@ int lpd_main(int argc ATTRIBUTE_UNUSED, char *argv[])
                                expected_len, real_len);
                        goto err_exit;
                }
-               // get ACK and see whether it is NUL (ok)
+               // get EOF indicator, see whether it is NUL (ok)
                // (and don't trash s[0]!)
                if (safe_read(STDIN_FILENO, &s[1], 1) != 1 || s[1] != 0) {
                        // don't send error msg to peer - it obviously
@@ -262,6 +265,9 @@ int lpd_main(int argc ATTRIBUTE_UNUSED, char *argv[])
 
                free(s);
                close(fd); // NB: can do close(-1). Who cares?
+
+               // NB: don't do "signal OK" write here, it will be done
+               // at the top of the loop
        } // while (1)
 
  err_exit: