xl: uptime: skip dom0 when calling print_domU_uptime
PATCH 1/2 xl: uptime: skip dom0 when calling print_domU_uptime
Dom0 is handled separately (via print_dom0_uptime) and the domU variant doesn't work for dom0 since libxl_vm_get_start_time() doesn't.
--- tools/libxl/xl_cmdimpl.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
tools/libxl/xl_cmdimpl.c +3 -1
@@ -7055,8 +7055,10 @@ static void print_uptime(int short_mode, uint32_t doms[], int nb_doms)fprintf (stderr,"Could not list vms.\n" );return ; } -for (i =0 ; i < nb_vm; i++) +for (i =0 ; i < nb_vm; i++) { +if (info[i].domid ==0 )continue ;print_domU_uptime (info[i].domid, short_mode, now); + }libxl_vminfo_list_free (info, nb_vm); }else {for (i =0 ; i < nb_doms; i++) {
Signature · 1 line
2.1.4
PATCH 2/2 xl: NULL terminate buf when reading dom0 /proc/uptime
The contents of /proc/uptime is typically something like "80164.57 640617.58", so the existing 512 byte buffer is more than large enoguh, so reduce its effective size to 511 bytes and ensure we include a NULL.
Otherwise Coverity points out that we pass a potentially unterminated string to strtok. In practice this likely doesn't actually cause issues (at least on Linux) because the
string should always contain a space so we will stop parsing.
CID: 105590
--- tools/libxl/xl_cmdimpl.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
tools/libxl/xl_cmdimpl.c +5 -1
@@ -6959,6 +6959,7 @@ static char *current_time_to_string(time_t now)static void print_dom0_uptime (int short_mode,time_t now) {int fd; +ssize_t nr;char buf[512 ];uint32_t uptime =0 ;char *uptime_str =NULL ;
@@ -6969,12 +6970,15 @@ static void print_dom0_uptime(int short_mode, time_t now)if (fd ==-1 ) goto err; -if (read (fd, buf,sizeof (buf)) ==-1 ) { + nr =read (fd, buf,sizeof (buf) -1 ); +if (nr ==-1 ) {close (fd); goto err; }close (fd); + buf[nr] ='\0' ; +strtok (buf," " ); uptime =strtoul (buf,NULL ,10 );
Signature · 1 line
2.1.4
Re: [PATCH 2/2] xl: NULL terminate buf when reading dom0 /proc/uptime
Ian Campbell writes ("[PATCH 2/2] xl: NULL terminate buf when reading dom0 /proc/uptime"):
Quoted 9 lines
The contents of
/proc/uptimeis typically something like "80164.57 640617.58", so the existing 512 byte buffer is more than large enoguh, so reduce its effective size to 511 bytes and ensure we include a NULL.Otherwise Coverity points out that we pass a potentially unterminated string to strtok. In practice this likely doesn't actually cause issues (at least on Linux) because the
string should always contain a space so we will stop parsing.
and queued
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Quoted 4 lines · Ian Campbell
Dom0 is handled separately (via
print_dom0_uptime) and the domU variant doesn't work for dom0 sincelibxl_vm_get_start_time()doesn't.Signed-off-by Ian Campbell <[email protected]>
Ping? (and for 2/2 "xl: NULL terminate buf when reading dom0 /proc/uptime")
Quoted 20 lines
---
tools/libxl/xl_cmdimpl.c | 4 +++-1 file changed, 3 insertions(+), 1 deletion(-)tools/libxl/xl_cmdimpl.c +3
-1@@ -7055,8 +7055,10 @@ static void print_uptime(int short_mode, uint32_t doms[], int nb_doms) fprintf(stderr, "Could not list vms.\n"); return; } - for (i = 0; i < nb_vm; i++) + for (i = 0; i < nb_vm; i++) { + if (info[i].domid == 0) continue; print_domU_uptime(info[i].domid, short_mode, now); + } libxl_vminfo_list_free(info, nb_vm); } else {
Quoted 1 line
for (i = 0; i <
nb_doms; i++) {
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Ian Campbell writes ("[PATCH 1/2] xl: uptime: skip dom0 when calling print_domU_uptime"):
Quoted 4 lines
Dom0 is handled separately (via
print_dom0_uptime) and the domU variant doesn't work for dom0 sincelibxl_vm_get_start_time()doesn't.Signed-off-by Ian Campbell <[email protected]>
and queued
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel