summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMichael Larson <slioch@slioch.vyatta.com>2010-06-05 09:48:06 -0700
committerMichael Larson <slioch@slioch.vyatta.com>2010-06-05 09:48:06 -0700
commit6fcaf773333e0285464e774751c95b79ec9c4ff5 (patch)
treeacbb76d9adf1e02c669a868f48969dffa648221c /src
parenta15eb820c2a21546c39be544b69bd91b3f8a6b6c (diff)
downloadvyatta-cfg-6fcaf773333e0285464e774751c95b79ec9c4ff5.tar.gz
vyatta-cfg-6fcaf773333e0285464e774751c95b79ec9c4ff5.zip
add commit hook directory.
The entitlement bug can be fixed https://bugzilla.vyatta.com/show_bug.cgi?id=5354 by adding a hook into this directory.
Diffstat (limited to 'src')
-rw-r--r--src/commit2.c43
-rw-r--r--src/common/defs.h4
2 files changed, 39 insertions, 8 deletions
diff --git a/src/commit2.c b/src/commit2.c
index 01631d6..d5ed4d0 100644
--- a/src/commit2.c
+++ b/src/commit2.c
@@ -1,6 +1,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
+#include <dirent.h>
#include <syslog.h>
#include <string.h>
#include <sys/time.h>
@@ -131,13 +132,13 @@ main(int argc, char** argv)
boolean disable_partial_commit = FALSE;
boolean full_commit_check = FALSE;
boolean break_priority = FALSE;
- char *hook = NULL;
+ boolean disable_hook = FALSE;
/* this is needed before calling certain glib functions */
g_type_init();
//grab inputs
- while ((ch = getopt(argc, argv, "dpthsecoafbr:")) != -1) {
+ while ((ch = getopt(argc, argv, "dpthsecoafbr")) != -1) {
switch (ch) {
case 'd':
g_debug = TRUE;
@@ -174,7 +175,7 @@ main(int argc, char** argv)
break_priority = TRUE;
break;
case 'r':
- hook = optarg;
+ disable_hook = TRUE;
break;
default:
usage();
@@ -232,7 +233,7 @@ main(int argc, char** argv)
}
//open the changes file and clear
- FILE *fp_changes = fopen("/tmp/.changes","w");
+ FILE *fp_changes = fopen(COMMIT_CHANGES_FILE,"w");
if (fp_changes == NULL) {
printf("commit2: Cannot access changes file, exiting\n");
syslog(LOG_ERR,"commit2: Cannot access changes file, exiting");
@@ -350,14 +351,40 @@ main(int argc, char** argv)
fclose(fp_changes);
}
- if (hook != NULL) {
- if (system(hook) == -1) {
- syslog(LOG_DEBUG,"commit::main(), error on call to hook");
+ if (disable_hook == FALSE) {
+ DIR *dp;
+ if ((dp = opendir(COMMIT_HOOK_DIR)) == NULL){
+ if (g_debug) {
+ //could also be a terminating value now
+ printf("could not open hook directory\n");
+ syslog(LOG_DEBUG,"could not open hook directory");
+ }
+ }
+ else {
+ if (no_errors == TRUE) {
+ setenv(ENV_COMMIT_STATUS,"SUCCESS",1);
+ }
+ else {
+ setenv(ENV_COMMIT_STATUS,"FAILURE",1);
+ }
+ struct dirent *dirp = NULL;
+ while ((dirp = readdir(dp)) != NULL) {
+ if (strcmp(dirp->d_name, ".") != 0 &&
+ strcmp(dirp->d_name, "..") != 0) {
+ char buf[MAX_LENGTH_DIR_PATH*sizeof(char)];
+ sprintf(buf,"%s/%s",COMMIT_HOOK_DIR,dirp->d_name);
+ if (system(buf) == -1) {
+ syslog(LOG_DEBUG,"commit::main(), error on call to hook: %s", buf);
+ }
+ }
+ }
+ unsetenv(ENV_COMMIT_STATUS);
+ closedir(dp);
}
}
//remove tmp changes file as all the work is now done
- unlink("/tmp/.changes");
+ unlink(COMMIT_CHANGES_FILE);
exit (no_errors == FALSE);
}
diff --git a/src/common/defs.h b/src/common/defs.h
index 88b8441..dcced15 100644
--- a/src/common/defs.h
+++ b/src/common/defs.h
@@ -17,6 +17,10 @@
#define ENV_ACTION_ACTIVE "ACTIVE"
#define ENV_SIBLING_POSITION "COMMIT_SIBLING_POSITION"
#define ENV_DATA_PATH "NODE_DATA_PATH"
+#define ENV_COMMIT_STATUS "COMMIT_STATUS"
+
+#define COMMIT_CHANGES_FILE "/tmp/.changes"
+#define COMMIT_HOOK_DIR "/etc/commit"
struct Result
{