Пример #1
0
/* 连接某个服务进程的监听接口,发送停止消息 */
static void proctl_monitor_stop_service(ACL_VSTREAM *client,
	const char *filepath, const char *args)
{
	const char *myname = "proctl_monitor_stop_service";
	ACL_VSTREAM *stream;
	char  addr[256], ebuf[256], buf[1024], logfile[MAX_PATH];
	int   n;

	get_lock_file2(filepath, logfile, sizeof(logfile));

	if (get_addr_from_file(logfile, addr, sizeof(addr)) < 0) {
		acl_vstream_fprintf(client, "-ERR|get addr error from %s\r\n", filepath);
		acl_msg_error("%s(%d): get addr for filepath(%s) error",
			myname, __LINE__, filepath);
		return;
	}

	stream = acl_vstream_connect(addr, ACL_BLOCKING, 10, 10, 1024);
	if (stream == NULL) {
		acl_vstream_fprintf(client, "-ERR|connect addr=%s error, file=%s\r\n",
			addr, filepath);
		acl_msg_error("%s(%d): connect addr(%s) error(%s)",
			myname, __LINE__, addr, acl_last_strerror(ebuf, sizeof(ebuf)));
		return;
	}

	if (args && *args)
		n = acl_vstream_fprintf(stream, "%s|-d|STOP|-f|%s|-a|%s\r\n",
				filepath, filepath, args);
	else
		n = acl_vstream_fprintf(stream, "%s|-d|STOP|-f|%s\r\n",
				filepath, filepath);

	buf[0] = 0;

	if (n == ACL_VSTREAM_EOF) {
		acl_vstream_fprintf(client, "-ERR|write to addr=%s error, file=%s\r\n",
			addr, filepath);
		acl_msg_error("%s(%d): fprintf to acl_master error(%s)",
			myname, __LINE__, acl_last_strerror(ebuf, sizeof(ebuf)));
	} else if (acl_vstream_gets_nonl(stream, buf, sizeof(buf)) == ACL_VSTREAM_EOF) {
		acl_vstream_fprintf(client, "-ERR|filepath(%s), not get respond\r\n", filepath);
		acl_msg_error("%s(%d): not get respond, filepath(%s)",
			myname, __LINE__, filepath);
	} else if (strncasecmp(buf, "+OK", 3) != 0) {
		acl_vstream_fprintf(client, "-ERR|filepath(%s), child respond(%s)\r\n",
			filepath, buf);
		acl_msg_error("%s(%d): child respond error(%s), filepath(%s)",
			myname, __LINE__, buf, filepath);
	} else {
		acl_vstream_fprintf(client, "+OK|stopped %s\r\n", filepath);
		acl_msg_info("%s(%d): stop child(%s) ok", myname, __LINE__, filepath);
	}

	acl_vstream_close(stream);
}
Пример #2
0
/* 打开与控制进程的监听线程之间的数据连接 */
static ACL_VSTREAM *proctl_client_open(const char *progname)
{
	const char *myname = "proctl_client_open";
	char  ebuf[256], lock_file[MAX_PATH], addr[256];
	ACL_VSTREAM *client;

	proctl_init(progname);

	get_lock_file(lock_file, sizeof(lock_file));

	if (get_addr_from_file(lock_file, addr, sizeof(addr)) < 0)
		acl_msg_fatal("%s(%d): get addr from file(%s) error(%s)",
		myname, __LINE__, lock_file, acl_last_strerror(ebuf, sizeof(ebuf)));

	client = acl_vstream_connect(addr, ACL_BLOCKING, 10, 10, 1024);
	if (client == NULL)
		acl_msg_fatal("%s(%d): connect addr(%s) error(%s)",
		myname, __LINE__, addr, acl_last_strerror(ebuf, sizeof(ebuf)));

	return (client);
}