Module Name:    src
Committed By:   martin
Date:           Tue May 12 17:26:43 UTC 2020

Modified Files:
        src/usr.sbin/sysinst: defs.h disks.c main.c

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


To generate a diff of this commit:
cvs rdiff -u -r1.60 -r1.61 src/usr.sbin/sysinst/defs.h
cvs rdiff -u -r1.66 -r1.67 src/usr.sbin/sysinst/disks.c
cvs rdiff -u -r1.24 -r1.25 src/usr.sbin/sysinst/main.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.sbin/sysinst/defs.h
diff -u src/usr.sbin/sysinst/defs.h:1.60 src/usr.sbin/sysinst/defs.h:1.61
--- src/usr.sbin/sysinst/defs.h:1.60	Tue May 12 17:04:00 2020
+++ src/usr.sbin/sysinst/defs.h	Tue May 12 17:26:43 2020
@@ -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 @@ void	disp_cur_fspart(int, int);
 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 *);

Index: src/usr.sbin/sysinst/disks.c
diff -u src/usr.sbin/sysinst/disks.c:1.66 src/usr.sbin/sysinst/disks.c:1.67
--- src/usr.sbin/sysinst/disks.c:1.66	Wed Feb 19 18:08:03 2020
+++ src/usr.sbin/sysinst/disks.c	Tue May 12 17:26:43 2020
@@ -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 @@ mount_disks(struct install_partition_des
 	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 @@ int
 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 @@ set_swap(struct install_partition_desc *
 		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

Index: src/usr.sbin/sysinst/main.c
diff -u src/usr.sbin/sysinst/main.c:1.24 src/usr.sbin/sysinst/main.c:1.25
--- src/usr.sbin/sysinst/main.c:1.24	Wed Apr 22 23:43:12 2020
+++ src/usr.sbin/sysinst/main.c	Tue May 12 17:26:43 2020
@@ -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 @@ toplevel(void)
 		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 @@ cleanup(void)
 	chdir(getenv("HOME"));
 	unwind_mounts();
 	umount_mnt2();
+	clear_swap();
 
 	endwin();
 

Reply via email to