Ignore:
Timestamp:
Sep 10, 2009, 2:55:51 AM (15 years ago)
Author:
Bruno Cornec
Message:

call_program_and_get_last_line_of_output is now allocating memory and returning that string

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2.10/mondo/src/common/libmondo-tools.c

    r2382 r2383  
    225225    d = 5.2;                    // :-)
    226226#else
    227     mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output("uname -r"));
     227    tmp = call_program_and_get_last_line_of_output("uname -r");
    228228    p = strchr(tmp, '.');
    229229    if (p) {
     
    523523        if (getenv ("SUDO_COMMAND")) {
    524524            mr_asprintf(command, "strings `which growisofs` | grep -c SUDO_COMMAND");
    525             if (!strcmp(call_program_and_get_last_line_of_output(command), "1")) {
     525            tmp = call_program_and_get_last_line_of_output(command);
     526            if (!strcmp(tmp, "1")) {
    526527                mr_free(command);
     528                mr_free(tmp);
    527529                popup_and_OK("Fatal Error: Can't write DVDs as sudo because growisofs doesn't support this - see the growisofs manpage for details.");
    528530                fatal_error("Can't write DVDs as sudo because growisofs doesn't support this - see the growisofs manpage for details.");
    529531            }       
    530532            mr_free(command);
     533            mr_free(tmp);
    531534        }
    532535        log_msg(2, "call_make_iso (DVD res) is ... %s", bkpinfo->call_make_iso);
     
    613616        mr_asprintf(command, "df -P %s | tail -n1 | cut -d' ' -f1", bkpinfo->isodir);
    614617        log_it("command = %s", command);
    615         log_it("res of it = %s", call_program_and_get_last_line_of_output(command));
    616         mr_asprintf(iso_dev, "%s", call_program_and_get_last_line_of_output(command));
     618        iso_dev = call_program_and_get_last_line_of_output(command);
     619        log_it("res of it = %s", iso_dev);
    617620        mr_asprintf(tmp, "%s/ISO-DEV", bkpinfo->tmpdir);
    618         write_one_liner_data_file(tmp, call_program_and_get_last_line_of_output(command));
     621        write_one_liner_data_file(tmp, iso_dev);
    619622        mr_free(tmp);
    620623        mr_free(command);
     
    624627
    625628        log_it("command = %s", command);
    626         log_it("res of it = %s", call_program_and_get_last_line_of_output(command));
    627         mr_asprintf(iso_mnt, "%s", call_program_and_get_last_line_of_output(command));
     629        iso_mnt = call_program_and_get_last_line_of_output(command);
     630        log_it("res of it = %s", iso_mnt);
    628631        mr_asprintf(tmp, "%s/ISO-MNT", bkpinfo->tmpdir);
    629         write_one_liner_data_file(tmp, call_program_and_get_last_line_of_output(command));
     632        write_one_liner_data_file(tmp, iso_mnt);
    630633        mr_free(tmp);
    631634        mr_free(command);
     
    899902
    900903    mr_asprintf(command, "df -m -P %s | tail -n1 | tr -s ' ' '\t' | cut -f4", partition);
    901     mr_asprintf(out_sz, "%s", call_program_and_get_last_line_of_output(command));
     904    out_sz = call_program_and_get_last_line_of_output(command);
    902905    mr_free(command);
    903906
     
    941944        run_program_and_log_output("ln -sf `which mkfs.msdos` /sbin/mkfs.vfat", FALSE);
    942945    }
    943     mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output("free | grep Mem | head -n1 | tr -s ' ' '\t' | cut -f2"));
     946    tmp = call_program_and_get_last_line_of_output("free | grep Mem | head -n1 | tr -s ' ' '\t' | cut -f2");
    944947    if (atol(tmp) < 35000) {
    945948        retval++;
     
    10141017
    10151018    run_program_and_log_output("umount `mount | grep cdr | cut -d' ' -f3 | tr '\n' ' '`", 5);
    1016     mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output("mount | grep -E \"cdr(om|w)\""));
     1019    tmp = call_program_and_get_last_line_of_output("mount | grep -E \"cdr(om|w)\"");
    10171020    if (strcmp("", tmp)) {
    10181021        if (strstr(tmp, "autofs")) {
     
    11041107    } else {
    11051108        mr_asprintf(command, "grep '%s .*' %s| cut -d' ' -f2,3,4,5", label, config_file);
    1106         mr_asprintf(value, "%s", call_program_and_get_last_line_of_output(command));
     1109        value = call_program_and_get_last_line_of_output(command);
    11071110        mr_free(command);
    11081111
     
    12321235    mr_asprintf(command, "%s", "grep -v \":\" /etc/fstab | grep -vE '^#.*$' | grep -E \"[   ]/boot[     ]\" | tr -s ' ' '\t' | cut -f1 | head -n1");
    12331236    log_msg(4, "Cool. Command = '%s'", command);
    1234     mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command));
     1237    tmp = call_program_and_get_last_line_of_output(command);
    12351238    mr_free(command);
    12361239
     
    12391242    mr_asprintf(command, "mount | grep -Ew '/boot'");
    12401243    mr_free(tmp);
    1241     mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command));
     1244    tmp = call_program_and_get_last_line_of_output(command);
    12421245    mr_free(command);
    12431246
     
    14391442 * The command used to start it is saved in @p g_magicdev_command.
    14401443 */
    1441 void stop_magicdev_if_necessary()
    1442 {
    1443     strcpy(g_magicdev_command,
    1444            call_program_and_get_last_line_of_output
    1445            ("ps ax | grep -w magicdev | grep -v grep | tr -s '\t' ' '| cut -d' ' -f6-99"));
     1444void stop_magicdev_if_necessary() {
     1445
     1446    char *tmp = NULL;
     1447
     1448    tmp = call_program_and_get_last_line_of_output("ps ax | grep -w magicdev | grep -v grep | tr -s '\t' ' '| cut -d' ' -f6-99");
     1449
     1450    strcpy(g_magicdev_command, tmp);
     1451    mr_free(tmp);
     1452
    14461453    if (g_magicdev_command[0]) {
    14471454        log_msg(1, "g_magicdev_command = '%s'", g_magicdev_command);
Note: See TracChangeset for help on using the changeset viewer.