halt="don't use ctype.h; instead, use c-ctype.h" \
$(_sc_search_regexp)
+# Insist on correct types for [pug]id.
+sc_correct_id_types:
+ @prohibit='\<(int|long) *[pug]id\>' \
+ halt="use pid_t for pid, uid_t for uid, gid_t for gid" \
+ $(_sc_search_regexp)
+
# Ensure that no C source file, docs, or rng schema uses TABs for
# indentation. Also match *.h.in files, to get libvirt.h.in. Exclude
# files in gnulib, since they're imported.
/*
* libvirtd.c: daemon start of day, guest process & i/o management
*
- * Copyright (C) 2006-2011 Red Hat, Inc.
+ * Copyright (C) 2006-2012 Red Hat, Inc.
* Copyright (C) 2006 Daniel P. Berrange
*
* This library is free software; you can redistribute it and/or
if (pipe(statuspipe) < 0)
return -1;
- int pid = fork();
+ pid_t pid = fork();
switch (pid) {
case 0:
{
* Description: Provides the interfaces of the libvirt library to handle
* qemu specific methods
*
- * Copy: Copyright (C) 2010 Red Hat, Inc.
+ * Copy: Copyright (C) 2010, 2012 Red Hat, Inc.
*
* See COPYING.LIB for the License of this software
*
char **result, unsigned int flags);
virDomainPtr virDomainQemuAttach(virConnectPtr domain,
- unsigned int pid,
+ unsigned int pid_value,
unsigned int flags);
# ifdef __cplusplus
virMutex lock;
int refs;
- int pid;
+ pid_t pid;
virDomainStateReason state;
unsigned int autostart : 1;
} else {
char *end = NULL;
perms->mode = strtol(mode, &end, 8);
- if (*end || perms->mode < 0 || perms->mode > 0777) {
+ if (*end || (perms->mode & ~0777)) {
VIR_FREE(mode);
virStorageReportError(VIR_ERR_XML_ERROR,
"%s", _("malformed octal mode"));
typedef struct _virStoragePerms virStoragePerms;
typedef virStoragePerms *virStoragePermsPtr;
struct _virStoragePerms {
- int mode;
- int uid;
- int gid;
+ mode_t mode;
+ uid_t uid;
+ gid_t gid;
char *label;
};
(*virDrvDomainQemuMonitorCommand)(virDomainPtr domain, const char *cmd,
char **result, unsigned int flags);
+/* Choice of unsigned int rather than pid_t is intentional. */
typedef virDomainPtr
(*virDrvDomainQemuAttach)(virConnectPtr conn,
- unsigned int pid,
+ unsigned int pid_value,
unsigned int flags);
typedef int
* libvirt-qemu.c: Interfaces for the libvirt library to handle qemu-specific
* APIs.
*
- * Copyright (C) 2010-2011 Red Hat, Inc.
+ * Copyright (C) 2010-2012 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
/**
* virDomainQemuAttach:
* @conn: pointer to a hypervisor connection
- * @pid: the UNIX process ID of the external QEMU process
+ * @pid_value: the UNIX process ID of the external QEMU process
* @flags: optional flags, currently unused
*
* This API is QEMU specific, so it will only work with hypervisor
* - The '-name' and '-uuid' arguments should have been set (not
* mandatory, but strongly recommended)
*
+ * To date, the only platforms we know of where pid_t is larger than
+ * unsigned int (64-bit Windows) also lack UNIX sockets, so the choice
+ * of @pid_value as an unsigned int should not present any difficulties.
+ *
* If successful, then the guest will appear in the list of running
* domains for this connection, and other APIs should operate
* normally (provided the above requirements were honored).
*/
virDomainPtr
virDomainQemuAttach(virConnectPtr conn,
- unsigned int pid,
+ unsigned int pid_value,
unsigned int flags)
{
- VIR_DEBUG("conn=%p, pid=%u, flags=%x", conn, pid, flags);
+ pid_t pid = pid_value;
+ VIR_DEBUG("conn=%p, pid=%u, flags=%x", conn, pid_value, flags);
virResetLastError();
return NULL;
}
- if (pid <= 1) {
+ if (pid != pid_value || pid <= 1) {
virLibDomainError(domain, VIR_ERR_INVALID_ARG, __FUNCTION__);
goto error;
}
if (conn->driver->qemuDomainAttach) {
virDomainPtr ret;
- ret = conn->driver->qemuDomainAttach(conn, pid, flags);
+ ret = conn->driver->qemuDomainAttach(conn, pid_value, flags);
if (!ret)
goto error;
return ret;
# file: src/rpc/virnetsocket.c
# prefix: rpc
- probe rpc_socket_new(void *sock, int refs, int fd, int errfd, int pid, const char *localAddr, const char *remoteAddr);
+ probe rpc_socket_new(void *sock, int refs, int fd, int errfd, pid_t pid, const char *localAddr, const char *remoteAddr);
probe rpc_socket_send_fd(void *sock, int fd);
probe rpc_socket_recv_fd(void *sock, int fd);
probe rpc_socket_ref(void *sock, int refs);
}
-static int qemuParseProcFileStrings(unsigned int pid,
+static int qemuParseProcFileStrings(int pid_value,
const char *name,
const char ***list)
{
const char **str = NULL;
int i;
- if (virAsprintf(&path, "/proc/%u/%s", pid, name) < 0) {
+ if (virAsprintf(&path, "/proc/%d/%s", pid_value, name) < 0) {
virReportOOMError();
goto cleanup;
}
}
virDomainDefPtr qemuParseCommandLinePid(virCapsPtr caps,
- unsigned int pid,
+ pid_t pid,
char **pidfile,
virDomainChrSourceDefPtr *monConfig,
bool *monJSON)
char *emulator;
int i;
- if (qemuParseProcFileStrings(pid, "cmdline", &progargv) < 0 ||
+ /* The parser requires /proc/pid, which only exists on platforms
+ * like Linux where pid_t fits in int. */
+ if ((int) pid != pid ||
+ qemuParseProcFileStrings(pid, "cmdline", &progargv) < 0 ||
qemuParseProcFileStrings(pid, "environ", &progenv) < 0)
goto cleanup;
pidfile, monConfig, monJSON)))
goto cleanup;
- if (virAsprintf(&exepath, "/proc/%u/exe", pid) < 0) {
+ if (virAsprintf(&exepath, "/proc/%d/exe", (int) pid) < 0) {
virReportOOMError();
goto cleanup;
}
if (virFileResolveLink(exepath, &emulator) < 0) {
virReportSystemError(errno,
_("Unable to resolve %s for pid %u"),
- exepath, pid);
+ exepath, (int) pid);
goto cleanup;
}
VIR_FREE(def->emulator);
/*
* qemu_command.h: QEMU command generation
*
- * Copyright (C) 2006-2011 Red Hat, Inc.
+ * Copyright (C) 2006-2012 Red Hat, Inc.
* Copyright (C) 2006 Daniel P. Berrange
*
* This library is free software; you can redistribute it and/or
virDomainChrSourceDefPtr *monConfig,
bool *monJSON);
virDomainDefPtr qemuParseCommandLinePid(virCapsPtr caps,
- unsigned int pid,
+ pid_t pid,
char **pidfile,
virDomainChrSourceDefPtr *monConfig,
bool *monJSON);
static int
qemudGetProcessInfo(unsigned long long *cpuTime, int *lastCpu, long *vm_rss,
- int pid, int tid)
+ pid_t pid, int tid)
{
char *proc;
FILE *pidinfo;
int cpu;
int ret;
+ /* In general, we cannot assume pid_t fits in int; but /proc parsing
+ * is specific to Linux where int works fine. */
if (tid)
- ret = virAsprintf(&proc, "/proc/%d/task/%d/stat", pid, tid);
+ ret = virAsprintf(&proc, "/proc/%d/task/%d/stat", (int) pid, tid);
else
- ret = virAsprintf(&proc, "/proc/%d/stat", pid);
+ ret = virAsprintf(&proc, "/proc/%d/stat", (int) pid);
if (ret < 0)
return -1;
VIR_DEBUG("Got status for %d/%d user=%llu sys=%llu cpu=%d rss=%ld",
- pid, tid, usertime, systime, cpu, rss);
+ (int) pid, tid, usertime, systime, cpu, rss);
VIR_FORCE_FCLOSE(pidinfo);
static virDomainPtr qemuDomainAttach(virConnectPtr conn,
- unsigned int pid,
+ unsigned int pid_value,
unsigned int flags)
{
struct qemud_driver *driver = conn->privateData;
virDomainPtr dom = NULL;
virDomainChrSourceDefPtr monConfig = NULL;
bool monJSON = false;
+ pid_t pid = pid_value;
char *pidfile = NULL;
virCheckFlags(0, NULL);
if (!monConfig) {
qemuReportError(VIR_ERR_CONFIG_UNSUPPORTED,
- _("No monitor connection for pid %u"),
- pid);
+ _("No monitor connection for pid %u"), pid_value);
goto cleanup;
}
if (monConfig->type != VIR_DOMAIN_CHR_TYPE_UNIX) {
qemuReportError(VIR_ERR_CONFIG_UNSUPPORTED,
- _("Cannot connect to monitor connection of type '%s' for pid %u"),
- virDomainChrTypeToString(monConfig->type), pid);
+ _("Cannot connect to monitor connection of type '%s' "
+ "for pid %u"),
+ virDomainChrTypeToString(monConfig->type),
+ pid_value);
goto cleanup;
}
if (!(def->name) &&
- virAsprintf(&def->name, "attach-pid-%u", pid) < 0) {
+ virAsprintf(&def->name, "attach-pid-%u", pid_value) < 0) {
virReportOOMError();
goto cleanup;
}
int qemuProcessAttach(virConnectPtr conn ATTRIBUTE_UNUSED,
struct qemud_driver *driver,
virDomainObjPtr vm,
- int pid,
+ pid_t pid,
const char *pidfile,
virDomainChrSourceDefPtr monConfig,
bool monJSON)
int qemuProcessAttach(virConnectPtr conn,
struct qemud_driver *driver,
virDomainObjPtr vm,
- int pid,
+ pid_t pid,
const char *pidfile,
virDomainChrSourceDefPtr monConfig,
bool monJSON);
remote_nonnull_string result;
};
struct qemu_domain_attach_args {
- u_int pid;
+ u_int pid_value;
u_int flags;
};
struct qemu_domain_attach_ret {
* remote_internal driver and libvirtd. This protocol is
* internal and may change at any time.
*
- * Copyright (C) 2010-2011 Red Hat, Inc.
+ * Copyright (C) 2010-2012 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
struct qemu_domain_attach_args {
- unsigned int pid;
+ unsigned int pid_value;
unsigned int flags;
};
/*
- * Copyright (C) 2010-2011 Red Hat, Inc.
+ * Copyright (C) 2010-2012 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
}
static int
-virSecurityDACSetOwnership(const char *path, int uid, int gid)
+virSecurityDACSetOwnership(const char *path, uid_t uid, gid_t gid)
{
- VIR_INFO("Setting DAC user and group on '%s' to '%d:%d'", path, uid, gid);
+ VIR_INFO("Setting DAC user and group on '%s' to '%ld:%ld'",
+ path, (long) uid, (long) gid);
if (chown(path, uid, gid) < 0) {
struct stat sb;
}
if (chown_errno == EOPNOTSUPP || chown_errno == EINVAL) {
- VIR_INFO("Setting user and group to '%d:%d' on '%s' not supported by filesystem",
- uid, gid, path);
+ VIR_INFO("Setting user and group to '%ld:%ld' on '%s' not "
+ "supported by filesystem",
+ (long) uid, (long) gid, path);
} else if (chown_errno == EPERM) {
- VIR_INFO("Setting user and group to '%d:%d' on '%s' not permitted",
- uid, gid, path);
+ VIR_INFO("Setting user and group to '%ld:%ld' on '%s' not "
+ "permitted",
+ (long) uid, (long) gid, path);
} else if (chown_errno == EROFS) {
- VIR_INFO("Setting user and group to '%d:%d' on '%s' not possible on readonly filesystem",
- uid, gid, path);
+ VIR_INFO("Setting user and group to '%ld:%ld' on '%s' not "
+ "possible on readonly filesystem",
+ (long) uid, (long) gid, path);
} else {
virReportSystemError(chown_errno,
- _("unable to set user and group to '%d:%d' on '%s'"),
- uid, gid, path);
+ _("unable to set user and group to '%ld:%ld' "
+ "on '%s'"),
+ (long) uid, (long) gid, path);
return -1;
}
}
/*
* uml_driver.c: core driver methods for managing UML guests
*
- * Copyright (C) 2006-2011 Red Hat, Inc.
+ * Copyright (C) 2006-2012 Red Hat, Inc.
* Copyright (C) 2006-2008 Daniel P. Berrange
*
* This library is free software; you can redistribute it and/or
-static int umlGetProcessInfo(unsigned long long *cpuTime, int pid)
+static int umlGetProcessInfo(unsigned long long *cpuTime, pid_t pid)
{
char *proc;
FILE *pidinfo;
unsigned long long usertime, systime;
- if (virAsprintf(&proc, "/proc/%d/stat", pid) < 0) {
+ if (virAsprintf(&proc, "/proc/%lld/stat", (long long) pid) < 0) {
return -1;
}
goto cleanup;
} else {
while (!feof(fp)) {
- unsigned long pid;
- if (fscanf(fp, "%lu", &pid) != 1) {
+ unsigned long pid_value;
+ if (fscanf(fp, "%lu", &pid_value) != 1) {
if (feof(fp))
break;
rc = -errno;
VIR_DEBUG("Failed to read %s: %m\n", keypath);
goto cleanup;
}
- if (virHashLookup(pids, (void*)pid))
+ if (virHashLookup(pids, (void*)pid_value))
continue;
- VIR_DEBUG("pid=%lu", pid);
- if (kill((pid_t)pid, signum) < 0) {
+ VIR_DEBUG("pid=%lu", pid_value);
+ /* Cgroups is a Linux concept, so this cast is safe. */
+ if (kill((pid_t)pid_value, signum) < 0) {
if (errno != ESRCH) {
rc = -errno;
goto cleanup;
done = false;
}
- ignore_value(virHashAddEntry(pids, (void*)pid, (void*)1));
+ ignore_value(virHashAddEntry(pids, (void*)pid_value, (void*)1));
}
VIR_FORCE_FCLOSE(fp);
}
static uint32_t virCgroupPidCode(const void *name, uint32_t seed)
{
- unsigned long pid = (unsigned long)(intptr_t)name;
- return virHashCodeGen(&pid, sizeof(pid), seed);
+ unsigned long pid_value = (unsigned long)(intptr_t)name;
+ return virHashCodeGen(&pid_value, sizeof(pid_value), seed);
}
static bool virCgroupPidEqual(const void *namea, const void *nameb)
{
*
* Returns 0 on success or -1 in case of error
*/
-int virNetDevSetNamespace(const char *ifname, int pidInNs)
+int virNetDevSetNamespace(const char *ifname, pid_t pidInNs)
{
int rc;
char *pid = NULL;
"ip", "link", "set", ifname, "netns", NULL, NULL
};
- if (virAsprintf(&pid, "%d", pidInNs) == -1) {
+ if (virAsprintf(&pid, "%lld", (long long) pidInNs) == -1) {
virReportOOMError();
return -1;
}
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK;
int virNetDevGetMTU(const char *ifname)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURN_CHECK;
-int virNetDevSetNamespace(const char *ifname, int pidInNs)
+int virNetDevSetNamespace(const char *ifname, pid_t pidInNs)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURN_CHECK;
int virNetDevSetName(const char *ifname, const char *newifname)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK;
/*---------------------------------------------------------------------------*/
/*
- * Copyright (C) 2011 Red Hat, Inc.
+ * Copyright (C) 2011-2012 Red Hat, Inc.
* Copyright 2010, diateam (www.diateam.net)
*
* This library is free software; you can redistribute it and/or
FILE *logFile = NULL;
char line[1024];
char *tmp = NULL;
- int pid = -1;
+ int pid_value = -1;
if ((vmxDir = mdir_name(vmxPath)) == NULL)
goto cleanup;
tmp += strlen(" pid=");
- if (virStrToLong_i(tmp, &tmp, 10, &pid) < 0 || *tmp != ' ') {
+ /* Although 64-bit windows allows 64-bit pid_t, a domain id has to be
+ * 32 bits. For now, we just reject pid values that overflow int. */
+ if (virStrToLong_i(tmp, &tmp, 10, &pid_value) < 0 || *tmp != ' ') {
vmwareError(VIR_ERR_INTERNAL_ERROR, "%s",
_("cannot parse pid in vmware log file"));
goto cleanup;
VIR_FREE(vmxDir);
VIR_FREE(logFilePath);
VIR_FORCE_FCLOSE(logFile);
- return pid;
+ return pid_value;
}
char *
if (pipe(pipefd) < 0)
return -1;
- int pid = fork();
+ pid_t pid = fork();
switch (pid) {
case 0:
VIR_FORCE_CLOSE(pipefd[0]);
virDomainPtr dom = NULL;
bool ret = false;
unsigned int flags = 0;
- unsigned int pid;
+ unsigned int pid_value; /* API uses unsigned int, not pid_t */
if (!vshConnectionUsability(ctl, ctl->conn))
goto cleanup;
- if (vshCommandOptUInt(cmd, "pid", &pid) <= 0) {
+ if (vshCommandOptUInt(cmd, "pid", &pid_value) <= 0) {
vshError(ctl, "%s", _("missing pid value"));
goto cleanup;
}
- if (!(dom = virDomainQemuAttach(ctl->conn, pid, flags)))
+ if (!(dom = virDomainQemuAttach(ctl->conn, pid_value, flags)))
goto cleanup;
if (dom != NULL) {
vshPrint(ctl, _("Domain %s attached to pid %u\n"),
- virDomainGetName(dom), pid);
+ virDomainGetName(dom), pid_value);
virDomainFree(dom);
ret = true;
} else {
- vshError(ctl, _("Failed to attach to pid %u"), pid);
+ vshError(ctl, _("Failed to attach to pid %u"), pid_value);
}
cleanup: