Exemple #1
0
static void
rread(Fcall* f)
{
	ulong	n, rn, nn, delta;
	Dir	d;
	Fid*	fp;

	if (!isfdir(f, &fp))
		return;
	if (f->count == 0)
		goto done;
	cleannames();
	for (n = nn = 0; n < f->count; n += rn){
		rn = convM2D((uchar*)f->data + n, f->count - n, &d, statbuf);
		if (rn <= BIT16SZ)
			break;
		d.name = importname(d.name);
		//dprint("⇒ %D\n", &d);
		nn += convD2M(&d, (uchar*)dirbuf + nn, sizeof(dirbuf) - nn);
	}
	delta = nn - n;
	setaux(fp, getaux(fp) + delta);
	f->count = nn;
	f->data = dirbuf;
done:
	closefid(fp);
}
Exemple #2
0
// Dir read is tricky.
// We have to change the user supplied offset to match the sizes
// seen by the server. Sizes seen by client are greater than those
// seen by server since the change from ' ' to '␣' adds 2 bytes.
static void
tread(Fcall* f)
{
	Fid*	fp;

	fp = nil;
	if (!isfdir(f, &fp))
		return;
	f->count /= 3;	// sizes will grow upon return.
	if (fp == nil)
		sysfatal("can't find fid\n");
	if (f->offset == 0)
		setaux(fp, 0);
	f->offset -= getaux(fp);	// cumulative size delta
	closefid(fp);
}
Exemple #3
0
uint8_t *
sindnt()
{
  int j;                           /* Scratch */
  long i4, k4;                     /* Scratch */
/*
 * In fact look back for a non-blank line
 */
  i4 = ptrpos;                     /* Remember pos'n on entry */
  k4 = 1;                          /* # of lines we are going back */
  if (modify)
    k4 = 2;                        /* To skip over line being modified */
  lstvld = true;                   /* Will be true after we finish */
  do
  {
    if (i4 == k4)
    {
/* At start of file */
      ndntch = 0;                  /* No indent if at s.o.f. */
      prev->bchars = 0;            /* No data in 0th line */
      prev->bcurs = 0;             /* Cursor at line strt */
      *prev->bdata = 0;            /* Null-terminate bdata */
      return prev->bdata;
    }                              /* if (i4 != k4) */
    setaux(i4 - k4);
    rdlin(prev, true);
    k4 = k4 + 1;                   /* In case line empty */
  }
  while (prev->bchars == 0);
  if (INDENT)
  {
/*
 * Set the INDENT - code copied from SCRDIT with CURR -> PREV
 */
    j = prev->bchars;
/* Finish when find non-space */
    for (ndntch = 0; ndntch < j; ndntch++)
      if (!isspace(prev->bdata[ndntch]))
        break;
  }                                /* if (INDENT) */
  return prev->bdata;
}
Exemple #4
0
void
sindnt()
{
  int j;                           /* Scratch */
  long i4, k4;                     /* Scratch */
/*
 * In fact look back for a non-blank line
 */
  i4 = ptrpos;                     /* Remember pos'n on entry */
  k4 = 1;                          /* # of lines we are going back */
  if (modify)
    k4 = 2;                        /* To skip over line being modified */
  lstvld = true;                   /* Will be true after we finish */
p1002:
  if (i4 != k4)
    goto p1001;                    /* J not at s.o.f. */
  ndntch = 0;                      /* No indent if at s.o.f. */
  prev->bchars = 0;                /* No data in 0th line */
  prev->bcurs = 0;                 /* Cursor at line strt */
  return;
p1001:setaux(i4 - k4);
  (void)rdlin(prev, 1);
  k4 = k4 + 1;                     /* In case line empty */
  if (prev->bchars == 0)
    goto p1002;
/* J line was empty */
  if (!INDENT)
    return;                        /* Finished if no indenting */
/*
 * Set the INDENT - code copied from SCRDIT with CURR -> PREV
 */
  j = prev->bchars;
/* Finish when find non-space */
  for (ndntch = 0; ndntch < j; ndntch++)
    if (prev->bdata[ndntch] != SPACE)
      return;
}
Exemple #5
0
int
main(int argc, char *argv[])
{
	int	index;
	struct	sigaction sa;
	int	c;
	char	*p = strrchr(argv[0], '/');

	if (p == NULL)
		p = argv[0];
	else
		p++;

	pname = p;

	(void) setlocale(LC_ALL, "");
#if	!defined(TEXT_DOMAIN)	/* Should be defined by cc -D */
#define	TEXT_DOMAIN "SYS_TEST"	/* Use this only if it weren't */
#endif
	(void) textdomain(TEXT_DOMAIN);

	if (getuid() != 0)
		die(gettext("must be root to run this program\n"));

	/*
	 * Handle normal termination signals that may be received.
	 */
	sa.sa_handler = SIG_IGN;
	sa.sa_flags = 0;
	(void) sigemptyset(&sa.sa_mask);
	(void) sigaction(SIGHUP, &sa, NULL);
	(void) sigaction(SIGINT, &sa, NULL);
	(void) sigaction(SIGQUIT, &sa, NULL);
	(void) sigaction(SIGTERM, &sa, NULL);

	/*
	 * To make sure persistent state gets removed.
	 */
	sa.sa_handler = cleanup_on_exit;
	sa.sa_flags = 0;
	(void) sigemptyset(&sa.sa_mask);
	(void) sigaction(SIGSEGV, &sa, NULL);
	(void) sigaction(SIGILL, &sa, NULL);
	(void) sigaction(SIGABRT, &sa, NULL);
	(void) sigaction(SIGBUS, &sa, NULL);

	if (strcmp(pname, CONSDAEMON) == 0) {
		fallbackdaemon();
		return (E_SUCCESS);
	}

	if (argc == 1)
		display++;
	else {
		while ((c = getopt(argc, argv, "adp")) != EOF)  {
			switch (c) {
			case 'a':
				addflag++;
				break;
			case 'd':
				deleteflag++;
				break;
			case 'p':
				persist++;
				break;
			default:
				(void) fprintf(stderr, gettext(usage));
				exit(E_USAGE);
				/*NOTREACHED*/
			}
		}
	}

	if (display) {
		getconsole();
		return (E_SUCCESS);
	}
	if (addflag && deleteflag) {
		(void) fprintf(stderr, gettext(usage));
		return (E_ERROR);
	}
	if (addflag) {
		if (optind == argc) {
			(void) fprintf(stderr, gettext(usage));
			return (E_ERROR);
		}
		/* separately check every device path specified */
		for (index = optind; index < argc; index++) {
			if (verifyarg(argv[index], addflag))
				return (E_ERROR);
		}

		for (index = optind; index < argc; index++) {
			setaux(argv[index]);
			if (persist)
				addtolist(argv[index]);
		}

		/*
		 * start/restart daemon based on the auxilary
		 * consoles at this time.
		 */
		setfallback(argv);
		return (E_SUCCESS);
	} else if (deleteflag) {
		if (optind == argc) {
			(void) fprintf(stderr, gettext(usage));
			return (E_ERROR);
		}
		/* separately check every device path specified */
		for (index = optind; index < argc; index++) {
			if (verifyarg(argv[index], 0))
				return (E_ERROR);
		}

		for (index = optind; index < argc; index++) {
			unsetaux(argv[index]);
			if (persist && deleteflag)
				removefromlist(argv[index]);
		}

		/*
		 * kill off daemon and restart with
		 * new list of auxiliary consoles
		 */
		setfallback(argv);
		return (E_SUCCESS);
	} else if (persist) {
		if (optind < argc) {
			(void) fprintf(stderr, gettext(usage));
			return (E_ERROR);
		}

		persistlist();
		return (E_SUCCESS);
	} else {
		(void) fprintf(stderr, gettext(usage));
		return (E_ERROR);
	}
} /* main */