along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- $Id: tincd.c,v 1.10.4.60 2002/06/21 10:11:34 guus Exp $
+ $Id: tincd.c,v 1.10.4.61 2002/07/16 13:12:49 guus Exp $
*/
#include "config.h"
#include <signal.h>
#include <string.h>
#include <termios.h>
+#include <sys/mman.h>
#ifdef HAVE_SYS_IOCTL_H
# include <sys/ioctl.h>
/* If nonzero, use null ciphers and skip all key exchanges. */
int bypass_security = 0;
+/* If nonzero, disable swapping for this process. */
+int do_mlock = 0;
+
char *identname; /* program name for syslog */
char *pidfilename; /* pid file location */
char **g_argv; /* a copy of the cmdline arguments */
{ "generate-keys", optional_argument, NULL, 'K'},
{ "debug", optional_argument, NULL, 'd'},
{ "bypass-security", no_argument, &bypass_security, 1 },
+ { "mlock", no_argument, &do_mlock, 1},
{ NULL, 0, NULL, 0 }
};
" -D, --no-detach Don't fork and detach.\n"
" -d, --debug[=LEVEL] Increase debug level or set it to LEVEL.\n"
" -k, --kill[=SIGNAL] Attempt to kill a running tincd and exit.\n"
- " -n, --net=NETNAME Connect to net NETNAME.\n"));
- printf(_(" -K, --generate-keys[=BITS] Generate public/private RSA keypair.\n"
+ " -n, --net=NETNAME Connect to net NETNAME.\n"
+ " -K, --generate-keys[=BITS] Generate public/private RSA keypair.\n"
+ " -L, --mlock Lock tinc into main memory.\n"
" --help Display this help and exit.\n"
" --version Output version information and exit.\n\n"));
printf(_("Report bugs to tinc@nl.linux.org.\n"));
int r;
int option_index = 0;
- while((r = getopt_long(argc, argv, "c:Dd::k::n:K::", long_options, &option_index)) != EOF)
+ while((r = getopt_long(argc, argv, "c:DLd::k::n:K::", long_options, &option_index)) != EOF)
{
switch(r)
{
case 'D': /* no detach */
do_detach = 0;
break;
+ case 'L': /* no detach */
+ do_mlock = 1;
+ break;
case 'd': /* inc debug level */
if(optarg)
debug_lvl = atoi(optarg);
openlog("tinc", LOG_PERROR, LOG_DAEMON); /* Catch all syslog() calls issued before detaching */
#endif
+ /* Lock all pages into memory if requested */
+
+ if(do_mlock)
+ if(mlockall(MCL_CURRENT | MCL_FUTURE)) {
+ syslog(LOG_ERR, _("System call `%s' failed: %s"), "mlockall", strerror(errno));
+ return -1;
+ }
+
g_argv = argv;
make_names();