From: Jason U. <jas...@sg...> - 2006-03-27 14:15:37
|
This makes savedump save a copy of Kerntypes in /var/log/dump like the old /sbin/lkcd script did. It also makes us save /boot/System.map-`uname -r` (which is also what /sbin/lkcd used to do) instead of /boot/System.map. Not all distros provide the symlink for us. Index: lkcd/7.X.X/lkcdutils/dumputils/savedump.c =================================================================== --- lkcd.orig/7.X.X/lkcdutils/dumputils/savedump.c 2006-01-11 11:19:24.000000000 -0800 +++ lkcd/7.X.X/lkcdutils/dumputils/savedump.c 2006-03-27 06:06:10.842743983 -0800 @@ -169,12 +169,20 @@ copy_map(struct confInfo *conf, int bounds) { char *smname; + char srcname[NAME_MAX]; FILE *dfd=NULL, *fp=NULL; + struct utsname utsbuf; char line[255], *fuser=NULL, *fpass=NULL; int err=0; disconnect(); + if (uname(&utsbuf) < 0) { + perror("uname"); + exit(EXIT_FAILURE); + } + sprintf(srcname, "/boot/System.map-%s", utsbuf.release); + if(conf->ftp){ if(conf->path == NULL){ @@ -221,14 +229,14 @@ return 39; } - if((fp = fopen("/boot/System.map", "r")) != NULL){ + if((fp = fopen(srcname, "r")) != NULL){ while (fgets(line,sizeof(line),fp) != NULL) { fprintf(dfd, "%s", line); } fflush(dfd); }else{ - fprintf(stderr, "Couldn't open /boot/System.map!\n"); + fprintf(stderr, "Couldn't open %s!\n", srcname); free(fuser); free(fpass); free(smname); @@ -276,14 +284,14 @@ return 81; } - if((fp = fopen("/boot/System.map", "r")) != NULL){ + if((fp = fopen(srcname, "r")) != NULL){ while (fgets(line,sizeof(line),fp) != NULL) { fprintf(dfd, "%s", line); } fflush(dfd); }else{ - fprintf(stderr, "Couldn't open /boot/System.map\n"); + fprintf(stderr, "Couldn't open %s\n", srcname); free(smname); disconnect(); return 82; @@ -302,6 +310,122 @@ } + +int +copy_kerntypes(struct confInfo *conf, int bounds) +{ + char srcname[NAME_MAX], dstname[NAME_MAX]; + struct utsname utsbuf; + FILE *dfd=NULL, *fp=NULL; + char *fuser, *fpass; + char buf[512]; + int n; + int err=0; + + disconnect(); + + if (uname(&utsbuf) < 0) { + perror("uname"); + exit(EXIT_FAILURE); + } + sprintf(srcname, "/boot/Kerntypes-%s", utsbuf.release); + +#ifdef DEBUG + printf("Kerntypes file name: %s\n", dstname); +#endif + + if(conf->ftp){ + if (conf->path) + sprintf(dstname, "%s/%d/kerntypes.%d", conf->path, bounds, bounds); + else + sprintf(dstname, "%d/kerntypes.%d", bounds, bounds); + + if ((fuser=(char *)malloc(strlen(conf->user)+7)) == NULL) { + perror("FATAL ERROR: Couldn't allocate enough memory"); + exit(10); + } + + if ((fpass=(char *)malloc(strlen(conf->pass)+7)) == NULL) { + perror("FATAL ERROR: Couldn't allocate enough memory"); + exit(10); + } + + sprintf(fuser, "USER %s", conf->user); + sprintf(fpass, "PASS %s", conf->pass); + + if ( ((err = FTPConnect(conf->host, fuser, fpass)) < 0) ){ + fprintf(stderr, "Could not connect to server!\n"); + free(fuser); + free(fpass); + exit(err); + } + + dfd = do_open(dstname); + if (!dfd) { + fprintf(stderr, "Could not create file!\n"); + free(fuser); + free(fpass); + disconnect(); + return 39; + } + + fopen(srcname, "r"); + if (!fp) { + fprintf(stderr, "Couldn't open %s!\n", srcname); + free(fuser); + free(fpass); + disconnect(); + return 82; + } + + while ((n = fread(buf, sizeof(buf), 1, fp))) + fwrite(buf, n, 1, fp); + +#ifdef DEBUG + printf("Wrote Kerntypes: %s\n", ktname); +#endif + + fflush(dfd); + fclose(fp); + free(fuser); + free(fpass); + disconnect(); + + return 0; + + } else { /* not ftp */ + if (conf->dir) + sprintf(dstname, "%s/%d/kerntypes.%d", conf->dir, bounds, bounds); + else + sprintf(dstname, "%d/kerntypes.%d", bounds, bounds); + + if ((dfd = fopen(dstname, "w")) == NULL) { + perror("Error opening destination kerntypes file"); + return 81; + } + + fp = fopen(srcname, "r"); + if (!fp) { + fprintf(stderr, "Couldn't open %s\n", srcname); + disconnect(); + return 82; + } + + while ((n = fread(buf, 1, sizeof(buf), fp))) + fwrite(buf, 1, n, dfd); + +#ifdef DEBUG + printf("Wrote kerntypes file: %s\n", dstname); +#endif + + fflush(dfd); + fclose(fp); + fclose(dfd); + return 0; + } +} + + // create a bounds file. // int @@ -1486,5 +1610,12 @@ printf("Successfully wrote System.map\n"); + if ( (i=copy_kerntypes(conf, bounds)) < 0) { + fprintf(stderr, "Error while copying Kerntypes\n"); + exit (i); + } + + printf("Successfully wrote Kerntypes\n"); + return 0; } //end main Index: lkcd/7.X.X/lkcdutils/dumputils/savedump.h =================================================================== --- lkcd.orig/7.X.X/lkcdutils/dumputils/savedump.h 2005-06-01 12:13:02.000000000 -0700 +++ lkcd/7.X.X/lkcdutils/dumputils/savedump.h 2006-03-27 06:06:10.842743983 -0800 @@ -37,6 +37,8 @@ #include <sys/types.h> #include <fcntl.h> #include <string.h> +#include <limits.h> +#include <sys/utsname.h> #define DUMP_BUFFER_SIZE (64 * 1024) #define DUMP_HEADER_SIZE DUMP_BUFFER_SIZE |