hooks: Complain if hook parameters are overwritten. Fixed 2 space leaks.
Signed-off-by: Stefan Klinger <git@stefan-klinger.de> Signed-off-by: Allan McRae <allan@archlinux.org>
This commit is contained in:
parent
a5dd5d4141
commit
d884a791b9
6 changed files with 109 additions and 0 deletions
|
@ -267,6 +267,7 @@ static int _alpm_hook_parse_cb(const char *file, int line,
|
||||||
struct _alpm_hook_t *hook = ctx->hook;
|
struct _alpm_hook_t *hook = ctx->hook;
|
||||||
|
|
||||||
#define error(...) _alpm_log(handle, ALPM_LOG_ERROR, __VA_ARGS__); return 1;
|
#define error(...) _alpm_log(handle, ALPM_LOG_ERROR, __VA_ARGS__); return 1;
|
||||||
|
#define warning(...) _alpm_log(handle, ALPM_LOG_WARNING, __VA_ARGS__);
|
||||||
|
|
||||||
if(!section && !key) {
|
if(!section && !key) {
|
||||||
error(_("error while reading hook %s: %s\n"), file, strerror(errno));
|
error(_("error while reading hook %s: %s\n"), file, strerror(errno));
|
||||||
|
@ -296,6 +297,9 @@ static int _alpm_hook_parse_cb(const char *file, int line,
|
||||||
error(_("hook %s line %d: invalid value %s\n"), file, line, value);
|
error(_("hook %s line %d: invalid value %s\n"), file, line, value);
|
||||||
}
|
}
|
||||||
} else if(strcmp(key, "Type") == 0) {
|
} else if(strcmp(key, "Type") == 0) {
|
||||||
|
if(t->type != 0) {
|
||||||
|
warning(_("hook %s line %d: overwriting previous definition of %s\n"), file, line, "Type");
|
||||||
|
}
|
||||||
if(strcmp(value, "Package") == 0) {
|
if(strcmp(value, "Package") == 0) {
|
||||||
t->type = ALPM_HOOK_TYPE_PACKAGE;
|
t->type = ALPM_HOOK_TYPE_PACKAGE;
|
||||||
} else if(strcmp(value, "File") == 0) {
|
} else if(strcmp(value, "File") == 0) {
|
||||||
|
@ -312,6 +316,9 @@ static int _alpm_hook_parse_cb(const char *file, int line,
|
||||||
}
|
}
|
||||||
} else if(strcmp(section, "Action") == 0) {
|
} else if(strcmp(section, "Action") == 0) {
|
||||||
if(strcmp(key, "When") == 0) {
|
if(strcmp(key, "When") == 0) {
|
||||||
|
if(hook->when != 0) {
|
||||||
|
warning(_("hook %s line %d: overwriting previous definition of %s\n"), file, line, "When");
|
||||||
|
}
|
||||||
if(strcmp(value, "PreTransaction") == 0) {
|
if(strcmp(value, "PreTransaction") == 0) {
|
||||||
hook->when = ALPM_HOOK_PRE_TRANSACTION;
|
hook->when = ALPM_HOOK_PRE_TRANSACTION;
|
||||||
} else if(strcmp(value, "PostTransaction") == 0) {
|
} else if(strcmp(value, "PostTransaction") == 0) {
|
||||||
|
@ -320,6 +327,10 @@ static int _alpm_hook_parse_cb(const char *file, int line,
|
||||||
error(_("hook %s line %d: invalid value %s\n"), file, line, value);
|
error(_("hook %s line %d: invalid value %s\n"), file, line, value);
|
||||||
}
|
}
|
||||||
} else if(strcmp(key, "Description") == 0) {
|
} else if(strcmp(key, "Description") == 0) {
|
||||||
|
if(hook->desc != NULL) {
|
||||||
|
warning(_("hook %s line %d: overwriting previous definition of %s\n"), file, line, "Description");
|
||||||
|
FREE(hook->desc);
|
||||||
|
}
|
||||||
STRDUP(hook->desc, value, return 1);
|
STRDUP(hook->desc, value, return 1);
|
||||||
} else if(strcmp(key, "Depends") == 0) {
|
} else if(strcmp(key, "Depends") == 0) {
|
||||||
char *val;
|
char *val;
|
||||||
|
@ -330,6 +341,10 @@ static int _alpm_hook_parse_cb(const char *file, int line,
|
||||||
} else if(strcmp(key, "NeedsTargets") == 0) {
|
} else if(strcmp(key, "NeedsTargets") == 0) {
|
||||||
hook->needs_targets = 1;
|
hook->needs_targets = 1;
|
||||||
} else if(strcmp(key, "Exec") == 0) {
|
} else if(strcmp(key, "Exec") == 0) {
|
||||||
|
if(hook->cmd != NULL) {
|
||||||
|
warning(_("hook %s line %d: overwriting previous definition of %s\n"), file, line, "Exec");
|
||||||
|
_alpm_wordsplit_free(hook->cmd);
|
||||||
|
}
|
||||||
if((hook->cmd = _alpm_wordsplit(value)) == NULL) {
|
if((hook->cmd = _alpm_wordsplit(value)) == NULL) {
|
||||||
if(errno == EINVAL) {
|
if(errno == EINVAL) {
|
||||||
error(_("hook %s line %d: invalid value %s\n"), file, line, value);
|
error(_("hook %s line %d: invalid value %s\n"), file, line, value);
|
||||||
|
@ -344,6 +359,7 @@ static int _alpm_hook_parse_cb(const char *file, int line,
|
||||||
}
|
}
|
||||||
|
|
||||||
#undef error
|
#undef error
|
||||||
|
#undef warning
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,6 +55,8 @@ TESTS += test/pacman/tests/fileconflict030.py
|
||||||
TESTS += test/pacman/tests/fileconflict031.py
|
TESTS += test/pacman/tests/fileconflict031.py
|
||||||
TESTS += test/pacman/tests/fileconflict032.py
|
TESTS += test/pacman/tests/fileconflict032.py
|
||||||
TESTS += test/pacman/tests/hook-abortonfail.py
|
TESTS += test/pacman/tests/hook-abortonfail.py
|
||||||
|
TESTS += test/pacman/tests/hook-description-reused.py
|
||||||
|
TESTS += test/pacman/tests/hook-exec-reused.py
|
||||||
TESTS += test/pacman/tests/hook-exec-with-arguments.py
|
TESTS += test/pacman/tests/hook-exec-with-arguments.py
|
||||||
TESTS += test/pacman/tests/hook-file-change-packages.py
|
TESTS += test/pacman/tests/hook-file-change-packages.py
|
||||||
TESTS += test/pacman/tests/hook-file-remove-trigger-match.py
|
TESTS += test/pacman/tests/hook-file-remove-trigger-match.py
|
||||||
|
@ -65,7 +67,9 @@ TESTS += test/pacman/tests/hook-pkg-postinstall-trigger-match.py
|
||||||
TESTS += test/pacman/tests/hook-pkg-remove-trigger-match.py
|
TESTS += test/pacman/tests/hook-pkg-remove-trigger-match.py
|
||||||
TESTS += test/pacman/tests/hook-pkg-upgrade-trigger-match.py
|
TESTS += test/pacman/tests/hook-pkg-upgrade-trigger-match.py
|
||||||
TESTS += test/pacman/tests/hook-target-list.py
|
TESTS += test/pacman/tests/hook-target-list.py
|
||||||
|
TESTS += test/pacman/tests/hook-type-reused.py
|
||||||
TESTS += test/pacman/tests/hook-upgrade-trigger-no-match.py
|
TESTS += test/pacman/tests/hook-upgrade-trigger-no-match.py
|
||||||
|
TESTS += test/pacman/tests/hook-when-reused.py
|
||||||
TESTS += test/pacman/tests/ignore001.py
|
TESTS += test/pacman/tests/ignore001.py
|
||||||
TESTS += test/pacman/tests/ignore002.py
|
TESTS += test/pacman/tests/ignore002.py
|
||||||
TESTS += test/pacman/tests/ignore003.py
|
TESTS += test/pacman/tests/ignore003.py
|
||||||
|
|
23
test/pacman/tests/hook-description-reused.py
Normal file
23
test/pacman/tests/hook-description-reused.py
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
self.description = "Hook using multiple 'Description's"
|
||||||
|
|
||||||
|
self.add_hook("hook",
|
||||||
|
"""
|
||||||
|
[Trigger]
|
||||||
|
Type = Package
|
||||||
|
Operation = Install
|
||||||
|
Target = foo
|
||||||
|
|
||||||
|
[Action]
|
||||||
|
Description = lala
|
||||||
|
Description = foobar
|
||||||
|
When = PreTransaction
|
||||||
|
Exec = /bin/date
|
||||||
|
""");
|
||||||
|
|
||||||
|
sp = pmpkg("foo")
|
||||||
|
self.addpkg2db("sync", sp)
|
||||||
|
|
||||||
|
self.args = "-S foo"
|
||||||
|
|
||||||
|
self.addrule("PACMAN_RETCODE=0")
|
||||||
|
self.addrule("PACMAN_OUTPUT=warning.*overwriting previous definition of Description")
|
22
test/pacman/tests/hook-exec-reused.py
Normal file
22
test/pacman/tests/hook-exec-reused.py
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
self.description = "Hook using multiple 'Exec's"
|
||||||
|
|
||||||
|
self.add_hook("hook",
|
||||||
|
"""
|
||||||
|
[Trigger]
|
||||||
|
Type = Package
|
||||||
|
Operation = Install
|
||||||
|
Target = foo
|
||||||
|
|
||||||
|
[Action]
|
||||||
|
When = PostTransaction
|
||||||
|
Exec = /bin/date
|
||||||
|
Exec = /bin/date
|
||||||
|
""");
|
||||||
|
|
||||||
|
sp = pmpkg("foo")
|
||||||
|
self.addpkg2db("sync", sp)
|
||||||
|
|
||||||
|
self.args = "-S foo"
|
||||||
|
|
||||||
|
self.addrule("PACMAN_RETCODE=0")
|
||||||
|
self.addrule("PACMAN_OUTPUT=warning.*overwriting previous definition of Exec")
|
22
test/pacman/tests/hook-type-reused.py
Normal file
22
test/pacman/tests/hook-type-reused.py
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
self.description = "Hook using multiple 'Type's"
|
||||||
|
|
||||||
|
self.add_hook("hook",
|
||||||
|
"""
|
||||||
|
[Trigger]
|
||||||
|
Type = Package
|
||||||
|
Type = File
|
||||||
|
Operation = Install
|
||||||
|
Target = foo
|
||||||
|
|
||||||
|
[Action]
|
||||||
|
When = PostTransaction
|
||||||
|
Exec = /bin/date
|
||||||
|
""");
|
||||||
|
|
||||||
|
sp = pmpkg("foo")
|
||||||
|
self.addpkg2db("sync", sp)
|
||||||
|
|
||||||
|
self.args = "-S foo"
|
||||||
|
|
||||||
|
self.addrule("PACMAN_RETCODE=0")
|
||||||
|
self.addrule("PACMAN_OUTPUT=warning.*overwriting previous definition of Type")
|
22
test/pacman/tests/hook-when-reused.py
Normal file
22
test/pacman/tests/hook-when-reused.py
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
self.description = "Hook using multiple 'When's"
|
||||||
|
|
||||||
|
self.add_hook("hook",
|
||||||
|
"""
|
||||||
|
[Trigger]
|
||||||
|
Type = Package
|
||||||
|
Operation = Install
|
||||||
|
Target = foo
|
||||||
|
|
||||||
|
[Action]
|
||||||
|
When = PreTransaction
|
||||||
|
Exec = /bin/date
|
||||||
|
When = PostTransaction
|
||||||
|
""");
|
||||||
|
|
||||||
|
sp = pmpkg("foo")
|
||||||
|
self.addpkg2db("sync", sp)
|
||||||
|
|
||||||
|
self.args = "-S foo"
|
||||||
|
|
||||||
|
self.addrule("PACMAN_RETCODE=0")
|
||||||
|
self.addrule("PACMAN_OUTPUT=warning.*overwriting previous definition of When")
|
Loading…
Add table
Reference in a new issue