Ignore:
Timestamp:
Jun 3, 2009, 7:10:19 PM (15 years ago)
Author:
Bruno Cornec
Message:

r3089@localhost: bruno | 2009-05-18 06:41:05 +0200

  • move call to asprintf to call to mr_asprintf (suppress a compiler warning)
  • remove all the most obvious bad call to strcat and replace by mr_strcat as appropriate
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2.9/mondo/src/common/libmondo-cli.c

    r2202 r2211  
    1212#include <pthread.h>
    1313#include "my-stuff.h"
     14#include "mr_mem.h"
     15#include "mr_string.h"
    1416#include "mondostructures.h"
    1517#include "libmondo-cli-EXT.h"
    1618#include "libmondo.h"
    17 #include "mr_string.h"
    1819
    1920extern int g_loglevel;
     
    278279    ********/
    279280    /* Get the number of mounted file systems ((those that start with "/dev/" */
    280     asprintf(&command, "mount 2>/dev/null | awk '{if($1 ~ \"^/dev/\"){print $0}}'|wc -l");
     281    mr_asprintf(&command, "mount 2>/dev/null | awk '{if($1 ~ \"^/dev/\"){print $0}}'|wc -l");
    281282    log_msg(5, "Running: %s", command);
    282     asprintf(&mounted_file_system, "%s", call_program_and_get_last_line_of_output(command));
     283    mr_asprintf(&mounted_file_system, "%s", call_program_and_get_last_line_of_output(command));
    283284    paranoid_free(command);
    284285
     
    288289
    289290    for (i=mount_cnt; i > 0; i--) {
    290         asprintf(&command, "mount 2>/dev/null | awk '{if($1 ~ \"^/dev/\"){print $1,$3}}'|head -n %d", i);
     291        mr_asprintf(&command, "mount 2>/dev/null | awk '{if($1 ~ \"^/dev/\"){print $1,$3}}'|head -n %d", i);
    291292        log_msg(5, "Running: %s", command);
    292         asprintf(&mounted_file_system, "%s", call_program_and_get_last_line_of_output(command));
     293        mr_asprintf(&mounted_file_system, "%s", call_program_and_get_last_line_of_output(command));
    293294        paranoid_free(command);
    294295
     
    366367    log_msg(5, "  %s looks like a device special file", dsf);
    367368    /* Verify that the dsf exists */
    368     asprintf(&command, "ls -al %s 2>/dev/null | wc -l", dsf);
     369    mr_asprintf(&command, "ls -al %s 2>/dev/null | wc -l", dsf);
    369370    log_msg(5, "  Executing: %s", command);
    370     asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command));
     371    mr_asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command));
    371372    paranoid_free(command);
    372373
     
    392393    * Either way, it's an error.
    393394    ********/
    394     asprintf(&command,
     395    mr_asprintf(&command,
    395396      "fdisk -l %s 2>/dev/null|grep -E \"^/dev/\"|awk '{printf(\"%%s \", $1)}END{print \"\"}'", dsf);
    396397    log_msg(4, "Executing: %s", command);
    397     asprintf(&partition_list, "%s", call_program_and_get_last_line_of_output(command));
     398    mr_asprintf(&partition_list, "%s", call_program_and_get_last_line_of_output(command));
    398399    paranoid_free(command);
    399400    log_msg(4, "Partition list for %s: %s", dsf, partition_list);
     
    445446        log_msg(4, "Processing partition: %s", partitions[i]);
    446447        /* See if it's swap. If it is, ignore it. */
    447         asprintf(&command,
     448        mr_asprintf(&command,
    448449          "fdisk -l %s 2>/dev/null | awk '{if(($1==\"%s\")&&(toupper($0) ~ \"SWAP\")){print $1;exit}}'",
    449450          dsf, partitions[i]);
    450451        log_msg(4, "  Running: %s", command);
    451         asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command));
     452        mr_asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command));
    452453        paranoid_free(command);
    453454        log_msg(4, "  Return value: %s", tmp);
     
    459460        }
    460461        /* It's not swap. See if we can find the mount point from the mount command. */
    461         asprintf(&command, "mount 2>/dev/null | awk '{if((NF>0)&&($1==\"%s\")){print $3}}'", partitions[i]);
    462         asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command));
     462        mr_asprintf(&command, "mount 2>/dev/null | awk '{if((NF>0)&&($1==\"%s\")){print $3}}'", partitions[i]);
     463        mr_asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command));
    463464        paranoid_free(command);
    464465        if (strlen(tmp)) {
     
    477478        log_msg(4, "  It's not mounted. Checking to see if it's LVM...");
    478479        /* Get the partition ID; 8e for LVM */
    479         asprintf(&command, "fdisk -l %s |awk '{if($1 ~ \"^%s\"){print $5}}'", dsf, partitions[i]);
     480        mr_asprintf(&command, "fdisk -l %s |awk '{if($1 ~ \"^%s\"){print $5}}'", dsf, partitions[i]);
    480481        log_msg(4, "  Running: %s", command);
    481         asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command));
     482        mr_asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command));
    482483        paranoid_free(command);
    483484        if (strlen(tmp)) {
     
    486487                /* It's LVM: Find the VG it's in */
    487488                log_msg(4, "  It's LVM: Find the VG it's in...");
    488                 asprintf(&command, "pvdisplay -v %s 2>/dev/null|grep \"VG Name\"|awk '{print $NF}'", partitions[i]);
     489                mr_asprintf(&command, "pvdisplay -v %s 2>/dev/null|grep \"VG Name\"|awk '{print $NF}'", partitions[i]);
    489490                log_msg(4, "  Running: %s", command);
    490491                strcpy(VG, call_program_and_get_last_line_of_output(command));
     
    494495                    /* Found the Volume Group. Now find all of the VG's mount points */
    495496                    log_msg(4, "  Found the Volume Group. Now find all of the VG's mount points");
    496                     asprintf(&command,
     497                    mr_asprintf(&command,
    497498                      "mount 2>/dev/null|grep -E \"/dev/mapper/%s-|/dev/%s/\"|awk '{printf(\"%%s \",$3)}END{print \"\"}'",
    498499                      VG, VG);
    499500                    log_msg(4, "  Running: %s", command);
    500                     asprintf(&mount_list, "%s", call_program_and_get_last_line_of_output(command));
     501                    mr_asprintf(&mount_list, "%s", call_program_and_get_last_line_of_output(command));
    501502                    paranoid_free(command);
    502503                    log_msg(4, "  VG %s mount_list: %s", VG, mount_list);
     
    516517                     *******/
    517518                    paranoid_free(mount_list);
    518                     asprintf(&command, "%s",
     519                    mr_asprintf(&command, "%s",
    519520                        "cat /proc/mdstat|grep -iv Personal|awk '{if($0~\"^.*[ ]+:\"){printf(\"/dev/%s \", $1)}}END{print \"\"}'");
    520521                    log_msg (5, "Running: %s", command);
    521                     asprintf(&mount_list, "%s", call_program_and_get_last_line_of_output(command));
     522                    mr_asprintf(&mount_list, "%s", call_program_and_get_last_line_of_output(command));
    522523                    paranoid_free(command);
    523524                    log_msg(4, "  Software raid device list: %s", mount_list);   
    524525                    lastpos = 0;
    525526                    while ((token = mr_strtok(mount_list, token_chars, &lastpos)) != NULL) {
    526                         asprintf(&command, "mdadm --detail %s 2>/dev/null | grep -c %s", token, VG);
     527                        mr_asprintf(&command, "mdadm --detail %s 2>/dev/null | grep -c %s", token, VG);
    527528                        log_msg (5, "Running: %s", command);
    528529                        paranoid_free(tmp);
    529                         asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command));
     530                        mr_asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command));
    530531                        paranoid_free(command);
    531532                        log_msg(4, "Number of Software raid device: %s", tmp);
     
    557558         ********/
    558559        log_msg (5, "It's not swap, mounted, or LVM. See if it's used in a software raid device.");
    559         asprintf(&command, "mdadm --examine %s 2>/dev/null | awk '{if($1 == \"UUID\"){print $3}}'", partitions[i]);
     560        mr_asprintf(&command, "mdadm --examine %s 2>/dev/null | awk '{if($1 == \"UUID\"){print $3}}'", partitions[i]);
    560561        log_msg(4, "  Running: %s", command);
    561         asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command));
     562        mr_asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command));
    562563        paranoid_free(command);
    563564        if (!strlen(tmp)) {
     
    568569        log_msg (5, "  UUID: %s", tmp);
    569570        /* Get the Software raid device list */
    570         asprintf(&command, "%s",
     571        mr_asprintf(&command, "%s",
    571572         "cat /proc/mdstat|grep -iv Personal|awk '{if($0~\"^.*[ ]+:\"){printf(\"/dev/%s \", $1)}}END{print \"\"}'");
    572573        log_msg (5, "  Running: %s", command);
    573         asprintf(&mount_list, "%s", call_program_and_get_last_line_of_output(command));
     574        mr_asprintf(&mount_list, "%s", call_program_and_get_last_line_of_output(command));
    574575        paranoid_free(command);
    575576        log_msg(4, "  Software raid device list: %s", mount_list);   
     
    577578        lastpos = 0;
    578579        while ((token = mr_strtok(mount_list, token_chars, &lastpos)) != NULL) {
    579             asprintf(&command, "mdadm --detail %s 2>/dev/null | grep -c %s", token, tmp);
     580            mr_asprintf(&command, "mdadm --detail %s 2>/dev/null | grep -c %s", token, tmp);
    580581            log_msg(4, "  Running: %s", command);
    581582            paranoid_free(tmp);
    582             asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command));
     583            mr_asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command));
    583584            paranoid_free(command);
    584585            if (!atoi(tmp)) {
     
    756757        }
    757758       
    758         asprintf(&tmp1, "%s", flag_val['I']);
     759        mr_asprintf(&tmp1, "%s", flag_val['I']);
    759760        p = tmp1;
    760761        q = tmp1;
     
    10351036    if (flag_set['z']) {
    10361037        if (find_home_of_exe("getfattr")) {
    1037             asprintf(&g_getfattr,"getfattr");
     1038            mr_asprintf(&g_getfattr,"getfattr");
    10381039        }
    10391040        if (find_home_of_exe("getfacl")) {
    1040             asprintf(&g_getfacl,"getfacl");
     1041            mr_asprintf(&g_getfacl,"getfacl");
    10411042        }
    10421043    }
     
    10551056            strcat(bkpinfo->exclude_paths, " ");
    10561057        }
    1057         asprintf(&tmp1, "%s", flag_val['E']);
     1058        mr_asprintf(&tmp1, "%s", flag_val['E']);
    10581059
    10591060        p = tmp1;
     
    12111212
    12121213    if ((flag_set['n']) && (! bkpinfo->restore_data)) {
    1213         asprintf(&tmp1,"%s/%s/.dummy.txt", bkpinfo->isodir,bkpinfo->nfs_remote_dir);
     1214        mr_asprintf(&tmp1,"%s/%s/.dummy.txt", bkpinfo->isodir,bkpinfo->nfs_remote_dir);
    12141215        sprintf(tmp, "echo hi > %s", tmp1);
    12151216        if (run_program_and_log_output(tmp, 2)) {
     
    14671468            if (flag_set[optopt]) {
    14681469                bad_switches = TRUE;
    1469                 (void) asprintf(&tmp, "Switch -%c previously defined as %s\n", opt,
     1470                mr_asprintf(&tmp, "Switch -%c previously defined as %s\n", opt,
    14701471                        flag_val[i]);
    14711472                log_to_screen(tmp);
     
    14841485                        if (strchr(flag_val[opt], '/')
    14851486                            && flag_val[opt][0] != '/') {
    1486                             (void)asprintf(&tmp,
     1487                            mr_asprintf(&tmp,
    14871488                                    "-%c flag --- must be absolute path --- '%s' isn't absolute",
    14881489                                    opt, flag_val[opt]);
     
    14991500    for (i = optind; i < argc; i++) {
    15001501        bad_switches = TRUE;
    1501         (void)asprintf(&tmp, "Invalid arg -- %s\n", argv[i]);
     1502        mr_asprintf(&tmp, "Invalid arg -- %s\n", argv[i]);
    15021503        log_to_screen(tmp);
    15031504        paranoid_free(tmp);
     
    15251526void terminate_daemon(int sig)
    15261527{
    1527     char tmp[64];
    1528     char tmp2[MAX_STR_LEN];
    1529     //  char command[512];
    1530     //  pid_t pid;
     1528    char *tmp = NULL;
     1529    char *tmp2 = NULL;
    15311530
    15321531    switch (sig) {
    15331532    case SIGINT:
    1534         sprintf(tmp, "SIGINT");
    1535         strcpy(tmp2, "You interrupted me :-)");
     1533        mr_asprintf(&tmp, "SIGINT");
     1534        mr_asprintf(&tmp2, "You interrupted me :-)");
    15361535        break;
    15371536    case SIGKILL:
    1538         sprintf(tmp, "SIGKILL");
    1539         strcpy(tmp2,
     1537        mr_asprintf(&tmp, "SIGKILL");
     1538        mr_asprintf(&tmp2,
    15401539               "I seriously have no clue how this signal even got to me. Something's wrong with your system.");
    15411540        break;
    15421541    case SIGTERM:
    1543         sprintf(tmp, "SIGTERM");
    1544         strcpy(tmp2, "Got terminate signal");
     1542        mr_asprintf(&tmp, "SIGTERM");
     1543        mr_asprintf(&tmp2, "Got terminate signal");
    15451544        break;
    15461545    case SIGHUP:
    1547         sprintf(tmp, "SIGHUP");
    1548         strcpy(tmp2, "Hangup on line");
     1546        mr_asprintf(&tmp, "SIGHUP");
     1547        mr_asprintf(&tmp2, "Hangup on line");
    15491548        break;
    15501549    case SIGSEGV:
    1551         sprintf(tmp, "SIGSEGV");
    1552         strcpy(tmp2,
     1550        mr_asprintf(&tmp, "SIGSEGV");
     1551        mr_asprintf(&tmp2,
    15531552               "Internal programming error. Please send a backtrace as well as your log.");
    15541553        break;
    15551554    case SIGPIPE:
    1556         sprintf(tmp, "SIGPIPE");
    1557         strcpy(tmp2, "Pipe was broken");
     1555        mr_asprintf(&tmp, "SIGPIPE");
     1556        mr_asprintf(&tmp2, "Pipe was broken");
    15581557        break;
    15591558    case SIGABRT:
    1560         sprintf(tmp, "SIGABRT");
    1561         sprintf(tmp2,
     1559        mr_asprintf(&tmp, "SIGABRT");
     1560        mr_asprintf(&tmp2,
    15621561                "Abort - probably failed assertion. I'm sleeping for a few seconds so you can read the message.");
    15631562        break;
    15641563    default:
    1565         sprintf(tmp, "(Unknown)");
    1566     }
    1567 
    1568     strcat(tmp, " signal received from OS");
     1564        mr_asprintf(&tmp, "(Unknown)");
     1565        mr_asprintf(&tmp2, "(Unknown)");
     1566    }
     1567
     1568    mr_strcat(tmp, " signal received from OS");
    15691569    log_to_screen(tmp);
     1570    paranoid_free(tmp);
     1571
    15701572    log_to_screen(tmp2);
     1573    paranoid_free(tmp2);
    15711574    if (sig == SIGABRT) {
    15721575        sleep(10);
Note: See TracChangeset for help on using the changeset viewer.