Summary:ASTERISK-12614: [patch] Problem using UpdateConfig AMI command when dstfilename points to non-existing file
Reporter:vadim (vadim)Labels:
Date Opened:2008-08-19 08:43:37Date Closed:2008-08-25 10:43:56
Versions:Frequency of
Environment:Attachments:( 0) 13341.patch
( 1) config_save.patch
Description:I'm running following putconfig command:
Action: updateconfig
reload: no
SrcFilename: extensions.conf
DstFilename: extensions.conf.new
Action-000000: newcat
Cat-000000: ami-test-01
Action-000001: append
Var-000001: exten
Value-000001: 888,1,Noop(888)
Cat-000001: ami-test-01
Action-000002: append
Var-000002: exten
Value-000002: 999,1,Noop(999)
Cat-000002: ami-test-0
And getting following as result:
Response: Error
Message: Save of config failed


The reason is a small bug in the function config_text_file_save
which tries to unlink nonexisting file and complains
Comments:By: Leif Madsen (lmadsen) 2008-08-19 09:12:22

Oops... I guess this doesn't really need to be marked as Needs License since its in a pending status. Bit quick on the trigger there :)

By: Mark Michelson (mmichelson) 2008-08-22 16:05:39

Ah, nice patch. I think it's important to catch any potential errors on the unlink call, but only if the file actually exists to be unlinked. In the spirit of your patch, I've changed the logic a bit so that the return value of stat() is checked to see if we should actually attempt to unlink.

Could you test to make sure this works, too?

By: vadim (vadim) 2008-08-25 03:32:26

Seems  to work here

By: Sean Bright (seanbright) 2008-08-25 08:32:52

putnopvut, might want to skip the fchmod() as well if stat returns non-zero.

By: Mark Michelson (mmichelson) 2008-08-25 10:33:49

Yes, that makes sense, too. I'll make that change when I commit.

By: Digium Subversion (svnbot) 2008-08-25 10:43:52

Repository: asterisk
Revision: 139769

U   branches/1.4/main/config.c

r139769 | mmichelson | 2008-08-25 10:43:52 -0500 (Mon, 25 Aug 2008) | 12 lines

Fix the logic in config_text_file_save so that if an
UpdateConfig manager action is issued and the
file specified in DstFileName does not yet exist,
an error is not returned.

(closes issue ASTERISK-12614)
Reported by: vadim
     13341.patch uploaded by putnopvut (license 60)
 (with small modification from seanbright)