コード例 #1
0
ファイル: rmdir.c プロジェクト: bandari/linux_utils
int main(int argc, char **argv)
{
 	int opt, i, err = 0;

	while ((opt = getopt(argc, argv, "ipv")) != -1)
		switch (opt) {
		case 'p':
			pflag = 1; break;
		case 'v':
			vflag = 1; break;
		case 'i':
			iflag = 1; break;
		case '?':
		default :
			usage();   break;
		}

	argc -= optind;
	argv += optind;

	if (argc == 0) {
		fprintf(stderr, "rmdir: missing operand\n");
		usage();
	}

	for (; *argv; argv++) {
		if (vflag)
			printf("rmdir: removing direntory, `%s'\n", *argv);

		if (rmdir(*argv) < 0 && !iflag) {
			fprintf(stderr, "rmdir: failed to remove `%s': ", *argv);
			perror(NULL);
			err = 1;
		} else  if (pflag) {
			err |= rmdir_path(*argv);
		} 
	}

	return err;	
}
コード例 #2
0
ファイル: lookup_file.c プロジェクト: bryder/bryder_autofs414
int lookup_mount(const char *root, const char *name, int name_len, void *context)
{
	struct lookup_context *ctxt = (struct lookup_context *) context;
	struct stat st;
	char key[KEY_MAX_LEN + 1];
	int key_len;
	char mapent[MAPENT_MAX_LEN + 1];
	struct mapent_cache *me;
	time_t now = time(NULL);
	time_t t_last_read;
	int need_hup = 0;
	int ret = 1;

	if (stat(ctxt->mapname, &st)) {
		crit(MODPREFIX "file map %s, could not stat", ctxt->mapname);
		return 1;
	}

	if (ap.type == LKP_DIRECT)
		key_len = snprintf(key, KEY_MAX_LEN, "%s/%s", root, name);
	else
		key_len = snprintf(key, KEY_MAX_LEN, "%s", name);

	if (key_len > KEY_MAX_LEN)
		return 1;

	me = cache_lookup_first();
	t_last_read = me ? now - me->age : ap.exp_runfreq + 1;

	/* only if it has been modified */
	if (st.st_mtime > ctxt->mtime) {
		ret = lookup_one(root, key, key_len, ctxt);
		if (!ret)
			return 1;

		debug("ret = %d", ret);

		if (t_last_read > ap.exp_runfreq)
			if (ret & (CHE_UPDATED | CHE_MISSING))
				need_hup = 1;

		if (ret == CHE_MISSING) {
			int wild = CHE_MISSING;

			/* Maybe update wild card map entry */
			if (ap.type == LKP_INDIRECT) {
				wild = lookup_wild(root, ctxt);
				if (wild == CHE_MISSING)
					cache_delete(root, "*", 0);
			}

			if (cache_delete(root, key, 0) &&
					wild & (CHE_MISSING | CHE_FAIL))
				rmdir_path(key);
		}
	}

	me = cache_lookup(key);
	if (me == NULL) {
		/* path component, do submount */
		me = cache_partial_match(key);
		if (me)
			sprintf(mapent, "-fstype=autofs file:%s", ctxt->mapname);
	} else
		sprintf(mapent, me->mapent);

	if (me) {
		debug(MODPREFIX "%s -> %s", key, mapent);
		ret = ctxt->parse->parse_mount(root, name, name_len,
						  mapent, ctxt->parse->context);
	}

	/* Have parent update its map ? */
	if (need_hup)
		kill(getppid(), SIGHUP);

	return ret;
}
コード例 #3
0
int mount_mount(const char *root, const char *name, int name_len,
                const char *what, const char *fstype, const char *options, void *context)
{
    char *fullpath;
    int err;
    int status, existed = 1;

    fstype = "iso9660";

    fullpath = alloca(strlen(root) + name_len + 2);
    if (!fullpath) {
        error(MODPREFIX "alloca: %m");
        return 1;
    }

    if (name_len)
        sprintf(fullpath, "%s/%s", root, name);
    else
        sprintf(fullpath, "%s", root);

    debug(MODPREFIX "calling umount %s", what);

    err = spawnll(LOG_DEBUG,
                  PATH_UMOUNT, PATH_UMOUNT, what, NULL);
    if (err) {
        error(MODPREFIX "umount of %s failed (all may be unmounted)",
              what);
    }

    debug(MODPREFIX "calling mkdir_path %s", fullpath);

    status = mkdir_path(fullpath, 0555);
    if (status && errno != EEXIST) {
        error(MODPREFIX "mkdir_path %s failed: %m", fullpath);
        return 1;
    }

    if (!status)
        existed = 0;

    debug(MODPREFIX "Swapping CD to slot %s", name);

    err = swapCD(what, name);
    if (err) {
        error(MODPREFIX "failed to swap CD to slot %s", name);
        return 1;
    }

    if (options && options[0]) {
        debug(MODPREFIX "calling mount -t %s " SLOPPY "-o %s %s %s",
              fstype, options, what, fullpath);

        err = spawnll(LOG_DEBUG,
                      PATH_MOUNT, PATH_MOUNT, "-t", fstype,
                      SLOPPYOPT "-o", options, what, fullpath, NULL);
    } else {
        debug(MODPREFIX "calling mount -t %s %s %s",
              fstype, what, fullpath);

        err = spawnll(LOG_DEBUG, PATH_MOUNT, PATH_MOUNT,
                      "-t", fstype, what, fullpath, NULL);
    }

    if (err) {
        if ((!ap.ghost && name_len) || !existed)
            rmdir_path(name);

        error(MODPREFIX "failed to mount %s (type %s) on %s",
              what, fstype, fullpath);
        return 1;
    } else {
        debug(MODPREFIX "mounted %s type %s on %s",
              what, fstype, fullpath);
        return 0;
    }
}