Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit dbb787f

Browse files
committed
Propagate errno from remote agent
1 parent 236a906 commit dbb787f

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

src/utils/file.c

+22-6
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,12 @@ int fio_fstat(int fd, struct stat* st)
535535
Assert(hdr.cop == FIO_FSTAT);
536536
IO_CHECK(fio_read_all(fio_stdin, st, sizeof(*st)), sizeof(*st));
537537

538-
return hdr.arg;
538+
if (hdr.arg != 0)
539+
{
540+
errno = hdr.arg;
541+
return -1;
542+
}
543+
return 0;
539544
}
540545
else
541546
{
@@ -563,7 +568,12 @@ int fio_stat(char const* path, struct stat* st, bool follow_symlinks, fio_locati
563568
Assert(hdr.cop == FIO_STAT);
564569
IO_CHECK(fio_read_all(fio_stdin, st, sizeof(*st)), sizeof(*st));
565570

566-
return hdr.arg;
571+
if (hdr.arg != 0)
572+
{
573+
errno = hdr.arg;
574+
return -1;
575+
}
576+
return 0;
567577
}
568578
else
569579
{
@@ -589,7 +599,12 @@ int fio_access(char const* path, int mode, fio_location location)
589599
IO_CHECK(fio_read_all(fio_stdin, &hdr, sizeof(hdr)), sizeof(hdr));
590600
Assert(hdr.cop == FIO_ACCESS);
591601

592-
return hdr.arg;
602+
if (hdr.arg != 0)
603+
{
604+
errno = hdr.arg;
605+
return -1;
606+
}
607+
return 0;
593608
}
594609
else
595610
{
@@ -1074,19 +1089,20 @@ void fio_communicate(int in, int out)
10741089
break;
10751090
case FIO_FSTAT: /* Get information about opened file */
10761091
hdr.size = sizeof(st);
1077-
hdr.arg = fstat(fd[hdr.handle], &st);
1092+
hdr.arg = fstat(fd[hdr.handle], &st) < 0 ? errno : 0;
10781093
IO_CHECK(fio_write_all(out, &hdr, sizeof(hdr)), sizeof(hdr));
10791094
IO_CHECK(fio_write_all(out, &st, sizeof(st)), sizeof(st));
10801095
break;
10811096
case FIO_STAT: /* Get information about file with specified path */
10821097
hdr.size = sizeof(st);
1083-
hdr.arg = hdr.arg ? stat(buf, &st) : lstat(buf, &st);
1098+
rc = hdr.arg ? stat(buf, &st) : lstat(buf, &st);
1099+
hdr.arg = rc < 0 ? errno : 0;
10841100
IO_CHECK(fio_write_all(out, &hdr, sizeof(hdr)), sizeof(hdr));
10851101
IO_CHECK(fio_write_all(out, &st, sizeof(st)), sizeof(st));
10861102
break;
10871103
case FIO_ACCESS: /* Check presence of file with specified name */
10881104
hdr.size = 0;
1089-
hdr.arg = access(buf, hdr.arg);
1105+
hdr.arg = access(buf, hdr.arg) < 0 ? errno : 0;
10901106
IO_CHECK(fio_write_all(out, &hdr, sizeof(hdr)), sizeof(hdr));
10911107
break;
10921108
case FIO_RENAME: /* Rename file */

src/utils/remote.c

+1
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ bool launch_agent(void)
128128
if (execvp(ssh_argv[0], ssh_argv) < 0)
129129
return false;
130130
} else {
131+
elog(LOG, "Spawn agent %d", child_pid);
131132
SYS_CHECK(close(infd[1])); /* These are being used by the child */
132133
SYS_CHECK(close(outfd[0]));
133134
/*atexit(kill_child);*/

0 commit comments

Comments
 (0)