fixed error messages
[unix-history] / usr / src / sbin / swapon / swapon.c
CommitLineData
3b5307c6 1static char *sccsid = "@(#)swapon.c 4.6 (Berkeley) %G%";
1885c525 2#include <stdio.h>
f0861f40 3#include <fstab.h>
1885c525
BJ
4
5#define VSWAPON 85
6
7main(argc, argv)
8 int argc;
9 char *argv[];
10{
11 int stat = 0;
12
13 --argc, argv++;
14 if (argc == 0) {
15 fprintf(stderr, "usage: swapon name...\n");
16 exit(1);
17 }
f0861f40 18 if (argc == 1 && !strcmp(*argv, "-a")) {
8d6ccf8b
BJ
19 struct fstab *fsp;
20 if (setfsent() == 0)
21 perror(FSTAB), exit(1);
22 while ( (fsp = getfsent()) != 0){
23 if (strcmp(fsp->fs_type, FSTAB_SW) != 0)
f0861f40 24 continue;
687c01bb 25 printf("Adding %s as swap device\n",
8d6ccf8b
BJ
26 fsp->fs_spec);
27 if (syscall(VSWAPON, fsp->fs_spec) == -1) {
3b5307c6 28 perror(fsp->fs_spec);
f0861f40
BJ
29 stat = 1;
30 }
31 }
8d6ccf8b 32 endfsent();
f0861f40
BJ
33 exit(stat);
34 }
1885c525
BJ
35 do {
36 if (syscall(VSWAPON, *argv++) == -1) {
37 stat = 1;
38 perror(argv[-1]);
39 }
40 argc--;
41 } while (argc > 0);
42 exit(stat);
43}