2010-10-19 14:23:51 +00:00
|
|
|
/*
|
2011-07-19 18:32:58 +00:00
|
|
|
* virfile.h: safer file handling
|
2010-10-19 14:23:51 +00:00
|
|
|
*
|
2011-07-19 18:17:22 +00:00
|
|
|
* Copyright (C) 2010-2011 Red Hat, Inc.
|
2010-10-19 14:23:51 +00:00
|
|
|
* Copyright (C) 2010 IBM Corporation
|
|
|
|
* Copyright (C) 2010 Stefan Berger
|
|
|
|
* Copyright (C) 2010 Eric Blake
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef __VIR_FILES_H_
|
|
|
|
# define __VIR_FILES_H_
|
|
|
|
|
2010-11-17 02:13:29 +00:00
|
|
|
# include <stdio.h>
|
2010-10-19 14:23:51 +00:00
|
|
|
|
|
|
|
# include "internal.h"
|
|
|
|
# include "ignore-value.h"
|
|
|
|
|
|
|
|
|
2010-11-17 02:13:29 +00:00
|
|
|
/* Don't call these directly - use the macros below */
|
2011-07-19 18:32:58 +00:00
|
|
|
int virFileClose(int *fdptr, bool preserve_errno) ATTRIBUTE_RETURN_CHECK;
|
|
|
|
int virFileFclose(FILE **file, bool preserve_errno) ATTRIBUTE_RETURN_CHECK;
|
|
|
|
FILE *virFileFdopen(int *fdptr, const char *mode) ATTRIBUTE_RETURN_CHECK;
|
2010-10-19 14:23:51 +00:00
|
|
|
|
|
|
|
/* For use on normal paths; caller must check return value,
|
maint: reject raw close, popen in 'make syntax-check'
commit f1fe9671e was supposed to make sure we use files.h
macros to avoid double close, but it didn't work.
Meanwhile, virCommand is vastly superior to system(), fork(),
and popen() (also to virExec, but we haven't completed that
conversion), so enforce that, too.
* cfg.mk (sc_prohibit_close): Fix typo that excluded close, and
add pclose.
(sc_prohibit_fork_wrappers): New rule, for fork, system, and popen.
* .x-sc_prohibit_close: More exemptions.
* .x-sc_prohibit_fork_wrappers: New file.
* Makefile.am (syntax_check_exceptions): Ship new file.
* src/datatypes.c (virReleaseConnect): Tweak comment to avoid
false positive.
* src/util/files.h (VIR_CLOSE): Likewise.
2011-01-27 22:16:14 +00:00
|
|
|
and failure sets errno per close. */
|
2011-07-19 18:32:58 +00:00
|
|
|
# define VIR_CLOSE(FD) virFileClose(&(FD), false)
|
|
|
|
# define VIR_FCLOSE(FILE) virFileFclose(&(FILE), false)
|
2010-11-17 02:13:29 +00:00
|
|
|
|
|
|
|
/* Wrapper around fdopen that consumes fd on success. */
|
2011-07-19 18:32:58 +00:00
|
|
|
# define VIR_FDOPEN(FD, MODE) virFileFdopen(&(FD), MODE)
|
2010-10-19 14:23:51 +00:00
|
|
|
|
|
|
|
/* For use on cleanup paths; errno is unaffected by close,
|
|
|
|
and no return value to worry about. */
|
2011-07-19 18:32:58 +00:00
|
|
|
# define VIR_FORCE_CLOSE(FD) ignore_value(virFileClose(&(FD), true))
|
|
|
|
# define VIR_FORCE_FCLOSE(FILE) ignore_value(virFileFclose(&(FILE), true))
|
2010-10-19 14:23:51 +00:00
|
|
|
|
2011-07-11 21:26:33 +00:00
|
|
|
/* Opaque type for managing a wrapper around an O_DIRECT fd. */
|
|
|
|
struct _virFileDirectFd;
|
|
|
|
|
|
|
|
typedef struct _virFileDirectFd virFileDirectFd;
|
|
|
|
typedef virFileDirectFd *virFileDirectFdPtr;
|
|
|
|
|
|
|
|
int virFileDirectFdFlag(void);
|
|
|
|
|
|
|
|
virFileDirectFdPtr virFileDirectFdNew(int *fd, const char *name)
|
|
|
|
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK;
|
|
|
|
|
|
|
|
int virFileDirectFdClose(virFileDirectFdPtr dfd);
|
|
|
|
|
|
|
|
void virFileDirectFdFree(virFileDirectFdPtr dfd);
|
|
|
|
|
2010-10-19 14:23:51 +00:00
|
|
|
#endif /* __VIR_FILES_H */
|