@@ -727,23 +727,30 @@ finish_progress(char *done)
727
727
pt_header = NULL ;
728
728
}
729
729
730
+ // This function checks if the passed fd refers to /dev/null or /dev/zero
730
731
static int
731
- is_dev_fs (int fd )
732
+ is_dev_files (int fd )
732
733
{
733
734
int nfd = open ("/dev/null" , O_WRONLY );
734
735
struct stat st , nst ;
735
736
fstat (fd , & st );
736
737
fstat (nfd , & nst );
737
738
int res = (st .st_dev == nst .st_dev );
738
739
close (nfd );
740
+ if (res != 1 ) {
741
+ nfd = open ("/dev/zero" , O_WRONLY );
742
+ fstat (nfd , & nst );
743
+ res = (st .st_dev == nst .st_dev );
744
+ close (nfd );
745
+ }
739
746
return (res );
740
747
}
741
748
742
749
static int
743
750
is_dev_error (int err , int fd )
744
751
{
745
752
#ifdef __linux__
746
- if (err == EINVAL && is_dev_fs (fd )) {
753
+ if (err == EINVAL && is_dev_files (fd )) {
747
754
return (1 );
748
755
}
749
756
#endif
@@ -4596,8 +4603,8 @@ zfs_do_send(int argc, char **argv)
4596
4603
resume_token );
4597
4604
if (err != 0 && is_dev_error (errno , STDOUT_FILENO )) {
4598
4605
(void ) fprintf (stderr ,
4599
- gettext ("Error: Stream cannot be written to /dev/ "
4600
- " files.\n" ));
4606
+ gettext ("Error: Stream cannot be written to "
4607
+ "/dev/{null,zero} files.\n" ));
4601
4608
4602
4609
}
4603
4610
zfs_close (zhp );
@@ -4607,8 +4614,8 @@ zfs_do_send(int argc, char **argv)
4607
4614
resume_token );
4608
4615
if (err != 0 && is_dev_error (errno , STDOUT_FILENO )) {
4609
4616
(void ) fprintf (stderr ,
4610
- gettext ("Error: Stream cannot be written to /dev/ "
4611
- " files.\n" ));
4617
+ gettext ("Error: Stream cannot be written to "
4618
+ "/dev/{null,zero} files.\n" ));
4612
4619
}
4613
4620
return (err );
4614
4621
}
@@ -4663,8 +4670,8 @@ zfs_do_send(int argc, char **argv)
4663
4670
zfs_close (zhp );
4664
4671
if (err != 0 && is_dev_error (errno , STDOUT_FILENO )) {
4665
4672
(void ) fprintf (stderr ,
4666
- gettext ("Error: Stream cannot be written to /dev/ "
4667
- " files.\n" ));
4673
+ gettext ("Error: Stream cannot be written to "
4674
+ "/dev/{null,zero} files.\n" ));
4668
4675
}
4669
4676
return (err != 0 );
4670
4677
}
@@ -4742,10 +4749,10 @@ zfs_do_send(int argc, char **argv)
4742
4749
nvlist_free (dbgnv );
4743
4750
}
4744
4751
zfs_close (zhp );
4745
- if (err != 0 && is_dev_error (errno , STDOUT_FILENO )) {
4752
+ if (is_dev_error (errno , STDOUT_FILENO )) {
4746
4753
(void ) fprintf (stderr ,
4747
- gettext ("Error: Stream cannot be written to /dev/ "
4748
- "files.\n" ));
4754
+ gettext ("Error: Stream cannot be written to "
4755
+ "/dev/{null,zero} files.\n" ));
4749
4756
}
4750
4757
4751
4758
return (err != 0 );
0 commit comments