Merge branch 'compiler-warnings' of https://github.com/rudimeier/util-linux

* 'compiler-warnings' of https://github.com/rudimeier/util-linux:
  exec_shell: prevent basename from modifying env
  lib/path: ifdef path_set_prefix() like in path.h
  lib: fix unused parameters and variables
  misc: fix some printf format strings
  include: add missing includes
  ipcs:  ulong -> unsigned long
  libcommon: don't include sysinfo.h
This commit is contained in:
Karel Zak 2016-02-12 13:35:18 +01:00
commit 173607a254
14 changed files with 82 additions and 59 deletions

View File

@ -591,26 +591,26 @@ static void print_stats(struct fsck_instance *inst)
if (report_stats_file)
fprintf(report_stats_file, "%s %d %ld "
"%ld.%06ld %d.%06d %d.%06d\n",
"%ld.%06ld %ld.%06ld %ld.%06ld\n",
fs_get_device(inst->fs),
inst->exit_status,
inst->rusage.ru_maxrss,
delta.tv_sec, delta.tv_usec,
(int)inst->rusage.ru_utime.tv_sec,
(int)inst->rusage.ru_utime.tv_usec,
(int)inst->rusage.ru_stime.tv_sec,
(int)inst->rusage.ru_stime.tv_usec);
(long)delta.tv_sec, (long)delta.tv_usec,
(long)inst->rusage.ru_utime.tv_sec,
(long)inst->rusage.ru_utime.tv_usec,
(long)inst->rusage.ru_stime.tv_sec,
(long)inst->rusage.ru_stime.tv_usec);
else
fprintf(stdout, "%s: status %d, rss %ld, "
"real %ld.%06ld, user %d.%06d, sys %d.%06d\n",
"real %ld.%06ld, user %ld.%06ld, sys %ld.%06ld\n",
fs_get_device(inst->fs),
inst->exit_status,
inst->rusage.ru_maxrss,
delta.tv_sec, delta.tv_usec,
(int)inst->rusage.ru_utime.tv_sec,
(int)inst->rusage.ru_utime.tv_usec,
(int)inst->rusage.ru_stime.tv_sec,
(int)inst->rusage.ru_stime.tv_usec);
(long)delta.tv_sec, (long)delta.tv_usec,
(long)inst->rusage.ru_utime.tv_sec,
(long)inst->rusage.ru_utime.tv_usec,
(long)inst->rusage.ru_stime.tv_sec,
(long)inst->rusage.ru_stime.tv_usec);
}
/*

View File

@ -22,8 +22,8 @@ int fstat_at(int dir, const char *dirname __attribute__ ((__unused__)),
nofollow ? AT_SYMLINK_NOFOLLOW : 0);
}
#else
int fstat_at(int dir, const char *dirname, const char *filename,
struct stat *st, int nofollow)
int fstat_at(int dir __attribute__ ((__unused__)), const char *dirname,
const char *filename, struct stat *st, int nofollow)
{
if (*filename != '/') {
@ -48,7 +48,8 @@ int open_at(int dir, const char *dirname __attribute__ ((__unused__)),
return openat(dir, filename, flags);
}
#else
int open_at(int dir, const char *dirname, const char *filename, int flags)
int open_at(int dir __attribute__((__unused__)), const char *dirname,
const char *filename, int flags)
{
if (*filename != '/') {
char path[PATH_MAX];
@ -82,8 +83,8 @@ ssize_t readlink_at(int dir, const char *dirname __attribute__ ((__unused__)),
return readlinkat(dir, pathname, buf, bufsiz);
}
#else
ssize_t readlink_at(int dir, const char *dirname, const char *pathname,
char *buf, size_t bufsiz)
ssize_t readlink_at(int dir __attribute__((__unused__)), const char *dirname,
const char *pathname, char *buf, size_t bufsiz)
{
if (*pathname != '/') {
char path[PATH_MAX];
@ -128,7 +129,7 @@ int main(int argc, char *argv[])
printf("%32s ", d->d_name);
if (fstat_at(dirfd(dir), dirname, d->d_name, &st, 0) == 0)
printf("%16jd bytes ", st.st_size);
printf("%16zd bytes ", st.st_size);
else
printf("%16s bytes ", "???");

View File

@ -202,17 +202,20 @@ blkdev_get_sectors(int fd, unsigned long long *sectors)
* This is the smallest unit the storage device can
* address. It is typically 512 bytes.
*/
#ifdef BLKSSZGET
int blkdev_get_sector_size(int fd, int *sector_size)
{
#ifdef BLKSSZGET
if (ioctl(fd, BLKSSZGET, sector_size) >= 0)
return 0;
return -1;
}
#else
int blkdev_get_sector_size(int fd __attribute__((__unused__)), int *sector_size)
{
*sector_size = DEFAULT_SECTOR_SIZE;
return 0;
#endif
}
#endif
/*
* Get physical block device size. The BLKPBSZGET is supported since Linux
@ -228,24 +231,27 @@ int blkdev_get_sector_size(int fd, int *sector_size)
* physec = DEFAULT_SECTOR_SIZE;
* }
*/
#ifdef BLKPBSZGET
int blkdev_get_physector_size(int fd, int *sector_size)
{
#ifdef BLKPBSZGET
if (ioctl(fd, BLKPBSZGET, &sector_size) >= 0)
return 0;
return -1;
}
#else
int blkdev_get_physector_size(int fd __attribute__((__unused__)), int *sector_size)
{
*sector_size = DEFAULT_SECTOR_SIZE;
return 0;
#endif
}
#endif
/*
* Return the alignment status of a device
*/
#ifdef BLKALIGNOFF
int blkdev_is_misaligned(int fd)
{
#ifdef BLKALIGNOFF
int aligned;
if (ioctl(fd, BLKALIGNOFF, &aligned) < 0)
@ -255,10 +261,13 @@ int blkdev_is_misaligned(int fd)
* sizes and alignments exist for stacked devices
*/
return aligned != 0 ? 1 : 0;
#else
return 0;
#endif
}
#else
int blkdev_is_misaligned(int fd __attribute__((__unused__)))
{
return 0;
}
#endif
int open_blkdev_or_file(const struct stat *st, const char *name, const int oflag)
{
@ -278,19 +287,22 @@ int open_blkdev_or_file(const struct stat *st, const char *name, const int oflag
return fd;
}
#ifdef CDROM_GET_CAPABILITY
int blkdev_is_cdrom(int fd)
{
#ifdef CDROM_GET_CAPABILITY
int ret;
if ((ret = ioctl(fd, CDROM_GET_CAPABILITY, NULL)) < 0)
return 0;
else
return ret;
#else
return 0;
#endif
}
#else
int blkdev_is_cdrom(int fd __attribute__((__unused__)))
{
return 0;
}
#endif
/*
* Get kernel's interpretation of the device's geometry.
@ -300,9 +312,9 @@ int blkdev_is_cdrom(int fd)
*
* Note that this is deprecated in favor of LBA addressing.
*/
#ifdef HDIO_GETGEO
int blkdev_get_geometry(int fd, unsigned int *h, unsigned int *s)
{
#ifdef HDIO_GETGEO
struct hd_geometry geometry;
if (ioctl(fd, HDIO_GETGEO, &geometry) == 0) {
@ -311,6 +323,9 @@ int blkdev_get_geometry(int fd, unsigned int *h, unsigned int *s)
return 0;
}
#else
int blkdev_get_geometry(int fd __attribute__((__unused__)),
unsigned int *h, unsigned int *s)
{
*h = 0;
*s = 0;
#endif

View File

@ -20,6 +20,7 @@
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <libgen.h>
#include "nls.h"
#include "c.h"
@ -31,12 +32,15 @@
void exec_shell(void)
{
const char *shell = getenv("SHELL"), *shell_basename;
const char *shell = getenv("SHELL");
char *shellc = xstrdup(shell);
const char *shell_basename;
char *arg0;
if (!shell)
shell = DEFAULT_SHELL;
shell_basename = basename(shell);
shell_basename = basename(shellc);
arg0 = xmalloc(strlen(shell_basename) + 2);
arg0[0] = '-';
strcpy(arg0 + 1, shell_basename);

View File

@ -311,9 +311,7 @@ leave:
int check_mount_point(const char *device, int *mount_flags,
char *mtpt, int mtlen)
{
struct stat st_buf;
int retval = 0;
int fd;
if (is_swap_device(device)) {
*mount_flags = MF_MOUNTED | MF_SWAP;
@ -337,15 +335,19 @@ int check_mount_point(const char *device, int *mount_flags,
return retval;
#ifdef __linux__ /* This only works on Linux 2.6+ systems */
if ((stat(device, &st_buf) != 0) ||
!S_ISBLK(st_buf.st_mode))
return 0;
fd = open(device, O_RDONLY|O_EXCL|O_CLOEXEC);
if (fd < 0) {
if (errno == EBUSY)
*mount_flags |= MF_BUSY;
} else
close(fd);
{
struct stat st_buf;
int fd;
if ((stat(device, &st_buf) != 0) ||
!S_ISBLK(st_buf.st_mode))
return 0;
fd = open(device, O_RDONLY|O_EXCL|O_CLOEXEC);
if (fd < 0) {
if (errno == EBUSY)
*mount_flags |= MF_BUSY;
} else
close(fd);
}
#endif
return 0;

View File

@ -12,6 +12,7 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <signal.h>
#include "c.h"
#include "xalloc.h"

View File

@ -244,8 +244,6 @@ path_read_cpulist(int maxcpus, const char *path, ...)
return set;
}
#endif /* HAVE_CPU_SET_T */
void
path_set_prefix(const char *prefix)
{
@ -253,3 +251,5 @@ path_set_prefix(const char *prefix)
strncpy(pathbuf, prefix, sizeof(pathbuf));
pathbuf[sizeof(pathbuf) - 1] = '\0';
}
#endif /* HAVE_CPU_SET_T */

View File

@ -519,7 +519,7 @@ char *size_to_human_string(int options, uint64_t bytes)
if (!dp || !*dp)
dp = ".";
snprintf(buf, sizeof(buf), "%d%s%jd%s", dec, dp, frac, suffix);
snprintf(buf, sizeof(buf), "%d%s%" PRIu64 "%s", dec, dp, frac, suffix);
} else
snprintf(buf, sizeof(buf), "%d%s", dec, suffix);

View File

@ -5,6 +5,7 @@
* Written by Karel Zak <kzak@redhat.com>
*/
#include <ctype.h>
#include <libgen.h>
#include "c.h"
#include "at.h"
@ -461,7 +462,7 @@ int sysfs_write_u64(struct sysfs_cxt *cxt, const char *attr, uint64_t num)
if (fd < 0)
return -errno;
len = snprintf(buf, sizeof(buf), "%ju", num);
len = snprintf(buf, sizeof(buf), "%" PRIu64, num);
if (len < 0 || (size_t) len + 1 > sizeof(buf))
rc = -errno;
else

View File

@ -21,8 +21,6 @@
#include <assert.h>
#include <ctype.h>
#include <string.h>
#include <sys/sysinfo.h>
#include <sys/time.h>
#include <time.h>
#include "c.h"

View File

@ -312,8 +312,8 @@ try_again:
if (state_fd >= 0) {
rewind(state_f);
len = fprintf(state_f,
"clock: %04x tv: %016lu %08lu adj: %08d\n",
clock_seq, last.tv_sec, last.tv_usec, adjustment);
"clock: %04x tv: %016ld %08ld adj: %08d\n",
clock_seq, (long)last.tv_sec, (long)last.tv_usec, adjustment);
fflush(state_f);
if (ftruncate(state_fd, len) < 0) {
fprintf(state_f, " \n");

View File

@ -163,7 +163,7 @@ main(int argc, char **argv)
printf("Warning: not a time-based UUID, so UUID time "
"decoding will likely not work!\n");
}
printf("UUID time is: (%ld, %ld): %s\n", tv.tv_sec, tv.tv_usec,
printf("UUID time is: (%ld, %ld): %s\n", (long)tv.tv_sec, (long)tv.tv_usec,
ctime(&time_reg));
return 0;

View File

@ -35,11 +35,11 @@
# define SHM_INFO 14
struct shm_info {
int used_ids;
ulong shm_tot; /* total allocated shm */
ulong shm_rss; /* total resident shm */
ulong shm_swp; /* total swapped shm */
ulong swap_attempts;
ulong swap_successes;
unsigned long shm_tot; /* total allocated shm */
unsigned long shm_rss; /* total resident shm */
unsigned long shm_swp; /* total swapped shm */
unsigned long swap_attempts;
unsigned long swap_successes;
};
#endif

View File

@ -249,7 +249,8 @@ static void write_output(struct script_control *ctl, char *obuf,
gettime_monotonic(&now);
timersub(&now, &ctl->oldtime, &delta);
fprintf(ctl->timingfp, "%ld.%06ld %zd\n", delta.tv_sec, delta.tv_usec, bytes);
fprintf(ctl->timingfp, "%ld.%06ld %zd\n",
(long)delta.tv_sec, (long)delta.tv_usec, bytes);
if (ctl->flush)
fflush(ctl->timingfp);
ctl->oldtime = now;