# Get my app version in c/c++ code

**URL:** <https://forum.legato.io/t/get-my-app-version-in-c-c-code/5117>\
**Category:** Legato Application Framework\
**Created:** [March 30, 2020, 12:49pm UTC](https://forum.legato.io/t/get-my-app-version-in-c-c-code/5117 "2020-03-30T12:49:35Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![damir](https://avatars.discourse-cdn.com/v4/letter/d/7993a0/32.png) [@damir](https://forum.legato.io/u/damir)\
**Post date:** [March 30, 2020, 12:49pm UTC](https://forum.legato.io/t/get-my-app-version-in-c-c-code/5117/1 "2020-03-30T12:49:35Z")

</div>

Hi,

I tried this:

> le\_cfg\_QuickGetString(“/apps/appname/version”, version, 256, “unknown”);

no luck, always unknown

Is there a better way to read app version from adef?

adef:

> ```
> requires:
> {
> configTree:
> {
> [r] .
> }
> }
> 
> ```

Device: FX30(WP7702)  
Firmware Version: SWI9X06Y\_02.16.06.00 7605a6 jenkins 2018/06/20 17:56:12  
Bootloader Version: SWI9X06Y\_02.16.06.00 7605a6 jenkins 2018/06/20 17:56:12  
MCU Version: 002.009  
PRI Revision: 001.000  
Carrier PRI Name: GENERIC  
Carrier PRI Revision: 001.028\_002  
Legato version: 18.06.1

---

<div class="post-metadata">

**Author:** ![Sasha](https://avatars.discourse-cdn.com/v4/letter/s/54ee81/32.png) [@Sasha](https://forum.legato.io/u/Sasha)\
**Post date:** [March 30, 2020, 2:19pm UTC](https://forum.legato.io/t/get-my-app-version-in-c-c-code/5117/2 "2020-03-30T14:19:38Z")

</div>

You should use the real name of your application, not just `appname`, unless the name of your application is `appname`. So, if the name of your application is `someApp` the code should be something like

```auto
char version[256] ;

le_cfg_QuickGetString("/apps/someApp/version", version, sizeof(version), "unknown");

```

---

<div class="post-metadata">

**Author:** ![damir](https://avatars.discourse-cdn.com/v4/letter/d/7993a0/32.png) [@damir](https://forum.legato.io/u/damir)\
**Post date:** [March 30, 2020, 3:00pm UTC](https://forum.legato.io/t/get-my-app-version-in-c-c-code/5117/3 "2020-03-30T15:00:34Z")

</div>

Lets imagine for a minute that i am not a complete idiot and i actually used my real app name (app name is irrelevant to the question) and it still doesn’t work.  
What else should i try?

---

<div class="post-metadata">

**Author:** ![Sasha](https://avatars.discourse-cdn.com/v4/letter/s/54ee81/32.png) [@Sasha](https://forum.legato.io/u/Sasha)\
**Post date:** [March 30, 2020, 3:18pm UTC](https://forum.legato.io/t/get-my-app-version-in-c-c-code/5117/4 "2020-03-30T15:18:34Z")

</div>

- If your application is multithreaded, check that the thread calls `le_cfg_ConnectService`.
- Check return value of this function, it may clarify the situation
- Check logs, look for Legato-related errors.
- Check config tree from shell: `config get /apps/someApp/version`

Well, most probably, you’ve already took all those steps.

---

<div class="post-metadata">

**Author:** ![damir](https://avatars.discourse-cdn.com/v4/letter/d/7993a0/32.png) [@damir](https://forum.legato.io/u/damir)\
**Post date:** [March 30, 2020, 4:13pm UTC](https://forum.legato.io/t/get-my-app-version-in-c-c-code/5117/5 "2020-03-30T16:13:53Z")

</div>

- Code being called form main thread, i presume le\_cfg\_ConnectService being called automatically for main thread
- Always returns LE\_OK
- No error whatsoever in logs
- It works, returns proper value

---

<div class="post-metadata">

**Author:** ![Sasha](https://avatars.discourse-cdn.com/v4/letter/s/54ee81/32.png) [@Sasha](https://forum.legato.io/u/Sasha)\
**Post date:** [March 30, 2020, 5:01pm UTC](https://forum.legato.io/t/get-my-app-version-in-c-c-code/5117/6 "2020-03-30T17:01:21Z")

</div>

Try to grant your application access to the system tree.  
For example, in your `.adef`

```auto
requires:
{
  configTree:
    {
        [r] .
        otherApp
    }
}
```

---

<div class="post-metadata">

**Author:** ![damir](https://avatars.discourse-cdn.com/v4/letter/d/7993a0/32.png) [@damir](https://forum.legato.io/u/damir)\
**Post date:** [March 30, 2020, 5:54pm UTC](https://forum.legato.io/t/get-my-app-version-in-c-c-code/5117/7 "2020-03-30T17:54:48Z")

</div>

Tried. As mentioned in my very first post.

---

<div class="post-metadata">

**Author:** ![Sasha](https://avatars.discourse-cdn.com/v4/letter/s/54ee81/32.png) [@Sasha](https://forum.legato.io/u/Sasha)\
**Post date:** [March 30, 2020, 6:05pm UTC](https://forum.legato.io/t/get-my-app-version-in-c-c-code/5117/8 "2020-03-30T18:05:29Z")

</div>

adef in your first post looks

```auto
requires:
{
  configTree:
    {
        [r] .
    }
}

```

It grants read access to your own tree, not system tree

---

<div class="post-metadata">

**Author:** ![damir](https://avatars.discourse-cdn.com/v4/letter/d/7993a0/32.png) [@damir](https://forum.legato.io/u/damir)\
**Post date:** [March 31, 2020, 12:29pm UTC](https://forum.legato.io/t/get-my-app-version-in-c-c-code/5117/9 "2020-03-31T12:29:48Z")

</div>

> [@Sasha](#):
>
> otherApp

Is it some kind of reserved name? Otherwise i don’t understand what should i put there and how it should help.  
Sorry i can’t test it right now, problems with my linux machine.

---

<div class="post-metadata">

**Author:** ![Sasha](https://avatars.discourse-cdn.com/v4/letter/s/54ee81/32.png) [@Sasha](https://forum.legato.io/u/Sasha)\
**Post date:** [March 31, 2020, 5:17pm UTC](https://forum.legato.io/t/get-my-app-version-in-c-c-code/5117/10 "2020-03-31T17:17:19Z")

</div>

Actually, there are 2 slightly different cases:

- Sandboxed application
- Non-sandboxed application

If your application is non-sandboxed, then your original procedure should work, afaik.  
In case of sandboxed application, for each application there is its own config tree and you should grant your application access to to those trees. `version` information is located in `system` tree, so you should grant access to the `system` tree.

```auto
requires:
{
	configTree:
	{
		[w] . // I need write access to my configuration data.
		[r] system // I need read access to system configuration data.
	}
}

```

But that’s not all. If you’re accessing another tree, you should specify the name of this tree in `path` argument. So, it should look something like:

```auto
char version[256] = "unknown";
le_cfg_QuickGetString("system:/apps/helloWorld/version", version, sizeof(version), version);

```

---

<div class="post-metadata">

**Author:** ![damir](https://avatars.discourse-cdn.com/v4/letter/d/7993a0/32.png) [@damir](https://forum.legato.io/u/damir)\
**Post date:** [March 31, 2020, 6:06pm UTC](https://forum.legato.io/t/get-my-app-version-in-c-c-code/5117/11 "2020-03-31T18:06:05Z")

</div>

Yep, it worked!  
Thank you very much for your support …and patience 🙂

---

<div class="post-metadata">

**Author:** ![Sasha](https://avatars.discourse-cdn.com/v4/letter/s/54ee81/32.png) [@Sasha](https://forum.legato.io/u/Sasha)\
**Post date:** [April 1, 2020, 5:54am UTC](https://forum.legato.io/t/get-my-app-version-in-c-c-code/5117/12 "2020-04-01T05:54:24Z")

</div>

My pleasure.

Hurmat bilan,  
Sasha.

---

<div class="post-metadata">

**Author:** ![mike.brearton](https://avatars.discourse-cdn.com/v4/letter/m/e495f1/32.png) [@mike.brearton](https://forum.legato.io/u/mike.brearton)\
**Post date:** [October 7, 2022, 5:22am UTC](https://forum.legato.io/t/get-my-app-version-in-c-c-code/5117/13 "2022-10-07T05:22:55Z")

</div>

Is there another way to do this? It’s been a while… so hoping.  
The manuals specifically say to NOT grant access to system, for security reasons; but then tell us that’s the only way for an application to know its own version. It’s an important piece of trivia… so… hoping there’s a cleaner way.

---

<div class="post-metadata">

**Author:** ![jyijyi](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/jyijyi/32/822_2.png) [@jyijyi](https://forum.legato.io/u/jyijyi)\
**Post date:** [October 7, 2022, 6:10am UTC](https://forum.legato.io/t/get-my-app-version-in-c-c-code/5117/14 "2022-10-07T06:10:15Z")

</div>

do you mean this?

```auto
root@swi-mdm9x28-wp:~# app version wifi
wifi 19.02.0.rc3
root@swi-mdm9x28-wp:~# app version atServerIntegrationTest
atServerIntegrationTest has no version

```

---

<div class="post-metadata">

**Author:** ![mike.brearton](https://avatars.discourse-cdn.com/v4/letter/m/e495f1/32.png) [@mike.brearton](https://forum.legato.io/u/mike.brearton)\
**Post date:** [October 7, 2022, 7:36am UTC](https://forum.legato.io/t/get-my-app-version-in-c-c-code/5117/15 "2022-10-07T07:36:04Z")

</div>

Those are the details I’m trying to get… from inside my (sandboxed) Legato C code. I was hoping the app\_info API would help, but… no.

---

<div class="post-metadata">

**Author:** ![jyijyi](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/jyijyi/32/822_2.png) [@jyijyi](https://forum.legato.io/u/jyijyi)\
**Post date:** [October 7, 2022, 7:39am UTC](https://forum.legato.io/t/get-my-app-version-in-c-c-code/5117/16 "2022-10-07T07:39:16Z")

</div>

Have you referred to the code here for “app version”?

> <https://github.com/legatoproject/legato-af/blob/master/framework/tools/target/linux/appCtrl/appCtrl.c>

BTW, will you consider an easier way to create an unsandboxed application to handle this “app version” and then your sandboxed application can communicate with it via IPC?

---

<div class="post-metadata">

**Author:** ![mike.brearton](https://avatars.discourse-cdn.com/v4/letter/m/e495f1/32.png) [@mike.brearton](https://forum.legato.io/u/mike.brearton)\
**Post date:** [October 8, 2022, 8:06am UTC](https://forum.legato.io/t/get-my-app-version-in-c-c-code/5117/17 "2022-10-08T08:06:13Z")

</div>

The appCtrl code uses same technique: read the system:/apps config tree. So I suppose… that’s how it’s done.  
Needing to expose system: just to include a version number in help-about response text… seems there should be a better way. The appinfo API returns a HASH of the version number, but not the version number itself… unsure where that decision came from.

---

<div class="post-metadata">

**Author:** ![jyijyi](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/jyijyi/32/822_2.png) [@jyijyi](https://forum.legato.io/u/jyijyi)\
**Post date:** [October 8, 2022, 9:29am UTC](https://forum.legato.io/t/get-my-app-version-in-c-c-code/5117/18 "2022-10-08T09:29:55Z")

</div>

will you consider an easier way to create an unsandboxed application to handle this “app version” and then your sandboxed application can communicate with it via IPC?

---

<div class="post-metadata">

**Author:** ![mike.brearton](https://avatars.discourse-cdn.com/v4/letter/m/e495f1/32.png) [@mike.brearton](https://forum.legato.io/u/mike.brearton)\
**Post date:** [October 9, 2022, 7:44am UTC](https://forum.legato.io/t/get-my-app-version-in-c-c-code/5117/19 "2022-10-09T07:44:19Z")

</div>

IPC plus another application. Might be easier. Perhaps not.  
Using “make”, I can achieve the goal without that.

To make the application version available to both Legato and the application itself, I did the following.

1. I removed the version from ADEF, and put it into a one-line “app.version” file
2. mkapp then adds it back when building (using the -a parameter)
3. make also creates an app.version.h file… which will be compiled into the code  
OR
4. use a -D compile option to add the #define statement using pre-processing

This way, the version number is available to both Legato and my application code. They get the information from different sources, but the answer will be consistent.

I’m a “make” newbie… but here’s my Makefile change. (Listening eagerly for a better alternative.)

```
$(TARGETS):
	# appVersion=`cat $@.version`; echo -n "#define APPVERSION \"${appVersion}\"" > $@.version.h

mkapp -t wp77xx \
	-i $(LEGATO_ROOT)/interfaces/modemServices \
	-C -DAPPVERSION=\\\"`cat $@.version`\\\" \
	-a `cat $@.version` \
	-a . \
	-a `date +%Y%m%d%H%M` \
	$@.adef

```
