Merge tag 'upstream/3.3.3'
[debian/amanda] / client-src / selfcheck.c
index ac5ed538c8cd29a7964b1e5680943156564cdf00..dfffe2e3c8c214fe3b9b337d97c7ae88dd089f29 100644 (file)
@@ -1,6 +1,7 @@
 /*
  * Amanda, The Advanced Maryland Automatic Network Disk Archiver
  * Copyright (c) 1991-1998 University of Maryland at College Park
+ * Copyright (c) 2007-2012 Zmanda, Inc.  All Rights Reserved.
  * All Rights Reserved.
  *
  * Permission to use, copy, modify, distribute, and sell this software and its
@@ -78,6 +79,7 @@ static void check_disk(dle_t *dle);
 static void check_overall(void);
 static int check_file_exist(char *filename);
 static void check_space(char *dir, off_t kbytes);
+static void print_platform(void);
 
 int
 main(
@@ -94,7 +96,12 @@ main(
     dle_t *dle;
     int level;
     GSList *errlist;
-    level_t *alevel;
+    am_level_t *alevel;
+
+    if (argc > 1 && argv && argv[1] && g_str_equal(argv[1], "--version")) {
+       printf("selfcheck-%s\n", VERSION);
+       return (0);
+    }
 
     /* initialize */
 
@@ -121,6 +128,8 @@ main(
     dbopen(DBG_SUBDIR_CLIENT);
     startclock();
     dbprintf(_("version %s\n"), VERSION);
+    g_printf("OK version %s\n", VERSION);
+    print_platform();
 
     if(argc > 2 && strcmp(argv[1], "amandad") == 0) {
        amandad_auth = stralloc(argv[2]);
@@ -252,7 +261,7 @@ main(
        if (ch == '\0' || sscanf(s - 1, "%d", &level) != 1) {
            goto err;                           /* bad level */
        }
-       alevel = g_new0(level_t, 1);
+       alevel = g_new0(am_level_t, 1);
        alevel->level = level;
        dle->levellist = g_slist_append(dle->levellist, alevel);
        skip_integer(s, ch);
@@ -306,13 +315,16 @@ main(
 
     if (am_has_feature(g_options->features, fe_req_xml)) {
        char  *errmsg = NULL;
-       dle_t *dles, *dle;
+       dle_t *dles, *dle, *dle_next;
 
        dles = amxml_parse_node_FILE(stdin, &errmsg);
        if (errmsg) {
            err_extra = errmsg;
            goto err;
        }
+       if (merge_dles_properties(dles, 1) == 0) {
+           goto checkoverall;
+       }
        for (dle = dles; dle != NULL; dle = dle->next) {
            run_client_scripts(EXECUTE_ON_PRE_HOST_AMCHECK, g_options, dle,
                               stdout);
@@ -329,8 +341,13 @@ main(
            run_client_scripts(EXECUTE_ON_POST_HOST_AMCHECK, g_options, dle,
                               stdout);
        }
+       for (dle = dles; dle != NULL; dle = dle_next) {
+           dle_next = dle->next;
+           free_dle(dle);
+       }
     }
 
+checkoverall:
     check_overall();
 
     amfree(line);
@@ -603,6 +620,7 @@ check_disk(
 #endif
                                     "-c", "quit",
                                     NULL);
+               checkpid = checkpid;
                amfree(domain);
                aclose(nullfd);
                /*@ignore@*/
@@ -913,8 +931,8 @@ check_disk(
            access_type = "access";
 #endif
            if(access_result == -1) {
-               err = vstrallocf(_("Could not access %s (%s): %s"),
-                                qdevice, qdisk, strerror(errno));
+               err = vstrallocf(_("Could not %s %s (%s): %s"),
+                                access_type, qdevice, qdisk, strerror(errno));
            }
 #ifdef CHECK_FOR_ACCESS_WITH_OPEN
            aclose(access_result);
@@ -1120,8 +1138,8 @@ check_overall(void)
        check_file(COMPRESS_PATH, X_OK);
 
     if (need_dump || need_xfsdump ) {
-       if (check_file_exist("/etc/dumpdates")) {
-           check_file("/etc/dumpdates",
+       if (check_file_exist("/var/lib/dumpdates")) {
+           check_file("/var/lib/dumpdates",
 #ifdef USE_RUNDUMP
                       F_OK
 #else
@@ -1131,15 +1149,15 @@ check_overall(void)
        } else {
 #ifndef USE_RUNDUMP
            if (access("/etc", R_OK|W_OK) == -1) {
-               g_printf(_("ERROR [dump will not be able to create the /etc/dumpdates file: %s]\n"), strerror(errno));
+               g_printf(_("ERROR [dump will not be able to create the /var/lib/dumpdates file: %s]\n"), strerror(errno));
            }
 #endif
        }
     }
 
     if (need_vdump) {
-       if (check_file_exist("/etc/vdumpdates")) {
-            check_file("/etc/vdumpdates", F_OK);
+       if (check_file_exist("/var/lib/vdumpdates")) {
+            check_file("/var/lib/vdumpdates", F_OK);
        }
     }
 
@@ -1151,6 +1169,7 @@ check_overall(void)
     check_space(AMANDA_DBGDIR, (off_t)64);     /* for amandad i/o */
 #endif
 
+    check_space("/var/lib", (off_t)64);                /* for /var/lib/dumpdates writing */
     check_space("/etc", (off_t)64);            /* for /etc/dumpdates writing */
     }
 }
@@ -1201,3 +1220,84 @@ check_file_exist(
     return 1;
 }
 
+static void
+print_platform(void)
+{
+    struct stat stat_buf;
+    char *uname;
+    char *distro = NULL;
+    char *platform = NULL;
+    char  line[1025];
+    GPtrArray *argv_ptr;
+
+    if (stat("/etc/lsb-release", &stat_buf) == 0) {
+       FILE *release = fopen("/etc/lsb-release", "r");
+       distro = "Ubuntu";
+       if (release) {
+           while (fgets(line, 1024, release)) {
+               if (strstr(line, "DESCRIPTION")) {
+                   platform = strchr(line, '=');
+                   if (platform) platform++;
+               }
+           }
+           fclose(release);
+       }
+    } else if (stat("/etc/redhat-release", &stat_buf) == 0) {
+       FILE *release = fopen("/etc/redhat-release", "r");
+       distro = "RPM";
+       if (release) {
+           char *result;
+           result = fgets(line, 1024, release);
+           if (result) {
+               platform = line;
+           }
+           fclose(release);
+       }
+    } else if (stat("/etc/debian_version", &stat_buf) == 0) {
+       FILE *release = fopen("/etc/debian_version", "r");
+       distro = "Debian";
+       if (release) {
+           char *result;
+           result = fgets(line, 1024, release);
+           if (result) {
+               platform = line;
+           }
+           fclose(release);
+       }
+    } else {
+       argv_ptr = g_ptr_array_new();
+
+       g_ptr_array_add(argv_ptr, UNAME_PATH);
+       g_ptr_array_add(argv_ptr, "-s");
+       g_ptr_array_add(argv_ptr, NULL);
+       uname = get_first_line(argv_ptr);
+       if (uname) {
+           if (strncmp(uname, "SunOS", 5) == 0) {
+               FILE *release = fopen("/etc/release", "r");
+               distro = "Solaris";
+               if (release) {
+                   char *result;
+                   result = fgets(line, 1024, release);
+                   if (result) {
+                       platform = line;
+                   }
+                   fclose(release);
+               }
+           }
+           amfree(uname);
+       }
+       g_ptr_array_free(argv_ptr, TRUE);
+    }
+
+    if (!distro) {
+       distro = "Unknown";
+    }
+    if (!platform) {
+       platform = "Unknown";
+    }
+    if (platform[strlen(platform) -1] == '\n') {
+       platform[strlen(platform) -1] = '\0';
+    }
+    g_fprintf(stdout, "OK distro %s\n", distro);
+    g_fprintf(stdout, "OK platform %s\n", platform);
+}