~azzar1/unity/add-show-desktop-key

« back to all changes in this revision

Viewing changes to trampoline/trampoline.c

  • Committer: drtomc
  • Date: 2008-03-05 00:22:02 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:645
trampoline: Add cpu etc limits.

Show diffs side-by-side

added added

removed removed

Lines of Context:
39
39
#include <unistd.h>
40
40
#include <sys/types.h>
41
41
#include <sys/stat.h>
 
42
#include <sys/time.h>
 
43
#include <sys/resource.h>
42
44
#include <limits.h>
43
45
 
44
46
/* conf.h is admin-configured by the setup process.
112
114
static void usage(const char* nm)
113
115
{
114
116
    fprintf(stderr,
115
 
        "usage: %s [-d] <uid> <jail> <cwd> <program> [args...]\n", nm);
 
117
        "usage: %s [-d] [-u] <uid> <jail> <cwd> <program> [args...]\n", nm);
116
118
    exit(1);
117
119
}
118
120
 
125
127
    int uid;
126
128
    int arg_num = 1;
127
129
    int daemon_mode = 0;
 
130
    int unlimited = 0;
128
131
    char canonical_jailpath[PATH_MAX];
129
132
 
130
133
    /* Disallow execution from all users but the whitelisted ones, and root */
149
152
        daemon_mode = 1;
150
153
        arg_num++;
151
154
    }
 
155
 
 
156
    if (strcmp(argv[arg_num], "-u") == 0)
 
157
    {
 
158
        if (argc < 6)
 
159
        {
 
160
            usage(argv[0]);
 
161
        }
 
162
        unlimited = 1;
 
163
        arg_num++;
 
164
    }
152
165
    uid = atoi(argv[arg_num++]);
153
166
    jailpath = argv[arg_num++];
154
167
    work_dir = argv[arg_num++];
212
225
        daemonize();
213
226
    }
214
227
 
 
228
    /* set user resource limits */
 
229
    if (!unlimited)
 
230
    {
 
231
        struct rlimit l;
 
232
        /* Process size in virtual memory */
 
233
        l.rlim_cur = 64 * 1024 * 1024; /* 64Mb */
 
234
        l.rlim_max = 72 * 1024 * 1024; /* 64Mb */
 
235
        if (setrlimit(RLIMIT_AS, &l))
 
236
        {
 
237
            perror("could not setrlimit/RLIMIT_AS");
 
238
            exit(1);
 
239
        }
 
240
 
 
241
        /* Core */
 
242
        l.rlim_cur = 0;
 
243
        l.rlim_max = 0;
 
244
        if (setrlimit(RLIMIT_CORE, &l))
 
245
        {
 
246
            perror("could not setrlimit/RLIMIT_CORE");
 
247
            exit(1);
 
248
        }
 
249
 
 
250
        /* CPU */
 
251
        l.rlim_cur = 25;
 
252
        l.rlim_max = 30;
 
253
        if (setrlimit(RLIMIT_CPU, &l))
 
254
        {
 
255
            perror("could not setrlimit/RLIMIT_CPU");
 
256
            exit(1);
 
257
        }
 
258
 
 
259
        /* File Size */
 
260
        l.rlim_cur = 64 * 1024 * 1024; /* 64Mb */
 
261
        l.rlim_max = 72 * 1024 * 1024; /* 72Mb */
 
262
        if (setrlimit(RLIMIT_FSIZE, &l))
 
263
        {
 
264
            perror("could not setrlimit/RLIMIT_FSIZE");
 
265
            exit(1);
 
266
        }
 
267
    }
 
268
 
215
269
    /* exec (replace this process with the a new instance of the target
216
270
     * program). Pass along all the arguments.
217
271
     * Note that for script execution, the "program" will be the interpreter,