+
+/*
+ * WARNING: This is SPI specifically intended for use by launchd to start UI
+ * apps. We use it here for a test tool only to opt into QoS using the same
+ * policies. Do not use this outside xnu or libxpc/launchd.
+ */
+void
+selfexec_with_apptype(int argc, char *argv[])
+{
+ int ret;
+ posix_spawnattr_t attr;
+ extern char **environ;
+ char *new_argv[argc + 1 + 1 /* NULL */];
+ int i;
+ char prog[PATH_MAX];
+ uint32_t prog_size = PATH_MAX;
+
+ ret = _NSGetExecutablePath(prog, &prog_size);
+ if (ret != 0) err(1, "_NSGetExecutablePath");
+
+ for (i=0; i < argc; i++) {
+ new_argv[i] = argv[i];
+ }
+
+ new_argv[i] = "-switched_apptype";
+ new_argv[i+1] = NULL;
+
+ ret = posix_spawnattr_init(&attr);
+ if (ret != 0) errc(1, ret, "posix_spawnattr_init");
+
+ ret = posix_spawnattr_setflags(&attr, POSIX_SPAWN_SETEXEC);
+ if (ret != 0) errc(1, ret, "posix_spawnattr_setflags");
+
+ ret = posix_spawnattr_setprocesstype_np(&attr, POSIX_SPAWN_PROC_TYPE_APP_DEFAULT);
+ if (ret != 0) errc(1, ret, "posix_spawnattr_setprocesstype_np");
+
+ ret = posix_spawn(NULL, prog, NULL, &attr, new_argv, environ);
+ if (ret != 0) errc(1, ret, "posix_spawn");
+}