BSD 4_3 release
[unix-history] / usr / src / etc / swapon.c
index 7e7f5de..7b3c827 100644 (file)
@@ -1,8 +1,24 @@
-static char *sccsid = "@(#)swapon.c    4.4 (Berkeley) 10/16/80";
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved.  The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+#ifndef lint
+char copyright[] =
+"@(#) Copyright (c) 1980 Regents of the University of California.\n\
+ All rights reserved.\n";
+#endif not lint
+
+#ifndef lint
+static char sccsid[] = "@(#)swapon.c   5.2 (Berkeley) 3/4/86";
+#endif not lint
+
 #include <stdio.h>
 #include <fstab.h>
 #include <stdio.h>
 #include <fstab.h>
+#include <errno.h>
 
 
-#define        VSWAPON 85
+extern int errno;
 
 main(argc, argv)
        int argc;
 
 main(argc, argv)
        int argc;
@@ -22,23 +38,48 @@ main(argc, argv)
                while ( (fsp = getfsent()) != 0){
                        if (strcmp(fsp->fs_type, FSTAB_SW) != 0)
                                continue;
                while ( (fsp = getfsent()) != 0){
                        if (strcmp(fsp->fs_type, FSTAB_SW) != 0)
                                continue;
-                       printf("Adding %s as swap device\n",
-                           fsp->fs_spec);
-                       if (syscall(VSWAPON, fsp->fs_spec) == -1) {
-                               extern errno;
-                               extern char *sys_errlist[];
-                               printf("%s: %s\n",
-                                   sys_errlist[errno]);
-                               stat = 1;
-                       }
+                       if (swapon(fsp->fs_spec) == -1) {
+                               switch(errno) {
+                               case EINVAL:
+                                       fprintf(stderr,
+                                               "%s: Device not configured\n",
+                                               fsp->fs_spec);
+                                       stat = 1;
+                                       break;
+
+                               case EBUSY:     /* ignore already in use */
+                                       break;
+
+                               default:
+                                       perror(fsp->fs_spec);
+                                       stat = 1;
+                                       break;
+                               }
+                       } else
+                               printf("Adding %s as swap device\n",
+                                   fsp->fs_spec);
                }
                endfsent();
                exit(stat);
        }
        do {
                }
                endfsent();
                exit(stat);
        }
        do {
-               if (syscall(VSWAPON, *argv++) == -1) {
+               if (swapon(*argv++) == -1) {
                        stat = 1;
                        stat = 1;
-                       perror(argv[-1]);
+                       switch (errno) {
+                       case EINVAL:
+                               fprintf(stderr, "%s: Device not configured\n",
+                                               argv[-1]);
+                               break;
+
+                       case EBUSY:
+                               fprintf(stderr, "%s: Device already in use\n",
+                                               argv[-1]);
+                               break;
+
+                       default:
+                               perror(argv[-1]);
+                               break;
+                       }
                }
                argc--;
        } while (argc > 0);
                }
                argc--;
        } while (argc > 0);