xref: /csrg-svn/sbin/swapon/swapon.c (revision 1444)
1*1444Sbill static char *sccsid = "@(#)swapon.c	4.3 (Berkeley) 10/15/80";
21113Sbill #include <stdio.h>
31417Sbill #include <fstab.h>
41113Sbill 
51113Sbill #define	VSWAPON	85
61113Sbill 
71113Sbill main(argc, argv)
81113Sbill 	int argc;
91113Sbill 	char *argv[];
101113Sbill {
111113Sbill 	int stat = 0;
121113Sbill 
131113Sbill 	--argc, argv++;
141113Sbill 	if (argc == 0) {
151113Sbill 		fprintf(stderr, "usage: swapon name...\n");
161113Sbill 		exit(1);
171113Sbill 	}
181417Sbill 	if (argc == 1 && !strcmp(*argv, "-a")) {
19*1444Sbill 		struct	fstab	*fsp;
20*1444Sbill 		if (setfsent() == 0)
21*1444Sbill 			perror(FSTAB), exit(1);
22*1444Sbill 		while ( (fsp = getfsent()) != 0){
23*1444Sbill 			if (strcmp(fsp->fs_type, FSTAB_SW) != 0)
241417Sbill 				continue;
25*1444Sbill 			fprintf(stdout, "Adding %s as swap device\n",
26*1444Sbill 			    fsp->fs_spec);
27*1444Sbill 			if (syscall(VSWAPON, fsp->fs_spec) == -1) {
28*1444Sbill 				perror(fsp->fs_spec);
291417Sbill 				stat = 1;
301417Sbill 			}
311417Sbill 		}
32*1444Sbill 		endfsent();
331417Sbill 		exit(stat);
341417Sbill 	}
351113Sbill 	do {
361113Sbill 		if (syscall(VSWAPON, *argv++) == -1) {
371113Sbill 			stat = 1;
381113Sbill 			perror(argv[-1]);
391113Sbill 		}
401113Sbill 		argc--;
411113Sbill 	} while (argc > 0);
421113Sbill 	exit(stat);
431113Sbill }
44