|
|
1.1 ! root 1: /* ! 2: * Copyright (c) 1980 Regents of the University of California. ! 3: * All rights reserved. ! 4: * ! 5: * Redistribution and use in source and binary forms are permitted ! 6: * provided that: (1) source distributions retain this entire copyright ! 7: * notice and comment, and (2) distributions including binaries display ! 8: * the following acknowledgement: ``This product includes software ! 9: * developed by the University of California, Berkeley and its contributors'' ! 10: * in the documentation or other materials provided with the distribution ! 11: * and in all advertising materials mentioning features or use of this ! 12: * software. Neither the name of the University nor the names of its ! 13: * contributors may be used to endorse or promote products derived ! 14: * from this software without specific prior written permission. ! 15: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR ! 16: * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED ! 17: * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ! 18: */ ! 19: ! 20: #ifndef lint ! 21: char copyright[] = ! 22: "@(#) Copyright (c) 1980 Regents of the University of California.\n\ ! 23: All rights reserved.\n"; ! 24: #endif /* not lint */ ! 25: ! 26: #ifndef lint ! 27: static char sccsid[] = "@(#)swapon.c 5.4 (Berkeley) 6/1/90"; ! 28: #endif /* not lint */ ! 29: ! 30: #include <fstab.h> ! 31: #include <errno.h> ! 32: #include <stdio.h> ! 33: ! 34: main(argc, argv) ! 35: int argc; ! 36: char **argv; ! 37: { ! 38: extern char *optarg; ! 39: extern int optind; ! 40: register struct fstab *fsp; ! 41: register int stat; ! 42: int ch, doall; ! 43: ! 44: doall = 0; ! 45: while ((ch = getopt(argc, argv, "a")) != EOF) ! 46: switch((char)ch) { ! 47: case 'a': ! 48: doall = 1; ! 49: break; ! 50: case '?': ! 51: default: ! 52: usage(); ! 53: } ! 54: argv += optind; ! 55: ! 56: stat = 0; ! 57: if (doall) ! 58: while (fsp = getfsent()) { ! 59: if (strcmp(fsp->fs_type, FSTAB_SW)) ! 60: continue; ! 61: if (add(fsp->fs_spec, 1)) ! 62: stat = 1; ! 63: else ! 64: printf("swapon: adding %s as swap device\n", ! 65: fsp->fs_spec); ! 66: } ! 67: else if (!*argv) ! 68: usage(); ! 69: for (; *argv; ++argv) ! 70: stat |= add(*argv, 0); ! 71: exit(stat); ! 72: } ! 73: ! 74: static ! 75: add(name, ignoreebusy) ! 76: char *name; ! 77: int ignoreebusy; ! 78: { ! 79: extern int errno; ! 80: ! 81: if (swapon(name) == -1) { ! 82: switch (errno) { ! 83: case EINVAL: ! 84: fprintf(stderr, "swapon: %s: device not configured\n", ! 85: name); ! 86: break; ! 87: case EBUSY: ! 88: if (!ignoreebusy) ! 89: fprintf(stderr, ! 90: "swapon: %s: device already in use\n", ! 91: name); ! 92: break; ! 93: default: ! 94: fprintf(stderr, "swapon: %s: ", name); ! 95: perror((char *)NULL); ! 96: break; ! 97: } ! 98: return(1); ! 99: } ! 100: return(0); ! 101: } ! 102: ! 103: static ! 104: usage() ! 105: { ! 106: fprintf(stderr, "usage: swapon [-a] [special_file ...]\n"); ! 107: exit(1); ! 108: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.