示例#1
0
int
main (int argc, char *argv[])
{
  ptytty::init ();

  static char opt_fork, opt_opendisplay, opt_quiet;
#if ENABLE_PERL
  static char *opt_eval;
#endif
#if ENABLE_MLOCK
  static char opt_lock;
#endif

  for (int i = 1; i < argc; i++)
    {
      if (!strcmp (argv [i], "-f") || !strcmp (argv [i], "--fork"))
        opt_fork = 1;
      else if (!strcmp (argv [i], "-o") || !strcmp (argv [i], "--opendisplay"))
        opt_opendisplay = 1;
      else if (!strcmp (argv [i], "-q") || !strcmp (argv [i], "--quiet"))
        opt_quiet = 1;
#if ENABLE_MLOCK
      else if (!strcmp (argv [i], "-m") || !strcmp (argv [i], "--mlock"))
        opt_lock = 1;
#endif
#if ENABLE_PERL
      else if (!strcmp (argv [i], "-e") || !strcmp (argv [i], "--eval"))
        opt_eval = argv [++i];
#endif
      else
        {
          rxvt_log ("%s: unknown option '%s', aborting.\n", argv [0], argv [i]);
          return EXIT_FAILURE;
        }
    }

  rxvt_init ();

#if ENABLE_PERL
  if (opt_eval)
    {
      rxvt_perl.init ();
      rxvt_perl.eval (opt_eval);
    }
#endif

  // optionally open display and never release it.
  if (opt_opendisplay)
    if (const char *dpy = getenv ("DISPLAY"))
      displays.get (dpy ? dpy : ":0"); // move string logic into rxvt_display maybe?

  char *sockname = rxvt_connection::unix_sockname ();
  unix_listener l (sockname);

  chdir ("/");

  if (!opt_quiet)
    {
      printf ("rxvt-unicode daemon listening on %s.\n", sockname);
      fflush (stdout);
    }

  free (sockname);

  pid_t pid = 0;
  if (opt_fork)
    {
      pid = fork ();
    }

#if ENABLE_MLOCK
  // Optionally perform an mlockall so this process does not get swapped out.
  if (opt_lock && !pid)
    if (mlockall (MCL_CURRENT | MCL_FUTURE) < 0)
      perror ("unable to lock into ram");
#endif

  if (opt_fork)
    {
      if (pid < 0)
        {
          rxvt_log ("unable to fork daemon, aborting.\n");
          return EXIT_FAILURE;
        }
      else if (pid > 0)
        _exit (EXIT_SUCCESS);

      ev_loop_fork (EV_DEFAULT_UC);
    }

  ev_run ();

  return EXIT_SUCCESS;
}
示例#2
0
/*----------------------------------------------------------------------*/
void
rxvt_term::rxvt_usage (int type)
{
  unsigned int i, col;

  rxvt_log ("%s%s%s", releasestring, optionsstring, RESNAME);

  switch (type)
    {
      case 0:			/* brief listing */
        rxvt_log (" [-help] [--help]\n");

        for (col = 1, i = 0; i < ecb_array_length (optList); i++)
          if (optList[i].desc != NULL)
            {
              int len = 0;

              if (optList[i].arg)
                len = strlen (optList[i].arg) + 1;

              assert (optList[i].opt != NULL);
              len += 4 + strlen (optList[i].opt) + (optList_isBool (i) ? 2 : 0);
              col += len;

              if (col > 79)
                {
                  /* assume regular width */
                  rxvt_log ("\n");
                  col = 1 + len;
                }

              rxvt_log (" [-%s%s", (optList_isBool (i) ? "/+" : ""), optList[i].opt);

              if (optList[i].arg)
                rxvt_log (" %s]", optList[i].arg);
              else
                rxvt_log ("]");
            }
        break;

      case 1:			/* full command-line listing */
        rxvt_log (" [options] [-e command args]\n\nwhere options include:\n");

        for (i = 0; i < ecb_array_length (optList); i++)
          if (optList[i].desc != NULL)
            {
              assert (optList[i].opt != NULL);
              rxvt_log ("  %s%s %-*s%s%s\n",
                         (optList_isBool (i) ? "-/+" : "-"), optList[i].opt,
                         (INDENT - strlen (optList[i].opt)
                          + (optList_isBool (i) ? 0 : 2)),
                         (optList[i].arg ? optList[i].arg : ""),
                         (optList_isBool (i) ? "turn on/off " : ""),
                         optList[i].desc);
            }

#if ENABLE_PERL
        rxvt_perl.init (this);
        rxvt_perl.usage (this, 1);
#endif

        rxvt_log ("\n  --help to list long-options");
        break;

      case 2:			/* full resource listing */
        rxvt_log (" [options] [-e command args]\n\n"
                   "where resources (long-options) include:\n");

        for (i = 0; i < ecb_array_length (optList); i++)
          if (optList[i].kw != NULL)
            rxvt_log ("  %s: %*s%s\n",
                    optList[i].kw,
                    (INDENT + 2 - strlen (optList[i].kw)), "", /* XXX */
                    (optList_isBool (i) ? "boolean" : optList[i].arg));

#if ENABLE_PERL
        rxvt_perl.init (this);
        rxvt_perl.usage (this, 2);
#endif

        rxvt_log ("\n  -help to list options");
        break;
    }

  rxvt_log ("\n\n");
  rxvt_exit_failure ();
}