2012-06-22 10:05:41 +01:00
|
|
|
#include "status.h"
|
|
|
|
#include "serve.h"
|
|
|
|
#include "util.h"
|
|
|
|
|
|
|
|
struct status * status_create( struct server * serve )
|
|
|
|
{
|
|
|
|
NULLCHECK( serve );
|
|
|
|
struct status * status;
|
2012-10-09 17:20:39 +01:00
|
|
|
|
2012-06-22 10:05:41 +01:00
|
|
|
status = xmalloc( sizeof( struct status ) );
|
2012-07-16 11:50:59 +01:00
|
|
|
status->pid = getpid();
|
2012-10-09 17:35:20 +01:00
|
|
|
status->has_control = serve->success;
|
2012-06-22 10:05:41 +01:00
|
|
|
status->is_mirroring = NULL != serve->mirror;
|
|
|
|
return status;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#define BOOL_S(var) (var ? "true" : "false" )
|
2012-07-16 11:50:59 +01:00
|
|
|
#define PRINT_BOOL( var ) \
|
2012-06-22 10:05:41 +01:00
|
|
|
do{dprintf( fd, #var "=%s ", BOOL_S( status->var ) );}while(0)
|
2012-07-16 11:50:59 +01:00
|
|
|
#define PRINT_INT( var ) \
|
|
|
|
do{dprintf( fd, #var "=%d ", status->var );}while(0)
|
2012-06-22 10:05:41 +01:00
|
|
|
|
|
|
|
int status_write( struct status * status, int fd )
|
|
|
|
{
|
2012-07-16 11:50:59 +01:00
|
|
|
PRINT_INT( pid );
|
|
|
|
PRINT_BOOL( is_mirroring );
|
|
|
|
PRINT_BOOL( has_control );
|
2012-06-22 10:05:41 +01:00
|
|
|
dprintf(fd, "\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void status_destroy( struct status * status )
|
|
|
|
{
|
|
|
|
NULLCHECK( status );
|
|
|
|
free( status );
|
|
|
|
}
|