[prev in list] [next in list] [prev in thread] [next in thread]
List: asterisk-dev
Subject: Re: [asterisk-dev] Segmentation fault (core dumped) on custom application execution
From: Borja SIXTO <borja.sixto () ulex ! fr>
Date: 2017-08-18 8:45:05
Message-ID: 3b3239ea-94e2-e5dd-5ab7-67fbe18db2b6 () ulex ! fr
[Download RAW message or body]
[Attachment #2 (multipart/alternative)]
Hi,
It seems that you are not a C language developer...
static int sendfile_exec(struct ast_channel *chan, const char *data)
{
size_t fnameLength= strlen(pbx_builtin_getvar_helper(chan,
"MIXMONITOR_FILENAME"));
char fileName[fnameLength];
strcpy(fileName, pbx_builtin_getvar_helper(chan,
"MIXMONITOR_FILENAME"));
char fullCommand[1]= "\0";
strcat(fullCommand, ID3V2_COMMAND);
strcat(fullCommand, fileName);
system(fullCommand);
return 1;
}
replace by
static int sendfile_exec(struct ast_channel *chan, const char *data)
{
char fileName[1024];
strcpy(fileName, pbx_builtin_getvar_helper(chan,
"MIXMONITOR_FILENAME"));
char fullCommand[1024+100] = "\0";
strcat(fullCommand, ID3V2_COMMAND);
strcat(fullCommand, fileName);
system(fullCommand);
return 1;
}
To catch the coredump file and identify the C code line, use the option
"-g" of the asterisk (you can set ulimit -c 0, if necessary)
To make this kind of process with the Asterisk it is better to use the
Dialplan (command System()), use an AGI, or use Voximal (VoiceXML
interpreter for Asterisk).
Regards,
Borja SIXTO from ulex.fr
Le 18/08/2017 à 09:38, Yukio Tanaka a écrit :
>
> Hello,
>
> I am in the process of writing an application for my server.
> Compilation and installation run without a hitch. However at runtime
> the application provokes a “Segmentation fault (core dumped)” which
> shuts down my server. I am clueless as to what sends the error and
> even more so on how to fix it so any help would be appreciated. Below
> is a copy of my code.
>
> Thanks in advance for any help.
>
> Yukio
>
> /***
>
> * Send File (app_sendfile.c) by Yukio Tanaka (yukio@starcb.com)
>
> *
>
> * Use at the end of the dialplan in a monitored call. This will:
>
> * a) Add call metadatas to the monitor file.
>
> * b) Send the file to the specified server using ssh.
>
> *
>
> ******
>
> * Version 0.1 – 2017.07
>
> *
>
> * - Testing metadata hard writing for the moment
>
> * /!\ At runtime encountering error: Segmentation fault (core dumped)
>
> ***/
>
> #include "asterisk.h"
>
> /*ASTERISK_FILE_VERSION(__FILE__, "$Revision$")*/
>
> #include "asterisk/cdr.h"
>
> #include "asterisk/logger.h"
>
> #include "asterisk/module.h"
>
> #include "asterisk/channel.h"
>
> #include "asterisk/file.h"
>
> #include "asterisk/pbx.h"
>
> /* Use id3v2 application to add an author metadata */
>
> const char ID3V2_COMMAND[]= "id3v2 -a \"Algernopp Krieger\" ";
>
> static int sendfile_exec(struct ast_channel *chan, const char *data)
>
> {
>
> size_t fnameLength= strlen(pbx_builtin_getvar_helper(chan,
> "MIXMONITOR_FILENAME"));
>
> char fileName[fnameLength];
>
> strcpy(fileName, pbx_builtin_getvar_helper(chan,
> "MIXMONITOR_FILENAME"));
>
> char fullCommand[1]= "\0";
>
> strcat(fullCommand, ID3V2_COMMAND);
>
> strcat(fullCommand, fileName);
>
> system(fullCommand);
>
> return 1;
>
> }
>
> static int load_module(void)
>
> {
>
> ast_register_application("SendFile", sendfile_exec, "Send a recorded
> call to a server.", "Some description.");
>
> return AST_MODULE_LOAD_SUCCESS;
>
> }
>
> static int unload_module(void)
>
> {
>
> ast_cdr_unregister("SendFile");
>
> return 0;
>
> }
>
> AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "SendFile")
>
>
>
--
Borja SIXTO (co-founder/manager)
Mail: borja.sixto@ulex.fr
Tel: +33(0)4 28 35 03 44 Ext. 11
Ulex Innovative Systems | 4 rue des Prairies, 38460 St Romain de Jalionas, France
www.ulex.fr
[Attachment #5 (text/html)]
<html>
<head>
<meta content="text/html; charset=windows-1252"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<p>Hi,</p>
<p>It seems that you are not a C language developer...</p>
<p class="MsoNormal"><span style="font-family:"Courier
New"" lang="EN-US">static int sendfile_exec(struct
ast_channel *chan, const char *data)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier
New"" lang="EN-US">{<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier
New"" lang="EN-US"> size_t fnameLength=
strlen(pbx_builtin_getvar_helper(chan, \
"MIXMONITOR_FILENAME"));<o:p></o:p></span></p> <p class="MsoNormal"><span \
style="font-family:"Courier
New"" lang="EN-US"> char fileName[fnameLength];<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier
New"" lang="EN-US"> strcpy(fileName,
pbx_builtin_getvar_helper(chan, \
"MIXMONITOR_FILENAME"));<o:p></o:p></span></p> <p class="MsoNormal"><span \
style="font-family:"Courier
New"" lang="EN-US"> char fullCommand[1]= "\0";<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier
New"" lang="EN-US"> strcat(fullCommand, \
ID3V2_COMMAND);<o:p></o:p></span></p> <p class="MsoNormal"><span \
style="font-family:"Courier
New"" lang="EN-US"> strcat(fullCommand, \
fileName);<o:p></o:p></span></p> <p class="MsoNormal"><span \
style="font-family:"Courier
New"" lang="EN-US"> system(fullCommand);<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier
New"" lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier
New"" lang="EN-US"> return 1;<o:p></o:p></span></p>
<span style="font-family:"Courier New"" lang="EN-US">}</span>
<p>replace by</p>
<span style="font-family:"Courier New"" lang="EN-US">static
int sendfile_exec(struct ast_channel *chan, const char *data)<o:p></o:p></span>
<p class="MsoNormal"><span style="font-family:"Courier
New"" lang="EN-US">{</span></p>
<p class="MsoNormal"><span style="font-family:"Courier
New"" lang="EN-US"> char fileName[1024];<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier
New"" lang="EN-US"> strcpy(fileName,
pbx_builtin_getvar_helper(chan, \
"MIXMONITOR_FILENAME"));<o:p></o:p></span></p> <p class="MsoNormal"><span \
style="font-family:"Courier
New"" lang="EN-US"> char fullCommand[1024+100] = \
"\0";<o:p></o:p></span></p> <p class="MsoNormal"><span \
style="font-family:"Courier
New"" lang="EN-US"> strcat(fullCommand, \
ID3V2_COMMAND);<o:p></o:p></span></p> <p class="MsoNormal"><span \
style="font-family:"Courier
New"" lang="EN-US"> strcat(fullCommand, \
fileName);<o:p></o:p></span></p> <p class="MsoNormal"><span \
style="font-family:"Courier
New"" lang="EN-US"> system(fullCommand);<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier
New"" lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier
New"" lang="EN-US"> return 1;<o:p></o:p></span></p>
<span style="font-family:"Courier New"" lang="EN-US">}<br>
<br>
</span>
<div class="moz-cite-prefix">To catch the coredump file and identify
the C code line, use the option "-g" of the asterisk (you can set
ulimit -c 0, if necessary)<br>
<br>
To make this kind of process with the Asterisk it is better to use
the Dialplan (command System()), use an AGI, or use Voximal
(VoiceXML interpreter for Asterisk).<br>
<br>
Regards,<br>
<br>
<br>
Borja SIXTO from ulex.fr<br>
<br>
<br>
Le 18/08/2017 à 09:38, Yukio Tanaka a écrit :<br>
</div>
<blockquote
cite="mid:0B12E6F2ED56AA428CEFC582E66D80FDD11BE6@mbx025-e1-nj-2.exch025.domain.local"
type="cite">
<meta http-equiv="Content-Type" content="text/html;
charset=windows-1252">
<meta name="Generator" content="Microsoft Word 14 (filtered
medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:Wingdings;
panose-1:5 0 0 0 0 0 0 0 0 0;}
@font-face
{font-family:Wingdings;
panose-1:5 0 0 0 0 0 0 0 0 0;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri","sans-serif";
mso-fareast-language:EN-US;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:purple;
text-decoration:underline;}
p.MsoListParagraph, li.MsoListParagraph, div.MsoListParagraph
{mso-style-priority:34;
margin-top:0cm;
margin-right:0cm;
margin-bottom:0cm;
margin-left:36.0pt;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri","sans-serif";
mso-fareast-language:EN-US;}
span.EmailStyle17
{mso-style-type:personal-compose;
font-family:"Calibri","sans-serif";
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;
font-family:"Calibri","sans-serif";
mso-fareast-language:EN-US;}
@page WordSection1
{size:612.0pt 792.0pt;
margin:70.85pt 70.85pt 70.85pt 70.85pt;}
div.WordSection1
{page:WordSection1;}
/* List Definitions */
@list l0
{mso-list-id:417945112;
mso-list-type:hybrid;
mso-list-template-ids:570557304 -808388558 269221891 269221893 269221889 269221891 \
269221893 269221889 269221891 269221893;} @list l0:level1
{mso-level-start-at:0;
mso-level-number-format:bullet;
mso-level-text:\F0B7;
mso-level-tab-stop:none;
mso-level-number-position:left;
margin-left:24.75pt;
text-indent:-18.0pt;
font-family:Symbol;
mso-fareast-font-family:Calibri;
mso-bidi-font-family:"Courier New";}
@list l0:level2
{mso-level-number-format:bullet;
mso-level-text:o;
mso-level-tab-stop:none;
mso-level-number-position:left;
margin-left:60.75pt;
text-indent:-18.0pt;
font-family:"Courier New";}
@list l0:level3
{mso-level-number-format:bullet;
mso-level-text:\F0A7;
mso-level-tab-stop:none;
mso-level-number-position:left;
margin-left:96.75pt;
text-indent:-18.0pt;
font-family:Wingdings;}
@list l0:level4
{mso-level-number-format:bullet;
mso-level-text:\F0B7;
mso-level-tab-stop:none;
mso-level-number-position:left;
margin-left:132.75pt;
text-indent:-18.0pt;
font-family:Symbol;}
@list l0:level5
{mso-level-number-format:bullet;
mso-level-text:o;
mso-level-tab-stop:none;
mso-level-number-position:left;
margin-left:168.75pt;
text-indent:-18.0pt;
font-family:"Courier New";}
@list l0:level6
{mso-level-number-format:bullet;
mso-level-text:\F0A7;
mso-level-tab-stop:none;
mso-level-number-position:left;
margin-left:204.75pt;
text-indent:-18.0pt;
font-family:Wingdings;}
@list l0:level7
{mso-level-number-format:bullet;
mso-level-text:\F0B7;
mso-level-tab-stop:none;
mso-level-number-position:left;
margin-left:240.75pt;
text-indent:-18.0pt;
font-family:Symbol;}
@list l0:level8
{mso-level-number-format:bullet;
mso-level-text:o;
mso-level-tab-stop:none;
mso-level-number-position:left;
margin-left:276.75pt;
text-indent:-18.0pt;
font-family:"Courier New";}
@list l0:level9
{mso-level-number-format:bullet;
mso-level-text:\F0A7;
mso-level-tab-stop:none;
mso-level-number-position:left;
margin-left:312.75pt;
text-indent:-18.0pt;
font-family:Wingdings;}
ol
{margin-bottom:0cm;}
ul
{margin-bottom:0cm;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
<div class="WordSection1">
<p class="MsoNormal">Hello,<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><span lang="EN-US">I am in the process of
writing an application for my server. Compilation and
installation run without a hitch. However at runtime the
application provokes a “Segmentation fault (core dumped)”
which shuts down my server. I am clueless as to what sends
the error and even more so on how to fix it so any help
would be appreciated. Below is a copy of my code.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">Thanks in advance for
any help.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">Yukio<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier
New"" lang="EN-US">/***<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier
New"" lang="EN-US">* Send File (app_sendfile.c) by
Yukio Tanaka (<a class="moz-txt-link-abbreviated" \
href="mailto:yukio@starcb.com">yukio@starcb.com</a>)<o:p></o:p></span></p> <p \
class="MsoNormal"><span style="font-family:"Courier New"" lang="EN-US">* \
<o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier
New"" lang="EN-US"> * Use at the end of the dialplan in
a monitored call. This will:<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier
New"" lang="EN-US">* a) Add call metadatas to the
monitor file.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier
New"" lang="EN-US">* b) Send the file to the
specified server using ssh.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier
New"" lang="EN-US">* <o:p>
</o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier
New"" lang="EN-US"> ******<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier
New"" lang="EN-US">* Version 0.1 – 2017.07<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier
New"" lang="EN-US">* <o:p>
</o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier
New"" lang="EN-US"> * - Testing metadata hard writing
for the moment<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier
New"" lang="EN-US">* /!\ At runtime encountering error:
Segmentation fault (core dumped)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier
New"" lang="EN-US">***/<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier
New"" lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier
New"" lang="EN-US">#include "asterisk.h"<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier
New"" lang="EN-US">/*ASTERISK_FILE_VERSION(__FILE__,
"$Revision$")*/<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier
New"" lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier
New"" lang="EN-US">#include "asterisk/cdr.h"<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier
New"" lang="EN-US">#include \
"asterisk/logger.h"<o:p></o:p></span></p> <p class="MsoNormal"><span \
style="font-family:"Courier
New"" lang="EN-US">#include \
"asterisk/module.h"<o:p></o:p></span></p> <p class="MsoNormal"><span \
style="font-family:"Courier
New"" lang="EN-US">#include \
"asterisk/channel.h"<o:p></o:p></span></p> <p class="MsoNormal"><span \
style="font-family:"Courier
New"" lang="EN-US">#include "asterisk/file.h"<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier
New"" lang="EN-US">#include "asterisk/pbx.h"<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier
New"" lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier
New"" lang="EN-US">/* Use id3v2 application to add an
author metadata */<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier
New"" lang="EN-US">const char ID3V2_COMMAND[]= "id3v2
-a \"Algernopp Krieger\" ";<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier
New"" lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier
New"" lang="EN-US">static int sendfile_exec(struct
ast_channel *chan, const char *data)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier
New"" lang="EN-US">{<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier
New"" lang="EN-US"> size_t fnameLength=
strlen(pbx_builtin_getvar_helper(chan,
"MIXMONITOR_FILENAME"));<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier
New"" lang="EN-US"> char \
fileName[fnameLength];<o:p></o:p></span></p> <p class="MsoNormal"><span \
style="font-family:"Courier New"" lang="EN-US"> strcpy(fileName,
pbx_builtin_getvar_helper(chan, \
"MIXMONITOR_FILENAME"));<o:p></o:p></span></p> <p class="MsoNormal"><span \
style="font-family:"Courier
New"" lang="EN-US"> char fullCommand[1]= \
"\0";<o:p></o:p></span></p> <p class="MsoNormal"><span \
style="font-family:"Courier New"" lang="EN-US"> strcat(fullCommand,
ID3V2_COMMAND);<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier
New"" lang="EN-US"> strcat(fullCommand, \
fileName);<o:p></o:p></span></p> <p class="MsoNormal"><span \
style="font-family:"Courier
New"" lang="EN-US"> system(fullCommand);<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier
New"" lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier
New"" lang="EN-US"> return 1;<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier
New"" lang="EN-US">}<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier
New"" lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier
New"" lang="EN-US">static int \
load_module(void)<o:p></o:p></span></p> <p class="MsoNormal"><span \
style="font-family:"Courier New"" lang="EN-US">{<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier
New"" lang="EN-US">
ast_register_application("SendFile", sendfile_exec, "Send a
recorded call to a server.", "Some description.");<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier
New"" lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier
New"" lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier
New"" lang="EN-US"> return \
AST_MODULE_LOAD_SUCCESS;<o:p></o:p></span></p> <p class="MsoNormal"><span \
style="font-family:"Courier New"" lang="EN-US">}<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier
New"" lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier
New"" lang="EN-US">static int \
unload_module(void)<o:p></o:p></span></p> <p class="MsoNormal"><span \
style="font-family:"Courier New"" lang="EN-US">{<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier
New"" lang="EN-US"> \
ast_cdr_unregister("SendFile");<o:p></o:p></span></p> <p class="MsoNormal"><span \
style="font-family:"Courier New"" lang="EN-US"> return \
0;<o:p></o:p></span></p> <p class="MsoNormal"><span style="font-family:"Courier
New"" lang="EN-US">}<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier
New"" lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier
New"" lang="EN-US">AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY,
"SendFile")<o:p></o:p></span></p>
</div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
</blockquote>
<br>
<pre class="moz-signature" cols="72">--
Borja SIXTO (co-founder/manager)
Mail: <a class="moz-txt-link-abbreviated" \
href="mailto:borja.sixto@ulex.fr">borja.sixto@ulex.fr</a>
Tel: +33(0)4 28 35 03 44 Ext. 11
Ulex Innovative Systems | 4 rue des Prairies, 38460 St Romain de Jalionas, France
<a class="moz-txt-link-abbreviated" href="http://www.ulex.fr">www.ulex.fr</a></pre>
</body>
</html>
--
_____________________________________________________________________
-- Bandwidth and Colocation Provided by http://www.api-digital.com --
asterisk-dev mailing list
To UNSUBSCRIBE or update options visit:
http://lists.digium.com/mailman/listinfo/asterisk-dev
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic