Ejemplo n.º 1
0
int
main (int argc, char **argv)
{
  setprogname (argv[0]);

  if (!isunixsocket (0))
    fatal << "stdin must be a unix domain socket\n";
  if (argc < 2)
    fatal << "usage: " << progname << " command [arg1 arg2 ... ]\n";

  char **cmdargv = argv + 1;
  str path = find_program_plus_libsfs (cmdargv[0]);
  if (!path)
    fatal << "Could not locate program: " << cmdargv[0] << "\n";

  make_sync (0);

  char buf[1024];
  int fd;
  while (readfd (0, buf, 1024, &fd) > 0)
    if (fd >= 0) {
      aspawn (path, cmdargv, fd, fd, errfd);
      close (fd);
    }
  
  return 0;
}
Ejemplo n.º 2
0
void
_err_output_async (suio *uio, int flags)
{
  int saved_errno = errno;
  
  if (flags & warnobj::panicflag) {
    erruio->copyu (uio);
    make_sync (errfd);
    erruio->output (errfd);
    myabort ();
  }

  /* Start new iovecs after newlines so as to output entire lines when
   * possible. */
  if (erruio->resid ()) {
    const iovec *iovp = erruio->iov () + erruio->iovcnt () - 1;
    if (((char *) iovp->iov_base)[iovp->iov_len - 1] == '\n')
      erruio->breakiov ();
  }
  erruio->copyu (uio);

  if (flags & warnobj::fatalflag) {
    err_flush ();
    exit (1);
  }

  err_wcb ();
  errno = saved_errno;
}
Ejemplo n.º 3
0
void
err_flush ()
{
  if (_err_output != _err_output_async)
    return;
  make_sync (errfd);
  erruio->output (errfd);
}
Ejemplo n.º 4
0
static void
sfskey_version ()
{
  strbuf msg;
  msg << "sfskey -- SFS version " << VERSION << "\n";
  make_sync (1);
  msg.tosuio ()->output (1);
  exit (0);
}
void
resolv_conf::reload_dumpres (int fd)
{
  make_sync (fd);
  bzero (&_res, sizeof (_res));
  res_init ();
  write (fd, &_res, sizeof (_res));
  _exit (0);
}
Ejemplo n.º 6
0
void
sfskey_help (int argc, char **argv)
{
  strbuf msg;
  msg << "usage: " << progname << " [-S sock] [-p pwfd] command [args]\n";
  for (const modevec *mp = modes; mp->name; mp++)
    if (mp->usage)
      msg << "	 " << progname << " " << mp->usage << "\n";
  make_sync (1);
  msg.tosuio ()->output (1);
  exit (0);
}
Ejemplo n.º 7
0
Archivo: aios.C Proyecto: bougyman/sfs
int
aios::flush ()
{
  ptr<aios> hold;
  if (fd >= 0 && outb.tosuio ()->resid ()) {
    hold = mkref (this);	// Don't let this be freed under us
    make_sync (fd);
    output ();
    _make_async (fd);
  }
  return err;
}
Ejemplo n.º 8
0
Archivo: aios.C Proyecto: bougyman/sfs
void
aios::finalize ()
{
  if (globaldestruction)
    make_sync (fd);
  if (!outb.tosuio ()->resid () || fd < 0)
    delete this;
  else if (err) {
    // Make one last effort to flush buffer
    if (err == ETIMEDOUT)
      outb.tosuio ()->output (fd);
    delete this;
  }
  else if (outb.tosuio ()->output (fd) < 0)
    delete this;
}
Ejemplo n.º 9
0
static void
err_wcb ()
{
  int n;
  int cnt;

  if (!erruio->resid () || _err_output != _err_output_async) {
    fdcb (errfd, selwrite, NULL);
    return;
  }

  /* Try to write whole lines at a time. */
  for (cnt = min (erruio->iovcnt (), (size_t) UIO_MAXIOV);
       cnt > 0 && (erruio->iov ()[cnt-1].iov_len == 0
		   || *((char *) erruio->iov ()[cnt-1].iov_base
			+ erruio->iov ()[cnt-1].iov_len - 1) != '\n');
       cnt--)
    ;
  if (!cnt) {
    if (erruio->iovcnt () < UIO_MAXIOV) {
      /* Wait for a carriage return */
      fdcb (errfd, selwrite, NULL);
      return;
    }
    else
      cnt = -1;
  }

  /* Write asynchronously, but keep stderr synchronous in case of
   * emergency (e.g. maybe assert wants to fprintf to stderr). */
  if (globaldestruction)
    n = erruio->output (errfd, cnt);
  else {
    _make_async (errfd);
    n = erruio->output (errfd, cnt);
    make_sync (errfd);
  }

  if (n < 0)
    err_reset ();

  if (erruio->resid () && !globaldestruction)
    fdcb (errfd, selwrite, wrap (err_wcb)); 
  else
    fdcb (errfd, selwrite, NULL);
}
Ejemplo n.º 10
0
void
axprt_dgram::poll ()
{
  assert (cb);

  make_sync (fd);

  socklen_t ss = socksize;
  bzero (sabuf, ss);
  ssize_t ps = recvfrom (fd, pktbuf, pktsize, 0, sabuf, &ss);

  make_async (fd);

  if (ps < 0) {
    if (errno != EAGAIN && connected)
      (*cb) (NULL, -1, NULL);
    return;
  }
  (*cb) (pktbuf, ps, sabuf);
}
Ejemplo n.º 11
0
void demo_manager::do_inputs()
{
  switch (state)
  {
    case RECORDING :
    {
      base->packet.packet_reset();       // reset input buffer
      view *p=player_list;               // get current inputs
      for (; p; p=p->next)
        if (p->local_player())
          p->get_input();

      base->packet.write_uint8(SCMD_SYNC);
      base->packet.write_uint16(make_sync());
      demo_man.save_packet(base->packet.packet_data(),base->packet.packet_size());
      process_packet_commands(base->packet.packet_data(),base->packet.packet_size());

    } break;
    case PLAYING :
    {
      uint8_t buf[1500];
      int size;
      if (get_packet(buf,size))              // get starting inputs
      {
        process_packet_commands(buf, size);
        ivec2 mouse = the_game->GameToMouse(ivec2(player_list->pointer_x,
                                                  player_list->pointer_y),
                                            player_list);
        wm->SetMousePos((small_render ? 2 : 1) * mouse);
      }
      else
      {
    set_state(NORMAL);
    return ;
      }
    } break;
    default :
      break;
  }
}
Ejemplo n.º 12
0
Archivo: aiod.C Proyecto: bougyman/sfs
 aiosrv (int f, ref<shmbuf> b) : fd (f), buf (b) { make_sync (fd); }
Ejemplo n.º 13
0
int
main (int argc, char **argv)
{
#ifdef MAINTAINER
  if (getenv ("SFS_RUNINPLACE")) {
    setgid (getgid ());
    setuid (getuid ());
  }
#endif /* MAINTAINER */
  setprogname (argv[0]);
  sfsconst_init ();

  const uid_t procuid = getuid ();
  uid_t newuid = procuid;
  uid_t uid = myaid () & INT64 (0xffffffff);
  gid_t gid;
  bool opt_gid = false;
  bool opt_login = false;
  bool opt_nogid = false;
  bool opt_U = false;
  str opt_chdir;
  size_t num_u = 0;

  int ch;
  while ((ch = getopt (argc, argv, "lu:U:g:GC:")) != -1)
    switch (ch) {
    case 'l':
      opt_login = true;
      break;
    case 'u':
      if (num_u++ || !convertint (optarg, &uid))
	usage ();
      break;
    case 'U':
      if (num_u++ || !convertint (optarg, &newuid))
	usage ();
      uid = newuid;
      opt_U = true;
      break;
    case 'g':
      if (opt_nogid || !convertint (optarg, &gid))
	usage ();
      opt_gid = true;
      break;
    case 'G':
      if (opt_gid)
	usage ();
      opt_nogid = true;
    case 'C':
      if (opt_chdir)
	usage ();
      opt_chdir = optarg;
      break;
    default:
      usage ();
    }
  argc -= optind;
  argv += optind;

  if (procuid && (newuid != procuid || uid != procuid))
    fatal ("only root can change uids.\n");

  if (!opt_gid && !opt_nogid)
    opt_gid = gid_alloc (&gid, uid);

  fixgroups (newuid != uid, uid, opt_gid, gid);
  if (opt_U)
    sfs_setlogin (newuid);
  if (setgid (getgid ()) < 0 || setuid (newuid) < 0)
    fatal ("setuid/setgid: %m\n");

  vec<char *> av;
  char *path = argc > 0 ? argv[0] : getenv ("SHELL");
  if (!path)
    fatal ("no SHELL environment variable\n");
  av.push_back (path);
  for (int i = 1; i < argc; i++)
    av.push_back (argv[i]);
  av.push_back (NULL);

  str av0;
  if (opt_login) {
    const char *p = strrchr (path, '/');
    p = p ? p + 1 : path;
    av0 = strbuf ("-%s", p);
    av[0] = const_cast<char *> (av0.cstr ());
  }

  if (opt_chdir) {
    if (chdir (opt_chdir) < 0)
      warn << opt_chdir << ": " << strerror (errno) << "\n";
    else if (opt_chdir[0] == '/') {
      str e (strbuf ("PWD=%s", opt_chdir.cstr ()));
      xputenv (e);
    }
    else if (const char *p = getenv ("PWD")) {
      str e (strbuf ("PWD=%s/%s", p, opt_chdir.cstr ()));
      xputenv (e);
    }
  }

  str aidvar (strbuf ("SFS_AID=") << myaid ());
  xputenv (aidvar);

  /* The SFS libraries use asynchronous IO which some programs don't
   * like.  Thus, we remove the O_NONBLOCK flag from stdin/stdout. */
  make_sync (0);
  make_sync (1);

  execvp (path, av.base ());
  warnx ("%s: %m\n", path);
  return 1;
}
Ejemplo n.º 14
0
int
main (int argc, char **argv)
{
  pid_t child;
  int an;
  vec<const char *> av;
  char *fname = NULL;
  char *basename;
  enum { BAD, HEADER, CFILE, PYTHON, PYL, PYH, PYS } mode = BAD;
  void (*fn) (str) = NULL;
  int len;

  av.push_back (PATH_CPP);
  av.push_back ("-DRPCC");
  av.push_back (NULL);

  for (an = 1; an < argc; an++) {
    char *arg = argv[an];
    int arglen = strlen (arg);

    if (arg[0] == '-' && (arg[1] == 'D' || arg[1] == 'I'))
      av.push_back (arg);
    else if (!fname && arglen > 2 && arg[0] != '-'
	     && arg[arglen-1] == 'x' && arg[arglen-2] == '.')
      fname = arg;
    else if (!strcmp (arg, "-h") && mode == BAD)
      mode = HEADER;
    else if (!strcmp (arg, "-c") && mode == BAD)
      mode = CFILE;
    else if (!strcmp (arg, "-python") && mode == BAD)
      mode = PYTHON;
    else if (!strcmp (arg, "-pyl") && mode == BAD)
      mode = PYL;
    else if (!strcmp (arg, "-pyh") && mode == BAD)
      mode = PYH;
    else if (!strcmp (arg, "-pys") && mode == BAD)
      mode = PYS;
    else if (!strcmp (arg, "-o") && !outfile && ++an < argc)
      outfile = argv[an];
    else if (!strncmp (arg, "-o", 2) && !outfile && arg[2])
      outfile = arg + 2;
    else if (!strcmp (arg, "-P") && !idprefix && ++an < argc)
      idprefix = argv[an];
    else if (!strncmp (arg, "-P", 2) && !idprefix && arg[2])
      idprefix = arg + 2;
    else if (!strcmp (arg, "-n") &&  !python_module_name && ++an < argc)
      python_module_name = argv[an];
    else if (!strncmp (arg, "-n", 2) && !python_module_name && arg[2])
      python_module_name = arg + 2;
    else 
      usage ();
  }
  if (python_module_name && !(mode == PYL || mode == PYS)) {
    warn << "-n parameter only valid with -pyl or -pys\n";
    usage ();
  }
  if (!fname)
    usage ();

  if (idprefix)
    idprefix = idprefix << "_";

  av.push_back (fname);
  av.push_back (NULL);

  if ((basename = strrchr (fname, '/')))
    basename++;
  else
    basename = fname;
  len = strlen (basename);

  switch (mode) {
  case HEADER:
    av[2] = "-DRPCC_H";
    fn = genheader;
    if (!outfile)
      outfile = strbuf ("%.*sh", len - 1, basename);
    break;
  case CFILE:
    av[2] = "-DRPCC_C";
    fn = gencfile;
    if (!outfile)
      outfile = strbuf ("%.*sC", len - 1, basename);
    break;
  case PYTHON:
    av[2] = "-DRPCC_P";
    fn = genpython;
    if (!outfile)
      outfile = strbuf ("%.*spy", len - 1, basename);
     break;
  case PYL:
    av[2] = "-DRPCC_PYL";
    fn = genpyc_lib;
    // foo.x -> foo_lib.C
    if (!outfile)
      outfile = strbuf ("%.*s_lib.C", len - 2, basename);
    break;
  case PYH:
    av[2] = "-DRPCC_PYH";
    fn = genpyh;
    if (!outfile)
      outfile = strbuf ("%.*sh", len -1, basename);
    break;
  case PYS:
    av[2] = "-DRPCC_PYS";
    fn = genpyc_so;
    // foo.x -> foo_so.C
    if (!outfile)
      outfile = strbuf ("%.*s_so.C", len -2, basename);
    break;
  default:
    usage ();
    break;
  }

  child = runcpp (av.base ());

  if (outfile != "-") {
    if (outfile[0] != '|')
      atexit (cleanup);
    setstdout ();
  }

  make_sync (0);
  yyparse ();
  checkliterals ();
  if (outfile != "-" && outfile[0] != '|')
    fn (outfile);
  else
    fn (fname);
#if 0
  chldcb (child, wrap (reapcpp));
  amain ();
#else
  int status;
  if (waitpid (child, &status, 0) < 0)
    fatal ("waitpid: %m\n");
  reapcpp (status);
#endif
  return 0;
}