Add krb5_storage_fsync().

We add a function to cause krb5_storage's to be sync'd to their backing
store.  For memory backed storages, this is a NOP.  For files, it calls
fsync on the file descriptor.
This commit is contained in:
Roland C. Dowdeswell
2012-05-28 13:14:55 +01:00
parent 8dc7c43a8b
commit df42274d96
6 changed files with 33 additions and 0 deletions

View File

@@ -40,6 +40,7 @@ struct krb5_storage_data {
ssize_t (*store)(struct krb5_storage_data*, const void*, size_t);
off_t (*seek)(struct krb5_storage_data*, off_t, int);
int (*trunc)(struct krb5_storage_data*, off_t);
int (*fsync)(struct krb5_storage_data*);
void (*free)(struct krb5_storage_data*);
krb5_flags flags;
int eof_code;

View File

@@ -190,6 +190,25 @@ krb5_storage_truncate(krb5_storage *sp, off_t offset)
return (*sp->trunc)(sp, offset);
}
/**
* Sync the storage buffer to its backing store. If there is no
* backing store this function will return success.
*
* @param sp the storage buffer to sync
*
* @return A Kerberos 5 error code
*
* @ingroup krb5_storage
*/
KRB5_LIB_FUNCTION int KRB5_LIB_CALL
krb5_storage_fsync(krb5_storage *sp)
{
if (sp->fsync != NULL)
return sp->fsync(sp);
return 0;
}
/**
* Read to the storage buffer.
*

View File

@@ -189,6 +189,7 @@ krb5_storage_emem(void)
sp->store = emem_store;
sp->seek = emem_seek;
sp->trunc = emem_trunc;
sp->fsync = NULL;
sp->free = emem_free;
sp->max_alloc = UINT_MAX/8;
return sp;

View File

@@ -66,6 +66,14 @@ fd_trunc(krb5_storage * sp, off_t offset)
return 0;
}
static int
fd_sync(krb5_storage * sp)
{
if (fsync(FD(sp)) == -1)
return errno;
return 0;
}
static void
fd_free(krb5_storage * sp)
{
@@ -134,6 +142,7 @@ krb5_storage_from_fd(krb5_socket_t fd_in)
sp->store = fd_store;
sp->seek = fd_seek;
sp->trunc = fd_trunc;
sp->fsync = fd_sync;
sp->free = fd_free;
sp->max_alloc = UINT_MAX/8;
return sp;

View File

@@ -144,6 +144,7 @@ krb5_storage_from_mem(void *buf, size_t len)
sp->store = mem_store;
sp->seek = mem_seek;
sp->trunc = mem_trunc;
sp->fsync = NULL;
sp->free = NULL;
sp->max_alloc = UINT_MAX/8;
return sp;
@@ -203,6 +204,7 @@ krb5_storage_from_readonly_mem(const void *buf, size_t len)
sp->store = mem_no_store;
sp->seek = mem_seek;
sp->trunc = mem_no_trunc;
sp->fsync = NULL;
sp->free = NULL;
sp->max_alloc = UINT_MAX/8;
return sp;

View File

@@ -600,6 +600,7 @@ HEIMDAL_KRB5_2.0 {
krb5_storage_from_fd;
krb5_storage_from_mem;
krb5_storage_from_readonly_mem;
krb5_storage_fsync;
krb5_storage_get_byteorder;
krb5_storage_get_eof_code;
krb5_storage_is_flags;