00001
00005 #ifndef H_SYSTEM
00006 #define H_SYSTEM
00007
00008 #ifdef HAVE_CONFIG_H
00009 #include "config.h"
00010 #endif
00011
00012 #include <sys/types.h>
00013
00014 #include <sys/stat.h>
00015 #include <stdio.h>
00016
00017 #ifdef HAVE_SYS_PARAM_H
00018 #include <sys/param.h>
00019 #endif
00020
00021
00022
00023 #ifdef HAVE_UNISTD_H
00024 #include <unistd.h>
00025 #if !defined(__GLIBC__)
00026 #ifdef __APPLE__
00027 #include <crt_externs.h>
00028 #define environ (*_NSGetEnviron())
00029 #else
00030 extern char ** environ;
00031 #endif
00032 #endif
00033 #endif
00034
00035 #if TIME_WITH_SYS_TIME
00036 # include <sys/time.h>
00037 # include <time.h>
00038 #else
00039 # if HAVE_SYS_TIME_H
00040 # include <sys/time.h>
00041 # else
00042 # include <time.h>
00043 # endif
00044 #endif
00045
00046
00047 #if MAJOR_IN_MKDEV
00048 #include <sys/mkdev.h>
00049 #define HAVE_MAJOR
00050 #endif
00051 #if MAJOR_IN_SYSMACROS
00052 #include <sys/sysmacros.h>
00053 #define HAVE_MAJOR
00054 #endif
00055 #ifdef major
00056 #define HAVE_MAJOR
00057 #endif
00058
00059 #ifndef HAVE_MAJOR
00060 #define major(dev) (((dev) >> 8) & 0xff)
00061 #define minor(dev) ((dev) & 0xff)
00062 #define makedev(maj, min) (((maj) << 8) | (min))
00063 #endif
00064 #undef HAVE_MAJOR
00065
00066 #ifdef HAVE_UTIME_H
00067 #include <utime.h>
00068 #endif
00069
00070 #ifdef HAVE_STRING_H
00071 # if !STDC_HEADERS && HAVE_MEMORY_H
00072 # include <memory.h>
00073 # endif
00074 # include <string.h>
00075 #else
00076 # include <strings.h>
00077 char *memchr ();
00078 #endif
00079
00080 #if !defined(HAVE_STPCPY)
00081 char * stpcpy(char * dest, const char * src);
00082 #endif
00083
00084 #if !defined(HAVE_STPNCPY)
00085 char * stpncpy(char * dest, const char * src, size_t n);
00086 #endif
00087
00088 #include <errno.h>
00089 #ifndef errno
00090 extern int errno;
00091 #endif
00092
00093 #if HAVE_ERROR && HAVE_ERROR_H
00094 #include <error.h>
00095 #endif
00096
00097 #if HAVE___SECURE_GETENV
00098 #define getenv(_s) __secure_getenv(_s)
00099 #endif
00100
00101 #ifdef STDC_HEADERS
00102
00103 #define getopt system_getopt
00104 #include <stdlib.h>
00105 #undef getopt
00106 #else
00107 char *getenv (const char *name);
00108 #if ! HAVE_REALPATH
00109 char *realpath(const char *path, char resolved_path []);
00110 #endif
00111 #endif
00112
00113
00114 #if !defined(EXIT_FAILURE)
00115 #define EXIT_FAILURE 1
00116 #endif
00117
00118 #ifdef HAVE_FCNTL_H
00119 #include <fcntl.h>
00120 #else
00121 #include <sys/file.h>
00122 #endif
00123
00124 #if !defined(SEEK_SET)
00125 #define SEEK_SET 0
00126 #define SEEK_CUR 1
00127 #define SEEK_END 2
00128 #endif
00129 #if !defined(F_OK)
00130 #define F_OK 0
00131 #define X_OK 1
00132 #define W_OK 2
00133 #define R_OK 4
00134 #endif
00135
00136 #ifdef HAVE_DIRENT_H
00137 # include <dirent.h>
00138 # define NLENGTH(direct) (strlen((direct)->d_name))
00139 #else
00140 # define dirent direct
00141 # define NLENGTH(direct) ((direct)->d_namlen)
00142 # ifdef HAVE_SYS_NDIR_H
00143 # include <sys/ndir.h>
00144 # endif
00145 # ifdef HAVE_SYS_DIR_H
00146 # include <sys/dir.h>
00147 # endif
00148 # ifdef HAVE_NDIR_H
00149 # include <ndir.h>
00150 # endif
00151 #endif
00152
00153 #include <ctype.h>
00154
00155 #if HAVE_SYS_MMAN_H
00156 #include <sys/mman.h>
00157 #endif
00158
00159
00160 #if HAVE_SYS_RESOURCE_H && HAVE_SYS_TIME_H
00161 #include <sys/resource.h>
00162 #endif
00163
00164 #if HAVE_SYS_UTSNAME_H
00165 #include <sys/utsname.h>
00166 #endif
00167
00168 #if HAVE_SYS_WAIT_H
00169 #include <sys/wait.h>
00170 #endif
00171
00172 #if HAVE_GETOPT_H
00173 #include <getopt.h>
00174 #endif
00175
00176 #if HAVE_GRP_H
00177 #include <grp.h>
00178 #endif
00179
00180 #if HAVE_LIMITS_H
00181 #include <limits.h>
00182 #endif
00183
00184 #ifndef PATH_MAX
00185 #ifdef _POSIX_PATH_MAX
00186 #define PATH_MAX _POSIX_PATH_MAX
00187 #elif defined MAXPATHLEN
00188 #define PATH_MAX MAXPATHLEN
00189 #else
00190 #define PATH_MAX 256
00191 #endif
00192 #endif
00193
00194 #if HAVE_ERR_H
00195 #include <err.h>
00196 #endif
00197
00198 #if HAVE_MALLOC_H
00199 #include <malloc.h>
00200 #endif
00201
00202 #if WITH_SELINUX
00203 #include <selinux/selinux.h>
00204 #else
00205 typedef char * security_context_t;
00206
00207 #define freecon(_c)
00208
00209 #define getfilecon(_fn, _c) (-1)
00210 #define lgetfilecon(_fn, _c) (-1)
00211 #define fgetfilecon(_fd, _c) (-1)
00212
00213 #define setfilecon(_fn, _c) (-1)
00214 #define lsetfilecon(_fn, _c) (-1)
00215 #define fsetfilecon(_fd, _c) (-1)
00216
00217 #define security_check_context(_c) (0)
00218
00219 #define is_selinux_enabled() (0)
00220
00221 #define matchpathcon_init(_fn) (-1)
00222 #define matchpathcon_fini() (0)
00223 #define matchpathcon(_fn, _fm, _c) (-1)
00224
00225 #define rpm_execcon(_v, _fn, _av, _envp) (0)
00226 #endif
00227
00233 static inline
00234 void * _free(void * p)
00235 {
00236 if (p != NULL) free(p);
00237 return NULL;
00238 }
00239
00240 #if WITH_CAP
00241 #include <sys/capability.h>
00242 #else
00243 typedef void * cap_t;
00244 #endif
00245
00246 #if WITH_ACL
00247 #include <acl/libacl.h>
00248 #endif
00249
00257 static inline
00258 void * _constfree(const void * p)
00259 {
00260 if (p != NULL) free((void *)p);
00261 return NULL;
00262 }
00263
00264
00267 void * xmalloc (size_t size);
00268
00271 void * xcalloc (size_t nmemb, size_t size);
00272
00276 void * xrealloc (void * ptr,
00277 size_t size);
00278
00281 char * xstrdup (const char *str);
00282
00285 void * vmefail(size_t size);
00286
00287 #if HAVE_MCHECK_H
00288 #include <mcheck.h>
00289
00290 #if defined(__GNUC__)
00291 #define xmalloc(_size) (malloc(_size) ? : vmefail(_size))
00292 #define xcalloc(_nmemb, _size) (calloc((_nmemb), (_size)) ? : vmefail(_size))
00293 #define xrealloc(_ptr, _size) (realloc((_ptr), (_size)) ? : vmefail(_size))
00294 #define xstrdup(_str) (strcpy((malloc(strlen(_str)+1) ? : vmefail(strlen(_str)+1)), (_str)))
00295 #endif
00296 #endif
00297
00298
00299 #if defined __GLIBC__ && __GLIBC__ >= 2
00300 #if __GLIBC_MINOR__ >= 1
00301 #define __progname __assert_program_name
00302 #endif
00303 #define setprogname(pn)
00304 #else
00305 #define __progname program_name
00306 #define setprogname(pn) \
00307 { if ((__progname = strrchr(pn, '/')) != NULL) __progname++; \
00308 else __progname = pn; \
00309 }
00310 #endif
00311 extern const char *__progname;
00312
00313 #if HAVE_NETDB_H
00314 #include <netdb.h>
00315 #endif
00316
00317 #if HAVE_PWD_H
00318 #include <pwd.h>
00319 #endif
00320
00321
00322
00323 #if HAVE_LOCALE_H
00324 # include <locale.h>
00325 #endif
00326 #if !HAVE_SETLOCALE
00327 # define setlocale(Category, Locale)
00328 #endif
00329
00330 #if ENABLE_NLS
00331 # include <libintl.h>
00332 # define _(Text) dgettext (PACKAGE, Text)
00333 #else
00334 # undef bindtextdomain
00335 # define bindtextdomain(Domain, Directory)
00336 # undef textdomain
00337 # define textdomain(Domain)
00338 # define _(Text) Text
00339 # undef dgettext
00340 # define dgettext(DomainName, Text) Text
00341 #endif
00342
00343 #define N_(Text) Text
00344
00345
00346
00347 #if !defined(USE_GNU_GLOB)
00348 #if HAVE_FNMATCH_H
00349 #include <fnmatch.h>
00350 #endif
00351
00352 #if HAVE_GLOB_H
00353 #include <glob.h>
00354 #endif
00355 #else
00356 #include "misc/glob.h"
00357 #include "misc/fnmatch.h"
00358 #endif
00359
00360 #if ! HAVE_S_IFSOCK
00361 #define S_IFSOCK (0xc000)
00362 #endif
00363
00364 #if ! HAVE_S_ISLNK
00365 #define S_ISLNK(mode) ((mode & 0xf000) == S_IFLNK)
00366 #endif
00367
00368 #if ! HAVE_S_ISSOCK
00369 #define S_ISSOCK(mode) ((mode & 0xf000) == S_IFSOCK)
00370 #endif
00371
00372 #if NEED_STRINGS_H
00373 #include <strings.h>
00374 #endif
00375
00376 #if NEED_MYREALLOC
00377 #define realloc(ptr,size) myrealloc(ptr,size)
00378 extern void *myrealloc(void *, size_t);
00379 #endif
00380
00381 #if ! HAVE_SETENV
00382 extern int setenv(const char *name, const char *value, int replace);
00383 extern void unsetenv(const char *name);
00384 #endif
00385
00386 #if HAVE_SYS_SOCKET_H
00387 #include <sys/types.h>
00388 #include <sys/socket.h>
00389 #endif
00390
00391 #if HAVE_POLL_H
00392 #include <poll.h>
00393 #else
00394 #if HAVE_SYS_SELECT_H
00395 #include <sys/select.h>
00396 #endif
00397 #endif
00398
00399
00400 #if HAVE_GETPASSPHRASE
00401 #define getpass getpassphrase
00402 #endif
00403
00404 #if ! HAVE_LCHOWN
00405 #define lchown chown
00406 #endif
00407
00408 #if HAVE_GETMNTINFO || HAVE_GETMNTINFO_R || HAVE_MNTCTL
00409 # define GETMNTENT_ONE 0
00410 # define GETMNTENT_TWO 0
00411 # if HAVE_SYS_MNTCTL_H
00412 # include <sys/mntctl.h>
00413 # endif
00414 # if HAVE_SYS_VMOUNT_H
00415 # include <sys/vmount.h>
00416 # endif
00417 # if HAVE_SYS_MOUNT_H
00418 # include <sys/mount.h>
00419 # endif
00420 #elif HAVE_MNTENT_H || !(HAVE_GETMNTENT) || HAVE_STRUCT_MNTTAB
00421 # if HAVE_MNTENT_H
00422 # include <stdio.h>
00423 # include <mntent.h>
00424 # define our_mntent struct mntent
00425 # define our_mntdir mnt_dir
00426 # elif HAVE_STRUCT_MNTTAB
00427 # include <stdio.h>
00428 # include <mnttab.h>
00429 struct our_mntent {
00430 char * our_mntdir;
00431 };
00432 struct our_mntent *getmntent(FILE *filep);
00433 # define our_mntent struct our_mntent
00434 # else
00435 # include <stdio.h>
00436 struct our_mntent {
00437 char * our_mntdir;
00438 };
00439 struct our_mntent *getmntent(FILE *filep);
00440 # define our_mntent struct our_mntent
00441 # endif
00442 # define GETMNTENT_ONE 1
00443 # define GETMNTENT_TWO 0
00444 #elif HAVE_SYS_MNTTAB_H
00445 # include <stdio.h>
00446 # include <sys/mnttab.h>
00447 # define GETMNTENT_ONE 0
00448 # define GETMNTENT_TWO 1
00449 # define our_mntent struct mnttab
00450 # define our_mntdir mnt_mountp
00451 #else
00452 # error Neither mntent.h, mnttab.h, or mntctl() exists. I cannot build on this system.
00453 #endif
00454
00455 #ifndef MOUNTED
00456 #define MOUNTED "/etc/mnttab"
00457 #endif
00458
00459 #endif