… | |
… | |
100 | fcntl (fd, F_SETFL, O_NONBLOCK); |
100 | fcntl (fd, F_SETFL, O_NONBLOCK); |
101 | |
101 | |
102 | sa.sun_family = AF_UNIX; |
102 | sa.sun_family = AF_UNIX; |
103 | strcpy (sa.sun_path, sockname); |
103 | strcpy (sa.sun_path, sockname); |
104 | |
104 | |
105 | unlink (rxvt_connection::unix_sockname ()); |
105 | unlink (sockname); |
106 | |
106 | |
107 | mode_t omask = umask (0077); |
107 | mode_t omask = umask (0077); |
108 | |
108 | |
109 | if (bind (fd, (sockaddr *)&sa, sizeof (sa))) |
109 | if (bind (fd, (sockaddr *)&sa, sizeof (sa))) |
110 | { |
110 | { |
… | |
… | |
222 | } |
222 | } |
223 | else |
223 | else |
224 | return err (); |
224 | return err (); |
225 | } |
225 | } |
226 | |
226 | |
227 | int opt_fork, opt_opendisplay, opt_quiet; |
|
|
228 | #if ENABLE_MLOCK |
|
|
229 | int opt_lock; |
|
|
230 | #endif |
|
|
231 | |
|
|
232 | int |
227 | int |
233 | main (int argc, const char *const *argv) |
228 | main (int argc, const char *const *argv) |
234 | { |
229 | { |
235 | rxvt_init (); |
230 | ptytty::init (); |
|
|
231 | |
|
|
232 | static char opt_fork, opt_opendisplay, opt_quiet; |
|
|
233 | #if ENABLE_MLOCK |
|
|
234 | static char opt_lock; |
|
|
235 | #endif |
236 | |
236 | |
237 | for (int i = 1; i < argc; i++) |
237 | for (int i = 1; i < argc; i++) |
238 | { |
238 | { |
239 | if (!strcmp (argv [i], "-f") || !strcmp (argv [i], "--fork")) |
239 | if (!strcmp (argv [i], "-f") || !strcmp (argv [i], "--fork")) |
240 | opt_fork = 1; |
240 | opt_fork = 1; |
… | |
… | |
251 | 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]); |
252 | return EXIT_FAILURE; |
252 | return EXIT_FAILURE; |
253 | } |
253 | } |
254 | } |
254 | } |
255 | |
255 | |
|
|
256 | rxvt_init (); |
|
|
257 | |
256 | // optionally open display and never release it. |
258 | // optionally open display and never release it. |
257 | if (opt_opendisplay) |
259 | if (opt_opendisplay) |
258 | if (const char *dpy = getenv ("DISPLAY")) |
260 | if (const char *dpy = getenv ("DISPLAY")) |
259 | displays.get (dpy ? dpy : ":0"); // move string logic into rxvt_display maybe? |
261 | displays.get (dpy ? dpy : ":0"); // move string logic into rxvt_display maybe? |
260 | |
262 | |
… | |
… | |
276 | { |
278 | { |
277 | pid = fork (); |
279 | pid = fork (); |
278 | } |
280 | } |
279 | |
281 | |
280 | #if ENABLE_MLOCK |
282 | #if ENABLE_MLOCK |
281 | // Optionally preform a mlockall so this process does not get swapped out. |
283 | // Optionally perform an mlockall so this process does not get swapped out. |
282 | if (opt_lock && pid == 0) |
284 | if (opt_lock && !pid) |
283 | if (mlockall(MCL_CURRENT | MCL_FUTURE) == -1) |
285 | if (mlockall (MCL_CURRENT | MCL_FUTURE) < 0) |
284 | perror("unable to lock into ram"); |
286 | perror ("unable to lock into ram"); |
285 | #endif |
287 | #endif |
286 | |
288 | |
287 | if (opt_fork) |
289 | if (opt_fork) |
288 | { |
290 | { |
289 | if (pid < 0) |
291 | if (pid < 0) |
… | |
… | |
292 | return EXIT_FAILURE; |
294 | return EXIT_FAILURE; |
293 | } |
295 | } |
294 | else if (pid > 0) |
296 | else if (pid > 0) |
295 | _exit (EXIT_SUCCESS); |
297 | _exit (EXIT_SUCCESS); |
296 | |
298 | |
297 | ev_default_fork (); |
299 | ev_loop_fork (EV_DEFAULT_UC); |
298 | } |
300 | } |
299 | |
301 | |
300 | ev_loop (0); |
302 | ev_run (); |
301 | |
303 | |
302 | return EXIT_SUCCESS; |
304 | return EXIT_SUCCESS; |
303 | } |
305 | } |
304 | |
306 | |