Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sbin/swapctl Allow named wedges to be used on command line, ...
details: https://anonhg.NetBSD.org/src/rev/2f0df75ed1a0
branches: trunk
changeset: 783496:2f0df75ed1a0
user: mlelstv <mlelstv%NetBSD.org@localhost>
date: Wed Dec 26 10:15:28 2012 +0000
description:
Allow named wedges to be used on command line, also fix name lookup
for the dump device.
diffstat:
sbin/swapctl/swapctl.c | 64 +++++++++++++++++++++++++++++++++++--------------
1 files changed, 45 insertions(+), 19 deletions(-)
diffs (141 lines):
diff -r f305aca0ed24 -r 2f0df75ed1a0 sbin/swapctl/swapctl.c
--- a/sbin/swapctl/swapctl.c Tue Dec 25 22:34:36 2012 +0000
+++ b/sbin/swapctl/swapctl.c Wed Dec 26 10:15:28 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: swapctl.c,v 1.37 2012/04/07 04:52:20 christos Exp $ */
+/* $NetBSD: swapctl.c,v 1.38 2012/12/26 10:15:28 mlelstv Exp $ */
/*
* Copyright (c) 1996, 1997, 1999 Matthew R. Green
@@ -64,7 +64,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: swapctl.c,v 1.37 2012/04/07 04:52:20 christos Exp $");
+__RCSID("$NetBSD: swapctl.c,v 1.38 2012/12/26 10:15:28 mlelstv Exp $");
#endif
@@ -150,6 +150,7 @@
static void change_priority(char *);
static int add_swap(char *, int);
static int delete_swap(char *);
+static void set_dumpdev1(char *);
static void set_dumpdev(char *);
static int get_dumpdev(void);
__dead static void do_fstab(int);
@@ -445,8 +446,14 @@
add_swap(char *path, int priority)
{
struct stat sb;
+ char buf[MAXPATHLEN];
+ char *spec;
- if (stat(path, &sb) < 0)
+ if (getfsspecname(buf, sizeof(buf), path) == NULL)
+ goto oops;
+ spec = buf;
+
+ if (stat(spec, &sb) < 0)
goto oops;
if (sb.st_mode & S_IROTH)
@@ -455,7 +462,7 @@
warnx("WARNING: %s is writable by the world", path);
if (fflag || oflag) {
- set_dumpdev(path);
+ set_dumpdev1(spec);
if (oflag)
exit(0);
else
@@ -465,7 +472,7 @@
if (nflag)
return 1;
- if (swapctl(SWAP_ON, path, priority) < 0) {
+ if (swapctl(SWAP_ON, spec, priority) < 0) {
oops:
err(1, "%s", path);
}
@@ -478,31 +485,50 @@
static int
delete_swap(char *path)
{
+ char buf[MAXPATHLEN];
+ char *spec;
+
+ if (getfsspecname(buf, sizeof(buf), path) == NULL)
+ err(1, "%s", path);
+ spec = buf;
if (nflag)
return 1;
- if (swapctl(SWAP_OFF, path, pri) < 0)
+ if (swapctl(SWAP_OFF, spec, pri) < 0)
err(1, "%s", path);
return (1);
}
static void
+set_dumpdev1(char *spec)
+{
+ int rv = 0;
+
+ if (!nflag) {
+ if (strcmp(spec, "none") == 0)
+ rv = swapctl(SWAP_DUMPOFF, NULL, 0);
+ else
+ rv = swapctl(SWAP_DUMPDEV, spec, 0);
+ }
+
+ if (rv == -1)
+ err(1, "could not set dump device to %s", spec);
+ else
+ printf("%s: setting dump device to %s\n", getprogname(), spec);
+}
+
+static void
set_dumpdev(char *path)
{
- int rv = 0;
+ char buf[MAXPATHLEN];
+ char *spec;
- if (!nflag) {
- if (strcmp(path, "none") == 0)
- rv = swapctl(SWAP_DUMPOFF, NULL, 0);
- else
- rv = swapctl(SWAP_DUMPDEV, path, 0);
- }
+ if (getfsspecname(buf, sizeof(buf), path) == NULL)
+ err(1, "%s", path);
+ spec = buf;
- if (rv == -1)
- err(1, "could not set dump device to %s", path);
- else
- printf("%s: setting dump device to %s\n", getprogname(), path);
+ return set_dumpdev1(spec);
}
static int
@@ -706,7 +732,7 @@
cmd[0] = '\0';
if (strcmp(fp->fs_type, "dp") == 0 && add) {
- set_dumpdev(spec);
+ set_dumpdev1(spec);
continue;
}
@@ -715,7 +741,7 @@
/* handle dp as mnt option */
if (strstr(fp->fs_mntops, "dp") && add)
- set_dumpdev(spec);
+ set_dumpdev1(spec);
isblk = 0;
Home |
Main Index |
Thread Index |
Old Index