diff options
| author | Gregor Beck <gbeck@sernet.de> | 2013-04-22 13:33:00 +0200 |
|---|---|---|
| committer | Michael Adam <obnox@samba.org> | 2013-12-11 17:54:16 +0100 |
| commit | ae6a13eecb8cf368c49ec069a395865fba6765f1 (patch) | |
| tree | b71c128148df4d5ee76ffa4cf473edf7ab6207d5 /source3/lib | |
| parent | dfff01910be57d0f693f3539dac010859ecb01c9 (diff) | |
| download | samba-ae6a13eecb8cf368c49ec069a395865fba6765f1.tar.gz samba-ae6a13eecb8cf368c49ec069a395865fba6765f1.tar.xz samba-ae6a13eecb8cf368c49ec069a395865fba6765f1.zip | |
s3: use directory_create_or_exist_strict() to create corepath
This simplifies the code and even works in testenv where the chown call
fails.
Signed-off-by: Gregor Beck <gbeck@sernet.de>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
Diffstat (limited to 'source3/lib')
| -rw-r--r-- | source3/lib/dumpcore.c | 33 |
1 files changed, 17 insertions, 16 deletions
diff --git a/source3/lib/dumpcore.c b/source3/lib/dumpcore.c index 90acc1679b..f284ea4673 100644 --- a/source3/lib/dumpcore.c +++ b/source3/lib/dumpcore.c @@ -43,34 +43,35 @@ static char *corepath; */ static char *get_default_corepath(const char *logbase, const char *progname) { + const mode_t mode = 0700; + const uid_t uid = getuid(); char *tmp_corepath; /* Setup core dir in logbase. */ tmp_corepath = talloc_asprintf(NULL, "%s/cores", logbase); - if (!tmp_corepath) + if (!tmp_corepath) { + DEBUG(0, ("Out of memory\n")); return NULL; + } - if ((mkdir(tmp_corepath, 0700) == -1) && errno != EEXIST) - goto err_out; - - if (chmod(tmp_corepath, 0700) == -1) + if (!directory_create_or_exist_strict(tmp_corepath, uid, mode)) { + DEBUG(0, ("Failed to create %s for user %d with mode 0%o\n", + tmp_corepath, (int)uid, (int)mode)); goto err_out; - - talloc_free(tmp_corepath); + } /* Setup progname-specific core subdir */ - tmp_corepath = talloc_asprintf(NULL, "%s/cores/%s", logbase, progname); - if (!tmp_corepath) - return NULL; - - if (mkdir(tmp_corepath, 0700) == -1 && errno != EEXIST) - goto err_out; - - if (chown(tmp_corepath, getuid(), getgid()) == -1) + tmp_corepath = talloc_asprintf_append(tmp_corepath, "/%s", progname); + if (!tmp_corepath) { + DEBUG(0, ("Out of memory\n")); goto err_out; + } - if (chmod(tmp_corepath, 0700) == -1) + if (!directory_create_or_exist(tmp_corepath, uid, mode)) { + DEBUG(0, ("Failed to create %s for user %d with mode 0%o\n", + tmp_corepath, (int)uid, (int)mode)); goto err_out; + } return tmp_corepath; |
