예제 #1
0
int main(int argc, char **argv) {
	int i;
	FILE *fd;
	char *file, buf[4096];
	if (argc==1 || !strcmp (argv[1], "-h")) {
		eprintf ("Usage: rarun2 [-v] [script.rr2] [directive ..]\n");
		printf (
			"program=/bin/ls\n"
			"arg1=/bin\n"
			"# arg2=hello\n"
			"# arg3=\"hello\\nworld\"\n"
			"# arg4=:048490184058104849\n"
			"# [email protected]\n"
			"# system=r2 -\n"
			"setenv=FOO=BAR\n"
			"# unsetenv=FOO\n"
			"# envfile=environ.txt\n"
			"timeout=3\n"
			"# connect=localhost:8080\n"
			"# listen=8080\n"
			"# #stdio=blah.txt\n"
			"# #stderr=foo.txt\n"
			"# stdout=foo.txt\n"
			"# stdin=input.txt\n"
			"# input=input.txt\n"
			"# chdir=/\n"
			"# chroot=/mnt/chroot\n"
			"# libpath=$PWD:/tmp/lib\n"
			"# r2preload=yes\n"
			"# preload=/lib/libfoo.so\n"
			"# setuid=2000\n"
			"# seteuid=2000\n"
			"# setgid=2001\n"
			"# setegid=2001\n");
		return 1;
	}
	if (!strcmp (argv[1], "-v")) {
		printf ("rarun2 "R2_VERSION"\n");
		return 0;
	}
	file = argv[1];
	if (*file && !strchr (file, '=')) {
		fd = fopen (file, "r");
		if (!fd) {
			eprintf ("Cannot open %s\n", file);
			return 1;
		}
		for (;;) {
			fgets (buf, sizeof (buf)-1, fd);
			if (feof (fd)) break;
			buf[strlen (buf)-1] = 0;
			parseline (buf);
		}
		fclose (fd);
	} else {
		for (i=*file?1:2; i<argc; i++)
			parseline (argv[i]);
	}
	return runfile ();
}
예제 #2
0
int main(int argc, char **argv) {
	int i;
	FILE *fd;
	char *file, buf[4096];
	if (argc==1 || !strcmp (argv[1], "-h")) {
		fprintf (stderr, "Usage: rarun2 [-v] [script.rr2] [directive ..]\n");
		printf (
			"program=/bin/ls\n"
			"arg1=/bin\n"
			"# arg#=...\n"
			"setenv=FOO=BAR\n"
			"timeout=3\n"
			"# connect=localhost:8080\n"
			"# listen=8080\n"
			"# stdout=foo.txt\n"
			"# stdin=input.txt\n"
			"# input=input.txt\n"
			"# chdir=/\n"
			"# chroot=/mnt/chroot\n"
			"# preload=/lib/libfoo.so\n"
			"# setuid=2000\n"
			"# seteuid=2000\n"
			"# setgid=2001\n"
			"# setegid=2001\n");
		return 1;
	}
	if (!strcmp (argv[1], "-v")) {
		printf ("rarun2 "R2_VERSION"\n");
		return 0;
	}
	file = argv[1];
	if (*file && !strchr (file, '=')) {
		fd = fopen (file, "r");
		if (!fd) {
			fprintf (stderr, "Cannot open %s\n", file);
			return 1;
		}
		for (;;) {
			fgets (buf, sizeof (buf)-1, fd);
			if (feof (fd)) break;
			buf[strlen (buf)-1] = 0;
			parseline (buf);
		}
		fclose (fd);
	} else {
		for (i=*file?1:2; i<argc; i++)
			parseline (argv[i]);
	}
	return runfile ();
}
예제 #3
0
파일: otserv.cpp 프로젝트: 081421/otxserver
void runfileHandler(void)
{
	std::ofstream runfile(g_config.getString(ConfigManager::RUNFILE).c_str(), std::ios::trunc | std::ios::out);
	runfile.close();
}
예제 #4
0
/*-----------------------------------------------------------------------------------*/
static void
execfile(char *str)
{
  runfile(str);
  shell_quit(NULL);
}
예제 #5
0
파일: ssh.c 프로젝트: IIJ-NetBSD/netbsd-src
int
main(int argc, char *argv[])
{
	struct sigaction sa;
	FILE *cfp;		/* command file ptr */
	int c, sig;
	int error = 0;

	while ((c = getopt(argc, argv, "eisx")) != -1) {
		switch (c) {
		case 'e':
			eflag++;
			break;
		case 'i':
			eflag++;
			break;
		case 's':
			sflag++;
			break;
		case 'x':
			xflag++;
			break;
		case '?':
			error++;
			break;
		}
	}
	if (error) {
		fprintf(stderr, "usage:  ssh [-eisx] [cmd_file [...]]\n");
		exit(EXIT_FAILURE);
	}
	cf_argc = argc - optind;
	cf_argv = &argv[optind];

	/* If this is a login shell, run the rc file. */
	if (argv[0] && argv[0][0] == '-') {
		cf_line = 0;
		cf_name = rc_name;
		if ((cfp = fopen(cf_name, "r")) != NULL) {
			error = runfile(cfp);
			fclose(cfp);
		}
	}

	/* If no file names, read commands from stdin. */
	if (cf_argc == 0)
		sflag++;
	/* If stdin is a tty, be interactive. */
	if (sflag && isatty(fileno(stdin)))
		iflag++;

	/* Maybe run a command file... */
	if (!sflag && cf_argc) {
		cf_line = 0;
		cf_name = cf_argv[0];
		cfp = fopen(cf_name, "r");
		if (cfp == NULL) {
			perror(cf_name);
			exit(EXIT_FAILURE);
		}
		error = runfile(cfp);
		fclose(cfp);
		exit(error);
	}

	/* Read commands from stdin. */
	cf_line = 0;
	cf_name = "(stdin)";
	if (iflag) {
		eflag = 0;	/* don't kill shell on error. */
		sig = setjmp(next_cmd);
		if (sig == 0) {
			/* Initialization... */
			sa.sa_handler = catchsig;
			sa.sa_flags = 0;
			sigemptyset(&sa.sa_mask);
			sigaction(SIGINT,  &sa, NULL);
			sigaction(SIGQUIT, &sa, NULL);
			sigaction(SIGTERM, &sa, NULL);
		} else {
			/* Got here via longjmp. */
			fprintf(stderr, " signal %d\n", sig);
			sigemptyset(&sa.sa_mask);
			sigprocmask(SIG_SETMASK, &sa.sa_mask, NULL);
		}
	}
	error = runfile(stdin);
	exit(error);
}