Merge branch 'for-upstream' of https://github.com/andyprice/blktrace
[blktrace.git] / blktrace.c
index 228838af1758954ea8bf8d24d9ea71c224d9884c..3c8fb4c43885c48b2c73d113ce282df5bb007ce4 100644 (file)
@@ -621,13 +621,19 @@ static void dpp_free(struct devpath *dpp)
 
 static int lock_on_cpu(int cpu)
 {
-       cpu_set_t cpu_mask;
-
-       CPU_ZERO(&cpu_mask);
-       CPU_SET(cpu, &cpu_mask);
-       if (sched_setaffinity(0, sizeof(cpu_mask), &cpu_mask) < 0)
+       cpu_set_t * cpu_mask;
+       size_t size;
+       cpu_mask = CPU_ALLOC(ncpus);
+       size = CPU_ALLOC_SIZE(ncpus);
+
+       CPU_ZERO_S(size, cpu_mask);
+       CPU_SET_S(cpu, size, cpu_mask);
+       if (sched_setaffinity(0, size, cpu_mask) < 0) {
+               CPU_FREE(cpu_mask);             
                return errno;
+       }
 
+       CPU_FREE(cpu_mask);             
        return 0;
 }
 
@@ -872,8 +878,9 @@ static int net_send_header(int fd, int cpu, char *buts_name, int len)
        memset(&hdr, 0, sizeof(hdr));
 
        hdr.magic = BLK_IO_TRACE_MAGIC;
+       memset(hdr.buts_name, 0, sizeof(hdr.buts_name));
        strncpy(hdr.buts_name, buts_name, sizeof(hdr.buts_name));
-       hdr.buts_name[sizeof(hdr.buts_name)-1] = '\0';
+       hdr.buts_name[sizeof(hdr.buts_name) - 1] = '\0';
        hdr.cpu = cpu;
        hdr.max_cpus = ncpus;
        hdr.len = len;
@@ -981,7 +988,9 @@ retry:
                }
 
                memcpy(&addr->sin_addr, hent->h_addr, 4);
-               strcpy(hostname, hent->h_name);
+               memset(hostname, 0, sizeof(hostname));
+               strncpy(hostname, hent->h_name, sizeof(hostname));
+               hostname[sizeof(hostname) - 1] = '\0';
        }
 
        return 0;
@@ -1728,11 +1737,10 @@ static int handle_pfds_netclient(struct tracer *tp, int nevs, int force_read)
 {
        struct stat sb;
        int i, nentries = 0;
-       struct pdc_stats *sp;
        struct pollfd *pfd = tp->pfds;
        struct io_info *iop = tp->ios;
 
-       for (i = 0; i < ndevs; i++, pfd++, iop++, sp++) {
+       for (i = 0; i < ndevs; i++, pfd++, iop++) {
                if (pfd->revents & POLLIN || force_read) {
                        if (fstat(iop->ifd, &sb) < 0) {
                                perror(iop->ifn);
@@ -1905,6 +1913,7 @@ static void stop_tracers(void)
                struct tracer *tp = list_entry(p, struct tracer, head);
                tp->is_done = 1;
        }
+       pthread_cond_broadcast(&mt_cond);
 }
 
 static void del_tracers(void)
@@ -2132,7 +2141,9 @@ static int handle_args(int argc, char *argv[])
                        break;
                case 'h':
                        net_mode = Net_client;
-                       strcpy(hostname, optarg);
+                       memset(hostname, 0, sizeof(hostname));
+                       strncpy(hostname, optarg, sizeof(hostname));
+                       hostname[sizeof(hostname) - 1] = '\0';
                        break;
                case 'l':
                        net_mode = Net_server;
@@ -2652,9 +2663,9 @@ int main(int argc, char *argv[])
 
        setlocale(LC_NUMERIC, "en_US");
        pagesize = getpagesize();
-       ncpus = sysconf(_SC_NPROCESSORS_ONLN);
+       ncpus = sysconf(_SC_NPROCESSORS_CONF);
        if (ncpus < 0) {
-               fprintf(stderr, "sysconf(_SC_NPROCESSORS_ONLN) failed %d/%s\n",
+               fprintf(stderr, "sysconf(_SC_NPROCESSORS_CONF) failed %d/%s\n",
                        errno, strerror(errno));
                ret = 1;
                goto out;