Message ID | 20200608090652.805516-3-gary.bisson@boundarydevices.com |
---|---|
State | New |
Headers | show |
Series | Add Android build support | expand |
On Mon, Jun 8, 2020 at 11:07 AM Gary Bisson <gary.bisson@boundarydevices.com> wrote: > > program_invocation_name doesn't exist in Android, getprogname() should > be used instead. > > Signed-off-by: Gary Bisson <gary.bisson@boundarydevices.com> > --- > Hi, > > I couldn't an equivalent to program_invocation_short_name, so the > program is now using program_invocation_name all the time, hope it's ok. > > Regards, > Gary > --- > tools/tools-common.c | 10 +++++++--- > 1 file changed, 7 insertions(+), 3 deletions(-) > > diff --git a/tools/tools-common.c b/tools/tools-common.c > index 12bde20..1d7fc2c 100644 > --- a/tools/tools-common.c > +++ b/tools/tools-common.c > @@ -21,7 +21,11 @@ > > const char *get_progname(void) > { > +#if defined __ANDROID__ I'd prefer to keep libgpiod Android-agnostic. Does prctl() exist in Android? It too can be used for that. Bartosz > + return getprogname(); > +#else > return program_invocation_name; > +#endif > } > > void die(const char *fmt, ...) > @@ -29,7 +33,7 @@ void die(const char *fmt, ...) > va_list va; > > va_start(va, fmt); > - fprintf(stderr, "%s: ", program_invocation_name); > + fprintf(stderr, "%s: ", get_progname()); > vfprintf(stderr, fmt, va); > fprintf(stderr, "\n"); > va_end(va); > @@ -42,7 +46,7 @@ void die_perror(const char *fmt, ...) > va_list va; > > va_start(va, fmt); > - fprintf(stderr, "%s: ", program_invocation_name); > + fprintf(stderr, "%s: ", get_progname()); > vfprintf(stderr, fmt, va); > fprintf(stderr, ": %s\n", strerror(errno)); > va_end(va); > @@ -53,7 +57,7 @@ void die_perror(const char *fmt, ...) > void print_version(void) > { > printf("%s (libgpiod) v%s\n", > - program_invocation_short_name, gpiod_version_string()); > + get_progname(), gpiod_version_string()); > printf("Copyright (C) 2017-2018 Bartosz Golaszewski\n"); > printf("License: LGPLv2.1\n"); > printf("This is free software: you are free to change and redistribute it.\n"); > -- > 2.26.2 >
Hi, Sorry for the delay. On Mon, Aug 10, 2020 at 09:15:18PM +0200, Bartosz Golaszewski wrote: > On Mon, Jun 8, 2020 at 11:07 AM Gary Bisson > <gary.bisson@boundarydevices.com> wrote: > > > > program_invocation_name doesn't exist in Android, getprogname() should > > be used instead. > > > > Signed-off-by: Gary Bisson <gary.bisson@boundarydevices.com> > > --- > > Hi, > > > > I couldn't an equivalent to program_invocation_short_name, so the > > program is now using program_invocation_name all the time, hope it's ok. > > > > Regards, > > Gary > > --- > > tools/tools-common.c | 10 +++++++--- > > 1 file changed, 7 insertions(+), 3 deletions(-) > > > > diff --git a/tools/tools-common.c b/tools/tools-common.c > > index 12bde20..1d7fc2c 100644 > > --- a/tools/tools-common.c > > +++ b/tools/tools-common.c > > @@ -21,7 +21,11 @@ > > > > const char *get_progname(void) > > { > > +#if defined __ANDROID__ > > I'd prefer to keep libgpiod Android-agnostic. Does prctl() exist in > Android? It too can be used for that. Yes I understand. prctl() can be used in Android so it would definitely be a better option. Regards, Gary
On Mon, Aug 17, 2020 at 10:23 AM Gary Bisson <gary.bisson@boundarydevices.com> wrote: > > Hi, > > Sorry for the delay. > > On Mon, Aug 10, 2020 at 09:15:18PM +0200, Bartosz Golaszewski wrote: > > On Mon, Jun 8, 2020 at 11:07 AM Gary Bisson > > <gary.bisson@boundarydevices.com> wrote: > > > > > > program_invocation_name doesn't exist in Android, getprogname() should > > > be used instead. > > > > > > Signed-off-by: Gary Bisson <gary.bisson@boundarydevices.com> > > > --- > > > Hi, > > > > > > I couldn't an equivalent to program_invocation_short_name, so the > > > program is now using program_invocation_name all the time, hope it's ok. > > > > > > Regards, > > > Gary > > > --- > > > tools/tools-common.c | 10 +++++++--- > > > 1 file changed, 7 insertions(+), 3 deletions(-) > > > > > > diff --git a/tools/tools-common.c b/tools/tools-common.c > > > index 12bde20..1d7fc2c 100644 > > > --- a/tools/tools-common.c > > > +++ b/tools/tools-common.c > > > @@ -21,7 +21,11 @@ > > > > > > const char *get_progname(void) > > > { > > > +#if defined __ANDROID__ > > > > I'd prefer to keep libgpiod Android-agnostic. Does prctl() exist in > > Android? It too can be used for that. > > Yes I understand. prctl() can be used in Android so it would definitely > be a better option. > > Regards, > Gary The name returned by prctl(PR_GET_NAME, ...) is equivalent to program_invocation_short_name. That would mean ditching the full executable path everywhere in messages. Alternatively we can just set the full program name at the start of every tool. I'm fine with the latter too as long as we don't stick these __ANDROID__ ifdefs in the tree. Bart
Hi, On Mon, Aug 17, 2020 at 03:04:57PM +0200, Bartosz Golaszewski wrote: > On Mon, Aug 17, 2020 at 10:23 AM Gary Bisson > <gary.bisson@boundarydevices.com> wrote: > > > > Hi, > > > > Sorry for the delay. > > > > On Mon, Aug 10, 2020 at 09:15:18PM +0200, Bartosz Golaszewski wrote: > > > On Mon, Jun 8, 2020 at 11:07 AM Gary Bisson > > > <gary.bisson@boundarydevices.com> wrote: > > > > > > > > program_invocation_name doesn't exist in Android, getprogname() should > > > > be used instead. > > > > > > > > Signed-off-by: Gary Bisson <gary.bisson@boundarydevices.com> > > > > --- > > > > Hi, > > > > > > > > I couldn't an equivalent to program_invocation_short_name, so the > > > > program is now using program_invocation_name all the time, hope it's ok. > > > > > > > > Regards, > > > > Gary > > > > --- > > > > tools/tools-common.c | 10 +++++++--- > > > > 1 file changed, 7 insertions(+), 3 deletions(-) > > > > > > > > diff --git a/tools/tools-common.c b/tools/tools-common.c > > > > index 12bde20..1d7fc2c 100644 > > > > --- a/tools/tools-common.c > > > > +++ b/tools/tools-common.c > > > > @@ -21,7 +21,11 @@ > > > > > > > > const char *get_progname(void) > > > > { > > > > +#if defined __ANDROID__ > > > > > > I'd prefer to keep libgpiod Android-agnostic. Does prctl() exist in > > > Android? It too can be used for that. > > > > Yes I understand. prctl() can be used in Android so it would definitely > > be a better option. > > > > Regards, > > Gary > > The name returned by prctl(PR_GET_NAME, ...) is equivalent to > program_invocation_short_name. That would mean ditching the full > executable path everywhere in messages. Alternatively we can just set > the full program name at the start of every tool. I'm fine with the > latter too as long as we don't stick these __ANDROID__ ifdefs in the > tree. Ok, I'll test this and send a v2. Might not be before next week though. Regards, Gary
diff --git a/tools/tools-common.c b/tools/tools-common.c index 12bde20..1d7fc2c 100644 --- a/tools/tools-common.c +++ b/tools/tools-common.c @@ -21,7 +21,11 @@ const char *get_progname(void) { +#if defined __ANDROID__ + return getprogname(); +#else return program_invocation_name; +#endif } void die(const char *fmt, ...) @@ -29,7 +33,7 @@ void die(const char *fmt, ...) va_list va; va_start(va, fmt); - fprintf(stderr, "%s: ", program_invocation_name); + fprintf(stderr, "%s: ", get_progname()); vfprintf(stderr, fmt, va); fprintf(stderr, "\n"); va_end(va); @@ -42,7 +46,7 @@ void die_perror(const char *fmt, ...) va_list va; va_start(va, fmt); - fprintf(stderr, "%s: ", program_invocation_name); + fprintf(stderr, "%s: ", get_progname()); vfprintf(stderr, fmt, va); fprintf(stderr, ": %s\n", strerror(errno)); va_end(va); @@ -53,7 +57,7 @@ void die_perror(const char *fmt, ...) void print_version(void) { printf("%s (libgpiod) v%s\n", - program_invocation_short_name, gpiod_version_string()); + get_progname(), gpiod_version_string()); printf("Copyright (C) 2017-2018 Bartosz Golaszewski\n"); printf("License: LGPLv2.1\n"); printf("This is free software: you are free to change and redistribute it.\n");
program_invocation_name doesn't exist in Android, getprogname() should be used instead. Signed-off-by: Gary Bisson <gary.bisson@boundarydevices.com> --- Hi, I couldn't an equivalent to program_invocation_short_name, so the program is now using program_invocation_name all the time, hope it's ok. Regards, Gary --- tools/tools-common.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)