optflags: set _FORTIFY_SOURCE for preproc
[platform/upstream/rpm.git] / plugins / exec.c
1 #include "plugin.h"
2
3 #include <sys/wait.h>
4
5 static char * options;
6 static char * name;
7
8 rpmPluginHook PLUGIN_HOOKS = \
9         PLUGINHOOK_INIT | \
10         PLUGINHOOK_CLEANUP | \
11         PLUGINHOOK_COLL_POST_ANY;
12
13 rpmRC PLUGINHOOK_INIT_FUNC(rpmts ts, const char *name, const char *opts)
14 {
15     options = strdup(opts);
16     name = strdup(name);
17     return RPMRC_OK;
18 }
19
20 rpmRC PLUGINHOOK_CLEANUP_FUNC(void)
21 {
22     options = _free(options);
23     name = _free(name);
24     return RPMRC_OK;
25 }
26
27 rpmRC PLUGINHOOK_COLL_POST_ANY_FUNC(void)
28 {
29     rpmRC rc = RPMRC_FAIL;
30
31     if (rpmChrootIn()) {
32         goto exit;
33     }
34
35     if (options) {
36         int status = system(options);
37         if (!WIFEXITED(status) || WEXITSTATUS(status)) {
38             rpmlog(RPMLOG_ERR, "%s collection action failed\n", name);
39             goto exit;
40         }
41     }
42
43     rc = RPMRC_OK;
44
45   exit:
46     if (rpmChrootOut()) {
47         rc = RPMRC_FAIL;
48     }
49
50     return rc;
51 }