diff options
-rw-r--r-- | disk-utils/fdisk.c | 2 | ||||
-rw-r--r-- | include/pathnames.h | 2 | ||||
-rw-r--r-- | lib/canonicalize.c | 5 | ||||
-rw-r--r-- | libfdisk/src/partition.c | 2 | ||||
-rw-r--r-- | login-utils/last.c | 2 | ||||
-rw-r--r-- | sys-utils/chcpu.c | 22 | ||||
-rw-r--r-- | sys-utils/choom.c | 2 | ||||
-rw-r--r-- | sys-utils/lscpu.c | 13 | ||||
-rw-r--r-- | sys-utils/zramctl.c | 4 |
9 files changed, 32 insertions, 22 deletions
diff --git a/disk-utils/fdisk.c b/disk-utils/fdisk.c index 55af8dc11..2126b4cb1 100644 --- a/disk-utils/fdisk.c +++ b/disk-utils/fdisk.c @@ -100,7 +100,7 @@ int get_user_reply(const char *prompt, char *buf, size_t bufsz) size_t sz; int ret = 0; - DBG(ASK, ul_debug("asking for user replay %s", is_interactive ? "[interactive]" : "")); + DBG(ASK, ul_debug("asking for user reply %s", is_interactive ? "[interactive]" : "")); sigemptyset(&act.sa_mask); sigaction(SIGINT, &act, &oldact); diff --git a/include/pathnames.h b/include/pathnames.h index 59cc66736..abf0cdee9 100644 --- a/include/pathnames.h +++ b/include/pathnames.h @@ -131,6 +131,8 @@ # define _PATH_DEV "/dev/" #endif +#define _PATH_DEV_MAPPER "/dev/mapper" + #define _PATH_DEV_MEM "/dev/mem" #define _PATH_DEV_LOOP "/dev/loop" diff --git a/lib/canonicalize.c b/lib/canonicalize.c index b600248c7..ef3342b12 100644 --- a/lib/canonicalize.c +++ b/lib/canonicalize.c @@ -16,6 +16,7 @@ #include <sys/stat.h> #include "canonicalize.h" +#include "pathnames.h" /* * Converts private "dm-N" names to "/dev/mapper/<name>" @@ -27,7 +28,7 @@ char *canonicalize_dm_name(const char *ptname) { FILE *f; size_t sz; - char path[256], name[256], *res = NULL; + char path[256], name[sizeof(path) - sizeof(_PATH_DEV_MAPPER)], *res = NULL; if (!ptname || !*ptname) return NULL; @@ -39,7 +40,7 @@ char *canonicalize_dm_name(const char *ptname) /* read "<name>\n" from sysfs */ if (fgets(name, sizeof(name), f) && (sz = strlen(name)) > 1) { name[sz - 1] = '\0'; - snprintf(path, sizeof(path), "/dev/mapper/%s", name); + snprintf(path, sizeof(path), _PATH_DEV_MAPPER "/%s", name); if (access(path, F_OK) == 0) res = strdup(path); diff --git a/libfdisk/src/partition.c b/libfdisk/src/partition.c index 085d0cfab..a790dc9c9 100644 --- a/libfdisk/src/partition.c +++ b/libfdisk/src/partition.c @@ -130,8 +130,8 @@ void fdisk_unref_partition(struct fdisk_partition *pa) pa->refcount--; if (pa->refcount <= 0) { - fdisk_reset_partition(pa); list_del(&pa->parts); + fdisk_reset_partition(pa); DBG(PART, ul_debugobj(pa, "free")); free(pa); } diff --git a/login-utils/last.c b/login-utils/last.c index 80d77d20b..59dfdb2f5 100644 --- a/login-utils/last.c +++ b/login-utils/last.c @@ -395,7 +395,7 @@ static int list(const struct last_control *ctl, struct utmpx *p, time_t logout_t * uucp and ftp have special-type entries */ utline[0] = 0; - strncat(utline, p->ut_line, sizeof(p->ut_line)); + strncat(utline, p->ut_line, sizeof(utline) - 1); if (strncmp(utline, "ftp", 3) == 0 && isdigit(utline[3])) utline[3] = 0; if (strncmp(utline, "uucp", 4) == 0 && isdigit(utline[4])) diff --git a/sys-utils/chcpu.c b/sys-utils/chcpu.c index 12e52d887..4b5c7579a 100644 --- a/sys-utils/chcpu.c +++ b/sys-utils/chcpu.c @@ -75,13 +75,13 @@ enum { */ static int cpu_enable(cpu_set_t *cpu_set, size_t setsize, int enable) { - unsigned int cpu; + int cpu; int online, rc; int configured = -1; - size_t fails = 0; + int fails = 0; - for (cpu = 0; cpu < setsize; cpu++) { - if (!CPU_ISSET(cpu, cpu_set)) + for (cpu = 0; cpu < maxcpus; cpu++) { + if (!CPU_ISSET_S(cpu, setsize, cpu_set)) continue; if (!path_exist(_PATH_SYS_CPU "/cpu%d", cpu)) { warnx(_("CPU %u does not exist"), cpu); @@ -127,12 +127,12 @@ static int cpu_enable(cpu_set_t *cpu_set, size_t setsize, int enable) } else { printf(_("CPU %u disabled\n"), cpu); if (onlinecpus) - CPU_CLR(cpu, onlinecpus); + CPU_CLR_S(cpu, setsize, onlinecpus); } } } - return fails == 0 ? 0 : fails == setsize ? -1 : 1; + return fails == 0 ? 0 : fails == maxcpus ? -1 : 1; } static int cpu_rescan(void) @@ -168,12 +168,12 @@ static int cpu_set_dispatch(int mode) */ static int cpu_configure(cpu_set_t *cpu_set, size_t setsize, int configure) { - unsigned int cpu; + int cpu; int rc, current; - size_t fails = 0; + int fails = 0; - for (cpu = 0; cpu < setsize; cpu++) { - if (!CPU_ISSET(cpu, cpu_set)) + for (cpu = 0; cpu < maxcpus; cpu++) { + if (!CPU_ISSET_S(cpu, setsize, cpu_set)) continue; if (!path_exist(_PATH_SYS_CPU "/cpu%d", cpu)) { warnx(_("CPU %u does not exist"), cpu); @@ -217,7 +217,7 @@ static int cpu_configure(cpu_set_t *cpu_set, size_t setsize, int configure) } } - return fails == 0 ? 0 : fails == setsize ? -1 : 1; + return fails == 0 ? 0 : fails == maxcpus ? -1 : 1; } static void cpu_parse(char *cpu_string, cpu_set_t *cpu_set, size_t setsize) diff --git a/sys-utils/choom.c b/sys-utils/choom.c index 9920916c1..21cb0ee10 100644 --- a/sys-utils/choom.c +++ b/sys-utils/choom.c @@ -139,6 +139,8 @@ int main(int argc, char **argv) /* Start new process */ } else { + if (set_score_adj(getpid(), adj)) + err(EXIT_FAILURE, _("failed to set score adjust value")); argv += optind; execvp(argv[0], argv); errexec(argv[0]); diff --git a/sys-utils/lscpu.c b/sys-utils/lscpu.c index f260fe7ca..619a7df1d 100644 --- a/sys-utils/lscpu.c +++ b/sys-utils/lscpu.c @@ -478,7 +478,7 @@ read_basicinfo(struct lscpu_desc *desc, struct lscpu_modifier *mod) desc->idx2cpunum = xcalloc(desc->ncpuspos, sizeof(int)); for (num = 0, idx = 0; num < maxcpus; num++) { - if (CPU_ISSET(num, tmp)) + if (CPU_ISSET_S(num, setsize, tmp)) desc->idx2cpunum[idx++] = num; } cpuset_free(tmp); @@ -1109,10 +1109,11 @@ cpu_max_mhz(struct lscpu_desc *desc, char *buf, size_t bufsz) { int i; float cpu_freq = 0.0; + size_t setsize = CPU_ALLOC_SIZE(maxcpus); if (desc->present) { for (i = 0; i < desc->ncpuspos; i++) { - if (CPU_ISSET(real_cpu_num(desc, i), desc->present) + if (CPU_ISSET_S(real_cpu_num(desc, i), setsize, desc->present) && desc->maxmhz[i]) { float freq = atof(desc->maxmhz[i]); @@ -1131,10 +1132,11 @@ cpu_min_mhz(struct lscpu_desc *desc, char *buf, size_t bufsz) { int i; float cpu_freq = -1.0; + size_t setsize = CPU_ALLOC_SIZE(maxcpus); if (desc->present) { for (i = 0; i < desc->ncpuspos; i++) { - if (CPU_ISSET(real_cpu_num(desc, i), desc->present) + if (CPU_ISSET_S(real_cpu_num(desc, i), setsize, desc->present) && desc->minmhz[i]) { float freq = atof(desc->minmhz[i]); @@ -1931,6 +1933,7 @@ int main(int argc, char *argv[]) int c, i; int columns[ARRAY_SIZE(coldescs)], ncolumns = 0; int cpu_modifier_specified = 0; + size_t setsize; enum { OPT_OUTPUT_ALL = CHAR_MAX + 1, @@ -2045,10 +2048,12 @@ int main(int argc, char *argv[]) read_basicinfo(desc, mod); + setsize = CPU_ALLOC_SIZE(maxcpus); + for (i = 0; i < desc->ncpuspos; i++) { /* only consider present CPUs */ if (desc->present && - !CPU_ISSET(real_cpu_num(desc, i), desc->present)) + !CPU_ISSET_S(real_cpu_num(desc, i), setsize, desc->present)) continue; read_topology(desc, i); read_cache(desc, i); diff --git a/sys-utils/zramctl.c b/sys-utils/zramctl.c index 4d900f119..642d88d41 100644 --- a/sys-utils/zramctl.c +++ b/sys-utils/zramctl.c @@ -215,9 +215,9 @@ static struct sysfs_cxt *zram_get_sysfs(struct zram *z) return NULL; if (*z->devname != '/') { /* canonicalize the device name according to /sys */ - char name[PATH_MAX]; + char name[sizeof(z->devname) - sizeof(_PATH_DEV)]; if (sysfs_get_devname(&z->sysfs, name, sizeof(name))) - snprintf(z->devname, sizeof(z->devname), "/dev/%s", name); + snprintf(z->devname, sizeof(z->devname), _PATH_DEV "%s", name); } } |