service with shared libraries
robin at uk-smiths.com
Wed Apr 15 07:50:57 UTC 2015
It has been many years since I wrote any C but can you flush the printf with the fflush command and possibly a sync() to really force it to disk?
From: Andrei Porumb <anporumb at microsoft.com>
To: Andrei Porumb <anporumb at microsoft.com>; "snappy-app-devel at lists.ubuntu.com" <snappy-app-devel at lists.ubuntu.com>
Sent: Wednesday, 15 April 2015, 1:37
Subject: RE: service with shared libraries
After a lot of debugging and with the help of people much more knowledgeable than I am, I return with updated information.
The information which I posted was true, but I was on a wrong debug track. After int main(void) there was a printf in my code... and since I never saw that printf I was assuming "something happens before main" (and since I was using a special shared library it made sense that "loading shared libraries has a problem"). On the other hand, having the app run just nicely, was a sign that my assumption was wrong.
And it was. The reason I was not seeing any printf debugging was because of the Segmentation Fault. Printf output is buffered and when segfault happens, that buffer is not flushed. And it is lost. So in reality the printfs were happening (and so was most of my code), just I was not able to gain any insight on that.
The reason why the service was crashing with segfault was because of a simple getchar() C function call. Hint: services do not have a standard input. Because no console is created for a service. As opposed to an application (that runs from a console, so it has stdin, stdout).
It was all fine and nice when printf("press any key to continue"); has been replaced with while(1);
TL;DR version: don't use getchar() in a service.
From: snappy-app-devel-bounces at lists.ubuntu.com [mailto:snappy-app-devel-bounces at lists.ubuntu.com] On Behalf Of Andrei Porumb
Sent: Monday, April 13, 2015 10:28 AM
To: snappy-app-devel at lists.ubuntu.com
Subject: service with shared libraries
I need to use Ubuntu Snappy to develop a service. The service has "special communication needs"... err... AMQP... so it needs a shared library to do so.
The code is written in C. For the executable to load the shared library, it needs to have set LD_LIBRARY_PATH. So the service is started by a bash script that doesn't do much, except:
echo this line should never be executed.
This is the content of package.yaml
maintainer: mailto:anporumb at microsoft.com
- name: sum
Problem: the service doesn't start.
Observations: if the app is run from the command line (as a regular app), the app runs just fine and performs as expected.
When run as a service, there's no life.
Journalctl helps a little here, and this is the output:
ubuntu at localhost:/apps/simplesampleamqp/current$ sudo journalctl -f -u simplesampleamqp_sum_45
-- Logs begin at Sun 2015-04-12 16:33:29 UTC. --
Apr 13 16:59:12 localhost.localdomain systemd: Started SomeService.
Apr 13 16:59:12 localhost.localdomain systemd: Starting SomeService...
Apr 13 16:59:12 localhost.localdomain sum.sh: Segmentation fault
Apr 13 16:59:12 localhost.localdomain sum.sh: this line should never be executed.
The segmentation fault happens (as far as I can tell) before the first line in main. Since this is C code (as opposed to C++) there cannot be other code executed before main.
Further investigation revealed that in the small script that attempts to start the service there cannot be just any command. For example, "ldd" cannot be there (if it is, there's going to be a DENIAL something like : Apr 12 19:53:10 localhost.localdomain kernel: audit: type=1400 audit(1428868390.904:62): apparmor="DENIED" operation="exec" profile="simplesampleamqp_sum_44" name="/usr/bin/ldd" pid=2310 comm="sum.sh" requested_mask="x" denied_mask="x" fsuid=0 ouid=0). Echo is fine to be in the script...
I guess it all boils down to: how does one write some service in C that needs some shared libraries and loads them and executes? As an "app" the executable runs fine...
Any hints/help is greatly appreciated.
snappy-app-devel mailing list
snappy-app-devel at lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/snappy-app-devel
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the snappy-app-devel