diff options
author | Sebastien Douheret <sebastien.douheret@iot.bzh> | 2017-07-13 22:02:20 +0200 |
---|---|---|
committer | José Bollo <jose.bollo@iot.bzh> | 2017-07-24 14:01:38 +0200 |
commit | c2fa10efe8e8b2443883e7b04b2cf452b6b8dd85 (patch) | |
tree | 3d49d3d0ae5e66f23c55593957506dd34230fafd | |
parent | 92736672c93cb9cc159af5dbc831249eb15261ed (diff) |
Add service debugging support (afm-debug).
Add necessary tools/scripts, such as afm-debug, to allow service binding.
These tools are only available in develvopment (AGL_DEVEL is set).
Change-Id: I4e946146af985c74c8bd97d8c118b932394bbc5e
Signed-off-by: Sebastien Douheret <sebastien.douheret@iot.bzh>
Signed-off-by: José Bollo <jose.bollo@iot.bzh>
-rw-r--r-- | conf/CMakeLists.txt | 8 | ||||
-rw-r--r-- | conf/afm-unit-debug.conf.in | 286 | ||||
-rw-r--r-- | conf/afm-unit.conf.in | 4 | ||||
-rw-r--r-- | scripts/CMakeLists.txt | 3 | ||||
-rw-r--r-- | scripts/afm-debug | 90 |
5 files changed, 388 insertions, 3 deletions
diff --git a/conf/CMakeLists.txt b/conf/CMakeLists.txt index cf3d3ec..5f15dd6 100644 --- a/conf/CMakeLists.txt +++ b/conf/CMakeLists.txt @@ -20,6 +20,7 @@ cmake_minimum_required(VERSION 2.8) configure_file(afm-launch.conf.in afm-launch.conf) configure_file(afm-unit.conf.in afm-unit.conf) +configure_file(afm-unit-debug.conf.in afm-unit-debug.conf) configure_file(afm-system-daemon.service.in afm-system-daemon.service) configure_file(afm-user-daemon.service.in afm-user-daemon.service) @@ -34,7 +35,12 @@ if(NOT USE_SDK) install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/afm-user-daemon.conf DESTINATION ${SYSCONFDIR_DBUS_USER}) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/afm-user-daemon.service DESTINATION ${UNITDIR_USER}) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/afm-launch.conf DESTINATION ${afm_confdir}) - install(FILES ${CMAKE_CURRENT_BINARY_DIR}/afm-unit.conf DESTINATION ${afm_confdir}) install(DIRECTORY DESTINATION ${afm_confdir}/unit.env.d) + + if(AGL_DEVEL) + install(FILES ${CMAKE_CURRENT_BINARY_DIR}/afm-unit-debug.conf DESTINATION ${afm_confdir} RENAME afm-unit.conf) + else() + install(FILES ${CMAKE_CURRENT_BINARY_DIR}/afm-unit.conf DESTINATION ${afm_confdir}) + endif() endif() diff --git a/conf/afm-unit-debug.conf.in b/conf/afm-unit-debug.conf.in new file mode 100644 index 0000000..3429f2d --- /dev/null +++ b/conf/afm-unit-debug.conf.in @@ -0,0 +1,286 @@ +;--------------------------------------------------------------------------------- +; File: +; +; afm-unit.conf +; +; Role: +; +; Configure how installation of widget produces unit files for systemd +; +; Processing and format: +; +; 1. File load +; +; Lines beginning with ; are firstly removed +; +; 2. File instantiation +; +; Mustache (extended) substitutions are applied using JSON +; data deduced from config.xml file of the widget. +; +; 3. Extraction of units +; +; Extract produced units, pack it (remove empty lines and directives) +; +; Directives: +; +; Any directive occupy one whole line starting with % +; +; - %nl +; +; produce an empty line at the end +; +; - %begin systemd-unit +; - %end systemd-unit +; +; delimit the produced unit +; +; - %systemd-unit user +; - %systemd-unit system +; +; tells the kind of unit (user/system) +; +; - %systemd-unit service NAME +; - %systemd-unit socket NAME +; +; gives the name and type of the unit +; +; - %systemd-unit wanted-by NAME +; +; tells to install a link to unit in the wants of NAME +; +; Setting variables: +; +; AFM uses the feature of systemd that completely ignores options prefixed +; with X- +; +; Consequently, options starting with X-AFM- are recorded as public data +; about the application and options starting starting with X-AFM-- are +; recorded as private data. +; +; Examples: +; +; X-AFM-description={{description}} +; +; Records the description of the unit in the field "description" +; of both the public and private object describing the unit. +; +; X-AFM--wgtdir={{:#metadata.install-dir}} +; +; Records the installation directory path in the field "wgtdir" +; of the private object only. +; +;--------------------------------------------------------------------------------- +{{#targets}} + +;--------------------------------------------------------------------------------- +;---- P R O V I D E D U N I T S ---- +;--------------------------------------------------------------------------------- +%begin systemd-unit + +# auto generated by wgtpkg-unit for {{id}} version {{version}} target {{:#target}} of {{idaver}} +%nl + +[Unit] +Description={{description}} +X-AFM-description={{description}} +X-AFM-name={{name.content}} +X-AFM-shortname={{name.short}} +X-AFM-id={{idaver}}{{^#target=main}}@{{:#target}}{{/#target=main}} +X-AFM-version={{version}} +X-AFM-author={{author.content}} +X-AFM-author-email={{author.email}} +X-AFM-width={{width}} +X-AFM-height={{height}} +X-AFM--ID={{id}} +X-AFM--target-name={{:#target}} +X-AFM--content={{content.src}} +X-AFM--type={{content.type}} +X-AFM--wgtdir={{:#metadata.install-dir}} +X-AFM--workdir={{&#metadata.app-data-dir}}/{{id}} +%nl + +Wants=sockets.target + +# Adds check to smack +ConditionSecurity=smack +%nl + +# Automatic bound to required api +{{#required-api}} +{{#value=auto|ws}} +BindsTo=afm-api-ws-{{name}} +After=afm-api-ws-{{name}} +{{/value=auto|ws}} +{{/required-api}} +%nl + +[Service] +EnvironmentFile=-@afm_confdir@/unit.env.d/* +SmackProcessLabel=User::App::{{id}} +SuccessExitStatus=0 SIGKILL + +{{#required-permission}} + {{#urn:AGL:permission::platform:no-oom}} OOMScoreAdjust=-500 {{/urn:AGL:permission::platform:no-oom}} + {{#urn:AGL:permission::partner:real-time}} IOSchedulingClass=realtime {{/urn:AGL:permission::partner:real-time}} +# {{^urn:AGL:permission::partner:real-time}} RestrictRealtime=on {{/urn:AGL:permission::partner:real-time}} + {{#urn:AGL:permission::public:display}} SupplementaryGroups=display {{/urn:AGL:permission::public:display}} + {{^urn:AGL:permission::public:syscall:clock}} SystemCallFilter=~@clock {{/urn:AGL:permission::public:syscall:clock}} +{{/required-permission}} +%nl + +WorkingDirectory=-{{&#metadata.app-data-dir}}/{{id}} +ExecStartPre=/bin/mkdir -p {{&#metadata.app-data-dir}}/{{id}} +Environment=AFM_APP_INSTALL_DIR={{:#metadata.install-dir}} + +; Needed to enable debug +Environment=AFM_ID={{idaver}}{{^#target=main}}@{{:#target}}{{/#target=main}} +EnvironmentFile=-/var/run/afm-debug/{{idaver}}{{^#target=main}}@{{:#target}}{{/#target=main}}.env + +%systemd-unit user +{{#required-permission.urn:AGL:permission::public:hidden}}\ +%systemd-unit service afm-service-{{idaver}}{{^#target=main}}@{{:#target}}{{/#target=main}} +{{/required-permission.urn:AGL:permission::public:hidden}}\ +{{^required-permission.urn:AGL:permission::public:hidden}}\ +%systemd-unit service afm-appli-{{idaver}}{{^#target=main}}@{{:#target}}{{/#target=main}} +{{/required-permission.urn:AGL:permission::public:hidden}}\ + + +;--------------------------------------------------------------------------------- +;---- text/html application/vnd.agl.native application/vnd.agl.service ---- +;--------------------------------------------------------------------------------- +{{#content.type=text/html|application/vnd.agl.native|application/vnd.agl.service}} + +{{^content.type=application/vnd.agl.service}} +X-AFM--http-port={{:#metadata.http-port}} +{{/content.type=application/vnd.agl.service}} + +ExecStart=/usr/bin/afb-daemon \ + {{^content.type=application/vnd.agl.service}}\ + --port={{:#metadata.http-port}} \ + --random-token \ + {{/content.type=application/vnd.agl.service}}\ + --rootdir={{:#metadata.install-dir}} \ + --workdir={{&#metadata.app-data-dir}}/{{id}} \ + {{#required-permission.urn:AGL:permission::public:no-htdocs}}\ + --roothttp=. \ + {{/required-permission.urn:AGL:permission::public:no-htdocs}}\ + {{^required-permission.urn:AGL:permission::public:no-htdocs}}\ + --roothttp=htdocs \ + {{/required-permission.urn:AGL:permission::public:no-htdocs}}\ + {{#required-permission.urn:AGL:permission::public:applications:read}}\ + --alias=/icons:{{:#metadata.icons-dir}} \ + {{/required-permission.urn:AGL:permission::public:applications:read}}\ + {{#required-api}}\ + {{#value=auto}}\ + --ws-client=unix:%t/apis/ws/{{name}} \ + {{/value=auto}}\ + {{#value=ws}}\ + --ws-client=unix:%t/apis/ws/{{name}} \ + {{/value=ws}}\ + {{#value=dbus}}\ + --dbus-client={{name}} \ + {{/value=dbus}}\ + {{#value=link}}\ + --binding=%t/apis/lib/{{name}} \ + {{/value=link}}\ + {{#value=cloud}}\ + --cloud-client={{name}} \ + {{/value=cloud}}\ + {{#value=local}}\ + --binding={{:#metadata.install-dir}}/{{name}} \ + {{/value=local}}\ + {{/required-api}}\ + {{#provided-api}}\ + {{#value=auto}}\ + {{^required-permission.urn:AGL:permission::partner:service:no-ws}}\ + --ws-server=sd:{{name}} \ + {{/required-permission.urn:AGL:permission::partner:service:no-ws}}\ + {{^required-permission.urn:AGL:permission::partner:service:no-dbus}}\ + --dbus-server={{name}} \ + {{/required-permission.urn:AGL:permission::partner:service:no-dbus}}\ + {{/value=auto}}\ + {{#value=ws}}\ + --ws-server=sd:{{name}} \ + {{/value=ws}}\ + {{#value=dbus}}\ + --dbus-server={{name}} \ + {{/value=dbus}}\ + {{/provided-api}}\ + {{#content.type=text/html}}\ + --exec /usr/bin/web-runtime http://localhost:@p/{{content.src}}?token=@t + {{/content.type=text/html}}\ + {{#content.type=application/vnd.agl.native}}\ + --exec {{:#metadata.install-dir}}/{{content.src}} @p @t + {{/content.type=application/vnd.agl.native}}\ + {{#content.type=application/vnd.agl.service}}\ + --no-httpd + {{/content.type=application/vnd.agl.service}} + +{{/content.type=text/html|application/vnd.agl.native|application/vnd.agl.service}} + + +;--------------------------------------------------------------------------------- +;---- application/x-executable ---- +;--------------------------------------------------------------------------------- +{{#content.type=application/x-executable}} + +Environment=LD_LIBRARY_PATH=$ORIGIN/$LIB + +ExecStart={{:#metadata.install-dir}}/{{content.src}} + +{{/content.type=application/x-executable}} + +;--------------------------------------------------------------------------------- +; auto start +;--------------------------------------------------------------------------------- +{{#required-permission.urn:AGL:permission::system:run-by-default}} +%nl +[Install] +WantedBy=default.target +%systemd-unit wanted-by default.target +{{/required-permission.urn:AGL:permission::system:run-by-default}} + +%end systemd-unit + + +;--------------------------------------------------------------------------------- +;---- P R O V I D E D A P I S ---- +;--------------------------------------------------------------------------------- + +{{#provided-api}} +{{#value=ws|auto}} + +%begin systemd-unit + +# auto generated by wgtpkg-unit for {{id}} version {{version}} target {{:#target}} of {{idaver}} +# +%systemd-unit user +%systemd-unit socket afm-api-ws-{{name}} + +[Socket] +SmackLabel=* +ListenStream=%t/apis/ws/{{name}} +FileDescriptorName={{name}} + +{{#required-permission.urn:AGL:permission::public:hidden}}\ +Service=afm-service-{{idaver}}{{^#target=main}}@{{:#target}}{{/#target=main}}.service +{{/required-permission.urn:AGL:permission::public:hidden}}\ +{{^required-permission.urn:AGL:permission::public:hidden}}\ +Service=afm-appli-{{idaver}}{{^#target=main}}@{{:#target}}{{/#target=main}}.service +{{/required-permission.urn:AGL:permission::public:hidden}}\ + +;--------------------------------------------------------------------------------- +%nl +[Install] +WantedBy=sockets.target +%systemd-unit wanted-by sockets.target +;--------------------------------------------------------------------------------- + +%end systemd-unit + +{{/value=ws|auto}} +{{/provided-api}} + +{{/targets}} + diff --git a/conf/afm-unit.conf.in b/conf/afm-unit.conf.in index 7f35a58..43cfce5 100644 --- a/conf/afm-unit.conf.in +++ b/conf/afm-unit.conf.in @@ -13,7 +13,7 @@ ; ; Lines beginning with ; are firstly removed ; -; 2. File instanciation +; 2. File instantiation ; ; Mustache (extended) substitutions are applied using JSON ; data deduced from config.xml file of the widget. @@ -62,7 +62,7 @@ ; ; X-AFM-description={{description}} ; -; Records the descritpion of the unit in the field "description" +; Records the description of the unit in the field "description" ; of both the public and private object describing the unit. ; ; X-AFM--wgtdir={{:#metadata.install-dir}} diff --git a/scripts/CMakeLists.txt b/scripts/CMakeLists.txt index aef41cb..bf0846c 100644 --- a/scripts/CMakeLists.txt +++ b/scripts/CMakeLists.txt @@ -20,5 +20,8 @@ cmake_minimum_required(VERSION 2.8) if(NOT USE_SDK) install(PROGRAMS afm-util DESTINATION ${CMAKE_INSTALL_BINDIR}) + if(AGL_DEVEL) + install(PROGRAMS afm-debug DESTINATION ${CMAKE_INSTALL_BINDIR}) + endif() endif() diff --git a/scripts/afm-debug b/scripts/afm-debug new file mode 100644 index 0000000..18ecae2 --- /dev/null +++ b/scripts/afm-debug @@ -0,0 +1,90 @@ +#!/bin/bash + +########################################################################### +# Copyright 2017 IoT.bzh +# +# Author: Stephane Desneux <sdx@iot.bzh> +# Sebastien Douheret <sebastien@iot.bzh> +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +########################################################################### + +# This script should be invoked by gdb client through a ssh connection. +# It relays gdbmi protocol from gdbserver to gdb client +# +# WARNING: nothing should be sent to stdout except gdbserver output + +# FIXME: add support of --debugger option to support tcf or gdb-remote + + +function error() { + echo "ERR: $@" >&2 + exit 1 +} +function info() { + echo "INF: $@" >&2 +} + +# setup debug dir (shared with service file) +DBGDIR=/var/run/afm-debug +mkdir -p $DBGDIR + +# check application name passed as first arg by gdb +APP=$1 +[[ -z "$APP" ]] && error "Invalid application name" + +# redirect to log file +exec 2>$DBGDIR/$APP.dbgclt.log + +# activate DEBUG in environment file sourced in systemd service +AFB_WAIT_POINT="start-start" +echo "AFB_DEBUG_WAIT=$AFB_WAIT_POINT" >$DBGDIR/$APP.env + +# remove debug env file on exit +trap "rm $DBGDIR/$APP.*" STOP INT QUIT EXIT + +# ask appfw to start application +pid=$(afm-util start $APP) +[[ -z "$pid" || ! -e "/proc/$pid" ]] && error "Failed to start application $APP" +info "$APP started with pid=$pid" + +# wait debugging process is stop/waiting at start-start point +AFB_FILE=/tmp/afb-debug-$pid +tmo=100 +info "Waiting for process stopped..." +while [[ ! -e "$AFB_FILE" ]]; do + sleep 0.1 + tmo=$(expr $tmo - 1) + [[ "$tmo" == "0" ]] && error "Timeout waiting for process $pid stopped" +done + +info "Waiting for process stopped..." +AFB_WAIT_FILE=/tmp/afb-debug-$pid +tmo=100 +res=1 +while [[ "$res" != "0" ]]; do + sleep 0.1 + tmo=$(expr $tmo - 1) + [[ "$tmo" == "0" ]] && error "Timeout waiting for process $pid stopped" + grep $AFB_WAIT_POINT $AFB_WAIT_FILE > /dev/null 2>&1 + res=$? +done + +# debugging +info "Attaching gdbserver to pid $pid ..." +gdbserver --attach - $pid + +# end of debug session +info "proxy connection terminated - killing $APP (pid $pid)" +afm-util kill $pid >&2 +info "$APP killed" |