00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "defs.h"
00022 #include <sys/resource.h>
00023
00024 static void showvalue(rlim_t lim)
00025 {
00026
00027
00028
00029
00030 if (lim == RLIM_INFINITY)
00031 printf("RLIM_INFINITY");
00032 #ifndef BSD_DERIVED
00033 else if (lim == RLIM_SAVED_CUR)
00034 printf("RLIM_SAVED_CUR");
00035 else if (lim == RLIM_SAVED_MAX)
00036 printf("RLIM_SAVED_MAX");
00037 #endif
00038 else
00039 printf("%llu", (unsigned long long)lim);
00040 }
00041
00042 static bool showlimit(int resource, const char *name)
00043 {
00044 struct rlimit r;
00045
00046 ec_neg1( getrlimit(resource, &r) )
00047 printf("%s: ", name);
00048 printf("rlim_cur = ");
00049 showvalue(r.rlim_cur);
00050 printf("; rlim_max = ");
00051 showvalue(r.rlim_max);
00052 printf("\n");
00053 return true;
00054
00055 EC_CLEANUP_BGN
00056 return false;
00057 EC_CLEANUP_END
00058 }
00059
00060 int main(void)
00061 {
00062 struct rlimit r;
00063 int fd;
00064 char buf[500] = { 0 };
00065
00066 if (sizeof(rlim_t) > sizeof(long long))
00067 printf("Warning: rlim_t > long long; results may be wrong\n");
00068 ec_false( showlimit(RLIMIT_CORE, "RLIMIT_CORE") )
00069 ec_false( showlimit(RLIMIT_CPU, "RLIMIT_CPU") )
00070 ec_false( showlimit(RLIMIT_DATA, "RLIMIT_DATA") )
00071 ec_false( showlimit(RLIMIT_FSIZE, "RLIMIT_FSIZE") )
00072 ec_false( showlimit(RLIMIT_NOFILE, "RLIMIT_NOFILE") )
00073 ec_false( showlimit(RLIMIT_STACK, "RLIMIT_STACK") )
00074 #ifndef BSD_DERIVED
00075 ec_false( showlimit(RLIMIT_AS, "RLIMIT_AS") )
00076 #endif
00077 ec_neg1( getrlimit(RLIMIT_FSIZE, &r) )
00078 r.rlim_cur = 500;
00079 ec_neg1( setrlimit(RLIMIT_FSIZE, &r) )
00080 ec_neg1( fd = open("tmp", O_WRONLY | O_CREAT | O_TRUNC, PERM_FILE) )
00081 ec_neg1( write(fd, buf, sizeof(buf)) )
00082 ec_neg1( write(fd, buf, sizeof(buf)) )
00083 printf("Wrote two buffers! (?)\n");
00084 exit(EXIT_SUCCESS);
00085
00086 EC_CLEANUP_BGN
00087 exit(EXIT_FAILURE);
00088 EC_CLEANUP_END
00089 }
00090