diff options
author | slioch <slioch@eng-140.vyatta.com> | 2008-12-15 17:03:00 -0800 |
---|---|---|
committer | slioch <slioch@eng-140.vyatta.com> | 2008-12-15 17:03:00 -0800 |
commit | 5da26e172a8c1ed5201527aefddabd6e277e5c03 (patch) | |
tree | 17b9536117774b0dfd76969b1b3b0aed82c24117 /src/exe_action.c | |
parent | 9ed9edcfe9aef3db9306a0d2b7c24f73831b1149 (diff) | |
download | vyatta-cfg-5da26e172a8c1ed5201527aefddabd6e277e5c03.tar.gz vyatta-cfg-5da26e172a8c1ed5201527aefddabd6e277e5c03.zip |
initial checkin of new commit code--building but does not replace original commit. New commit may be accessed through
my_commit2 binary.
Diffstat (limited to 'src/exe_action.c')
-rw-r--r-- | src/exe_action.c | 122 |
1 files changed, 122 insertions, 0 deletions
diff --git a/src/exe_action.c b/src/exe_action.c new file mode 100644 index 0000000..200ec2d --- /dev/null +++ b/src/exe_action.c @@ -0,0 +1,122 @@ +#include <sys/types.h> +#include <sys/stat.h> +#include <string.h> +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <glib-2.0/glib.h> +#include "common/common.h" + +boolean g_debug = FALSE; + +/** + * + * + **/ +void +usage() +{ + printf("exe_action\n"); + printf("-p\t\trelative path to node.def\n"); + printf("-a\t\taction (integer value)\n"); + printf("-d\t\tdebug mode\n"); + printf("-h\t\thelp\n"); +} + + +/** + * + **/ +const char* get_tmpp(void) { + + const char* tmpp=getenv(ENV_T_DIR); + + if(!tmpp) + tmpp=""; + + return tmpp; +} + + +/** + * + * + **/ +int +main(int argc, char** argv) +{ + int ch; + char *path = NULL; + unsigned long act = 0; + + //grab inputs + while ((ch = getopt(argc, argv, "dhp:a:")) != -1) { + switch (ch) { + case 'd': + g_debug = TRUE; + break; + case 'h': + usage(); + exit(0); + break; + case 'p': + path = optarg; + break; + case 'a': + act = strtoul(optarg,NULL,10); + break; + default: + usage(); + exit(0); + } + } + + + vtw_def def; + struct stat s; + const char *root = get_tmpp(); + char buf[2048]; + sprintf(buf,"%s/%snode.def",root,path); + printf("%s\n",buf); + initialize_output(); + init_paths(TRUE); + + printf("[path: %s][act: %lu]\n",buf,act); + + if ((lstat(buf,&s) == 0) && S_ISREG(s.st_mode)) { + memset(&def, 0, sizeof(def)); + if (parse_def(&def,buf,FALSE) == 0) { + //execute + int status; + if (def.actions[act].vtw_list_head) { + set_in_commit(TRUE); + + char foo[1024]; + sprintf(foo,"b"); + set_at_string(foo); + + //BROKEN--NEEDS TO BE FIX BELOW FOR DPATH AND CPATH + common_set_context(path,path); + + status = execute_list(def.actions[act].vtw_list_head,&def); + if (status == FALSE) { + printf("command failed! status: %d\n", status); + } + else { + printf("SUCCESS!\n"); + } + set_in_commit(FALSE); + } + else { + printf("no action for this node\n"); + } + } + else { + printf("failure to parse defination file\n"); + } + } + else { + printf("node.def not found at: %s\n",buf); + } + return 0; +} |