Changeset 2392 in MondoRescue
- Timestamp:
- Sep 11, 2009, 3:22:01 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.2.10/mondo/src/common/libmondo-fork.c
r2383 r2392 32 32 * @param call The program to run. 33 33 * @return The last line of its output. 34 * @note The returned value points to static storage that will be overwritten with each call.34 * @note The returned value points to an allocated string that the caller needs to free 35 35 */ 36 36 char *call_program_and_get_last_line_of_output(char *call) … … 38 38 /*@ buffers ***************************************************** */ 39 39 char *result = NULL; 40 char *p = NULL; 40 41 41 42 /*@ pointers **************************************************** */ … … 45 46 46 47 assert_string_is_neither_NULL_nor_zerolength(call); 48 49 log_msg(4, "Calling command: %s", call); 50 /* By default return an empty string in any case */ 51 mr_asprintf(result, ""); 52 53 /* popen seems to always return an empty line after the interesting last line result */ 47 54 if ((fin = popen(call, "r"))) { 48 for (mr_getline(result, fin); !feof(fin); mr_getline(result, fin)); 55 while (!feof(fin)) { 56 mr_getline(p, fin); 57 log_msg(9, "p: %s", p); 58 if ((p != NULL) && (strlen(p) > 1)) { 59 mr_free(result); 60 mr_asprintf(result, "%s", p); 61 log_msg(9, "Result: %s", result); 62 } 63 mr_free(p); 64 } 65 log_msg(4, "Result: %s", result); 66 mr_strip_spaces(result); 49 67 paranoid_pclose(fin); 50 68 } else { 51 69 log_OS_error("Unable to popen call"); 52 70 } 53 mr_strip_spaces(result);71 log_msg(4, "Returns: %s", result); 54 72 return(result); 55 73 }
Note:
See TracChangeset
for help on using the changeset viewer.