Exemplo n.º 1
0
void
makePath(const char *base, char *out, size_t outsz)
{
    const char *zroot = zone_get_nroot();

    (void) snprintf(out, outsz, "%s%s", zroot != NULL ? zroot : "", base);
}
Exemplo n.º 2
0
void
doexec(char *fstype, char *newargv[])
{
	const char *zroot = zone_get_nroot();
	char	full_path[PATH_MAX];
	char	alter_path[PATH_MAX];
	char	*vfs_path = VFS_PATH;
	char	*alt_path = ALT_PATH;
	int	i;

	/* build the full pathname of the fstype dependent command. */
	(void) snprintf(full_path, sizeof (full_path), "%s/%s/%s/%s",
	    (zroot != NULL ? zroot : ""), vfs_path, fstype, myname);
	sprintf(alter_path, "%s/%s/%s", alt_path, fstype, myname);
	newargv[1] = myname;

	if (Vflg) {
		printf("%s -F %s", newargv[1], fstype);
		for (i = 2; newargv[i]; i++)
			printf(" %s", newargv[i]);
		printf("\n");
		fflush(stdout);
		exit(0);
	}

	/*
	 * Try to exec the fstype dependent portion of the mount.
	 * See if the directory is there before trying to exec dependent
	 * portion.  This is only useful for eliminating the
	 * '..mount: not found' message when '/usr' is mounted
	 */
	if (access(full_path, 0) == 0) {
		execv(full_path, &newargv[1]);
		if (errno == EACCES) {
			fprintf(stderr,
			gettext("%s: Cannot execute %s - permission denied\n"),
			    myname, full_path);
		}
		if (errno == ENOEXEC) {
			newargv[0] = "sh";
			newargv[1] = full_path;
			execv("/sbin/sh", &newargv[0]);
		}
	}
	execv(alter_path, &newargv[1]);
	if (errno == EACCES) {
		fprintf(stderr, gettext(
		    "%s: Cannot execute %s - permission denied\n"),
		    myname, alter_path);
		exit(1);
	}
	if (errno == ENOEXEC) {
		newargv[0] = "sh";
		newargv[1] = alter_path;
		execv("/sbin/sh", &newargv[0]);
	}
	fprintf(stderr,
	    gettext("%s: Operation not applicable to FSType %s\n"),
	    myname, fstype);
	exit(1);
}