Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6a721aa

Browse files
knizhnikgsmolk
authored andcommitted
Grab abnd log agent messages to stderr
1 parent736fc41 commit6a721aa

File tree

3 files changed

+31
-4
lines changed

3 files changed

+31
-4
lines changed

‎src/utils/file.c‎

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ static __thread unsigned long fio_fdset = 0;
2020
static __threadvoid*fio_stdin_buffer;
2121
static __threadintfio_stdout=0;
2222
static __threadintfio_stdin=0;
23+
static __threadintfio_stderr=0;
2324

2425
fio_locationMyLocation;
2526

@@ -38,10 +39,28 @@ typedef struct
3839
#definefio_fileno(f) (((size_t)f - 1) | FIO_PIPE_MARKER)
3940

4041
/* Use specified file descriptors as stdin/stdout for FIO functions */
41-
voidfio_redirect(intin,intout)
42+
voidfio_redirect(intin,intout,interr)
4243
{
4344
fio_stdin=in;
4445
fio_stdout=out;
46+
fio_stderr=err;
47+
}
48+
49+
voidfio_error(intrc,intsize,charconst*file,intline)
50+
{
51+
if (remote_agent)
52+
{
53+
fprintf(stderr,"%s:%d: proceeds %d bytes instead of %d: %s\n",file,line,rc,size,rc >=0 ?"end of data" :strerror(errno));
54+
exit(EXIT_FAILURE);
55+
}
56+
else
57+
{
58+
charbuf[PRINTF_BUF_SIZE];
59+
interr_size=read(fio_stderr,buf,sizeof(buf));
60+
if (err_size>0)
61+
elog(LOG,"Agent error: %s",buf);
62+
elog(ERROR,"Communication error: %s",rc >=0 ?"end of data" :strerror(errno));
63+
}
4564
}
4665

4766
/* Check if file descriptor is local or remote (created by FIO) */

‎src/utils/file.h‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ typedef enum
4949
#definePAGE_CHECKSUM_MISMATCH (-256)
5050

5151
#defineSYS_CHECK(cmd) do if ((cmd) < 0) { fprintf(stderr, "%s:%d: (%s) %s\n", __FILE__, __LINE__, #cmd, strerror(errno)); exit(EXIT_FAILURE); } while (0)
52-
#defineIO_CHECK(cmd,size) do { int _rc = (cmd); if (_rc != (size)){ if (remote_agent) { fprintf(stderr, "%s:%d: proceeds %d bytes instead of %d: %s\n", __FILE__, __LINE__, _rc, (int)(size), _rc >= 0 ? "end of data" : strerror(errno)); exit(EXIT_FAILURE); } else elog(ERROR, "Communication error: %s", _rc >= 0 ? "end of data" : strerror(errno)); } } while (0)
52+
#defineIO_CHECK(cmd,size) do { int _rc = (cmd); if (_rc != (size))fio_error(_rc, size, __FILE__, __LINE__); } while (0)
5353

5454
typedefstruct
5555
{
@@ -64,7 +64,7 @@ extern fio_location MyLocation;
6464
/* Check if FILE handle is local or remote (created by FIO) */
6565
#definefio_is_remote_file(file) ((size_t)(file) <= FIO_FDMAX)
6666

67-
externvoidfio_redirect(intin,intout);
67+
externvoidfio_redirect(intin,intout,interr);
6868
externvoidfio_communicate(intin,intout);
6969

7070
externFILE*fio_fopen(charconst*name,charconst*mode,fio_locationlocation);
@@ -77,6 +77,7 @@ extern int fio_fseek(FILE* f, off_t offs);
7777
externintfio_ftruncate(FILE*f,off_tsize);
7878
externintfio_fclose(FILE*f);
7979
externintfio_ffstat(FILE*f,structstat*st);
80+
externvoidfio_error(intrc,intsize,charconst*file,intline);
8081

8182
structpgFile;
8283
externintfio_send_pages(FILE*in,FILE*out,structpgFile*file,XLogRecPtrhorizonLsn,

‎src/utils/remote.c‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ bool launch_agent(void)
110110
intssh_argc;
111111
intoutfd[2];
112112
intinfd[2];
113+
interrfd[2];
113114

114115
ssh_argc=0;
115116
#ifdefWIN32
@@ -195,20 +196,25 @@ bool launch_agent(void)
195196
#else
196197
SYS_CHECK(pipe(infd));
197198
SYS_CHECK(pipe(outfd));
199+
SYS_CHECK(pipe(errfd));
198200

199201
SYS_CHECK(child_pid=fork());
200202

201203
if (child_pid==0) {/* child */
202204
SYS_CHECK(close(STDIN_FILENO));
203205
SYS_CHECK(close(STDOUT_FILENO));
206+
SYS_CHECK(close(STDERR_FILENO));
204207

205208
SYS_CHECK(dup2(outfd[0],STDIN_FILENO));
206209
SYS_CHECK(dup2(infd[1],STDOUT_FILENO));
210+
SYS_CHECK(dup2(errfd[1],STDERR_FILENO));
207211

208212
SYS_CHECK(close(infd[0]));
209213
SYS_CHECK(close(infd[1]));
210214
SYS_CHECK(close(outfd[0]));
211215
SYS_CHECK(close(outfd[1]));
216+
SYS_CHECK(close(errfd[0]));
217+
SYS_CHECK(close(errfd[1]));
212218

213219
if (execvp(ssh_argv[0],ssh_argv)<0)
214220
return false;
@@ -217,9 +223,10 @@ bool launch_agent(void)
217223
elog(LOG,"Spawn agent %d version %s",child_pid,PROGRAM_VERSION);
218224
SYS_CHECK(close(infd[1]));/* These are being used by the child */
219225
SYS_CHECK(close(outfd[0]));
226+
SYS_CHECK(close(errfd[1]));
220227
/*atexit(kill_child);*/
221228

222-
fio_redirect(infd[0],outfd[1]);/* write to stdout */
229+
fio_redirect(infd[0],outfd[1],errfd[0]);/* write to stdout */
223230
}
224231
return true;
225232
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp