Esempio n. 1
0
int
main(
	int	argc,
	char	**argv)
{
	int	c, i, done = 0;
	char	*input;
	char	**v;

	pushfile(stdin);
	init(argc, argv);

	for (i = 0; !done && i < ncmdline; i++) {
		v = breakline(cmdline[i], &c);
		if (c)
			done = command(c, v);
		xfree(v);
	}
	if (cmdline) {
		xfree(cmdline);
		return exitcode;
	}

	while (!done) {
		if ((input = fetchline()) == NULL)
			break;
		v = breakline(input, &c);
		if (c)
			done = command(c, v);
		doneline(input, v);
	}
	return exitcode;
}
Esempio n. 2
0
/***
Create a Lua file object from a file descriptor.
@function fdopen
@tparam int fd file descriptor
@tparam string mode the mode in which to open the file descriptor
@treturn[1] file file Lua file object *fd*, if successful
@return[2] nil
@treturn[2] string error message
@treturn[2] int errnum
@usage
local fdopen = require "posix.stdio".fdopen
local STDOUT_FILENO = require "posix.unistd".STDOUT_FILENO
stdout = fdopen (STDOUT_FILENO, "w")
*/
static int
Pfdopen(lua_State *L)	/** fdopen(fd, mode) */
{
	int fd = checkint(L, 1);
	const char *mode = luaL_checkstring(L, 2);
	checknargs(L, 2);
	if (!pushfile(L, fd, mode))
		return pusherror(L, "fdopen");
	return 1;
}
Esempio n. 3
0
void
setinputstring(char *string)
{
	INTOFF;
	pushfile();
	parsefile->nextc = string;
	parsefile->nleft = strlen(string);
	parsefile->buf = NULL;
	plinno = 1;
	INTON;
}
Esempio n. 4
0
void
setinputstring(char *string, int push)
{
	INTOFF;
	if (push)
		pushfile();
	parsenextc = string;
	parselleft = parsenleft = strlen(string);
	parsefile->buf = NULL;
	plinno = 1;
	INTON;
}
Esempio n. 5
0
static void
setinputfd(int fd, int push)
{
	if (push) {
		pushfile();
		parsefile->buf = 0;
	}
	parsefile->fd = fd;
	if (parsefile->buf == NULL)
		parsefile->buf = ckmalloc(IBUFSIZ);
	parsefile->lleft = parsefile->nleft = 0;
	plinno = 1;
}
Esempio n. 6
0
/* ARGSUSED */
static int
source_f(
	int	argc,
	char	**argv)
{
	FILE	*f;

	f = fopen(argv[1], "r");
	if (f == NULL)
		dbprintf("can't open %s\n", argv[0]);
	else
		pushfile(f);
	return 0;
}
Esempio n. 7
0
void
loadmodule(char *s)
{
	interactive = 0;
	if(setjmp(err)) {
		unwind();
		return;
	}
	pushfile(s);
	silent = 0;
	yyparse();
	popio();
	return;
}
Esempio n. 8
0
void
setinputfd(int fd, int push)
{
	(void)fcntl(fd, F_SETFD, FD_CLOEXEC);
	if (push) {
		pushfile();
		parsefile->buf = ckmalloc(BUFSIZ + 1);
	}
	if (parsefile->fd > 0)
		close(parsefile->fd);
	parsefile->fd = fd;
	if (parsefile->buf == NULL)
		parsefile->buf = ckmalloc(BUFSIZ + 1);
	parselleft = parsenleft = 0;
	plinno = 1;
}
bool upload(char *param, void *conf)
{
    clientConfig *c=(clientConfig*)conf;
    if (!isDir(param))
    {
        sendCommand(CMD_SEND, (char *)param, &(c->sock));
        return pushfile(param, &(c->sock));
    }
    else
    {
        printf("* parameter %s is a directory, sending recursively\n",param);
        senddir(param,&(c->sock));
    }

    return true;
}
Esempio n. 10
0
bool senddir(const char *dir, unsigned int *sock)
{
    struct dirent *pdir;
    struct stat st;
    DIR *d=opendir(dir);
    char *path=(char *)my_malloc(sizeof(char)*256);
    char *buffer=(char *)my_malloc(sizeof(char)*256);


    if (!path)
        return false;

    while((pdir=readdir(d))!=NULL)
    {
        if (strcmp(pdir->d_name,".") == 0)
            continue;
        if (strcmp(pdir->d_name,"..") == 0)
            continue;

        strcpy(path, dir);
        addSlash(path);
        strcat(path, pdir->d_name);
        if (!(lstat(path, &st)>=0))
            continue;
        if (st.st_mode&S_IFREG)
        {
            sendCommand(CMD_SEND,(char *)path, sock);
            pushfile(path, sock);
        }
        else if (st.st_mode&S_IFDIR)
            senddir(path, sock);
    }

    free(buffer);
    free(path);
    return true;
}
Esempio n. 11
0
void
parseopts(int argc, char **argv)
{
	int c;

	/* initialize default option values */
	psc_dynarray_init(&opts.exclude);
	psc_dynarray_init(&opts.files);
	psc_dynarray_init(&opts.filter);
	psc_dynarray_init(&opts.include);
	opts.progress = 1;
	opts.psync_path = "psync";
	opts.rsh = "ssh "
	    "-oControlPath=none "
	    "-oCompression=no "
	    "-oKbdInteractiveAuthentication=no "
	    "-oNumberOfPasswordPrompts=1";
	opts.streams = getnstreams(getnprocessors());

	while ((c = getopt_long(argc, argv,
	    "0468aB:bCcDdEEe:f:gHhIiKkLlmN:nOoPpqRrST:tuVvWxyz", longopts,
	    NULL)) != -1) {
		switch (c) {
		case '0':		opts.from0 = 1;			break;
		case '4':		opts.ipv4 = 1;			break;
		case '6':		opts.ipv6 = 1;			break;
		case '8':		opts._8_bit_output = 1;		break;
		case 'a':		opts.devices = 1;
					opts.group = 1;
					opts.links = 1;
					opts.owner = 1;
					opts.perms = 1;
					opts.recursive = 1;
					opts.specials = 1;
					opts.times = 1;			break;
		case 'B':
			if (!parsesize(&opts.block_size, optarg, 1))
				err(1, "-B %s", optarg);
			break;
		case 'b':		opts.backup = 1;		break;
		case 'C':		opts.cvs_exclude = 1;		break;
		case 'c':		opts.checksum = 1;		break;
		case 'D':		opts.devices = 1;
					opts.specials = 1;		break;
		case 'd':		opts.dirs = 1;			break;
		case 'E':		opts.extended_attributes = 1;	break;
		case 'e':		opts.rsh = optarg;		break;
		case 'f':
			push_filter(&opts.filter, optarg, FPT_INCL);	break;
		case 'g':		opts.group = 1;			break;
		case 'H':		opts.hard_links = 1;		break;
		case 'h':		opts.human_readable = 1;	break;
		case 'I':		opts.ignore_times = 1;		break;
		case 'i':		opts.itemize_changes = 1;	break;
		case 'K':		opts.keep_dirlinks = 1;		break;
		case 'k':		opts.copy_dirlinks = 1;		break;
		case 'L':		opts.copy_links = 1;		break;
		case 'l':		opts.links = 1;			break;
		case 'm':		opts.prune_empty_dirs = 1;	break;
		case 'N':
			if (!parsenum(&opts.streams, optarg, 0, MAX_STREAMS))
				err(1, "streams: %s", optarg);
			break;
		case 'n':		opts.dry_run = 1;		break;
		case 'O':		opts.omit_dir_times = 1;	break;
		case 'o':		opts.owner = 1;			break;
		case 'P':		opts.progress = 1;
					opts.partial = 1;		break;
		case 'p':		opts.perms = 1;			break;
		case 'q':		opts.quiet = 1;			break;
		case 'R':		opts.relative = 1;		break;
		case 'r':		opts.recursive = 1;		break;
		case 'S':		opts.sparse = 1;		break;
		case 'T':		opts.temp_dir = optarg;		break;
		case 't':		opts.times = 1;			break;
		case 'u':		opts.update = 1;		break;
		case 'V':
			fprintf(stderr, "psync version %d\n", PSYNC_VERSION);
			exit(0);
			break;
		case 'v':		opts.verbose = 1;		break;
		case 'W':		opts.whole_file = 1;		break;
		case 'x':		opts.one_file_system = 1;	break;
		case 'y':		opts.fuzzy = 1;			break;
		case 'z':		opts.compress = 1;		break;
		case OPT_ADDRESS:	opts.address = optarg;		break;
		case OPT_BWLIMIT:
			if (!parsesize(&opts.bwlimit, optarg, 1024))
				err(1, "--bwlimit=%s", optarg);
			break;
		case OPT_CHMOD:		opts.chmod = optarg;		break;
		case OPT_COMPARE_DEST:	opts.compare_dest = optarg;	break;
		case OPT_COMPRESS_LEVEL:
			if (!parsenum(&opts.compress_level, optarg, 0, 10))
				err(1, "--compress-level=%s", optarg);
			break;
		case OPT_COPY_DEST:	opts.copy_dest = optarg;	break;
		case OPT_EXCLUDE:
			push_filter(&opts.filter, optarg, FPT_EXCL);	break;
		case OPT_EXCLUDE_FROM:
			pushfile(&opts.filter, optarg, push_filter,
			    FPT_EXCL);					break;
		case OPT_FILES_FROM:
			pushfile(&opts.files, optarg, push_files_from,
			    FPT_INCL);					break;
		case OPT_INCLUDE:
			push_filter(&opts.filter, optarg, FPT_INCL);	break;
		case OPT_INCLUDE_FROM:
			pushfile(&opts.filter, optarg, push_filter,
			    FPT_INCL);					break;
		case OPT_LINK_DEST:	opts.link_dest = optarg;	break;
		case OPT_LOG_FILE:	opts.log_file = optarg;		break;
		case OPT_LOG_FILE_FORMAT:
					opts.log_file_format = optarg;	break;
		case OPT_MAX_DELETE:
			if (!parsenum(&opts.max_delete, optarg, 0, INT_MAX))
				err(1, "--max-delete=%s", optarg);
			break;
		case OPT_MAX_SIZE:
			if (!parsesize(&opts.max_size, optarg, 1))
				err(1, "--max-size=%s", optarg);
			break;
		case OPT_MIN_SIZE:
			if (!parsesize(&opts.min_size, optarg, 1))
				err(1, "--min-size=%s", optarg);
			break;
		case OPT_MODIFY_WINDOW:
			if (!parsenum(&opts.modify_window, optarg, 0, INT_MAX))
				err(1, "--modify-window=%s", optarg);
			break;
		case OPT_ONLY_WRITE_BATCH:opts.write_batch = optarg;	break;
		case OPT_OUT_FORMAT:	opts.out_format = optarg;	break;
		case OPT_PORT:
			if (!parsenum(&opts.port, optarg, 0, 65535))
				err(1, "--port=%s", optarg);
			break;
		case OPT_PARTIAL_DIR:	opts.partial_dir = optarg;	break;
		case OPT_PASSWORD_FILE:	opts.password_file = optarg;	break;
		case OPT_PSYNC_PATH:	opts.psync_path = optarg;	break;
		case OPT_READ_BATCH:	opts.read_batch = optarg;	break;
		case OPT_SOCKOPTS:	opts.sockopts = optarg;		break;
		case OPT_SUFFIX:	opts.suffix = optarg;		break;
		case OPT_TIMEOUT:
			if (!parsenum(&opts.timeout, optarg, 0, INT_MAX))
				err(1, "--timeout=%s", optarg);
			break;
		case OPT_WRITE_BATCH:	opts.write_batch = optarg;	break;

		/* psync specific options */
		case OPT_DSTDIR:	opts.dstdir = optarg;		break;
		case OPT_PUPPET:
			if (!parsenum(&opts.puppet, optarg, 0, 1000000))
				err(1, "--PUPPET=%s", optarg);
			break;

		case 0:
			break;
		default:
			warn("invalid option: -%c", c);
			usage();
		}
	}
}
Esempio n. 12
0
void
main(int argc, char *argv[])
{
	Dir *db;
	Lsym *l;
	Node *n;
	char buf[128], *s;
	int pid, i;
	char *p;
	char afile[512];

	argv0 = argv[0];
	pid = 0;
	aout = "v.out";
	quiet = 1;
	/* turn off all debugging */
	protodebug = 0;

	mtype = 0;
	ARGBEGIN{
	case 'm':
		mtype = ARGF();
		break;
	case 'w':
		wtflag = 1;
		break;
	case 'l':
		s = ARGF();
		if(s == 0)
			usage();
		lm[nlm++] = s;
		break;
	case 'd':
		p = ARGF();
		if (p == 0)
			usage();
		while (*p) {
			setdbg_opt(*p, 0); /* don't print set message */
			p++;
		}
		break;
	case 'k':
		kernel++;
		break;
	case 'q':
		quiet = 0;
		break;
	case 'r':
		pid = 1;
		remote++;
		kernel++;
		break;
	case 'R':
		pid = 1;
		rdebug++;
		s = ARGF();
		if(s == 0)
			usage();
		remfd = opentty(s, 0);
		if(remfd < 0){
			fprint(2, "acid: can't open %s: %r\n", s);
			exits("open");
		}
		break;
	default:
		usage();
	}ARGEND

	if(argc > 0) {
		if(remote || rdebug)
			aout = argv[0];
		else
		if(isnumeric(argv[0])) {
			pid = atoi(argv[0]);
			sprint(prog, "/proc/%d/text", pid);
			aout = prog;
			if(argc > 1)
				aout = argv[1];
			else if(kernel)
				aout = mysystem();
		}
		else {
			if(kernel) {
				print("-k requires a pid");
				kernel = 0;
			}
			aout = argv[0];
		}
	} else if(rdebug)
		aout = "/386/bpc";
	else if(remote)
		aout = "/mips/bcarrera";

	fmtinstall('x', xfmt);
	fmtinstall('L', Lfmt);
	fmtinstall('f', gfltconv);
	fmtinstall('F', gfltconv);
	fmtinstall('g', gfltconv);
	fmtinstall('G', gfltconv);
	fmtinstall('e', gfltconv);
	fmtinstall('E', gfltconv);
	Binit(&bioout, 1, OWRITE);
	bout = &bioout;

	kinit();
	initialising = 1;
	pushfile(0);
	loadvars();
	installbuiltin();

	if(mtype && machbyname(mtype) == 0)
		print("unknown machine %s", mtype);

	if (attachfiles(aout, pid) < 0)
		varreg();		/* use default register set on error */

	acidlib = getenv("ACIDLIB");
	if(acidlib == nil){
		p = getenv("ROOT");
		if(p == nil)
			p = "/usr/inferno";
		snprint(afile, sizeof(afile)-1, "%s/lib/acid", p);
		acidlib = strdup(afile);
	}

	snprint(afile, sizeof(afile)-1, "%s/port", acidlib);
	loadmodule(afile);
	for(i = 0; i < nlm; i++) {
		if((db = dirstat(lm[i])) != nil) {
			free(db);
			loadmodule(lm[i]);
		} else {
			sprint(buf, "%s/%s", acidlib, lm[i]);
			loadmodule(buf);
		}
	}

	userinit();
	varsym();

	l = look("acidmap");
	if(l && l->proc) {
		n = an(ONAME, ZN, ZN);
		n->sym = l;
		n = an(OCALL, n, ZN);
		execute(n);
	}

	interactive = 1;
	initialising = 0;
	line = 1;

	setup_os_notify();

	for(;;) {
		if(setjmp(err)) {
			Binit(&bioout, 1, OWRITE);
			unwind();
		}
		stacked = 0;

		Bprint(bout, "acid: ");

		if(yyparse() != 1)
			die();
		restartio();

		unwind();
	}
	/* not reached */
}
Esempio n. 13
0
File: main.c Progetto: Fluray/NxM
void
main(int argc, char *argv[])
{
	Lsym *l;
	Node *n;
	char *s;
	int pid, i;

	argv0 = argv[0];
	pid = 0;
	aout = "8.out";
	quiet = 1;

	mtype = 0;
	ARGBEGIN{
	case 'm':
		mtype = EARGF(usage());
		break;
	case 'w':
		wtflag = 1;
		break;
	case 'l':
		s = EARGF(usage());
		lm[nlm++] = s;
		break;
	case 'k':
		kernel++;
		break;
	case 'q':
		quiet = 0;
		break;
	case 'r':
		pid = 1;
		remote++;
		kernel++;
		break;
	default:
		usage();
	}ARGEND

	if(argc > 0) {
		if(remote)
			aout = argv[0];
		else
		if(isnumeric(argv[0])) {
			pid = strtol(argv[0], 0, 0);
			snprint(prog, sizeof(prog), "/proc/%d/text", pid);
			aout = prog;
			if(argc > 1)
				aout = argv[1];
			else if(kernel)
				aout = system();
		}
		else {
			if(kernel) {
				fprint(2, "acid: -k requires a pid\n");
				usage();
			}
			aout = argv[0];
		}
	} else
	if(remote)
		aout = "/mips/9ch";

	fmtinstall('x', xfmt);
	fmtinstall('L', Lfmt);
	Binit(&bioout, 1, OWRITE);
	bout = &bioout;

	kinit();
	initialising = 1;
	pushfile(0);
	loadvars();
	installbuiltin();

	if(mtype && machbyname(mtype) == 0)
		print("unknown machine %s", mtype);

	if (attachfiles(aout, pid) < 0)
		varreg();		/* use default register set on error */

	loadmodule("/sys/lib/acid/port");
	loadmoduleobjtype();

	for(i = 0; i < nlm; i++) {
		if(access(lm[i], AREAD) >= 0)
			loadmodule(lm[i]);
		else {
			s = smprint("/sys/lib/acid/%s", lm[i]);
			loadmodule(s);
			free(s);
		}
	}

	userinit();
	varsym();

	l = look("acidmap");
	if(l && l->proc) {
		n = an(ONAME, ZN, ZN);
		n->sym = l;
		n = an(OCALL, n, ZN);
		execute(n);
	}

	interactive = 1;
	initialising = 0;
	line = 1;

	notify(catcher);

	for(;;) {
		if(setjmp(err)) {
			Binit(&bioout, 1, OWRITE);
			unwind();
		}
		stacked = 0;

		Bprint(bout, "acid: ");

		if(yyparse() != 1)
			die();
		restartio();

		unwind();
	}
	/* not reached */
}