Changeset 2323 in MondoRescue for branches/2.2.10/mondo/src/common/libmondo-files.c
- Timestamp:
- Aug 18, 2009, 3:05:43 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.2.10/mondo/src/common/libmondo-files.c
r2321 r2323 62 62 assert_string_is_neither_NULL_nor_zerolength(filename); 63 63 if (does_file_exist(filename)) { 64 mr_asprintf( &command, "md5sum \"%s\"", filename);64 mr_asprintf(command, "md5sum \"%s\"", filename); 65 65 fin = popen(command, "r"); 66 66 if (fin) { … … 71 71 mr_free(command); 72 72 } else { 73 mr_asprintf( &tmp, "File '%s' not found; cannot calc checksum", filename);73 mr_asprintf(tmp, "File '%s' not found; cannot calc checksum", filename); 74 74 log_it(tmp); 75 75 mr_free(tmp); … … 142 142 assert_string_is_neither_NULL_nor_zerolength(filename); 143 143 if (!does_file_exist(filename)) { 144 mr_asprintf( &tmp, "%s does not exist, so I cannot found the number of lines in it", filename);144 mr_asprintf(tmp, "%s does not exist, so I cannot found the number of lines in it", filename); 145 145 log_it(tmp); 146 146 mr_free(tmp); 147 147 return (0); 148 148 } 149 mr_asprintf( &command, "cat %s | wc -l", filename);149 mr_asprintf(command, "cat %s | wc -l", filename); 150 150 if (!does_file_exist(filename)) { 151 151 mr_free(command); … … 224 224 225 225 assert_string_is_neither_NULL_nor_zerolength(inout); 226 mr_asprintf( &infname, "%s.in", inout);227 mr_asprintf( &outfname, "%s", inout);228 mr_asprintf( &tmp, "cp -f %s %s", inout, infname);226 mr_asprintf(infname, "%s.in", inout); 227 mr_asprintf(outfname, "%s", inout); 228 mr_asprintf(tmp, "cp -f %s %s", inout, infname); 229 229 run_program_and_log_output(tmp, FALSE); 230 230 mr_free(tmp); … … 251 251 fprintf(fout, "%s\n", incoming); 252 252 } else { 253 mr_asprintf( &tmp, "Excluding '%s'-nonexistent\n", incoming);253 mr_asprintf(tmp, "Excluding '%s'-nonexistent\n", incoming); 254 254 log_it(tmp); 255 255 mr_free(tmp); … … 289 289 // If we didn't get anything back, check whether mindi raised a fatal error 290 290 if (!kernel[0]) { 291 mr_asprintf( &command, "%s", "grep 'Fatal error' /var/log/mindi.log");292 mr_asprintf( &tmp, "%s", call_program_and_get_last_line_of_output(command));291 mr_asprintf(command, "%s", "grep 'Fatal error' /var/log/mindi.log"); 292 mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command)); 293 293 if (strlen(tmp) > 1) { 294 294 popup_and_OK(tmp); … … 344 344 345 345 assert_string_is_neither_NULL_nor_zerolength(fname); 346 mr_asprintf( &command, "which %s 2> /dev/null", fname);346 mr_asprintf(command, "which %s 2> /dev/null", fname); 347 347 strcpy(incoming, call_program_and_get_last_line_of_output(command)); 348 348 mr_free(command); … … 353 353 return (NULL); // forget it :) 354 354 } 355 mr_asprintf( &command, "file %s 2> /dev/null | cut -d':' -f1 2> /dev/null", incoming);355 mr_asprintf(command, "file %s 2> /dev/null | cut -d':' -f1 2> /dev/null", incoming); 356 356 strcpy(incoming, 357 357 call_program_and_get_last_line_of_output(command)); … … 360 360 if (incoming[0] == '\0') // yes, it is == '\0' twice, not once :) 361 361 { 362 mr_asprintf( &command, "dirname %s 2> /dev/null", incoming);362 mr_asprintf(command, "dirname %s 2> /dev/null", incoming); 363 363 strcpy(incoming, 364 364 call_program_and_get_last_line_of_output(command)); … … 452 452 && !strstr(err_log_lines[i], "% done"); i--); 453 453 if (i < 0) { 454 mr_asprintf( &command, "tail -n3 %s | grep -Fi \"%c\" | tail -n1 | awk '{print $0;}'", filename, '%');454 mr_asprintf(command, "tail -n3 %s | grep -Fi \"%c\" | tail -n1 | awk '{print $0;}'", filename, '%'); 455 455 strcpy(lastline, 456 456 call_program_and_get_last_line_of_output(command)); … … 503 503 504 504 if (!does_file_exist(filename)) { 505 mr_asprintf( &tmp, "Tring to get last line of nonexistent file (%s)", filename);505 mr_asprintf(tmp, "Tring to get last line of nonexistent file (%s)", filename); 506 506 log_it(tmp); 507 507 mr_free(tmp); … … 509 509 return (output); 510 510 } 511 mr_asprintf( &command, "tail -n1 %s", filename);511 mr_asprintf(command, "tail -n1 %s", filename); 512 512 fin = popen(command, "r"); 513 513 mr_free(command); … … 602 602 stub_fname[i] = '\0'; 603 603 } 604 mr_asprintf( &tmp, "%s%s", comppath, stub_fname);604 mr_asprintf(tmp, "%s%s", comppath, stub_fname); 605 605 strcpy(curr_fname, tmp + 1); 606 606 mr_free(tmp); … … 620 620 time_remaining = 621 621 time_taken * 100 / (long) (percentage) - time_taken; 622 mr_asprintf( &tmp, "%02d%% done %02d:%02d taken %02d:%02d remaining %-37s\r", percentage, (int) (time_taken / 60), (int) (time_taken % 60), (int) (time_remaining / 60), (int) (time_remaining % 60), curr_fname);622 mr_asprintf(tmp, "%02d%% done %02d:%02d taken %02d:%02d remaining %-37s\r", percentage, (int) (time_taken / 60), (int) (time_taken % 60), (int) (time_remaining / 60), (int) (time_remaining % 60), curr_fname); 623 623 log_to_screen(tmp); 624 624 mr_free(tmp); … … 645 645 646 646 assert_string_is_neither_NULL_nor_zerolength(outdir_fname); 647 mr_asprintf( &tmp, "mkdir -p %s", outdir_fname);647 mr_asprintf(tmp, "mkdir -p %s", outdir_fname); 648 648 res = system(tmp); 649 649 mr_free(tmp); … … 671 671 assert(!strstr(outfile_fname, MNT_CDROM)); 672 672 assert(!strstr(outfile_fname, "/dev/cdrom")); 673 mr_asprintf( &command, "mkdir -p \"%s\" 2> /dev/null", outfile_fname);673 mr_asprintf(command, "mkdir -p \"%s\" 2> /dev/null", outfile_fname); 674 674 res += system(command); 675 675 mr_free(command); 676 676 677 mr_asprintf( &command, "rmdir \"%s\" 2> /dev/null", outfile_fname);677 mr_asprintf(command, "rmdir \"%s\" 2> /dev/null", outfile_fname); 678 678 res += system(command); 679 679 mr_free(command); 680 680 681 mr_asprintf( &command, "rm -f \"%s\" 2> /dev/null", outfile_fname);681 mr_asprintf(command, "rm -f \"%s\" 2> /dev/null", outfile_fname); 682 682 res += system(command); 683 683 mr_free(command); … … 742 742 long file_len_K; 743 743 744 mr_asprintf( &mountlist, "%s/mountlist.txt", tmpdir);745 mr_asprintf( &command, "grep \"%s \" %s/mountlist.txt | head -n1 | awk '{print $4}'", dev, tmpdir);744 mr_asprintf(mountlist, "%s/mountlist.txt", tmpdir); 745 mr_asprintf(command, "grep \"%s \" %s/mountlist.txt | head -n1 | awk '{print $4}'", dev, tmpdir); 746 746 mr_free(mountlist); 747 747 … … 782 782 malloc_string(fname); 783 783 log_it("Calculating size of all biggiefiles (in total)"); 784 mr_asprintf( &biggielist, "%s/biggielist.txt", bkpinfo->tmpdir);784 mr_asprintf(biggielist, "%s/biggielist.txt", bkpinfo->tmpdir); 785 785 log_it("biggielist = %s", biggielist); 786 786 fin = fopen(biggielist, "r"); … … 801 801 fatal_error("ntfsresize not found"); 802 802 } 803 mr_asprintf( &command, "ntfsresize --force --info %s|grep '^You might resize at '|cut -d' ' -f5", fname);803 mr_asprintf(command, "ntfsresize --force --info %s|grep '^You might resize at '|cut -d' ' -f5", fname); 804 804 log_it("command = %s", command); 805 mr_asprintf( &tmp, "%s", call_program_and_get_last_line_of_output(command));805 mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command)); 806 806 mr_free(command); 807 807 … … 820 820 log_msg(4, "%s --> %ld K", fname, file_len_K); 821 821 } 822 mr_asprintf( &comment, "After adding %s, scratchL+%ld now equals %ld", fname, file_len_K, scratchL);822 mr_asprintf(comment, "After adding %s, scratchL+%ld now equals %ld", fname, file_len_K, scratchL); 823 823 log_msg(4, comment); 824 824 mr_free(comment); … … 853 853 /*@ end vars *************************************************** */ 854 854 855 mr_asprintf( &command, "du -sk %s", mountpt);855 mr_asprintf(command, "du -sk %s", mountpt); 856 856 errno = 0; 857 857 fin = popen(command, "r"); … … 923 923 int res = 0; 924 924 925 mr_asprintf( &command, "which %s > /dev/null 2> /dev/null", fname);925 mr_asprintf(command, "which %s > /dev/null 2> /dev/null", fname); 926 926 res = system(command); 927 927 mr_free(command); 928 928 929 929 if (res) { 930 mr_asprintf( &errorstr, "Please install '%s'. I cannot find it on your system.", fname);930 mr_asprintf(errorstr, "Please install '%s'. I cannot find it on your system.", fname); 931 931 log_to_screen(errorstr); 932 932 mr_free(errorstr); … … 1041 1041 find_and_store_mondoarchives_home(g_mondo_home); 1042 1042 } 1043 mr_asprintf( &command, CP_BIN " --parents -pRdf %s %s", g_mondo_home, bkpinfo->scratchdir);1043 mr_asprintf(command, CP_BIN " --parents -pRdf %s %s", g_mondo_home, bkpinfo->scratchdir); 1044 1044 1045 1045 log_msg(4, "command = %s", command); … … 1051 1051 } 1052 1052 1053 mr_asprintf( &command, "cp -f %s/LAST-FILELIST-NUMBER %s", bkpinfo->tmpdir, bkpinfo->scratchdir);1053 mr_asprintf(command, "cp -f %s/LAST-FILELIST-NUMBER %s", bkpinfo->tmpdir, bkpinfo->scratchdir); 1054 1054 res = run_program_and_log_output(command, FALSE); 1055 1055 mr_free(command); … … 1065 1065 ("'which mondorestore' returned null. Where's your mondorestore? `which` can't find it. That's odd. Did you install mondorestore?"); 1066 1066 } 1067 mr_asprintf( &command, "cp -f %s %s", tmp, bkpinfo->tmpdir);1067 mr_asprintf(command, "cp -f %s %s", tmp, bkpinfo->tmpdir); 1068 1068 res = run_program_and_log_output(command, FALSE); 1069 1069 mr_free(command); … … 1073 1073 } 1074 1074 1075 mr_asprintf( &command, "hostname > %s/HOSTNAME", bkpinfo->scratchdir);1075 mr_asprintf(command, "hostname > %s/HOSTNAME", bkpinfo->scratchdir); 1076 1076 paranoid_system(command); 1077 1077 mr_free(command); 1078 1078 1079 1079 if (bkpinfo->postnuke_tarball[0]) { 1080 mr_asprintf( &command, "cp -f %s %s/post-nuke.tgz", bkpinfo->postnuke_tarball, bkpinfo->tmpdir);1080 mr_asprintf(command, "cp -f %s %s/post-nuke.tgz", bkpinfo->postnuke_tarball, bkpinfo->tmpdir); 1081 1081 res = run_program_and_log_output(command, FALSE); 1082 1082 mr_free(command); … … 1121 1121 1122 1122 log_it("Storing NFS configuration"); 1123 mr_asprintf( &tmp, "%s", bkpinfo->nfs_mount);1123 mr_asprintf(tmp, "%s", bkpinfo->nfs_mount); 1124 1124 p = strchr(tmp, ':'); 1125 1125 if (!p) { … … 1128 1128 } 1129 1129 *(p++) = '\0'; 1130 mr_asprintf( &nfs_server_ipaddr, "%s", tmp);1131 mr_asprintf( &nfs_mount, "%s", p);1130 mr_asprintf(nfs_server_ipaddr, "%s", tmp); 1131 mr_asprintf(nfs_mount, "%s", p); 1132 1132 mr_free(tmp); 1133 1133 1134 1134 /* BERLIOS : there is a bug #67 here as it only considers the first NIC */ 1135 mr_asprintf( &command, "ifconfig | tr '\n' '#' | sed s/##// | tr '#' ' ' | tr '' '\n' | head -n1 | cut -d' ' -f1");1136 mr_asprintf( &nfs_dev, "%s", call_program_and_get_last_line_of_output(command));1137 mr_free(command); 1138 1139 mr_asprintf( &command, "%s", "ifconfig | tr '\n' '#' | sed s/##// | tr '#' ' ' | tr '' '\\n' | head -n1 | tr -s '\t' ' ' | cut -d' ' -f7 | cut -d':' -f2");1140 mr_asprintf( &nfs_client_ipaddr, "%s", call_program_and_get_last_line_of_output(command));1141 mr_free(command); 1142 1143 mr_asprintf( &command, "%s", "ifconfig | tr '\n' '#' | sed s/##// | tr '#' ' ' | tr '' '\\n' | head -n1 | tr -s '\t' ' ' | cut -d' ' -f9 | cut -d':' -f2");1144 mr_asprintf( &nfs_client_netmask, "%s", call_program_and_get_last_line_of_output(command));1145 mr_free(command); 1146 1147 mr_asprintf( &command, "%s", "ifconfig | tr '\n' '#' | sed s/##// | tr '#' ' ' | tr '' '\\n' | head -n1 | tr -s '\t' ' ' | cut -d' ' -f8 | cut -d':' -f2");1148 mr_asprintf( &nfs_client_broadcast, "%s", call_program_and_get_last_line_of_output(command));1149 mr_free(command); 1150 1151 mr_asprintf( &command, "%s", "route -n | grep '^0.0.0.0' | awk '{print $2}'");1152 mr_asprintf( &nfs_client_defgw, "%s", call_program_and_get_last_line_of_output(command));1135 mr_asprintf(command, "ifconfig | tr '\n' '#' | sed s/##// | tr '#' ' ' | tr '' '\n' | head -n1 | cut -d' ' -f1"); 1136 mr_asprintf(nfs_dev, "%s", call_program_and_get_last_line_of_output(command)); 1137 mr_free(command); 1138 1139 mr_asprintf(command, "%s", "ifconfig | tr '\n' '#' | sed s/##// | tr '#' ' ' | tr '' '\\n' | head -n1 | tr -s '\t' ' ' | cut -d' ' -f7 | cut -d':' -f2"); 1140 mr_asprintf(nfs_client_ipaddr, "%s", call_program_and_get_last_line_of_output(command)); 1141 mr_free(command); 1142 1143 mr_asprintf(command, "%s", "ifconfig | tr '\n' '#' | sed s/##// | tr '#' ' ' | tr '' '\\n' | head -n1 | tr -s '\t' ' ' | cut -d' ' -f9 | cut -d':' -f2"); 1144 mr_asprintf(nfs_client_netmask, "%s", call_program_and_get_last_line_of_output(command)); 1145 mr_free(command); 1146 1147 mr_asprintf(command, "%s", "ifconfig | tr '\n' '#' | sed s/##// | tr '#' ' ' | tr '' '\\n' | head -n1 | tr -s '\t' ' ' | cut -d' ' -f8 | cut -d':' -f2"); 1148 mr_asprintf(nfs_client_broadcast, "%s", call_program_and_get_last_line_of_output(command)); 1149 mr_free(command); 1150 1151 mr_asprintf(command, "%s", "route -n | grep '^0.0.0.0' | awk '{print $2}'"); 1152 mr_asprintf(nfs_client_defgw, "%s", call_program_and_get_last_line_of_output(command)); 1153 1153 mr_free(command); 1154 1154 … … 1168 1168 if (!strncmp(nfs_dev, "bond", 4) || !strncmp(nfs_dev, "alb", 3) || !strncmp(nfs_dev, "aft", 3)) { 1169 1169 log_to_screen("Found bonding device %s; looking for corresponding ethN slave device\n", nfs_dev); 1170 mr_asprintf( &command, "%s", "ifconfig %s | awk '{print $5}' | head -n1", nfs_dev);1171 mr_asprintf( &mac_addr, "%s", call_program_and_get_last_line_of_output(command));1170 mr_asprintf(command, "%s", "ifconfig %s | awk '{print $5}' | head -n1", nfs_dev); 1171 mr_asprintf(mac_addr, "%s", call_program_and_get_last_line_of_output(command)); 1172 1172 mr_free(command); 1173 1173 1174 mr_asprintf( &command, "ifconfig | grep -E '%s' | grep -v '%s' | head -n1 | cut -d' ' -f1", mac_addr,nfs_dev);1174 mr_asprintf(command, "ifconfig | grep -E '%s' | grep -v '%s' | head -n1 | cut -d' ' -f1", mac_addr,nfs_dev); 1175 1175 mr_free(mac_addr); 1176 1176 mr_free(nfs_dev); 1177 1177 1178 mr_asprintf( &nfs_dev, "%s", call_program_and_get_last_line_of_output(command));1178 mr_asprintf(nfs_dev, "%s", call_program_and_get_last_line_of_output(command)); 1179 1179 mr_free(command); 1180 1180 … … 1182 1182 } 1183 1183 1184 mr_asprintf( &tmp, "%s/NFS-DEV", bkpinfo->tmpdir);1184 mr_asprintf(tmp, "%s/NFS-DEV", bkpinfo->tmpdir); 1185 1185 write_one_liner_data_file(tmp, nfs_dev); 1186 1186 mr_free(nfs_dev); 1187 1187 mr_free(tmp); 1188 1188 1189 mr_asprintf( &tmp, "%s/NFS-CLIENT-IPADDR", bkpinfo->tmpdir);1189 mr_asprintf(tmp, "%s/NFS-CLIENT-IPADDR", bkpinfo->tmpdir); 1190 1190 write_one_liner_data_file(tmp, nfs_client_ipaddr); 1191 1191 mr_free(nfs_client_ipaddr); 1192 1192 mr_free(tmp); 1193 1193 1194 mr_asprintf( &tmp, "%s/NFS-CLIENT-NETMASK", bkpinfo->tmpdir);1194 mr_asprintf(tmp, "%s/NFS-CLIENT-NETMASK", bkpinfo->tmpdir); 1195 1195 write_one_liner_data_file(tmp, nfs_client_netmask); 1196 1196 mr_free(nfs_client_netmask); 1197 1197 mr_free(tmp); 1198 1198 1199 mr_asprintf( &tmp, "%s/NFS-CLIENT-BROADCAST", bkpinfo->tmpdir);1199 mr_asprintf(tmp, "%s/NFS-CLIENT-BROADCAST", bkpinfo->tmpdir); 1200 1200 write_one_liner_data_file(tmp, nfs_client_broadcast); 1201 1201 mr_free(nfs_client_broadcast); 1202 1202 mr_free(tmp); 1203 1203 1204 mr_asprintf( &tmp, "%s/NFS-CLIENT-DEFGW", bkpinfo->tmpdir);1204 mr_asprintf(tmp, "%s/NFS-CLIENT-DEFGW", bkpinfo->tmpdir); 1205 1205 write_one_liner_data_file(tmp, nfs_client_defgw); 1206 1206 mr_free(nfs_client_defgw); 1207 1207 mr_free(tmp); 1208 1208 1209 mr_asprintf( &tmp, "%s/NFS-SERVER-IPADDR", bkpinfo->tmpdir);1209 mr_asprintf(tmp, "%s/NFS-SERVER-IPADDR", bkpinfo->tmpdir); 1210 1210 write_one_liner_data_file(tmp, nfs_server_ipaddr); 1211 1211 mr_free(tmp); 1212 1212 mr_free(nfs_server_ipaddr); 1213 1213 1214 mr_asprintf( &tmp, "%s/NFS-SERVER-MOUNT", bkpinfo->tmpdir);1214 mr_asprintf(tmp, "%s/NFS-SERVER-MOUNT", bkpinfo->tmpdir); 1215 1215 write_one_liner_data_file(tmp, bkpinfo->nfs_mount); 1216 1216 mr_free(tmp); 1217 1217 mr_free(nfs_mount); 1218 1218 1219 mr_asprintf( &tmp, "%s/NFS-SERVER-PATH", bkpinfo->tmpdir);1219 mr_asprintf(tmp, "%s/NFS-SERVER-PATH", bkpinfo->tmpdir); 1220 1220 write_one_liner_data_file(tmp, bkpinfo->nfs_remote_dir); 1221 1221 mr_free(tmp); 1222 1222 1223 mr_asprintf( &tmp, "%s/ISO-PREFIX", bkpinfo->tmpdir);1223 mr_asprintf(tmp, "%s/ISO-PREFIX", bkpinfo->tmpdir); 1224 1224 write_one_liner_data_file(tmp, bkpinfo->prefix); 1225 1225 mr_free(tmp); … … 1282 1282 if (scratchLL <= 1) { 1283 1283 mds = media_descriptor_string(bkpinfo->backup_media_type); 1284 mr_asprintf( &tmp, "Your backup will probably occupy a single %s. Maybe two.", mds);1284 mr_asprintf(tmp, "Your backup will probably occupy a single %s. Maybe two.", mds); 1285 1285 mr_free(mds); 1286 1286 } else if (scratchLL > 4) { 1287 mr_asprintf( &tmp, "Your backup will occupy one meeeeellion media! (maybe %s)", number_to_text((int) (scratchLL + 1)));1287 mr_asprintf(tmp, "Your backup will occupy one meeeeellion media! (maybe %s)", number_to_text((int) (scratchLL + 1))); 1288 1288 } else { 1289 mr_asprintf( &tmp, "Your backup will occupy approximately %s media.", number_to_text((int) (scratchLL + 1)));1289 mr_asprintf(tmp, "Your backup will occupy approximately %s media.", number_to_text((int) (scratchLL + 1))); 1290 1290 } 1291 1291 if (!bkpinfo->image_devs[0] && (scratchLL < 50)) { … … 1336 1336 } 1337 1337 1338 mr_asprintf( &tmp, "%s/do-not-compress-these", g_mondo_home);1338 mr_asprintf(tmp, "%s/do-not-compress-these", g_mondo_home); 1339 1339 if (!does_file_exist(tmp)) { 1340 1340 mr_free(tmp); … … 1346 1346 1347 1347 for (p = do_not_compress_these; p != NULL; p++) { 1348 mr_asprintf( &tmp, "%s", p);1348 mr_asprintf(tmp, "%s", p); 1349 1349 if (strchr(tmp, ' ')) { 1350 1350 *(strchr(tmp, ' ')) = '\0'; … … 1394 1394 paranoid_fclose(fout); 1395 1395 log_msg(2, "Created %s", outfile); 1396 mr_asprintf( &tmp, "chmod +x %s", outfile);1396 mr_asprintf(tmp, "chmod +x %s", outfile); 1397 1397 paranoid_system(tmp); 1398 1398 mr_free(tmp);
Note:
See TracChangeset
for help on using the changeset viewer.