1 /* 2 * Copyright (C) 2003 Sam Horrocks 3 * 4 * This program is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU General Public License 6 * as published by the Free Software Foundation; either version 2 7 * of the License, or (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program; if not, write to the Free Software 16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 * 18 */ 19 20 /* Implementing DIE_QUIET as a macro was problematic, so now it's a function. */ 21 #ifndef DIE_QUIET 22 #define DIE_QUIET speedy_util_die_quiet 23 #endif 24 25 typedef struct { 26 void *addr; 27 int maplen; 28 int is_mmaped; 29 } SpeedyMapInfo; 30 31 typedef struct { 32 char *buf; 33 int alloced; 34 int len; 35 } SpeedyBuf; 36 37 int speedy_util_pref_fd(int oldfd, int newfd); 38 SPEEDY_INLINE int speedy_util_getuid(void); 39 SPEEDY_INLINE int speedy_util_geteuid(void); 40 int speedy_util_seteuid(int id); 41 int speedy_util_argc(const char * const * argv); 42 SPEEDY_INLINE int speedy_util_getpid(void); 43 void speedy_util_pid_invalidate(void); 44 void speedy_util_die(const char *fmt, ...); 45 void speedy_util_die_quiet(const char *fmt, ...); 46 int speedy_util_execvp(const char *filename, const char *const *argv); 47 char *speedy_util_strndup(const char *s, int len); 48 SPEEDY_INLINE int speedy_util_time(void); 49 SPEEDY_INLINE void speedy_util_gettimeofday(struct timeval *tv); 50 void speedy_util_time_invalidate(void); 51 char *speedy_util_fname(int num, char type); 52 char *speedy_util_getcwd(void); 53 SpeedyMapInfo *speedy_util_mapin(int fd, int max_size, int file_size); 54 void speedy_util_mapout(SpeedyMapInfo *mi); 55 SPEEDY_INLINE SpeedyDevIno speedy_util_stat_devino(const struct stat *stbuf); 56 SPEEDY_INLINE int speedy_util_open_stat(const char *path, struct stat *stbuf); 57 void speedy_util_exit(int status, int underbar_exit); 58 int speedy_util_kill(pid_t pid, int sig); 59 60 #define speedy_util_strdup(s) speedy_util_strndup(s, strlen(s)) 61 62 #define PREF_FD_DONTCARE -1 63 64 /* Preferred file descriptors */ 65 66 #ifdef SPEEDY_BACKEND 67 #define PREF_FD_ACCEPT_I 0 68 #define PREF_FD_ACCEPT_O 1 69 #define PREF_FD_ACCEPT_E 2 70 #define PREF_FD_FILE 17 71 #define PREF_FD_LISTENER 18 72 #define PREF_FD_CWD 19 73 #else 74 #define PREF_FD_FILE PREF_FD_DONTCARE 75 #endif 76 77 #ifdef SPEEDY_DEBUG 78 79 #if !defined(RLIM_INFINITY) || !defined(RLIMIT_CORE) 80 #include <sys/resource.h> 81 #endif 82 83 #define speedy_util_unlimit_core() \ 84 { \ 85 struct rlimit rlimitvals; \ 86 rlimitvals.rlim_cur = RLIM_INFINITY; \ 87 rlimitvals.rlim_max = RLIM_INFINITY; \ 88 setrlimit(RLIMIT_CORE, &rlimitvals); \ 89 } 90 91 #else 92 93 #define speedy_util_unlimit_core() 94 95 #endif /* SPEEDY_DEBUG */ 96