#include #include #include #include #include #include /* for errno translation */ /* ulimiter * * Quick hack. Runs condor_master with an increased number of allowed file * handles. Must be run as root (probably as a setuid script). */ /* Number of open files to increase to */ #define NEW_MAX (1024*8) /* Path to condor_master to start */ #define CONDOR_MASTER "/home/mopmast/condorg/sbin/condor_master" /* environment variable CONDOR_CONFIG */ #define CONDOR_CONFIG "/home/mopmast/condorg/etc/condor_config" /* UID / GUID */ #define UID 101 #define GID 101 int main() { int ret; struct rlimit rl; if(getuid() != UID) { fprintf(stderr, "Only uid %d is allowed to run this\n", UID); return 1; } ret = getrlimit(RLIMIT_NOFILE, &rl); if(ret != 0) { fprintf(stderr, "Unable to read open file limit.\n" "(getrlimit(RLIMIT_NOFILE, &rl) failed)\n" "(%d, %s)", errno, strerror(errno)); return 1; } fprintf(stderr, "Limit was %d (max %d), setting to %d\n", rl.rlim_cur, rl.rlim_max, NEW_MAX); rl.rlim_cur = rl.rlim_max = NEW_MAX; ret = setrlimit(RLIMIT_NOFILE, &rl); if(ret != 0) { fprintf(stderr, "Unable to set open file limit.\n" "(setrlimit(RLIMIT_NOFILE, &rl) failed)\n" "(%d, %s)", errno, strerror(errno)); return 1; } ret = getrlimit(RLIMIT_NOFILE, &rl); if(ret != 0) { fprintf(stderr, "Unable to read new open file limit.\n" "(getrlimit(RLIMIT_NOFILE, &rl) failed)\n" "(%d, %s)", errno, strerror(errno)); return 1; } if(rl.rlim_cur < NEW_MAX) { fprintf(stderr, "Failed to set new open file limit.\n" "Limit is %d, expected %d\n", rl.rlim_cur, NEW_MAX); return 1; } fprintf(stderr, "Success\n"); if(setgid(GID) != 0) { fprintf(stderr, "setgid failed (%d, %s)\n", errno, strerror(errno)); return 1; } if(setuid(UID) != 0) { fprintf(stderr, "setuid failed (%d, %s)\n", errno, strerror(errno)); return 1; } if(setenv("CONDOR_CONFIG", CONDOR_CONFIG, 1) != 0) { fprintf(stderr, "setenv failed\n"); return 1; } ret = execl(CONDOR_MASTER, CONDOR_MASTER, 0); fprintf(stderr, "execl returned, failure\n" "returned %d, errno is %d (%s)\n", ret, errno, strerror(errno)); return 1; }