[PATCH] urxvtd, getopt and mlock
Russell Harmon
russ at eatnumber1.com
Sun Jan 25 10:45:15 CET 2009
I removed the use of getopt_long. Now the patch only renames
--opendisplay to --open-display and adds the --mlock flag when
ENABLE_FRILLS is defined.
> Great to hear that the mlockall bug has been fixed, although I definitely
> see the bug with debians glibc-2.7 (I reported that bug against glibc-2.7
> in april of last year), so this is definitely worth considering.
According to https://bugzilla.redhat.com/show_bug.cgi?id=405781, the
bug was fixed and backported all the way to glibc-2.5.20. You may not
be running the latest bugfix release of glibc-2.7.
>> I renamed --opendisplay to --open-display (opendisplay is improper english).
>
> And so is --open-display... it's a technical term.
However --open-display is at least two real words. And in a technical
context, it is more correct than --opendisplay
--Russell Harmon
diff --git a/doc/rxvtd.1.pod b/doc/rxvtd.1.pod
index 60c54d3..7c91939 100644
--- a/doc/rxvtd.1.pod
+++ b/doc/rxvtd.1.pod
@@ -4,7 +4,7 @@
=head1 SYNOPSIS
-B<@@RXVT_NAME@@d> [-q|--quiet] [-o|--opendisplay] [-f|--fork]
+B<@@RXVT_NAME@@d> [-q|--quiet] [-o|--opendisplay] [-f|--fork] [-m|--mlock]
B<@@RXVT_NAME@@d> -q -o -f # for .xsession use
@@ -40,7 +40,7 @@ Normally, B<@@RXVT_NAME@@d> outputs the message C<<
rxvt-unicode daemon
listening on <path> >> after binding to its control socket. This option
will suppress this message (errors and warnings will still be logged).
-=item B<-o>, B<--opendisplay>
+=item B<-o>, B<--open-display>
This forces B<@@RXVT_NAME@@d> to open a connection to the current
C<$DISPLAY> and keep it open.
@@ -54,6 +54,15 @@ B<@@RXVT_NAME@@d> will be killed automatically.
This makes B<@@RXVT_NAME@@d> fork after it has bound itself to its control
socket.
+=item B<-m>, B<--mlock>
+
+This makes B<@@RXVT_NAME@@d> call mlockall(2) on itself. This locks
+B<@@RXVT_NAME@@d> in RAM and prevents it from being swapped out to disk.
+
+Note: In order to use this feature, your system administrator must have set
+your user's RLIMIT_MEMLOCK to a size greater than or equal to the size of the
+B<@@RXVT_NAME@@d> binary (or to unlimited). See /etc/security/limits.conf
+
=back
=head1 EXAMPLES
diff --git a/src/rxvtd.C b/src/rxvtd.C
index 5642827..6dbd402 100644
--- a/src/rxvtd.C
+++ b/src/rxvtd.C
@@ -33,6 +33,14 @@
#include <sys/socket.h>
#include <sys/un.h>
+#if ! ( ( defined(__GLIBC__) && defined(__GLIBC_MINOR__) ) && (
__GLIBC__ > 2 || ( __GLIBC__ == 2 && __GLIBC_MINOR__ >= 5 ) ) )
+#define ENABLE_MLOCK
+#endif
+
+#ifdef ENABLE_MLOCK
+#include <sys/mman.h>
+#endif
+
#include <cerrno>
#include "rxvt.h"
@@ -217,6 +225,9 @@ void server::read_cb (ev::io &w, int revents)
}
int opt_fork, opt_opendisplay, opt_quiet;
+#ifdef ENABLE_MLOCK
+int opt_lock;
+#endif
int
main (int argc, const char *const *argv)
@@ -227,10 +238,15 @@ main (int argc, const char *const *argv)
{
if (!strcmp (argv [i], "-f") || !strcmp (argv [i], "--fork"))
opt_fork = 1;
- else if (!strcmp (argv [i], "-o") || !strcmp (argv [i], "--opendisplay"))
+ else if (!strcmp (argv [i], "-o") || !strcmp (argv [i], "--opendisplay")
+ || !strcmp (argv [i], "--open-display"))
opt_opendisplay = 1;
else if (!strcmp (argv [i], "-q") || !strcmp (argv [i], "--quiet"))
opt_quiet = 1;
+#ifdef ENABLE_MLOCK
+ else if (!strcmp (argv [i], "-m") || !strcmp (argv [i], "--mlock"))
+ opt_lock = 1;
+#endif
else
{
rxvt_log ("%s: unknown option '%s', aborting.\n", argv [0],
argv [i]);
@@ -256,10 +272,21 @@ main (int argc, const char *const *argv)
free (sockname);
+ pid_t pid = 0;
if (opt_fork)
{
- pid_t pid = fork ();
+ pid = fork ();
+ }
+#ifdef ENABLE_MLOCK
+ // Optionally preform a mlockall so this process does not get swapped out.
+ if (opt_lock && pid == 0)
+ if (mlockall(MCL_CURRENT | MCL_FUTURE) == -1)
+ perror("unable to lock into ram");
+#endif
+
+ if (opt_fork)
+ {
if (pid < 0)
{
rxvt_log ("unable to fork daemon, aborting.\n");
-------------- next part --------------
A non-text attachment was scrubbed...
Name: rxvt-unicode_mlock.patch
Type: application/octet-stream
Size: 3243 bytes
Desc: not available
URL: <http://lists.schmorp.de/pipermail/rxvt-unicode/attachments/20090125/77b162d8/attachment.obj>
More information about the rxvt-unicode
mailing list