rpms/kexec-tools/devel kcp.c, 1.2, 1.3 kexec-tools.spec, 1.58, 1.59 mkdumprd, 1.3, 1.4
fedora-cvs-commits at redhat.com
fedora-cvs-commits at redhat.com
Thu Aug 24 11:55:30 UTC 2006
Author: nhorman
Update of /cvs/dist/rpms/kexec-tools/devel
In directory cvs.devel.redhat.com:/tmp/cvs-serv10666
Modified Files:
kcp.c kexec-tools.spec mkdumprd
Log Message:
updating kexec-tools with new kcp utiltiy
Index: kcp.c
===================================================================
RCS file: /cvs/dist/rpms/kexec-tools/devel/kcp.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- kcp.c 20 Jul 2006 03:36:18 -0000 1.2
+++ kcp.c 24 Aug 2006 11:55:28 -0000 1.3
@@ -30,36 +30,6 @@
#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)
{
@@ -101,8 +71,8 @@
{
printf("usage: kcp source dest\n");
- printf(" kcp --ssh dest (first time)\n");
- printf(" kcp --ssh src (second time)\n");
+ printf(" kcp --ssh src user at host:/dst\n");
+ printf(" kcp --local src dst\n");
printf("Will translate any %%DATE command properly\n");
printf("in the 'dest' variable\n");
exit(rc);
@@ -110,95 +80,103 @@
int main(int argc, char *argv[])
{
- char *src,*dst, *new_dst, *top;
- char path[256];
+ char *src, *dst, *new_dst, *ptr;
+ char *path;
int using_ssh=0;
char *login;
+ int status;
+ pid_t child;
- if (argc < 3)
+ if (argc < 4)
usage(1);
- if (!strncmp(argv[1], "--ssh", 5))
- using_ssh=1;
- else
- src=argv[1];
-
- dst=argv[2];
-
+ src = argv[2];
+ dst = argv[3];
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: ");
+ if (!strcmp(argv[1], "--ssh"))
+ using_ssh =1;
+
+ /*
+ * Now that we have called xlate_time, new_dst
+ * holds the expanded ssh destination
+ */
+ if (using_ssh) {
+ login=strdup(new_dst);
+ ptr=index(login, ':');
+ *ptr++='\0';
+ path = ptr;
+ } else {
+ login = NULL;
+ path = new_dst;
+ }
+
+ /*
+ *this makes our target directory
+ */
+ if ((child = fork()) == 0) {
+ /*
+ * child
+ */
+ if (using_ssh) {
+ if (execlp("ssh", "ssh", "-q", "-o", "BatchMode=yes", "-o",
+ "StrictHostKeyChecking=no", login, "mkdir", "-p",
+ path, NULL) < 0) {
+ perror("Failed to run ssh");
+ exit(1);
+ }
+ } 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);
+ }
+ wait(&status);
+ if (WEXITSTATUS(status) != 0) {
+ 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);
}
- sprintf(path,"%s/%s",top,new_dst);
}
-
- if (copy_core(src,path) < 0){
- perror("Failed to write core file: ");
- exit(1);
- }
-
- return 0;
+
+ exit(0);
}
Index: kexec-tools.spec
===================================================================
RCS file: /cvs/dist/rpms/kexec-tools/devel/kexec-tools.spec,v
retrieving revision 1.58
retrieving revision 1.59
diff -u -r1.58 -r1.59
--- kexec-tools.spec 23 Aug 2006 20:27:56 -0000 1.58
+++ kexec-tools.spec 24 Aug 2006 11:55:28 -0000 1.59
@@ -1,6 +1,6 @@
Name: kexec-tools
Version: 1.101
-Release: 48%{?dist}
+Release: 49%{?dist}
License: GPL
Group: Applications/System
Summary: The kexec/kdump userspace component.
@@ -157,7 +157,11 @@
%doc TODO
%changelog
-* Wed Aug 23 2006 Neil Horman <nhorman at redhat.com> - 1.101-47%{dist}
+* Thu Aug 24 2006 Neil Horman <nhorman at 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 at redhat.com> - 1.101-48%{dist}
- Bumping revision number
* Tue Aug 22 2006 Jarod Wilson <jwilson at redhat.com> - 1.101-47%{dist}
Index: mkdumprd
===================================================================
RCS file: /cvs/dist/rpms/kexec-tools/devel/mkdumprd,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- mkdumprd 18 Aug 2006 17:00:45 -0000 1.3
+++ mkdumprd 24 Aug 2006 11:55:28 -0000 1.4
@@ -1093,7 +1093,7 @@
#setup nfs case
mkdir -p $MNTIMAGE/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"
else
#SSH path
@@ -1123,8 +1123,7 @@
emit "mknod /dev/urandom c 1 9"
fi
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"
+ emit "cond kcp --ssh /proc/vmcore $rlocation:/var/crash/$lhost-%DATE/vmcore"
emit "cond reboot -h -f"
bin="$bin /usr/bin/scp /usr/bin/ssh /bin/dd"
@@ -1157,7 +1156,7 @@
emit "echo Saving to the local filesystem $location"
emit "fsck.$type $location"
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 reboot -h -f"
bin="$bin /sbin/fsck.$type /bin/mount"
More information about the fedora-cvs-commits
mailing list