~ubuntu-branches/ubuntu/precise/boinc/precise

« back to all changes in this revision

Viewing changes to client/switcher.cpp

Tags: 6.12.8+dfsg-1
* New upstream release.
* Simplified debian/rules

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
//  once as part of the Full_Path and again as just the name
25
25
 
26
26
#include <unistd.h>
27
 
#include <stdio.h>
28
 
#include <string.h>
 
27
#include <cstdio>
 
28
#include <cstring>
29
29
#include <cerrno>
 
30
#ifdef HAVE_SYS_PARAM_H
30
31
#include <sys/param.h>  // for MAXPATHLEN
 
32
#endif
31
33
#include <pwd.h>        // getpwuid
32
34
#include <grp.h>
33
35
 
 
36
#include "app_ipc.h"
 
37
 
 
38
using std::strcpy;
 
39
 
34
40
int main(int argc, char** argv) {
35
 
    passwd      *pw;
36
 
    group       *grp;
37
 
    char        user_name[256], group_name[256];
 
41
    passwd          *pw;
 
42
    group           *grp;
 
43
    char            user_name[256], group_name[256];
 
44
    APP_INIT_DATA   aid;
 
45
    FILE            *f;
 
46
    int             retval = -1;
 
47
    char            libpath[8192];
 
48
    char            newlibs[256];
 
49
    char            *projectDirName;
38
50
 
39
51
    strcpy(user_name, "boinc_project");
40
52
    strcpy(group_name, "boinc_project");
70
82
    pw = getpwnam(user_name);
71
83
    if (pw) setuid(pw->pw_uid);
72
84
 
 
85
    // For unknown reasons, the LD_LIBRARY_PATH and DYLD_LIBRARY_PATH
 
86
    // environment variables are not passed in to switcher, though all 
 
87
    // other environment variables do get propagated.  So we recreate 
 
88
    // LD_LIBRARY_PATH and DYLD_LIBRARY_PATH here.
 
89
    f = fopen(INIT_DATA_FILE, "r");
 
90
    if (f) {
 
91
        retval = parse_init_data_file(f, aid);
 
92
        fclose(f);
 
93
    }
 
94
 
 
95
    if (!retval) {
 
96
        // Get project name without leading path
 
97
        projectDirName = strrchr(aid.project_dir, '/');
 
98
        if (projectDirName) {
 
99
            ++projectDirName;
 
100
        } else {
 
101
            projectDirName = aid.project_dir;
 
102
        } 
 
103
        sprintf(newlibs, "../../%s:.:../..", projectDirName);
 
104
#ifdef __APPLE__
 
105
        strcat(newlibs, ":/usr/local/cuda/lib/");
 
106
#endif
 
107
        char* p = getenv("LD_LIBRARY_PATH");
 
108
        if (p) {
 
109
            sprintf(libpath, "%s:%s", newlibs, p);
 
110
        } else {
 
111
            strcpy(libpath, newlibs);
 
112
        }
 
113
        setenv("LD_LIBRARY_PATH", libpath, 1);
 
114
 
 
115
        // On the Mac, do the same for DYLD_LIBRARY_PATH
 
116
        //
 
117
#ifdef __APPLE__
 
118
        p = getenv("DYLD_LIBRARY_PATH");
 
119
        if (p) {
 
120
            sprintf(libpath, "%s:%s", newlibs, p);
 
121
        } else {
 
122
            strcpy(libpath, newlibs);
 
123
        }
 
124
        setenv("DYLD_LIBRARY_PATH", libpath, 1);
 
125
#endif
 
126
    }
 
127
 
73
128
    execv(argv[1], argv+2);
74
129
    
75
130
    // If we got here execv failed