# In debug statements, print flags as bitmask and mode_t as octal.
sc_flags_debug:
@prohibit='\<mode=%[0-9.]*[diux]' \
- halt='debug mode_t values with %o' \
+ halt='use %o to debug mode_t values' \
$(_sc_search_regexp)
- @prohibit='\<flags=%[0-9.]*l*[diou]' \
- halt='debug flag values with %x' \
+ @prohibit='[Ff]lags=%[0-9.]*l*[diou]' \
+ halt='use %x to debug flag values' \
+ $(_sc_search_regexp)
+
+# Prefer 'unsigned int flags', along with checks for unknown flags.
+# For historical reasons, we are stuck with 'unsigned long flags' in
+# migration, so check for those known 4 instances and no more in public
+# API. Also check that no flags are marked unused, and 'unsigned' should
+# appear before any declaration of a flags variable (achieved by
+# prohibiting the word prior to the type from ending in anything other
+# than d). The existence of long long, and of documentation about
+# flags, makes the regex in the third test slightly harder.
+sc_flags_usage:
+ @test "$$(cat $(srcdir)/include/libvirt/libvirt.h.in \
+ $(srcdir)/include/libvirt/virterror.h \
+ $(srcdir)/include/libvirt/libvirt-qemu.h \
+ | grep -c '\(long\|unsigned\) flags')" != 4 && \
+ { echo '$(ME): new API should use "unsigned int flags"' 1>&2; \
+ exit 1; } || :
+ @prohibit=' flags ''ATTRIBUTE_UNUSED' \
+ halt='flags should be checked with virCheckFlags' \
+ $(_sc_search_regexp)
+ @prohibit='^[^@]*([^d] (int|long long)|[^dg] long) flags[;,)]' \
+ halt='flags should be unsigned' \
$(_sc_search_regexp)
# Avoid functions that can lead to double-close bugs.
exclude_file_name_regexp--sc_bindtextdomain = ^(tests|examples)/
-exclude_file_name_regexp--sc_flags_debug = ^docs/
+exclude_file_name_regexp--sc_flags_usage = ^docs/
exclude_file_name_regexp--sc_libvirt_unmarked_diagnostics = \
^src/rpc/gendispatch\.pl$$
const char *path,
unsigned long long offset,
unsigned long long length,
- int flags,
+ int oflags,
int mode,
bool delete)
{
virCommandPtr cmd = NULL;
int errfd = -1;
- VIR_DEBUG("st=%p path=%s flags=%x offset=%llu length=%llu mode=%o delete=%d",
- st, path, flags, offset, length, mode, delete);
+ VIR_DEBUG("st=%p path=%s oflags=%x offset=%llu length=%llu mode=%o delete=%d",
+ st, path, oflags, offset, length, mode, delete);
- if (flags & O_CREAT)
- fd = open(path, flags, mode);
+ if (oflags & O_CREAT)
+ fd = open(path, oflags, mode);
else
- fd = open(path, flags);
+ fd = open(path, oflags);
if (fd < 0) {
virReportSystemError(errno,
_("Unable to open stream for '%s'"),
!S_ISFIFO(sb.st_mode))) {
int childfd;
- if ((flags & O_RDWR) == O_RDWR) {
+ if ((oflags & O_RDWR) == O_RDWR) {
streamsReportError(VIR_ERR_INTERNAL_ERROR,
_("%s: Cannot request read and write flags together"),
path);
cmd = virCommandNewArgList(LIBEXECDIR "/libvirt_iohelper",
path,
NULL);
- virCommandAddArgFormat(cmd, "%d", flags);
+ virCommandAddArgFormat(cmd, "%d", oflags);
virCommandAddArgFormat(cmd, "%d", mode);
virCommandAddArgFormat(cmd, "%llu", offset);
virCommandAddArgFormat(cmd, "%llu", length);
*/
delete = false;
- if (flags == O_RDONLY) {
+ if (oflags == O_RDONLY) {
childfd = fds[1];
fd = fds[0];
virCommandSetOutputFD(cmd, &childfd);
const char *path,
unsigned long long offset,
unsigned long long length,
- int flags,
+ int oflags,
bool delete)
{
- if (flags & O_CREAT) {
+ if (oflags & O_CREAT) {
streamsReportError(VIR_ERR_INTERNAL_ERROR,
_("Attempt to create %s without specifying mode"),
path);
}
return virFDStreamOpenFileInternal(st, path,
offset, length,
- flags, 0, delete);
+ oflags, 0, delete);
}
int virFDStreamCreateFile(virStreamPtr st,
const char *path,
unsigned long long offset,
unsigned long long length,
- int flags,
+ int oflags,
mode_t mode,
bool delete)
{
return virFDStreamOpenFileInternal(st, path,
offset, length,
- flags | O_CREAT,
+ oflags | O_CREAT,
mode, delete);
}
/*
* fdstream.h: generic streams impl for file descriptors
*
- * Copyright (C) 2009-2010 Red Hat, Inc.
+ * Copyright (C) 2009-2011 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
const char *path,
unsigned long long offset,
unsigned long long length,
- int flags,
+ int oflags,
bool delete);
int virFDStreamCreateFile(virStreamPtr st,
const char *path,
unsigned long long offset,
unsigned long long length,
- int flags,
+ int oflags,
mode_t mode,
bool delete);
unsigned int type ATTRIBUTE_UNUSED,
size_t nparams ATTRIBUTE_UNUSED,
virLockManagerParamPtr params ATTRIBUTE_UNUSED,
- unsigned int flags ATTRIBUTE_UNUSED)
+ unsigned int flags_unused ATTRIBUTE_UNUSED)
{
return 0;
}
const char *name ATTRIBUTE_UNUSED,
size_t nparams ATTRIBUTE_UNUSED,
virLockManagerParamPtr params ATTRIBUTE_UNUSED,
- unsigned int flags ATTRIBUTE_UNUSED)
+ unsigned int flags_unused ATTRIBUTE_UNUSED)
{
return 0;
static int virLockManagerNopAcquire(virLockManagerPtr lock ATTRIBUTE_UNUSED,
const char *state ATTRIBUTE_UNUSED,
- unsigned int flags ATTRIBUTE_UNUSED,
+ unsigned int flags_unused ATTRIBUTE_UNUSED,
int *fd ATTRIBUTE_UNUSED)
{
return 0;
static int virLockManagerNopRelease(virLockManagerPtr lock ATTRIBUTE_UNUSED,
char **state,
- unsigned int flags ATTRIBUTE_UNUSED)
+ unsigned int flags_unused ATTRIBUTE_UNUSED)
{
if (state)
*state = NULL;
static int virLockManagerNopInquire(virLockManagerPtr lock ATTRIBUTE_UNUSED,
char **state,
- unsigned int flags ATTRIBUTE_UNUSED)
+ unsigned int flags_unused ATTRIBUTE_UNUSED)
{
if (state)
*state = NULL;
return NULL;
}
#else /* !HAVE_DLFCN_H */
-virLockManagerPluginPtr virLockManagerPluginNew(const char *name ATTRIBUTE_UNUSED,
- const char *configFile ATTRIBUTE_UNUSED,
- unsigned int flags ATTRIBUTE_UNUSED)
+virLockManagerPluginPtr
+virLockManagerPluginNew(const char *name ATTRIBUTE_UNUSED,
+ const char *configFile ATTRIBUTE_UNUSED,
+ unsigned int flags_unused ATTRIBUTE_UNUSED)
{
virLockError(VIR_ERR_INTERNAL_ERROR, "%s",
_("this platform is missing dlopen"));
int infd ATTRIBUTE_UNUSED,
int *outfd ATTRIBUTE_UNUSED,
int *errfd ATTRIBUTE_UNUSED,
- int flags ATTRIBUTE_UNUSED,
+ int flags_unused ATTRIBUTE_UNUSED,
virExecHook hook ATTRIBUTE_UNUSED,
void *data ATTRIBUTE_UNUSED,
char *pidfile ATTRIBUTE_UNUSED)
#define VIR_FROM_THIS VIR_FROM_STORAGE
static int runIO(const char *path,
- int flags,
+ int oflags,
int mode,
unsigned long long offset,
unsigned long long length)
const char *fdinname, *fdoutname;
unsigned long long total = 0;
- if (flags & O_CREAT) {
- fd = open(path, flags, mode);
+ if (oflags & O_CREAT) {
+ fd = open(path, oflags, mode);
} else {
- fd = open(path, flags);
+ fd = open(path, oflags);
}
if (fd < 0) {
virReportSystemError(errno, _("Unable to open %s"), path);
goto cleanup;
}
- switch (flags & O_ACCMODE) {
+ switch (oflags & O_ACCMODE) {
case O_RDONLY:
fdin = fd;
fdinname = path;
default:
virReportSystemError(EINVAL,
_("Unable to process file with flags %d"),
- (flags & O_ACCMODE));
+ (oflags & O_ACCMODE));
goto cleanup;
}
virErrorPtr err;
unsigned long long offset;
unsigned long long length;
- int flags;
+ int oflags;
int mode;
unsigned int delete;
path = argv[1];
- if (virStrToLong_i(argv[2], NULL, 10, &flags) < 0) {
+ if (virStrToLong_i(argv[2], NULL, 10, &oflags) < 0) {
fprintf(stderr, _("%s: malformed file flags %s"), argv[0], argv[2]);
exit(EXIT_FAILURE);
}
exit(EXIT_FAILURE);
}
- if (runIO(path, flags, mode, offset, length) < 0)
+ if (runIO(path, oflags, mode, offset, length) < 0)
goto error;
if (delete)
#ifndef WIN32
int virSetInherit(int fd, bool inherit) {
- int flags;
- if ((flags = fcntl(fd, F_GETFD)) < 0)
+ int fflags;
+ if ((fflags = fcntl(fd, F_GETFD)) < 0)
return -1;
if (inherit)
- flags &= ~FD_CLOEXEC;
+ fflags &= ~FD_CLOEXEC;
else
- flags |= FD_CLOEXEC;
- if ((fcntl(fd, F_SETFD, flags)) < 0)
+ fflags |= FD_CLOEXEC;
+ if ((fcntl(fd, F_SETFD, fflags)) < 0)
return -1;
return 0;
}
mode_t mode ATTRIBUTE_UNUSED,
uid_t uid ATTRIBUTE_UNUSED,
gid_t gid ATTRIBUTE_UNUSED,
- unsigned int flags ATTRIBUTE_UNUSED)
+ unsigned int flags_unused ATTRIBUTE_UNUSED)
{
virUtilError(VIR_ERR_INTERNAL_ERROR,
"%s", _("virFileOpenAs is not implemented for WIN32"));
mode_t mode ATTRIBUTE_UNUSED,
uid_t uid ATTRIBUTE_UNUSED,
gid_t gid ATTRIBUTE_UNUSED,
- unsigned int flags ATTRIBUTE_UNUSED)
+ unsigned int flags_unused ATTRIBUTE_UNUSED)
{
virUtilError(VIR_ERR_INTERNAL_ERROR,
"%s", _("virDirCreate is not implemented for WIN32"));