コード例 #1
0
ファイル: function1.c プロジェクト: ocelot-inc/tarantool
int
function1(box_function_ctx_t *ctx, const char *args, const char *args_end)
{
	say_info("-- function1 -  called --");
	printf("ok - function1\n");
	return 0;
}
コード例 #2
0
ファイル: stdio_wrap.c プロジェクト: fazme/OPENRELEASE
int listen_port(char *ipaddr, int port)
{
	int fd __attribute__((cleanup(close_fd_))) = -1,
	    sock = -1;
	int flags;
	struct sockaddr_in sin;

	fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
	if (fd == -1) {
		say_error("can't create socket: %m");

		return -1;
	}

	if ((flags = fcntl(fd, F_GETFL, 0) < 0) ||
	    fcntl(fd, F_SETFL, flags | O_NONBLOCK) < 0) {
		say_error("can't move socket to non-blocking state: %m");

		return -1;
	}

	sin.sin_family = AF_INET;
	sin.sin_port = htons(port);
	if (ipaddr == NULL || ipaddr[0] == '\0')
		sin.sin_addr.s_addr = INADDR_ANY;
	else if (inet_aton(ipaddr, &sin.sin_addr) == 0) {
		say_error("inet_aton `%s': %m", ipaddr);

		return -1;
	}

	if (bind(fd, (struct sockaddr *)&sin, sizeof(sin)) != 0) {
		say_error("can't bind to `%s:%d': %m", ipaddr, port);

		return -1;
	}
	if (listen(fd, 1) != 0) {
		say_error("can't listen on `%s:%d': %m", ipaddr, port);

		return -1;
	}

	say_info("listenning on '%s:%d'", ipaddr, port);

	sock = fd;
	fd = -1;

	return sock;
}
コード例 #3
0
ファイル: openrelease.c プロジェクト: fazme/OPENRELEASE
int __wrap_main(int argc, char *argv[], char *envp[])
{
	int c;
	char *config_file = NULL;
	char *log_file = NULL;
	bool daemon = false;

	while ((c = getopt(argc, argv, "c:dhl:vV")) != -1) {
		switch (c) {
		case 'c':
			config_file = strdup(optarg);

			break;
		case 'd':
			daemon = true;

			break;
		case 'h':
			usage();

			_exit(EXIT_SUCCESS);
		case 'l':
			log_file = strdup(optarg);

			break;
		case 'v':
			++verbose;

			break;
		case 'V':
			printf("%s\n", openrelease_version());

			_exit(EXIT_SUCCESS);
		case '?':
			usage();

			_exit(EXIT_FAILURE);
		default:
			say_error("unmatched option: -%c", c);

			_exit(EXIT_FAILURE);
		}
	}

	create_log(log_file);

	config_init(config_file);

	if (getenv("OPENRELEASE_STAGE2") == NULL) {
		if (daemon) {
			if (daemonize(1, 0) == -1) {
				say_error("can't daemonize");

				_exit(EXIT_FAILURE);
			}
		}

		if (stdio_wrap(config.input, config.output) == -1) {
			say_error("stdio_wrap failed");

			_exit(EXIT_FAILURE);
		}

		putenv("OPENRELEASE_STAGE2=1");

		execvp(argv[0], argv);
	}

	mmaps_init();

	symfile_load(config.symfile);
	wrap_init();

	debug_init();
	key_action_init();

	say_info("dive into RELEASE");

	unsetenv("LD_PRELOAD");

	argc = 1;
	if (optind != argc) {
		memmove(&argv[1], &argv[optind], (optind - argc) * sizeof(argv[0]));
		argc += optind - argc;
	}
	argv[argc] = NULL;

	__real_main(argc, argv, envp);

	_exit(EXIT_SUCCESS);

	return 0;
}