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