Skip to content

Commit

Permalink
wrapper: use uname(3) to find OS version
Browse files Browse the repository at this point in the history
We warn if the OS is not "Darwin".

Major versions prior to 10.2 are not fully decoded (we have no
"attach" implementation for 10.4 and earlier anyway).
  • Loading branch information
ChrisJohnsen committed Mar 21, 2011
1 parent b4cac80 commit 25b0399
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
1 change: 0 additions & 1 deletion TODO
@@ -1,4 +1,3 @@
wrapper: detect OS version: probably uname(3): warn non-Darwin
wrapper: switch 10.6 to detach "detach from console" from 10.6's screen patch?
We want to move to newer "detach from console" function just in
case the "move subset to user" one is removed in a future
Expand Down
35 changes: 32 additions & 3 deletions user-session-wrapper.c
@@ -1,11 +1,12 @@
#include <string.h> /* strlen, strcpy, strerror, strcmp, strrchr */
#include <stdarg.h> /* va_... */
#include <stdio.h> /* fprintf, vfprintf */
#include <stdlib.h> /* malloc, exit, free */
#include <stdlib.h> /* malloc, exit, free, atoi */
#include <dlfcn.h> /* dlsym */
#include <stdint.h> /* uint64_t */
#include <unistd.h> /* execvp */
#include <sys/errno.h> /* errno */
#include <sys/utsname.h> /* uname */

#if 0
void * _vprocmgr_move_subset_to_user(uid_t target_user, const char *session_type, uint64_t flags); /* 10.6 */
Expand All @@ -29,12 +30,40 @@ void die(int ev, const char *fmt, ...) {
exit(ev);
}

/*
* ##__VA_ARGS_ is a GNU CPP extension to invoke with zero extra args.
* Expects f to be a literal string (for compile-time concatenation).
*/
#define die_errno(x,f,...) die((x),(f ": %s"),##__VA_ARGS__,strerror(errno))

int main(int argc, char *argv[]) {
if (argc < 2)
die(1, "usage: %s <program> [args...]", argv[0]);

/* TODO: detect OS version */
unsigned int os = 1060;
unsigned int os = 0;

struct utsname u;
if (uname(&u))
die_errno(2, "uname failed");
if (strcmp(u.sysname, "Darwin"))
fprintf(stderr, "warning: unsupported OS sysname: %s\n", u.sysname);

char *rest, *whole = strdup(u.release);
if (!whole)
die_errno(2, "strdup failed");
rest = whole;
strsep(&rest, ".");
if (whole && *whole && whole != rest) {
int major = atoi(whole);
if (major >= 6) /* 10.2 -- 10.7 */
os = 1000 + (major-4) * 10;
else /* 10.1, 10.0 and prior betas/previews */
os = 1000;
}
else
fprintf(stderr, "warning: unparsable major release number: '%s'\n", u.release);

free(whole);

if (os < 1050) {
fprintf(stderr, "warning: unsupported old OS, trying as if it were 10.5\n");
Expand Down

0 comments on commit 25b0399

Please sign in to comment.