15 #include <sys/param.h>
20 static char *default_tmpdir =
"/tmp";
26 static char *tempdir =
NULL;
28 static void __init find_tempdir(
void)
30 const char *dirs[] = {
"TMP",
"TEMP",
"TMPDIR",
NULL };
37 for (i = 0; dirs[
i]; i++) {
38 dir = getenv(dirs[i]);
39 if ((dir !=
NULL) && (*dir !=
'\0'))
42 if ((dir ==
NULL) || (*dir ==
'\0'))
46 if (tempdir ==
NULL) {
47 fprintf(stderr,
"Failed to malloc tempdir, "
48 "errno = %d\n", errno);
68 n =
read(fd, buf, size - 1);
85 n =
read(fd, &buf[len], size - len - 1);
94 static int checked_tmpdir = 0;
107 static void which_tmpdir(
void)
110 char buf[128] = {
'\0' };
117 printf(
"Checking for tmpfs mount on /dev/shm...");
121 printf(
"failed to open /proc/mounts, errno = %d\n", errno);
140 printf(
"nothing mounted on /dev/shm\n");
142 printf(
"read returned errno %d\n", -found);
160 default_tmpdir =
"/dev/shm";
164 static int __init make_tempfile(
const char *
template,
char **out_tempname,
172 if (tempname ==
NULL)
179 if (
template[0] !=
'/')
180 strcpy(tempname, tempdir);
184 fd = mkstemp(tempname);
186 fprintf(stderr,
"open - cannot create %s: %s\n", tempname,
190 if (do_unlink && (unlink(tempname) < 0)) {
195 *out_tempname = tempname;
206 #define TEMPNAME_TEMPLATE "vm_file-XXXXXX"
208 static int __init create_tmp_file(
unsigned long long len)
217 err = fchmod(fd, 0777);
227 if (lseek64(fd, len - 1,
SEEK_SET) < 0) {
234 err =
write(fd, &zero, 1);
247 fd = create_tmp_file(len);
252 perror(
"exec_close");
261 int err, fd = create_tmp_file(UM_KERN_PAGE_SIZE);
263 addr = mmap(
NULL, UM_KERN_PAGE_SIZE,
265 printf(
"Checking PROT_EXEC mmap in %s...",tempdir);
267 if (addr == MAP_FAILED) {
272 printf(
"%s must be not mounted noexec\n",tempdir);
276 munmap(addr, UM_KERN_PAGE_SIZE);