Changeset 1178 in MondoRescue
- Timestamp:
- Feb 17, 2007, 2:27:26 AM (18 years ago)
- Location:
- branches/stable/mondo/src
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/stable/mondo/src/common/libmondo-string-EXT.h
r1168 r1178 10 10 int lino); 11 11 extern long friendly_sizestr_to_sizelong(char *incoming); 12 extern char *leftpad_string(char *incoming, int width);13 12 extern char *marker_to_string(int marker); 14 13 extern char *mountlist_entry_to_string(struct mountlist_itself *mountlist, -
branches/stable/mondo/src/common/libmondo-string.c
r1168 r1178 1 /* $Id$ */ 2 1 /* 2 $Id$ 3 */ 3 4 4 5 /** … … 14 15 #include "libmondo-string.h" 15 16 #include "libmondo-files-EXT.h" 16 #include " libmondo-gui-EXT.h"17 #include "newt-specific-EXT.h" 17 18 #include "libmondo-tools-EXT.h" 19 #include <math.h> 18 20 19 21 /*@unused@*/ … … 22 24 extern int g_current_media_number; 23 25 extern long long g_tape_posK; 24 25 26 26 27 /** … … 38 39 char *build_partition_name(char *partition, const char *drive, int partno) 39 40 { 40 char *p, *c; 41 char *p = NULL; 42 char *c = NULL; 41 43 42 44 assert(partition != NULL); … … 49 51 if (c && strncmp(c, "/disc", 5) == 0) { 50 52 /* yup it's devfs, return the "part" path */ 53 /* format /dev/.../disc */ 51 54 strcpy(c + 1, "part"); 52 55 p = c + 5; … … 67 70 68 71 69 70 71 72 73 74 75 76 77 78 79 80 72 /** 81 73 * Pad a string on both sides so it appears centered. … … 85 77 void center_string(char *in_out, int width) 86 78 { 87 char scratch[MAX_STR_LEN]; 88 char *p; 89 int i; /* purpose */ 90 int len; /* purpose */ 91 int mid; /* purpose */ 92 int x; /* purpose */ 79 char *scratch = NULL; 80 char *out = NULL; 81 char *p = NULL; 82 int i = 0; /* purpose */ 83 int len = 0; /* purpose */ 84 int mid = 0; /* purpose */ 85 int x = 0; /* purpose */ 93 86 94 87 assert(in_out != NULL); … … 98 91 return; 99 92 } 100 for (p = in_out; *p == ' '; p++); 101 strcpy(scratch, p); 102 mr_strip_spaces (scratch); 93 mr_asprintf(&scratch, in_out); 94 mr_strip_spaces(scratch); 103 95 len = (int) strlen(scratch); 104 96 mid = width / 2; … … 129 121 *q = *p; // for the final '\0' 130 122 } 131 132 133 134 /**135 * Add commas every third place in @p input.136 * @param input The string to commarize.137 * @return The string with commas.138 * @note The returned string points to static storage that will be overwritten with each call.139 */140 char *commarize(char *input)141 {142 char pos_w_commas[MAX_STR_LEN];143 static char output[MAX_STR_LEN];144 char tmp[MAX_STR_LEN];145 int j;146 147 assert(input != NULL);148 149 strcpy(tmp, input);150 if (strlen(tmp) > 6) {151 strcpy(pos_w_commas, tmp);152 j = (int) strlen(pos_w_commas);153 tmp[j - 6] = ',';154 strcpy(tmp + j - 5, pos_w_commas + j - 6);155 // tmp[j-2] = ',';156 // strcpy(tmp+j-1, pos_w_commas+j-3);157 strcpy(pos_w_commas, tmp);158 }159 if (strlen(tmp) > 3) {160 j = (int) strlen(tmp);161 strcpy(pos_w_commas, tmp);162 pos_w_commas[j - 3] = ',';163 strcpy(pos_w_commas + j - 2, tmp + j - 3);164 } else {165 strcpy(pos_w_commas, tmp);166 }167 strcpy(output, pos_w_commas);168 return (output);169 }170 171 172 173 174 175 176 177 123 178 124 … … 201 147 202 148 203 204 205 206 149 /** 207 150 * Turn a "friendly" sizestring into a number of megabytes. … … 213 156 long friendly_sizestr_to_sizelong(char *incoming) 214 157 { 215 long outval ;216 int i ;217 char *tmp ;218 char ch ;158 long outval = 0L; 159 int i = 0; 160 char *tmp = NULL; 161 char ch = ' '; 219 162 220 163 assert_string_is_neither_NULL_nor_zerolength(incoming); 221 164 222 malloc_string(tmp);223 165 if (!incoming[0]) { 224 mr_free(tmp); 225 return (0); 166 return(0L); 226 167 } 227 168 if (strchr(incoming, '.')) { 228 169 fatal_error("Please use integers only. No decimal points."); 229 170 } 230 strcpy(tmp, incoming);171 mr_asprintf(&tmp, "%s", incoming); 231 172 i = (int) strlen(tmp); 232 173 if (tmp[i - 1] == 'B' || tmp[i - 1] == 'b') { … … 237 178 tmp[i] = '\0'; 238 179 outval = atol(tmp); 180 mr_free(tmp); 181 239 182 if (ch == 'g' || ch == 'G') { 240 183 outval = outval * 1024; … … 249 192 ("Oh my gosh. You actually think a YOTTABYTE will get you anywhere? What're you going to do with 1,208,925,819,614,629,174,706,176 bytes of data?!?!"); 250 193 popup_and_OK 251 ( "That sizespec is more than 1,208,925,819,614,629,174,706,176 bytes. You have a shocking amount of data. Please send a screenshot to the list :-)");194 (_("That sizespec is more than 1,208,925,819,614,629,174,706,176 bytes. You have a shocking amount of data. Please send a screenshot to the list :-)")); 252 195 fatal_error("Integer overflow."); 253 196 } else if (ch != 'm' && ch != 'M') { 254 sprintf(tmp, "Re: parameter '%s' - bad multiplier ('%c')",255 incoming, ch);197 mr_asprintf(&tmp, "Re: parameter '%s' - bad multiplier ('%c')", 198 incoming, ch); 256 199 fatal_error(tmp); 257 200 } 258 mr_free(tmp);259 201 return (outval); 260 202 } 261 262 263 264 /**265 * Add spaces to the right of @p incoming to make it @p width characters wide.266 * @param incoming The string to left-pad.267 * @param width The width to pad it to.268 * @return The left-padded string.269 * @note The returned string points to static storage that will be overwritten with each call.270 * @bug Why does center_string() modify its argument but leftpad_string() returns a modified copy?271 */272 char *leftpad_string(char *incoming, int width)273 {274 /*@ buffers ***************************************************** */275 static char output[MAX_STR_LEN];276 277 /*@ ints ******************************************************** */278 int i;279 280 /*@ end vars **************************************************** */281 assert(incoming != NULL);282 assert(width > 2);283 284 strcpy(output, incoming);285 for (i = (int) strlen(output); i < width; i++) {286 output[i] = ' ';287 }288 output[i] = '\0';289 return (output);290 }291 292 203 293 204 … … 374 285 return (outstr); 375 286 } 376 377 378 287 379 288 … … 405 314 406 315 407 408 409 410 411 316 /** 412 317 * Generate a friendly string containing "X blah blah disk(s)" … … 424 329 425 330 /*@ char ******************************************************** */ 426 char p ;331 char p = NULL; 427 332 428 333 assert(label != NULL); … … 495 400 return (output); 496 401 } 497 498 499 402 500 403 … … 530 433 mr_free(input); 531 434 } 532 533 534 535 435 536 436 … … 555 455 /*@ buffers **************************************************** */ 556 456 static char output[MAX_STR_LEN]; 557 static char suffix[MAX_STR_LEN];457 char *suffix = NULL; 558 458 559 459 /*@ end vars *************************************************** */ … … 561 461 assert_string_is_neither_NULL_nor_zerolength(path); 562 462 if (s[0] != '\0') { 563 sprintf(suffix, ".%s", s);463 mr_asprintf(&suffix, ".%s", s); 564 464 } else { 565 suffix[0] = '\0';465 mr_asprintf(&suffix, ""); 566 466 } 567 467 sprintf(output, "%s/slice-%07ld.%05ld.dat%s", path, bigfileno, sliceno, 568 468 suffix); 469 mr_free(suffix); 569 470 return (output); 570 471 } … … 597 498 598 499 599 600 601 500 /** 602 501 * Wrap @p flaws_str across three lines. The first two are no more than 74 characters wide. … … 650 549 651 550 652 653 551 /** 654 552 * Compare @p stringA and @p stringB. This uses an ASCII sort for everything … … 698 596 numA = atol(stringA + start_of_numbers_in_A); 699 597 numB = atol(stringB + start_of_numbers_in_B); 700 /*701 sprintf(tmp,"Comparing %s and %s --> %ld,%ld\n",stringA,stringB,numA,numB);702 log_to_screen(tmp);703 */704 598 return ((int) (numA - numB)); 705 599 } … … 773 667 { 774 668 int i = strlen(partition) - 1; 775 char *c ;669 char *c = NULL; 776 670 777 671 #ifdef __FreeBSD__ … … 793 687 if (c && strncmp(c, "/part", 5) == 0) { 794 688 /* yup it's devfs, return the "disc" path */ 795 str cpy(c + 1, "disc");689 strncpy(c + 1, "disc", (size_t)5); 796 690 return partition; 797 691 } … … 808 702 return partition; 809 703 } 810 811 812 813 704 814 705 … … 838 729 839 730 840 841 842 843 844 845 846 847 731 /** 848 732 * Determine the severity (1-3, 1 being low) of the fact that … … 854 738 int severity_of_difference(char *fn, char *out_reason) 855 739 { 856 int sev; 857 char *reason; 858 char *filename; 859 860 malloc_string(reason); 861 malloc_string(filename); 862 // out_reason might be null on purpose, so don't bomb if it is :) OK? 740 int sev = 0; 741 char *reason = NULL; 742 char *filename = NULL; 743 744 // out_reason might be null on purpose, so don't bomb if it is :) OK? 863 745 assert_string_is_neither_NULL_nor_zerolength(fn); 864 746 if (!strncmp(fn, MNT_RESTORING, strlen(MNT_RESTORING))) { 865 strcpy(filename, fn + strlen(MNT_RESTORING));747 mr_asprintf(&filename, fn + strlen(MNT_RESTORING)); 866 748 } else if (fn[0] != '/') { 867 sprintf(filename, "/%s", fn);749 mr_asprintf(&filename, "/%s", fn); 868 750 } else { 869 strcpy(filename, fn); 870 } 871 872 sev = 3; 873 sprintf(reason, 874 "Changed since backup. Consider running a differential backup in a day or two."); 751 mr_asprintf(&filename, fn); 752 } 753 875 754 if (!strncmp(filename, "/var/", 5)) { 876 755 sev = 2; 877 sprintf(reason,878 "/var's contents will change regularly, inevitably.");756 mr_asprintf(&reason, 757 _("/var's contents will change regularly, inevitably.")); 879 758 } 880 759 if (!strncmp(filename, "/home", 5)) { 881 760 sev = 2; 882 sprintf(reason,883 "It's in your /home partiton. Therefore, it is important.");761 mr_asprintf(&reason, 762 _("It's in your /home partiton. Therefore, it is important.")); 884 763 } 885 764 if (!strncmp(filename, "/usr/", 5)) { 886 765 sev = 3; 887 sprintf(reason,888 "You may have installed/removed software during the backup.");766 mr_asprintf(&reason, 767 _("You may have installed/removed software during the backup.")); 889 768 } 890 769 if (!strncmp(filename, "/etc/", 5)) { 891 770 sev = 3; 892 sprintf(reason,893 "Do not edit config files while backing up your PC.");771 mr_asprintf(&reason, 772 _("Do not edit config files while backing up your PC.")); 894 773 } 895 774 if (!strcmp(filename, "/etc/adjtime") 896 775 || !strcmp(filename, "/etc/mtab")) { 897 776 sev = 1; 898 sprintf(reason, "This file changes all the time. It's OK.");777 mr_asprintf(&reason, _("This file changes all the time. It's OK.")); 899 778 } 900 779 if (!strncmp(filename, "/root/", 6)) { 901 780 sev = 3; 902 sprintf(reason, "Were you compiling/editing something in /root?"); 781 mr_asprintf(&reason, 782 _("Were you compiling/editing something in /root?")); 903 783 } 904 784 if (!strncmp(filename, "/root/.", 7)) { 905 785 sev = 2; 906 sprintf(reason, "Temp or 'dot' files changed in /root.");786 mr_asprintf(&reason, _("Temp or 'dot' files changed in /root.")); 907 787 } 908 788 if (!strncmp(filename, "/var/lib/", 9)) { 909 789 sev = 2; 910 sprintf(reason, "Did you add/remove software during backing?");790 mr_asprintf(&reason, _("Did you add/remove software during backing?")); 911 791 } 912 792 if (!strncmp(filename, "/var/lib/rpm", 12)) { 913 793 sev = 3; 914 sprintf(reason, "Did you add/remove software during backing?");794 mr_asprintf(&reason, _("Did you add/remove software during backing?")); 915 795 } 916 796 if (!strncmp(filename, "/var/lib/slocate", 16)) { 917 797 sev = 1; 918 sprintf(reason,919 "The 'update' daemon ran during backup. This does not affect the integrity of your backup.");798 mr_asprintf(&reason, 799 _("The 'update' daemon ran during backup. This does not affect the integrity of your backup.")); 920 800 } 921 801 if (!strncmp(filename, "/var/log/", 9) … … 923 803 || !strcmp(filename + strlen(filename) - 4, ".log")) { 924 804 sev = 1; 925 sprintf(reason,926 "Log files change frequently as the computer runs. Fret not.");805 mr_asprintf(&reason, 806 _("Log files change frequently as the computer runs. Fret not.")); 927 807 } 928 808 if (!strncmp(filename, "/var/spool", 10)) { 929 809 sev = 1; 930 sprintf(reason,931 "Background processes or printers were active. This does not affect the integrity of your backup.");810 mr_asprintf(&reason, 811 _("Background processes or printers were active. This does not affect the integrity of your backup.")); 932 812 } 933 813 if (!strncmp(filename, "/var/spool/mail", 10)) { 934 814 sev = 2; 935 sprintf(reason, "Mail was sent/received during backup.");815 mr_asprintf(&reason, _("Mail was sent/received during backup.")); 936 816 } 937 817 if (filename[strlen(filename) - 1] == '~') { 938 818 sev = 1; 939 sprintf(reason,940 "Backup copy of another file which was modified recently.");819 mr_asprintf(&reason, 820 _("Backup copy of another file which was modified recently.")); 941 821 } 942 822 if (strstr(filename, "cache")) { 943 823 sev = 1; 944 sprintf(reason,945 "Part of a cache of data. Caches change from time to time. Don't worry.");824 mr_asprintf(&reason, 825 _("Part of a cache of data. Caches change from time to time. Don't worry.")); 946 826 } 947 827 if (!strncmp(filename, "/var/run/", 9) … … 950 830 || strstr(filename, "/.Xauthority")) { 951 831 sev = 1; 952 sprintf(reason, 953 "Temporary file (a lockfile, perhaps) used by software such as X or KDE to register its presence."); 832 mr_asprintf(&reason, 833 _("Temporary file (a lockfile, perhaps) used by software such as X or KDE to register its presence.")); 834 } 835 mr_free(filename); 836 837 if (sev == 0) { 838 sev = 3; 839 mr_asprintf(&reason, 840 _("Changed since backup. Consider running a differential backup in a day or two.")); 954 841 } 955 842 if (out_reason) { 956 843 strcpy(out_reason, reason); 957 844 } 958 mr_free(filename); 845 959 846 mr_free(reason); 960 847 return (sev); 961 848 } 962 963 849 964 850 … … 982 868 return (res); 983 869 } 984 985 986 987 988 989 870 990 871 … … 1002 883 { 1003 884 /*@ int *********************************************** */ 1004 int percentage; 1005 int j; 885 int percentage = 0; 886 int i = 0; 887 int j = 0; 1006 888 1007 889 /*@ buffers ******************************************* */ 1008 890 static char outstr[MAX_STR_LEN]; 1009 char *pos_w_commas, *tmp;1010 891 1011 892 assert(bkpinfo != NULL); 1012 malloc_string(pos_w_commas); 1013 malloc_string(tmp); 1014 sprintf(tmp, "%lld", g_tape_posK); 1015 strcpy(pos_w_commas, commarize(tmp)); 1016 1017 1018 1019 if (bkpinfo->media_size[g_current_media_number] <= 0) 1020 // { fatal_error( "percentage_media_full_comment() - unknown media size"); } 1021 { 1022 sprintf(outstr, "Volume %d: %s kilobytes archived so far", 1023 g_current_media_number, pos_w_commas); 893 894 if (bkpinfo->media_size[g_current_media_number] <= 0) { 895 sprintf(outstr, _("Volume %d: %'lld kilobytes archived so far"), 896 g_current_media_number, g_tape_posK); 1024 897 return (outstr); 1025 898 } 1026 899 1027 /* update screen */900 /* update screen */ 1028 901 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) { 1029 902 percentage = … … 1033 906 percentage = 100; 1034 907 } 1035 sprintf(outstr, "Volume %d: [", g_current_media_number);908 sprintf(outstr, _("Volume %d: ["), g_current_media_number); 1036 909 } else { 1037 910 percentage = … … 1039 912 bkpinfo->media_size[g_current_media_number]); 1040 913 sprintf(outstr, "%s %d: [", 1041 media_descriptor_string(bkpinfo->backup_media_type),914 bkpinfo->backup_media_string, 1042 915 g_current_media_number); 1043 916 } … … 1050 923 j = (int) strlen(outstr); 1051 924 sprintf(outstr + j, "] %d%% used", percentage); 1052 mr_free(pos_w_commas);1053 mr_free(tmp);1054 925 return (outstr); 1055 926 } 927 928 1056 929 1057 930 /** … … 1063 936 char *media_descriptor_string(t_bkptype type_of_bkp) 1064 937 { 1065 static char *type_of_backup = NULL; 1066 1067 if (!type_of_backup) { 1068 malloc_string(type_of_backup); 1069 } 1070 1071 switch (type_of_bkp) { 1072 case dvd: 1073 strcpy(type_of_backup, "DVD"); 1074 break; 1075 case cdr: 1076 strcpy(type_of_backup, "CDR"); 1077 break; 1078 case cdrw: 1079 strcpy(type_of_backup, "CDRW"); 1080 break; 1081 case tape: 1082 strcpy(type_of_backup, "tape"); 1083 break; 1084 case cdstream: 1085 strcpy(type_of_backup, "CDR"); 1086 break; 1087 case udev: 1088 strcpy(type_of_backup, "udev"); 1089 break; 1090 case iso: 1091 strcpy(type_of_backup, "ISO"); 1092 break; 1093 case nfs: 1094 strcpy(type_of_backup, "nfs"); 1095 break; 1096 case usb: 1097 strcpy(type_of_backup, "USB"); 1098 break; 1099 default: 1100 strcpy(type_of_backup, "ISO"); 1101 } 1102 return (type_of_backup); 1103 } 938 static char *type_of_backup = NULL; 939 940 if (!type_of_backup) { 941 malloc_string(type_of_backup); 942 } 943 944 switch (type_of_bkp) { 945 case dvd: 946 strcpy(type_of_backup, "DVD"); 947 break; 948 case cdr: 949 strcpy(type_of_backup, "CDR"); 950 break; 951 case cdrw: 952 strcpy(type_of_backup, "CDRW"); 953 break; 954 case tape: 955 strcpy(type_of_backup, "tape"); 956 break; 957 case cdstream: 958 strcpy(type_of_backup, "CDR"); 959 break; 960 case udev: 961 strcpy(type_of_backup, "udev"); 962 break; 963 case iso: 964 strcpy(type_of_backup, "ISO"); 965 break; 966 case nfs: 967 strcpy(type_of_backup, "nfs"); 968 break; 969 case usb: 970 strcpy(type_of_backup, "USB"); 971 break; 972 default: 973 strcpy(type_of_backup, "ISO"); 974 } 975 return (type_of_backup); 976 } 977 -
branches/stable/mondo/src/common/libmondo-tools.c
r1165 r1178 1 /* libmondo-tools.c misc tools2 $Id$ 1 /* $Id$ 2 misc tools 3 3 */ 4 5 4 6 5 /** … … 16 15 #include "mondostructures.h" 17 16 #include "libmondo-tools.h" 18 #include " libmondo-gui-EXT.h"17 #include "newt-specific-EXT.h" 19 18 #include "libmondo-files-EXT.h" 20 19 #include "libmondo-fork-EXT.h" … … 45 44 46 45 /** 47 * The place where /boot is mounted. 48 */ 49 char *g_boot_mountpt = NULL;46 * The place where /boot is mounted. - Used locally only 47 */ 48 static char *g_boot_mountpt = NULL; 50 49 51 50 /** … … 77 76 78 77 extern t_bkptype g_backup_media_type; 78 extern char *g_backup_media_string; 79 79 80 80 extern bool am_I_in_disaster_recovery_mode(void); … … 111 111 newtSuspend(); 112 112 #endif 113 printf( "ASSERTION FAILED: `%s'\n", exp);114 printf( "\tat %s:%d in %s\n\n", file, line, function);115 printf( "(I)gnore, ignore (A)ll, (D)ebug, a(B)ort, or (E)xit? ");113 printf(_("ASSERTION FAILED: `%s'\n"), exp); 114 printf(_("\tat %s:%d in %s\n\n"), file, line, function); 115 printf(_("(I)gnore, ignore (A)ll, (D)ebug, a(B)ort, or (E)xit? ")); 116 116 do { 117 117 is_valid = TRUE; … … 140 140 case '\n': 141 141 printf 142 ( "(I)gnore, ignore (A)ll, (D)ebug, a(B)ort, or (E)xit? ");142 (_("(I)gnore, ignore (A)ll, (D)ebug, a(B)ort, or (E)xit? ")); 143 143 break; 144 144 default: 145 145 is_valid = FALSE; 146 printf( "Invalid choice.\n");146 printf(_("Invalid choice.\n")); 147 147 break; 148 148 } … … 171 171 char *tmp; 172 172 173 malloc_string(tmp); 174 strcpy(tmp, 175 "for i in `find /root /home -type d -name Desktop -maxdepth 2`; do \ 173 mr_asprintf(&tmp, 174 "for i in `find /root /home -type d -name Desktop -maxdepth 2`; do \ 176 175 file=$i/.directory; if [ -f \"$file\" ] ; then mv -f $file $file.old ; \ 177 176 awk '{if (index($0, \"rootimagesmindi\")) { while (length($0)>2) { getline;} ; } \ … … 202 201 return ("i386"); 203 202 #endif 203 #ifdef __X86_64__ 204 return ("x86_64"); 205 #endif 204 206 #ifdef __IA64__ 205 207 return ("ia64"); … … 209 211 210 212 211 213 /* BERLIOS: Use uname instead */ 212 214 double get_kernel_version(void) 213 215 { … … 237 239 238 240 239 240 241 242 241 /** 243 242 * Get the current time. … … 248 247 return (long) time((void *) 0); 249 248 } 250 251 252 253 254 255 249 256 250 … … 295 289 296 290 297 298 299 291 /** 300 292 * Insert modules that Mondo requires. … … 308 300 system("kldstat | grep ext2fs || kldload ext2fs 2> /dev/null"); 309 301 #else 310 system("modprobe dos &> /dev/null"); 311 system("modprobe fat &> /dev/null"); 312 system("modprobe vfat &> /dev/null"); 313 // system("modprobe osst &> /dev/null"); 302 system("modprobe -a dos fat vfat loop &> /dev/null"); 314 303 #endif 315 304 } … … 349 338 int post_param_configuration(struct s_bkpinfo *bkpinfo) 350 339 { 351 char *extra_cdrom_params ;352 char *mondo_mkisofs_sz ;353 char *command ;354 char * mtpt;355 char * hostname, *ip_address;340 char *extra_cdrom_params = NULL; 341 char *mondo_mkisofs_sz = NULL; 342 char *command = NULL; 343 char *hostname = NULL; 344 char *ip_address = NULL; 356 345 int retval = 0; 357 346 long avm = 0; 358 char *colon; 359 char *cdr_exe; 360 char *tmp; 361 char call_before_iso_user[MAX_STR_LEN] = "\0"; 347 char *colon = NULL; 348 char *cdr_exe = NULL; 349 char *tmp = NULL; 350 char *tmp1 = NULL; 351 char *call_before_iso_user = NULL; 362 352 int rdsiz_MB; 363 char *iso_dev ;364 char *iso_mnt ;365 char *iso_tmp ;366 char *iso_path ;353 char *iso_dev = NULL; 354 char *iso_mnt = NULL; 355 char *iso_tmp = NULL; 356 char *iso_path = NULL; 367 357 FILE *fd1 = NULL; 368 358 369 359 assert(bkpinfo != NULL); 370 malloc_string(extra_cdrom_params);371 malloc_string(mondo_mkisofs_sz);372 malloc_string(command);373 malloc_string(mtpt);374 malloc_string(hostname);375 malloc_string(ip_address);376 malloc_string(cdr_exe);377 malloc_string(tmp);378 malloc_string(iso_dev);379 malloc_string(iso_mnt);380 malloc_string(iso_tmp);381 malloc_string(iso_path);382 360 bkpinfo->optimal_set_size = 383 361 (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type) ? 16 : 16) * … … 387 365 if (bkpinfo->backup_media_type == tape) { 388 366 mr_msg(1, "Bar"); 389 sprintf(tmp, "mt -f %s status", bkpinfo->media_device);367 mr_asprintf(&tmp, "mt -f %s status", bkpinfo->media_device); 390 368 mr_msg(1, "tmp = '%s'", tmp); 391 369 if (run_program_and_log_output(tmp, 3)) { … … 393 371 ("Unable to open tape device. If you haven't specified it with -d, do so. If you already have, check your parameter. I think it's wrong."); 394 372 } 373 mr_free(tmp); 395 374 } 396 375 make_hole_for_dir(bkpinfo->scratchdir); … … 403 382 run_program_and_log_output("cat /etc/*issue*", 5); 404 383 sprintf(g_tmpfs_mountpt, "%s/tmpfs", bkpinfo->tmpdir); 405 sprintf(command, "mkdir -p %s", g_tmpfs_mountpt);384 mr_asprintf(&command, "mkdir -p %s", g_tmpfs_mountpt); 406 385 paranoid_system(command); 386 mr_free(command); 407 387 rdsiz_MB = PPCFG_RAMDISK_SIZE + g_tape_buffer_size_MB; 408 388 #ifdef __FreeBSD__ 409 strcpy(tmp,389 mr_asprintf(&tmp, 410 390 call_program_and_get_last_line_of_output 411 391 ("vmstat | tail -1 | tr -s ' ' | cut -d' ' -f6")); 412 392 avm += atol(tmp); 413 strcpy(tmp, 393 mr_free(tmp); 394 mr_asprintf(&tmp, 414 395 call_program_and_get_last_line_of_output 415 396 ("swapinfo | grep -v Device | tr -s ' ' | cut -d' ' -f4 | tr '\n' '+' | sed 's/+$//' | bc")); 416 397 avm += atol(tmp); 417 sprintf(command, "mdmfs -s %d%c md9 %s", rdsiz_MB, 'm', 418 g_tmpfs_mountpt); 398 mr_free(tmp); 399 mr_asprintf(&command, "mdmfs -s %d%c md9 %s", rdsiz_MB, 'm', 400 g_tmpfs_mountpt); 419 401 #else 420 strcpy(tmp,402 mr_asprintf(&tmp, 421 403 call_program_and_get_last_line_of_output 422 404 ("free | grep ':' | tr -s ' ' '\t' | cut -f2 | head -n1")); 423 405 avm += atol(tmp); 424 sprintf(command, "mount /dev/shm -t tmpfs %s -o size=%d%c", 406 mr_free(tmp); 407 mr_asprintf(&command, "mount /dev/shm -t tmpfs %s -o size=%d%c", 425 408 g_tmpfs_mountpt, rdsiz_MB, 'm'); 426 409 run_program_and_log_output("cat /proc/cpuinfo", 5); 410 /* BERLIOS: rpm is not necessarily there ! */ 427 411 run_program_and_log_output 428 412 ("rpm -q newt newt-devel slang slang-devel ncurses ncurses-devel gcc", … … 440 424 log_it("It doesn't seem you have enough swap to use tmpfs. Fine."); 441 425 } 426 mr_free(command); 442 427 443 428 if (bkpinfo->use_lzo) { … … 457 442 458 443 if (bkpinfo->backup_media_type == dvd) { 459 extra_cdrom_params[0] = '\0';460 mondo_mkisofs_sz[0] = '\0';461 444 if (find_home_of_exe("growisofs")) { 462 strcpy(cdr_exe, "growisofs"); 463 } // unlikely to be used 464 else { 445 mr_asprintf(&cdr_exe, "growisofs"); 446 } else { 465 447 fatal_error("Please install growisofs."); 466 448 } 467 449 if (bkpinfo->nonbootable_backup) { 468 strcat(mondo_mkisofs_sz, MONDO_GROWISOFS_NONBOOT);450 mr_asprintf(&mondo_mkisofs_sz, MONDO_GROWISOFS_NONBOOT); 469 451 } else if 470 452 #ifdef __FreeBSD__ … … 475 457 #ifdef __IA64__ 476 458 { 477 strcat(mondo_mkisofs_sz, MONDO_GROWISOFS_REGULAR_ELILO);459 mr_asprintf(&mondo_mkisofs_sz, MONDO_GROWISOFS_REGULAR_ELILO); 478 460 } 479 461 #else 480 462 { 481 strcat(mondo_mkisofs_sz, MONDO_GROWISOFS_REGULAR_LILO);463 mr_asprintf(&mondo_mkisofs_sz, MONDO_GROWISOFS_REGULAR_LILO); 482 464 } 483 465 #endif 484 466 else 485 467 { 486 strcat(mondo_mkisofs_sz, MONDO_GROWISOFS_REGULAR_SYSLINUX);468 mr_asprintf(&mondo_mkisofs_sz, MONDO_GROWISOFS_REGULAR_SYSLINUX); 487 469 } 488 470 if (bkpinfo->manual_cd_tray) { … … 492 474 sprintf(bkpinfo->call_make_iso, 493 475 "%s %s -Z %s . 2>> _ERR_", 494 mondo_mkisofs_sz, 495 extra_cdrom_params, bkpinfo->media_device); 496 } 476 mondo_mkisofs_sz, "", bkpinfo->media_device); 477 } 478 mr_free(mondo_mkisofs_sz); 479 497 480 if (getenv ("SUDO_COMMAND")) { 498 sprintf(command, "strings `which growisofs` | grep -c SUDO_COMMAND");481 mr_asprintf(&command, "strings `which growisofs` | grep -c SUDO_COMMAND"); 499 482 if (!strcmp(call_program_and_get_last_line_of_output(command), "1")) { 500 483 popup_and_OK("Fatal Error: Can't write DVDs as sudo because growisofs doesn't support this - see the growisofs manpage for details."); 501 484 fatal_error("Can't write DVDs as sudo because growisofs doesn't support this - see the growisofs manpage for details."); 502 } 485 } 486 mr_free(command); 503 487 } 504 488 mr_msg(2, "call_make_iso (DVD res) is ... %s", … … 509 493 if (bkpinfo->backup_media_type == cdrw 510 494 || bkpinfo->backup_media_type == cdr) { 511 extra_cdrom_params[0] = '\0';512 495 if (!bkpinfo->manual_cd_tray) { 513 strcat(extra_cdrom_params, "-waiti ");496 mr_strcat(extra_cdrom_params, "-waiti "); 514 497 } 515 498 if (bkpinfo->backup_media_type == cdrw) { 516 strcat(extra_cdrom_params, "blank=fast ");499 mr_strcat(extra_cdrom_params, "blank=fast "); 517 500 } 518 501 if (find_home_of_exe("cdrecord")) { 519 strcpy(cdr_exe, "cdrecord");502 mr_asprintf(&cdr_exe, "cdrecord"); 520 503 } else if (find_home_of_exe("dvdrecord")) { 521 strcpy(cdr_exe, "dvdrecord");504 mr_asprintf(&cdr_exe, "dvdrecord"); 522 505 } else { 523 506 fatal_error("Please install either cdrecord or dvdrecord."); 524 507 } 525 508 if (bkpinfo->nonbootable_backup) { 526 strcpy(mondo_mkisofs_sz, MONDO_MKISOFS_NONBOOT);509 mr_asprintf(&mondo_mkisofs_sz, MONDO_MKISOFS_NONBOOT); 527 510 } else if 528 511 #ifdef __FreeBSD__ … … 533 516 #ifdef __IA64__ 534 517 { 535 strcat(mondo_mkisofs_sz, MONDO_MKISOFS_REGULAR_ELILO);518 mr_asprintf(&mondo_mkisofs_sz, MONDO_MKISOFS_REGULAR_ELILO); 536 519 } 537 520 #else 538 521 { 539 strcpy(mondo_mkisofs_sz, MONDO_MKISOFS_REGULAR_LILO);522 mr_asprintf(&mondo_mkisofs_sz, MONDO_MKISOFS_REGULAR_LILO); 540 523 } 541 524 #endif 542 525 else 543 526 { 544 strcpy(mondo_mkisofs_sz, MONDO_MKISOFS_REGULAR_SYSLINUX);527 mr_asprintf(&mondo_mkisofs_sz, MONDO_MKISOFS_REGULAR_SYSLINUX); 545 528 } 546 529 if (bkpinfo->manual_cd_tray) { … … 549 532 "%s -o %s/temporary.iso . 2>> _ERR_", 550 533 mondo_mkisofs_sz, bkpinfo->tmpdir); 551 552 strncpy(call_before_iso_user, bkpinfo->call_before_iso, MAX_STR_LEN);534 } else { 535 mr_asprintf(&call_before_iso_user, bkpinfo->call_before_iso); 553 536 sprintf (bkpinfo->call_before_iso, 554 537 "( %s -o %s/temporary.iso . 2>> _ERR_ ; %s )", 555 538 mondo_mkisofs_sz, bkpinfo->tmpdir, call_before_iso_user); 539 mr_free(call_before_iso_user); 556 540 } 557 541 log_it("bkpinfo->call_before_iso = %s", bkpinfo->call_before_iso); … … 569 553 bkpinfo->cdrw_speed); 570 554 } 555 mr_free(mondo_mkisofs_sz); 556 mr_free(cdr_exe); 557 mr_free(extra_cdrom_params); 571 558 } // end of CD code 572 573 /*574 if (bkpinfo->backup_data && bkpinfo->backup_media_type == tape)575 {576 sprintf (tmp,577 "dd if=/dev/zero of=%s bs=%ld count=32 2> /dev/null",578 bkpinfo->media_device, bkpinfo->internal_tape_block_size);579 if (system(tmp))580 {581 retval++;582 fprintf (stderr,583 "Cannot write to tape device. Is the tape set read-only?\n");584 }585 } // end of tape code586 */587 588 559 589 560 if (bkpinfo->backup_media_type == iso) { … … 597 568 598 569 log_it("isodir = %s", bkpinfo->isodir); 599 sprintf(command, "df -P %s | tail -n1 | cut -d' ' -f1",600 bkpinfo->isodir);570 mr_asprintf(&command, "df -P %s | tail -n1 | cut -d' ' -f1", 571 bkpinfo->isodir); 601 572 log_it("command = %s", command); 602 sprintf(iso_dev, "%s",603 call_program_and_get_last_line_of_output(command));573 mr_asprintf(&iso_dev, call_program_and_get_last_line_of_output(command)); 574 mr_free(command); 604 575 log_it("res of it = %s", iso_dev); 605 576 … … 607 578 mr_fprintf(fd1, "iso-dev=%s\n", iso_dev); 608 579 609 sprintf(command, "mount | grep -w %s | tail -n1 | cut -d' ' -f3", 610 iso_dev); 580 mr_asprintf(&command, "mount | grep -w %s | tail -n1 | cut -d' ' -f3", 581 iso_dev); 582 mr_free(iso_dev); 583 611 584 log_it("command = %s", command); 612 sprintf(iso_mnt, "%s",613 call_program_and_get_last_line_of_output(command));585 mr_asprintf(&iso_mnt,call_program_and_get_last_line_of_output(command)); 586 mr_free(command); 614 587 615 588 log_it("res of it = %s", iso_mnt); … … 617 590 log_it("isomnt: %s, %d", iso_mnt, strlen(iso_mnt)); 618 591 619 sprintf(iso_tmp, "%s", bkpinfo->isodir);620 if (strlen(iso_tmp) <strlen(iso_mnt)) {621 iso_path[0] = '\0';592 mr_asprintf(&iso_tmp, "%s", bkpinfo->isodir); 593 if (strlen(iso_tmp) >= strlen(iso_mnt)) { 594 mr_asprintf(&iso_path, "%s", iso_tmp + strlen(iso_mnt)); 622 595 } else { 623 sprintf(iso_path, "%s", iso_tmp + strlen(iso_mnt)); 624 } 596 mr_asprintf(&iso_path, ""); 597 } 598 mr_free(iso_tmp); 599 mr_free(iso_mnt); 600 625 601 log_it("isodir: %s", iso_path); 626 602 mr_fprintf(fd1, "isodir=%s\n", iso_path); 603 mr_free(iso_path); 627 604 628 605 log_it("iso-prefix: %s", bkpinfo->prefix); … … 633 610 634 611 if (bkpinfo->backup_media_type == nfs) { 635 strcpy(hostname, bkpinfo->nfs_mount);612 mr_asprintf(&hostname, bkpinfo->nfs_mount); 636 613 colon = strchr(hostname, ':'); 637 614 if (!colon) { … … 648 625 retval++; 649 626 } else { 650 strcpy(ip_address, inet_ntoa 651 ((struct in_addr) 652 *((struct in_addr *) hent->h_addr))); 653 strcat(ip_address, strchr(bkpinfo->nfs_mount, ':')); 627 mr_asprintf(&ip_address, "%s%s", inet_ntoa((struct in_addr) 628 *((struct in_addr *) hent->h_addr)), 629 strchr(bkpinfo->nfs_mount, ':')); 654 630 strcpy(bkpinfo->nfs_mount, ip_address); 631 mr_free(ip_address); 655 632 } 656 633 } 657 634 store_nfs_config(bkpinfo); 635 mr_free(hostname); 658 636 } 659 637 … … 662 640 fprintf(stderr, "Type 'man mondoarchive' for help.\n"); 663 641 } 664 sprintf(tmp, "%s", MONDO_TMPISOS); /* added #define 22 apr 2002 */642 mr_asprintf(&tmp, "%s", MONDO_TMPISOS); 665 643 if (does_file_exist(tmp)) { 666 644 unlink(tmp); 667 645 } 646 mr_free(tmp); 647 668 648 if (strlen(bkpinfo->tmpdir) < 2 || strlen(bkpinfo->scratchdir) < 2) { 669 649 log_it("tmpdir or scratchdir are blank/missing"); … … 677 657 chmod(bkpinfo->tmpdir, 0700); 678 658 g_backup_media_type = bkpinfo->backup_media_type; 679 mr_free(mtpt); 680 mr_free(extra_cdrom_params); 681 mr_free(mondo_mkisofs_sz); 682 mr_free(command); 683 mr_free(hostname); 684 mr_free(ip_address); 685 mr_free(cdr_exe); 686 mr_free(tmp); 687 mr_free(iso_dev); 688 mr_free(iso_mnt); 689 mr_free(iso_tmp); 690 mr_free(iso_path); 659 g_backup_media_string = bkpinfo->backup_media_string; 691 660 return (retval); 692 661 } 693 694 662 695 663 … … 745 713 746 714 mr_msg(1, "Hi"); 715 747 716 assert(bkpinfo != NULL); 717 /* BERLIOS : Useless ?? */ 748 718 memset((void *) bkpinfo, 0, sizeof(struct s_bkpinfo)); 719 749 720 bkpinfo->manual_cd_tray = FALSE; 750 721 bkpinfo->internal_tape_block_size = DEFAULT_INTERNAL_TAPE_BLOCK_SIZE; … … 769 740 strcpy(bkpinfo->isodir, "/"); 770 741 } else { 771 strcpy(bkpinfo->isodir, "/ root/images/mondo");742 strcpy(bkpinfo->isodir, "/var/cache/mondo/iso"); 772 743 } 773 744 strcpy(bkpinfo->prefix, STD_PREFIX); … … 778 749 bkpinfo->optimal_set_size = 0; 779 750 bkpinfo->backup_media_type = none; 751 bkpinfo->backup_media_string[0] = '\0'; 780 752 strcpy(bkpinfo->include_paths, "/"); 781 753 bkpinfo->exclude_paths[0] = '\0'; … … 799 771 800 772 801 802 803 773 /** 804 774 * Get the remaining free space (in MB) on @p partition. … … 808 778 long free_space_on_given_partition(char *partition) 809 779 { 810 char command[MAX_STR_LEN], out_sz[MAX_STR_LEN]; 811 long res; 780 char *command = NULL; 781 char *out_sz = NULL; 782 long res = 0L; 812 783 813 784 assert_string_is_neither_NULL_nor_zerolength(partition); 814 785 815 sprintf(command, "df -m -P %s &> /dev/null", partition);786 mr_asprintf(&command, "df -m -P %s &> /dev/null", partition); 816 787 if (system(command)) { 817 788 return (-1); 818 789 } // partition does not exist 819 sprintf(command, "df -m -P %s | tail -n1 | tr -s ' ' '\t' | cut -f4", 790 mr_free(command); 791 792 mr_asprintf(&command, "df -m -P %s | tail -n1 | tr -s ' ' '\t' | cut -f4", 820 793 partition); 821 strcpy(out_sz, call_program_and_get_last_line_of_output(command)); 794 mr_asprintf(&out_sz, call_program_and_get_last_line_of_output(command)); 795 mr_free(command); 796 822 797 if (strlen(out_sz) == 0) { 823 798 return (-1); 824 799 } // error within df, probably 825 800 res = atol(out_sz); 801 mr_free(out_sz); 826 802 return (res); 827 803 } 828 829 804 830 805 … … 845 820 846 821 /*@ buffers ************ */ 847 char tmp[MAX_STR_LEN];822 char *tmp = NULL; 848 823 849 824 /*@ int's *************** */ … … 852 827 853 828 854 mvaddstr_and_log_it(g_currentY, 0, "Checking sanity of your Linux distribution"); 829 mvaddstr_and_log_it(g_currentY, 0, 830 "Checking sanity of your Linux distribution"); 855 831 #ifndef __FreeBSD__ 856 832 if (system("which mkfs.vfat &> /dev/null") … … 861 837 ("ln -sf `which mkfs.msdos` /sbin/mkfs.vfat", FALSE); 862 838 } 863 strcpy(tmp,839 mr_asprintf(&tmp, 864 840 call_program_and_get_last_line_of_output 865 841 ("free | grep Mem | head -n1 | tr -s ' ' '\t' | cut -f2")); 866 842 if (atol(tmp) < 35000) { 867 843 retval++; 868 log_to_screen( "You must have at least 32MB of RAM to use Mondo.");844 log_to_screen(_("You must have at least 32MB of RAM to use Mondo.")); 869 845 } 870 846 if (atol(tmp) < 66000) { 871 847 log_to_screen 872 ("WARNING! You have very little RAM. Please upgrade to 64MB or more."); 873 } 848 (_("WARNING! You have very little RAM. Please upgrade to 64MB or more.")); 849 } 850 mr_free(tmp); 874 851 #endif 875 852 … … 878 855 879 856 if (Lres < 50) { 880 857 fatal_error("Your /var/cache partition has <50MB free. Please adjust your partition table to something saner."); 881 858 } 882 859 … … 892 869 ("grep ramdisk /proc/devices", FALSE)) { 893 870 if (!ask_me_yes_or_no 894 ( "Your kernel has no ramdisk support. That's mind-numbingly stupid but I'll allow it if you're planning to use a failsafe kernel. Are you?"))871 (_("Your kernel has no ramdisk support. That's mind-numbingly stupid but I'll allow it if you're planning to use a failsafe kernel. Are you?"))) 895 872 { 896 873 // retval++; 897 874 log_to_screen 898 ( "It looks as if your kernel lacks ramdisk and initrd support.");875 (_("It looks as if your kernel lacks ramdisk and initrd support.")); 899 876 log_to_screen 900 ( "I'll allow you to proceed but FYI, if I'm right, your kernel is broken.");877 (_("I'll allow you to proceed but FYI, if I'm right, your kernel is broken.")); 901 878 } 902 879 } … … 921 898 !run_program_and_log_output 922 899 ("mount | grep -w dos | grep -vE \"/dev/fd|nexdisk\"", 0)) { 923 log_to_screen( "I think you have a Windows 9x partition.");900 log_to_screen(_("I think you have a Windows 9x partition.")); 924 901 retval += whine_if_not_found("parted"); 925 902 #ifndef __IA64__ … … 946 923 run_program_and_log_output 947 924 ("umount `mount | grep cdr | cut -d' ' -f3 | tr '\n' ' '`", 5); 948 strcpy(tmp,925 mr_asprintf(&tmp, 949 926 call_program_and_get_last_line_of_output 950 927 ("mount | grep -E \"cdr(om|w)\"")); … … 952 929 if (strstr(tmp, "autofs")) { 953 930 log_to_screen 954 ( "Your CD-ROM is mounted via autofs. I therefore cannot tell");931 (_("Your CD-ROM is mounted via autofs. I therefore cannot tell")); 955 932 log_to_screen 956 ( "if a CD actually is inserted. If a CD is inserted, please");957 log_to_screen( "eject it. Thank you.");933 (_("if a CD actually is inserted. If a CD is inserted, please")); 934 log_to_screen(_("eject it. Thank you.")); 958 935 log_it 959 936 ("Ignoring autofs CD-ROM 'mount' since we hope nothing's in it."); … … 965 942 } 966 943 } 944 mr_free(tmp); 967 945 #ifndef __FreeBSD__ 968 946 if (!does_file_exist("/etc/modules.conf")) { … … 981 959 retval++; 982 960 log_to_screen 983 ( "Please find out what happened to /etc/modules.conf");961 (_("Please find out what happened to /etc/modules.conf")); 984 962 } 985 963 } … … 994 972 995 973 if (run_program_and_log_output("mindi -V", 1)) { 996 log_to_screen( "Could not ascertain mindi's version number.");974 log_to_screen(_("Could not ascertain mindi's version number.")); 997 975 log_to_screen 998 ( "You have not installed Mondo and/or Mindi properly.");999 log_to_screen( "Please uninstall and reinstall them both.");976 (_("You have not installed Mondo and/or Mindi properly.")); 977 log_to_screen(_("Please uninstall and reinstall them both.")); 1000 978 fatal_error("Please reinstall Mondo and Mindi."); 1001 979 } … … 1003 981 ("mindi --makemountlist /tmp/mountlist.txt.test", 5)) { 1004 982 log_to_screen 1005 ( "Mindi --makemountlist /tmp/mountlist.txt.test failed for some reason.");983 (_("Mindi --makemountlist /tmp/mountlist.txt.test failed for some reason.")); 1006 984 log_to_screen 1007 ( "Please run that command by hand and examine /var/log/mindi.log");985 (_("Please run that command by hand and examine /var/log/mindi.log")); 1008 986 log_to_screen 1009 ( "for more information. Perhaps your /etc/fstab file is insane.");987 (_("for more information. Perhaps your /etc/fstab file is insane.")); 1010 988 log_to_screen 1011 ( "Perhaps Mindi's MakeMountlist() subroutine has a bug. We'll see.");989 (_("Perhaps Mindi's MakeMountlist() subroutine has a bug. We'll see.")); 1012 990 retval++; 1013 991 } … … 1016 994 && !does_file_exist("/etc/raidtab")) { 1017 995 log_to_screen 1018 ( "You have RAID partitions but no /etc/raidtab - creating one from /proc/mdstat");996 (_("You have RAID partitions but no /etc/raidtab - creating one from /proc/mdstat")); 1019 997 create_raidtab_from_mdstat("/etc/raidtab"); 1020 998 } 1021 999 1022 1000 if (retval) { 1023 mvaddstr_and_log_it(g_currentY++, 74, "Failed.");1001 mvaddstr_and_log_it(g_currentY++, 74, _("Failed.")); 1024 1002 } else { 1025 mvaddstr_and_log_it(g_currentY++, 74, "Done.");1003 mvaddstr_and_log_it(g_currentY++, 74, _("Done.")); 1026 1004 } 1027 1005 return (retval); … … 1038 1016 { 1039 1017 /*@ buffer ****************************************************** */ 1040 char command[MAX_STR_LEN * 2];1041 char tmp[MAX_STR_LEN];1018 char *command = NULL; 1019 char *tmp = NULL; 1042 1020 1043 1021 /*@ end vars *************************************************** */ … … 1045 1023 assert_string_is_neither_NULL_nor_zerolength(config_file); 1046 1024 assert_string_is_neither_NULL_nor_zerolength(label); 1025 1047 1026 if (!does_file_exist(config_file)) { 1048 sprintf(tmp, "(read_cfg_var) Cannot find %s config file",1049 config_file);1027 mr_asprintf(&tmp, "(read_cfg_var) Cannot find %s config file", 1028 config_file); 1050 1029 log_to_screen(tmp); 1030 mr_free(tmp); 1051 1031 value[0] = '\0'; 1052 1032 return (1); 1053 } else if (strstr(value, "/dev/") && strstr(value, "t0") 1033 /* } BERLIOS: Useless: 1034 else if (strstr(value, "/dev/") && strstr(value, "t0") 1054 1035 && !strcmp(label, "media-dev")) { 1055 1036 mr_msg(2, "FYI, I shan't read new value for %s - already got %s", 1056 1037 label, value); 1057 1038 return (0); 1058 } else {1059 sprintf(command, "grep '%s .*' %s| cut -d'=' -f2,3,4,5",1039 */ } else { 1040 mr_asprintf(&command, "grep '%s .*' %s| cut -d'=' -f2,3,4,5", 1060 1041 label, config_file); 1061 1042 strcpy(value, call_program_and_get_last_line_of_output(command)); 1043 mr_free(command); 1062 1044 if (strlen(value) == 0) { 1063 1045 return (1); … … 1069 1051 1070 1052 1071 1072 1053 /** 1073 1054 * Remount @c supermount if it was unmounted earlier. … … 1101 1082 1102 1083 /** 1103 * Whether we had to stop autofs (if so, restart it at end).1104 */1105 bool g_autofs_stopped = FALSE;1106 1107 /**1108 * Path to the autofs initscript ("" if none exists).1109 */1110 char g_autofs_exe[MAX_STR_LEN];1111 1112 /**1113 * Autofs initscript in Xandros Linux distribution.1114 */1115 #define XANDROS_AUTOFS_FNAME "/etc/init.d/xandros-autofs"1116 1117 /**1118 * Autofs initscript in most Linux distributions.1119 */1120 #define STOCK_AUTOFS_FNAME "/etc/rc.d/init.d/autofs"1121 1122 /**1123 * If autofs is mounted, stop it (restart at end).1124 */1125 void stop_autofs_if_necessary()1126 {1127 char tmp[MAX_STR_LEN];1128 1129 g_autofs_exe[0] = '\0';1130 if (does_file_exist(XANDROS_AUTOFS_FNAME)) {1131 strcpy(g_autofs_exe, XANDROS_AUTOFS_FNAME);1132 } else if (does_file_exist(STOCK_AUTOFS_FNAME)) {1133 strcpy(g_autofs_exe, STOCK_AUTOFS_FNAME);1134 }1135 1136 if (!g_autofs_exe[0]) {1137 mr_msg(3, "No autofs detected.");1138 } else {1139 mr_msg(3, "%s --- autofs detected", g_autofs_exe);1140 // FIXME -- only disable it if it's running --- sprintf(tmp, "%s status", autofs_exe);1141 sprintf(tmp, "%s stop", g_autofs_exe);1142 if (run_program_and_log_output(tmp, 2)) {1143 log_it("Failed to stop autofs - I assume it wasn't running");1144 } else {1145 g_autofs_stopped = TRUE;1146 log_it("Stopped autofs OK");1147 }1148 }1149 }1150 1151 /**1152 * If autofs was stopped earlier, restart it.1153 */1154 void restart_autofs_if_necessary()1155 {1156 char tmp[MAX_STR_LEN];1157 1158 if (!g_autofs_stopped || !g_autofs_exe[0]) {1159 mr_msg(3, "No autofs detected.");1160 return;1161 }1162 sprintf(tmp, "%s start", g_autofs_exe);1163 if (run_program_and_log_output(tmp, 2)) {1164 log_it("Failed to start autofs");1165 } else {1166 g_autofs_stopped = FALSE;1167 log_it("Started autofs OK");1168 }1169 }1170 1171 1172 /**1173 1084 * If this is a distribution like Gentoo that doesn't keep /boot mounted, mount it. 1174 1085 */ 1175 1086 void mount_boot_if_necessary() 1176 1087 { 1177 char tmp[MAX_STR_LEN]; 1178 char command[MAX_STR_LEN]; 1088 char *tmp = NULL; 1089 char *tmp1 = NULL; 1090 char *command = NULL; 1179 1091 1180 1092 mr_msg(1, "Started sub"); 1181 1093 mr_msg(4, "About to set g_boot_mountpt[0] to '\\0'"); 1182 1094 g_boot_mountpt[0] = '\0'; 1183 mr_msg(4, "Done. Great. Se eting command to something");1184 strcpy(command,1185 "grep -v \":\"/etc/fstab | grep -vE '^#.*$' | grep -E \"[ ]/boot[ ]\" | tr -s ' ' '\t' | cut -f1 | head -n1");1095 mr_msg(4, "Done. Great. Setting command to something"); 1096 mr_asprintf(&command, 1097 "grep -v ':' /etc/fstab | grep -vE '^#.*$' | grep -E \"[ ]/boot[ ]\" | tr -s ' ' '\t' | cut -f1 | head -n1"); 1186 1098 mr_msg(4, "Cool. Command = '%s'", command); 1187 strcpy(tmp, call_program_and_get_last_line_of_output(command)); 1099 mr_asprintf(&tmp, call_program_and_get_last_line_of_output(command)); 1100 mr_free(command); 1101 1188 1102 mr_msg(4, "tmp = '%s'", tmp); 1189 1103 if (tmp[0]) { … … 1197 1111 } 1198 1112 } else { 1199 sprintf(command, "mount | grep -E '^%s'", tmp);1113 mr_asprintf(&command, "mount | grep -E '^%s'", tmp); 1200 1114 mr_msg(3, "command = %s", command); 1201 1115 if (run_program_and_log_output(command, 5)) { 1202 1116 strcpy(g_boot_mountpt, tmp); 1203 sprintf(tmp,1117 mr_asprintf(&tmp1, 1204 1118 "%s (your /boot partition) is not mounted. I'll mount it before backing up", 1205 1119 g_boot_mountpt); 1206 log_it(tmp); 1207 sprintf(tmp, "mount %s", g_boot_mountpt); 1208 if (run_program_and_log_output(tmp, 5)) { 1120 log_it(tmp1); 1121 mr_free(tmp1); 1122 1123 mr_asprintf(&tmp1, "mount %s", g_boot_mountpt); 1124 if (run_program_and_log_output(tmp1, 5)) { 1209 1125 g_boot_mountpt[0] = '\0'; 1210 1126 mr_msg(1, "Plan B"); … … 1217 1133 } 1218 1134 } 1135 mr_free(tmp1); 1219 1136 } 1220 } 1221 } 1137 mr_free(command); 1138 } 1139 } 1140 mr_free(tmp); 1222 1141 mr_msg(1, "Ended sub"); 1223 1142 } … … 1229 1148 void unmount_boot_if_necessary() 1230 1149 { 1231 char tmp[MAX_STR_LEN];1150 char *tmp; 1232 1151 1233 1152 mr_msg(3, "starting"); 1234 1153 if (g_boot_mountpt[0]) { 1235 sprintf(tmp, "umount %s", g_boot_mountpt);1154 mr_asprintf(&tmp, "umount %s", g_boot_mountpt); 1236 1155 if (run_program_and_log_output(tmp, 5)) { 1237 1156 log_it("WARNING - unable to unmount /boot"); 1238 1157 } 1158 mr_free(tmp); 1239 1159 } 1240 1160 mr_msg(3, "leaving"); 1241 1161 } 1242 1243 1162 1244 1163 … … 1254 1173 { 1255 1174 /*@ buffers ***************************************************** */ 1256 char command[MAX_STR_LEN * 2];1257 char tempfile[MAX_STR_LEN];1258 char tmp[MAX_STR_LEN];1175 char *command = NULL; 1176 char *tempfile = NULL; 1177 char *tmp = NULL; 1259 1178 1260 1179 … … 1263 1182 assert_string_is_neither_NULL_nor_zerolength(label); 1264 1183 assert(value != NULL); 1184 1265 1185 if (!does_file_exist(config_file)) { 1266 sprintf(tmp, "(write_cfg_file) Cannot find %s config file",1267 config_file);1186 mr_asprintf(&tmp, "(write_cfg_file) Cannot find %s config file", 1187 config_file); 1268 1188 log_to_screen(tmp); 1189 mr_free(tmp); 1269 1190 return (1); 1270 1191 } 1271 strcpy(tempfile,1192 mr_asprintf(&tempfile, 1272 1193 call_program_and_get_last_line_of_output 1273 1194 ("mktemp -q /tmp/mojo-jojo.blah.XXXXXX")); 1274 1195 if (does_file_exist(config_file)) { 1275 sprintf(command, "grep -vE '^%s .*$' %s > %s",1196 mr_asprintf(&command, "grep -vE '^%s .*$' %s > %s", 1276 1197 label, config_file, tempfile); 1277 1198 paranoid_system(command); 1278 } 1279 sprintf(command, "echo \"%s %s\" >> %s", label, value, tempfile); 1199 mr_free(command); 1200 } 1201 mr_asprintf(&command, "echo \"%s %s\" >> %s", label, value, tempfile); 1280 1202 paranoid_system(command); 1281 sprintf(command, "mv -f %s %s", tempfile, config_file); 1203 mr_free(command); 1204 1205 mr_asprintf(&command, "mv -f %s %s", tempfile, config_file); 1282 1206 paranoid_system(command); 1207 mr_free(command); 1283 1208 unlink(tempfile); 1209 mr_free(tempfile); 1284 1210 return (0); 1285 1211 } 1286 1212 1287 1288 /**1289 * If @p y, malloc @p x, else free @p x.1290 * @bug This function seems orphaned. Please remove.1291 */1292 #define do_alloc_or_free_depending(x,y) { if(y) {x=mr_malloc(MAX_STR_LEN);} else {mr_free(x);} }1293 1213 1294 1214 /** … … 1358 1278 void restart_magicdev_if_necessary() 1359 1279 { 1360 char *tmp; 1361 1362 malloc_string(tmp); 1280 char *tmp = NULL; 1281 1363 1282 if (g_magicdev_command && g_magicdev_command[0]) { 1364 sprintf(tmp, "%s &", g_magicdev_command);1283 mr_asprintf(&tmp, "%s &", g_magicdev_command); 1365 1284 paranoid_system(tmp); 1366 }1367 mr_free(tmp);1285 mr_free(tmp); 1286 } 1368 1287 } 1369 1288 -
branches/stable/mondo/src/include/mr_mem.h
r1162 r1178 23 23 #define mr_malloc(x) mr_malloc_int((size_t)x,__LINE__,__FILE__) 24 24 #define mr_setenv(x,y) mr_setenv_int(x,y,__LINE__,__FILE__) 25 #define mr_strcat(x,y) mr_strcat_int((char **)&x,y, __LINE__,__FILE__); 25 26 26 27 /* Internal function bringing debuging info … … 32 33 extern inline void *mr_malloc_int(size_t size, int line, char *file); 33 34 extern inline void mr_setenv_int(const char *name, const char *value, int line, char *file); 35 extern void mr_strcat_int(char **in, const char *add, int line, char *file); 34 36 35 37 #endif /* MR_MEM_H */ -
branches/stable/mondo/src/include/mr_str.h
r1168 r1178 11 11 /* functions (public methods) */ 12 12 13 extern inlinechar *mr_strtok(char *instr, const char *delims, int *lastpos);14 extern inlinechar *mr_stresc(char *instr, char *toesc, const char escchr);13 extern char *mr_strtok(char *instr, const char *delims, int *lastpos); 14 extern char *mr_stresc(char *instr, char *toesc, const char escchr); 15 15 extern inline char *mr_date(void); 16 extern inline void mr_strip_spaces(char *in_out);17 16 18 17 #endif /* MR_STR_H */ -
branches/stable/mondo/src/lib/mr_mem.c
r1174 r1178 110 110 } 111 111 } 112 113 /* 114 * Equivalent function of strcat but safe 115 * from memory allocation point of view 116 */ 117 void mr_strcat_int(char **in, const char *add, int line, char *file) { 118 char *p =NULL; 119 120 if (add == NULL) { 121 return; 122 } 123 if (in == NULL) { 124 mr_msg_int(1,line,file,"Unable to add %s to NULL pointer\nExiting...", add); 125 mr_exit(-1, "Unable to add to a NULL pointer"); 126 } 127 if (*in == NULL) { 128 mr_asprintf_int(&p,line,file,add); 129 } else { 130 mr_asprintf_int(&p,line,file,"%s%s",*in,add); 131 mr_free_int((void **)in,line,file); 132 } 133 *in = p; 134 } -
branches/stable/mondo/src/lib/mr_str.c
r1168 r1178 122 122 * @param in_out The string to strip spaces/control characters from (modified). 123 123 */ 124 void mr_strip_spaces(char *in_out) 125 { 126 /*@ int ******************************************************** */ 124 void mr_strip_spaces(char *in_out) { 127 125 int i; 128 126 int j; 129 127 size_t length; 130 131 /*@ end vars *************************************************** */132 128 133 129 if (in_out == NULL) { -
branches/stable/mondo/src/test/test-mem.c
r1140 r1178 1 1 #include <stdio.h> 2 2 #include <stdlib.h> 3 #include <string.h> 3 4 #include <assert.h> 4 5 … … 31 32 mr_free(str); 32 33 34 printf("*** Test with mr_strcat\n"); 35 mr_asprintf(&str,"Another Chain"); 36 mr_strcat(str," of trust"); 37 printf("Result: %s\n",str); 38 mr_free(str); 39 33 40 printf("*** Test with mr_getline/mr_free\n"); 34 41 fd = mr_fopen("/etc/passwd","r"); -
branches/stable/mondo/src/test/test-mem.res
r1134 r1178 1 *** Test with mr_ free1 *** Test with mr_malloc/mr_free 2 2 pointer is NOT null 3 3 pointer is null 4 *** Test with mr_asprintf/mr_free 5 Result: Chain of trust 6 *** Test with mr_strcat 7 Result: Another Chain of trust 8 *** Test with mr_getline/mr_free 9 1st Result: root:x:0:0:root:/root:/bin/bash 10 2nd Result: bin:x:1:1:bin:/bin:/bin/sh 11 3rd Result: another line 4 12 *** Test with NULL 5 13 pointer is null
Note:
See TracChangeset
for help on using the changeset viewer.