This code will wrap statvfs()in a function that sets an alarm to interrupt a call. It will return -1with errno set to EINTRif the alarm lights up and interrupts the call statvfs()(I have not tried this so that it is not perfect ...):
#include <sigaction.h>
#include <sys/statvfs.h>
#include <unistd.h>
#include <string.h>
static void alarm_handler( int sig )
{
return;
}
.
.
.
int statvfs_try( const char *path, struct statvfs *s, unsigned int seconds )
{
struct sigaction newact;
struct sigaction oldact;
memset( &newact, 0, sizeof( newact ) );
memset( &oldact, 0, sizeof( oldact) );
sigemptyset( &newact.sa_mask );
newact.sa_flags = 0;
newact.sa_handler = alarm_handler;
sigaction( SIGALRM, &newact, &oldact );
alarm( seconds );
errno = 0;
int rc = statvfs( path, s );
int save_errno = errno;
alarm( 0 );
sigaction( SIGALRM, &oldact, NULL );
errno = saved_errno;
return( rc );
}
It may also use some error checking, especially on calls sigaction(), but it is long enough to generate a scrollbar already, so I left it.
, statvfs(), Linux, strace . statvfs(), , statvfs(). statvfs(), , libc .