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