Esempio n. 1
0
bool
Downloader::ValidateDownloadPolicy (const Uri *source_location, const Uri *uri, DownloaderAccessPolicy policy)
{
	bool valid;
	
	/* We should always have a source location */
	g_return_val_if_fail (source_location != NULL, false);

	/* The uri combine rules are complex, so ensure they're already executed when we validate (to not duplicate combining code) */
	if (!uri->IsAbsolute ()) {
		fprintf (stderr, "Moonlight: Can't validate relative uri '%s' - '%s'\n", uri->GetOriginalString (), uri->ToString ());
		return false;
	}
	
	valid = validate_policy (source_location, uri, policy);
	
	LOG_DOWNLOADER ("Downloader::ValidatePolicy ('%s', '%s', %i) => %i\n", source_location->GetOriginalString (), uri->GetOriginalString (), policy, valid);

	return valid;
}
Esempio n. 2
0
long
lx_sched_setscheduler(uintptr_t pid, uintptr_t policy, uintptr_t param)
{
	int	rt_pol;
	int	rv;
	pid_t	s_pid;
	lwpid_t	s_tid;
	struct lx_sched_param lp;

	struct sched_param sp;

	if (((pid_t)pid < 0) || (param == NULL))
		return (-EINVAL);

	if ((rt_pol = validate_policy((int)policy)) < 0)
		return (rt_pol);

	if ((rv = ltos_sparam(policy, (struct lx_sched_param *)param,
	    &sp)) != 0)
		return (rv);

	if (uucopy((void *)param, &lp, sizeof (lp)) != 0)
		return (-errno);

	if (rt_pol == LX_SCHED_OTHER) {
		/*
		 * In Linux, the only valid SCHED_OTHER scheduler priority is 0
		 */
		if (lp.lx_sched_prio != 0)
			return (-EINVAL);

		/*
		 * If we're already SCHED_OTHER, there's nothing else to do.
		 */
		if (lx_sched_getscheduler(pid) == LX_SCHED_OTHER)
			return (0);
	}

	if (lx_lpid_to_spair((pid_t)pid, &s_pid, &s_tid) < 0)
		return (-ESRCH);

	/*
	 * Check if we're allowed to change the scheduler for the process.
	 *
	 * If we're operating on a thread, we can't just call
	 * pthread_setschedparam() because as all threads reside within a
	 * single Solaris process, Solaris will allow the modification.
	 *
	 * If we're operating on a process, we can't just call
	 * sched_setscheduler() because Solaris will allow the call to succeed
	 * if the scheduler and scheduler parameters do not differ from those
	 * being installed, but Linux wants the call to fail.
	 */
	if ((rv = check_schedperms(s_pid)) != 0)
		return (rv);

	if (s_pid == getpid()) {
		struct sched_param param;
		int pol;

		if ((pol = sched_getscheduler(s_pid)) == -1)
			return (-errno);

		/*
		 * sched_setscheduler() returns the previous scheduling policy
		 * on success, so call pthread_getschedparam() to get the
		 * current thread's scheduling policy and return that if the
		 * call to pthread_setschedparam() succeeds.
		 */
		if ((rv = pthread_getschedparam(s_tid, &pol, &param)) != 0)
			return (-rv);

		return (((rv = pthread_setschedparam(s_tid, rt_pol, &sp)) != 0)
		    ? -rv : pol);
	}

	return (((rv = sched_setscheduler(s_pid, rt_pol, &sp)) == -1)
	    ? -errno : rv);
}