lxcfs_info("Kernel does not support swap accounting");
lxcfs_info("api_extensions:");
- for (i = 0; i < nr_api_extensions; i++)
- lxcfs_info("- %s", api_extensions[i]);
+ for (size_t nr = 0; nr < nr_api_extensions; nr++)
+ lxcfs_info("- %s", api_extensions[nr]);
root_fd = open("/", O_PATH | O_CLOEXEC);
if (root_fd < 0)
* pid's namespace.
* Returns the mapped id, or -1 on error.
*/
-static unsigned int convert_id_to_ns(FILE *idfile, unsigned int in_id)
+static int convert_id_to_ns(FILE *idfile, unsigned int in_id)
{
unsigned int nsuid, // base id for a range in the idfile's namespace
hostuid, // base id for a range in the caller's namespace
static bool is_privileged_over(pid_t pid, uid_t uid, uid_t victim, bool req_ns_root)
{
+ FILE *f;
char fpath[PROCLEN];
int ret;
bool answer = false;
uid_t nsuid;
- if (victim == -1 || uid == -1)
+ if (victim == (uid_t)-1 || uid == (uid_t)-1)
return false;
/*
ret = snprintf(fpath, PROCLEN, "/proc/%d/uid_map", pid);
if (ret < 0 || ret >= PROCLEN)
return false;
- FILE *f = fopen(fpath, "re");
+
+ f = fopen(fpath, "re");
if (!f)
return false;
* will be sending requests where the vfs has converted
*/
nsuid = convert_id_to_ns(f, victim);
- if (nsuid == -1)
+ if (nsuid == (uid_t)-1)
goto out;
answer = true;
char v;
ret = snprintf(fnam, sizeof(fnam), "/proc/%d/ns/pid", tpid);
- if (ret < 0 || ret >= sizeof(fnam))
+ if (ret < 0 || (size_t)ret >= sizeof(fnam))
_exit(1);
newnsfd = open(fnam, O_RDONLY);
if (newnsfd < 0)
struct file_info *f = INTTYPE_TO_PTR(fi->fh);
struct cgfs_files *k = NULL;
char *data = NULL;
- int ret, s;
+ int ret;
+ size_t s;
bool r;
if (!liblxcfs_functional())
if (s > size)
s = size;
memcpy(buf, data, s);
- if (s > 0 && s < size && data[s-1] != '\n')
+ if ((s > 0) && (s < size) && (data[s - 1] != '\n'))
buf[s++] = '\n';
ret = s;
char v;
ret = snprintf(fnam, sizeof(fnam), "/proc/%d/ns/pid", tpid);
- if (ret < 0 || ret >= sizeof(fnam))
+ if (ret < 0 || (size_t)ret >= sizeof(fnam))
_exit(1);
newnsfd = open(fnam, O_RDONLY);
if (newnsfd < 0)
*answer = convert_id_to_ns(f, uid);
fclose(f);
- if (*answer == -1)
+ if (*answer == (uid_t)-1)
return false;
return true;
}
__do_free char *path = NULL;
int cfd;
size_t len;
+ ssize_t ret;
cfd = get_cgroup_fd_handle_named(controller);
if (cfd < 0)
return false;
len = strlen(value);
- return write_nointr(fd, value, len) == len;
+ ret = write_nointr(fd, value, len);
+ if (ret < 0)
+ return false;
+
+ return (size_t)ret == len;
}
__lxcfs_fuse_ops int cg_write(const char *path, const char *buf, size_t size,
continue;
ret = snprintf(pathname, sizeof(pathname), "%s/%s", path, dirent->d_name);
- if (ret < 0 || ret >= sizeof(pathname)) {
+ if (ret < 0 || (size_t)ret >= sizeof(pathname)) {
lxcfs_error("Pathname too long under %s\n", path);
continue;
}
#else
ret = snprintf(lxcfs_lib_path, sizeof(lxcfs_lib_path), "/usr/local/lib/lxcfs/liblxcfs.so");
#endif
- if (ret < 0 || ret >= sizeof(lxcfs_lib_path))
+ if (ret < 0 || (size_t)ret >= sizeof(lxcfs_lib_path))
log_exit("Failed to create path to open liblxcfs");
dlopen_handle = dlopen(lxcfs_lib_path, RTLD_LAZY);
return log_error(-1, "Error truncating PID file '%s': %m", pidfile);
ret = snprintf(buf, sizeof(buf), "%ld\n", (long)getpid());
- if (ret < 0 || ret >= sizeof(buf))
+ if (ret < 0 || (size_t)ret >= sizeof(buf))
return log_error(-1, "Failed to convert pid to string %m");
if (write(fd, buf, ret) != ret)
total_len = 0;
goto out_pthread_mutex_unlock;
}
- if (l >= buf_size) {
+ if ((size_t)l >= buf_size) {
lxcfs_error("Write to cache was truncated");
total_len = 0;
goto out_pthread_mutex_unlock;
total_len = 0;
goto out_pthread_mutex_unlock;
}
- if (l >= buf_size) {
+ if ((size_t)l >= buf_size) {
lxcfs_error("Write to cache was truncated");
total_len = 0;
goto out_pthread_mutex_unlock;
total_len = 0;
goto out_pthread_mutex_unlock;
}
- if (l >= buf_size) {
+ if ((size_t)l >= buf_size) {
lxcfs_error("Write to cache was truncated");
total_len = 0;
goto out_pthread_mutex_unlock;
total_len = 0;
goto out_pthread_mutex_unlock;
}
- if (l >= buf_size) {
+ if ((size_t)l >= buf_size) {
lxcfs_error("Write to cache was truncated");
total_len = 0;
goto out_pthread_mutex_unlock;
size_t cache_size = d->buflen;
if (offset) {
- int left;
+ size_t left;
if (offset > d->size)
return -EINVAL;
l = snprintf(cache, cache_size, "processor : %d\n", curcpu);
if (l < 0)
return log_error(0, "Failed to write cache");
- if (l >= cache_size)
+ if ((size_t)l >= cache_size)
return log_error(0, "Write to cache was truncated");
cache += l;
cache_size -= l;
l = snprintf(cache, cache_size, "processor %d:%s", curcpu, p);
if (l < 0)
return log_error(0, "Failed to write cache");
- if (l >= cache_size)
+ if ((size_t)l >= cache_size)
return log_error(0, "Write to cache was truncated");
cache += l;
l = snprintf(cache, cache_size, "%s", line);
if (l < 0)
return log_error(0, "Failed to write cache");
- if (l >= cache_size)
+ if ((size_t)l >= cache_size)
return log_error(0, "Write to cache was truncated");
cache += l;
cache_size = d->buflen;
total_len = 0;
l = snprintf(cache, cache_size, "vendor_id : IBM/S390\n");
- if (l < 0 || l >= cache_size)
+ if (l < 0 || (size_t)l >= cache_size)
return 0;
cache_size -= l;
cache += l;
total_len += l;
l = snprintf(cache, cache_size, "# processors : %d\n", curcpu + 1);
- if (l < 0 || l >= cache_size)
+ if (l < 0 || (size_t)l >= cache_size)
return 0;
cache_size -= l;
cache += l;
total_len += l;
l = snprintf(cache, cache_size, "%s", origcache);
- if (l < 0 || l >= cache_size)
+ if (l < 0 || (size_t)l >= cache_size)
return 0;
total_len += l;
}
size_t linelen = 0;
if (offset) {
- int left;
+ size_t left;
if (offset > d->size)
return -EINVAL;
d->cached = 1;
d->size = (int)total_len;
- if (total_len > size)
+ if ((size_t)total_len > size)
total_len = size;
memcpy(buf, d->buf, total_len);
int ret;
if (offset) {
- int left;
+ size_t left;
if (offset > d->size)
return -EINVAL;
l = snprintf(cache, cache_size, "%s", lbuf);
if (l < 0)
return log_error(0, "Failed to write cache");
- if (l >= cache_size)
+ if ((size_t)l >= cache_size)
return log_error(0, "Write to cache was truncated");
cache += l;
#endif
if (offset) {
- int left;
+ size_t left;
if (offset > d->size)
return -EINVAL;
d->cached = 1;
d->size = total_len;
- if (total_len > size)
+ if ((size_t)total_len > size)
total_len = size;
memcpy(buf, d->buf, total_len);
int cg_cpu_usage_size = 0;
if (offset) {
- int left;
+ size_t left;
if (offset > d->size)
return -EINVAL;
l = snprintf(cache, cache_size, "%s", line);
if (l < 0)
return log_error(0, "Failed to write cache");
- if (l >= cache_size)
+ if ((size_t)l >= cache_size)
return log_error(0, "Write to cache was truncated");
cache += l;
l = snprintf(cache, cache_size, "cpu%d%s", curcpu, c);
if (l < 0)
return log_error(0, "Failed to write cache");
- if (l >= cache_size)
+ if ((size_t)l >= cache_size)
return log_error(0, "Write to cache was truncated");
cache += l;
cg_cpu_usage[physcpu].system, new_idle);
if (l < 0)
return log_error(0, "Failed to write cache");
- if (l >= cache_size)
+ if ((size_t)l >= cache_size)
return log_error(0, "Write to cache was truncated");
cache += l;
int ret;
if (offset) {
- int left;
+ size_t left;
if (offset > d->size)
return -EINVAL;
l = snprintf(cache, cache_size, "%s", printme);
if (l < 0)
return log_error(0, "Failed to write cache");
- if (l >= cache_size)
+ if ((size_t)l >= cache_size)
return log_error(0, "Write to cache was truncated");
cache += l;
pid_t initpid;
if (offset) {
- int left;
+ size_t left;
if (offset > d->size)
return -EINVAL;
ssize_t l = snprintf(cache, cache_size, "%s", line);
if (l < 0)
return log_error(0, "Failed to write cache");
- if (l >= cache_size)
+ if ((size_t)l >= cache_size)
return log_error(0, "Write to cache was truncated");
cache += l;
uint64_t a, b, c;
if (offset) {
- int left;
+ size_t left;
if (offset > d->size)
return -EINVAL;
d->size = (int)total_len;
d->cached = 1;
- if (total_len > size)
+ if ((size_t)total_len > size)
total_len = size;
memcpy(buf, d->buf, total_len);
ssize_t total_len = 0;
if (offset) {
- int left;
+ size_t left;
if (!d->cached)
return 0;
d->size = (int)total_len;
d->cached = 1;
- if (total_len > size)
+ if ((size_t)total_len > size)
total_len = size;
memcpy(buf, d->buf, total_len);
if (!cpumask)
return -errno;
- for (size_t i = 0; i < max_cpus; i++) {
+ for (ssize_t i = 0; i < max_cpus; i++) {
int ret;
char cpu[100];
continue;
ret = snprintf(cpu, sizeof(cpu), "cpu%ld", i);
- if (ret < 0 || ret >= sizeof(cpu))
+ if (ret < 0 || (size_t)ret >= sizeof(cpu))
continue;
if (DIR_FILLER(filler, buf, cpu, NULL, 0) != 0)
__lxcfs_fuse_ops int sys_readlink(const char *path, char *buf, size_t size)
{
- int ret = readlink(path, buf, size);
+ ssize_t ret;
if (!liblxcfs_functional())
return -EIO;
+ ret = readlink(path, buf, size);
if (ret < 0)
return -errno;
- if (ret > size)
+
+ if ((size_t)ret > size)
return -1;
buf[ret] = '\0';
return 0;
while (getline(&line, &linelen, f) != -1) {
- ssize_t l = snprintf(cache, cache_size, "%s", line);
+ ssize_t l;
+
+ l = snprintf(cache, cache_size, "%s", line);
if (l < 0)
return log_error(0, "Failed to write cache");
- if (l >= cache_size)
+ if ((size_t)l >= cache_size)
return log_error(0, "Write to cache was truncated");
cache += l;
/* read from off 0 */
memcpy(buf, d->buf, total_len);
- if (d->size > total_len)
+ if (d->size > (int)total_len)
d->cached = d->size - total_len;
return total_len;
if (offset) {
ssize_t total_len = 0;
char *cache = d->buf;
- int left;
+ size_t left;
if (offset > d->size)
return -EINVAL;