/*
- * Copyright (c) 2013 Apple Inc. All rights reserved.
+ * Copyright (c) 2013-2016 Apple Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
pid_t pid = 0;
posix_spawnattr_t attr;
extern char **environ;
- bool flagx = false, flagX = false, flagb = false, flagB = false;
+ bool flagx = false, flagX = false, flagb = false, flagB = false, flaga = false;
int flagd = -1, flagg = -1;
struct task_qos_policy qosinfo = { LATENCY_QOS_TIER_UNSPECIFIED, THROUGHPUT_QOS_TIER_UNSPECIFIED };
uint64_t qos_clamp = POSIX_SPAWN_PROC_CLAMP_NONE;
-
- while ((ch = getopt(argc, argv, "xXbBd:g:c:t:l:p:")) != -1) {
+
+ while ((ch = getopt(argc, argv, "xXbBd:g:c:t:l:p:a")) != -1) {
switch (ch) {
case 'x':
flagx = true;
usage();
}
break;
+ case 'a':
+ flaga = true;
+ break;
case '?':
default:
usage();
warnx("Incompatible option(s) used with -p");
usage();
}
-
+
if (flagx && flagX){
warnx("Incompatible options -x, -X");
usage();
err(EX_SOFTWARE, "task_policy_set(...TASK_OVERRIDE_QOS_POLICY...)");
}
}
-
+
if (pid != 0)
return 0;
-
-
+
ret = posix_spawnattr_init(&attr);
if (ret != 0) errc(EX_NOINPUT, ret, "posix_spawnattr_init");
-
+
ret = posix_spawnattr_setflags(&attr, POSIX_SPAWN_SETEXEC);
if (ret != 0) errc(EX_NOINPUT, ret, "posix_spawnattr_setflags");
-
+
if (qos_clamp != POSIX_SPAWN_PROC_CLAMP_NONE) {
ret = posix_spawnattr_set_qos_clamp_np(&attr, qos_clamp);
if (ret != 0) errc(EX_NOINPUT, ret, "posix_spawnattr_set_qos_clamp_np");
}
-
+
+ if (flaga) {
+ ret = posix_spawnattr_setprocesstype_np(&attr, POSIX_SPAWN_PROC_TYPE_APP_DEFAULT);
+ if (ret != 0) errc(EX_NOINPUT, ret, "posix_spawnattr_setprocesstype_np");
+
+ ret = posix_spawnattr_set_darwin_role_np(&attr, PRIO_DARWIN_ROLE_UI);
+ if (ret != 0) errc(EX_NOINPUT, ret, "posix_spawnattr_set_darwin_role_np");
+ }
+
ret = posix_spawnp(&pid, argv[0], NULL, &attr, argv, environ);
if (ret != 0) errc(EX_NOINPUT, ret, "posix_spawn");
-
+
return EX_OSERR;
}
static void usage(void)
{
fprintf(stderr, "Usage: %s [-x|-X] [-d <policy>] [-g policy] [-c clamp] [-b] [-t <tier>]\n"
- " [-l <tier>] <program> [<pargs> [...]]\n", getprogname());
+ " [-l <tier>] [-a] <program> [<pargs> [...]]\n", getprogname());
fprintf(stderr, " %s [-b|-B] [-t <tier>] [-l <tier>] -p pid\n", getprogname());
exit(EX_USAGE);
}
{
long policy;
char *endptr = NULL;
-
+
/* first try as an integer */
policy = strtol(strpolicy, &endptr, 0);
if (endptr && (endptr[0] == '\0') && (strpolicy[0] != '\0')) {
/* parsed complete string as a number */
return (int)policy;
}
-
+
if (0 == strcasecmp(strpolicy, "DEFAULT") ) {
return IOPOL_DEFAULT;
} else if (0 == strcasecmp(strpolicy, "IMPORTANT")) {
static int parse_qos_tier(const char *strtier, int parameter){
long policy;
char *endptr = NULL;
-
+
/* first try as an integer */
policy = strtol(strtier, &endptr, 0);
if (endptr && (endptr[0] == '\0') && (strtier[0] != '\0')) {
}
static uint64_t parse_qos_clamp(const char *qos_string) {
-
+
if (0 == strcasecmp(qos_string, "utility") ) {
return POSIX_SPAWN_PROC_CLAMP_UTILITY;
} else if (0 == strcasecmp(qos_string, "background")) {