]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - scheduler/testlpd.c
Sync up with CUPS 1.7svn-r10893
[thirdparty/cups.git] / scheduler / testlpd.c
index 335312c3f8bb88f107598707974942cdb14cee74..c000ddc83bcb6663dda86cc3cb840b370e6402a6 100644 (file)
@@ -1,9 +1,9 @@
 /*
- * "$Id: testlpd.c 6649 2007-07-11 21:46:42Z mike $"
+ * "$Id: testlpd.c 6789 2007-08-13 19:52:43Z mike $"
  *
- *   cups-lpd test program for the Common UNIX Printing System (CUPS).
+ *   cups-lpd test program for CUPS.
  *
- *   Copyright 2007 by Apple Inc.
+ *   Copyright 2007-2013 by Apple Inc.
  *   Copyright 2006 by Easy Software Products, all rights reserved.
  *
  *   These coded instructions, statements, and computer programs are the
  */
 
 #include <cups/cups.h>
-#include <cups/string.h>
-#include <stdlib.h>
+#include <cups/string-private.h>
 #include <sys/stat.h>
-#include <errno.h>
+#include <sys/wait.h>
 #include <signal.h>
 #include <unistd.h>
 #include <fcntl.h>
  */
 
 static int     do_command(int outfd, int infd, const char *command);
-static int     print_job(int outfd, int infd, char *dest, char **args);
+static int     print_job(int outfd, int infd, char *dest, char **args) __attribute__((nonnull(4)));
 static int     print_waiting(int outfd, int infd, char *dest);
-static int     remove_job(int outfd, int infd, char *dest, char **args);
-static int     status_long(int outfd, int infd, char *dest, char **args);
-static int     status_short(int outfd, int infd, char *dest, char **args);
-static void    usage(void);
+static int     remove_job(int outfd, int infd, char *dest, char **args) __attribute__((nonnull(4)));
+static int     status_long(int outfd, int infd, char *dest, char **args) __attribute__((nonnull(4)));
+static int     status_short(int outfd, int infd, char *dest, char **args) __attribute__((nonnull(4)));
+static void    usage(void) __attribute__((noreturn));
 
 
 /*
@@ -68,7 +67,8 @@ main(int  argc,                               /* I - Number of command-line arguments */
   char *cupslpd_argv[1000];            /* Arguments for cups-lpd */
   int  cupslpd_stdin[2],               /* Standard input for cups-lpd */
        cupslpd_stdout[2],              /* Standard output for cups-lpd */
-       cupslpd_pid;                    /* Process ID for cups-lpd */
+       cupslpd_pid,                    /* Process ID for cups-lpd */
+       cupslpd_status;                 /* Status of cups-lpd process */
 
 
  /*
@@ -76,7 +76,7 @@ main(int  argc,                               /* I - Number of command-line arguments */
   */
 
   op              = NULL;
-  opargs          = NULL;
+  opargs          = argv + argc;
   dest            = NULL;
   cupslpd_argc    = 1;
   cupslpd_argv[0] = (char *)"cups-lpd";
@@ -86,7 +86,7 @@ main(int  argc,                               /* I - Number of command-line arguments */
     {
       cupslpd_argv[cupslpd_argc++] = argv[i];
 
-      if (argv[i][2])
+      if (!argv[i][2])
       {
         i ++;
 
@@ -114,7 +114,10 @@ main(int  argc,                            /* I - Number of command-line arguments */
       (strcmp(op, "print-job") && strcmp(op, "print-waiting") &&
        strcmp(op, "remove-job") && strcmp(op, "status-long") &&
        strcmp(op, "status-short")))
+  {
+    printf("op=\"%s\", dest=\"%s\", opargs=%p\n", op, dest, opargs);
     usage();
+  }
 
  /*
   * Run the cups-lpd program using pipes...
@@ -140,13 +143,11 @@ main(int  argc,                           /* I - Number of command-line arguments */
     * Child goes here...
     */
 
-    close(0);
-    dup(cupslpd_stdin[0]);
+    dup2(cupslpd_stdin[0], 0);
     close(cupslpd_stdin[0]);
     close(cupslpd_stdin[1]);
 
-    close(1);
-    dup(cupslpd_stdout[1]);
+    dup2(cupslpd_stdout[1], 1);
     close(cupslpd_stdout[0]);
     close(cupslpd_stdout[1]);
 
@@ -187,7 +188,10 @@ main(int  argc,                            /* I - Number of command-line arguments */
 
   close(cupslpd_stdin[1]);
   close(cupslpd_stdout[0]);
-  kill(cupslpd_pid, SIGTERM);
+
+  while (wait(&cupslpd_status) != cupslpd_pid);
+
+  printf("cups-lpd exit status was %d...\n", cupslpd_status);
 
  /*
   * Return the test status...
@@ -221,9 +225,9 @@ do_command(int        outfd,                /* I - Command file descriptor */
   }
 
   if (read(infd, &status, 1) < 1)
-    puts("IN: ERROR");
+    puts("STATUS: ERROR");
   else
-    printf("IN: %d\n", status);
+    printf("STATUS: %d\n", status);
 
   return (status);
 }
@@ -325,7 +329,7 @@ print_job(int  outfd,                       /* I - Command file descriptor */
 
   if (read(infd, command, 1) < 1)
   {
-    puts("IN: ERROR");
+    puts("STATUS: ERROR");
     close(fd);
     return (-1);
   }
@@ -333,7 +337,7 @@ print_job(int  outfd,                       /* I - Command file descriptor */
   {
     status = command[0];
 
-    printf("IN: %d\n", status);
+    printf("STATUS: %d\n", status);
   }
 
  /*
@@ -367,7 +371,7 @@ print_job(int  outfd,                       /* I - Command file descriptor */
 
   if (read(infd, command, 1) < 1)
   {
-    puts("IN: ERROR");
+    puts("STATUS: ERROR");
     close(fd);
     return (-1);
   }
@@ -375,7 +379,7 @@ print_job(int  outfd,                       /* I - Command file descriptor */
   {
     status = command[0];
 
-    printf("IN: %d\n", status);
+    printf("STATUS: %d\n", status);
   }
 
   return (status);
@@ -528,7 +532,7 @@ status_short(int  outfd,            /* I - Command file descriptor */
 static void
 usage(void)
 {
-  puts("Usage: testlpd [options] print-job printer user filename [... filename]");
+  puts("Usage: testlpd [options] print-job printer filename [... filename]");
   puts("       testlpd [options] print-waiting [printer or user]");
   puts("       testlpd [options] remove-job printer [user [job-id]]");
   puts("       testlpd [options] status-long [printer or user]");
@@ -542,5 +546,5 @@ usage(void)
 
 
 /*
- * End of "$Id: testlpd.c 6649 2007-07-11 21:46:42Z mike $".
+ * End of "$Id: testlpd.c 6789 2007-08-13 19:52:43Z mike $".
  */