Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.sbin/sysinst PR 55202: disable swapping if we started it...



details:   https://anonhg.NetBSD.org/src/rev/4d3e3d346415
branches:  trunk
changeset: 932620:4d3e3d346415
user:      martin <martin%NetBSD.org@localhost>
date:      Tue May 12 17:26:43 2020 +0000

description:
PR 55202: disable swapping if we started it due to low ram

diffstat:

 usr.sbin/sysinst/defs.h  |   8 +++++++-
 usr.sbin/sysinst/disks.c |  29 ++++++++++++++++++++++-------
 usr.sbin/sysinst/main.c  |   4 +++-
 3 files changed, 32 insertions(+), 9 deletions(-)

diffs (115 lines):

diff -r 08bfdbc95758 -r 4d3e3d346415 usr.sbin/sysinst/defs.h
--- a/usr.sbin/sysinst/defs.h   Tue May 12 17:04:00 2020 +0000
+++ b/usr.sbin/sysinst/defs.h   Tue May 12 17:26:43 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: defs.h,v 1.60 2020/05/12 17:04:00 martin Exp $ */
+/*     $NetBSD: defs.h,v 1.61 2020/05/12 17:26:43 martin Exp $ */
 
 /*
  * Copyright 1997 Piermont Information Systems Inc.
@@ -673,8 +673,14 @@
 int    make_filesystems(struct install_partition_desc *);
 int    make_fstab(struct install_partition_desc *);
 int    mount_disks(struct install_partition_desc *);
+/*
+ * set_swap_if_low_ram and set_swap return -1 on error,
+ * 0 if no swap was added on purpose and
+ * 1 if swap has been added (and needs to be cleared later).
+ */
 int    set_swap_if_low_ram(struct install_partition_desc *);
 int    set_swap(struct install_partition_desc *);
+void   clear_swap(void);
 int    check_swap(const char *, int);
 char *bootxx_name(struct install_partition_desc *);
 int get_dkwedges(struct dkwedge_info **, const char *);
diff -r 08bfdbc95758 -r 4d3e3d346415 usr.sbin/sysinst/disks.c
--- a/usr.sbin/sysinst/disks.c  Tue May 12 17:04:00 2020 +0000
+++ b/usr.sbin/sysinst/disks.c  Tue May 12 17:26:43 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: disks.c,v 1.66 2020/02/19 18:08:03 martin Exp $ */
+/*     $NetBSD: disks.c,v 1.67 2020/05/12 17:26:43 martin Exp $ */
 
 /*
  * Copyright 1997 Piermont Information Systems Inc.
@@ -1905,9 +1905,12 @@
        return error;
 }
 
+static char swap_dev[PATH_MAX];
+
 int
 set_swap_if_low_ram(struct install_partition_desc *install)
 {
+       swap_dev[0] = 0;
        if (get_ramsize() <= TINY_RAM_SIZE)
                return set_swap(install);
        return 0;
@@ -1917,9 +1920,9 @@
 set_swap(struct install_partition_desc *install)
 {
        size_t i;
-       char dev_buf[PATH_MAX];
        int rval;
 
+       swap_dev[0] = 0;
        for (i = 0; i < install->num; i++) {
                if (install->infos[i].type == PT_swap)
                        break;
@@ -1928,15 +1931,27 @@
                return 0;
 
        if (!install->infos[i].parts->pscheme->get_part_device(
-           install->infos[i].parts, install->infos[i].cur_part_id, dev_buf,
-           sizeof dev_buf, NULL, plain_name, true, true))
+           install->infos[i].parts, install->infos[i].cur_part_id, swap_dev,
+           sizeof swap_dev, NULL, plain_name, true, true))
                return -1;
 
-       rval = swapctl(SWAP_ON, dev_buf, 0);
-       if (rval != 0)
+       rval = swapctl(SWAP_ON, swap_dev, 0);
+       if (rval != 0) {
+               swap_dev[0] = 0;
                return -1;
+       }
 
-       return 0;
+       return 1;
+}
+
+void
+clear_swap(void)
+{
+
+       if (swap_dev[0] == 0)
+               return;
+       swapctl(SWAP_OFF, swap_dev, 0);
+       swap_dev[0] = 0;
 }
 
 int
diff -r 08bfdbc95758 -r 4d3e3d346415 usr.sbin/sysinst/main.c
--- a/usr.sbin/sysinst/main.c   Tue May 12 17:04:00 2020 +0000
+++ b/usr.sbin/sysinst/main.c   Tue May 12 17:26:43 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: main.c,v 1.24 2020/04/22 23:43:12 joerg Exp $  */
+/*     $NetBSD: main.c,v 1.25 2020/05/12 17:26:43 martin Exp $ */
 
 /*
  * Copyright 1997 Piermont Information Systems Inc.
@@ -450,6 +450,7 @@
                if (chdir(home) != 0)
                        (void)chdir("/");
        unwind_mounts();
+       clear_swap();
 
        /* Display banner message in (english, francais, deutsch..) */
        msg_display(MSG_hello);
@@ -540,6 +541,7 @@
        chdir(getenv("HOME"));
        unwind_mounts();
        umount_mnt2();
+       clear_swap();
 
        endwin();
 



Home | Main Index | Thread Index | Old Index