Changeset 1196 in MondoRescue for branches/stable
- Timestamp:
- Feb 21, 2007, 2:40:49 AM (18 years ago)
- Location:
- branches/stable
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/stable/mondo/src/common/newt-specific.c
r1193 r1196 1081 1081 1082 1082 if (g_text_mode) { 1083 /* Not very useful 1083 1084 printf(_("---progress-form---1--- %s\n"), blurb1); 1085 */ 1084 1086 printf(_("---progress-form---2--- %s\n"), blurb2); 1087 /* Not very useful 1085 1088 printf(_("---progress-form---3--- %s\n"), blurb3); 1086 printf(_("---progress-form---E---\n"));1089 */ 1087 1090 mr_asprintf(&taskprogress, "TASK: ["); 1088 1091 for (i = 0; i < percentage; i += 5) { -
branches/stable/mondo/src/include/mr_mem.h
r1178 r1196 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 #define mr_strcat(x,y,args...) mr_strcat_int((char **)&x, __LINE__,__FILE__, y,## args); 26 26 27 27 /* Internal function bringing debuging info … … 33 33 extern inline void *mr_malloc_int(size_t size, int line, char *file); 34 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);35 extern void mr_strcat_int(char **in, int line, char *file, const char *fmt, ...); 36 36 37 37 #endif /* MR_MEM_H */ -
branches/stable/mondo/src/lib/mr_mem.c
r1178 r1196 114 114 * Equivalent function of strcat but safe 115 115 * from memory allocation point of view 116 * and richer from an interface point of view 116 117 */ 117 void mr_strcat_int(char **in, const char *add, int line, char *file) { 118 char *p =NULL; 118 void mr_strcat_int(char **in, int line, const char *file, const char *fmt, ...) { 119 char *p = NULL; 120 char *fmt2 = NULL; 121 va_list args; 122 int res = 0; 119 123 120 if ( add== NULL) {124 if (fmt == NULL) { 121 125 return; 122 126 } 123 127 if (in == NULL) { 124 mr_msg_int(1,line,file,"Unable to add %s to NULL pointer\nExiting...", add);128 mr_msg_int(1,line,file,"Unable to add to NULL pointer\nExiting..."); 125 129 mr_exit(-1, "Unable to add to a NULL pointer"); 126 130 } 131 va_start(args,fmt); 127 132 if (*in == NULL) { 128 mr_asprintf_int(&p,line,file,add); 133 res = vasprintf(in, fmt, args); 134 if (res == -1) { 135 mr_msg_int(1,line,file,"Unable to alloc memory in mr_strcat\nExiting..."); 136 mr_exit(-1,"Unable to alloc memory in mr_strcat"); 137 } 129 138 } else { 130 mr_asprintf_int(&p,line,file,"%s%s",*in,add); 139 mr_asprintf_int(&fmt2, line, file, "%s%s", *in, fmt); 140 res = vasprintf(&p, fmt2, args); 141 mr_free_int((void **)&fmt2,line,file); 131 142 mr_free_int((void **)in,line,file); 143 *in = p; 132 144 } 133 *in = p;145 va_end(args); 134 146 } 147 148 -
branches/stable/mondo/src/mondorestore/mondo-prep.c
r1170 r1196 10 10 11 11 #include "my-stuff.h" 12 #include " ../common/mondostructures.h"12 #include "mondostructures.h" 13 13 #include "mondoprep.h" 14 #include " ../common/libmondo.h"14 #include "libmondo.h" 15 15 #include "mondo-rstr-tools-EXT.h" 16 16 17 #include <sys/ioctl.h> 17 18 #include <linux/hdreg.h> 18 19 #include <math.h> 20 #include <unistd.h> 19 21 #include "mr_mem.h" 20 22 #include "mr_msg.h" … … 42 44 extern char *g_mountlist_fname; 43 45 extern long g_current_progress, g_maximum_progress; 44 45 46 extern bool g_text_mode; 46 47 47 extern void pause_for_N_seconds(int, char *); 48 48 49 50 49 FILE *g_fprep = NULL; 51 52 53 54 50 int g_partition_table_locked_up = 0; 55 56 57 58 59 60 61 62 63 51 64 52 65 53 void wipe_MBRs_and_reboot_if_necessary(struct mountlist_itself *mountlist) 66 54 { 67 char *command; 68 char *tmp; 69 int lino; 70 int i; 71 FILE *fout; 72 char *buf; 73 const int blocksize = 512; 55 char *command = NULL; 56 int lino = 0; 57 int res = 0; 58 FILE *fout = NULL; 59 char *buf = NULL; 74 60 struct list_of_disks *drivelist = NULL; 75 // If LVMs are present and a zero-and-reboot wasn't recently undertaken 76 // then zero & insist on reboot. 77 malloc_string(command); 78 malloc_string(tmp); 79 buf = mr_malloc(blocksize); 61 62 // If LVMs are present and a zero-and-reboot wasn't recently undertaken 63 // then zero & insist on reboot. 80 64 if (does_file_exist("/tmp/i-want-my-lvm")) // FIXME - cheating :) 81 65 { … … 83 67 make_list_of_drives_in_mountlist(mountlist, drivelist); 84 68 for (lino = 0; lino < drivelist->entries; lino++) { 85 sprintf(command, 86 "dd if=%s bs=512 count=1 2> /dev/null | grep \"%s\"", 87 drivelist->el[lino].device, MONDO_WAS_HERE); 88 if (!run_program_and_log_output(command, 1)) { 69 mr_asprintf(&command, 70 "dd if=%s bs=512 count=1 2> /dev/null | grep \"%s\"", 71 drivelist->el[lino].device, MONDO_WAS_HERE); 72 res = run_program_and_log_output(command, 1); 73 mr_free(command); 74 if (!res) { 89 75 mr_msg(1, "Found MONDO_WAS_HERE marker on drive#%d (%s)", 90 76 lino, drivelist->el[lino].device); … … 94 80 95 81 if (lino == drivelist->entries) { 96 // zero & reboot82 // zero & reboot 97 83 log_to_screen 98 ("I am sorry for the inconvenience but I must ask you to reboot."); 99 log_to_screen 100 ("I need to reset the Master Boot Record; in order to be"); 101 log_to_screen 102 ("sure the kernel notices, I must reboot after doing it."); 84 (_ 85 ("I am sorry for the inconvenience but I must ask you to reboot.")); 86 log_to_screen(_ 87 ("I need to reset the Master Boot Record; in order to be")); 88 log_to_screen(_ 89 ("sure the kernel notices, I must reboot after doing it.")); 103 90 log_to_screen("Please hit 'Enter' to reboot."); 104 91 for (lino = 0; lino < drivelist->entries; lino++) { 105 for (i = 0; i < blocksize; i++) { 106 buf[i] = 0; 107 } 108 sprintf(buf, "%s\n", MONDO_WAS_HERE); 92 mr_asprintf(&buf, "%s\n", MONDO_WAS_HERE); 109 93 fout = fopen(drivelist->el[lino].device, "w+"); 110 94 if (!fout) { … … 112 96 drivelist->el[lino].device); 113 97 } else { 114 if (1 != fwrite(buf, blocksize, 1, fout)) {98 if (1 != fwrite(buf, strlen(buf)+1, 1, fout)) { 115 99 mr_msg(1, "Failed to wipe %s", 116 100 drivelist->el[lino].device); … … 121 105 fclose(fout); 122 106 } 123 } 124 system("sync"); 125 system("sync"); 126 system("sync"); 107 mr_free(buf); 108 } 109 sync(); 110 sync(); 111 sync(); 127 112 popup_and_OK 128 ("I must now reboot. Please leave the boot media in the drive and repeat your actions - e.g. type 'nuke' - and it should work fine."); 113 (_ 114 ("I must reboot now. Please leave the boot media in the drive and repeat your actions - e.g. type 'nuke' - and it should work fine.")); 129 115 system("reboot"); 130 116 } 131 117 } 132 118 // Still here? Cool! 133 mr_free(command);134 mr_free(tmp);135 119 mr_msg(1, "Cool. I didn't have to wipe anything."); 136 120 } 137 121 138 122 139 140 141 142 143 123 int fput_string_one_char_at_a_time(FILE * fout, char *str) 144 124 { 145 int i , j;146 FILE *fq ;125 int i = 0, j = 0; 126 FILE *fq = NULL; 147 127 148 128 if (ferror(fout)) { … … 168 148 return (i); 169 149 } 170 171 172 173 174 175 176 177 178 150 179 151 … … 187 159 * @return The number of errors encountered (0 for success). 188 160 */ 189 190 191 161 int do_my_funky_lvm_stuff(bool just_erase_existing_volumes, 192 162 bool vacuum_pack) 193 163 { 194 /** buffers **********************************************/ 195 char *tmp; 196 char *incoming; 197 char *command; 198 char *lvscan_sz; 199 char *lvremove_sz; 200 char *pvscan_sz; 201 char *vgscan_sz; 202 char *vgcreate_sz; 203 char *vgchange_sz; 204 char *vgremove_sz; 205 // char *do_this_last; 206 207 /** char **************************************************/ 208 char *p; 209 char *q; 164 char *tmp = NULL; 165 char *tmp1 = NULL; 166 char *incoming = NULL; 167 char *command = NULL; 168 char *lvscan_sz = NULL; 169 char *lvremove_sz = NULL; 170 char *pvscan_sz = NULL; 171 char *vgscan_sz = NULL; 172 char *vgchange_sz = NULL; 173 char *vgremove_sz = NULL; 174 char *p = NULL; 175 char *q = NULL; 210 176 211 177 /** int ***************************************************/ 212 178 int retval = 0; 213 179 int res = 0; 214 int i ;180 int i = 0; 215 181 int lvmversion = 1; 216 long extents ;182 long extents = 0L; 217 183 fpos_t orig_pos; 184 size_t n = 0; 185 size_t n1 = 0; 218 186 219 187 /** pointers **********************************************/ 220 FILE *fin ;188 FILE *fin = NULL; 221 189 222 190 /** end *****************************************************/ … … 231 199 } 232 200 233 malloc_string(tmp);234 malloc_string(incoming);235 malloc_string(lvscan_sz);236 malloc_string(lvremove_sz);237 malloc_string(vgscan_sz);238 malloc_string(pvscan_sz);239 malloc_string(vgcreate_sz);240 malloc_string(vgchange_sz);241 malloc_string(vgremove_sz);242 // malloc_string(do_this_last); // postpone lvcreate call if necessary243 command = mr_malloc(512);244 245 // do_this_last[0] = '\0';246 201 iamhere("STARTING"); 247 202 mr_msg(1, "OK, opened i-want-my-lvm. Shutting down LVM volumes..."); 248 203 if (find_home_of_exe("lvm")) // found it :) cool 249 204 { 250 strcpy(lvscan_sz, "lvm lvscan"); 251 strcpy(lvremove_sz, "lvm lvremove"); 252 strcpy(vgscan_sz, "lvm vgscan"); 253 strcpy(pvscan_sz, "lvm pvscan"); 254 strcpy(vgcreate_sz, "lvm vgcreate"); 255 strcpy(vgchange_sz, "lvm vgchange"); 256 strcpy(vgremove_sz, "lvm vgremove"); 205 mr_asprintf(&lvscan_sz, "lvm lvscan"); 206 mr_asprintf(&lvremove_sz, "lvm lvremove"); 207 mr_asprintf(&vgscan_sz, "lvm vgscan"); 208 mr_asprintf(&pvscan_sz, "lvm pvscan"); 209 mr_asprintf(&vgchange_sz, "lvm vgchange"); 210 mr_asprintf(&vgremove_sz, "lvm vgremove"); 257 211 } else { 258 strcpy(lvscan_sz, "lvscan"); 259 strcpy(lvremove_sz, "lvremove"); 260 strcpy(vgscan_sz, "vgscan"); 261 strcpy(pvscan_sz, "pvscan"); 262 strcpy(vgcreate_sz, "vgcreate"); 263 strcpy(vgchange_sz, "vgchange"); 264 strcpy(vgremove_sz, "vgremove"); 265 } 266 sprintf(command, 212 mr_asprintf(&lvscan_sz, "lvscan"); 213 mr_asprintf(&lvremove_sz, "lvremove"); 214 mr_asprintf(&vgscan_sz, "vgscan"); 215 mr_asprintf(&pvscan_sz, "pvscan"); 216 mr_asprintf(&vgchange_sz, "vgchange"); 217 mr_asprintf(&vgremove_sz, "vgremove"); 218 } 219 mr_asprintf(&command, 267 220 "for i in `%s | cut -d\"'\" -f2 | sort -r` ; do echo \"Shutting down lv $i\" >> " 268 221 MONDO_LOGFILE "; %s -f $i; done", lvscan_sz, lvremove_sz); 222 mr_free(lvscan_sz); 223 mr_free(lvremove_sz); 224 269 225 run_program_and_log_output(command, 5); 226 mr_free(command); 227 270 228 sleep(1); 271 sprintf(command,229 mr_asprintf(&command, 272 230 "for i in `%s | grep -i lvm | cut -d'\"' -f2` ; do %s -a n $i ; %s $i; echo \"Shutting down vg $i\" >> " 273 231 MONDO_LOGFILE "; done", vgscan_sz, vgchange_sz, vgremove_sz); 232 mr_free(vgchange_sz); 233 mr_free(vgremove_sz); 234 274 235 run_program_and_log_output(command, 5); 236 mr_free(command); 237 275 238 if (just_erase_existing_volumes) { 276 239 paranoid_fclose(fin); 277 240 mr_msg(1, "Closed i-want-my-lvm. Finished erasing LVMs."); 278 retval = 0; 279 goto end_of_i_want_my_lvm; 241 sync(); 242 sync(); 243 sync(); 244 sleep(1); 245 iamhere("ENDING"); 246 mr_msg(1, "Not many errors. Returning 0."); 247 return (0); 280 248 } 281 249 282 250 mr_msg(1, "OK, rewound i-want-my-lvm. Doing funky stuff..."); 283 251 rewind(fin); 284 for ( fgets(incoming, 512, fin); !feof(fin); fgets(incoming, 512, fin)) {252 for (mr_getline(&incoming, &n1, fin); !feof(fin); mr_getline(&incoming, &n1, fin)) { 285 253 fgetpos(fin, &orig_pos); 254 /* we want to execute lines begining with a # */ 286 255 if (incoming[0] != '#') { 287 256 continue; 288 257 } 289 if (res && strstr(command, "create") && vacuum_pack) {290 sleep(2);291 system("sync");292 system("sync");293 system("sync");294 }295 258 if ((p = strstr(incoming, "vgcreate"))) { 296 // include next line(s) if they end in /dev (cos we've got a broken i-want-my-lvm)297 for ( fgets(tmp, 512, fin); !feof(fin); fgets(tmp, 512, fin)) {259 // include next line(s) if they end in /dev (cos we've got a broken i-want-my-lvm) 260 for (mr_getline(&tmp, &n, fin); !feof(fin); mr_getline(&tmp, &n, fin)) { 298 261 if (tmp[0] == '#') { 299 262 fsetpos(fin, &orig_pos); … … 301 264 } else { 302 265 fgetpos(fin, &orig_pos); 303 strcat(incoming, tmp);266 mr_strcat(incoming, tmp); 304 267 } 305 268 } 269 mr_free(tmp); 270 306 271 for (q = incoming; *q != '\0'; q++) { 307 272 if (*q < 32) { … … 309 274 } 310 275 } 311 strcpy(tmp, p + strlen("vgcreate") + 1);312 for (q = tmp ; *q > 32; q++);276 mr_asprintf(&tmp1, p + strlen("vgcreate") + 1); 277 for (q = tmp1; *q > 32; q++); 313 278 *q = '\0'; 314 mr_msg(1, "Deleting old entries at /dev/%s", tmp );315 // sprintf(command, "%s -f %s", vgremove_sz, tmp);316 // run_program_and_log_output(command,1);317 sprintf(command, "rm -Rf /dev/%s", tmp); 279 mr_msg(1, "Deleting old entries at /dev/%s", tmp1); 280 mr_asprintf(&command, "rm -Rf /dev/%s", tmp1); 281 mr_free(tmp1); 282 318 283 run_program_and_log_output(command, 1); 284 mr_free(command); 285 319 286 run_program_and_log_output(vgscan_sz, 1); 320 287 run_program_and_log_output(pvscan_sz, 1); … … 324 291 } 325 292 for (p = incoming + 1; *p == ' '; p++); 326 strcpy(command,p);293 mr_asprintf(&command,p); 327 294 for (p = command; *p != '\0'; p++); 328 for (; *(p - 1) < 32; p--);295 for (; (*(p - 1) < 32) && (p > command) ; p--); 329 296 *p = '\0'; 297 298 /* BERLIOS: we should rather define LVMv1 or v2 and use it */ 330 299 res = run_program_and_log_output(command, 5); 331 300 if (res > 0 && (p = strstr(command, "lvm "))) { … … 341 310 if (strstr(command, "lvm lvcreate")) 342 311 lvmversion = 2; 343 log_it("%s... so I'll get creative.", tmp);344 312 if (lvmversion == 2) { 345 strcpy(tmp, call_program_and_get_last_line_of_output346 ("tail -n5 /var/log/mondo-archive.log| grep Insufficient | tail -n1"));313 mr_asprintf(&tmp, call_program_and_get_last_line_of_output 314 ("tail -n5 " MONDO_LOGFILE " | grep Insufficient | tail -n1")); 347 315 } else { 348 strcpy(tmp, call_program_and_get_last_line_of_output349 ("tail -n5 /var/log/mondo-archive.log| grep lvcreate | tail -n1"));316 mr_asprintf(&tmp, call_program_and_get_last_line_of_output 317 ("tail -n5 " MONDO_LOGFILE " | grep lvcreate | tail -n1")); 350 318 } 351 319 for (p = tmp; *p != '\0' && !isdigit(*p); p++); 352 320 extents = atol(p); 353 321 mr_msg(5, "p='%s' --> extents=%ld", p, extents); 322 mr_free(tmp); 323 354 324 p = strstr(command, "-L"); 355 325 if (!p) { … … 363 333 *q = ' '; 364 334 } 335 /* BERLIOS: Dangerous: no size control !! */ 365 336 sprintf(p, "%ld", extents); 366 337 i = strlen(p); … … 373 344 *(q - 1) = ' '; 374 345 } 346 /* BERLIOS: Dangerous: no size control !! */ 375 347 sprintf(p, "%ld%c", extents, 'm'); 376 348 i = strlen(p); … … 387 359 mr_msg(0, "%s --> %d", command, res); 388 360 if (!res) { 389 mr_msg(5, "Y AY! This time, it succeeded.");361 mr_msg(5, "Yep! This time, it succeeded."); 390 362 } 391 363 } … … 399 371 retval++; 400 372 } 401 sprintf(tmp, "echo \"%s\" >> /tmp/out.sh", command);373 mr_asprintf(&tmp, "echo \"%s\" >> /tmp/out.sh", command); 402 374 system(tmp); 375 mr_free(tmp); 403 376 sleep(1); 404 377 } 405 378 paranoid_fclose(fin); 406 mr_msg(1, "Closed i-want-my-lvm. Finished doing funky stuff.");407 end_of_i_want_my_lvm:408 mr_free(tmp);409 mr_free(incoming);410 mr_free(command);411 mr_free(lvscan_sz);412 mr_free(lvremove_sz);413 379 mr_free(vgscan_sz); 414 380 mr_free(pvscan_sz); 415 mr_free( vgcreate_sz);416 mr_free( vgchange_sz);417 mr_free(vgremove_sz); 418 // mr_free(do_this_last);419 sy stem("sync");420 sy stem("sync");421 sy stem("sync");381 mr_free(command); 382 mr_free(incoming); 383 384 mr_msg(1, "Closed i-want-my-lvm. Finished doing funky stuff."); 385 sync(); 386 sync(); 387 sync(); 422 388 sleep(1); 423 389 iamhere("ENDING"); … … 445 411 *old_mountlist) 446 412 { 447 /** pointers *********************************************************/ 448 FILE *fin; 449 450 /** int **************************************************************/ 451 int lino; 452 int j; 453 454 /** buffers **********************************************************/ 455 char *incoming; 456 char *tmp; 457 458 /** pointers *********************************************************/ 459 char *p; 413 FILE *fin = NULL; 414 int lino = 0; 415 int j = 0; 416 char *incoming = NULL; 417 char *p = NULL; 418 size_t n = 0; 460 419 461 420 /** init *************************************************************/ … … 464 423 /** end **************************************************************/ 465 424 466 malloc_string(incoming);467 malloc_string(tmp);468 425 assert(new_mountlist != NULL); 469 426 assert(old_mountlist != NULL); … … 471 428 #ifdef __FreeBSD__ 472 429 log_to_screen 473 ("I don't know how to extrapolate the mountlist on FreeBSD. Sorry."); 430 (_ 431 ("I don't know how to extrapolate the mountlist on FreeBSD. Sorry.")); 474 432 return (1); 475 433 #endif … … 480 438 if (!does_file_exist("/etc/raidtab")) { 481 439 log_to_screen 482 ("Cannot find /etc/raidtab - cannot extrapolate the fdisk entries"); 440 (_ 441 ("Cannot find /etc/raidtab - cannot extrapolate the fdisk entries")); 483 442 finish(1); 484 443 } … … 487 446 finish(1); 488 447 } 489 for ( fgets(incoming, MAX_STR_LEN - 1, fin); !feof(fin)448 for (mr_getline(&incoming, &n, fin); !feof(fin) 490 449 && !strstr(incoming, old_mountlist->el[lino].device); 491 fgets(incoming, MAX_STR_LEN - 1, fin));450 mr_getline(&incoming, &n, fin)); 492 451 if (!feof(fin)) { 493 sprintf(tmp,"Investigating %s",452 log_it("Investigating %s", 494 453 old_mountlist->el[lino].device); 495 log_it(tmp); 496 for (fgets(incoming, MAX_STR_LEN - 1, fin); !feof(fin) 454 for (mr_getline(&incoming, &n, fin); !feof(fin) 497 455 && !strstr(incoming, "raiddev"); 498 fgets(incoming, MAX_STR_LEN - 1, fin)) {456 mr_getline(&incoming, &n, fin)) { 499 457 if (strstr(incoming, OSSWAP("device", "drive")) 500 458 && !strchr(incoming, '#')) { 501 459 for (p = incoming + strlen(incoming); 502 *(p - 1) <= 32; p--);460 (*(p - 1) <= 32) && (p >= incoming) ; p--); 503 461 *p = '\0'; 504 for (p--; p > incoming && *(p - 1) > 32; p--); 505 sprintf(tmp, "Extrapolating %s", p); 506 log_it(tmp); 462 for (p--; (p >= incoming) && (*(p - 1) > 32); p--); 463 log_it("Extrapolating %s", p); 507 464 for (j = 0; 508 465 j < new_mountlist->entries … … 522 479 new_mountlist->entries++; 523 480 } else { 524 sprintf(tmp, 525 "Not adding %s to mountlist: it's already there", 526 p); 527 log_it(tmp); 481 log_it("Not adding %s to mountlist: it's already there", p); 528 482 } 529 483 } 530 484 } 531 485 } 486 mr_free(incoming); 487 532 488 paranoid_fclose(fin); 533 489 } else { … … 543 499 } 544 500 } 545 mr_free(incoming);546 mr_free(tmp);547 548 501 return (0); 549 502 } … … 561 514 { 562 515 /** int **************************************************************/ 563 int i= 0;564 int j= 0;565 566 516 int i = 0; 517 int j = 0; 518 int res = 0; 519 567 520 /** buffers ***********************************************************/ 568 521 char *devices = NULL; … … 590 543 mr_asprintf(&devices, raidlist->el[i].data_disks.el[0].device); 591 544 for (j = 1; j < raidlist->el[i].data_disks.entries; j++) { 592 mr_asprintf(&strtmp, "%s", devices); 593 mr_free(devices); 594 mr_asprintf(&devices, "%s %s", strtmp, 595 raidlist->el[i].data_disks.el[j].device); 596 mr_free(strtmp); 545 mr_strcat(devices, " %s", raidlist->el[i].data_disks.el[j].device); 597 546 } 598 547 for (j = 0; j < raidlist->el[i].spare_disks.entries; j++) { 599 mr_asprintf(&strtmp, "%s", devices); 600 mr_free(devices); 601 mr_asprintf(&devices, "%s %s", strtmp, 602 raidlist->el[i].spare_disks.el[j].device); 603 mr_free(strtmp); 548 mr_strcat(devices, " %s", raidlist->el[i].spare_disks.el[j].device); 604 549 } 605 550 // translate RAID level … … 620 565 raidlist->el[i].raid_device, level, 621 566 raidlist->el[i].data_disks.entries); 567 mr_free(level); 622 568 if (raidlist->el[i].parity != -1) { 623 mr_asprintf(&strtmp, "%s", program);624 mr_free(program);625 569 switch(raidlist->el[i].parity) { 626 570 case 0: 627 mr_ asprintf(&program, "%s --parity=%s", strtmp, "la");571 mr_strcat(program, " --parity=%s", "la"); 628 572 break; 629 573 case 1: 630 mr_ asprintf(&program, "%s --parity=%s", strtmp, "ra");574 mr_strcat(program, " --parity=%s", "ra"); 631 575 break; 632 576 case 2: 633 mr_ asprintf(&program, "%s --parity=%s", strtmp, "ls");577 mr_strcat(program, " --parity=%s", "ls"); 634 578 break; 635 579 case 3: 636 mr_ asprintf(&program, "%s --parity=%s", strtmp, "rs");580 mr_strcat(program, " --parity=%s", "rs"); 637 581 break; 638 582 default: … … 640 584 break; 641 585 } 642 mr_free(strtmp);643 586 } 644 587 if (raidlist->el[i].chunk_size != -1) { 645 mr_asprintf(&strtmp, "%s", program); 646 mr_free(program); 647 mr_asprintf(&program, "%s --chunk=%d", strtmp, raidlist->el[i].chunk_size); 648 mr_free(strtmp); 588 mr_strcat(program, " --chunk=%d", raidlist->el[i].chunk_size); 649 589 } 650 590 if (raidlist->el[i].spare_disks.entries > 0) { 651 mr_asprintf(&strtmp, "%s", program); 652 mr_free(program); 653 mr_asprintf(&program, "%s --spare-devices=%d", strtmp, 654 raidlist->el[i].spare_disks.entries); 655 mr_free(strtmp); 591 mr_strcat(program, " --spare-devices=%d", raidlist->el[i].spare_disks.entries); 656 592 } 657 mr_asprintf(&strtmp, "%s", program); 658 mr_free(program); 659 mr_asprintf(&program, "%s %s", strtmp, devices); 660 mr_free(strtmp); 593 mr_strcat(program, " %s", devices); 661 594 res = run_program_and_log_output(program, 1); 662 595 // free memory 663 596 mr_free(devices); 664 mr_free(level);665 597 mr_free(program); 666 598 // return to calling instance 667 return res;599 return(res); 668 600 } 669 601 … … 682 614 { 683 615 /** int **************************************************************/ 684 int res ;616 int res = 0; 685 617 int retval = 0; 686 618 #ifdef __FreeBSD__ … … 689 621 690 622 /** buffers ***********************************************************/ 691 char *program; 692 char *tmp; 623 char *program = NULL; 624 char *program2 = NULL; 625 char *tmp = NULL; 626 char *tmp1 = NULL; 627 #ifdef __FreeBSD__ 628 char *line = NULL; 629 char *status = NULL; 630 FILE *pin = NULL; 631 FILE *fin = NULL; 632 size_t n = 0; 633 size_t n1 = 0; 634 #endif 693 635 694 636 /** end ****************************************************************/ 695 637 696 malloc_string(program);697 malloc_string(tmp);698 638 assert_string_is_neither_NULL_nor_zerolength(device); 699 639 assert(format != NULL); 700 640 701 641 if (strstr(format, "raid")) { // do not form RAID disks; do it to /dev/md* instead 702 sprintf(tmp, "Not formatting %s (it is a RAID disk)", device); 703 log_it(tmp); 704 mr_free(program); 705 mr_free(tmp); 642 log_it("Not formatting %s (it is a RAID disk)", device); 706 643 return (0); 707 644 } … … 709 646 if (strcmp(format, "swap") == 0) { 710 647 log_it("Not formatting %s - it's swap", device); 711 mr_free(program);712 mr_free(tmp);713 648 return (0); 714 649 } 715 650 #endif 716 651 if (strlen(format) <= 2) { 717 sprintf(tmp,652 mr_asprintf(&tmp, 718 653 "%s has a really small format type ('%s') - this is probably a hexadecimal string, which would suggest the partition is an image --- I shouldn't format it", 719 654 device, format); 720 log_it(tmp);721 mr_free(program);722 mr_free(tmp);723 655 return (0); 724 656 } 725 657 if (is_this_device_mounted(device)) { 726 sprintf(tmp, "%s is mounted - cannot format it ", device); 727 log_to_screen(tmp); 728 mr_free(program); 729 mr_free(tmp); 658 log_to_screen(_("%s is mounted - cannot format it "), device); 730 659 return (1); 731 660 } … … 736 665 if (!does_file_exist("/tmp/raidconf.txt")) { 737 666 log_to_screen 738 ("/tmp/raidconf.txt does not exist. I therefore cannot start Vinum."); 667 (_ 668 ("/tmp/raidconf.txt does not exist. I therefore cannot start Vinum.")); 739 669 } else { 740 670 int res; … … 744 674 if (res) { 745 675 log_to_screen 746 ("`vinum create /tmp/raidconf.txt' returned errors. Please fix them and re-run mondorestore."); 676 (_ 677 ("`vinum create /tmp/raidconf.txt' returned errors. Please fix them and re-run mondorestore.")); 747 678 finish(1); 748 679 } … … 752 683 753 684 if (vinum_started_yet) { 754 FILE *fin; 755 char line[MAX_STR_LEN]; 756 sprintf(tmp, 757 "Initializing Vinum device %s (this may take a *long* time)", 685 log_to_screen(_("Initializing Vinum device %s (this may take a *long* time)"), 758 686 device); 759 log_to_screen(tmp); 687 760 688 /* format raid partition */ 761 // sprintf (program, "mkraid --really-force %s", device); --- disabled -- BB, 02/12/2003 762 sprintf(program, 689 mr_asprintf(&program, 763 690 "for plex in `vinum lv -r %s | grep '^P' | tr '\t' ' ' | tr -s ' ' | cut -d' ' -f2`; do echo $plex; done > /tmp/plexes", 764 691 basename(device)); 765 692 system(program); 693 766 694 if (g_fprep) { 767 695 fprintf(g_fprep, "%s\n", program); 768 696 } 697 mr_free(program); 698 769 699 fin = fopen("/tmp/plexes", "r"); 770 while ( fgets(line, MAX_STR_LEN - 1, fin)) {700 while (mr_getline(&line, &n, fin)) { 771 701 if (strchr(line, '\n')) 772 702 *(strchr(line, '\n')) = '\0'; // get rid of the \n on the end 773 703 774 sprintf(tmp, "Initializing plex: %s", line);704 mr_asprintf(&tmp, "Initializing plex: %s", line); 775 705 open_evalcall_form(tmp); 776 sprintf(tmp, "vinum init %s", line); 706 mr_free(tmp); 707 708 mr_asprintf(&tmp, "vinum init %s", line); 777 709 system(tmp); 710 mr_free(tmp); 711 778 712 while (1) { 779 sprintf(tmp,713 mr_asprintf(&tmp, 780 714 "vinum lp -r %s | grep '^S' | head -1 | tr -s ' ' | cut -d: -f2 | cut -f1 | sed 's/^ //' | sed 's/I //' | sed 's/%%//'", 781 715 line); 782 FILE *pin = popen(tmp, "r"); 783 char status[MAX_STR_LEN / 4]; 784 fgets(status, MAX_STR_LEN / 4 - 1, pin); 716 pin = popen(tmp, "r"); 717 mr_free(tmp); 718 719 mr_getline(&status, &n1, pin); 785 720 pclose(pin); 786 721 … … 790 725 update_evalcall_form(atoi(status)); 791 726 usleep(250000); 727 mr_free(status); 792 728 } 793 729 close_evalcall_form(); 794 730 } 731 mr_free(line); 732 795 733 fclose(fin); 796 734 unlink("/tmp/plexes"); … … 798 736 } 799 737 #else 800 sprintf(tmp, "Initializing RAID device %s", device); 801 log_to_screen(tmp); 802 803 // Shouldn't be necessary. 804 log_to_screen("Stopping %s", device); 738 log_to_screen(_("Initializing RAID device %s"), device); 739 740 // Shouldn't be necessary. 741 log_to_screen(_("Stopping %s"), device); 805 742 stop_raid_device(device); 806 sy stem("sync");743 sync(); 807 744 sleep(1); 808 if (g_fprep) {809 fprintf(g_fprep, "%s\n", program);810 }811 745 812 746 mr_msg(1, "Making %s", device); … … 816 750 mr_msg(1, "Creating RAID device %s via mdadm returned %d", device, res); 817 751 } else { 818 sprintf(program, "mkraid --really-force %s", device);752 mr_asprintf(&program, "mkraid --really-force %s", device); 819 753 res = run_program_and_log_output(program, 1); 820 754 mr_msg(1, "%s returned %d", program, res); 821 sy stem("sync");755 sync(); 822 756 sleep(3); 823 757 start_raid_device(device); … … 825 759 fprintf(g_fprep, "%s\n", program); 826 760 } 827 } 828 system("sync"); 761 mr_free(program); 762 } 763 sync(); 829 764 sleep(2); 830 // log_to_screen("Starting %s", device); 831 // sprintf(program, "raidstart %s", device); 832 // res = run_program_and_log_output(program, 1); 833 // mr_msg(1, "%s returned %d", program, res); 834 // system("sync"); sleep(1); 835 #endif 836 system("sync"); 765 #endif 766 sync(); 837 767 sleep(1); 838 768 newtResume(); 839 769 } 840 //#ifndef __FreeBSD__841 //#endif842 770 843 771 if (!strcmp(format, "lvm")) { 844 772 mr_msg(1, "Don't format %s - it's part of an lvm volume", device); 845 mr_free(program);846 mr_free(tmp);847 773 return (0); 848 774 } 849 res = which_format_command_do_i_need(format, program); 850 sprintf(tmp, "%s %s", program, device); 851 if (strstr(program, "kludge")) { 852 strcat(tmp, " /"); 853 } 854 sprintf(program, "sh -c 'echo -en \"y\\ny\\ny\\n\" | %s'", tmp); 855 sprintf(tmp, "Formatting %s as %s", device, format); 775 malloc_string(program2); 776 res = which_format_command_do_i_need(format, program2); 777 mr_asprintf(&tmp, "%s %s", program2, device); 778 if (strstr(program2, "kludge")) { 779 mr_strcat(tmp, " /"); 780 } 781 mr_free(program2); 782 783 mr_asprintf(&program, "sh -c 'echo -en \"y\\ny\\ny\\n\" | %s'", tmp); 784 mr_free(tmp); 785 786 mr_asprintf(&tmp, _("Formatting %s as %s"), device, format); 856 787 update_progress_form(tmp); 788 857 789 res = run_program_and_log_output(program, FALSE); 858 790 if (res && strstr(program, "kludge")) { 859 sprintf(tmp, "Kludge failed; using regular mkfs.%s to format %s", 860 format, device); 791 mr_free(tmp); 792 mr_asprintf(&tmp, _("Kludge failed; using regular mkfs.%s to format %s"), format, device); 793 mr_free(program); 861 794 #ifdef __FreeBSD__ 862 sprintf(program, "newfs_msdos -F 32 %s", device);795 mr_asprintf(&program, "newfs_msdos -F 32 %s", device); 863 796 #else 864 797 #ifdef __IA64__ 865 798 /* For EFI partitions take fat16 866 799 * as we want to make small ones */ 867 sprintf(program, "mkfs -t %s -F 16 %s", format, device);800 mr_asprintf(&program, "mkfs -t %s -F 16 %s", format, device); 868 801 #else 869 sprintf(program, "mkfs -t %s -F 32 %s", format, device);802 mr_asprintf(&program, "mkfs -t %s -F 32 %s", format, device); 870 803 #endif 871 804 #endif … … 875 808 } 876 809 } 810 mr_free(program); 811 877 812 retval += res; 878 813 if (retval) { 879 strcat(tmp, "...failed");814 mr_strcat(tmp, _("...failed")); 880 815 } else { 881 strcat(tmp, "...OK"); 882 } 883 816 mr_strcat(tmp, _("...OK")); 817 } 884 818 log_to_screen(tmp); 885 mr_free(program);886 819 mr_free(tmp); 887 system("sync"); 820 821 sync(); 888 822 sleep(1); 889 823 return (retval); 890 824 } 891 892 893 894 825 895 826 … … 900 831 * @return The number of errors encountered (0 for success). 901 832 */ 902 int format_everything(struct mountlist_itself *mountlist, bool interactively,903 833 int format_everything(struct mountlist_itself *mountlist, 834 bool interactively, struct raidlist_itself *raidlist) 904 835 { 905 836 /** int **************************************************************/ 906 837 int retval = 0; 907 int lino; 908 int res; 909 // int i; 910 // struct list_of_disks *drivelist; 838 int lino = 0; 839 int res = 0; 911 840 912 841 /** long *************************************************************/ 913 long progress_step ;842 long progress_step = 0L; 914 843 915 844 /** bools ************************************************************/ 916 bool do_it ;845 bool do_it = FALSE; 917 846 918 847 /** buffers **********************************************************/ 919 char *tmp ;848 char *tmp = NULL; 920 849 921 850 /** pointers *********************************************************/ 922 struct mountlist_line *me ; // mountlist entry851 struct mountlist_line *me = NULL; // mountlist entry 923 852 /** end **************************************************************/ 924 853 925 854 assert(mountlist != NULL); 926 malloc_string(tmp); 927 sprintf(tmp, "format_everything (mountlist, interactively = %s", 855 log_it("format_everything (mountlist, interactively = %s", 928 856 (interactively) ? "true" : "false"); 929 log_it(tmp); 930 mvaddstr_and_log_it(g_currentY, 0, "Formatting partitions "); 931 open_progress_form("Formatting partitions", 932 "I am now formatting your hard disk partitions.", 933 "This may take up to five minutes.", "", 857 mvaddstr_and_log_it(g_currentY, 0, _("Formatting partitions ")); 858 open_progress_form(_("Formatting partitions"), 859 _("I am now formatting your hard disk partitions."), 860 _("This may take up to five minutes."), "", 934 861 mountlist->entries + 1); 935 862 … … 937 864 (mountlist->entries > 938 865 0) ? g_maximum_progress / mountlist->entries : 1; 939 // start soft-raids now (because LVM might depend on them)940 // ...and for simplicity's sake, let's format them at the same time :)866 // start soft-raids now (because LVM might depend on them) 867 // ...and for simplicity's sake, let's format them at the same time :) 941 868 mr_msg(1, "Stopping all RAID devices"); 942 869 stop_all_raid_devices(mountlist); 943 sy stem("sync");944 sy stem("sync");945 sy stem("sync");870 sync(); 871 sync(); 872 sync(); 946 873 sleep(2); 947 874 mr_msg(1, "Prepare soft-RAIDs"); // prep and format too … … 952 879 if (interactively) { 953 880 // ask user if we should format the current device 954 sprintf(tmp, "Shall I format %s (%s) ?", me->device,881 mr_asprintf(&tmp, "Shall I format %s (%s) ?", me->device, 955 882 me->mountpoint); 956 883 do_it = ask_me_yes_or_no(tmp); 884 mr_free(tmp); 957 885 } else { 958 886 do_it = TRUE; … … 965 893 } 966 894 } 967 sy stem("sync");968 sy stem("sync");969 sy stem("sync");895 sync(); 896 sync(); 897 sync(); 970 898 sleep(2); 971 // This last step is probably necessary972 // log_to_screen("Re-starting software RAIDs...");973 // start_all_raid_devices(mountlist);974 // system("sync"); system("sync"); system("sync");975 // sleep(5);976 // do LVMs now899 // This last step is probably necessary 900 // log_to_screen("Re-starting software RAIDs..."); 901 // start_all_raid_devices(mountlist); 902 // system("sync"); system("sync"); system("sync"); 903 // sleep(5); 904 // do LVMs now 977 905 mr_msg(1, "Creating LVMs"); 978 906 if (does_file_exist("/tmp/i-want-my-lvm")) { 979 907 wait_until_software_raids_are_prepped("/proc/mdstat", 100); 980 log_to_screen( "Configuring LVM");908 log_to_screen(_("Configuring LVM")); 981 909 if (!g_text_mode) { 982 910 newtSuspend(); 983 911 } 984 /*985 for(i=0; i<3; i++)986 {987 res = do_my_funky_lvm_stuff(FALSE, FALSE);988 if (!res) { break; }989 sleep(3);990 res = do_my_funky_lvm_stuff(TRUE, FALSE);991 sleep(3);992 }993 if (res) {994 mr_msg(1, "Vacuum-packing...");995 */996 912 res = do_my_funky_lvm_stuff(FALSE, TRUE); 997 /*998 }999 */1000 913 if (!g_text_mode) { 1001 914 newtResume(); … … 1006 919 log_to_screen("Failed to initialize LVM"); 1007 920 } 1008 // retval += res;1009 921 if (res) { 1010 922 retval++; … … 1012 924 sleep(3); 1013 925 } 1014 // do regulars at last926 // do regulars at last 1015 927 sleep(2); // woo! 1016 928 mr_msg(1, "Formatting regulars"); … … 1018 930 me = &mountlist->el[lino]; // the current mountlist entry 1019 931 if (!strcmp(me->mountpoint, "image")) { 1020 sprintf(tmp, "Not formatting %s - it's an image", me->device); 1021 log_it(tmp); 932 log_it("Not formatting %s - it's an image", me->device); 1022 933 } else if (!strcmp(me->format, "raid")) { 1023 sprintf(tmp, "Not formatting %s - it's a raid-let", 1024 me->device); 1025 log_it(tmp); 934 log_it("Not formatting %s - it's a raid-let", me->device); 1026 935 continue; 1027 936 } else if (!strcmp(me->format, "lvm")) { 1028 sprintf(tmp, "Not formatting %s - it's an LVM", me->device); 1029 log_it(tmp); 937 log_it("Not formatting %s - it's an LVM", me->device); 1030 938 continue; 1031 939 } else if (!strncmp(me->device, "/dev/md", 7)) { 1032 sprintf(tmp, "Already formatted %s - it's a soft-RAID dev", 1033 me->device); 1034 log_it(tmp); 940 log_it("Already formatted %s - it's a soft-RAID dev", me->device); 1035 941 continue; 1036 942 } else if (!does_file_exist(me->device) 1037 943 && strncmp(me->device, "/dev/hd", 7) 1038 944 && strncmp(me->device, "/dev/sd", 7)) { 1039 sprintf(tmp, 1040 "Not formatting %s yet - doesn't exist - probably an LVM", 1041 me->device); 1042 log_it(tmp); 945 log_it("Not formatting %s yet - doesn't exist - probably an LVM", me->device); 1043 946 continue; 1044 947 } else { 1045 948 if (interactively) { 1046 949 // ask user if we should format the current device 1047 sprintf(tmp, "Shall I format %s (%s) ?", me->device,950 mr_asprintf(&tmp, "Shall I format %s (%s) ?", me->device, 1048 951 me->mountpoint); 1049 952 do_it = ask_me_yes_or_no(tmp); 953 mr_free(tmp); 1050 954 } else { 1051 955 do_it = TRUE; … … 1069 973 1070 974 if (retval) { 1071 mvaddstr_and_log_it(g_currentY++, 74, "Failed.");975 mvaddstr_and_log_it(g_currentY++, 74, _("Failed.")); 1072 976 log_to_screen 1073 ("Errors occurred during the formatting of your hard drives."); 977 (_ 978 ("Errors occurred during the formatting of your hard drives.")); 1074 979 } else { 1075 mvaddstr_and_log_it(g_currentY++, 74, "Done.");1076 } 1077 1078 sprintf(tmp,"format_everything () - %s",980 mvaddstr_and_log_it(g_currentY++, 74, _("Done.")); 981 } 982 983 log_it("format_everything () - %s", 1079 984 (retval) ? "failed!" : "finished successfully"); 1080 log_it(tmp);1081 985 1082 986 if (g_partition_table_locked_up > 0) { … … 1084 988 //123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 1085 989 log_to_screen 1086 ("Partition table locked up %d times. At least one 'mkfs' (format) command", 990 (_ 991 ("Partition table locked up %d times. At least one 'mkfs' (format) command"), 1087 992 g_partition_table_locked_up); 1088 log_to_screen 1089 ("failed. I think these two events are related. Sometimes, fdisk's ioctl() call");1090 log_to_screen 1091 ("to refresh its copy of the partition table causes the kernel to lock the ");1092 log_to_screen 1093 ("partition table. I believe this has just happened.");993 log_to_screen(_ 994 ("failed. I think these two events are related. Sometimes, fdisk's ioctl() call")); 995 log_to_screen(_ 996 ("to refresh its copy of the partition table causes the kernel to lock the ")); 997 log_to_screen(_ 998 ("partition table. I believe this has just happened.")); 1094 999 if (ask_me_yes_or_no 1095 ("Please choose 'yes' to reboot and try again; or 'no' to ignore this warning and continue.")) 1000 (_ 1001 ("Please choose 'yes' to reboot and try again; or 'no' to ignore this warning and continue."))) 1096 1002 { 1097 sy stem("sync");1098 sy stem("sync");1099 sy stem("sync");1003 sync(); 1004 sync(); 1005 sync(); 1100 1006 system("reboot"); 1101 1007 } 1102 1008 } else { 1103 1009 log_to_screen 1104 ("Partition table locked up %d time%c. However, disk formatting succeeded.", 1010 (_ 1011 ("Partition table locked up %d time%c. However, disk formatting succeeded."), 1105 1012 g_partition_table_locked_up, 1106 1013 (g_partition_table_locked_up == 1) ? '.' : 's'); … … 1110 1017 system("clear"); 1111 1018 newtResume(); 1112 mr_free(tmp);1113 1019 return (retval); 1114 1020 } … … 1127 1033 { 1128 1034 /** int **************************************************************/ 1129 int current_devno ;1130 int previous_devno ;1035 int current_devno = 0; 1036 int previous_devno = 0; 1131 1037 int retval = 0; 1132 int res; 1133 1134 /** buffers **********************************************************/ 1135 char *tmp; 1038 int res = 0; 1136 1039 1137 1040 /** end **************************************************************/ 1138 1041 1139 malloc_string(tmp);1140 1042 assert_string_is_neither_NULL_nor_zerolength(drivename); 1141 1043 1142 1044 if (devno_we_must_allow_for >= 5) { 1143 sprintf(tmp, "Making dummy primary %s%d", drivename, 1); 1144 log_it(tmp); 1045 log_it("Making dummy primary %s%d", drivename, 1); 1145 1046 g_maximum_progress++; 1146 1047 res = … … 1155 1056 } 1156 1057 for (; current_devno < devno_we_must_allow_for; current_devno++) { 1157 sprintf(tmp, "Creating dummy partition %s%d", drivename, 1158 current_devno); 1159 log_it(tmp); 1058 log_it("Creating dummy partition %s%d", drivename, current_devno); 1160 1059 g_maximum_progress++; 1161 1060 res = … … 1165 1064 previous_devno = current_devno; 1166 1065 } 1167 mr_free(tmp);1168 1066 return (previous_devno); 1169 1067 } … … 1196 1094 } 1197 1095 } 1096 1198 1097 1199 1098 /* The following 2 functions are stolen from /usr/src/sbin/disklabel/disklabel.c */ … … 1297 1196 { 1298 1197 static struct disklabel loclab; 1299 struct partition *dp ;1300 char lnamebuf[BBSIZE];1198 struct partition *dp = NULL; 1199 char *lnamebuf = NULL; 1301 1200 int f; 1302 1201 u_int secsize, u; 1303 1202 off_t mediasize; 1304 1203 1305 (void) snprintf(lnamebuf, BBSIZE, "%s", dkname);1204 mr_asprintf(&lnamebuf, "%s", dkname); 1306 1205 if ((f = open(lnamebuf, O_RDONLY)) == -1) { 1307 1206 warn("cannot open %s", lnamebuf); 1207 mr_free(lnamebuf); 1308 1208 return (NULL); 1309 1209 } 1210 mr_free(lnamebuf); 1310 1211 1311 1212 /* New world order */ … … 1378 1279 char *drivename, struct disklabel *ret) 1379 1280 { 1380 char subdev_str[MAX_STR_LEN];1381 char command[MAX_STR_LEN];1382 struct disklabel *lp ;1281 char *subdev_str = NULL; 1282 char *command = NULL; 1283 struct disklabel *lp = NULL; 1383 1284 int i, lo = 0; 1384 1285 int retval = 0; 1385 char c ;1386 FILE *ftmp ;1286 char c = ' '; 1287 FILE *ftmp = NULL; 1387 1288 1388 1289 lp = get_virgin_disklabel(drivename); 1389 1290 for (c = 'a'; c <= 'z'; ++c) { 1390 1291 int idx; 1391 sprintf(subdev_str, "%s%c", drivename, c);1292 mr_asprintf(&subdev_str, "%s%c", drivename, c); 1392 1293 if ((idx = find_device_in_mountlist(mountlist, subdev_str)) < 0) { 1393 1294 lp->d_partitions[c - 'a'].p_size = 0; … … 1414 1315 lp->d_partitions[c - 'a'].p_fstype = FS_OTHER; 1415 1316 } 1317 mr_free(subdev_str); 1416 1318 } 1417 1319 … … 1444 1346 display_disklabel(ftmp, lp); 1445 1347 fclose(ftmp); 1446 sprintf(command, "disklabel -wr %s auto", canonical_name(drivename));1348 mr_asprintf(&command, "disklabel -wr %s auto", canonical_name(drivename)); 1447 1349 retval += run_program_and_log_output(command, TRUE); 1448 sprintf(command, "disklabel -R %s /tmp/disklabel", 1350 mr_free(command); 1351 1352 mr_asprintf(&command, "disklabel -R %s /tmp/disklabel", 1449 1353 canonical_name(drivename)); 1450 1354 retval += run_program_and_log_output(command, TRUE); 1355 mr_free(command); 1451 1356 if (ret) 1452 1357 *ret = *lp; … … 1465 1370 { 1466 1371 /** int *************************************************************/ 1467 int current_devno ;1372 int current_devno = 0; 1468 1373 int previous_devno = 0; 1469 int lino ;1374 int lino = 0; 1470 1375 int retval = 0; 1471 int i ;1376 int i = 0; 1472 1377 FILE *pout_to_fdisk = NULL; 1473 1378 1474 1379 #ifdef __FreeBSD__ 1475 1380 bool fbsd_part = FALSE; 1476 char subdev_str[MAX_STR_LEN];1381 char *subdev_str = NULL; 1477 1382 #endif 1478 1383 … … 1481 1386 1482 1387 /** buffers *********************************************************/ 1483 char *device_str; 1484 char *format; 1485 char *tmp; 1388 char *device_str = NULL; 1389 char *format = NULL; 1390 char *tmp = NULL; 1391 char *tmp1 = NULL; 1486 1392 1487 1393 /** end *************************************************************/ … … 1490 1396 assert_string_is_neither_NULL_nor_zerolength(drivename); 1491 1397 1492 malloc_string(device_str); 1493 malloc_string(format); 1494 malloc_string(tmp); 1495 1496 sprintf(tmp, "Partitioning drive %s", drivename); 1497 log_it(tmp); 1398 log_it("Partitioning drive %s", drivename); 1498 1399 1499 1400 #if __FreeBSD__ … … 1502 1403 #else 1503 1404 make_hole_for_file(FDISK_LOG); 1504 sprintf(tmp, "parted2fdisk %s >> %s 2>> %s", drivename, FDISK_LOG, FDISK_LOG); 1405 mr_asprintf(&tmp, "parted2fdisk %s >> %s 2>> %s", drivename, FDISK_LOG, 1406 FDISK_LOG); 1505 1407 pout_to_fdisk = popen(tmp, "w"); 1408 mr_free(tmp); 1409 1506 1410 if (!pout_to_fdisk) { 1507 log_to_screen("Cannot call parted2fdisk to configure %s", drivename); 1508 mr_free(device_str); 1509 mr_free(format); 1510 mr_free(tmp); 1411 log_to_screen(_("Cannot call parted2fdisk to configure %s"), 1412 drivename); 1511 1413 return (1); 1512 1414 } 1513 1415 #endif 1416 1417 malloc_string(device_str); 1418 1514 1419 for (current_devno = 1; current_devno < 99; current_devno++) { 1515 1420 build_partition_name(device_str, drivename, current_devno); … … 1522 1427 // then see if the user has picked 'dangerously-dedicated' mode. 1523 1428 // If so, then we just call label_drive_or_slice() and return. 1524 char c; 1429 char c = ' '; 1430 char *command = NULL; 1431 1525 1432 if (current_devno == 1) { 1526 1433 // try DangerouslyDedicated mode 1527 1434 for (c = 'a'; c <= 'z'; c++) { 1528 sprintf(subdev_str, "%s%c", drivename, c); 1529 if (find_device_in_mountlist(mountlist, subdev_str) > 1530 0) { 1435 mr_asprintf(&subdev_str, "%s%c", drivename, c); 1436 if (find_device_in_mountlist(mountlist, subdev_str) > 0) { 1531 1437 fbsd_part = TRUE; 1532 1438 } 1439 mr_free(subdev_str); 1533 1440 } 1534 1441 if (fbsd_part) { … … 1536 1443 drivename, 1537 1444 0); 1538 char command[MAX_STR_LEN]; 1539 sprintf(command, "disklabel -B %s", 1445 mr_asprintf(&command, "disklabel -B %s", 1540 1446 basename(drivename)); 1541 1447 if (system(command)) { 1542 1448 log_to_screen 1543 ("Warning! Unable to make the drive bootable."); 1449 (_ 1450 ("Warning! Unable to make the drive bootable.")); 1544 1451 } 1452 mr_free(command); 1545 1453 mr_free(device_str); 1546 mr_free(format);1547 mr_free(tmp);1548 1454 return r; 1549 1455 } 1550 1456 } 1551 1457 for (c = 'a'; c <= 'z'; c++) { 1552 sprintf(subdev_str, "%s%c", device_str, c);1458 mr_asprintf(&subdev_str, "%s%c", device_str, c); 1553 1459 if (find_device_in_mountlist(mountlist, subdev_str) > 0) { 1554 1460 fbsd_part = TRUE; 1555 1461 } 1462 mr_free(subdev_str); 1556 1463 } 1557 1464 // Now we check the subpartitions of the current partition. … … 1559 1466 int i, line; 1560 1467 1561 strcpy(format, "ufs");1468 mr_asprintf(&format, "ufs"); 1562 1469 partsize = 0; 1563 1470 for (i = 'a'; i < 'z'; ++i) { 1564 sprintf(subdev_str, "%s%c", device_str, i);1471 mr_asprintf(&subdev_str, "%s%c", device_str, i); 1565 1472 line = find_device_in_mountlist(mountlist, subdev_str); 1473 mr_free(subdev_str); 1474 1566 1475 if (line > 0) { 1567 1476 // We found one! Add its size to the total size. … … 1586 1495 #if __FreeBSD__ 1587 1496 // FreeBSD doesn't let you write to blk devices in <512byte chunks. 1588 // sprintf(tmp, "dd if=/dev/zero of=%s count=1 bs=512", drivename);1589 // if (run_program_and_log_output(tmp, TRUE)) {1590 1497 file = open(drivename, O_WRONLY); 1591 1498 if (!file) { 1592 sprintf(tmp, 1593 "Warning - unable to open %s for wiping it's partition table", 1594 drivename); 1595 log_to_screen(tmp); 1499 log_to_screen(_("Warning - unable to open %s for wiping it's partition table"), drivename); 1596 1500 } 1597 1501 1598 1502 for (i = 0; i < 512; i++) { 1599 1503 if (!write(file, "\0", 1)) { 1600 sprintf(tmp, "Warning - unable to write to %s", 1601 drivename); 1602 log_to_screen(tmp); 1504 log_to_screen(_("Warning - unable to write to %s"), drivename); 1603 1505 } 1604 1506 } 1605 sy stem("sync");1507 sync(); 1606 1508 #else 1607 1509 iamhere("New, kernel-friendly partition remover"); … … 1610 1512 fflush(pout_to_fdisk); 1611 1513 } 1612 // sprintf(tmp, "dd if=/dev/zero of=%s count=1 bs=512", drivename);1613 // run_program_and_log_output(tmp, 1);1614 1514 #endif 1615 1515 if (current_devno > 1) { … … 1622 1522 if (!fbsd_part) { 1623 1523 #endif 1624 1625 strcpy(format, mountlist->el[lino].format);1524 mr_free(format); 1525 mr_asprintf(&format, mountlist->el[lino].format); 1626 1526 partsize = mountlist->el[lino].size; 1627 1527 … … 1633 1533 if (current_devno == 5 && previous_devno == 4) { 1634 1534 log_to_screen 1635 ("You must leave at least one partition spare as the Extended partition."); 1535 (_ 1536 ("You must leave at least one partition spare as the Extended partition.")); 1636 1537 mr_free(device_str); 1637 1538 mr_free(format); 1638 mr_free(tmp);1639 1539 return (1); 1640 1540 } … … 1647 1547 #ifdef __FreeBSD__ 1648 1548 if ((current_devno <= 4) && fbsd_part) { 1649 sprintf(tmp, "disklabel -B %s", basename(device_str));1549 mr_asprintf(&tmp, "disklabel -B %s", basename(device_str)); 1650 1550 retval += label_drive_or_slice(mountlist, device_str, 0); 1651 1551 if (system(tmp)) { 1652 1552 log_to_screen 1653 ("Warning! Unable to make the slice bootable."); 1654 } 1553 (_("Warning! Unable to make the slice bootable.")); 1554 } 1555 mr_free(tmp); 1655 1556 } 1656 1557 #endif … … 1658 1559 previous_devno = current_devno; 1659 1560 } 1561 mr_free(device_str); 1562 mr_free(format); 1660 1563 1661 1564 if (pout_to_fdisk) { 1662 // mark relevant partition as bootable1663 sprintf(tmp, "a\n%s\n",1565 // mark relevant partition as bootable 1566 mr_asprintf(&tmp, "a\n%s\n", 1664 1567 call_program_and_get_last_line_of_output 1665 1568 ("make-me-bootable /tmp/mountlist.txt dummy")); 1666 1569 fput_string_one_char_at_a_time(pout_to_fdisk, tmp); 1667 // close fdisk 1570 mr_free(tmp); 1571 1572 // close fdisk 1668 1573 fput_string_one_char_at_a_time(pout_to_fdisk, "w\n"); 1669 sy stem("sync");1574 sync(); 1670 1575 paranoid_pclose(pout_to_fdisk); 1671 1576 mr_msg(0, 1672 1577 "------------------- fdisk.log looks like this ------------------"); 1673 sprintf(tmp, "cat %s >> %s", FDISK_LOG, MONDO_LOGFILE);1578 mr_asprintf(&tmp, "cat %s >> %s", FDISK_LOG, MONDO_LOGFILE); 1674 1579 system(tmp); 1580 mr_free(tmp); 1581 1675 1582 mr_msg(0, 1676 1583 "------------------- end of fdisk.log... word! ------------------"); 1677 sprintf(tmp, "tail -n6 %s | grep -F \"16: \"", FDISK_LOG);1584 mr_asprintf(&tmp, "tail -n6 %s | grep -F \"16: \"", FDISK_LOG); 1678 1585 if (!run_program_and_log_output(tmp, 5)) { 1679 1586 g_partition_table_locked_up++; 1680 1587 log_to_screen 1681 ("A flaw in the Linux kernel has locked the partition table."); 1682 } 1683 } 1684 mr_free(device_str); 1685 mr_free(format); 1686 mr_free(tmp); 1588 (_ 1589 ("A flaw in the Linux kernel has locked the partition table.")); 1590 } 1591 mr_free(tmp); 1592 } 1687 1593 return (retval); 1688 1594 } 1595 1689 1596 1690 1597 /** -
branches/stable/mondo/src/mondorestore/mondo-rstr-tools.c
r1168 r1196 2427 2427 sprintf(command, "cp -f tmp/i-want-my-lvm /tmp/"); 2428 2428 run_program_and_log_output(command, 1); 2429 /* sprintf(command, "grep \" lvm \" %s", g_mountlist_fname);2430 if (!run_program_and_log_output(command, 5) && !does_file_exist("/tmp/i-want-my-lvm"))2431 {2432 mr_msg(1, "Warning. You want LVM but I don't have i-want-my-lvm. FIXME.");2433 }2434 else if (run_program_and_log_output(command,5) && does_file_exist("/tmp/i-want-my-lvm"))2435 {2436 mr_msg(1, "Warning. You don't want LVM but i-want-my-lvm exists. I'll delete it. Cool.");2437 do_my_funky_lvm_stuff(TRUE, FALSE); // ...after I stop any LVMs :)2438 stop_raid_device("/dev/md0");2439 stop_raid_device("/dev/md1");2440 stop_raid_device("/dev/md2");2441 unlink("/tmp/i-want-my-lvm");2442 }2443 else if (!run_program_and_log_output(command,5) && does_file_exist("/tmp/i-want-my-lvm"))2444 {2445 mr_msg(1, "You had better pray that i-want-my-lvm patches your mountlist. FIXME.");2446 }2447 */2448 2429 } 2449 2430 } -
branches/stable/mondo/src/test/test-mem.c
r1178 r1196 38 38 mr_free(str); 39 39 40 printf("*** Test2 with mr_strcat\n"); 41 mr_asprintf(&str,"Another Chain"); 42 mr_strcat(str," %s", "of distrust"); 43 printf("Result: %s\n",str); 44 mr_free(str); 45 40 46 printf("*** Test with mr_getline/mr_free\n"); 41 47 fd = mr_fopen("/etc/passwd","r"); -
branches/stable/mondo/src/test/test-mem.res
r1178 r1196 6 6 *** Test with mr_strcat 7 7 Result: Another Chain of trust 8 *** Test2 with mr_strcat 9 Result: Another Chain of distrust 8 10 *** Test with mr_getline/mr_free 9 11 1st Result: root:x:0:0:root:/root:/bin/bash -
branches/stable/tools/quality
r1129 r1196 28 28 29 29 # How many sprintf/strcat/strcpy vs asprintf are they 30 for s in asprintf mr_asprintf sprintf strcat strcpy strncpy fgets malloc mr_malloc malloc_string getline mr_getline MAX_STR_LEN getcwd goto free mr_free paranoid_free; do30 for s in asprintf mr_asprintf sprintf strcat strcpy strncpy malloc mr_malloc malloc_string fgets getline mr_getline MAX_STR_LEN getcwd goto free mr_free paranoid_free system paranoid_system mr_system; do 31 31 echo "monodrescue $s usage : " 32 32 tot=0
Note:
See TracChangeset
for help on using the changeset viewer.