~ubuntu-branches/ubuntu/natty/9base/natty

« back to all changes in this revision

Viewing changes to lib9/getns.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Baumann
  • Date: 2009-08-20 17:34:06 UTC
  • mfrom: (6.2.2 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090820173406-xpwqa9ruyevvc0ut
Tags: 1:3-3
* Updating maintainer field.
* Updating vcs fields.
* Updating package to standards version 3.8.3.
* Updatin variables writing in rules to consistent style.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
#include <libc.h>
3
3
#include <ctype.h>
4
4
 
 
5
static int
 
6
isme(char *uid)
 
7
{
 
8
        int n;
 
9
        char *p;
 
10
 
 
11
        n = strtol(uid, &p, 10);
 
12
        if(*p == 0 && p > uid)
 
13
                return n == getuid();
 
14
        return strcmp(getuser(), uid) == 0;
 
15
}
5
16
/*
6
17
 * Absent other hints, it works reasonably well to use
7
18
 * the X11 display name as the name space identifier.
18
29
        char *disp, *p;
19
30
 
20
31
        if((disp = getenv("DISPLAY")) == nil){
 
32
#ifdef __APPLE__
 
33
                // Might be running native GUI on OS X.
 
34
                disp = strdup(":0.0");
 
35
                if(disp == nil)
 
36
                        return nil;
 
37
#else
21
38
                werrstr("$DISPLAY not set");
22
39
                return nil;
 
40
#endif
23
41
        }
24
42
 
25
43
        /* canonicalize: xxx:0.0 => xxx:0 */
31
49
                if(strcmp(p, ".0") == 0)
32
50
                        *p = 0;
33
51
        }
 
52
        
 
53
        /* turn /tmp/launch/:0 into _tmp_launch_:0 (OS X 10.5) */
 
54
        for(p=disp; *p; p++)
 
55
                if(*p == '/')
 
56
                        *p = '_';
34
57
 
35
58
        p = smprint("/tmp/ns.%s.%s", getuser(), disp);
36
59
        free(disp);
48
71
                free(p);
49
72
                return nil;
50
73
        }
51
 
        if((d->mode&0777) != 0700 || strcmp(d->uid, getuser()) != 0){
 
74
        if((d->mode&0777) != 0700 || !isme(d->uid)){
52
75
                werrstr("bad name space dir %s", p);
53
76
                free(p);
54
77
                free(d);