adding kexec frontend
This commit is contained in:
parent
58031ca557
commit
ea179a207a
2
Makefile
2
Makefile
@ -3,4 +3,6 @@
|
|||||||
NAME := kexec-tools
|
NAME := kexec-tools
|
||||||
SPECFILE = $(firstword $(wildcard *.spec))
|
SPECFILE = $(firstword $(wildcard *.spec))
|
||||||
|
|
||||||
|
SUBDIRS = kcp
|
||||||
|
|
||||||
include ../common/Makefile.common
|
include ../common/Makefile.common
|
||||||
|
35
Makefile.kcp
Normal file
35
Makefile.kcp
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
#
|
||||||
|
# kcp (copying date-stamped core files to filesystems)
|
||||||
|
#
|
||||||
|
|
||||||
|
KCP_C_SRCS:= kcp/kcp.c
|
||||||
|
|
||||||
|
KCP_C_OBJS:= $(patsubst %.c, $(OBJDIR)/%.o, $(KCP_C_SRCS))
|
||||||
|
KCP_C_DEPS:= $(patsubst %.c, $(OBJDIR)/%.d, $(KCP_C_SRCS))
|
||||||
|
KCP_SRCS:= $(KCP_C_SRCS)
|
||||||
|
KCP_OBJS:= $(KCP_C_OBJS)
|
||||||
|
KCP_DEPS:= $(KCP_C_DEPS)
|
||||||
|
KCP:= $(SBINDIR)/kcp
|
||||||
|
|
||||||
|
include $(KCP_DEPS)
|
||||||
|
|
||||||
|
$(KCP_C_DEPS): $(OBJDIR)/%.d: %.c
|
||||||
|
mkdir -p $(@D)
|
||||||
|
$(CC) $(CFLAGS) -M $< | sed -e 's|$(patsubst %.d,%.o,$(@F))|$(patsubst %.d,%.o,$(@))|' > $@
|
||||||
|
|
||||||
|
$(KCP_C_OBJS): $(OBJDIR)/%.o: %.c $(OBJDIR)/%.d
|
||||||
|
mkdir -p $(@D)
|
||||||
|
$(CC) $(CFLAGS) -o $@ -c $<
|
||||||
|
|
||||||
|
$(KCP): $(KCP_OBJS)
|
||||||
|
mkdir -p $(@D)
|
||||||
|
$(CC) $(CFLAGS) -o $@ $(KCP_OBJS)
|
||||||
|
|
||||||
|
echo::
|
||||||
|
@echo "KCP_C_SRCS $(KCP_C_SRCS)"
|
||||||
|
@echo "KCP_C_DEPS $(KCP_C_DEPS)"
|
||||||
|
@echo "KCP_C_OBJS $(KCP_C_OBJS)"
|
||||||
|
@echo "KCP_SRCS $(KCP_SRCS)"
|
||||||
|
@echo "KCP_DEPS $(KCP_DEPS)"
|
||||||
|
@echo "KCP_OBJS $(KCP_OBJS)"
|
||||||
|
|
204
kcp.c
Normal file
204
kcp.c
Normal file
@ -0,0 +1,204 @@
|
|||||||
|
|
||||||
|
/* Cheap program to make a variable directory first before copying contents.
|
||||||
|
* Main use is for kdump because nash does not support variables, hence a
|
||||||
|
* command sequence like the following does not work:
|
||||||
|
* date=`date ...`
|
||||||
|
* mkdir -p /x/y/$date
|
||||||
|
* cp foo /x/y/$date/bar
|
||||||
|
*
|
||||||
|
* Don Zickus (dzickus@redhat.com)
|
||||||
|
*
|
||||||
|
* Copyright 2006 Red Hat Software
|
||||||
|
*
|
||||||
|
* This software may be freely redistributed under the terms of the GNU
|
||||||
|
* General Public License, version 2.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define _GNU_SOURCE
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <strings.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#define BLOCK_SIZE 512
|
||||||
|
#define SSH_TMP ".kcp-ssh"
|
||||||
|
|
||||||
|
/* simple copy routine to copy src to dst */
|
||||||
|
int copy_core(const char *src, const char *dst)
|
||||||
|
{
|
||||||
|
int bytes, total=0;
|
||||||
|
int fd_dst, fd_src;
|
||||||
|
char buf[BLOCK_SIZE];
|
||||||
|
|
||||||
|
if ((fd_dst=open(dst,O_RDWR|O_CREAT, 0755)) < 0)
|
||||||
|
return -1;
|
||||||
|
if ((fd_src=open(src,O_RDONLY)) < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
while ((bytes=read(fd_src,buf,BLOCK_SIZE)) > 0) {
|
||||||
|
if ((bytes=write(fd_dst,buf,bytes)) < 0)
|
||||||
|
break;
|
||||||
|
total+=bytes;
|
||||||
|
}
|
||||||
|
if (bytes < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
close(fd_dst);
|
||||||
|
close(fd_src);
|
||||||
|
|
||||||
|
printf("Total bytes written: %d\n", total);
|
||||||
|
return total;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* grab the local time and replace the %DATE var with it */
|
||||||
|
char * xlate_time(const char *dst)
|
||||||
|
{
|
||||||
|
struct tm *lclnow;
|
||||||
|
time_t now;
|
||||||
|
char *new_dst,*top;
|
||||||
|
int x;
|
||||||
|
|
||||||
|
//get the time
|
||||||
|
if ((top=(char *)malloc(256)) == NULL)
|
||||||
|
return NULL;
|
||||||
|
if ((now = time(NULL)) < 1)
|
||||||
|
return NULL;
|
||||||
|
if ((lclnow = localtime(&now)) == NULL)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
//copy the easy stuff
|
||||||
|
new_dst=top;
|
||||||
|
while (*dst && (*dst != '%')) *new_dst++ = *dst++;
|
||||||
|
|
||||||
|
//translate the date part
|
||||||
|
//we output Year-Month-Day-Hour:Minute
|
||||||
|
if (*dst == '%'){
|
||||||
|
x = sprintf(new_dst,"%d-%02d-%02d-%02d:%02d", lclnow->tm_year+1900,
|
||||||
|
lclnow->tm_mon+1, lclnow->tm_mday, lclnow->tm_hour,
|
||||||
|
lclnow->tm_min);
|
||||||
|
new_dst += x;
|
||||||
|
|
||||||
|
//finish the copy
|
||||||
|
dst += 5; //skip over %DATE
|
||||||
|
while (*dst) *new_dst++ = *dst++;
|
||||||
|
}
|
||||||
|
*new_dst='\0';
|
||||||
|
|
||||||
|
return top;
|
||||||
|
}
|
||||||
|
|
||||||
|
void usage(int rc)
|
||||||
|
{
|
||||||
|
|
||||||
|
printf("usage: kcp source dest\n");
|
||||||
|
printf(" kcp --ssh dest (first time)\n");
|
||||||
|
printf(" kcp --ssh src (second time)\n");
|
||||||
|
printf("Will translate any %%DATE command properly\n");
|
||||||
|
printf("in the 'dest' variable\n");
|
||||||
|
exit(rc);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
char *src,*dst, *new_dst, *top;
|
||||||
|
char path[256];
|
||||||
|
int using_ssh=0;
|
||||||
|
char *login;
|
||||||
|
|
||||||
|
if (argc < 3)
|
||||||
|
usage(1);
|
||||||
|
|
||||||
|
if (!strncmp(argv[1], "--ssh", 5))
|
||||||
|
using_ssh=1;
|
||||||
|
else
|
||||||
|
src=argv[1];
|
||||||
|
|
||||||
|
dst=argv[2];
|
||||||
|
|
||||||
|
if ((new_dst=xlate_time(dst)) == NULL){
|
||||||
|
printf("Failed to translate time\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
top=new_dst;
|
||||||
|
|
||||||
|
//Hack for ssh because nash doesn't support variables
|
||||||
|
//The idea here is to save the translated date to a file to
|
||||||
|
//be read back later for scp
|
||||||
|
if (using_ssh){
|
||||||
|
int fd_dst, x;
|
||||||
|
|
||||||
|
if ((fd_dst=open(SSH_TMP, O_RDWR|O_CREAT, 0755)) < 0){
|
||||||
|
perror("Failed to open SSH_TMP: ");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
if ((x=read(fd_dst, path, BLOCK_SIZE)) > 0){
|
||||||
|
//second time around
|
||||||
|
src=dst;
|
||||||
|
path[x]='\0';
|
||||||
|
close(fd_dst);
|
||||||
|
remove(SSH_TMP);
|
||||||
|
execlp("scp", "scp", "-q", "-o", "BatchMode=yes", "-o",
|
||||||
|
"StrictHostKeyChecking=no", src, path, NULL);
|
||||||
|
//should never return!!
|
||||||
|
perror("Failed to scp: ");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
//save data for next run of this program
|
||||||
|
printf("writing <%s> to file %s\n",top, SSH_TMP);
|
||||||
|
if ((write(fd_dst, top, strlen(top))) < 0){
|
||||||
|
perror("Failed to write to SSH_TMP: ");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
close(fd_dst);
|
||||||
|
|
||||||
|
//save the login info
|
||||||
|
login=top;
|
||||||
|
if ((top=index(login, ':')) == NULL){
|
||||||
|
printf("Bad ssh format %s\n", path);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
*top++='\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
//find the directory portion and separate it from the file
|
||||||
|
if ((new_dst=rindex(top, '/')) == NULL){
|
||||||
|
new_dst=top; //strange but okay, only the file passed in
|
||||||
|
sprintf(path,"%s",new_dst);
|
||||||
|
}else{
|
||||||
|
*new_dst='\0';
|
||||||
|
new_dst++;
|
||||||
|
|
||||||
|
//finish the ssh hack by running mkdir
|
||||||
|
if (using_ssh){
|
||||||
|
execlp("ssh", "ssh", "-q", "-o", "BatchMode=yes", "-o",
|
||||||
|
"StrictHostKeyChecking=no", login, "mkdir", "-p",
|
||||||
|
top, NULL);
|
||||||
|
//should never return!!
|
||||||
|
perror("Failed to ssh: ");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
//make the new directory
|
||||||
|
if ((mkdir(top, 0777)) != 0){
|
||||||
|
perror("mkdir failed: ");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
sprintf(path,"%s/%s",top,new_dst);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (copy_core(src,path) < 0){
|
||||||
|
perror("Failed to write core file: ");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
24
kdump.conf
Normal file
24
kdump.conf
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
# Configures where to put the kdump /proc/vmcore files
|
||||||
|
#
|
||||||
|
# This file contains a series of commands to perform (in order) when a
|
||||||
|
# kernel crash has happened and the kdump kernel has been loaded
|
||||||
|
#
|
||||||
|
# The commands are chained together to allow redundancy in case the
|
||||||
|
# primary choice is not available at crash time
|
||||||
|
#
|
||||||
|
# Basics commands supported are:
|
||||||
|
# raw <partition> - will dd /proc/vmcore into <partition>
|
||||||
|
# net <nfs mount> - will mount fs and copy /proc/vmcore to
|
||||||
|
# <mnt>/var/crash/%DATE/ , supports DNS
|
||||||
|
# net <ssh user@location> - will scp /proc/vmcore to
|
||||||
|
# <user@location>:/var/crash/%DATE/, supports DNS
|
||||||
|
# <fs type> - will mount -t <fs type> /mnt and copy /proc/vmcore to
|
||||||
|
# /mnt/var/crash/%DATE/
|
||||||
|
# default reboot - if all of the above fail, then reboot the system
|
||||||
|
# and accept the /proc/vmcore is lost, else
|
||||||
|
# comment out 'default' to fall through and fix
|
||||||
|
# the system (if the disk is available)
|
||||||
|
|
||||||
|
#raw /dev/sda5
|
||||||
|
#ext3 /dev/sda3
|
||||||
|
#default reboot
|
@ -1,12 +1,16 @@
|
|||||||
Name: kexec-tools
|
Name: kexec-tools
|
||||||
Version: 1.101
|
Version: 1.101
|
||||||
Release: 29%{dist}.1
|
Release: 30%{dist}.1
|
||||||
License: GPL
|
License: GPL
|
||||||
Group: Applications/System
|
Group: Applications/System
|
||||||
Summary: The kexec/kdump userspace component.
|
Summary: The kexec/kdump userspace component.
|
||||||
Source0: %{name}-%{version}.tar.gz
|
Source0: %{name}-%{version}.tar.gz
|
||||||
Source1: kdump.init
|
Source1: kdump.init
|
||||||
Source2: kdump.sysconfig
|
Source2: kdump.sysconfig
|
||||||
|
Source3: mkdumprd
|
||||||
|
Source4: kdump.conf
|
||||||
|
Source5: kcp.c
|
||||||
|
Source6: Makefile.kcp
|
||||||
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-buildroot
|
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-buildroot
|
||||||
Requires(pre): coreutils chkconfig sed
|
Requires(pre): coreutils chkconfig sed
|
||||||
BuildRequires: zlib-devel
|
BuildRequires: zlib-devel
|
||||||
@ -45,6 +49,7 @@ Patch501: kexec-tools-1.101-ppc-fixup.patch
|
|||||||
# Patches 601 onward are generic patches
|
# Patches 601 onward are generic patches
|
||||||
#
|
#
|
||||||
Patch601: kexec-tools-1.101-Makefile.patch
|
Patch601: kexec-tools-1.101-Makefile.patch
|
||||||
|
Patch602: kexec-tools-1.101-Makefile-kcp.patch
|
||||||
|
|
||||||
%description
|
%description
|
||||||
kexec-tools provides /sbin/kexec binary that facilitates a new
|
kexec-tools provides /sbin/kexec binary that facilitates a new
|
||||||
@ -63,9 +68,15 @@ rm -f ../kexec-tools-1.101.spec
|
|||||||
%patch401 -p1
|
%patch401 -p1
|
||||||
%patch501 -p1
|
%patch501 -p1
|
||||||
%patch601 -p1
|
%patch601 -p1
|
||||||
|
%patch602 -p1
|
||||||
|
|
||||||
cp $RPM_SOURCE_DIR/kdump.init .
|
cp $RPM_SOURCE_DIR/kdump.init .
|
||||||
cp $RPM_SOURCE_DIR/kdump.sysconfig .
|
cp $RPM_SOURCE_DIR/kdump.sysconfig .
|
||||||
|
cp $RPM_SOURCE_DIR/kdump.conf .
|
||||||
|
cp $RPM_SOURCE_DIR/mkdumprd .
|
||||||
|
mkdir -p -m755 kcp
|
||||||
|
cp $RPM_SOURCE_DIR/kcp.c kcp/kcp.c
|
||||||
|
cp $RPM_SOURCE_DIR/Makefile.kcp kcp/Makefile
|
||||||
|
|
||||||
%build
|
%build
|
||||||
%configure --sbindir=/sbin
|
%configure --sbindir=/sbin
|
||||||
@ -79,11 +90,14 @@ mkdir -p -m755 $RPM_BUILD_ROOT/etc/rc.d/init.d
|
|||||||
mkdir -p -m755 $RPM_BUILD_ROOT/etc/sysconfig
|
mkdir -p -m755 $RPM_BUILD_ROOT/etc/sysconfig
|
||||||
install -m 644 kdump.sysconfig $RPM_BUILD_ROOT/etc/sysconfig/kdump
|
install -m 644 kdump.sysconfig $RPM_BUILD_ROOT/etc/sysconfig/kdump
|
||||||
install -m 755 kdump.init $RPM_BUILD_ROOT/etc/rc.d/init.d/kdump
|
install -m 755 kdump.init $RPM_BUILD_ROOT/etc/rc.d/init.d/kdump
|
||||||
|
install -m 755 mkdumprd $RPM_BUILD_ROOT/sbin/mkdumprd
|
||||||
|
install -m 755 kdump.conf $RPM_BUILD_ROOT/etc/kdump.conf
|
||||||
|
|
||||||
%clean
|
%clean
|
||||||
rm -rf $RPM_BUILD_ROOT
|
rm -rf $RPM_BUILD_ROOT
|
||||||
|
|
||||||
%post
|
%post
|
||||||
|
touch /etc/kdump.conf
|
||||||
/sbin/chkconfig --add kdump
|
/sbin/chkconfig --add kdump
|
||||||
|
|
||||||
%postun
|
%postun
|
||||||
@ -103,6 +117,7 @@ exit 0
|
|||||||
%defattr(-,root,root,-)
|
%defattr(-,root,root,-)
|
||||||
/sbin/*
|
/sbin/*
|
||||||
%config(noreplace,missingok) /etc/sysconfig/kdump
|
%config(noreplace,missingok) /etc/sysconfig/kdump
|
||||||
|
%config(noreplace,missingok) /etc/kdump.conf
|
||||||
%config /etc/rc.d/init.d/kdump
|
%config /etc/rc.d/init.d/kdump
|
||||||
%ifarch %{ix86} x86_64
|
%ifarch %{ix86} x86_64
|
||||||
%{_libdir}/kexec-tools/kexec_test
|
%{_libdir}/kexec-tools/kexec_test
|
||||||
@ -112,6 +127,9 @@ exit 0
|
|||||||
%doc TODO
|
%doc TODO
|
||||||
|
|
||||||
%changelog
|
%changelog
|
||||||
|
* Wed Jul 19 2006 Neil Horman <nhorman@redhat.com> - 1.101-30%{dist}.1
|
||||||
|
-add kexec frontend (bz 197695)
|
||||||
|
|
||||||
* Wed Jul 12 2006 Jesse Keating <jkeating@redhat.com> - 1.101-29%{dist}.1
|
* Wed Jul 12 2006 Jesse Keating <jkeating@redhat.com> - 1.101-29%{dist}.1
|
||||||
- rebuild
|
- rebuild
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user