service with shared libraries

Robin Smith robin at
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>
To: Andrei Porumb <anporumb at>; "snappy-app-devel at" <snappy-app-devel at> 
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); 
                Thank you. 
Best Regards, 
Andrei Porumb 
TL;DR version: don't use getchar() in a service. 
From: snappy-app-devel-bounces at [mailto:snappy-app-devel-bounces at] On Behalf Of Andrei Porumb
Sent: Monday, April 13, 2015 10:28 AM
To: snappy-app-devel at
Subject: service with shared libraries   
Hello all, 
                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: 
export LD_LIBRARY_PATH=./bin 
echo this line should never be executed. 
This is the content of package.yaml 
name: simplesampleamqp 
version: 45 
icon: meta/icon.png 
maintainer: mailto:anporumb at 
- name: sum 
   description: SomeService 
   start: bin/ 
   caps: networking 
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[1]: Started SomeService. 
Apr 13 16:59:12 localhost.localdomain systemd[1]: Starting SomeService... 
Apr 13 16:59:12 localhost.localdomain[2920]: Segmentation fault 
Apr 13 16:59:12 localhost.localdomain[2920]: 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="" 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. 
Best Regards, 
Andrei Porumb 

snappy-app-devel mailing list
snappy-app-devel at
Modify settings or unsubscribe at:
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the snappy-app-devel mailing list