updating kexec-tools with new kcp utiltiy
This commit is contained in:
parent
afa62db75a
commit
3060ffe3d7
190
kcp.c
190
kcp.c
@ -30,36 +30,6 @@
|
|||||||
#include <strings.h>
|
#include <strings.h>
|
||||||
#include <string.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 */
|
/* grab the local time and replace the %DATE var with it */
|
||||||
char * xlate_time(const char *dst)
|
char * xlate_time(const char *dst)
|
||||||
{
|
{
|
||||||
@ -101,8 +71,8 @@ void usage(int rc)
|
|||||||
{
|
{
|
||||||
|
|
||||||
printf("usage: kcp source dest\n");
|
printf("usage: kcp source dest\n");
|
||||||
printf(" kcp --ssh dest (first time)\n");
|
printf(" kcp --ssh src user@host:/dst\n");
|
||||||
printf(" kcp --ssh src (second time)\n");
|
printf(" kcp --local src dst\n");
|
||||||
printf("Will translate any %%DATE command properly\n");
|
printf("Will translate any %%DATE command properly\n");
|
||||||
printf("in the 'dest' variable\n");
|
printf("in the 'dest' variable\n");
|
||||||
exit(rc);
|
exit(rc);
|
||||||
@ -110,95 +80,103 @@ void usage(int rc)
|
|||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
char *src,*dst, *new_dst, *top;
|
char *src, *dst, *new_dst, *ptr;
|
||||||
char path[256];
|
char *path;
|
||||||
int using_ssh=0;
|
int using_ssh=0;
|
||||||
char *login;
|
char *login;
|
||||||
|
int status;
|
||||||
|
pid_t child;
|
||||||
|
|
||||||
if (argc < 3)
|
if (argc < 4)
|
||||||
usage(1);
|
usage(1);
|
||||||
|
|
||||||
if (!strncmp(argv[1], "--ssh", 5))
|
src = argv[2];
|
||||||
using_ssh=1;
|
dst = argv[3];
|
||||||
else
|
|
||||||
src=argv[1];
|
|
||||||
|
|
||||||
dst=argv[2];
|
|
||||||
|
|
||||||
if ((new_dst=xlate_time(dst)) == NULL){
|
if ((new_dst=xlate_time(dst)) == NULL){
|
||||||
printf("Failed to translate time\n");
|
printf("Failed to translate time\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
top=new_dst;
|
|
||||||
|
if (!strcmp(argv[1], "--ssh"))
|
||||||
|
using_ssh =1;
|
||||||
|
|
||||||
//Hack for ssh because nash doesn't support variables
|
/*
|
||||||
//The idea here is to save the translated date to a file to
|
* Now that we have called xlate_time, new_dst
|
||||||
//be read back later for scp
|
* holds the expanded ssh destination
|
||||||
if (using_ssh){
|
*/
|
||||||
int fd_dst, x;
|
if (using_ssh) {
|
||||||
|
login=strdup(new_dst);
|
||||||
if ((fd_dst=open(SSH_TMP, O_RDWR|O_CREAT, 0755)) < 0){
|
ptr=index(login, ':');
|
||||||
perror("Failed to open SSH_TMP: ");
|
*ptr++='\0';
|
||||||
exit(1);
|
path = ptr;
|
||||||
}
|
} else {
|
||||||
if ((x=read(fd_dst, path, BLOCK_SIZE)) > 0){
|
login = NULL;
|
||||||
//second time around
|
path = new_dst;
|
||||||
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){
|
*this makes our target directory
|
||||||
new_dst=top; //strange but okay, only the file passed in
|
*/
|
||||||
sprintf(path,"%s",new_dst);
|
if ((child = fork()) == 0) {
|
||||||
}else{
|
/*
|
||||||
*new_dst='\0';
|
* child
|
||||||
new_dst++;
|
*/
|
||||||
|
if (using_ssh) {
|
||||||
//finish the ssh hack by running mkdir
|
if (execlp("ssh", "ssh", "-q", "-o", "BatchMode=yes", "-o",
|
||||||
if (using_ssh){
|
"StrictHostKeyChecking=no", login, "mkdir", "-p",
|
||||||
execlp("ssh", "ssh", "-q", "-o", "BatchMode=yes", "-o",
|
path, NULL) < 0) {
|
||||||
"StrictHostKeyChecking=no", login, "mkdir", "-p",
|
perror("Failed to run ssh");
|
||||||
top, NULL);
|
exit(1);
|
||||||
//should never return!!
|
}
|
||||||
perror("Failed to ssh: ");
|
} else {
|
||||||
|
if (execlp("mkdir", "mkdir", "-p", path, NULL) < 0) {
|
||||||
|
perror("Failed to run mkdir");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
/*
|
||||||
|
* parent
|
||||||
|
*/
|
||||||
|
if (child < 0) {
|
||||||
|
perror("Could not fork");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
//make the new directory
|
wait(&status);
|
||||||
if ((mkdir(top, 0777)) != 0){
|
if (WEXITSTATUS(status) != 0) {
|
||||||
perror("mkdir failed: ");
|
printf ("%s exited abnormally: error = %d\n",
|
||||||
|
using_ssh ? "ssh":"mkdir", WEXITSTATUS(status));
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* now that we have our directory, lets copy everything over
|
||||||
|
* Note that scp can be used for local copies as well
|
||||||
|
*/
|
||||||
|
if ((child = fork()) == 0) {
|
||||||
|
/*need to include login info if scp to remote host*/
|
||||||
|
if (using_ssh)
|
||||||
|
path=new_dst;
|
||||||
|
src, path;
|
||||||
|
if (execlp("scp", "scp", "-q", "-o", "BatchMode=yes", "-o",
|
||||||
|
"StrictHostKeyChecking=no", src, path, NULL) < 0) {
|
||||||
|
perror("Failed to run scp\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (child < 0) {
|
||||||
|
perror("Could not fork");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
wait(&status);
|
||||||
|
if (WEXITSTATUS(status) != 0) {
|
||||||
|
printf("scp exited abnormally: error = %d\n",
|
||||||
|
WEXITSTATUS(status));
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
sprintf(path,"%s/%s",top,new_dst);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (copy_core(src,path) < 0){
|
exit(0);
|
||||||
perror("Failed to write core file: ");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
Name: kexec-tools
|
Name: kexec-tools
|
||||||
Version: 1.101
|
Version: 1.101
|
||||||
Release: 48%{?dist}
|
Release: 49%{?dist}
|
||||||
License: GPL
|
License: GPL
|
||||||
Group: Applications/System
|
Group: Applications/System
|
||||||
Summary: The kexec/kdump userspace component.
|
Summary: The kexec/kdump userspace component.
|
||||||
@ -157,7 +157,11 @@ exit 0
|
|||||||
%doc TODO
|
%doc TODO
|
||||||
|
|
||||||
%changelog
|
%changelog
|
||||||
* Wed Aug 23 2006 Neil Horman <nhorman@redhat.com> - 1.101-47%{dist}
|
* Thu Aug 24 2006 Neil Horman <nhorman@redhat.com> - 1.101-49%{dist}
|
||||||
|
- rewriting kcp to properly do ssh and scp
|
||||||
|
- updating mkdumprd to use new kcp syntax
|
||||||
|
|
||||||
|
* Wed Aug 23 2006 Neil Horman <nhorman@redhat.com> - 1.101-48%{dist}
|
||||||
- Bumping revision number
|
- Bumping revision number
|
||||||
|
|
||||||
* Tue Aug 22 2006 Jarod Wilson <jwilson@redhat.com> - 1.101-47%{dist}
|
* Tue Aug 22 2006 Jarod Wilson <jwilson@redhat.com> - 1.101-47%{dist}
|
||||||
|
7
mkdumprd
7
mkdumprd
@ -1093,7 +1093,7 @@ if [ -n "$KDUMP_CONFIG_FILE" ]; then
|
|||||||
#setup nfs case
|
#setup nfs case
|
||||||
mkdir -p $MNTIMAGE/mnt
|
mkdir -p $MNTIMAGE/mnt
|
||||||
emit "mount -t nfs -o nolock $rlocation /mnt"
|
emit "mount -t nfs -o nolock $rlocation /mnt"
|
||||||
emit "cond kcp /proc/vmcore /mnt/var/crash/$lhost-%DATE/vmcore"
|
emit "cond kcp --local /proc/vmcore /mnt/var/crash/$lhost-%DATE/vmcore"
|
||||||
emit "cond reboot -h -f"
|
emit "cond reboot -h -f"
|
||||||
else
|
else
|
||||||
#SSH path
|
#SSH path
|
||||||
@ -1123,8 +1123,7 @@ if [ -n "$KDUMP_CONFIG_FILE" ]; then
|
|||||||
emit "mknod /dev/urandom c 1 9"
|
emit "mknod /dev/urandom c 1 9"
|
||||||
fi
|
fi
|
||||||
emit "dd if=/dev/mem of=/dev/urandom count=1 bs=512 skip=100"
|
emit "dd if=/dev/mem of=/dev/urandom count=1 bs=512 skip=100"
|
||||||
emit "cond kcp --ssh $rlocation:/var/crash/$lhost-%DATE/vmcore"
|
emit "cond kcp --ssh /proc/vmcore $rlocation:/var/crash/$lhost-%DATE/vmcore"
|
||||||
emit "cond kcp --ssh /proc/vmcore"
|
|
||||||
emit "cond reboot -h -f"
|
emit "cond reboot -h -f"
|
||||||
bin="$bin /usr/bin/scp /usr/bin/ssh /bin/dd"
|
bin="$bin /usr/bin/scp /usr/bin/ssh /bin/dd"
|
||||||
|
|
||||||
@ -1157,7 +1156,7 @@ if [ -n "$KDUMP_CONFIG_FILE" ]; then
|
|||||||
emit "echo Saving to the local filesystem $location"
|
emit "echo Saving to the local filesystem $location"
|
||||||
emit "fsck.$type $location"
|
emit "fsck.$type $location"
|
||||||
emit "cond mount -t $type $location /mnt"
|
emit "cond mount -t $type $location /mnt"
|
||||||
emit "cond kcp /proc/vmcore /mnt/var/crash/$lhost-%DATE/vmcore"
|
emit "cond kcp --local /proc/vmcore /mnt/var/crash/$lhost-%DATE/vmcore"
|
||||||
emit "cond umount /mnt"
|
emit "cond umount /mnt"
|
||||||
emit "cond reboot -h -f"
|
emit "cond reboot -h -f"
|
||||||
bin="$bin /sbin/fsck.$type /bin/mount"
|
bin="$bin /sbin/fsck.$type /bin/mount"
|
||||||
|
Loading…
Reference in New Issue
Block a user