source: MondoRescue/trunk/mondo/src/common/libmondo-files.c@ 839

Last change on this file since 839 was 839, checked in by Bruno Cornec, 18 years ago

merge -r814:838 $SVN_M/branches/stable

  • Property svn:keywords set to Id
File size: 34.8 KB
RevLine 
[171]1/* $Id: libmondo-files.c 839 2006-09-26 07:47:32Z bruno $
2 * file manipulation
[1]3*/
4
5/**
6 * @file
7 * Functions to manipulate files.
8 */
9
10
11#include "my-stuff.h"
12#include "mondostructures.h"
13#include "libmondo-files.h"
14
15#include "libmondo-tools-EXT.h"
[507]16#include "newt-specific-EXT.h"
[1]17#include "libmondo-devices-EXT.h"
18#include "libmondo-fork-EXT.h"
19#include "libmondo-string-EXT.h"
20
21/*@unused@*/
[59]22//static char cvsid[] = "$Id: libmondo-files.c 839 2006-09-26 07:47:32Z bruno $";
[1]23
[688]24extern char **err_log_lines;
[1]25
26extern int g_currentY;
[783]27extern int g_noof_log_lines;
[1]28extern char *g_mondo_home;
29
30/**
31 * @addtogroup fileGroup
32 * @{
33 */
34/**
35 * Get an md5 checksum of the specified file.
36 * @param filename The file to checksum.
37 * @return The 32-character ASCII representation of the 128-bit checksum.
38 * @note The returned string points to static storage that will be overwritten with each call.
39 */
[59]40char *calc_checksum_of_file(char *filename)
[1]41{
[59]42 /*@ buffers ***************************************************** */
[171]43 static char *output = NULL;
44 char *command;
45 char *tmp;
46 size_t n = 0;
[1]47
[59]48 /*@ pointers **************************************************** */
49 char *p;
50 FILE *fin;
[1]51
[59]52 /*@ initialize pointers ***************************************** */
[1]53
[59]54 p = output;
[1]55
[59]56 /*@************************************************************** */
[1]57
[59]58 assert_string_is_neither_NULL_nor_zerolength(filename);
[171]59
[59]60 if (does_file_exist(filename)) {
[171]61 asprintf(&command, "md5sum \"%s\"", filename);
[59]62 fin = popen(command, "r");
[171]63 paranoid_free(command);
64
[59]65 if (fin) {
[171]66 (void) getline(&output, &n, fin);
[59]67 p = strchr(output, ' ');
68 paranoid_pclose(fin);
69 }
70 } else {
[171]71 asprintf(&tmp, "File '%s' not found; cannot calc checksum",
[59]72 filename);
73 log_it(tmp);
[171]74 paranoid_free(tmp);
[1]75 }
[59]76 if (p) {
77 *p = '\0';
78 }
79 return (output);
[1]80}
81
82
83/**
84 * Get the number of lines in @p filename.
85 * @param filename The file to count lines in.
86 * @return The number of lines in @p filename.
87 * @bug This function uses the shell and "wc -l"; it should probably be rewritten in C.
88 */
[59]89long count_lines_in_file(char *filename)
[1]90{
91
[59]92 /*@ buffers ***************************************************** */
[171]93 char *command;
94 char *incoming = NULL;
95 char *tmp;
[1]96
[59]97 /*@ long ******************************************************** */
98 long noof_lines = -1L;
[1]99
[171]100 /*@ int ******************************************************** */
101 size_t n = 0;
102
[59]103 /*@ pointers **************************************************** */
104 FILE *fin;
[1]105
[59]106 assert_string_is_neither_NULL_nor_zerolength(filename);
107 if (!does_file_exist(filename)) {
[171]108 asprintf(&tmp,
[59]109 "%s does not exist, so I cannot found the number of lines in it",
110 filename);
111 log_it(tmp);
[171]112 paranoid_free(tmp);
[59]113 return (0);
[1]114 }
[171]115 asprintf(&command, "cat %s | wc -l", filename);
[59]116 if (!does_file_exist(filename)) {
117 return (-1);
[1]118 }
[59]119 fin = popen(command, "r");
[171]120 paranoid_free(command);
121
[59]122 if (fin) {
123 if (feof(fin)) {
124 noof_lines = 0;
125 } else {
[171]126 (void) getline(&incoming, &n, fin);
[59]127 while (strlen(incoming) > 0
128 && incoming[strlen(incoming) - 1] < 32) {
129 incoming[strlen(incoming) - 1] = '\0';
130 }
131 noof_lines = atol(incoming);
[171]132 paranoid_free(incoming);
[59]133 }
134 paranoid_pclose(fin);
135 }
136 return (noof_lines);
[1]137}
138
139
140/**
141 * Check for existence of given @p filename.
142 * @param filename The file to check for.
143 * @return TRUE if it exists, FALSE otherwise.
144 */
[59]145bool does_file_exist(char *filename)
[1]146{
147
[59]148 /*@ structures ************************************************** */
149 struct stat buf;
[1]150
[59]151 /*@************************************************************** */
[1]152
[59]153 assert(filename != NULL);
[171]154
[59]155 if (lstat(filename, &buf)) {
156 log_msg(20, "%s does not exist", filename);
157 return (FALSE);
158 } else {
159 log_msg(20, "%s exists", filename);
160 return (TRUE);
161 }
[1]162}
163
164
165/**
166 * Modify @p inout (a file containing a list of files) to only contain files
167 * that exist.
168 * @param inout The filelist to operate on.
169 * @note The original file is renamed beforehand, so it will not be accessible
170 * while the modification is in progress.
171 */
[59]172void exclude_nonexistent_files(char *inout)
[1]173{
[171]174 char *infname;
175 char *outfname;
176 char *tmp;
177 char *incoming = NULL;
[1]178
[59]179 /*@ int ********************************************************* */
180 int i;
[171]181 size_t n = 0;
[1]182
[59]183 /*@ pointers **************************************************** */
184 FILE *fin, *fout;
[1]185
186
[59]187 /*@ end vars *********************************************************** */
[1]188
[59]189 assert_string_is_neither_NULL_nor_zerolength(inout);
[171]190
191 asprintf(&infname, "%s.in", inout);
192
193 asprintf(&tmp, "cp -f %s %s", inout, infname);
[59]194 run_program_and_log_output(tmp, FALSE);
[171]195 paranoid_free(tmp);
196
[59]197 if (!(fin = fopen(infname, "r"))) {
198 log_OS_error("Unable to openin infname");
[171]199 paranoid_free(infname);
[59]200 return;
[1]201 }
[171]202
203 asprintf(&outfname, "%s", inout);
[59]204 if (!(fout = fopen(outfname, "w"))) {
205 log_OS_error("Unable to openout outfname");
[171]206 paranoid_free(outfname);
[59]207 return;
[1]208 }
[171]209 paranoid_free(outfname);
210
211 for (getline(&incoming, &n, fin); !feof(fin);
212 getline(&incoming, &n, fin)) {
[59]213 i = strlen(incoming) - 1;
214 if (i >= 0 && incoming[i] < 32) {
215 incoming[i] = '\0';
216 }
217 if (does_file_exist(incoming)) {
218 fprintf(fout, "%s\n", incoming);
219 } else {
[171]220 asprintf(&tmp, "Excluding '%s'-nonexistent\n", incoming);
[59]221 log_it(tmp);
[171]222 paranoid_free(tmp);
[59]223 }
[1]224 }
[171]225 paranoid_free(incoming);
[59]226 paranoid_fclose(fout);
227 paranoid_fclose(fin);
228 unlink(infname);
[171]229 paranoid_free(infname);
[1]230}
231
232
233/**
234 * Attempt to find the user's kernel by calling Mindi.
235 * If Mindi can't find the kernel, ask user. If @p kernel is not empty,
236 * don't do anything.
237 * @param kernel Where to put the found kernel.
238 * @return 0 for success, 1 for failure.
239 */
[59]240int figure_out_kernel_path_interactively_if_necessary(char *kernel)
[1]241{
[688]242 char *tmp = NULL;
243 char *command = NULL;
[1]244
[688]245 if (kernel == NULL) {
246 kernel = call_program_and_get_last_line_of_output
[783]247 ("mindi --findkernel 2> /dev/null");
[59]248 }
[393]249 // If we didn't get anything back, check whether mindi raised a fatal error
[688]250 if (kernel == NULL) {
[393]251 asprintf(&command, "grep 'Fatal error' /var/log/mindi.log");
[688]252 tmp = call_program_and_get_last_line_of_output(command);
[393]253 if (strlen(tmp) > 1) {
254 popup_and_OK(tmp);
255 fatal_error("Mindi gave a fatal error. Please check '/var/log/mindi.log'.");
256 }
257 paranoid_free(command);
258 paranoid_free(tmp);
259 }
[688]260
261 if (kernel != NULL) {
262 log_it("Calling Mindi with kernel path of '%s'", kernel);
263 } else {
264 log_it("Calling Mindi without kernel, so asking one");
265 }
266
267 while (kernel == NULL) {
[59]268 if (!ask_me_yes_or_no
[507]269 (_("Kernel not found or invalid. Choose another?"))) {
[59]270 return (1);
271 }
272 if (!popup_and_get_string
[507]273 (_("Kernel path"),
274 _("What is the full path and filename of your kernel, please?"),
[688]275 kernel)) {
[59]276 fatal_error
277 ("Kernel not found. Please specify with the '-k' flag.");
278 }
[688]279 log_it("User says kernel is at %s", kernel);
[59]280 }
281 return (0);
[1]282}
283
284
285/**
286 * Find location of specified executable in user's PATH.
287 * @param fname The basename of the executable to search for (e.g. @c afio).
288 * @return The full path to the executable, or "" if it does not exist, or NULL if @c file could not be found.
289 * @note The returned string points to static storage that will be overwritten with each call.
290 * @bug The checks with @c file and @c dirname seem pointless. If @c incoming is "", then you're calling
291 * <tt>dirname 2\>/dev/null</tt> or <tt>file 2\>/dev/null | cut -d':' -f1 2\>/dev/null</tt>, which basically amounts
292 * to nothing.
293 */
[59]294char *find_home_of_exe(char *fname)
[1]295{
[59]296 /*@ buffers ********************* */
[688]297 char *output = NULL;
298 char *incoming = NULL;
299 char *command = NULL;
[1]300
[59]301 /*@******************************* */
[1]302
[59]303 assert_string_is_neither_NULL_nor_zerolength(fname);
[688]304
[171]305 asprintf(&command, "which %s 2> /dev/null", fname);
[688]306 incoming = call_program_and_get_last_line_of_output(command);
[171]307 paranoid_free(command);
308
[688]309 if (incoming == NULL) {
[59]310 if (system("which file > /dev/null 2> /dev/null")) {
311 return (NULL); // forget it :)
312 }
[171]313 asprintf(&command,
[59]314 "file %s 2> /dev/null | cut -d':' -f1 2> /dev/null",
315 incoming);
[171]316 paranoid_free(incoming);
317
[688]318 incoming = call_program_and_get_last_line_of_output(command);
[171]319 paranoid_free(command);
[59]320 }
[688]321 if (incoming == NULL) // yes, it is == '\0' twice, not once :)
[1]322 {
[171]323 asprintf(&command, "dirname %s 2> /dev/null", incoming);
324 paranoid_free(incoming);
325
[688]326 incoming = call_program_and_get_last_line_of_output(command);
[171]327 paranoid_free(command);
[1]328 }
[688]329 output = incoming;
[171]330
[688]331 if (output != NULL && does_file_exist(output)) {
332 log_msg(4, "find_home_of_exe () --- Found %s at %s", fname, output);
[59]333 } else {
[688]334 paranoid_free(output);
[59]335 log_msg(4, "find_home_of_exe() --- Could not find %s", fname);
336 }
[688]337 return (output);
[1]338}
339
340
341/**
342 * Get the last sequence of digits surrounded by non-digits in the first 32k of
343 * a file.
344 * @param logfile The file to look in.
345 * @return The number found, or 0 if none.
346 */
[59]347int get_trackno_from_logfile(char *logfile)
[1]348{
349
[59]350 /*@ pointers ********************************************************* */
351 FILE *fin;
[1]352
[59]353 /*@ int ************************************************************** */
354 int trackno = 0;
355 size_t len = 0;
[1]356
[59]357 /*@ buffer ************************************************************ */
358 char datablock[32701];
[1]359
[59]360 assert_string_is_neither_NULL_nor_zerolength(logfile);
[171]361
[59]362 if (!(fin = fopen(logfile, "r"))) {
363 log_OS_error("Unable to open logfile");
364 fatal_error("Unable to open logfile to read trackno");
365 }
366 len = fread(datablock, 1, 32700, fin);
367 paranoid_fclose(fin);
368 if (len <= 0) {
369 return (0);
370 }
371 for (; len > 0 && !isdigit(datablock[len - 1]); len--);
372 datablock[len--] = '\0';
373 for (; len > 0 && isdigit(datablock[len - 1]); len--);
374 trackno = atoi(datablock + len);
375 return (trackno);
[1]376}
377
378
379/**
380 * Get a percentage from the last line of @p filename. We look for the string
381 * "% done" on the last line and, if we find it, grab the number before the last % sign.
382 * @param filename The file to get the percentage from.
383 * @return The percentage found, or 0 for error.
384 */
[59]385int grab_percentage_from_last_line_of_file(char *filename)
[1]386{
387
[688]388 char *lastline = NULL;
389 char *command = NULL;
390 char *p = NULL;
[59]391 int i;
[1]392
[688]393 for (i = g_noof_log_lines - 1;
[59]394 i >= 0 && !strstr(err_log_lines[i], "% Done")
395 && !strstr(err_log_lines[i], "% done"); i--);
396 if (i < 0) {
[171]397 asprintf(&command,
[687]398 "tail -n3 %s | grep -Fi \"%c\" | tail -n1 | awk '{print $0;}'",
[59]399 filename, '%');
[688]400 lastline = call_program_and_get_last_line_of_output(command);
[171]401 paranoid_free(command);
[688]402 if (!lastline) {
[59]403 return (0);
404 }
405 } else {
[171]406 asprintf(&lastline, err_log_lines[i]);
[1]407 }
408
[59]409 p = strrchr(lastline, '%');
410 if (p) {
411 *p = '\0';
412 }
413 if (!p) {
[171]414 paranoid_free(lastline);
[59]415 return (0);
416 }
417 *p = '\0';
418 for (p--; *p != ' ' && p != lastline; p--);
419 if (p != lastline) {
420 p++;
421 }
422 i = atoi(p);
[171]423 paranoid_free(lastline);
[1]424
[59]425 return (i);
[1]426}
427
428
429/**
430 * Return the last line of @p filename.
431 * @param filename The file to get the last line of.
432 * @return The last line of the file.
433 * @note The returned string points to static storage that will be overwritten with each call.
434 */
[59]435char *last_line_of_file(char *filename)
[1]436{
[59]437 /*@ buffers ***************************************************** */
[688]438 char *output = NULL;
439 char *command = NULL;
440 char *tmp = NULL;
[1]441
[59]442 /*@ pointers **************************************************** */
443 FILE *fin;
[688]444 size_t n = 0;
[1]445
[59]446 /*@ end vars **************************************************** */
[1]447
[59]448 if (!does_file_exist(filename)) {
[507]449 asprintf(&tmp, _("Tring to get last line of nonexistent file (%s)"),
[59]450 filename);
451 log_it(tmp);
[171]452 paranoid_free(tmp);
[783]453 return (NULL);
[59]454 }
[171]455 asprintf(&command, "tail -n1 %s", filename);
[59]456 fin = popen(command, "r");
[171]457 paranoid_free(command);
458
[688]459 getline(&output, &n, fin);
[59]460 paranoid_pclose(fin);
461 while (strlen(output) > 0 && output[strlen(output) - 1] < 32) {
462 output[strlen(output) - 1] = '\0';
463 }
464 return (output);
[1]465}
466
[171]467
[1]468/**
469 * Get the length of @p filename in bytes.
470 * @param filename The file to get the length of.
471 * @return The length of the file, or -1 for error.
472 */
[687]473off_t length_of_file(char *filename)
[1]474{
[59]475 /*@ pointers *************************************************** */
476 FILE *fin;
[1]477
[59]478 /*@ long long ************************************************* */
[687]479 off_t length;
[1]480
[59]481 fin = fopen(filename, "r");
482 if (!fin) {
483 log_it("filename=%s", filename);
484 log_OS_error("Unable to openin filename");
485 return (-1);
486 }
[416]487 fseeko(fin, 0, SEEK_END);
[687]488 length = ftello(fin);
[59]489 paranoid_fclose(fin);
490 return (length);
[1]491}
492
493
494/**
495 * Create the directory @p outdir_fname and all parent directories. Equivalent to <tt>mkdir -p</tt>.
496 * @param outdir_fname The directory to create.
497 * @return The return value of @c mkdir.
498 */
[87]499/* BERLIOS: This function shouldn't call system at all */
[59]500int make_hole_for_dir(char *outdir_fname)
[1]501{
[171]502 char *tmp;
[59]503 int res = 0;
[1]504
[59]505 assert_string_is_neither_NULL_nor_zerolength(outdir_fname);
[171]506 asprintf(&tmp, "mkdir -p %s", outdir_fname);
[59]507 res = system(tmp);
[171]508 paranoid_free(tmp);
[59]509 return (res);
[1]510}
511
512
513/**
514 * Create the parent directories of @p outfile_fname.
515 * @param outfile_fname The file to make a "hole" for.
516 * @return 0, always.
517 * @bug Return value unnecessary.
518 */
[87]519/* BERLIOS: This function shouldn't call system at all */
[59]520int make_hole_for_file(char *outfile_fname)
[1]521{
[59]522 /*@ buffer ****************************************************** */
[171]523 char *command;
[1]524
[59]525 /*@ int ******************************************************** */
526 int res = 0;
[1]527
[59]528 /*@ end vars *************************************************** */
[1]529
[59]530 assert_string_is_neither_NULL_nor_zerolength(outfile_fname);
531 assert(!strstr(outfile_fname, MNT_CDROM));
532 assert(!strstr(outfile_fname, "/dev/cdrom"));
[171]533
534 asprintf(&command, "mkdir -p \"%s\" 2> /dev/null", outfile_fname);
[59]535 res += system(command);
[171]536 paranoid_free(command);
537
538 asprintf(&command, "rmdir \"%s\" 2> /dev/null", outfile_fname);
[59]539 res += system(command);
[171]540 paranoid_free(command);
541
542 asprintf(&command, "rm -f \"%s\" 2> /dev/null", outfile_fname);
[59]543 res += system(command);
[171]544 paranoid_free(command);
[59]545 unlink(outfile_fname);
546 return (0);
[1]547}
548
549
550/**
551 * Get the number of lines in @p filelist_fname that contain the string @p wildcard.
552 * @param filelist_fname The file to search through.
553 * @param wildcard The string to search for. This is @e not a shell glob or a regular expression.
554 * @return The number of lines matched.
555 */
[59]556long noof_lines_that_match_wildcard(char *filelist_fname, char *wildcard)
[1]557{
[59]558 /*@ long ******************************************************* */
559 long matches = 0;
[1]560
[59]561 /*@ pointers *************************************************** */
562 FILE *fin;
[1]563
[59]564 /*@ buffers **************************************************** */
[171]565 char *incoming = NULL;
[1]566
[171]567 size_t n = 0;
[59]568 /*@ end vars *************************************************** */
[1]569
570
[59]571 fin = fopen(filelist_fname, "r");
[1]572
[59]573 if (!fin) {
574 log_OS_error("Unable to openin filelist_fname");
575 return (0);
[1]576 }
[171]577 (void) getline(&incoming, &n, fin);
[59]578 while (!feof(fin)) {
579 if (strstr(incoming, wildcard)) {
580 matches++;
581 }
[171]582 (void) getline(&incoming, &n, fin);
[59]583 }
584 paranoid_fclose(fin);
[171]585 paranoid_free(incoming);
[59]586 return (matches);
[1]587}
588
589
590/**
591 * Register our PID in a file in /var/run.
592 * The PID will be put in /var/run/monitas-<tt>name_str</tt>.pid.
593 * @param pid 0 to remove file, anything else to create it.
594 * @param name_str The basename of the PID file (e.g. "mondo" or "server")
595 * @note This function does not provide support against multiple instances, unless you check for that yourself.
596 */
[59]597void register_pid(pid_t pid, char *name_str)
[1]598{
[171]599 char *tmp;
600 char *lockfile_fname;
[59]601 int res;
[171]602 size_t n = 0;
[59]603 FILE *fin;
[1]604
[171]605 asprintf(&lockfile_fname, "/var/run/monitas-%s.pid", name_str);
[59]606 if (!pid) {
607 log_it("Unregistering PID");
608 if (unlink(lockfile_fname)) {
609 log_it("Error unregistering PID");
610 }
[171]611 paranoid_free(lockfile_fname);
[59]612 return;
613 }
614 if (does_file_exist(lockfile_fname)) {
615 if ((fin = fopen(lockfile_fname, "r"))) {
[171]616 (void) getline(&tmp, &n, fin);
[59]617 paranoid_fclose(fin);
618 } else {
619 log_OS_error("Unable to openin lockfile_fname");
620 }
621 pid = (pid_t) atol(tmp);
[171]622 paranoid_free(tmp);
623
624 asprintf(&tmp, "ps %ld > /dev/null 2> /dev/null", (long int) pid);
[59]625 res = system(tmp);
[171]626 paranoid_free(tmp);
[59]627 if (!res) {
628 log_it
629 ("I believe the daemon is already running. If it isn't, please delete %s and try again.",
630 lockfile_fname);
631 }
632 }
[171]633 asprintf(&tmp, "echo %ld > %s 2> /dev/null", (long int) getpid(),
[59]634 lockfile_fname);
[171]635 paranoid_free(lockfile_fname);
636
[59]637 if (system(tmp)) {
638 fatal_error("Cannot register PID");
639 }
[171]640 paranoid_free(tmp);
641 return;
[1]642}
643
644
645/**
646 * Determine the size (in KB) of @p dev in the mountlist in <tt>tmpdir</tt>/mountlist.txt.
647 * @param tmpdir The tempdir where the mountlist is stored.
648 * @param dev The device to search for.
649 * @return The size of the partition in KB.
650 */
[59]651long size_of_partition_in_mountlist_K(char *tmpdir, char *dev)
[1]652{
[688]653 char *command = NULL;
654 char *sz_res = NULL;
655 long file_len_K = 0L;
[59]656
[171]657 asprintf(&command,
658 "grep '%s ' %s/mountlist.txt | head -n1 | awk '{print $4;}'",
659 dev, tmpdir);
[59]660 log_it(command);
[688]661 sz_res = call_program_and_get_last_line_of_output(command);
[59]662 file_len_K = atol(sz_res);
663 log_msg(4, "%s --> %s --> %ld", command, sz_res, file_len_K);
[171]664 paranoid_free(command);
665 paranoid_free(sz_res);
[59]666 return (file_len_K);
[1]667}
668
[171]669
[1]670/**
671 * Calculate the total size (in KB) of all the biggiefiles in this backup.
672 * @param bkpinfo The backup information structure. Only the @c bkpinfo->tmpdir field is used.
673 * @return The total size of all biggiefiles in KB.
674 */
[59]675long size_of_all_biggiefiles_K(struct s_bkpinfo *bkpinfo)
[1]676{
[688]677 char *fname = NULL;
678 char *biggielist = NULL;
679 char *comment = NULL;
680 char *tmp = NULL;
681 char *command = NULL;
[1]682
[59]683 /*@ long ******************************************************** */
[688]684 long scratchL = 0L;
685 long file_len_K = 0L;
[1]686
[59]687 /*@ pointers *************************************************** */
688 FILE *fin = NULL;
[171]689 size_t n = 0;
[1]690
[59]691 /*@ end vars *************************************************** */
[1]692
[59]693 log_it("Calculating size of all biggiefiles (in total)");
[171]694 asprintf(&biggielist, "%s/biggielist.txt", bkpinfo->tmpdir);
[59]695 log_it("biggielist = %s", biggielist);
696 if (!(fin = fopen(biggielist, "r"))) {
697 log_OS_error
698 ("Cannot open biggielist. OK, so estimate is based on filesets only.");
699 } else {
700 log_msg(4, "Reading it...");
[171]701 for (getline(&fname, &n, fin); !feof(fin);
702 getline(&fname, &n, fin)) {
[59]703 if (fname[strlen(fname) - 1] <= 32) {
704 fname[strlen(fname) - 1] = '\0';
705 }
706 if (0 == strncmp(fname, "/dev/", 5)) {
[300]707 if (is_dev_an_NTFS_dev(fname)) {
[689]708 tmp = find_home_of_exe("ntfsresize");
709 if (!tmp) {
[300]710 fatal_error("ntfsresize not found");
711 }
[689]712 paranoid_free(tmp);
713
[688]714 asprintf(&command, "ntfsresize --force --info %s|grep '^You might resize at '|cut -d' ' -f5", fname);
[300]715 log_it("command = %s", command);
[688]716 tmp = call_program_and_get_last_line_of_output(command);
717 paranoid_free(command);
718
[300]719 log_it("res of it = %s", tmp);
720 file_len_K = atoll(tmp) / 1024L;
[688]721 paranoid_free(tmp);
[300]722 } else {
723 file_len_K = get_phys_size_of_drive(fname) * 1024L;
724 }
[59]725 } else {
[687]726 /* BERLIOS: more than long here ??? */
[59]727 file_len_K = (long) (length_of_file(fname) / 1024);
728 }
729 if (file_len_K > 0) {
730 scratchL += file_len_K;
731 log_msg(4, "%s --> %ld K", fname, file_len_K);
732 }
[171]733 asprintf(&comment,
[59]734 "After adding %s, scratchL+%ld now equals %ld", fname,
735 file_len_K, scratchL);
736 log_msg(4, comment);
[171]737 paranoid_free(comment);
738
[59]739 if (feof(fin)) {
740 break;
741 }
742 }
[171]743 paranoid_free(fname);
[1]744 }
[171]745 paranoid_free(biggielist);
746
[59]747 log_it("Closing...");
748 paranoid_fclose(fin);
749 log_it("Finished calculating total size of all biggiefiles");
750 return (scratchL);
[1]751}
752
[171]753
[1]754/**
755 * Determine the amount of space (in KB) occupied by a mounted CD.
756 * This can also be used to find the space used for other directories.
757 * @param mountpt The mountpoint/directory to check.
758 * @return The amount of space occupied in KB.
759 */
[59]760long long space_occupied_by_cd(char *mountpt)
[1]761{
[59]762 /*@ buffer ****************************************************** */
[171]763 char *tmp = NULL;
[688]764 char *command = NULL;
[59]765 long long llres;
[171]766 size_t n = 0;
[59]767 /*@ pointers **************************************************** */
[688]768 char *p = NULL;
769 FILE *fin = NULL;
[1]770
[59]771 /*@ end vars *************************************************** */
[1]772
[171]773 asprintf(&command, "du -sk %s", mountpt);
[839]774 errno = 0;
[59]775 fin = popen(command, "r");
[839]776 if (errno) {
777 log_it("popen() FAILED: command=%s, mountpt=%s, fin=%d, errno=%d, strerror=%s", command, mountpt, fin, errno, strerror(errno));
778 llres = 0;
779 } else {
780 (void) getline(&tmp, &n, fin);
781 paranoid_pclose(fin);
782 p = strchr(tmp, '\t');
783 if (p) {
784 *p = '\0';
785 }
786 for (p = tmp, llres = 0; *p != '\0'; p++) {
787 llres *= 10;
788 llres += (int) (*p - '0');
789 }
790 }
791
[171]792 paranoid_free(command);
793 paranoid_free(tmp);
[59]794 return (llres);
[1]795}
796
797
798/**
799 * Update a CRC checksum to include another character.
800 * @param crc The original CRC checksum.
801 * @param c The character to add.
802 * @return The new CRC checksum.
803 * @ingroup utilityGroup
804 */
[59]805unsigned int updcrc(unsigned int crc, unsigned int c)
[1]806{
[59]807 unsigned int tmp;
808 tmp = (crc >> 8) ^ c;
809 crc = (crc << 8) ^ crctttab[tmp & 255];
810 return crc;
[1]811}
812
[171]813
[1]814/**
815 * Update a reverse CRC checksum to include another character.
816 * @param crc The original CRC checksum.
817 * @param c The character to add.
818 * @return The new CRC checksum.
819 * @ingroup utilityGroup
820 */
[59]821unsigned int updcrcr(unsigned int crc, unsigned int c)
[1]822{
[59]823 unsigned int tmp;
824 tmp = crc ^ c;
825 crc = (crc >> 8) ^ crc16tab[tmp & 0xff];
826 return crc;
[1]827}
828
829
830/**
831 * Check for an executable on the user's system; write a message to the
832 * screen and the log if we can't find it.
833 * @param fname The executable basename to look for.
834 * @return 0 if it's found, nonzero if not.
835 */
[59]836int whine_if_not_found(char *fname)
[1]837{
[59]838 /*@ buffers *** */
[171]839 char *command;
840 char *errorstr;
841 int res = 0;
[1]842
843
[171]844 asprintf(&command, "which %s > /dev/null 2> /dev/null", fname);
845 res = system(command);
846 paranoid_free(command);
847
848 if (res) {
849 asprintf(&errorstr,
[507]850 _("Please install '%s'. I cannot find it on your system."),
[59]851 fname);
852 log_to_screen(errorstr);
[171]853 paranoid_free(errorstr);
[59]854 log_to_screen
[507]855 (_("There may be an hyperlink at http://www.mondorescue.org which"));
856 log_to_screen(_("will take you to the relevant (missing) package."));
[59]857 return (1);
858 } else {
859 return (0);
860 }
[1]861}
862
863
864/**
865 * Create a data file at @p fname containing @p contents.
866 * The data actually can be multiple lines, despite the name.
867 * @param fname The file to create.
868 * @param contents The data to put in it.
869 * @return 0 for success, 1 for failure.
870 */
[59]871int write_one_liner_data_file(char *fname, char *contents)
[1]872{
[59]873 /*@ pointers *************************************************** */
874 FILE *fout;
875 int res = 0;
[1]876
[59]877 /*@ end vars *************************************************** */
[1]878
[59]879 assert_string_is_neither_NULL_nor_zerolength(fname);
880 if (!contents) {
881 log_it("%d: Warning - writing NULL to %s", __LINE__, fname);
882 }
883 if (!(fout = fopen(fname, "w"))) {
884 log_it("fname=%s");
885 log_OS_error("Unable to openout fname");
886 return (1);
887 }
888 fprintf(fout, "%s\n", contents);
889 paranoid_fclose(fout);
890 return (res);
[1]891}
892
893
894/**
895 * Read @p fname into @p contents.
896 * @param fname The file to read.
897 * @param contents Where to put its contents.
898 * @return 0 for success, nonzero for failure.
899 */
[59]900int read_one_liner_data_file(char *fname, char *contents)
[1]901{
[59]902 /*@ pointers *************************************************** */
903 FILE *fin;
904 int res = 0;
905 int i;
[1]906
[59]907 /*@ end vars *************************************************** */
[1]908
[59]909 assert_string_is_neither_NULL_nor_zerolength(fname);
910 if (!contents) {
911 log_it("%d: Warning - reading NULL from %s", __LINE__, fname);
912 }
913 if (!(fin = fopen(fname, "r"))) {
914 log_it("fname=%s", fname);
915 log_OS_error("Unable to openin fname");
916 return (1);
917 }
918 fscanf(fin, "%s\n", contents);
919 i = strlen(contents);
920 if (i > 0 && contents[i - 1] < 32) {
921 contents[i - 1] = '\0';
922 }
923 paranoid_fclose(fin);
924 return (res);
[1]925}
926
927
928/**
929 * Copy the files that Mondo/Mindi need to run to the scratchdir or tempdir.
930 * Currently this includes: copy Mondo's home directory to scratchdir, untar "mondo_home/payload.tgz"
931 * if it exists, copy LAST-FILELIST-NUMBER to scratchdir, copy mondorestore
932 * and post-nuke.tgz (if it exists) to tmpdir, and run "hostname > scratchdir/HOSTNAME".
933 * @param bkpinfo The backup information structure. Fields used:
934 * - @c bkpinfo->postnuke_tarball
935 * - @c bkpinfo->scratchdir
936 * - @c bkpinfo->tmpdir
937 */
[59]938void copy_mondo_and_mindi_stuff_to_scratchdir(struct s_bkpinfo *bkpinfo)
[1]939{
[59]940 /*@ Char buffers ** */
[171]941 char *command;
942 char *tmp;
[59]943 char old_pwd[MAX_STR_LEN];
[1]944
[59]945 mvaddstr_and_log_it(g_currentY, 0,
946 "Copying Mondo's core files to the scratch directory");
[1]947
[94]948 /* BERLIOS: Why do we need to do it here as well ? */
[59]949 log_msg(4, "g_mondo_home='%s'", g_mondo_home);
[94]950 if ((g_mondo_home == NULL) || strlen(g_mondo_home) < 2) {
951 paranoid_free(g_mondo_home);
952 g_mondo_home = find_and_store_mondoarchives_home();
[59]953 }
[171]954 asprintf(&command, CP_BIN " --parents -pRdf %s %s", g_mondo_home,
[59]955 bkpinfo->scratchdir);
[1]956
[59]957 log_msg(4, "command = %s", command);
958 if (run_program_and_log_output(command, 1)) {
959 fatal_error("Failed to copy Mondo's stuff to scratchdir");
960 }
[171]961 paranoid_free(command);
[1]962
[171]963 asprintf(&tmp, "%s/payload.tgz", g_mondo_home);
[507]964
965 /* i18n */
966 asprintf(&command, CP_BIN " --parents /usr/share/locale/*/LC_MESSAGES/mondo.mo %s",bkpinfo->scratchdir);
967 log_msg(4, "command = %s", command);
968 run_program_and_log_output(command, 1);
969 paranoid_free(command);
970
[59]971 if (does_file_exist(tmp)) {
972 log_it("Untarring payload %s to scratchdir %s", tmp,
973 bkpinfo->scratchdir);
974 (void) getcwd(old_pwd, MAX_STR_LEN - 1);
975 chdir(bkpinfo->scratchdir);
[171]976 asprintf(&command, "tar -zxvf %s", tmp);
[59]977 if (run_program_and_log_output(command, FALSE)) {
978 fatal_error("Failed to untar payload");
979 }
[171]980 paranoid_free(command);
[59]981 chdir(old_pwd);
982 }
[171]983 paranoid_free(tmp);
[1]984
[171]985 asprintf(&command, "cp -f %s/LAST-FILELIST-NUMBER %s", bkpinfo->tmpdir,
[59]986 bkpinfo->scratchdir);
987 if (run_program_and_log_output(command, FALSE)) {
988 fatal_error("Failed to copy LAST-FILELIST-NUMBER to scratchdir");
989 }
[171]990 paranoid_free(command);
[1]991
[688]992 tmp = call_program_and_get_last_line_of_output("which mondorestore");
993 if (!tmp) {
[59]994 fatal_error
995 ("'which mondorestore' returned null. Where's your mondorestore? `which` can't find it. That's odd. Did you install mondorestore?");
996 }
[171]997 asprintf(&command, "cp -f %s %s", tmp, bkpinfo->tmpdir);
998 paranoid_free(tmp);
999
[59]1000 if (run_program_and_log_output(command, FALSE)) {
1001 fatal_error("Failed to copy mondorestore to tmpdir");
1002 }
[171]1003 paranoid_free(command);
[1]1004
[171]1005 asprintf(&command, "hostname > %s/HOSTNAME", bkpinfo->scratchdir);
[59]1006 paranoid_system(command);
[171]1007 paranoid_free(command);
[1]1008
[783]1009 if (bkpinfo->postnuke_tarball) {
[171]1010 asprintf(&command, "cp -f %s %s/post-nuke.tgz",
[59]1011 bkpinfo->postnuke_tarball, bkpinfo->tmpdir);
1012 if (run_program_and_log_output(command, FALSE)) {
1013 fatal_error("Unable to copy post-nuke tarball to tmpdir");
1014 }
[171]1015 paranoid_free(command);
[59]1016 }
[1]1017
[59]1018 mvaddstr_and_log_it(g_currentY++, 74, "Done.");
[1]1019}
1020
1021
1022/**
1023 * Store the client's NFS configuration in files to be restored at restore-time.
1024 * Assumes that @c bkpinfo->media_type = nfs, but does not check for this.
1025 * @param bkpinfo The backup information structure. Fields used:
1026 * - @c nfs_mount
1027 * - @c nfs_remote_dir
1028 * - @c tmpdir
1029 */
[59]1030void store_nfs_config(struct s_bkpinfo *bkpinfo)
[1]1031{
1032
[59]1033 /*@ buffers ******** */
[688]1034 char *nfs_dev = NULL;
[808]1035 char *mac_addr = NULL;
[688]1036 char *nfs_mount = NULL;
1037 char *nfs_client_ipaddr = NULL;
1038 char *nfs_client_netmask = NULL;
1039 char *nfs_client_broadcast = NULL;
1040 char *nfs_client_defgw = NULL;
1041 char *nfs_server_ipaddr = NULL;
1042 char *tmp = NULL;
1043 char *command = NULL;
[1]1044
[59]1045 /*@ pointers ***** */
1046 char *p;
[1]1047
[59]1048 log_it("Storing NFS configuration");
[171]1049 asprintf(&tmp, bkpinfo->nfs_mount);
[59]1050 p = strchr(tmp, ':');
1051 if (!p) {
1052 fatal_error
1053 ("NFS mount doesn't have a colon in it, e.g. 192.168.1.4:/home/nfs");
1054 }
1055 *(p++) = '\0';
[171]1056 asprintf(&nfs_server_ipaddr, tmp);
1057 paranoid_free(tmp);
1058
1059 asprintf(&nfs_mount, p);
[808]1060 /* BERLIOS : there is a bug #67 here as it only considers the first NIC */
[171]1061 asprintf(&command,
[59]1062 "ifconfig | tr '\n' '#' | sed s/##// | tr '#' ' ' | tr '' '\n' | head -n1 | cut -d' ' -f1");
[688]1063 nfs_dev = call_program_and_get_last_line_of_output(command);
[171]1064 paranoid_free(command);
1065
1066 asprintf(&command,
[59]1067 "ifconfig | tr '\n' '#' | sed s/##// | tr '#' ' ' | tr '' '\\n' | head -n1 | tr -s '\t' ' ' | cut -d' ' -f7 | cut -d':' -f2");
[688]1068 nfs_client_ipaddr = call_program_and_get_last_line_of_output(command);
[171]1069 paranoid_free(command);
1070
1071 asprintf(&command,
[149]1072 "ifconfig | tr '\n' '#' | sed s/##// | tr '#' ' ' | tr '' '\\n' | head -n1 | tr -s '\t' ' ' | cut -d' ' -f9 | cut -d':' -f2");
[688]1073 nfs_client_netmask = call_program_and_get_last_line_of_output(command);
[171]1074 paranoid_free(command);
1075
1076 asprintf(&command,
[197]1077 "ifconfig | tr '\n' '#' | sed s/##// | tr '#' ' ' | tr '' '\\n' | head -n1 | tr -s '\t' ' ' | cut -d' ' -f8 | cut -d':' -f2");
[688]1078 nfs_client_broadcast = call_program_and_get_last_line_of_output(command);
1079 paranoid_free(command);
1080
1081 asprintf(&command,
[226]1082 "route -n | grep '^0.0.0.0' | awk '{print $2}'");
[688]1083 nfs_client_defgw = call_program_and_get_last_line_of_output(command);
[171]1084 paranoid_free(command);
1085
1086 asprintf(&tmp,
1087 "nfs_client_ipaddr=%s; nfs_client_netmask=%s; nfs_server_ipaddr=%s; nfs_mount=%s; nfs_client_defgw=%s; ",
1088 nfs_client_ipaddr, nfs_client_netmask, nfs_server_ipaddr, nfs_mount, nfs_client_defgw);
1089 paranoid_free(nfs_mount);
1090 log_it(tmp);
1091 paranoid_free(tmp);
1092
[59]1093 if (strlen(nfs_dev) < 2) {
1094 fatal_error
1095 ("Unable to find ethN (eth0, eth1, ...) adapter via NFS mount you specified.");
1096 }
1097 make_hole_for_dir("/var/cache/mondo-archive");
[808]1098 /********
1099 * If the NFS device that found above is a bonded device,
1100 * we need to replace it with an ethN device or the
1101 * networking will not start during an NFS restore.
1102 *
1103 * If the NFS device in nfs_dev begins with the word "bond",
1104 * look for the corresponding slave ethN device and copy it to nfs_dev.
1105 * Using the common MAC address
1106 ********/
1107 if (!strncmp(nfs_dev, "bond", 4)) {
1108 log_to_screen("Found bonding device %s; looking for corresponding ethN slave device\n", nfs_dev);
1109 asprintf(&command,
1110 "ifconfig %s | awk '{print $5}'", nfs_dev);
1111 mac_addr = call_program_and_get_last_line_of_output(command);
1112 asprintf(&command,
1113 "ifconfig | grep -E '%s' | head -n1 | cut -d' ' -f1", mac_addr);
1114 paranoid_free(nfs_dev);
1115 nfs_dev = call_program_and_get_last_line_of_output(command);
1116 paranoid_free(command);
1117 paranoid_free(mac_addr);
[1]1118
[808]1119 log_to_screen("Replacing it with %s\n", nfs_dev);
1120 }
1121
[171]1122 asprintf(&tmp, "%s/NFS-DEV", bkpinfo->tmpdir);
[59]1123 write_one_liner_data_file(tmp, nfs_dev);
[171]1124 paranoid_free(nfs_dev);
1125 paranoid_free(tmp);
[1]1126
[171]1127 asprintf(&tmp, "%s/NFS-CLIENT-IPADDR", bkpinfo->tmpdir);
[59]1128 write_one_liner_data_file(tmp, nfs_client_ipaddr);
[171]1129 paranoid_free(nfs_client_ipaddr);
1130 paranoid_free(tmp);
1131
1132 asprintf(&tmp, "%s/NFS-CLIENT-NETMASK", bkpinfo->tmpdir);
[149]1133 write_one_liner_data_file(tmp, nfs_client_netmask);
[171]1134 paranoid_free(nfs_client_netmask);
1135 paranoid_free(tmp);
1136
1137 asprintf(&tmp, "%s/NFS-CLIENT-DEFGW", bkpinfo->tmpdir);
[149]1138 write_one_liner_data_file(tmp, nfs_client_defgw);
[171]1139 paranoid_free(nfs_client_defgw);
1140 paranoid_free(tmp);
1141
[197]1142 asprintf(&tmp, "%s/NFS-CLIENT-BROADCAST", bkpinfo->tmpdir);
1143 write_one_liner_data_file(tmp, nfs_client_broadcast);
1144 paranoid_free(nfs_client_broadcast);
1145 paranoid_free(tmp);
1146
[171]1147 asprintf(&tmp, "%s/NFS-SERVER-IPADDR", bkpinfo->tmpdir);
[59]1148 write_one_liner_data_file(tmp, nfs_server_ipaddr);
[171]1149 paranoid_free(nfs_server_ipaddr);
1150 paranoid_free(tmp);
1151
1152 asprintf(&tmp, "%s/NFS-SERVER-MOUNT", bkpinfo->tmpdir);
[59]1153 write_one_liner_data_file(tmp, bkpinfo->nfs_mount);
[171]1154 paranoid_free(tmp);
1155
1156 asprintf(&tmp, "%s/NFS-SERVER-PATH", bkpinfo->tmpdir);
[59]1157 write_one_liner_data_file(tmp, bkpinfo->nfs_remote_dir);
[171]1158 paranoid_free(tmp);
1159
1160 asprintf(&tmp, "%s/ISO-PREFIX", bkpinfo->tmpdir);
[149]1161 write_one_liner_data_file(tmp, bkpinfo->prefix);
[171]1162 paranoid_free(tmp);
1163
[59]1164 log_it("Finished storing NFS configuration");
[1]1165}
1166
1167
1168/**
1169 * Determine the approximate number of media that the backup will take up,
1170 * and tell the user. The uncompressed size is estimated as size_of_all_biggiefiles_K()
1171 * plus (noof_sets x bkpinfo->optimal_set_size). The compression factor is estimated as
1172 * 2/3 for LZO and 1/2 for bzip2. The data is not saved anywhere. If there are any
1173 * "imagedevs", the estimate is not shown as it will be wildly inaccurate.
1174 * If there are more than 50 media estimated, the estimate will not be shown.
1175 * @param bkpinfo The backup information structure. Fields used:
1176 * - @c bkpinfo->backup_media_type
1177 * - @c bkpinfo->image_devs
1178 * - @c bkpinfo->media_size
1179 * - @c bkpinfo->optimal_set_size
1180 * - @c bkpinfo->use_lzo
1181 * @param noof_sets The number of filesets created.
1182 * @ingroup archiveGroup
1183 */
1184void
[59]1185estimate_noof_media_required(struct s_bkpinfo *bkpinfo, long noof_sets)
[1]1186{
[59]1187 /*@ buffers *************** */
[783]1188 char *tmp = NULL;
[1]1189
[59]1190 /*@ long long ************* */
1191 long long scratchLL;
[1]1192
[59]1193 if (bkpinfo->media_size[1] <= 0 || bkpinfo->backup_media_type == nfs) {
1194 log_to_screen("Number of media required: UNKNOWN");
1195 return;
1196 }
[1]1197
[59]1198 log_it("Estimating number of media required...");
1199 scratchLL =
1200 (long long) (noof_sets) * (long long) (bkpinfo->optimal_set_size)
1201 + (long long) (size_of_all_biggiefiles_K(bkpinfo));
1202 scratchLL = (scratchLL / 1024) / bkpinfo->media_size[1];
1203 scratchLL++;
1204 if (bkpinfo->use_lzo) {
1205 scratchLL = (scratchLL * 2) / 3;
1206 } else {
1207 scratchLL = scratchLL / 2;
1208 }
1209 if (!scratchLL) {
1210 scratchLL++;
1211 }
1212 if (scratchLL <= 1) {
[171]1213 asprintf(&tmp,
[507]1214 _("Your backup will probably occupy a single %s. Maybe two."),
[783]1215 bkpinfo->backup_media_string);
[59]1216 } else {
[507]1217 asprintf(&tmp, _("Your backup will occupy approximately %s media."),
[59]1218 number_to_text((int) (scratchLL + 1)));
1219 }
[783]1220 if (!bkpinfo->image_devs && (scratchLL < 50)) {
[59]1221 log_to_screen(tmp);
1222 }
[171]1223 paranoid_free(tmp);
1224 return;
[1]1225}
1226
1227
1228/**
1229 * Determine whether a file is compressed. This is done
1230 * by reading through the "do-not-compress-these" file distributed with Mondo.
1231 * @param filename The file to check.
1232 * @return TRUE if it's compressed, FALSE if not.
1233 */
[59]1234bool is_this_file_compressed(char *filename)
[1]1235{
[783]1236 char *do_not_compress_these = NULL;
1237 char *tmp = NULL;
1238 char *p = NULL;
[1]1239
[171]1240 asprintf(&tmp, "%s/do-not-compress-these", g_mondo_home);
[59]1241 if (!does_file_exist(tmp)) {
[171]1242 paranoid_free(tmp);
[59]1243 return (FALSE);
1244 }
[171]1245 paranoid_free(tmp);
1246
[688]1247 do_not_compress_these = last_line_of_file(tmp);
[59]1248 for (p = do_not_compress_these; p != NULL; p++) {
[171]1249 asprintf(&tmp, p);
[59]1250 if (strchr(tmp, ' ')) {
1251 *(strchr(tmp, ' ')) = '\0';
1252 }
[171]1253 if (!strcmp(strrchr(filename, '.'), tmp)) {
1254 paranoid_free(do_not_compress_these);
1255 paranoid_free(tmp);
[59]1256 return (TRUE);
1257 }
[171]1258 paranoid_free(tmp);
1259
[59]1260 if (!(p = strchr(p, ' '))) {
1261 break;
1262 }
1263 }
[171]1264 paranoid_free(do_not_compress_these);
[59]1265 return (FALSE);
[1]1266}
1267
1268
[59]1269int mode_of_file(char *fname)
[1]1270{
[59]1271 struct stat buf;
[1]1272
[59]1273 if (lstat(fname, &buf)) {
1274 return (-1);
1275 } // error
1276 else {
1277 return (buf.st_mode);
1278 }
[1]1279}
1280
1281
1282/**
1283 * Create a small script that mounts /boot, calls @c grub-install, and syncs the disks.
1284 * @param outfile Where to put the script.
1285 * @return 0 for success, 1 for failure.
1286 */
[59]1287int make_grub_install_scriptlet(char *outfile)
[1]1288{
[59]1289 FILE *fout;
1290 char *tmp;
1291 int retval = 0;
[1]1292
[59]1293 if ((fout = fopen(outfile, "w"))) {
1294 fprintf(fout,
1295 "#!/bin/sh\n\nmount /boot > /dev/null 2> /dev/null\ngrub-install $@\nres=$?\nsync;sync;sync\nexit $res\n");
1296 paranoid_fclose(fout);
1297 log_msg(2, "Created %s", outfile);
[171]1298 asprintf(&tmp, "chmod +x %s", outfile);
[59]1299 paranoid_system(tmp);
[171]1300 paranoid_free(tmp);
1301
[59]1302 retval = 0;
1303 } else {
1304 retval = 1;
[1]1305 }
[59]1306 return (retval);
[1]1307}
1308
1309/* @} - end fileGroup */
[171]1310
1311void paranoid_alloc(char *alloc, char *orig)
1312{
1313 paranoid_free(alloc);
1314 asprintf(&alloc, orig);
1315}
1316
Note: See TracBrowser for help on using the repository browser.