]>
git.saurik.com Git - apple/system_cmds.git/blob - vifs.tproj/vifs.c
2 * Copyright (c) 2005 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
23 #include <sys/errno.h>
24 #include <sys/types.h>
40 # Warning - this file should only be modified with vifs(8)\n\
42 # Failure to do so is unsupported and may be destructive.\n\
46 main(int argc
, char *argv
[])
55 printf("usage: vifs\n");
61 errx(1, "need to run as root");
63 /* examine the existing fstab, try to create it if needed */
64 if (stat(_PATH_FSTAB
, &sb
) < 0) {
65 if (errno
== ENOENT
) {
66 fd
= open(_PATH_FSTAB
, O_CREAT
| O_WRONLY
,
67 S_IRUSR
| S_IWUSR
| S_IRGRP
| S_IROTH
);
69 errx(1, "error creating %s", _PATH_FSTAB
);
70 write(fd
, warning
, strlen(warning
));
73 errx(1, "could not stat %s", _PATH_FSTAB
);
77 /* prepare the file for the editor */
78 fd
= open(_PATH_FSTAB
, O_RDONLY
, 0);
80 errx(1, "error opening %s", _PATH_FSTAB
);
82 x
= fcntl(fd
, F_SETFD
, 1);
84 errx(1, "error setting close on exit");
86 x
= flock(fd
, LOCK_EX
| LOCK_NB
);
88 errx(1, "file is busy");
90 /* obtain and invoke the editor */
91 editor
= getenv("EDITOR");
94 p
= strrchr(editor
, '/');
102 execlp(editor
, p
, _PATH_FSTAB
, NULL
);
107 editpid
= waitpid(editpid
, (int *)&x
, WUNTRACED
);
109 errx(1, "editing error");
110 else if (WIFSTOPPED(x
))
112 else if (WIFEXITED(x
) && WEXITSTATUS(x
) == 0)
115 errx(1, "editing error");
118 /* let process death clean up locks and file descriptors */