crtools: also print the current kernel version

Submitted by Adrian Reber on Nov. 24, 2017, 10:19 a.m.

Details

Message ID 1511518775-15031-1-git-send-email-adrian@lisas.de
State New
Series "crtools: also print the current kernel version"
Headers show

Commit Message

Adrian Reber Nov. 24, 2017, 10:19 a.m.
From: Adrian Reber <areber@redhat.com>

In addition to writing the CRIU version to the log file this adds the
current kernel version to the log file:

(00.000008) Version: 3.5 (gitid v3.5-511-ga8cc6cf)
(00.000303) Running on node01 Linux 3.10.0-513.el7.x86_64 #1 SMP Tue Feb 29 06:78:90 EST 2017 x86_64

Signed-off-by: Adrian Reber <areber@redhat.com>
---
 criu/crtools.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

Patch hide | download patch | download mbox

diff --git a/criu/crtools.c b/criu/crtools.c
index 293d631..7519269 100644
--- a/criu/crtools.c
+++ b/criu/crtools.c
@@ -21,6 +21,7 @@ 
 
 #include <sys/time.h>
 #include <sys/resource.h>
+#include <sys/utsname.h>
 
 #include "int.h"
 #include "page.h"
@@ -421,6 +422,19 @@  static void init_configuration(int argc, char *argv[], int defaults_forbidden)
 	}
 }
 
+static void kernel_version()
+{
+	struct utsname buf;
+	if (uname(&buf) != 0) {
+		pr_perror("Reading kernel version failed!");
+		/* This pretty unlikely, just keep on running. */
+		return;
+	}
+
+	pr_info("Running on %s %s %s %s %s\n", buf.nodename, buf.sysname,
+		buf.release, buf.version, buf.machine);
+}
+
 int main(int argc, char *argv[], char *envp[])
 {
 #define PARSING_GLOBAL_CONF	1
@@ -967,6 +981,9 @@  int main(int argc, char *argv[], char *envp[])
 	compel_log_init(vprint_on_level, log_get_loglevel());
 
 	pr_info("Version: %s (gitid %s)\n", CRIU_VERSION, CRIU_GITID);
+
+	kernel_version();
+
 	if (opts.deprecated_ok)
 		pr_debug("DEPRECATED ON\n");
 

Comments

Dmitry Safonov Nov. 24, 2017, 12:16 p.m.
I like it!
Just very minor style nitpicks inline.

2017-11-24 10:19 GMT+00:00 Adrian Reber <adrian@lisas.de>:
> From: Adrian Reber <areber@redhat.com>
>
> In addition to writing the CRIU version to the log file this adds the
> current kernel version to the log file:
>
> (00.000008) Version: 3.5 (gitid v3.5-511-ga8cc6cf)
> (00.000303) Running on node01 Linux 3.10.0-513.el7.x86_64 #1 SMP Tue Feb 29 06:78:90 EST 2017 x86_64
>
> Signed-off-by: Adrian Reber <areber@redhat.com>
> ---
>  criu/crtools.c | 17 +++++++++++++++++
>  1 file changed, 17 insertions(+)
>
> diff --git a/criu/crtools.c b/criu/crtools.c
> index 293d631..7519269 100644
> --- a/criu/crtools.c
> +++ b/criu/crtools.c
> @@ -21,6 +21,7 @@
>
>  #include <sys/time.h>
>  #include <sys/resource.h>
> +#include <sys/utsname.h>
>
>  #include "int.h"
>  #include "page.h"
> @@ -421,6 +422,19 @@ static void init_configuration(int argc, char *argv[], int defaults_forbidden)
>         }
>  }
>
> +static void kernel_version()

Maybe
static void print_kernel_version(void)

> +{
> +       struct utsname buf;

newline here? ;-)

> +       if (uname(&buf) != 0) {

According to man:
> Upon successful completion, a non-negative value shall be returned.

So, something like that, hm?
if (uname(&buf) < 0) {

(just to be sure that it works with all fancy libcs)
Adrian Reber Nov. 24, 2017, 1:45 p.m.
On Fri, Nov 24, 2017 at 12:16:31PM +0000, Dmitry Safonov wrote:
> I like it!
> Just very minor style nitpicks inline.
> 
> 2017-11-24 10:19 GMT+00:00 Adrian Reber <adrian@lisas.de>:
> > From: Adrian Reber <areber@redhat.com>
> >
> > In addition to writing the CRIU version to the log file this adds the
> > current kernel version to the log file:
> >
> > (00.000008) Version: 3.5 (gitid v3.5-511-ga8cc6cf)
> > (00.000303) Running on node01 Linux 3.10.0-513.el7.x86_64 #1 SMP Tue Feb 29 06:78:90 EST 2017 x86_64
> >
> > Signed-off-by: Adrian Reber <areber@redhat.com>
> > ---
> >  criu/crtools.c | 17 +++++++++++++++++
> >  1 file changed, 17 insertions(+)
> >
> > diff --git a/criu/crtools.c b/criu/crtools.c
> > index 293d631..7519269 100644
> > --- a/criu/crtools.c
> > +++ b/criu/crtools.c
> > @@ -21,6 +21,7 @@
> >
> >  #include <sys/time.h>
> >  #include <sys/resource.h>
> > +#include <sys/utsname.h>
> >
> >  #include "int.h"
> >  #include "page.h"
> > @@ -421,6 +422,19 @@ static void init_configuration(int argc, char *argv[], int defaults_forbidden)
> >         }
> >  }
> >
> > +static void kernel_version()
> 
> Maybe
> static void print_kernel_version(void)
> 
> > +{
> > +       struct utsname buf;
> 
> newline here? ;-)
> 
> > +       if (uname(&buf) != 0) {
> 
> According to man:
> > Upon successful completion, a non-negative value shall be returned.
> 
> So, something like that, hm?
> if (uname(&buf) < 0) {
> 
> (just to be sure that it works with all fancy libcs)

Thanks for the useful feedback. Makes all sense to me. Will send a V2.

We could even move the printing of the CRIU version into this function.

		Adrian