halt='use virCommand for child processes' \
$(_sc_search_regexp)
+# access with X_OK accepts directories, but we can't exec() those.
+# access with F_OK or R_OK is okay, though.
+sc_prohibit_access_xok:
+ @prohibit='access''(at)? *\(.*X_OK' \
+ halt='use virFileIsExecutable instead of access''(,X_OK)' \
+ $(_sc_search_regexp)
+
# Similar to the gnulib maint.mk rule for sc_prohibit_strcmp
# Use STREQLEN or STRPREFIX rather than comparing strncmp == 0, or != 0.
sc_prohibit_strncmp:
exclude_file_name_regexp--sc_prohibit_VIR_ERR_NO_MEMORY = \
^(include/libvirt/virterror\.h|daemon/dispatch\.c|src/util/virterror\.c)$$
+exclude_file_name_regexp--sc_prohibit_access_xok = ^src/util/util\.c$$
+
exclude_file_name_regexp--sc_prohibit_always_true_header_tests = \
(^docs|^python/(libvirt-override|typewrappers)\.c$$)
network->radvdPid = -1;
- if (access(RADVD, X_OK) < 0) {
+ if (!virFileIsExecutable(RADVD)) {
virReportSystemError(errno,
_("Cannot find %s - "
"Possibly the package isn't installed"),
* Technically we could catch the exec() failure, but that's
* in a sub-process so it's hard to feed back a useful error.
*/
- if (access(binary, X_OK) < 0) {
+ if (!virFileIsExecutable(binary)) {
virReportSystemError(errno, _("Cannot find QEMU binary %s"), binary);
return -1;
}
*/
binary = virFindFileInPath(info->binary);
- if (binary == NULL || access(binary, X_OK) != 0) {
+ if (binary == NULL || !virFileIsExecutable(binary)) {
VIR_FREE(binary);
binary = virFindFileInPath(info->altbinary);
-
- if (binary != NULL && access(binary, X_OK) != 0)
- VIR_FREE(binary);
}
/* Can use acceleration for KVM/KQEMU if
for (i = 0; i < ARRAY_CARDINALITY(kvmbins); ++i) {
kvmbin = virFindFileInPath(kvmbins[i]);
- if (kvmbin == NULL || access(kvmbin, X_OK) != 0) {
- VIR_FREE(kvmbin);
+ if (!kvmbin)
continue;
- }
haskvm = 1;
if (!binary)
/* Then possibly the Xen paravirt guests (ie Xenner */
xenner = virFindFileInPath("xenner");
- if (xenner != NULL && access(xenner, X_OK) == 0 &&
+ if (xenner != NULL && virFileIsExecutable(xenner) == 0 &&
access("/dev/kvm", F_OK) == 0) {
for (i = 0 ; i < ARRAY_CARDINALITY(arch_info_xen) ; i++)
/* Allow Xen 32-on-32, 32-on-64 and 64-on-64 */
* Technically we could catch the exec() failure, but that's
* in a sub-process so it's hard to feed back a useful error.
*/
- if (access(qemu, X_OK) < 0) {
+ if (!virFileIsExecutable(qemu)) {
virReportSystemError(errno, _("Cannot find QEMU binary %s"), qemu);
return -1;
}
return(customDaemon);
for (i = 0; serverPaths[i]; i++) {
- if (access(serverPaths[i], X_OK | R_OK) == 0) {
+ if (virFileIsExecutable(serverPaths[i])) {
return serverPaths[i];
}
}
* Technically we could catch the exec() failure, but that's
* in a sub-process so its hard to feed back a useful error
*/
- if (access(vm->def->os.kernel, X_OK) < 0) {
+ if (!virFileIsExecutable(vm->def->os.kernel)) {
virReportSystemError(errno,
_("Cannot find UML kernel %s"),
vm->def->os.kernel);
/*
* hooks.c: implementation of the synchronous hooks support
*
- * Copyright (C) 2010 Red Hat, Inc.
+ * Copyright (C) 2010-2011 Red Hat, Inc.
* Copyright (C) 2010 Daniel Veillard
*
* This library is free software; you can redistribute it and/or
static int
virHookCheck(int no, const char *driver) {
char *path;
- struct stat sb;
int ret;
if (driver == NULL) {
virHookReportError(VIR_ERR_INTERNAL_ERROR,
_("Invalid hook name for #%d"), no);
- return(-1);
+ return -1;
}
ret = virBuildPath(&path, LIBVIRT_HOOK_DIR, driver);
virHookReportError(VIR_ERR_INTERNAL_ERROR,
_("Failed to build path for %s hook"),
driver);
- return(-1);
+ return -1;
}
- if (stat(path, &sb) < 0) {
+ if (!virFileIsExecutable(path)) {
ret = 0;
- VIR_DEBUG("No hook script %s", path);
+ VIR_WARN("Missing or non-executable hook script %s", path);
} else {
- if ((access(path, X_OK) != 0) || (!S_ISREG(sb.st_mode))) {
- ret = 0;
- VIR_WARN("Non executable hook script %s", path);
- } else {
- ret = 1;
- VIR_DEBUG("Found hook script %s", path);
- }
+ ret = 1;
+ VIR_DEBUG("Found hook script %s", path);
}
VIR_FREE(path);
- return(ret);
+ return ret;
}
/*