Changeset 1152 in MondoRescue for branches/stable/mondo/src


Ignore:
Timestamp:
Feb 12, 2007, 11:49:41 PM (17 years ago)
Author:
Bruno Cornec
Message:

More memory updates around mondoarchive (addition of mr_setenv) (based on ideas sent as patches by Michel)

Location:
branches/stable/mondo/src
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • branches/stable/mondo/src/common/libmondo-archive-EXT.h

    r543 r1152  
    4141                                          char *filelist, char *fname,
    4242                                          int setno);
    43 extern void setenv_mondo_share(void);
     43extern void setenv_mondo_var(void);
  • branches/stable/mondo/src/common/libmondo-archive.c

    r1147 r1152  
    1414#include <sys/ipc.h>
    1515#include <stdarg.h>
     16#include <stdlib.h>
    1617#include <unistd.h>
    1718
     
    39393940/* @} - end of utilityGroup */
    39403941
    3941 void setenv_mondo_share(void) {
    3942 
    3943 setenv("MONDO_SHARE", MONDO_SHARE, 1);
    3944 setenv("MONDORESTORECFG", MONDORESTORECFG, 1);
    3945 setenv("MONDO_CACHE", MONDO_CACHE, 1);
     3942void setenv_mondo_var(void) {
     3943
     3944    char *tmp = NULL;
     3945    char *p = NULL;
     3946    char *path_min = "/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/sbin:/usr/local/bin";
     3947
     3948    mr_setenv("MONDO_SHARE",MONDO_SHARE);
     3949    mr_setenv("MONDORESTORECFG",MONDORESTORECFG);
     3950    mr_setenv("MONDO_CACHE",MONDO_CACHE);
     3951
     3952    if ((p = getenv("PATH")) == NULL) {
     3953        mr_asprintf(&p,path_min);
     3954    }
     3955    mr_asprintf(&tmp, "%s:%s",p, path_min);
     3956    mr_free(p);
     3957    mr_setenv("PATH",tmp);
     3958    mr_free(tmp);
    39463959}
  • branches/stable/mondo/src/common/libmondo-tools.c

    r1144 r1152  
    197197
    198198
    199 char *get_architecture()
     199char *get_architecture(void)
    200200{
    201201#ifdef __IA32__
     
    210210
    211211
    212 double get_kernel_version()
     212double get_kernel_version(void)
    213213{
    214214    char *p, tmp[200];
     
    244244 * @return number of seconds since the epoch.
    245245 */
    246 long get_time()
     246long get_time(void)
    247247{
    248248    return (long) time((void *) 0);
  • branches/stable/mondo/src/include/mr_mem.h

    r1133 r1152  
    2222#define mr_getline(x,y,z) mr_getline_int(x,y,z,__LINE__,__FILE__)
    2323#define mr_malloc(x) mr_malloc_int((size_t)x,__LINE__,__FILE__)
     24#define mr_setenv(x,y) mr_setenv_int(x,y,__LINE__,__FILE__)
    2425
    2526/* Internal function bringing debuging info
     
    3031extern inline void mr_getline_int(char **lineptr, size_t *n, FILE *stream, int line, char *file);
    3132extern inline void *mr_malloc_int(size_t size, int line, char *file);
     33extern inline mr_setenv_int(const char *name, const char *value, int line, char *file);
    3234
    3335#endif                          /* MR_MEM_H */
  • branches/stable/mondo/src/lib/mr_mem.c

    r1138 r1152  
    8989    mr_asprintf_int(&alloc, line, file, orig);
    9090}
     91
     92/*
     93 * Function that properly put a variable in the environment
     94 */
     95void mr_setenv_int(const char *name, const char *value, int line, char *file) {
     96   
     97    if (name == NULL) {
     98        mr_msg_int(1,line,file,"Unable to setenv a NULL variable\nExiting...");
     99        mr_exit(-1, "Unable to setenv a NULL variable");
     100    }
     101    if (value == NULL) {
     102        mr_msg_int(1,line,file,"Unable to affect NULL to %s\nExiting...", name);
     103        mr_exit(-1, "Unable to affect a NULL variable");
     104    }
     105    if (mr_setenv(name, value, 1) != 0) {
     106        mr_msg_int(1,line,file,"Unable to put %s in environment", name);
     107        mr_exit(-1,"Unable to put in environment");
     108    }
     109}
  • branches/stable/mondo/src/mondoarchive/main.c

    r1151 r1152  
    157157    struct s_bkpinfo *bkpinfo;
    158158    struct stat stbuf;
    159     char *tmp;
     159    char *tmp = NULL;
    160160    int res, retval;
    161161    char *say_at_end;
     
    178178
    179179    malloc_libmondo_global_strings();
    180     malloc_string(tmp);
    181180    malloc_string(say_at_end);
    182181
     
    194193    bkpinfo = mr_malloc(sizeof(struct s_bkpinfo));
    195194
    196     /* make sure PATH environmental variable allows access to mkfs, fdisk, etc. */
    197     strncpy(tmp, getenv("PATH"), MAX_STR_LEN - 1);
    198     tmp[MAX_STR_LEN - 1] = '\0';
    199     if (strlen(tmp) >= MAX_STR_LEN - 33) {
    200         fatal_error
    201             ("Your PATH environmental variable is too long. Please shorten it.");
    202     }
    203     strcat(tmp, ":/sbin:/usr/sbin:/usr/local/sbin");
    204     setenv("PATH", tmp, 1);
    205 
    206195    /* Add the ARCH environment variable for ia64 purposes */
    207     strncpy(tmp, get_architecture(), MAX_STR_LEN - 1);
    208     tmp[MAX_STR_LEN - 1] = '\0';
    209     setenv("ARCH", tmp, 1);
     196    setenv("ARCH", get_architecture(), 1);
    210197
    211198    /* Add MONDO_SHARE + others environment variable for mindi */
    212     setenv_mondo_share();
     199    setenv_mondo_var();
    213200
    214201    if (stat(MONDO_CACHE, &stbuf) != 0) {
     
    247234    if (argc == 4 && !strcmp(argv[1], "setfattr")) {
    248235        g_loglevel = 10;
    249 //      chdir("/tmp");
    250236        g_text_mode = TRUE;
    251237        setup_newt_stuff();
     
    257243        g_text_mode = TRUE;
    258244        setup_newt_stuff();
     245        malloc_string(tmp);
    259246        turn_wildcard_chars_into_literal_chars(tmp, argv[2]);
    260247        printf("in=%s; out=%s\n", argv[2], tmp);
     248        mr_free(tmp);
    261249        finish(1);
    262250    }
     
    276264    if (argc == 4 && !strcmp(argv[1], "setfacl")) {
    277265        g_loglevel = 10;
    278 //      chdir("/tmp");
    279266        g_text_mode = TRUE;
    280267        setup_newt_stuff();
     
    286273        g_text_mode = TRUE;
    287274        setup_newt_stuff();
     275        malloc_string(tmp);
    288276        if (find_cdrw_device(tmp)) {
    289277            printf("Failed to find CDR-RW drive\n");
     
    297285            printf("CD-ROM is at %s\n", tmp);
    298286        }
     287        mr_free(tmp);
    299288        finish(0);
    300289    }
     
    304293        g_text_mode = TRUE;
    305294        setup_newt_stuff();
     295        malloc_string(tmp);
    306296        if (find_dvd_device(tmp, atoi(argv[2]))) {
    307297            printf("Failed to find DVD drive\n");
     
    309299            printf("DVD is at %s\n", tmp);
    310300        }
     301        mr_free(tmp);
    311302        finish(0);
    312303    }
     
    380371        res = verify_data(bkpinfo);
    381372        if (res < 0) {
    382             sprintf(tmp, "%d difference%c found.", -res,
     373            mr_asprintf(&tmp, "%d difference%c found.", -res,
    383374                    (-res != 1) ? 's' : ' ');
    384375            strcat(say_at_end, tmp);
    385376            log_to_screen(tmp);
     377            mr_free(tmp);
    386378            res = 0;
    387379        }
     
    427419    }
    428420    log_to_screen(say_at_end);
    429     sprintf(tmp, "umount %s/tmpfs", bkpinfo->tmpdir);
     421    mr_asprintf(&tmp, "umount %s/tmpfs", bkpinfo->tmpdir);
    430422    run_program_and_log_output(tmp, TRUE);
     423    mr_free(tmp);
    431424    run_program_and_log_output(g_erase_tmpdir_and_scratchdir, TRUE);
    432425
     
    447440    free_libmondo_global_strings();
    448441    mr_free(say_at_end);
    449     mr_free(tmp);
    450442    mr_free(bkpinfo);
    451443
Note: See TracChangeset for help on using the changeset viewer.