Ticket #3723: vm_check_29102011.patch

File vm_check_29102011.patch, 5.9 KB (added by hamish, 13 years ago)
  • src/bin/Jamfile

     
    2323AddResources mimeset : mimeset.rdef ;
    2424AddResources mountvolume : mountvolume.rdef ;
    2525AddResources notify : notify.rdef ;
     26AddResources swapcheck : swapcheck.rdef ;
    2627AddResources urlwrapper : urlwrapper.rdef ;
    2728
    2829# standard commands that don't need any additional library
     
    131132# commands that need libbe.so and liblocale.so
    132133StdBinCommands
    133134    query.cpp
     135    swapcheck.cpp
    134136    : be $(HAIKU_LOCALE_LIBS) : $(haiku-utils_rsrc) ;
    135137
    136138# commands that need libbe.so, libsupc++.so and liblocale.so
     
    234236    : filepanel.cpp
    235237;
    236238
     239DoCatalogs swapcheck
     240    : x-vnd.Haiku-cmd-swapcheck
     241    : swapcheck.cpp
     242;
     243
    237244SubInclude HAIKU_TOP src bin addattr ;
    238245SubInclude HAIKU_TOP src bin bash ;
    239246SubInclude HAIKU_TOP src bin bc ;
  • src/bin/swapcheck.rdef

     
     1resource app_signature "application/x-vnd.Haiku-cmd-swapcheck";
     2
     3resource app_flags B_MULTIPLE_LAUNCH;
     4
     5resource app_version {
     6    major = 1,
     7    middle = 0,
     8    minor = 0,
     9    variety = B_APPV_FINAL,
     10    internal = 0,
     11    short_info = "Haiku SwapCheck",
     12    long_info  = "Haiku SwapCheck ©2011 Haiku, Inc."
     13};
     14 No newline at end of file
  • src/bin/swapcheck.cpp

     
     1/*
     2 * Copyright 2011, Haiku, Inc. All rights reserved.
     3 * Distributed under the terms of the MIT License.
     4 *
     5 * Authors:
     6 *      Hamish Morrison <hamish@lavabit.com>
     7 */
     8
     9#include <stdio.h>
     10
     11#include <Alert.h>
     12#include <Application.h>
     13#include <Catalog.h>
     14#include <File.h>
     15#include <FindDirectory.h>
     16#include <kernel/fs_info.h>
     17#include <Path.h>
     18#include <Roster.h>
     19
     20#include <driver_settings.h>
     21
     22
     23#undef B_TRANSLATE_CONTEXT
     24#define B_TRANSLATE_CONTEXT "swapcheck"
     25
     26
     27static const char* const kSwapErrorFilePath = "swaperr";
     28static const char* const kVirtualMemorySettings = "virtual_memory";
     29
     30
     31int
     32main()
     33{
     34    // Ensure that the swap error file is not old
     35    time_t currentTime = time(NULL);
     36    bigtime_t bootTime = (system_time() / 1000000) + 1;
     37
     38    BPath path;
     39    if (find_directory(B_COMMON_SETTINGS_DIRECTORY, &path) != B_OK)
     40        return 1;
     41    path.Append(kSwapErrorFilePath);
     42
     43    const char* pathString = path.Path();
     44    struct stat errFile;
     45    if (stat(pathString, &errFile) < 0)
     46        return 0;
     47
     48    time_t modTime = currentTime - errFile.st_mtime;
     49    if (modTime >= bootTime) {
     50        unlink(pathString);
     51        return 0;
     52    }
     53
     54    // Currently all swap errors result in the swap file
     55    // being created on the boot device, so update the swap
     56    // settings to reflect that.
     57    void* settings = load_driver_settings(kVirtualMemorySettings);
     58    if (settings != NULL) {
     59        const char* enabled = get_driver_parameter(settings,
     60            "vm", NULL, NULL);
     61        const char* size = get_driver_parameter(settings,
     62            "swap_size", NULL, NULL);
     63
     64        if (enabled != NULL && size != NULL) {
     65            BPath path;
     66            if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) == B_OK) {
     67                path.Append("kernel/drivers");
     68                path.Append(kVirtualMemorySettings);
     69
     70                BFile file;
     71                if (file.SetTo(path.Path(),
     72                    B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE) == B_OK) {
     73                    fs_info info;
     74                    fs_stat_dev(dev_for_path("/boot"), &info);
     75
     76                    char buffer[1024];
     77                    snprintf(buffer, sizeof(buffer), "vm %s\nswap_size %s\n"
     78                        "swap_volume_name %s\nswap_volume_device %s\n"
     79                        "swap_volume_filesystem %s\n"
     80                        "swap_volume_capacity %lld\n", enabled, size,
     81                        info.volume_name, info.device_name, info.fsh_name,
     82                        info.total_blocks * info.block_size);
     83                    file.Write(buffer, strlen(buffer));
     84                }
     85            }
     86        }
     87        unload_driver_settings(settings);
     88    }
     89
     90    int fd = open(pathString, O_RDONLY);
     91    if (fd >= 0) {
     92        char buf[8] = { 0 };
     93        if (read(fd, &buf, sizeof(buf)) > 0) {
     94            BApplication app("application/x-vnd.Haiku-cmd-swapcheck");
     95            const char* prompt = NULL;
     96            if (strcmp(buf, "nfnd") == 0)
     97                prompt = B_TRANSLATE("The system could not locate the "
     98                    "specified swap volume at boot time. The boot "
     99                    "device has been used instead");
     100            else if (strcmp(buf, "nmnt") == 0)
     101                prompt = B_TRANSLATE("The system could not mount the "
     102                    "specified swap volume at boot time. The boot "
     103                    "device has been used instead");
     104
     105            if (prompt != NULL) {
     106                int32 choice = 0;
     107                choice = (new BAlert("swapcheck", prompt,
     108                    B_TRANSLATE("OK"), B_TRANSLATE("Adjust swap "
     109                    "settings" B_UTF8_ELLIPSIS)))->Go();
     110                if (choice == 1)
     111                    be_roster->Launch("application/x-vnd."
     112                        "Haiku-VirtualMemory");
     113            }
     114
     115        }
     116        unlink(pathString);
     117        close(fd);
     118    }
     119
     120    return 0;
     121}
  • data/system/boot/Bootscript

     
    170170# Synchronize network time
    171171launch system/preferences/Time "" --update
    172172
     173# Check if swap worked
     174launch system/bin/swapcheck
     175
    173176if [ "$SAFEMODE" != "yes" ]; then
    174177    # Start user boot script
    175178    if [ -f $HOME/config/boot/UserBootscript ]; then
  • build/jam/HaikuImage

     
    5555    safemode screen_blanker screenmode screenshot sdiff setdecor settype
    5656    setversion setvolume seq sha1sum shar shred shuf shutdown sleep sort
    5757    spamdbm
    58     split stat strace stty su sum sync sysinfo
     58    split stat strace stty su sum swapcheck sync sysinfo
    5959    tac tail tcpdump tcptester tee telnet telnetd test timeout top touch
    6060    tput tr traceroute translate trash true truncate tsort tty
    6161    uname unchop unexpand unmount uniq unlink unrar unshar unzip unzipsfx