~mterry/snap-confine/tmpdir-15.04

« back to all changes in this revision

Viewing changes to src/main.c

  • Committer: Michael Terry
  • Date: 2015-06-04 15:17:05 UTC
  • Revision ID: michael.terry@canonical.com-20150604151705-uhthnv68djq1pk2y
Backport r68 from trunk (fixing TMPDIR being passed to command)

Show diffs side-by-side

added added

removed removed

Lines of Context:
245
245
        return;
246
246
    }
247
247
 
 
248
    // strtok trashes its argument, so to avoid changing the TMPDIR variable,
 
249
    // we make a copy.
 
250
    dir = strdup(dir);
 
251
    if (!dir) {
 
252
        die("out of memory");
 
253
    }
 
254
 
248
255
    int n = 4;
249
256
    char buf[MAX_BUF] = "/tmp";
250
257
    char *d = strtok(dir+4, "/");
251
258
    while (d) {
252
259
        n += must_snprintf(buf+n, MAX_BUF-n, "/%s", d);
253
 
        if (mkdir(buf, 01777) < 0) {
254
 
            return;
 
260
        if (mkdir(buf, 01777) < 0 && errno != EEXIST) {
 
261
            break;
255
262
        }
256
263
 
257
264
        d = strtok(NULL, "/");
258
265
    }
 
266
 
 
267
    free(dir);
259
268
}
260
269
 
261
270
int main(int argc, char **argv)