~tritone-team/tritone/eucalyptus

« back to all changes in this revision

Viewing changes to storage/storage.c

  • Committer: Bazaar Package Importer
  • Author(s): Dustin Kirkland
  • Date: 2009-12-01 21:09:28 UTC
  • mto: This revision was merged to the branch mainline in revision 75.
  • Revision ID: james.westby@ubuntu.com-20091201210928-o2dvg0ubljhb0ft6
Tags: upstream-1.6.1~bzr1083
ImportĀ upstreamĀ versionĀ 1.6.1~bzr1083

Show diffs side-by-side

added added

removed removed

Lines of Context:
107
107
        return 1;
108
108
    }
109
109
    /* read in configuration */
110
 
    char * home = getenv (EUCALYPTUS_ENV_VAR_NAME);
 
110
    char *home, *tmp;
 
111
    tmp = getenv (EUCALYPTUS_ENV_VAR_NAME);
 
112
    if (tmp) {
 
113
        home = strdup(tmp);
 
114
    } else {
 
115
        home = strdup(""); /* root by default */
 
116
    }
111
117
    if (!home) {
112
 
        home = strdup(""); /* root by default */
 
118
       logprintfl (EUCAERROR, "out of memory\n");
 
119
       return 1;
113
120
    }
114
121
    
115
122
    snprintf(config, BUFSIZE, EUCALYPTUS_CONF_LOCATION, home);
117
124
        logprintfl (EUCAINFO, "SC is looking for configuration in %s\n", config);
118
125
        
119
126
        if (get_conf_var(config, INSTANCE_PATH, &s)>0){ 
120
 
            sc_instance_path = strdup (s); 
121
 
            free (s); 
 
127
            sc_instance_path = s; 
122
128
        }
123
129
 
124
130
        if (get_conf_var(config, CONFIG_NC_CACHE_SIZE, &s)>0){ 
137
143
    /* we need to have valid path */
138
144
    if (check_directory(sc_instance_path)) {
139
145
            logprintfl (EUCAERROR, "ERROR: INSTANCE_PATH (%s) does not exist!\n", sc_instance_path);
 
146
            free(home);
140
147
            return(1);
141
148
    }
142
149
 
143
150
    if (euca_init_cert ()) {
144
151
        logprintfl (EUCAFATAL, "failed to find cryptographic certificates\n");
 
152
        free(home);
145
153
        return 1;
146
154
    }
147
155
 
148
156
    snprintf (disk_convert_command_path, BUFSIZE, EUCALYPTUS_DISK_CONVERT, home, home);
 
157
    free(home);
149
158
 
150
159
    scConfigInit=1;
151
160
    return(0);
182
191
     * directory (we're assuming that instanceIds are unique in the system) */
183
192
    if ((insts_dir=opendir(sc_instance_path))==NULL) {
184
193
            logprintfl(EUCADEBUG, "scRecoverInstanceInfo: failed to open %s!\n", sc_instance_path);
 
194
            free(instance);
185
195
            return NULL;
186
196
    }
187
197
    while ((dir_entry=readdir(insts_dir))!=NULL) {
194
204
            break; /* we got it! */
195
205
        }
196
206
    }
 
207
    closedir(insts_dir);
197
208
    if (userId==NULL) {
198
209
            logprintfl(EUCADEBUG, "scRecoverInstanceInfo: didn't find instance %s!\n", instanceId);
 
210
            free(instance);
199
211
            return NULL;
200
212
    }
201
213
 
260
272
    }
261
273
    for ( e = cache_head; e; e=e->next) {
262
274
        bzero (&mystat, sizeof (mystat));
263
 
        stat (e->path, &mystat);
264
 
        logprintfl (EUCAINFO, "\t%5dMB %8dsec %s\n", e->size_mb, mystat.st_mtime, e->path);
 
275
        if (stat (e->path, &mystat) == 0) {
 
276
           logprintfl (EUCAINFO, "\t%5dMB %8dsec %s\n", e->size_mb, mystat.st_mtime, e->path);
 
277
        }
265
278
    }
266
279
}
267
280
 
371
384
 
372
385
        if (stat (image_path, &mystat) < 0) {
373
386
            logprintfl (EUCAWARN, "warning: could not stat %s\n", image_path);
 
387
            closedir(image_dir);
374
388
            continue;
375
389
        }
376
390
        image_size += mystat.st_size;
414
428
                strncpy (X_digest, name, BUFSIZE);
415
429
            }
416
430
        }
 
431
        closedir(image_dir);
417
432
 
418
433
        if (image_files > 0) { /* ignore empty directories */
419
434
            if (image_files != 2 || strncmp (X, X_digest, BUFSIZE) != 0 ) {
563
578
            snprintf (instance_path, BUFSIZE, "%s/%s", user_path, iname);
564
579
 
565
580
            if (!strcmp("cache", iname) &&
566
 
                !strcmp(EUCALYPTUS_ADMIN, uname)) { /* cache is in admin's dir */
 
581
                        !strcmp(EUCALYPTUS_ADMIN, uname)) { /* cache is in admin's dir */
 
582
                if (cache_path) {
 
583
                    logprintfl (EUCADEBUG, "Found a second cache_path?\n");
 
584
                    free(cache_path);
 
585
                }
567
586
                cache_path = strdup (instance_path);
568
587
                continue;
569
588
            }
643
662
                printf ("trying to create path %s\n", path_copy);
644
663
                if ( mkdir (path_copy, mode) == -1) {
645
664
                    printf ("error: failed to create path %s\n", path_copy);
 
665
                    if (path_copy) free(path_copy);
646
666
                    return errno;
647
667
                }
648
668
            }
1053
1073
int scStoreStringToInstanceFile (const char *userId, const char *instanceId, const char * file, const char * data)
1054
1074
{
1055
1075
    FILE * fp;
 
1076
    int ret = ERROR;
1056
1077
        char path [BUFSIZE];
1057
1078
        snprintf (path, BUFSIZE, "%s/%s/%s/%s", sc_instance_path, userId, instanceId, file);
1058
1079
    if ( (fp = fopen (path, "w")) != NULL ) {
1059
 
        if ( fputs (data, fp) == EOF ) return ERROR;
 
1080
        if ( fputs (data, fp) != EOF ) {
 
1081
           ret = OK;
 
1082
        }
1060
1083
        fclose (fp);
1061
 
        return OK;
1062
1084
    }
1063
 
    return ERROR;
 
1085
    return ret;
1064
1086
}