… | |
… | |
31 | #include <sys/types.h> |
31 | #include <sys/types.h> |
32 | #include <sys/stat.h> |
32 | #include <sys/stat.h> |
33 | #include <sys/socket.h> |
33 | #include <sys/socket.h> |
34 | #include <sys/un.h> |
34 | #include <sys/un.h> |
35 | |
35 | |
|
|
36 | #if defined(ENABLE_FRILLS) && defined(_POSIX_MEMLOCK) && _POSIX_MEMLOCK > 0 |
|
|
37 | # define ENABLE_MLOCK 1 |
|
|
38 | #endif |
|
|
39 | |
|
|
40 | #if ENABLE_MLOCK |
|
|
41 | # include <sys/mman.h> |
|
|
42 | #endif |
|
|
43 | |
36 | #include <cerrno> |
44 | #include <cerrno> |
37 | |
45 | |
38 | #include "rxvt.h" |
46 | #include "rxvt.h" |
39 | #include "rxvtdaemon.h" |
47 | #include "rxvtdaemon.h" |
40 | #include "libptytty.h" |
48 | #include "libptytty.h" |
… | |
… | |
215 | else |
223 | else |
216 | return err (); |
224 | return err (); |
217 | } |
225 | } |
218 | |
226 | |
219 | int opt_fork, opt_opendisplay, opt_quiet; |
227 | int opt_fork, opt_opendisplay, opt_quiet; |
|
|
228 | #if ENABLE_MLOCK |
|
|
229 | int opt_lock; |
|
|
230 | #endif |
220 | |
231 | |
221 | int |
232 | int |
222 | main (int argc, const char *const *argv) |
233 | main (int argc, const char *const *argv) |
223 | { |
234 | { |
224 | rxvt_init (); |
235 | rxvt_init (); |
… | |
… | |
229 | opt_fork = 1; |
240 | opt_fork = 1; |
230 | else if (!strcmp (argv [i], "-o") || !strcmp (argv [i], "--opendisplay")) |
241 | else if (!strcmp (argv [i], "-o") || !strcmp (argv [i], "--opendisplay")) |
231 | opt_opendisplay = 1; |
242 | opt_opendisplay = 1; |
232 | else if (!strcmp (argv [i], "-q") || !strcmp (argv [i], "--quiet")) |
243 | else if (!strcmp (argv [i], "-q") || !strcmp (argv [i], "--quiet")) |
233 | opt_quiet = 1; |
244 | opt_quiet = 1; |
|
|
245 | #if ENABLE_MLOCK |
|
|
246 | else if (!strcmp (argv [i], "-m") || !strcmp (argv [i], "--mlock")) |
|
|
247 | opt_lock = 1; |
|
|
248 | #endif |
234 | else |
249 | else |
235 | { |
250 | { |
236 | rxvt_log ("%s: unknown option '%s', aborting.\n", argv [0], argv [i]); |
251 | rxvt_log ("%s: unknown option '%s', aborting.\n", argv [0], argv [i]); |
237 | return EXIT_FAILURE; |
252 | return EXIT_FAILURE; |
238 | } |
253 | } |
… | |
… | |
254 | fflush (stdout); |
269 | fflush (stdout); |
255 | } |
270 | } |
256 | |
271 | |
257 | free (sockname); |
272 | free (sockname); |
258 | |
273 | |
|
|
274 | pid_t pid = 0; |
259 | if (opt_fork) |
275 | if (opt_fork) |
260 | { |
276 | { |
261 | pid_t pid = fork (); |
277 | pid = fork (); |
|
|
278 | } |
262 | |
279 | |
|
|
280 | #if ENABLE_MLOCK |
|
|
281 | // Optionally preform a mlockall so this process does not get swapped out. |
|
|
282 | if (opt_lock && pid == 0) |
|
|
283 | if (mlockall(MCL_CURRENT | MCL_FUTURE) == -1) |
|
|
284 | perror("unable to lock into ram"); |
|
|
285 | #endif |
|
|
286 | |
|
|
287 | if (opt_fork) |
|
|
288 | { |
263 | if (pid < 0) |
289 | if (pid < 0) |
264 | { |
290 | { |
265 | rxvt_log ("unable to fork daemon, aborting.\n"); |
291 | rxvt_log ("unable to fork daemon, aborting.\n"); |
266 | return EXIT_FAILURE; |
292 | return EXIT_FAILURE; |
267 | } |
293 | } |