Skip to contentSkip to conversation

libxl/xl: Enable -Wshadow

PATCH Applied Ian Campbell 2 participants 9 messages Sep 14, 2012 – Sep 17, 2012

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libxl/xl: Enable -Wshadow

We've had several occuranced of confusion on xl due to shadowing the global domid variable with a local one. The main bulk of this series removes that global, the rest is smaller cleanups to allow Wshadow.

I've already sent the libxl part of this, but am reincluding here as part of the set.

#1 lore raw

PATCH 1/1 libxl: Enable -Wshadow

# HG changeset patch
# User Ian Campbell <[email protected]> # Date 1347620983 -3600
# Node ID 58ab3fb73d13e250f334a38599b749640deac190 # Parent 0547430886c507989dd9091ef5f1e2d089a50351
libxl: Enable -Wshadow.

It was convenient to invent $(CFLAGS_LIBXL) to do this.

Various renamings to avoid shadowing standard functions:
- index(3)
- listen(2)
- link(2)
- abort(3)
- abs(3)

Reduced the scope of some variables to avoid conflicts.

Change to libxc is due to the nested hypercall buf macros in set_xen_guest_handle (used in libxl) using the same local private vars.

Build tested only.

tools/libxc/xenctrl.h +12 -12
diff -r 0547430886c5 -r 58ab3fb73d13 tools/libxc/xenctrl.h
@@ -236,10 +236,10 @@ typedef struct xc_hypercall_buffer xc_hy
  * Returns the hypercall_buffer associated with a variable.
  */
 #define HYPERCALL_BUFFER(_name)                                                              \
-    ({  xc_hypercall_buffer_t _val1;                                                         \
-        typeof(XC__HYPERCALL_BUFFER_NAME(_name)) *_val2 = &XC__HYPERCALL_BUFFER_NAME(_name); \
-        (void)(&_val1 == _val2);                                                             \
-        (_val2)->param_shadow ? (_val2)->param_shadow : (_val2);                             \
+    ({  xc_hypercall_buffer_t _buf1;                                                         \
+        typeof(XC__HYPERCALL_BUFFER_NAME(_name)) *_buf2 = &XC__HYPERCALL_BUFFER_NAME(_name); \
+        (void)(&_buf1 == _buf2);                                                             \
+        (_buf2)->param_shadow ? (_buf2)->param_shadow : (_buf2);                             \
      })
 
 #define HYPERCALL_BUFFER_INIT_NO_BOUNCE .dir = 0, .sz = 0, .ubuf = (void *)-1
@@ -274,10 +274,10 @@ typedef struct xc_hypercall_buffer xc_hy
  * directly as a hypercall argument.
  */
 #define HYPERCALL_BUFFER_AS_ARG(_name)                                             \
-    ({  xc_hypercall_buffer_t _val1;                                               \
-        typeof(XC__HYPERCALL_BUFFER_NAME(_name)) *_val2 = HYPERCALL_BUFFER(_name); \
-        (void)(&_val1 == _val2);                                                   \
-        (unsigned long)(_val2)->hbuf;                                              \
+    ({  xc_hypercall_buffer_t _bufarg1;                                               \
+        typeof(XC__HYPERCALL_BUFFER_NAME(_name)) *_bufarg2 = HYPERCALL_BUFFER(_name); \
+        (void)(&_bufarg1 == _bufarg2);                                                   \
+        (unsigned long)(_bufarg2)->hbuf;                                              \
      })
 
 /*
@@ -287,10 +287,10 @@ typedef struct xc_hypercall_buffer xc_hy
 #undef set_xen_guest_handle
 #define set_xen_guest_handle(_hnd, _val)                                         \
     do {                                                                         \
-        xc_hypercall_buffer_t _val1;                                             \
-        typeof(XC__HYPERCALL_BUFFER_NAME(_val)) *_val2 = HYPERCALL_BUFFER(_val); \
-        (void) (&_val1 == _val2);                                                 \
-        set_xen_guest_handle_raw(_hnd, (_val2)->hbuf);                           \
+        xc_hypercall_buffer_t _bufhnd1;                                             \
+        typeof(XC__HYPERCALL_BUFFER_NAME(_val)) *_bufhnd2 = HYPERCALL_BUFFER(_val); \
+        (void) (&_bufhnd1 == _bufhnd2);                                                 \
+        set_xen_guest_handle_raw(_hnd, (_bufhnd2)->hbuf);                           \
     } while (0)
 
 /* Use with set_xen_guest_handle in place of NULL */
tools/libxl/Makefile +7 -1
diff -r 0547430886c5 -r 58ab3fb73d13 tools/libxl/Makefile
@@ -22,6 +22,12 @@ endif
 LIBXL_LIBS =
 LIBXL_LIBS = $(LDLIBS_libxenctrl) $(LDLIBS_libxenguest) $(LDLIBS_libxenstore) $(LDLIBS_libblktapctl) $(PTYFUNCS_LIBS) $(LIBUUID_LIBS)
 
+CFLAGS_LIBXL += $(CFLAGS_libxenctrl)
+CFLAGS_LIBXL += $(CFLAGS_libxenguest)
+CFLAGS_LIBXL += $(CFLAGS_libxenstore)
+CFLAGS_LIBXL += $(CFLAGS_libblktapctl) 
+CFLAGS_LIBXL += -Wshadow
+
 CFLAGS += $(PTHREAD_CFLAGS)
 LDFLAGS += $(PTHREAD_LDFLAGS)
 LIBXL_LIBS += $(PTHREAD_LIBS)
@@ -71,7 +77,7 @@ LIBXL_OBJS = flexarray.o libxl.o libxl_c
 			libxl_qmp.o libxl_event.o libxl_fork.o $(LIBXL_OBJS-y)
 LIBXL_OBJS += _libxl_types.o libxl_flask.o _libxl_types_internal.o
 
-$(LIBXL_OBJS): CFLAGS += $(CFLAGS_libxenctrl) $(CFLAGS_libxenguest) $(CFLAGS_libxenstore) $(CFLAGS_libblktapctl) -include $(XEN_ROOT)/tools/config.h
+$(LIBXL_OBJS): CFLAGS += $(CFLAGS_LIBXL) -include $(XEN_ROOT)/tools/config.h
 
 AUTOINCS= libxlu_cfg_y.h libxlu_cfg_l.h _libxl_list.h _paths.h \
 	_libxl_save_msgs_callout.h _libxl_save_msgs_helper.h
tools/libxl/flexarray.c +9 -9
diff -r 0547430886c5 -r 58ab3fb73d13 tools/libxl/flexarray.c
@@ -48,19 +48,19 @@ int flexarray_grow(flexarray_t *array, i
     return 0;
 }
 
-int flexarray_set(flexarray_t *array, unsigned int index, void *ptr)
+int flexarray_set(flexarray_t *array, unsigned int idx, void *ptr)
 {
-    if (index >= array->size) {
+    if (idx >= array->size) {
         int newsize;
         if (!array->autogrow)
             return 1;
-        newsize = (array->size * 2 < index) ? index + 1 : array->size * 2;
+        newsize = (array->size * 2 < idx) ? idx + 1 : array->size * 2;
         if (flexarray_grow(array, newsize - array->size))
             return 2;
     }
-    if ( index + 1 > array->count )
-        array->count = index + 1;
-    array->data[index] = ptr;
+    if ( idx + 1 > array->count )
+        array->count = idx + 1;
+    array->data[idx] = ptr;
     return 0;
 }
 
@@ -92,11 +92,11 @@ int flexarray_vappend(flexarray_t *array
     return ret;
 }
 
-int flexarray_get(flexarray_t *array, int index, void **ptr)
+int flexarray_get(flexarray_t *array, int idx, void **ptr)
 {
-    if (index >= array->size)
+    if (idx >= array->size)
         return 1;
-    *ptr = array->data[index];
+    *ptr = array->data[idx];
     return 0;
 }
 
tools/libxl/libxl.c +21 -20

127 lines not on this page · raw message

tools/libxl/libxl_dm.c +6 -6
diff -r 0547430886c5 -r 58ab3fb73d13 tools/libxl/libxl_dm.c
@@ -379,7 +379,7 @@ static char ** libxl__build_device_model
     }
     if (vnc) {
         int display = 0;
-        const char *listen = "127.0.0.1";
+        const char *addr = "127.0.0.1";
         char *vncarg = NULL;
 
         flexarray_append(dm_args, "-vnc");
@@ -387,16 +387,16 @@ static char ** libxl__build_device_model
         if (vnc->display) {
             display = vnc->display;
             if (vnc->listen && strchr(vnc->listen, ':') == NULL) {
-                listen = vnc->listen;
+                addr = vnc->listen;
             }
         } else if (vnc->listen) {
-            listen = vnc->listen;
+            addr = vnc->listen;
         }
 
-        if (strchr(listen, ':') != NULL)
-            vncarg = libxl__sprintf(gc, "%s", listen);
+        if (strchr(addr, ':') != NULL)
+            vncarg = libxl__sprintf(gc, "%s", addr);
         else
-            vncarg = libxl__sprintf(gc, "%s:%d", listen, display);
+            vncarg = libxl__sprintf(gc, "%s:%d", addr, display);
         if (vnc->passwd && vnc->passwd[0]) {
             vncarg = libxl__sprintf(gc, "%s,password", vncarg);
         }
tools/libxl/libxl_event.c +17 -17
diff -r 0547430886c5 -r 58ab3fb73d13 tools/libxl/libxl_event.c
@@ -167,15 +167,15 @@ static void time_insert_finite(libxl__gc
 }
 
 static int time_register_finite(libxl__gc *gc, libxl__ev_time *ev,
-                                struct timeval abs)
+                                struct timeval absolute)
 {
     int rc;
 
-    rc = OSEVENT_HOOK(timeout_register, &ev->for_app_reg, abs, ev);
+    rc = OSEVENT_HOOK(timeout_register, &ev->for_app_reg, absolute, ev);
     if (rc) return rc;
 
     ev->infinite = 0;
-    ev->abs = abs;
+    ev->abs = absolute;
     time_insert_finite(gc, ev);
 
     return 0;
@@ -202,16 +202,16 @@ static void time_done_debug(libxl__gc *g
 
 int libxl__ev_time_register_abs(libxl__gc *gc, libxl__ev_time *ev,
                                 libxl__ev_time_callback *func,
-                                struct timeval abs)
+                                struct timeval absolute)
 {
     int rc;
 
     CTX_LOCK;
 
     DBG("ev_time=%p register abs=%lu.%06lu",
-        ev, (unsigned long)abs.tv_sec, (unsigned long)abs.tv_usec);
+        ev, (unsigned long)absolute.tv_sec, (unsigned long)absolute.tv_usec);
 
-    rc = time_register_finite(gc, ev, abs);
+    rc = time_register_finite(gc, ev, absolute);
     if (rc) goto out;
 
     ev->func = func;
@@ -228,7 +228,7 @@ int libxl__ev_time_register_rel(libxl__g
                                 libxl__ev_time_callback *func,
                                 int milliseconds /* as for poll(2) */)
 {
-    struct timeval abs;
+    struct timeval absolute;
     int rc;
 
     CTX_LOCK;
@@ -238,10 +238,10 @@ int libxl__ev_time_register_rel(libxl__g
     if (milliseconds < 0) {
         ev->infinite = 1;
     } else {
-        rc = time_rel_to_abs(gc, milliseconds, &abs);
+        rc = time_rel_to_abs(gc, milliseconds, &absolute);
         if (rc) goto out;
 
-        rc = time_register_finite(gc, ev, abs);
+        rc = time_register_finite(gc, ev, absolute);
         if (rc) goto out;
     }
 
@@ -255,26 +255,26 @@ int libxl__ev_time_register_rel(libxl__g
 }
 
 int libxl__ev_time_modify_abs(libxl__gc *gc, libxl__ev_time *ev,
-                              struct timeval abs)
+                              struct timeval absolute)
 {
     int rc;
 
     CTX_LOCK;
 
     DBG("ev_time=%p modify abs==%lu.%06lu",
-        ev, (unsigned long)abs.tv_sec, (unsigned long)abs.tv_usec);
+        ev, (unsigned long)absolute.tv_sec, (unsigned long)absolute.tv_usec);
 
     assert(libxl__ev_time_isregistered(ev));
 
     if (ev->infinite) {
-        rc = time_register_finite(gc, ev, abs);
+        rc = time_register_finite(gc, ev, absolute);
         if (rc) goto out;
     } else {
-        rc = OSEVENT_HOOK(timeout_modify, &ev->for_app_reg, abs);
+        rc = OSEVENT_HOOK(timeout_modify, &ev->for_app_reg, absolute);
         if (rc) goto out;
 
         LIBXL_TAILQ_REMOVE(&CTX->etimes, ev, entry);
-        ev->abs = abs;
+        ev->abs = absolute;
         time_insert_finite(gc, ev);
     }
 
@@ -288,7 +288,7 @@ int libxl__ev_time_modify_abs(libxl__gc 
 int libxl__ev_time_modify_rel(libxl__gc *gc, libxl__ev_time *ev,
                               int milliseconds)
 {
-    struct timeval abs;
+    struct timeval absolute;
     int rc;
 
     CTX_LOCK;
@@ -304,10 +304,10 @@ int libxl__ev_time_modify_rel(libxl__gc 
         goto out;
     }
 
-    rc = time_rel_to_abs(gc, milliseconds, &abs);
+    rc = time_rel_to_abs(gc, milliseconds, &absolute);
     if (rc) goto out;
 
-    rc = libxl__ev_time_modify_abs(gc, ev, abs);
+    rc = libxl__ev_time_modify_abs(gc, ev, absolute);
     if (rc) goto out;
 
     rc = 0;
tools/libxl/libxl_exec.c +4 -4
diff -r 0547430886c5 -r 58ab3fb73d13 tools/libxl/libxl_exec.c
@@ -35,7 +35,7 @@ static void check_open_fds(const char *w
 #ifdef __linux__
         size_t len;
         char path[PATH_MAX];
-        char link[PATH_MAX+1];
+        char linkpath[PATH_MAX+1];
 #endif
         flags = fcntl(i, F_GETFD);
         if ( flags == -1 ) {
@@ -52,11 +52,11 @@ static void check_open_fds(const char *w
 
 #ifdef __linux__
         snprintf(path, PATH_MAX, "/proc/%d/fd/%d", getpid(), i);
-        len = readlink(path, link, PATH_MAX);
+        len = readlink(path, linkpath, PATH_MAX);
         if (len > 0) {
-            link[len] = '\0';
+            linkpath[len] = '\0';
             fprintf(stderr, "libxl: execing %s: fd %d is open to %s with flags %#x\n",
-                    what, i, link, flags);
+                    what, i, linkpath, flags);
         } else
 #endif
             fprintf(stderr, "libxl: execing %s: fd %d is open with flags %#x\n",
tools/libxl/libxl_json.c +8 -8
diff -r 0547430886c5 -r 58ab3fb73d13 tools/libxl/libxl_json.c
@@ -275,7 +275,7 @@ static int json_object_append_to(libxl__
 
 void libxl__json_object_free(libxl__gc *gc, libxl__json_object *obj)
 {
-    int index = 0;
+    int idx = 0;
 
     if (obj == NULL)
         return;
@@ -287,8 +287,8 @@ void libxl__json_object_free(libxl__gc *
     case JSON_MAP: {
         libxl__json_map_node *node = NULL;
 
-        for (index = 0; index < obj->u.map->count; index++) {
-            if (flexarray_get(obj->u.map, index, (void**)&node) != 0)
+        for (idx = 0; idx < obj->u.map->count; idx++) {
+            if (flexarray_get(obj->u.map, idx, (void**)&node) != 0)
                 break;
             libxl__json_object_free(gc, node->obj);
             free(node->map_key);
@@ -302,8 +302,8 @@ void libxl__json_object_free(libxl__gc *
         libxl__json_object *node = NULL;
         break;
 
-        for (index = 0; index < obj->u.array->count; index++) {
-            if (flexarray_get(obj->u.array, index, (void**)&node) != 0)
+        for (idx = 0; idx < obj->u.array->count; idx++) {
+            if (flexarray_get(obj->u.array, idx, (void**)&node) != 0)
                 break;
             libxl__json_object_free(gc, node);
             node = NULL;
@@ -359,14 +359,14 @@ const libxl__json_object *libxl__json_ma
                                           libxl__json_node_type expected_type)
 {
     flexarray_t *maps = NULL;
-    int index = 0;
+    int idx = 0;
 
     if (libxl__json_object_is_map(o)) {
         libxl__json_map_node *node = NULL;
 
         maps = o->u.map;
-        for (index = 0; index < maps->count; index++) {
-            if (flexarray_get(maps, index, (void**)&node) != 0)
+        for (idx = 0; idx < maps->count; idx++) {
+            if (flexarray_get(maps, idx, (void**)&node) != 0)
                 return NULL;
             if (strcmp(key, node->map_key) == 0) {
                 if (expected_type == JSON_ANY
tools/libxl/libxl_pci.c +1 -1
diff -r 0547430886c5 -r 58ab3fb73d13 tools/libxl/libxl_pci.c
@@ -167,7 +167,6 @@ static int libxl__device_pci_remove_xens
     char *be_path, *num_devs_path, *num_devs, *xsdev, *tmp, *tmppath;
     int num, i, j;
     xs_transaction_t t;
-    unsigned int domain = 0, bus = 0, dev = 0, func = 0;
 
     be_path = libxl__sprintf(gc, "%s/backend/pci/%d/0", libxl__xs_get_dompath(gc, 0), domid);
     num_devs_path = libxl__sprintf(gc, "%s/num_devs", be_path);
@@ -188,6 +187,7 @@ static int libxl__device_pci_remove_xens
     }
 
     for (i = 0; i < num; i++) {
+        unsigned int domain = 0, bus = 0, dev = 0, func = 0;
         xsdev = libxl__xs_read(gc, XBT_NULL, libxl__sprintf(gc, "%s/dev-%d", be_path, i));
         sscanf(xsdev, PCI_BDF, &domain, &bus, &dev, &func);
         if (domain == pcidev->domain && bus == pcidev->bus &&
tools/libxl/libxl_qmp.c +4 -4
diff -r 0547430886c5 -r 58ab3fb73d13 tools/libxl/libxl_qmp.c
@@ -171,7 +171,7 @@ static int qmp_register_vnc_callback(lib
 {
     GC_INIT(qmp->ctx);
     const libxl__json_object *obj;
-    const char *listen, *port;
+    const char *addr, *port;
     int rc = -1;
 
     if (!libxl__json_object_is_map(o)) {
@@ -184,17 +184,17 @@ static int qmp_register_vnc_callback(lib
     }
 
     obj = libxl__json_map_get("host", o, JSON_STRING);
-    listen = libxl__json_object_get_string(obj);
+    addr = libxl__json_object_get_string(obj);
     obj = libxl__json_map_get("service", o, JSON_STRING);
     port = libxl__json_object_get_string(obj);
 
-    if (!listen || !port) {
+    if (!addr || !port) {
         LIBXL__LOG(qmp->ctx, LIBXL__LOG_ERROR,
                    "Failed to retreive VNC connect information.");
         goto out;
     }
 
-    rc = qmp_write_domain_console_item(gc, qmp->domid, "vnc-listen", listen);
+    rc = qmp_write_domain_console_item(gc, qmp->domid, "vnc-listen", addr);
     if (!rc)
         rc = qmp_write_domain_console_item(gc, qmp->domid, "vnc-port", port);
#2 lore raw

PATCH 1/1 xl: prepare to enable Wshadow

In reply to Ian Campbell

# HG changeset patch
# User Ian Campbell <[email protected]> # Date 1347621684 -3600
# Node ID 192e4a16a057a456cc78e4ee46242315d474d116 # Parent 58ab3fb73d13e250f334a38599b749640deac190
xl: prepare to enable Wshadow

Takes care of everything other than the global domid clashes.

Avoid galobal functions
- stime(2)
- time(2)

tools/libxl/xl_cmdimpl.c +21 -22
diff -r 58ab3fb73d13 -r 192e4a16a057 tools/libxl/xl_cmdimpl.c
@@ -676,7 +676,7 @@ static void parse_config_data(const char
         b_info->max_vcpus = l;
 
     if (!xlu_cfg_get_list (config, "cpus", &cpus, 0, 1)) {
-        int i, n_cpus = 0;
+        int n_cpus = 0;
 
         if (libxl_cpu_bitmap_alloc(ctx, &b_info->cpumap, 0)) {
             fprintf(stderr, "Unable to allocate cpumap\n");
@@ -1200,7 +1200,6 @@ skip_vfb:
     }
 
     if (!xlu_cfg_get_list (config, "pci", &pcis, 0, 0)) {
-        int i;
         d_config->num_pcidevs = 0;
         d_config->pcidevs = NULL;
         for(i = 0; (buf = xlu_cfg_get_listitem (pcis, i)) != NULL; i++) {
@@ -1223,7 +1222,6 @@ skip_vfb:
     switch (xlu_cfg_get_list(config, "cpuid", &cpuids, 0, 1)) {
     case 0:
         {
-            int i;
             const char *errstr;
 
             for (i = 0; (buf = xlu_cfg_get_listitem(cpuids, i)) != NULL; i++) {
@@ -1553,7 +1551,7 @@ static int preserve_domain(uint32_t *r_d
 {
     time_t now;
     struct tm tm;
-    char stime[24];
+    char strtime[24];
 
     libxl_uuid new_uuid;
 
@@ -1571,7 +1569,7 @@ static int preserve_domain(uint32_t *r_d
         return 0;
     }
 
-    if (!strftime(&stime[0], sizeof(stime), "-%Y%m%dT%H%MZ", &tm)) {
+    if (!strftime(&strtime[0], sizeof(strtime), "-%Y%m%dT%H%MZ", &tm)) {
         LOG("Failed to format time as a string");
         return 0;
     }
@@ -1579,9 +1577,9 @@ static int preserve_domain(uint32_t *r_d
     libxl_uuid_generate(&new_uuid);
 
     LOG("Preserving domain %d %s with suffix%s",
-        *r_domid, d_config->c_info.name, stime);
+        *r_domid, d_config->c_info.name, strtime);
     rc = libxl_domain_preserve(ctx, *r_domid, &d_config->c_info,
-                               stime, new_uuid);
+                               strtime, new_uuid);
 
     /*
      * Although the domain still exists it is no longer the one we are
@@ -2697,7 +2695,8 @@ static void destroy_domain(const char *p
     if (rc) { fprintf(stderr,"destroy failed (rc=%d)\n",rc); exit(-1); }
 }
 
-static void shutdown_domain(const char *p, int wait, int fallback_trigger)
+static void shutdown_domain(const char *p, int wait_for_it,
+                            int fallback_trigger)
 {
     int rc;
     libxl_event *event;
@@ -2719,7 +2718,7 @@ static void shutdown_domain(const char *
         fprintf(stderr,"shutdown failed (rc=%d)\n",rc);exit(-1);
     }
 
-    if (wait) {
+    if (wait_for_it) {
         libxl_evgen_domain_death *deathw;
 
         rc = libxl_evenable_domain_death(ctx, domid, 0, &deathw);
@@ -3685,7 +3684,7 @@ int main_destroy(int argc, char **argv)
 int main_shutdown(int argc, char **argv)
 {
     int opt;
-    int wait = 0;
+    int wait_for_it = 0;
     int fallback_trigger = 0;
 
     while ((opt = def_getopt(argc, argv, "wF", "shutdown", 1)) != -1) {
@@ -3693,7 +3692,7 @@ int main_shutdown(int argc, char **argv)
         case 0: case 2:
             return opt;
         case 'w':
-            wait = 1;
+            wait_for_it = 1;
             break;
         case 'F':
             fallback_trigger = 1;
@@ -3701,7 +3700,7 @@ int main_shutdown(int argc, char **argv)
         }
     }
 
-    shutdown_domain(argv[optind], wait, fallback_trigger);
+    shutdown_domain(argv[optind], wait_for_it, fallback_trigger);
     return 0;
 }
 
@@ -4461,7 +4460,7 @@ static void output_topologyinfo(void)
     return;
 }
 
-static void info(int numa)
+static void print_info(int numa)
 {
     output_nodeinfo();
 
@@ -4504,7 +4503,7 @@ int main_info(int argc, char **argv)
         }
     }
 
-    info(numa);
+    print_info(numa);
     return 0;
 }
 
@@ -5573,19 +5572,19 @@ int main_blockdetach(int argc, char **ar
     return rc;
 }
 
-static char *uptime_to_string(unsigned long time, int short_mode)
+static char *uptime_to_string(unsigned long uptime, int short_mode)
 {
     int sec, min, hour, day;
     char *time_string;
     int ret;
 
-    day = (int)(time / 86400);
-    time -= (day * 86400);
-    hour = (int)(time / 3600);
-    time -= (hour * 3600);
-    min = (int)(time / 60);
-    time -= (min * 60);
-    sec = time;
+    day = (int)(uptime / 86400);
+    uptime -= (day * 86400);
+    hour = (int)(uptime / 3600);
+    uptime -= (hour * 3600);
+    min = (int)(uptime / 60);
+    uptime -= (min * 60);
+    sec = uptime;
 
     if (short_mode)
         if (day > 1)
tools/libxl/xl_sxp.c +0 -1
diff -r 58ab3fb73d13 -r 192e4a16a057 tools/libxl/xl_sxp.c
@@ -78,7 +78,6 @@ void printf_info_sexp(int domid, libxl_d
            libxl_defbool_to_string(b_info->disable_migrate));
 
     if (c_info->type == LIBXL_DOMAIN_TYPE_PV && b_info->u.pv.bootloader) {
-        int i;
         printf("\t(bootloader %s)\n", b_info->u.pv.bootloader);
         if (b_info->u.pv.bootloader_args) {
             printf("\t(bootloader_args");
Acked-by on v1 1/1
#3 lore raw

Re: [PATCH 2 of 3] xl: prepare to enable Wshadow

Ian Campbell writes ("[PATCH 2 of 3] xl: prepare to enable Wshadow"):

Quoted 1 line

xl: prepare to enable Wshadow

#4 lore raw

PATCH 1/1 xl: Remove global domid and enable -Wshadow

In reply to Ian Campbell

# HG changeset patch
# User Ian Campbell <[email protected]> # Date 1347626449 -3600
# Node ID 8fad3481f8c90bb66fff4973b4c5653ebb7ca52e # Parent 192e4a16a057a456cc78e4ee46242315d474d116
xl: Remove global domid and enable -Wshadow

Lots of functions loop over a list of domain and others take a domid as a parameter, shadowing the global one and leading to all sorts of confusion.

Therefore remove the global domid and explicitly pass it around as necessary.

Adds a domid to the parameters for many functions and switches many others from taking a char * domain specifier to taking a domid, pushing the domid lookup to the toplevel.

Replaces some open-coded domain_qualifier_to_domid error checking with find_domain.

---

I find it hard to believe I won't have broken anything here... I tested basic lifecycle ops only.

tools/libxl/Makefile +4 -1
diff -r 192e4a16a057 -r 8fad3481f8c9 tools/libxl/Makefile
@@ -89,10 +89,13 @@ LIBXLU_OBJS = libxlu_cfg_y.o libxlu_cfg_
 
 CLIENTS = xl testidl libxl-save-helper
 
+CFLAGS_XL += $(CFLAGS_libxenlight)
+CFLAGS_XL += -Wshadow
+
 XL_OBJS = xl.o xl_cmdimpl.o xl_cmdtable.o xl_sxp.o
 $(XL_OBJS) _libxl.api-for-check: \
             CFLAGS += $(CFLAGS_libxenctrl) # For xentoollog.h
-$(XL_OBJS): CFLAGS += $(CFLAGS_libxenlight)
+$(XL_OBJS): CFLAGS += $(CFLAGS_XL)
 $(XL_OBJS): CFLAGS += -include $(XEN_ROOT)/tools/config.h # libxl_json.h needs it.
 
 SAVE_HELPER_OBJS = libxl_save_helper.o _libxl_save_msgs_helper.o
tools/libxl/xl_cmdimpl.c +136 -153

971 lines not on this page · raw message

#5 lore raw

Re: [PATCH 3 of 3] xl: Remove global domid and enable -Wshadow

Quoted 2 lines · Ian Campbell

I find it hard to believe I won't have broken anything here... I tested basic lifecycle ops only.

I should have taken this bet :-/

Incremental fixup to the patch below... (could be folded in)

8<--------------------------------------------------

xl: make sure we always use the result of find_domain

This is a leftover from when domid was a global.

Annotate it with want_unused_result and fix the handful of errors.

tools/libxl/xl_cmdimpl.c +5 -4
diff -r 8fad3481f8c9 tools/libxl/xl_cmdimpl.c
@@ -195,6 +195,7 @@ static int cpupool_qualifier_to_cpupooli
     return was_name ? libxl_name_to_cpupoolid(ctx, p, poolid_r) : 0;
 }
 
+static uint32_t find_domain(const char *p) __attribute__((warn_unused_result));
 static uint32_t find_domain(const char *p)
 {
     uint32_t domid;
@@ -5807,7 +5808,7 @@ int main_tmem_freeze(int argc, char **ar
     if (all)
         domid = INVALID_DOMID;
     else
-        find_domain(dom);
+        domid = find_domain(dom);
 
     libxl_tmem_freeze(ctx, domid);
     return 0;
@@ -5840,7 +5841,7 @@ int main_tmem_thaw(int argc, char **argv
     if (all)
         domid = INVALID_DOMID;
     else
-        find_domain(dom);
+        domid = find_domain(dom);
 
     libxl_tmem_thaw(ctx, domid);
     return 0;
@@ -5887,7 +5888,7 @@ int main_tmem_set(int argc, char **argv)
     if (all)
         domid = INVALID_DOMID;
     else
-        find_domain(dom);
+        domid = find_domain(dom);
 
     if (!opt_w && !opt_c && !opt_p) {
         fprintf(stderr, "No set value specified.\n\n");
@@ -5942,7 +5943,7 @@ int main_tmem_shared_auth(int argc, char
     if (all)
         domid = INVALID_DOMID;
     else
-        find_domain(dom);
+        domid = find_domain(dom);
 
     if (uuid == NULL || autharg == NULL) {
         fprintf(stderr, "No uuid or auth specified.\n\n");
Acked-by
#6 lore raw

Re: [PATCH 3 of 3] xl: Remove global domid and enable -Wshadow

Ian Campbell writes ("Re: [Xen-devel] [PATCH 3 of 3] xl: Remove global domid and enable -Wshadow"):

Quoted 1 line

Annotate it with want_unused_result and fix the handful of errors.

Oops,

Acked-by on v1 1/1
#7 lore raw

Re: [PATCH 3 of 3] xl: Remove global domid and enable -Wshadow

In reply to Ian Campbell

Ian Campbell writes ("[PATCH 3 of 3] xl: Remove global domid and enable -Wshadow"):

Quoted 1 line

xl: Remove global domid and enable -Wshadow

Quoted 2 lines

I find it hard to believe I won't have broken anything here... I tested basic lifecycle ops only.

You may also have fixed something. I say commit it.

Also, sorry for being the ultimate cause of this mess.

Ian.

author Applied
#8 lore raw
In reply to Ian Campbell
Quoted 6 lines · Ian Campbell

We've had several occuranced of confusion on xl due to shadowing the global domid variable with a local one. The main bulk of this series removes that global, the rest is smaller cleanups to allow Wshadow.

I've already sent the libxl part of this, but am reincluding here as part of the set.

I have applied 2/3 + 3/3 + folded in the incremental fix to 3/3 with Ian's acks.

I applied V2 of 1/3 from the separate "libxl: Enable -Wshadow" thread.

Thanks.
Ian.