1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
|
/* GDM - The GNOME Display Manager
* Copyright (C) 2005 Sun Microsystems, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*
* program to either force pages into memory or force them
* out (-o option)
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <unistd.h>
#include <errno.h>
#include <strings.h>
int out = 0;
static int
doout(char *s)
{
int fd;
void *map;
struct stat buf;
if (((fd = open (s, O_RDONLY)) < 0) ||
(fstat (fd, &buf) < 0) ||
((map = mmap (NULL, buf.st_size, PROT_READ, MAP_PRIVATE, fd, 0)) ==
MAP_FAILED)) {
(void)close(fd);
return (-1);
}
(void)close (fd);
(void)msync (map, buf.st_size, MS_INVALIDATE);
(void)munmap (map, buf.st_size);
return (0);
}
#define SIZE 1024*128
static int
doin (char *s)
{
int fd;
char buffer[SIZE];
if ((fd = open(s, O_RDONLY)) < 0) {
fprintf (stderr, "fopen: %s %s\n", strerror (errno), s);
return (-1);
}
while (read (fd, buffer, SIZE) != 0)
;
(void)close (fd);
return (0);
}
int
main (int argc, char *argv[])
{
FILE *fp = 0;
int c, errflg = 0;
extern int optind, optopt;
extern char *optarg;
while ((c = getopt (argc, argv, "o:")) != -1) {
switch (c) {
case 'o':
out = 1;
break;
default:
errflg++;
break;
}
}
if (errflg) {
fprintf (stderr, "usage: %s [-o] filename [filename]\n",
argv[0]);
exit (1);
}
for (; optind < argc; optind++) {
if ((argv[optind][0] == '@') && ((fp = fopen (argv[optind], "r")) == 0)) {
char path[1024];
if ((fp = fopen (&(argv[optind][1]), "r")) == 0) {
fprintf (stderr, "fopen: %s %s\n", strerror (errno), &argv[optind][1]);
continue;
}
while (fgets (path, sizeof (path), fp) != 0) {
path[strlen(path) -1] = '\0';
if (path[0] == '#') {
continue;
}
if (!out) {
doin (path);
} else {
doout (path);
}
}
fclose (fp);
fp = 0;
} else {
if (fp != 0) {
fclose (fp);
fp = 0;
}
if (!out) {
doin (argv[optind]);
} else {
doout (argv[optind]);
}
}
}
exit (0);
}
|