mirror of git://git.suckless.org/ubase
Implement umount -a
This commit is contained in:
parent
4879ea07b4
commit
7f92db7327
27
umount.c
27
umount.c
|
@ -1,23 +1,30 @@
|
||||||
/* See LICENSE file for copyright and license details. */
|
/* See LICENSE file for copyright and license details. */
|
||||||
#include <sys/mount.h>
|
#include <mntent.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <sys/mount.h>
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
static void
|
static void
|
||||||
usage(void)
|
usage(void)
|
||||||
{
|
{
|
||||||
eprintf("usage: %s [-lfn] target\n", argv0);
|
eprintf("usage: %s [-alfn] target\n", argv0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char *argv[])
|
main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
int aflag = 0;
|
||||||
int flags = 0;
|
int flags = 0;
|
||||||
int ret = EXIT_SUCCESS;
|
int ret = EXIT_SUCCESS;
|
||||||
|
FILE *fp;
|
||||||
|
struct mntent *me;
|
||||||
|
|
||||||
ARGBEGIN {
|
ARGBEGIN {
|
||||||
|
case 'a':
|
||||||
|
aflag = 1;
|
||||||
|
break;
|
||||||
case 'f':
|
case 'f':
|
||||||
flags |= MNT_FORCE;
|
flags |= MNT_FORCE;
|
||||||
break;
|
break;
|
||||||
|
@ -30,9 +37,23 @@ main(int argc, char *argv[])
|
||||||
usage();
|
usage();
|
||||||
} ARGEND;
|
} ARGEND;
|
||||||
|
|
||||||
if (argc < 1)
|
if (argc < 1 && aflag == 0)
|
||||||
usage();
|
usage();
|
||||||
|
|
||||||
|
if (aflag == 1) {
|
||||||
|
fp = setmntent("/etc/fstab", "r");
|
||||||
|
if (!fp)
|
||||||
|
eprintf("setmntent %s:", "/etc/fstab");
|
||||||
|
while ((me = getmntent(fp))) {
|
||||||
|
if (umount2(me->mnt_dir, flags) < 0) {
|
||||||
|
perror("umount2:");
|
||||||
|
ret = EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
endmntent(fp);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
for (i = 0; i < argc; i++) {
|
for (i = 0; i < argc; i++) {
|
||||||
if (umount2(argv[i], flags) < 0)
|
if (umount2(argv[i], flags) < 0)
|
||||||
perror("umount2:");
|
perror("umount2:");
|
||||||
|
|
Loading…
Reference in New Issue