| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2007 Niels Provos <provos@citi.umich.edu> | 2 * Copyright (c) 2007 Niels Provos <provos@citi.umich.edu> |
| 3 * All rights reserved. | 3 * All rights reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 #include <fcntl.h> | 46 #include <fcntl.h> |
| 47 #endif | 47 #endif |
| 48 #ifdef HAVE_STDLIB_H | 48 #ifdef HAVE_STDLIB_H |
| 49 #include <stdlib.h> | 49 #include <stdlib.h> |
| 50 #endif | 50 #endif |
| 51 #include <errno.h> | 51 #include <errno.h> |
| 52 #if defined WIN32 && !defined(HAVE_GETTIMEOFDAY_H) | 52 #if defined WIN32 && !defined(HAVE_GETTIMEOFDAY_H) |
| 53 #include <sys/timeb.h> | 53 #include <sys/timeb.h> |
| 54 #endif | 54 #endif |
| 55 #include <stdio.h> | 55 #include <stdio.h> |
| 56 #include <signal.h> |
| 56 | 57 |
| 58 #include <sys/queue.h> |
| 59 #include "event.h" |
| 60 #include "event-internal.h" |
| 57 #include "evutil.h" | 61 #include "evutil.h" |
| 58 #include "log.h" | 62 #include "log.h" |
| 59 | 63 |
| 60 int | 64 int |
| 61 evutil_socketpair(int family, int type, int protocol, int fd[2]) | 65 evutil_socketpair(int family, int type, int protocol, int fd[2]) |
| 62 { | 66 { |
| 63 #ifndef WIN32 | 67 #ifndef WIN32 |
| 64 return socketpair(family, type, protocol, fd); | 68 return socketpair(family, type, protocol, fd); |
| 65 #else | 69 #else |
| 66 /* This code is originally from Tor. Used with permission. */ | 70 /* This code is originally from Tor. Used with permission. */ |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 if (r >= 0) | 240 if (r >= 0) |
| 237 return r; | 241 return r; |
| 238 else | 242 else |
| 239 return _vscprintf(format, ap); | 243 return _vscprintf(format, ap); |
| 240 #else | 244 #else |
| 241 int r = vsnprintf(buf, buflen, format, ap); | 245 int r = vsnprintf(buf, buflen, format, ap); |
| 242 buf[buflen-1] = '\0'; | 246 buf[buflen-1] = '\0'; |
| 243 return r; | 247 return r; |
| 244 #endif | 248 #endif |
| 245 } | 249 } |
| 250 |
| 251 static int |
| 252 evutil_issetugid(void) |
| 253 { |
| 254 #ifdef _EVENT_HAVE_ISSETUGID |
| 255 return issetugid(); |
| 256 #else |
| 257 |
| 258 #ifdef _EVENT_HAVE_GETEUID |
| 259 if (getuid() != geteuid()) |
| 260 return 1; |
| 261 #endif |
| 262 #ifdef _EVENT_HAVE_GETEGID |
| 263 if (getgid() != getegid()) |
| 264 return 1; |
| 265 #endif |
| 266 return 0; |
| 267 #endif |
| 268 } |
| 269 |
| 270 const char * |
| 271 evutil_getenv(const char *varname) |
| 272 { |
| 273 if (evutil_issetugid()) |
| 274 return NULL; |
| 275 |
| 276 return getenv(varname); |
| 277 } |
| OLD | NEW |