[PATCH] New APIs to implement transactional changes to network config
by Laine Stump
This patch provides three new public API functions that allow
reverting the network configuration back to a previous "known good"
state. The three new functions are:
ncf_change_begin() - save a snapshot of current network config
ncf_change_rollback() - revert to the config previously saved
ncf_change_commit() - delete the saved snapshot, making the new
config permanent
If the system is rebooted after ncf_change_begin() is called, but
prior to calling ncf_change_commit(), the network config will be
automatically reverted to the saved state during the boot process.
The functionality is provided by the the script netcf-transaction,
which was added in the previous patch.
This initial version only updates the config files during a
rollback. It doesn't attempt to ifdown interfaces that are being
removed, ifup interfaces that are being added, or ifdown/ifup
interfaces that have been changed. That will be in an upcoming patch.
---
configure.ac | 2 +-
src/drv_initscripts.c | 43 +++++++++++++++++++++++++++++++++
src/internal.h | 4 +++
src/ncftool.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++++
src/netcf.c | 21 ++++++++++++++++
src/netcf.h | 22 +++++++++++++++++
src/netcf_public.syms | 7 +++++
7 files changed, 161 insertions(+), 1 deletions(-)
diff --git a/configure.ac b/configure.ac
index f62097b..abc7a13 100644
--- a/configure.ac
+++ b/configure.ac
@@ -6,7 +6,7 @@ AM_CONFIG_HEADER([config.h])
AM_INIT_AUTOMAKE([-Wno-portability 1.11 color-tests parallel-tests])
AM_SILENT_RULES([yes]) # make --enable-silent-rules the default.
-AC_SUBST([LIBNETCF_VERSION_INFO], [4:3:3])
+AC_SUBST([LIBNETCF_VERSION_INFO], [5:0:4])
AC_GNU_SOURCE
diff --git a/src/drv_initscripts.c b/src/drv_initscripts.c
index b2f16d5..39a8070 100644
--- a/src/drv_initscripts.c
+++ b/src/drv_initscripts.c
@@ -1070,6 +1070,49 @@ int drv_if_down(struct netcf_if *nif) {
return result;
}
+/* Functions to take a snapshot of network config (change_begin), and
+ * later either revert to that config (change_rollback), or make the
+ * new config permanent (change_commit).
+ */
+int
+drv_change_begin(struct netcf *ncf ATTRIBUTE_UNUSED,
+ unsigned int flags ATTRIBUTE_UNUSED)
+{
+ int result = -1;
+
+ run1(ncf, NETCF_TRANSACTION, "change-begin");
+ ERR_BAIL(ncf);
+ result = 0;
+error:
+ return result;
+}
+
+int
+drv_change_rollback(struct netcf *ncf ATTRIBUTE_UNUSED,
+ unsigned int flags ATTRIBUTE_UNUSED)
+{
+ int result = -1;
+
+ run1(ncf, NETCF_TRANSACTION, "change-rollback");
+ ERR_BAIL(ncf);
+ result = 0;
+error:
+ return result;
+}
+
+int
+drv_change_commit(struct netcf *ncf ATTRIBUTE_UNUSED,
+ unsigned int flags ATTRIBUTE_UNUSED)
+{
+ int result = -1;
+
+ run1(ncf, NETCF_TRANSACTION, "change-commit");
+ ERR_BAIL(ncf);
+ result = 0;
+error:
+ return result;
+}
+
/*
* Test interface
*/
diff --git a/src/internal.h b/src/internal.h
index b7fa5f2..78494e9 100644
--- a/src/internal.h
+++ b/src/internal.h
@@ -182,6 +182,10 @@ int drv_lookup_by_mac_string(struct netcf *, const char *mac,
char *drv_xml_desc(struct netcf_if *);
char *drv_xml_state(struct netcf_if *);
int drv_if_status(struct netcf_if *nif, unsigned int *flags);
+int drv_change_begin(struct netcf *ncf, unsigned int flags);
+int drv_change_rollback(struct netcf *ncf, unsigned int flags);
+int drv_change_commit(struct netcf *ncf, unsigned int flags);
+
const char *drv_mac_string(struct netcf_if *nif);
struct netcf_if *drv_define(struct netcf *ncf, const char *xml);
int drv_undefine(struct netcf_if *nif);
diff --git a/src/ncftool.c b/src/ncftool.c
index f86b62c..b202e17 100644
--- a/src/ncftool.c
+++ b/src/ncftool.c
@@ -412,6 +412,66 @@ static const struct command_def cmd_undefine_def = {
.help = "remove the configuration of an interface"
};
+static int cmd_change_begin(ATTRIBUTE_UNUSED const struct command *cmd)
+{
+ if (ncf_change_begin(ncf, 0) < 0)
+ return CMD_RES_ERR;
+ printf("config change transaction started\n");
+ return CMD_RES_OK;
+}
+
+static const struct command_opt_def cmd_change_begin_opts[] = {
+ CMD_OPT_DEF_LAST
+};
+
+static const struct command_def cmd_change_begin_def = {
+ .name = "change-begin",
+ .opts = cmd_change_begin_opts,
+ .handler = cmd_change_begin,
+ .synopsis = "mark the beginning of a set of revertable network config changes",
+ .help = "marks the beginning of a set of revertable network config changes",
+};
+
+static int cmd_change_commit(ATTRIBUTE_UNUSED const struct command *cmd)
+{
+ if (ncf_change_commit(ncf, 0) < 0)
+ return CMD_RES_ERR;
+ printf("config change transaction committed\n");
+ return CMD_RES_OK;
+}
+
+static const struct command_opt_def cmd_change_commit_opts[] = {
+ CMD_OPT_DEF_LAST
+};
+
+static const struct command_def cmd_change_commit_def = {
+ .name = "change-commit",
+ .opts = cmd_change_commit_opts,
+ .handler = cmd_change_commit,
+ .synopsis = "commit the pending network config changes",
+ .help = "commits (makes permanent) of a set of network config changes",
+};
+
+static int cmd_change_rollback(ATTRIBUTE_UNUSED const struct command *cmd)
+{
+ if (ncf_change_rollback(ncf, 0) < 0)
+ return CMD_RES_ERR;
+ printf("config change transaction rolled back\n");
+ return CMD_RES_OK;
+}
+
+static const struct command_opt_def cmd_change_rollback_opts[] = {
+ CMD_OPT_DEF_LAST
+};
+
+static const struct command_def cmd_change_rollback_def = {
+ .name = "change-rollback",
+ .opts = cmd_change_rollback_opts,
+ .handler = cmd_change_rollback,
+ .synopsis = "rollback (revert) a set of network config changes",
+ .help = "rollback (revert) a set of network config changes",
+};
+
static int cmd_help(const struct command *cmd) {
const char *name = param_value(cmd, "command");
if (name == NULL) {
@@ -616,6 +676,9 @@ static const struct command_def const *commands[] = {
&cmd_undefine_def,
&cmd_if_up_def,
&cmd_if_down_def,
+ &cmd_change_begin_def,
+ &cmd_change_commit_def,
+ &cmd_change_rollback_def,
&cmd_help_def,
&cmd_quit_def,
&cmd_def_last
diff --git a/src/netcf.c b/src/netcf.c
index 9440ed0..34994bb 100644
--- a/src/netcf.c
+++ b/src/netcf.c
@@ -196,6 +196,27 @@ int ncf_if_status(struct netcf_if *nif, unsigned int *flags) {
return drv_if_status(nif, flags);
}
+int
+ncf_change_begin(struct netcf *ncf, unsigned int flags)
+{
+ API_ENTRY(ncf);
+ return drv_change_begin(ncf, flags);
+}
+
+int
+ncf_change_rollback(struct netcf *ncf, unsigned int flags)
+{
+ API_ENTRY(ncf);
+ return drv_change_rollback(ncf, flags);
+}
+
+int
+ncf_change_commit(struct netcf *ncf, unsigned int flags)
+{
+ API_ENTRY(ncf);
+ return drv_change_commit(ncf, flags);
+}
+
/* Release any resources used by this NETCF_IF; the pointer is invalid
* after this call
*/
diff --git a/src/netcf.h b/src/netcf.h
index bf5e4e2..e507b97 100644
--- a/src/netcf.h
+++ b/src/netcf.h
@@ -169,6 +169,28 @@ char *ncf_if_xml_state(struct netcf_if *);
*/
int ncf_if_status(struct netcf_if *nif, unsigned int *flags);
+/* Mark the beginning of a sequence of revertable changes to the
+ * network interface config by saving a snapshot of all relevant
+ * config information.
+ * Returns 0 on success, -1 on failure
+ */
+int ncf_change_begin(struct netcf *ncf, unsigned int flags);
+
+/* Revert to the previously snapshotted (with ncf_change_begin)
+ * network config, effectively undoing the changes.
+ * Returns 0 on success, -1 on failure
+ */
+int ncf_change_rollback(struct netcf *ncf, unsigned int flags);
+
+/* Commit the changes made to network config since ncf_change_begin
+ * was called (usually by simply deleting the snapshot that was saved,
+ * as well as bringing down any interfaces that will not be present in
+ * the restored config, and bouncing interfaces that still exist, but
+ * have changed their config.)
+ * Returns 0 on success, -1 on failure
+ */
+int ncf_change_commit(struct netcf *ncf, unsigned int flags);
+
/* Release any resources used by this NETCF_IF; the pointer is invalid
* after this call
*/
diff --git a/src/netcf_public.syms b/src/netcf_public.syms
index 9180614..e0e034a 100644
--- a/src/netcf_public.syms
+++ b/src/netcf_public.syms
@@ -28,3 +28,10 @@ NETCF_1.3.0 {
global:
ncf_if_status;
} NETCF_1.2.0;
+
+NETCF_1.4.0 {
+ global:
+ ncf_change_begin;
+ ncf_change_commit;
+ ncf_change_rollback;
+} NETCF_1.3.0;
--
1.7.3.4
12 years, 11 months
[PATCH] add netcf-transaction initscript
by Laine Stump
netcf-transaction is a shell script that can take a snapshot of
network config files, and later either commit the changes made (by
deleting the snapshot) or revert back to the original config. If
uncommitted changes exist at boottime, netcf-transaction will
automatically revert them.
Available commands:
snapshot-config: save a copy of the current network interface config
commit-config: delete the saved snapshot
rollback-config: archive the current state of config into a rollback
directory, and copy the original snapshotted state
back into place
snapshot-dir: return the path to the snapshot directory.
start, restart, reload, force-reload, condrestart, and try-restart are
all synomyms for snapshot-config.
---
This script (which is based on Dan Kenigsberg's patch to
/etc/rc.d/init.d/network) will be used by the new APIs
ncf_change_begin(), ncf_change_commit(), and ncf_change_rollback(),
which will also be submitted sometime today.
netcf.spec.in | 1 +
src/Makefile.am | 28 ++++++++-
src/netcf-transaction.init.sh | 145 +++++++++++++++++++++++++++++++++++++++++
3 files changed, 173 insertions(+), 1 deletions(-)
create mode 100755 src/netcf-transaction.init.sh
diff --git a/netcf.spec.in b/netcf.spec.in
index 04224fe..0da97a0 100644
--- a/netcf.spec.in
+++ b/netcf.spec.in
@@ -64,6 +64,7 @@ rm -rf $RPM_BUILD_ROOT
%defattr(-,root,root,-)
%{_datadir}/netcf
%{_libdir}/*.so.*
+%{_sysconfdir}/rc.d/init.d/netcf-transaction
%doc AUTHORS COPYING NEWS
%files devel
diff --git a/src/Makefile.am b/src/Makefile.am
index 9d8a3d7..2c79f25 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -14,7 +14,8 @@ bin_PROGRAMS = ncftool
noinst_PROGRAMS = ncftransform
EXTRA_DIST = netcf_public.syms \
- netcf_private.syms
+ netcf_private.syms \
+ netcf-transaction.init.sh
if NETCF_DRIVER_INITSCRIPTS
DRIVER_SOURCES = drv_initscripts.c dutil.h dutil.c \
@@ -57,4 +58,29 @@ internal.h: datadir.h
datadir.h: $(top_builddir)/config.status
echo '#define DATADIR "$(datadir)"' > datadir.h
+# This is for the initscript that handles network config change
+# transactions.
+install-data-local: install-init
+
+uninstall-local: uninstall-init
+
+install-init: netcf-transaction.init
+ mkdir -p $(DESTDIR)$(sysconfdir)/rc.d/init.d
+ $(INSTALL_SCRIPT) netcf-transaction.init \
+ $(DESTDIR)$(sysconfdir)/rc.d/init.d/netcf-transaction
+
+uninstall-init:
+ rm -f $(DESTDIR)$(sysconfdir)/rc.d/init.d/netcf-transaction \
+ $(DESTDIR)$(sysconfdir)/sysconfig/netcf-transaction
+
+BUILT_SOURCES += netcf-transaction.init
+
+netcf-transaction.init: netcf-transaction.init.sh $(top_builddir)/config.status
+ $(AM_V_GEN)sed \
+ -e 's!\@localstatedir\@!$(localstatedir)!g' \
+ -e 's!\@sysconfdir\@!$(sysconfdir)!g' \
+ < $< > $@-t && \
+ chmod a+x $@-t && \
+ mv $@-t $@
+
DISTCLEANFILES += $(BUILT_SOURCES)
diff --git a/src/netcf-transaction.init.sh b/src/netcf-transaction.init.sh
new file mode 100755
index 0000000..5750e27
--- /dev/null
+++ b/src/netcf-transaction.init.sh
@@ -0,0 +1,145 @@
+#!/bin/sh
+#
+# netcf-transaction: save/restore current network interface configuration
+#
+# chkconfig: - 09 91
+# description: Potentially rolls back network interface config to a \
+# known good state at boot time. Also includes utility \
+# commands to create this "known good state", remove it \
+# (ie, accept the current config as "known good"), and \
+# to manually rollback to the known good state, if it \
+# exists.
+
+### BEGIN INIT INFO
+# Provides: netcf-transaction
+# Required-Start: $local_fs
+# Short-Description: save/restore network configuration files
+# Description: This script can save the current state of network config,
+# and later revert to that config, or commit the new config
+# (by deleting the snapshot). At boottime, if there are
+# uncomitted changes to the network config, they are
+# reverted (and the discarded changes are archived in
+# /var/lib/netcf/network-rollback-*).
+#
+### END INIT INFO
+
+sysconfdir="@sysconfdir@"
+localstatedir="@localstatedir@"
+
+netconfdir="$sysconfdir"/sysconfig/network-scripts
+snapshotdir="$localstatedir"/lib/netcf/network-snapshot
+rollbackdirbase="$localstatedir"/lib/netcf/network-rollback
+
+# Source function library.
+test ! -r "$sysconfdir"/rc.d/init.d/functions ||
+ . "$sysconfdir"/rc.d/init.d/functions
+
+# take a snapshot of current network configuration scripts
+snapshot_config ()
+{
+ if test -e "$snapshotdir"
+ then
+ echo "snapshot directory $snapshotdir already exists"
+ return 1;
+ fi
+ mkdir -p "$snapshotdir"
+ for f in "$netconfdir"/{ifcfg,route,rule}-*
+ do
+ test -f "$f" && cp -p "$f" "$snapshotdir"
+ done
+}
+
+commit_config ()
+{
+ rm -rf "$snapshotdir"
+}
+
+# rollback network configuration to last snapshot (if one exists)
+rollback_config ()
+{
+ # return immediately if there is no snapshot
+ test ! -d "$snapshotdir" && return 0
+
+ # eliminate all but the last 20 rollback saves
+ ls -d "$rollbackdirbase"-* 2>/dev/null | head -n -20 |\
+ while read r; do rm -rf "$r"; done
+
+ # save a copy of the current config before rollback "just in case"
+ rollbackdir=$rollbackdirbase-`date +%Y.%m.%d-%H:%M:%S`
+ mkdir -p "$rollbackdir"
+ for f in "$netconfdir"/{ifcfg,route,rule}-*
+ do
+ test -f "$f" && cp -p "$f" "$rollbackdir"
+ done
+
+ # There are 4 classes of files, each handled slightly differently to minimize
+ # disruption in services:
+ # 1) file in both, unmodified - just erase the snapshot copy
+ # 2) file in both, modified - copy the snapshot version over the current & erase copy
+ # 3) file in current only - remove the file
+ # 4) file in snapshot only - copy the snapshot file to current
+ #
+ # We handle the 1st three cases in one loop going through all current config
+ # files, and what is left over in snapshotdir is, by definition, case 4.
+ #
+ # (NB: we can't mv the files, because then the selinux labels
+ # don't get reset properly.)
+
+ for f in "$netconfdir"/{ifcfg,route,rule}-*
+ do
+ test ! -f "$f" && continue
+
+ rollbackf=$snapshotdir/`basename "$f"`
+ if test -f "$rollbackf"
+ then
+ # Case (1) & (2) (only copies if they're different)
+ ! diff "$rollbackf" "$f" >/dev/null 2>&1 && cp -pf "$rollbackf" "$f"
+ rm -f "$rollbackf"
+ else
+ # Case (3)
+ rm -f "$f"
+ fi
+ done
+
+ # Case (4)
+ for f in "$snapshotdir"/{ifcfg,route,rule}-*
+ do
+ test ! -f "$f" && continue
+ cp -pf "$f" "$netconfdir"
+ done
+ rm -rf "$snapshotdir"
+}
+
+case "$1" in
+ # commands required in all Fedora initscripts
+ start|restart|reload|force-reload|condrestart|try-restart)
+ echo -n $"Running $prog $1: "
+ rollback_config
+ retval=$?
+ echo
+ ;;
+ stop|status)
+ ;;
+
+
+ # specific to netcf-transaction
+ snapshot-config)
+ snapshot_config
+ ;;
+ commit-config)
+ commit_config
+ ;;
+ rollback-config)
+ rollback_config
+ retval=$?
+ ;;
+ snapshot-dir)
+ echo $snapshotdir
+ retval=0
+ ;;
+ *)
+ echo $"Usage: $0 {start|snapshot-config|commit-config|rollback-config|snapshot-dir}"
+ exit 2
+esac
+
+exit $retval
--
1.7.3.4
12 years, 11 months
debian/ubuntu support
by Serge E. Hallyn
Hi,
is anyone currently working on support for debian/ubuntu?
thanks,
-serge
12 years, 11 months
[PATCH] Capture stdout and stderr when execing external programs
by Laine Stump
This is in response to:
https://bugzilla.redhat.com/show_bug.cgi?id=616060
but will also be useful in an upcoming patch which needs to retrieve
the output of /etc/rc.d/init.d/netcf-transaction.
Before forking, we now create a pipe, then after forking, the child
dup2's both stdout and stderr to the write side of the pipe, and the
parent calls fdopen() on the read side of the pipe and then calls
gnulib's fread_file() before calling waitpid() to reap the process.
---
src/dutil_linux.c | 77 ++++++++++++++++++++++++++++++++++++++++++++++++----
src/dutil_linux.h | 2 +-
2 files changed, 72 insertions(+), 7 deletions(-)
diff --git a/src/dutil_linux.c b/src/dutil_linux.c
index 9935431..4950ce0 100644
--- a/src/dutil_linux.c
+++ b/src/dutil_linux.c
@@ -47,6 +47,7 @@
#include <arpa/inet.h>
#include "safe-alloc.h"
+#include "read-file.h"
#include "ref.h"
#include "list.h"
#include "netcf.h"
@@ -70,15 +71,29 @@ static int
exec_program(struct netcf *ncf,
const char *const*argv,
const char *commandline,
- pid_t *pid)
+ pid_t *pid,
+ int *outfd)
{
sigset_t oldmask, newmask;
struct sigaction sig_action;
char errbuf[128];
+ int pipeout[2] = {-1, -1};
/* commandline is only used for error reporting */
if (commandline == NULL)
commandline = argv[0];
+
+ /* create a pipe to receive stdout+stderr from child */
+ if (outfd) {
+ if (pipe(pipeout) < 0) {
+ report_error(ncf, NETCF_EEXEC,
+ "failed to create pipe while forking for '%s': %s",
+ commandline, strerror_r(errno, errbuf, sizeof(errbuf)));
+ goto error;
+ }
+ *outfd = pipeout[0];
+ }
+
/*
* Need to block signals now, so that child process can safely
* kill off caller's signal handlers without a race.
@@ -103,6 +118,11 @@ exec_program(struct netcf *ncf,
ncf, EEXEC,
"failed to restore signal mask while forking for '%s': %s",
commandline, strerror_r(errno, errbuf, sizeof(errbuf)));
+
+ /* parent doesn't use write side of the pipe */
+ if (pipeout[1] >= 0)
+ close(pipeout[1]);
+
return 0;
}
@@ -133,6 +153,18 @@ exec_program(struct netcf *ncf,
_exit(1);
}
+ if (pipeout[1] >= 0) {
+ /* direct stdout and stderr to the pipe */
+ if (dup2(pipeout[1], fileno(stdout)) < 0
+ || dup2(pipeout[1], fileno(stderr)) < 0) {
+ /* don't report_error, as it will never be seen anyway */
+ _exit(1);
+ }
+ }
+ /* child doesn't use the read side of the pipe */
+ if (pipeout[0] >= 0)
+ close(pipeout[0]);
+
/* close all open file descriptors */
int openmax = sysconf (_SC_OPEN_MAX);
for (i = 3; i < openmax; i++)
@@ -147,6 +179,12 @@ exec_program(struct netcf *ncf,
error:
/* This is cleanup of parent process only - child
should never jump here on error */
+ if (pipeout[0] >= 0)
+ close(pipeout[0]);
+ if (pipeout[1] >= 0)
+ close(pipeout[1]);
+ if (outfd)
+ *outfd = -1;
return -1;
}
@@ -157,20 +195,42 @@ error:
* return -1
*
*/
-int run_program(struct netcf *ncf, const char *const *argv) {
+int run_program(struct netcf *ncf, const char *const *argv, char **output)
+{
pid_t childpid;
int exitstatus, waitret;
char *argv_str;
int ret = -1;
char errbuf[128];
+ char *outtext = NULL;
+ int outfd = -1;
+ FILE *outfile = NULL;
+ size_t outlen;
+
+ if (!output)
+ output = &outtext;
argv_str = argv_to_string(argv);
ERR_NOMEM(argv_str == NULL, ncf);
- exec_program(ncf, argv, argv_str, &childpid);
+ exec_program(ncf, argv, argv_str, &childpid, &outfd);
ERR_BAIL(ncf);
+ outfile = fdopen(outfd, "r");
+ ERR_THROW(outfile == NULL, ncf, EEXEC,
+ "Failed to create file stream for stdout while executing '%s': %s",
+ argv_str, strerror_r(errno, errbuf, sizeof(errbuf)));
+
+ *output = fread_file(outfile, &outlen);
+ ERR_THROW(*output == NULL, ncf, EEXEC,
+ "Error while reading stdout from execution of '%s': %s",
+ argv_str, strerror_r(errno, errbuf, sizeof(errbuf)));
+
+ /* finished with the stream. Close it so the child can exit. */
+ fclose(outfile);
+ outfile = NULL;
+
while ((waitret = waitpid(childpid, &exitstatus, 0) == -1) &&
errno == EINTR) {
/* empty loop */
@@ -186,11 +246,16 @@ int run_program(struct netcf *ncf, const char *const *argv) {
"'%s' terminated improperly: %d",
argv_str, WEXITSTATUS(exitstatus));
ERR_THROW(WEXITSTATUS(exitstatus) != 0, ncf, EEXEC,
- "Running '%s' failed with exit code %d",
- argv_str, WEXITSTATUS(exitstatus));
+ "Running '%s' failed with exit code %d: %s",
+ argv_str, WEXITSTATUS(exitstatus), *output);
ret = 0;
error:
+ if (outfile)
+ fclose(outfile);
+ else if (outfd >= 0)
+ close(outfd);
+ FREE(outtext);
FREE(argv_str);
return ret;
}
@@ -201,7 +266,7 @@ void run1(struct netcf *ncf, const char *prog, const char *arg) {
prog, arg, NULL
};
- run_program(ncf, argv);
+ run_program(ncf, argv, NULL);
}
/*
diff --git a/src/dutil_linux.h b/src/dutil_linux.h
index 0f8b14a..91c83be 100644
--- a/src/dutil_linux.h
+++ b/src/dutil_linux.h
@@ -40,7 +40,7 @@ struct driver {
};
/* run an external program */
-int run_program(struct netcf *ncf, const char *const *argv);
+int run_program(struct netcf *ncf, const char *const *argv, char **output);
void run1(struct netcf *ncf, const char *prog, const char *arg);
/* Add a table of transformations that the next GET_AUGEAS should run */
--
1.7.3.4
12 years, 11 months
[PATCH] change sysconfdir and localstatedir during config if basedir is /usr
by Laine Stump
Usually when basedir is /usr, what we *really* want is for sysconfdir
and localstatedir to be /etc and /var, *not* /usr/etc and
/usr/var. This patch makes it that way. It can still be manually
overridden (with "--sysconfdir /usr/etc --localstatedir /usr/var") if
required.
---
configure.ac | 11 +++++++++++
1 files changed, 11 insertions(+), 0 deletions(-)
diff --git a/configure.ac b/configure.ac
index 0d0a4c7..9fd8607 100644
--- a/configure.ac
+++ b/configure.ac
@@ -46,6 +46,17 @@ AC_CHECK_HEADER([pthread.h],
LIBS="-lpthread $LIBS"
])])
+dnl if --prefix is /usr, don't use /usr/var for localstatedir
+dnl or /usr/etc for sysconfdir
+dnl as this makes a lot of things break in testing situations
+
+if test "$prefix" = "/usr" && test "$localstatedir" = '${prefix}/var' ; then
+ localstatedir='/var'
+fi
+if test "$prefix" = "/usr" && test "$sysconfdir" = '${prefix}/etc' ; then
+ sysconfdir='/etc'
+fi
+
AC_OUTPUT(Makefile \
gnulib/lib/Makefile \
gnulib/tests/Makefile \
--
1.7.3.4
12 years, 11 months
[PATCH] Remove unnecessary Requires: from netcf's pkgconfig file
by Laine Stump
This is in response to:
https://bugzilla.redhat.com/show_bug.cgi?id=662056 (Fedora)
https://bugzilla.redhat.com/show_bug.cgi?id=662057 (RHEL)
netcf.pc.in previously contained Requires for augeas, libxml, and
libxslt, but this was unnecessary - the pkgconfig file lists things
required to build an application that uses the netcf library, but
since netcf's use of those packages is purely internal/private, none
of those packages are actually required in order to build.
The solution is to remove everything from the Requires: line.
---
netcf.pc.in | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/netcf.pc.in b/netcf.pc.in
index e339266..994af13 100644
--- a/netcf.pc.in
+++ b/netcf.pc.in
@@ -6,6 +6,6 @@ includedir=@includedir@
Name: netcf
Version: @VERSION@
Description: Network configuration library
-Requires: augeas >= 0.5.0 libxml-2.0 libxslt
+Requires:
Libs: -L${libdir} -lnetcf
Cflags: -I${includedir}
--
1.7.3.4
12 years, 11 months
[PATCH] ncftool: Don't require "quit" command twice after a failed command
by Laine Stump
This is in response to: https://bugzilla.redhat.com/show_bug.cgi?id=681078
If an invalid command was entered at the ncftool prompt, and then
"quit" was immediately issued, it would be ignored - a 2nd "quit"
would be needed to exit from ncftool.
This was caused by main_loop() checking the wrong return status when
deciding to exit. Rather than checking the status of the command that
was just run, it was looking of the status of the command just prior
to that, and only exiting if that command was successful. What was
needed was to check the return status of the "quit" command (which
currently is always 0, but I suppose may change in the future.)
---
src/ncftool.c | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/ncftool.c b/src/ncftool.c
index 2cb139d..f86b62c 100644
--- a/src/ncftool.c
+++ b/src/ncftool.c
@@ -753,7 +753,7 @@ static int run_command_line(const char *line, int *cmdstatus)
static int main_loop(void) {
char *line;
- int ret;
+ int ret = 0;
while(1) {
int cmdret;
@@ -765,7 +765,7 @@ static int main_loop(void) {
}
cmdret = run_command_line(line, &cmdstatus);
- if (ret == 0 && cmdstatus == CMD_RES_QUIT)
+ if (cmdret == 0 && cmdstatus == CMD_RES_QUIT)
return ret;
add_history(line);
--
1.7.3.4
12 years, 11 months
[PATCH] Fix wording/typo in specfile
by Laine Stump
This is in response to https://bugzilla.redhat.com/show_bug.cgi?id=703318
The description in the specfile misspelled "expressed", and used an
incomplete sentence.
---
netcf.spec.in | 8 ++++----
1 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/netcf.spec.in b/netcf.spec.in
index 0da97a0..a41e49d 100644
--- a/netcf.spec.in
+++ b/netcf.spec.in
@@ -15,10 +15,10 @@ BuildRequires: libnl-devel
Requires: %{name}-libs = %{version}-%{release}
%description
-A library for modifying the network configuration of a system. Network
-configurations are expresed in a platform-independent XML format, which
-netcf translates into changes to the system's 'native' network
-configuration files.
+Netcf is a library used to modify the network configuration of a
+system. Network configurations are expressed in a platform-independent
+XML format, which netcf translates into changes to the system's
+'native' network configuration files.
%package devel
Summary: Development files for %{name}
--
1.7.3.4
12 years, 11 months