Imported Upstream version 3.3.1
[debian/amanda] / server-src / amcheck.c
index 3acb9919fa04b97aa54e1350ab73f369fb34ad71..539397659ca8430d311049b52db5c737a4cbdced 100644 (file)
@@ -48,6 +48,7 @@
 #include "timestamp.h"
 #include "amxml.h"
 #include "physmem.h"
+#include <getopt.h>
 
 #define BUFFER_SIZE    32768
 
@@ -70,7 +71,7 @@ int test_server_pgm(FILE *outf, char *dir, char *pgm, int suid, uid_t dumpuid);
 void
 usage(void)
 {
-    g_printf(_("Usage: amcheck [-am] [-w] [-sclt] [-M <address>] [-o configoption]* <conf> [host [disk]* ]*\n"));
+    g_printf(_("Usage: amcheck [--version] [-am] [-w] [-sclt] [-M <address>] [--client-verbose] [-o configoption]* <conf> [host [disk]* ]*\n"));
     exit(1);
     /*NOTREACHED*/
 }
@@ -80,6 +81,13 @@ static char *our_feature_string = NULL;
 static char *displayunit;
 static long int unitdivisor;
 
+static int client_verbose = FALSE;
+static struct option long_options[] = {
+    {"client-verbose", 0, NULL,  1},
+    {"version"       , 0, NULL,  2},
+    {NULL, 0, NULL, 0}
+};
+
 int
 main(
     int                argc,
@@ -92,7 +100,7 @@ main(
     int do_clientchk, client_probs;
     int do_localchk, do_tapechk, server_probs;
     pid_t clientchk_pid, serverchk_pid;
-    int opt, tempfd, mainfd;
+    int tempfd, mainfd;
     size_t size;
     amwait_t retstat;
     pid_t pid;
@@ -152,8 +160,20 @@ main(
     /* process arguments */
 
     cfg_ovr = new_config_overrides(argc/2);
-    while((opt = getopt(argc, argv, "M:mawsclto:")) != EOF) {
-       switch(opt) {
+    while (1) {
+       int option_index = 0;
+       int c;
+       c = getopt_long (argc, argv, "M:mawsclto:", long_options, &option_index);
+       if (c == -1) {
+           break;
+       }
+
+       switch(c) {
+       case 1:         client_verbose = TRUE;
+                       break;
+       case 2:         printf("amcheck-%s\n", VERSION);
+                       return(0);
+                       break;
        case 'M':       if (mailto) {
                            g_printf(_("Multiple -M options\n"));
                            exit(1);
@@ -2105,6 +2125,7 @@ handle_result(
     char *t;
     int ch;
     int tch;
+    gboolean printed_hostname = FALSE;
 
     hostp = (am_host_t *)datap;
     hostp->up = HOST_READY;
@@ -2155,7 +2176,15 @@ handle_result(
            continue;
        }
 
+       if (client_verbose && !printed_hostname) {
+           g_fprintf(outf, "HOST %s\n", hostp->hostname);
+           printed_hostname = TRUE;
+       }
+
        if(strncmp_const(line, "OK ") == 0) {
+           if (client_verbose) {
+               g_fprintf(outf, "%s\n", line);
+           }
            continue;
        }