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