Changeset 2330 in MondoRescue for branches/2.2.10/mondo/src/common/libmondo-devices.c
- Timestamp:
- Aug 18, 2009, 3:20:49 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.2.10/mondo/src/common/libmondo-devices.c
r2329 r2330 112 112 bool is_this_a_ramdisk = FALSE; 113 113 114 mr_asprintf(tmp, "%s", where_is_root_mounted());114 tmp = where_is_root_mounted(); 115 115 log_msg(0, "root is currently mounted at %s\n", tmp); 116 116 … … 156 156 static char *bkptype_to_string(t_bkptype bt) 157 157 { 158 static char output[MAX_STR_LEN / 4];158 char *output; 159 159 switch (bt) { 160 160 case none: 161 strcpy(output, "none");161 mr_asprintf(output, "none"); 162 162 break; 163 163 case iso: 164 strcpy(output, "iso");164 mr_asprintf(output, "iso"); 165 165 break; 166 166 case cdr: 167 strcpy(output, "cdr");167 mr_asprintf(output, "cdr"); 168 168 break; 169 169 case cdrw: 170 strcpy(output, "cdrw");170 mr_asprintf(output, "cdrw"); 171 171 break; 172 172 case cdstream: 173 strcpy(output, "cdstream");173 mr_asprintf(output, "cdstream"); 174 174 break; 175 175 case nfs: 176 strcpy(output, "nfs");176 mr_asprintf(output, "nfs"); 177 177 break; 178 178 case tape: 179 strcpy(output, "tape");179 mr_asprintf(output, "tape"); 180 180 break; 181 181 case udev: 182 strcpy(output, "udev");182 mr_asprintf(output, "udev"); 183 183 break; 184 184 case usb: 185 strcpy(output, "usb");185 mr_asprintf(output, "usb"); 186 186 break; 187 187 default: 188 strcpy(output, "default");188 mr_asprintf(output, "default"); 189 189 } 190 190 return (output); … … 572 572 char *output = NULL; 573 573 char *cdr_exe = NULL; 574 char *phrase_one = NULL;575 574 char *phrase_two = NULL; 576 575 char *command = NULL; … … 634 633 } 635 634 636 malloc_string(phrase_one);637 phrase_one[0] = '\0';638 malloc_string(phrase_two);639 phrase_two[0] = '\0';640 641 635 malloc_string(tmp); 642 636 tmp[0] = '\0'; … … 649 643 for (r = q; *(r - 1) == ' '; r--); 650 644 *r = '\0'; 651 strcpy(phrase_one, p);652 645 p = strchr(++q, '\''); 653 646 if (p) { … … 658 651 } 659 652 *q = '\0'; 660 strcpy(phrase_two, p);653 mr_asprintf(phrase_two, "%s", p); 661 654 } 662 655 } … … 665 658 } 666 659 paranoid_pclose(fin); 667 paranoid_free(phrase_one);668 660 669 661 #ifndef __FreeBSD__ 670 if ( strlen(phrase_two) == 0) {662 if (!phrase_two || strlen(phrase_two) == 0) { 671 663 log_msg(4, "Not running phase two. String is empty."); 672 664 } else { … … 699 691 } 700 692 } 701 paranoid_free(phrase_two);693 mr_free(phrase_two); 702 694 paranoid_free(tmp); 703 695 … … 1438 1430 } 1439 1431 */ 1440 log_msg(3, "media type = %s", bkptype_to_string(bkpinfo->backup_media_type)); 1432 tmp = bkptype_to_string(bkpinfo->backup_media_type); 1433 log_msg(3, "media type = %s", tmp); 1434 mr_free(tmp); 1435 1441 1436 bkpinfo->cdrw_speed = (bkpinfo->backup_media_type == cdstream) ? 2 : 4; 1442 bkpinfo->compression_level = 1443 (bkpinfo->backup_media_type == cdstream) ? 1 : 5; 1444 bkpinfo->use_lzo = 1445 (bkpinfo->backup_media_type == cdstream) ? TRUE : FALSE; 1437 bkpinfo->compression_level = (bkpinfo->backup_media_type == cdstream) ? 1 : 5; 1438 bkpinfo->use_lzo = (bkpinfo->backup_media_type == cdstream) ? TRUE : FALSE; 1446 1439 mvaddstr_and_log_it(2, 0, " "); 1447 1440 … … 1973 1966 log_it("media device = %s", bkpinfo->media_device); 1974 1967 log_it("media size = %ld", bkpinfo->media_size[1]); 1975 log_it("media type = %s", bkptype_to_string(bkpinfo->backup_media_type)); 1968 tmp = bkptype_to_string(bkpinfo->backup_media_type); 1969 log_it("media type = %s", tmp); 1970 mr_free(tmp); 1971 1976 1972 if (bkpinfo->prefix) { 1977 1973 log_it("prefix = %s", bkpinfo->prefix); … … 2235 2231 * The mountpoint (where it's mounted) will obviously be '/'. 2236 2232 */ 2237 char *where_is_root_mounted() 2238 { 2233 char *where_is_root_mounted() { 2239 2234 /*@ buffers **************** */ 2240 static char tmp[MAX_STR_LEN];2235 char *output; 2241 2236 2242 2237 2243 2238 #ifdef __FreeBSD__ 2244 strcpy(tmp, call_program_and_get_last_line_of_output 2245 ("mount | grep \" on / \" | cut -d' ' -f1")); 2239 mr_asprintf(output, call_program_and_get_last_line_of_output("mount | grep \" on / \" | cut -d' ' -f1")); 2246 2240 #else 2247 strcpy(tmp, call_program_and_get_last_line_of_output 2248 ("mount | grep \" on / \" | cut -d' ' -f1 | sed s/[0-9]// | sed s/[0-9]//")); 2249 if (strstr(tmp, "/dev/cciss/")) { 2250 strcpy(tmp, call_program_and_get_last_line_of_output 2251 ("mount | grep \" on / \" | cut -d' ' -f1 | cut -dp -f1")); 2252 } 2253 if (strstr(tmp, "/dev/md")) { 2254 strcpy(tmp, 2255 call_program_and_get_last_line_of_output 2256 ("mount | grep \" on / \" | cut -d' ' -f1")); 2257 } 2258 #endif 2259 2260 return (tmp); 2241 mr_asprintf(output, call_program_and_get_last_line_of_output("mount | grep \" on / \" | cut -d' ' -f1 | sed s/[0-9]// | sed s/[0-9]//")); 2242 if (strstr(output, "/dev/cciss/")) { 2243 mr_free(output); 2244 mr_asprintf(output, call_program_and_get_last_line_of_output("mount | grep \" on / \" | cut -d' ' -f1 | cut -dp -f1")); 2245 } 2246 if (strstr(output, "/dev/md")) { 2247 mr_free(output); 2248 mr_asprintf(output, call_program_and_get_last_line_of_output("mount | grep \" on / \" | cut -d' ' -f1")); 2249 } 2250 #endif 2251 2252 return (output); 2261 2253 } 2262 2254 … … 2269 2261 */ 2270 2262 #ifdef __FreeBSD__ 2271 char which_boot_loader(char *which_device) 2272 { 2263 char which_boot_loader(char *which_device) { 2273 2264 int count_lilos = 0; 2274 2265 int count_grubs = 0; … … 2286 2277 count_boot0s++; 2287 2278 } 2288 if (does_string_exist_in_first_N_blocks 2289 (which_device, "FreeBSD/i386", 17)) { 2279 if (does_string_exist_in_first_N_blocks(which_device, "FreeBSD/i386", 17)) { 2290 2280 count_dangerouslydedicated++; 2291 2281 } … … 2313 2303 #else 2314 2304 2315 char which_boot_loader(char *which_device) 2316 { 2305 char which_boot_loader(char *which_device) { 2317 2306 /*@ buffer ***************************************************** */ 2318 2307 char *list_drives_cmd = NULL; 2308 char *tmp = NULL; 2319 2309 char *current_drive; 2320 2310 … … 2328 2318 /*@ end vars *************************************************** */ 2329 2319 2330 malloc_string(current_drive);2331 2320 2332 2321 #ifdef __IA64__ … … 2334 2323 return ('E'); 2335 2324 #endif 2336 assert(which_device != NULL); 2337 2338 mr_asprintf(list_drives_cmd, "parted2fdisk -l 2>/dev/null | grep \"/dev/.*:\" | tr -s ':' ' ' | tr -s ' ' '\n' | grep /dev/; echo %s", where_is_root_mounted()); 2325 2326 tmp = where_is_root_mounted(); 2327 mr_asprintf(list_drives_cmd, "parted2fdisk -l 2>/dev/null | grep \"/dev/.*:\" | tr -s ':' ' ' | tr -s ' ' '\n' | grep /dev/; echo %s", tmp); 2328 mr_free(tmp); 2339 2329 log_it("list_drives_cmd = %s", list_drives_cmd); 2340 2330 2341 if (!(pdrives = popen(list_drives_cmd, "r"))) { 2331 pdrives = popen(list_drives_cmd, "r"); 2332 mr_free(list_drives_cmd); 2333 2334 if (!pdrives) { 2342 2335 log_OS_error("Unable to open list of drives"); 2343 mr_free(list_drives_cmd);2344 paranoid_free(current_drive);2345 2336 return ('\0'); 2346 2337 } 2347 mr_free(list_drives_cmd); 2348 2338 2339 malloc_string(current_drive); 2349 2340 for ((void)fgets(current_drive, MAX_STR_LEN, pdrives); !feof(pdrives); 2350 2341 (void)fgets(current_drive, MAX_STR_LEN, pdrives)) { … … 2353 2344 if (does_string_exist_in_boot_block(current_drive, "GRUB")) { 2354 2345 count_grubs++; 2355 strcpy(which_device, current_drive); 2346 mr_free(which_device); 2347 mr_asprintf(which_device, "%s", current_drive); 2356 2348 break; 2357 2349 } 2358 2350 if (does_string_exist_in_boot_block(current_drive, "LILO")) { 2359 2351 count_lilos++; 2360 strcpy(which_device, current_drive); 2352 mr_free(which_device); 2353 mr_asprintf(which_device, "%s", current_drive); 2361 2354 break; 2362 2355 } … … 2395 2388 if (does_string_exist_in_boot_block(current_drive, "GRUB")) { 2396 2389 count_grubs++; 2397 strcpy(which_device, current_drive); 2390 mr_free(which_device); 2391 mr_asprintf(which_device, "%s", current_drive); 2398 2392 break; 2399 2393 } 2400 2394 if (does_string_exist_in_boot_block(current_drive, "LILO")) { 2401 2395 count_lilos++; 2402 strcpy(which_device, current_drive); 2396 mr_free(which_device); 2397 mr_asprintf(which_device, "%s", current_drive); 2403 2398 break; 2404 2399 } … … 2461 2456 char *resolve_softlinks_to_get_to_actual_device_file(char *incoming) 2462 2457 { 2463 static char output[MAX_STR_LEN];2458 char *output; 2464 2459 char *command = NULL; 2465 2460 char *curr_fname; … … 2471 2466 malloc_string(curr_fname); 2472 2467 if (!does_file_exist(incoming)) { 2473 log_it 2474 ("resolve_softlinks_to_get_to_actual_device_file --- device not found"); 2475 strcpy(output, incoming); 2468 log_it("resolve_softlinks_to_get_to_actual_device_file --- device not found"); 2469 mr_asprintf(output, "%s", incoming); 2476 2470 } else { 2477 2471 strcpy(curr_fname, incoming); … … 2482 2476 mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command)); 2483 2477 mr_free(command); 2484 for (p = tmp + strlen(tmp); p != tmp && *p != '`' && *p != ' '; 2485 p--); 2478 for (p = tmp + strlen(tmp); p != tmp && *p != '`' && *p != ' '; p--); 2486 2479 p++; 2487 2480 mr_asprintf(scratch, "%s", p); … … 2506 2499 lstat(curr_fname, &statbuf); 2507 2500 } 2508 strcpy(output, curr_fname);2501 mr_asprintf(output, "%s", curr_fname); 2509 2502 log_it("resolved %s to %s", incoming, output); 2510 2503 } … … 2521 2514 char *which_partition_format(const char *drive) 2522 2515 { 2523 static char output[4];2516 char *output; 2524 2517 char *tmp = NULL; 2525 2518 char *command = NULL; … … 2538 2531 2539 2532 if (strstr(tmp, "GPT") == NULL) { 2540 strcpy(output, "MBR");2533 mr_asprintf(output, "MBR"); 2541 2534 } else { 2542 strcpy(output, "GPT");2535 mr_asprintf(output, "GPT"); 2543 2536 } 2544 2537 mr_free(tmp);
Note:
See TracChangeset
for help on using the changeset viewer.