Example #1
0
static void __post_jail_init_fn(char *unused_name, char **unused_argv)
{
	char  myname[] = "__post_jail_init_fn";
	ACL_VSTRING *why = acl_vstring_alloc(100);

	unused_name = unused_name;
	unused_argv = unused_argv;

	if (acl_msg_verbose)
		acl_msg_info("%s(%d)->%s: test only",
				__FILE__, __LINE__, myname);

	__data_buf = acl_mymalloc(var_proxy_bufsize);
	if (__data_buf == NULL)
		acl_msg_fatal("%s(%d)->%s: malloc data_buf, serr = %s",
				__FILE__, __LINE__, myname,
				strerror(errno));

	if (var_proxy_debug_request) {
		__request_stream = acl_safe_open(var_proxy_request_file,
						O_CREAT | O_RDWR | O_APPEND, 0600,
						(struct stat *) 0, (uid_t)-1,
						(uid_t )-1, why);
		if (__request_stream == NULL)
			acl_msg_fatal("%s(%d)->%s: can't open %s, err = %s",
					__FILE__, __LINE__, myname,
					var_proxy_request_file, acl_vstring_str(why));
	}

	if (var_proxy_debug_respond) {
		__respond_stream = acl_safe_open(var_proxy_respond_file,
						O_CREAT | O_RDWR | O_APPEND, 0600,
						(struct stat *) 0, (uid_t)-1,
						(uid_t )-1, why);
		if (__respond_stream == NULL)
			acl_msg_fatal("%s(%d)->%s: can't open %s, err = %s",
					__FILE__, __LINE__, myname,
					var_proxy_respond_file, acl_vstring_str(why));
	}

	acl_vstring_free(why);
}
Example #2
0
static void test_fseek2(int buflen)
{
	ACL_VSTREAM *fp;
	ACL_VSTRING *why = acl_vstring_alloc(100);
	char  filename[] ="./tmp.txt";
	char  buf[10];
	int   n;
	int offset, off2;
	int   ch;

	fp = acl_safe_open(filename, O_CREAT | O_RDWR, 0600,
			(struct stat *) 0, (uid_t)-1,
			(uid_t )-1, why);
	if (fp == 0)
		acl_msg_fatal("%s(%d)->%s: can't open %s, serr = %s",
			__FILE__, __LINE__, __FUNCTION__, filename, acl_vstring_str(why));

	fp->read_buf_len = buflen;

	ch = acl_vstream_getc(fp);
	printf("after read(1)(%d) >>> ch = %c, read_cnt = %d, offset=%d, %d\n",
		__LINE__, ch, (int) fp->read_cnt, (int) fp->offset, (int) fp->sys_offset);
	offset = acl_vstream_fseek2(fp, 0, SEEK_CUR);
	printf("after fseek(0)(%d) >>> ch = %c, read_cnt = %d, off = %d, offset=%d, %d\n\n",
		__LINE__, ch, (int)fp->read_cnt, offset, (int) fp->offset, (int) fp->sys_offset);

	ch = acl_vstream_getc(fp);
	printf("after read(1)(%d) >>> ch = %c, read_cnt = %d, offset=%d, %d\n",
		__LINE__, ch, (int) fp->read_cnt, (int) fp->offset, (int) fp->sys_offset);
	offset = acl_vstream_fseek2(fp, 0, SEEK_CUR);
	printf("after fseek(0)(%d) >>> ch = %c, read_cnt = %d, off = %d, %s, offset=%d, %d\n\n",
		__LINE__, ch, (int)fp->read_cnt, offset, strerror(errno), (int) fp->offset, (int) fp->sys_offset);

	offset = acl_vstream_fseek2(fp, 10, SEEK_CUR);
	off2 = lseek(ACL_VSTREAM_FILE(fp), 0, SEEK_CUR);
	printf("after fseek(10)(%d) >>> off=%d, lseek = %d, read_cnt = %d, offset=%d, %d\n\n",
		__LINE__, offset, off2, (int)fp->read_cnt, (int) fp->offset, (int) fp->sys_offset);

	n = acl_vstream_gets_nonl(fp, buf, sizeof(buf) - 1);
	printf("after read(getline)(%d) >>> buf = [%s], fp->read_cnt = %d, offset=%d, %d\n",
		__LINE__, buf, (int)fp->read_cnt, (int) fp->offset, (int) fp->sys_offset);
	offset = acl_vstream_fseek2(fp, 0, SEEK_CUR);
	printf("after fseek(0)(%d) >>> buf = [%s], read_cnt = %d, off = %d, offset=%d, %d\n\n",
		__LINE__, buf, (int) fp->read_cnt, offset, (int) fp->offset, (int) fp->sys_offset);

	ch = acl_vstream_getc(fp);
	printf("after read(1)(%d) >>> ch = %c, read_cnt = %d, offset=%d, %d\n",
		__LINE__, ch, (int)fp->read_cnt, (int) fp->offset, (int) fp->sys_offset);
	offset = acl_vstream_fseek2(fp, 0, SEEK_CUR);
	printf("after fseek(0)(%d) >>> ch = %c, read_cnt = %d, off = %d, offset=%d, %d\n\n",
		__LINE__, ch, (int) fp->read_cnt, offset, (int) fp->offset, (int) fp->sys_offset);

	n = acl_vstream_readn(fp, buf, 2);
	buf[n] = 0;
	printf("after read(buf)(%d) >>> buf = [%s], fp->read_cnt = %d, offset=%d, offset=%d, %d\n",
		__LINE__, buf, (int) fp->read_cnt, offset, (int) fp->offset, (int) fp->sys_offset);
	offset = acl_vstream_fseek2(fp, 10, SEEK_CUR);
	printf("after fseek(10)(%d) >>> read_cnt = %d, off = %d, offset=%d, %d\n\n",
		__LINE__, (int) fp->read_cnt, offset, (int) fp->offset, (int) fp->sys_offset);

	ch = acl_vstream_getc(fp);
	printf("after read(1)(%d) >>> ch = %c, read_cnt = %d, offset=%d, %d\n",
		__LINE__, ch, (int)fp->read_cnt, (int) fp->offset, (int) fp->sys_offset);
	offset = acl_vstream_fseek2(fp, 0, SEEK_CUR);
	printf("after fseek(0)(%d) >>> ch = %c, read_cnt = %d, off = %d, %s, offset=%d, %d\n\n",
		__LINE__, ch, (int) fp->read_cnt, offset, strerror(errno), (int) fp->offset, (int) fp->sys_offset);

	acl_vstring_free(why);
	acl_vstream_close(fp);
}