Exemplo n.º 1
0
/** Run ldconfig in a chroot.
 * @param handle the context handle
 * @return 0 on success, 1 on error
 */
int _alpm_ldconfig(alpm_handle_t *handle)
{
	char line[PATH_MAX];

	_alpm_log(handle, ALPM_LOG_DEBUG, "running ldconfig\n");

	snprintf(line, PATH_MAX, "%setc/ld.so.conf", handle->root);
	if(access(line, F_OK) == 0) {
		snprintf(line, PATH_MAX, "%ssbin/ldconfig", handle->root);
		if(access(line, X_OK) == 0) {
			char arg0[32];
			char *argv[] = { arg0, NULL };
			strcpy(arg0, "ldconfig");
			return _alpm_run_chroot(handle, "/sbin/ldconfig", argv);
		}
	}

	return 0;
}
Exemplo n.º 2
0
int _alpm_runscriptlet(alpm_handle_t *handle, const char *filepath,
		const char *script, const char *ver, const char *oldver, int is_archive)
{
	char arg0[64], arg1[3], cmdline[PATH_MAX];
	char *argv[] = { arg0, arg1, cmdline, NULL };
	char *tmpdir, *scriptfn = NULL, *scriptpath;
	int retval = 0;
	size_t len;

	if(_alpm_access(handle, NULL, filepath, R_OK) != 0) {
		_alpm_log(handle, ALPM_LOG_DEBUG, "scriptlet '%s' not found\n", filepath);
		return 0;
	}

	if(!is_archive && !grep(filepath, script)) {
		/* script not found in scriptlet file; we can only short-circuit this early
		 * if it is an actual scriptlet file and not an archive. */
		return 0;
	}

	strcpy(arg0, SCRIPTLET_SHELL);
	strcpy(arg1, "-c");

	/* create a directory in $root/tmp/ for copying/extracting the scriptlet */
	len = strlen(handle->root) + strlen("tmp/alpm_XXXXXX") + 1;
	MALLOC(tmpdir, len, RET_ERR(handle, ALPM_ERR_MEMORY, -1));
	snprintf(tmpdir, len, "%stmp/", handle->root);
	if(access(tmpdir, F_OK) != 0) {
		_alpm_makepath_mode(tmpdir, 01777);
	}
	snprintf(tmpdir, len, "%stmp/alpm_XXXXXX", handle->root);
	if(mkdtemp(tmpdir) == NULL) {
		_alpm_log(handle, ALPM_LOG_ERROR, _("could not create temp directory\n"));
		free(tmpdir);
		return 1;
	}

	/* either extract or copy the scriptlet */
	len += strlen("/.INSTALL");
	MALLOC(scriptfn, len, free(tmpdir); RET_ERR(handle, ALPM_ERR_MEMORY, -1));
	snprintf(scriptfn, len, "%s/.INSTALL", tmpdir);
	if(is_archive) {
		if(_alpm_unpack_single(handle, filepath, tmpdir, ".INSTALL")) {
			retval = 1;
		}
	} else {
		if(_alpm_copyfile(filepath, scriptfn)) {
			_alpm_log(handle, ALPM_LOG_ERROR, _("could not copy tempfile to %s (%s)\n"), scriptfn, strerror(errno));
			retval = 1;
		}
	}
	if(retval == 1) {
		goto cleanup;
	}

	if(is_archive && !grep(scriptfn, script)) {
		/* script not found in extracted scriptlet file */
		goto cleanup;
	}

	/* chop off the root so we can find the tmpdir in the chroot */
	scriptpath = scriptfn + strlen(handle->root) - 1;

	if(oldver) {
		snprintf(cmdline, PATH_MAX, ". %s; %s %s %s",
				scriptpath, script, ver, oldver);
	} else {
		snprintf(cmdline, PATH_MAX, ". %s; %s %s",
				scriptpath, script, ver);
	}

	_alpm_log(handle, ALPM_LOG_DEBUG, "executing \"%s\"\n", cmdline);

	retval = _alpm_run_chroot(handle, SCRIPTLET_SHELL, argv, NULL, NULL);

cleanup:
	if(scriptfn && unlink(scriptfn)) {
		_alpm_log(handle, ALPM_LOG_WARNING,
				_("could not remove %s\n"), scriptfn);
	}
	if(rmdir(tmpdir)) {
		_alpm_log(handle, ALPM_LOG_WARNING,
				_("could not remove tmpdir %s\n"), tmpdir);
	}

	free(scriptfn);
	free(tmpdir);
	return retval;
}
Exemplo n.º 3
0
int _alpm_runscriptlet(alpm_handle_t *handle, const char *installfn,
                       const char *script, const char *ver, const char *oldver)
{
    char scriptfn[PATH_MAX];
    char cmdline[PATH_MAX];
    char tmpdir[PATH_MAX];
    char *argv[] = { "sh", "-c", cmdline, NULL };
    char *scriptpath;
    int clean_tmpdir = 0;
    int retval = 0;

    if(access(installfn, R_OK)) {
        /* not found */
        _alpm_log(handle, ALPM_LOG_DEBUG, "scriptlet '%s' not found\n", installfn);
        return 0;
    }

    /* creates a directory in $root/tmp/ for copying/extracting the scriptlet */
    snprintf(tmpdir, PATH_MAX, "%stmp/", handle->root);
    if(access(tmpdir, F_OK) != 0) {
        _alpm_makepath_mode(tmpdir, 01777);
    }
    snprintf(tmpdir, PATH_MAX, "%stmp/alpm_XXXXXX", handle->root);
    if(mkdtemp(tmpdir) == NULL) {
        _alpm_log(handle, ALPM_LOG_ERROR, _("could not create temp directory\n"));
        return 1;
    } else {
        clean_tmpdir = 1;
    }

    /* either extract or copy the scriptlet */
    snprintf(scriptfn, PATH_MAX, "%s/.INSTALL", tmpdir);
    if(strcmp(script, "pre_upgrade") == 0 || strcmp(script, "pre_install") == 0) {
        if(_alpm_unpack_single(handle, installfn, tmpdir, ".INSTALL")) {
            retval = 1;
        }
    } else {
        if(_alpm_copyfile(installfn, scriptfn)) {
            _alpm_log(handle, ALPM_LOG_ERROR, _("could not copy tempfile to %s (%s)\n"), scriptfn, strerror(errno));
            retval = 1;
        }
    }
    if(retval == 1) {
        goto cleanup;
    }

    /* chop off the root so we can find the tmpdir in the chroot */
    scriptpath = scriptfn + strlen(handle->root) - 1;

    if(!grep(scriptfn, script)) {
        /* script not found in scriptlet file */
        goto cleanup;
    }

    if(oldver) {
        snprintf(cmdline, PATH_MAX, ". %s; %s %s %s",
                 scriptpath, script, ver, oldver);
    } else {
        snprintf(cmdline, PATH_MAX, ". %s; %s %s",
                 scriptpath, script, ver);
    }

    _alpm_log(handle, ALPM_LOG_DEBUG, "executing \"%s\"\n", cmdline);

    retval = _alpm_run_chroot(handle, "/bin/sh", argv);

cleanup:
    if(clean_tmpdir && _alpm_rmrf(tmpdir)) {
        _alpm_log(handle, ALPM_LOG_WARNING, _("could not remove tmpdir %s\n"), tmpdir);
    }

    return retval;
}