summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoralex <alex@builder.localdomain>2007-12-17 15:34:37 -0800
committeralex <alex@builder.localdomain>2007-12-17 15:34:37 -0800
commite031e51f8da8581311d780983d2e335f058fca99 (patch)
tree2981c37aa3fc5252f6659870e5b4bce1717e13a5
parentedb8226cb91b197f022bfdd28246ff5a86541614 (diff)
parente65d2f0e7423bd9d6120e0373a83aad3795670aa (diff)
downloadvyatta-cfg-e031e51f8da8581311d780983d2e335f058fca99.tar.gz
vyatta-cfg-e031e51f8da8581311d780983d2e335f058fca99.zip
Merge branch 'master' of http://phuket.vyatta.com/vyatta-cfg
-rw-r--r--debian/vyatta-cfg.postinst.in3
-rw-r--r--etc/bash_completion.d/20vyatta-cfg44
-rw-r--r--etc/default/vyatta-cfg21
-rwxr-xr-xetc/init.d/vyatta-ofr72
-rw-r--r--scripts/VyattaConfig.pm2
-rw-r--r--scripts/VyattaConfigDOMTree.pm2
-rwxr-xr-xscripts/vyatta-cfg-notify4
-rwxr-xr-xscripts/vyatta-load-config.pl6
-rwxr-xr-xscripts/vyatta-save-config.pl9
-rwxr-xr-xscripts/xorp_tmpl_tool14
-rw-r--r--src/cli_new.c134
-rw-r--r--src/commit.c4
-rw-r--r--src/delete.c4
13 files changed, 196 insertions, 123 deletions
diff --git a/debian/vyatta-cfg.postinst.in b/debian/vyatta-cfg.postinst.in
index 80ddb8c..3fce13b 100644
--- a/debian/vyatta-cfg.postinst.in
+++ b/debian/vyatta-cfg.postinst.in
@@ -3,6 +3,9 @@
prefix=@prefix@
sysconfdir=@sysconfdir@
+mkdir -m 0775 -p $sysconfdir/config $prefix/config
+chgrp quaggavty $sysconfdir/config $prefix/config
+
update-rc.d vyatta-ofr defaults 90 >/dev/null
# do we want to start vyatta-ofr here in postinst?
diff --git a/etc/bash_completion.d/20vyatta-cfg b/etc/bash_completion.d/20vyatta-cfg
index dc05cf1..bc9088f 100644
--- a/etc/bash_completion.d/20vyatta-cfg
+++ b/etc/bash_completion.d/20vyatta-cfg
@@ -647,6 +647,17 @@ ENDCOMMENT
vyatta_help_text="\\nNo help text available"
}
+generate_pipe_help ()
+{
+ local -a hcomps=( "${_vyatta_pipe_completions[@]}" \
+ "${_vyatta_pipe_noncompletions[@]}" )
+ local -a hstrs=()
+ for comp in "${hcomps[@]}"; do
+ hstrs+=("$(_vyatta_pipe_help "$comp")")
+ done
+ generate_help_text hcomps hstrs
+}
+
vyatta_config_complete ()
{
local restore_shopts=$( shopt -p extglob nullglob | tr \\n \; )
@@ -660,6 +671,14 @@ vyatta_config_complete ()
vyatta_do_help=0
fi
+ # handle pipe
+ if _vyatta_pipe_completion "${COMP_WORDS[@]}"; then
+ generate_pipe_help
+ vyatta_completions=( "${_vyatta_pipe_completions[@]}" )
+ vyatta_do_complete
+ return
+ fi
+
if (( ${#COMP_WORDS[@]} < 2 )); then
declare -a hitems=( "commit" \
"delete" \
@@ -707,19 +726,6 @@ vyatta_config_complete ()
(( num_comp -= 1 ))
fi
- # handle pipe
- if [ "${COMP_WORDS[$num_comp]}" == "|" ]; then
- declare -a hitems=( "more" \
- )
- declare -a hstrs=( \
- "Paginate the output" \
- )
- generate_help_text hitems hstrs
- vyatta_completions=( "${hitems[@]}" )
- vyatta_do_complete
- return
- fi
-
(( last_idx = num_comp - 1 ))
comp_words=( ${COMP_WORDS[@]:1:$num_comp} )
@@ -935,12 +941,18 @@ make_vyatta_config_dir ()
sudo chgrp ${DEF_GROUP} $1
}
+if grep -q union=aufs /proc/cmdline || grep -q aufs /proc/filesystems ; then
+ export UNIONFS=aufs
+else
+ export UNIONFS=unionfs
+fi
+
make_vyatta_config_dir $VYATTA_ACTIVE_CONFIGURATION_DIR
make_vyatta_config_dir $VYATTA_CHANGES_ONLY_DIR
make_vyatta_config_dir $VYATTA_CONFIG_TMP
if [ ! -d $VYATTA_TEMP_CONFIG_DIR ]; then
make_vyatta_config_dir $VYATTA_TEMP_CONFIG_DIR
- sudo mount -t unionfs -o dirs=${VYATTA_CHANGES_ONLY_DIR}=rw:/opt/vyatta/config/active=ro unionfs ${VYATTA_TEMP_CONFIG_DIR}
+ sudo mount -t $UNIONFS -o dirs=${VYATTA_CHANGES_ONLY_DIR}=rw:/opt/vyatta/config/active=ro $UNIONFS ${VYATTA_TEMP_CONFIG_DIR}
fi
# disallow 'Ctrl-D' exit, since we need special actions on 'exit'
@@ -970,3 +982,7 @@ complete -F vyatta_config_complete edit
complete -F vyatta_config_complete exit
complete -F vyatta_run_complete run
+# Local Variables:
+# mode: shell-script
+# sh-indentation: 4
+# End:
diff --git a/etc/default/vyatta-cfg b/etc/default/vyatta-cfg
index d369e0f..e560788 100644
--- a/etc/default/vyatta-cfg
+++ b/etc/default/vyatta-cfg
@@ -1,15 +1,18 @@
# Vyatta shell environment variables for config mode
# should be sourced from /etc/default/vyatta
-export VYATTA_ACTIVE_CONFIGURATION_DIR=${vyatta_configdir}/active
-export VYATTA_CHANGES_ONLY_DIR=${vyatta_configdir}/tmp/changes_only_$$
-export VYATTA_TEMP_CONFIG_DIR=${vyatta_configdir}/tmp/new_config_$$
-export VYATTA_CONFIG_TMP=${vyatta_configdir}/tmp/tmp_$$
-export VYATTA_CONFIG_TEMPLATE=$vyatta_cfg_templates
-export VYATTA_EDIT_LEVEL=/
-export VYATTA_TEMPLATE_LEVEL=/
-export VYATTA_TAG_NAME=node.tag
-export VYATTA_MOD_NAME=.modified
+{
+declare -x -r VYATTA_ACTIVE_CONFIGURATION_DIR=${vyatta_configdir}/active
+declare -x -r VYATTA_CHANGES_ONLY_DIR=${vyatta_configdir}/tmp/changes_only_$$
+declare -x -r VYATTA_TEMP_CONFIG_DIR=${vyatta_configdir}/tmp/new_config_$$
+declare -x -r VYATTA_CONFIG_TMP=${vyatta_configdir}/tmp/tmp_$$
+declare -x -r VYATTA_CONFIG_TEMPLATE=$vyatta_cfg_templates
+declare -x -r VYATTA_EDIT_LEVEL=/
+declare -x -r VYATTA_TEMPLATE_LEVEL=/
+declare -x -r VYATTA_TAG_NAME=node.tag
+declare -x -r VYATTA_MOD_NAME=.modified
+declare -x -r VYATTA_CFG_GROUP_NAME=vyattacfg
+} 2>/dev/null || :
# don't set level if already set
if [ -n "$VYATTA_USER_LEVEL_DIR" ]; then
diff --git a/etc/init.d/vyatta-ofr b/etc/init.d/vyatta-ofr
index 96770f6..4f8b7dd 100755
--- a/etc/init.d/vyatta-ofr
+++ b/etc/init.d/vyatta-ofr
@@ -69,53 +69,6 @@ have_rl_system () {
test -x $vyatta_sbindir/rl-system.init
}
-use_floppy () {
- _fd_=/media/floppy
-
- if have_rl_system ; then
-## only do this if we have the rl-system package
-## if we donot discover an fd device, try loading the floppy module
- grep -q fd /proc/devices || modprobe -q floppy 2>/dev/null
- if grep -q fd /proc/devices ; then
- if awk -- '$1 ~ /\/dev\/fd/ { exit 1 }' /proc/mounts
- then
- mkdir -p $_fd_
- mount -t ext2 /dev/fd0 $_fd_ -o sync 2>/dev/null
- test $? -eq 32 && mount -t vfat /dev/fd0 $_fd_ 2>/dev/null
- fi
- fi
- fi
- test -d ${_fd_}/config
-}
-
-setup_configdir() {
- [ -f $BOOTFILE ] && return 0
- mkdir -m 0775 -p ${vyatta_sysconfdir}/config
- chgrp ${GROUP} ${vyatta_sysconfdir}/config
- if [ -d ~root/vyatta/config ] ; then
- mount -o bind ~root/vyatta/config $vyatta_sysconfdir/config
- elif use_floppy ; then
- mount -o bind /media/floppy/config $vyatta_sysconfdir/config
- else
- mkdir -m 0775 -p ~root/vyatta/config
- chgrp ${GROUP} ~root/vyatta ~root/vyatta/config
- mount -o bind ~root/vyatta/config $vyatta_sysconfdir/config
- fi
-}
-
-setup_rclocal () {
- [ -f /etc/rc.local ] || touch /etc/rc.local
- if [ -f ~root/vyatta/rc.local ]; then
- mount -o bind ~root/vyatta/rc.local /etc/rc.local
- elif [ -f /media/floppy/rc.local ]; then
- mount -o bind /media/floppy/rc.local /etc/rc.local
- fi
-}
-
-restore_rclocal () {
- umount /etc/rc.local >& /dev/null
-}
-
# if necessary, provide initial config
init_bootfile () {
if [ ! -f $BOOTFILE ] ; then
@@ -150,28 +103,11 @@ load_bootfile ()
fi
}
-# this handles the "config dir" (/opt/vyatta/config), which is different
-# from the directory for config files (/opt/vyatta/etc/config).
-mount_cfg_dir ()
-{
- if [ ! -d ${vyatta_configdir} ] ; then
- mkdir -m 0775 -p ${vyatta_configdir}
- chgrp ${GROUP} ${vyatta_configdir}
- fi
- mount -o nosuid,nodev -t tmpfs none ${vyatta_configdir}
-}
-
-unmount_cfg_dir ()
-{
- umount ${vyatta_configdir}
-}
-
start ()
{
log_daemon_msg "Starting Vyatta Router"
- setup_configdir
- setup_rclocal
- mount_cfg_dir
+ mount -o nosuid,nodev,mode=775 -t tmpfs none ${vyatta_configdir}
+ chgrp ${GROUP} ${vyatta_configdir}
init_bootfile
migrate_bootfile
for s in ${subinit[@]} ; do
@@ -179,7 +115,6 @@ start ()
${vyatta_sbindir}/${s}.init start || (log_end_msg $? && return)
done
load_bootfile
- echo -n $BOOTFILE > ${vyatta_sysconfdir}/bootfile_path
log_end_msg $?
}
@@ -193,8 +128,7 @@ stop()
${vyatta_sbindir}/${s}.init stop
let status\|=$?
done
- unmount_cfg_dir
- restore_rclocal
+ umount ${vyatta_configdir}
log_end_msg $status
}
diff --git a/scripts/VyattaConfig.pm b/scripts/VyattaConfig.pm
index a783957..9b1b933 100644
--- a/scripts/VyattaConfig.pm
+++ b/scripts/VyattaConfig.pm
@@ -284,7 +284,7 @@ sub listDeleted {
if (! -d "$filepath") { return undef; }
else {
opendir DIR, "$filepath" or return undef;
- @nodes = grep /^\.wh./, readdir DIR;
+ @nodes = grep !/^\.wh\.\.wh\./, grep /^\.wh./, readdir DIR;
closedir DIR;
}
diff --git a/scripts/VyattaConfigDOMTree.pm b/scripts/VyattaConfigDOMTree.pm
index d951202..86aabf8 100644
--- a/scripts/VyattaConfigDOMTree.pm
+++ b/scripts/VyattaConfigDOMTree.pm
@@ -307,7 +307,7 @@ sub getSubNodesNumber {
my @subs = $node->getSubNodes();
- if(defined @subs) {
+ if(@subs) {
$ret = $#subs + 1;
}
}
diff --git a/scripts/vyatta-cfg-notify b/scripts/vyatta-cfg-notify
index 82dc6a3..07a385d 100755
--- a/scripts/vyatta-cfg-notify
+++ b/scripts/vyatta-cfg-notify
@@ -1,11 +1,13 @@
#!/bin/bash
+[ -r /etc/default/vyatta ] && source /etc/default/vyatta
+
declare cur_tty=$(ps -o tty= |head -n1)
declare cur_uid=($(ps -o ruser= n |head -n1))
declare cur_user=$(grep "[^:]\+:[^:]*:${cur_uid[0]}:" /etc/passwd \
| cut -d ':' -f 1)
declare -a ulist=( $(ps -a -o args,tty,ruser n \
- | grep '^newgrp quaggavty' | cut -c 29-) )
+ | grep "^newgrp $VYATTA_CFG_GROUP_NAME" | cut -c 29-) )
for (( i = 0; i < ${#ulist[@]}; i += 2 )); do
utty=${ulist[i]}
diff --git a/scripts/vyatta-load-config.pl b/scripts/vyatta-load-config.pl
index a6f037a..d011a65 100755
--- a/scripts/vyatta-load-config.pl
+++ b/scripts/vyatta-load-config.pl
@@ -8,11 +8,7 @@ use VyattaConfigLoad;
my $etcdir = $ENV{vyatta_sysconfdir};
my $sbindir = $ENV{vyatta_sbindir};
-my $bootpath = '';
-if (-r "$etcdir/bootfile_path") {
- $bootpath = `cat $etcdir/bootfile_path`;
-}
-$bootpath =~ s/\/[^\/]+$//;
+my $bootpath = $etcdir . "/config";
if ($#ARGV != 0) {
print "Usage: load <config_file_name>\n";
diff --git a/scripts/vyatta-save-config.pl b/scripts/vyatta-save-config.pl
index 26b8eec..bad7c45 100755
--- a/scripts/vyatta-save-config.pl
+++ b/scripts/vyatta-save-config.pl
@@ -5,19 +5,14 @@ use lib "/opt/vyatta/share/perl5/";
use VyattaConfigOutput;
my $etcdir = "/opt/vyatta/etc";
-my $bootfile = '';
-if (-r "$etcdir/bootfile_path") {
- $bootfile = `cat $etcdir/bootfile_path`;
-}
-my $bootpath = $bootfile;
-$bootpath =~ s/\/[^\/]+$//;
+my $bootpath = $etcdir . "/config";
+my $save_file = $bootpath . "/config.boot";
if ($#ARGV > 0) {
print "Usage: save [config_file_name]\n";
exit 1;
}
-my $save_file = "$bootfile";
if (defined($ARGV[0])) {
$save_file = $ARGV[0];
if (!($save_file =~ /^\//)) {
diff --git a/scripts/xorp_tmpl_tool b/scripts/xorp_tmpl_tool
index 54c87bb..014a53b 100755
--- a/scripts/xorp_tmpl_tool
+++ b/scripts/xorp_tmpl_tool
@@ -1,5 +1,11 @@
#!/bin/bash
+if grep -q union=aufs /proc/cmdline || grep -q aufs /proc/filesystems ; then
+ export UNIONFS=aufs
+else
+ export UNIONFS=unionfs
+fi
+
UMASK_SAVE_G=`umask`
umask 0111
XORPLOGFILE=/tmp/xorp_tmpl_tool.log
@@ -36,7 +42,7 @@ export VYATTA_TEMP_CONFIG_DIR=/opt/vyatta/config/tmp/new_config_$VTID;
if [ ! -d $VYATTA_TEMP_CONFIG_DIR ]
then
mkdir -p $VYATTA_TEMP_CONFIG_DIR
- sudo mount -t unionfs -o dirs=${VYATTA_CHANGES_ONLY_DIR}=rw:/opt/vyatta/config/active=ro unionfs ${VYATTA_TEMP_CONFIG_DIR}
+ sudo mount -t $UNIONFS -o dirs=${VYATTA_CHANGES_ONLY_DIR}=rw:/opt/vyatta/config/active=ro $UNIONFS ${VYATTA_TEMP_CONFIG_DIR}
fi
## cli ENV_TMP_DIR
@@ -110,7 +116,7 @@ case "$1" in
sudo umount ${VYATTA_TEMP_CONFIG_DIR}
sudo rm -rf $VYATTA_CHANGES_ONLY_DIR/* $VYATTA_CHANGES_ONLY_DIR/.modified
- sudo mount -t unionfs -o dirs=${VYATTA_CHANGES_ONLY_DIR}=rw:/opt/vyatta/config/active=ro unionfs ${VYATTA_TEMP_CONFIG_DIR}
+ sudo mount -t $UNIONFS -o dirs=${VYATTA_CHANGES_ONLY_DIR}=rw:/opt/vyatta/config/active=ro $UNIONFS ${VYATTA_TEMP_CONFIG_DIR}
RET_STATUS=0
;;
end_loading)
@@ -150,3 +156,7 @@ echo "ret=${RET_STATUS}" >> ${XORPLOGFILE}
umask ${UMASK_SAVE_G}
exit $RET_STATUS
+# Local Variables:
+# mode: shell-script
+# sh-indentation: 4
+# End:
diff --git a/src/cli_new.c b/src/cli_new.c
index d4380d5..b668e5b 100644
--- a/src/cli_new.c
+++ b/src/cli_new.c
@@ -14,6 +14,8 @@
#include "cli_val.h"
#include "cli_parse.h"
#include <regex.h>
+#include <errno.h>
+#include <time.h>
#include "cli_objects.h"
#include "cli_val_engine.h"
@@ -229,6 +231,7 @@ void di(vtw_sorted *srtp)
}
#define LOCK_FILE "/opt/vyatta/config/.lock"
+#define COMMIT_CMD "/opt/vyatta/sbin/my_commit"
static void
release_config_lock()
@@ -237,22 +240,133 @@ release_config_lock()
/* error ignored */
}
-int
-get_config_lock()
+/* try to clean up orphaned lock file. return -1 if failed */
+static int
+try_lock_cleanup()
{
- int fd = open(LOCK_FILE, O_WRONLY | O_CREAT | O_EXCL, 0660);
+ char buf[128];
+ char proc[128];
+ FILE *f = NULL;
+ int ret = -1;
+ struct stat statb;
+
+ do {
+ /* get the proc entry */
+ if ((f = fopen(LOCK_FILE, "r")) == NULL) {
+ break;
+ }
+ if (fgets(proc, 128, f) == NULL) {
+ break;
+ }
+ /* read the proc entry */
+ if (stat(proc, &statb) == -1) {
+ if (errno == ENOENT) {
+ /* proc entry doesn't exist. can clean up the lock now */
+ ret = 0;
+ break;
+ }
+ }
+ fclose(f);
+ if ((f = fopen(proc, "r")) == NULL) {
+ /* can't open proc entry. assume we can't clean up */
+ break;
+ }
+ if (fgets(buf, 128, f) == NULL) {
+ /* can't read proc entry. assume we can't clean up */
+ break;
+ }
+ /* check if the process is commit */
+ if (strcmp(buf, COMMIT_CMD) == 0) {
+ /* it is commit. can't clean up */
+ break;
+ }
+ /* can clean up the lock */
+ ret = 0;
+ } while (0);
+ if (f) {
+ fclose(f);
+ }
+ if (ret == 0) {
+ unlink(LOCK_FILE);
+ if (stat(LOCK_FILE, &statb) != -1 || errno != ENOENT) {
+ /* proc entry still exists. cleanup failed */
+ ret = -1;
+ }
+ }
+ return ret;
+}
+
+static int
+create_lock_file(int try_cleanup)
+{
+ int fd = -1;
+ int i = 0;
+ struct timespec req;
+
+#define LOCK_WAIT_TIME 2
+#define LOCK_NUM_RETRIES 5
+ req.tv_sec = LOCK_WAIT_TIME;
+ req.tv_nsec = 0;
+ fd = open(LOCK_FILE, O_WRONLY | O_CREAT | O_EXCL, 0660);
if (fd == -1) {
- return -1;
+ for (i = 0; i < LOCK_NUM_RETRIES; i++) {
+ nanosleep(&req, NULL);
+ fd = open(LOCK_FILE, O_WRONLY | O_CREAT | O_EXCL, 0660);
+ if (fd >= 0) {
+ break;
+ }
+ }
}
- if (close(fd) == -1) {
- release_config_lock();
- return -1;
+ if (fd == -1 && try_cleanup) {
+ if (try_lock_cleanup() != -1) {
+ /* cleanup succeeded */
+ fd = create_lock_file(0);
+ }
}
- if (atexit(release_config_lock) != 0) {
+ return fd;
+}
+
+int
+get_config_lock()
+{
+ int fd = -1;
+ FILE *lfile = NULL;
+ int ret = -1;
+
+ do {
+ /* create lock file */
+ fd = create_lock_file(1);
+ if (fd == -1) {
+ break;
+ }
+
+ /* write pid into lock file */
+ if ((lfile = fdopen(fd, "w")) == NULL) {
+ break;
+ }
+ if (fprintf(lfile, "/proc/%u/cmdline", getpid()) < 0) {
+ break;
+ }
+ /* fclose also closes fd */
+ if (fclose(lfile) != 0) {
+ break;
+ }
+ /* clean up on exit */
+ if (atexit(release_config_lock) != 0) {
+ break;
+ }
+ ret = 0;
+ } while (0);
+
+ if (ret == -1) {
+ if (lfile) {
+ fclose(lfile);
+ } else if (fd != -1) {
+ close(fd);
+ }
release_config_lock();
- return -1;
}
- return 0;
+ return ret;
}
void internal_error(int line, char *file)
diff --git a/src/commit.c b/src/commit.c
index 24aff34..c3219e5 100644
--- a/src/commit.c
+++ b/src/commit.c
@@ -1338,8 +1338,8 @@ static int fin_commit(boolean ok)
static char format4[]="rm -rf %s/{.*,*} >&/dev/null ; /bin/true"; /*cdirp*/
static char format5[]="rm -rf %s/{.*,*} >&/dev/null ; /bin/true"; /*adirp*/
static char format6[]="mv -f %s/* -t %s";/*tmpp, adirp*/
- static char format7[]="sudo mount -t unionfs -o dirs=%s=rw:%s=ro"
- " unionfs %s"; /*cdirp, adirp, mdirp*/
+ static char format7[]="sudo mount -t $UNIONFS -o dirs=%s=rw:%s=ro"
+ " $UNIONFS %s"; /*cdirp, adirp, mdirp*/
int m_len = strlen(get_mdirp());
int t_len = strlen(get_tmpp());
int c_len = strlen(get_cdirp());
diff --git a/src/delete.c b/src/delete.c
index 1b7b62e..b62a697 100644
--- a/src/delete.c
+++ b/src/delete.c
@@ -28,8 +28,8 @@ static void remove_rf(boolean do_umount)
command = my_malloc(strlen(get_mdirp()) + strlen(get_cdirp()) +
strlen(get_mdirp()) + 100,
"delete");
- sprintf(command, "sudo mount -t unionfs -o dirs=%s=rw:%s=ro:"
- " unionfs %s", get_cdirp(), get_adirp(), get_mdirp());
+ sprintf(command, "sudo mount -t $UNIONFS -o dirs=%s=rw:%s=ro:"
+ " $UNIONFS %s", get_cdirp(), get_adirp(), get_mdirp());
system(command);
free(command);
}