X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=common-src%2Futil.c;fp=common-src%2Futil.c;h=9d5ffca74d6eb824ecb623944c4f1886821d38a3;hb=691567b16c13087b31ee4c2b6d038e57872fae82;hp=eed9d981bca4bc5283453f532e281412de548788;hpb=cc7d7b45afc706099acf7ff2490ec5667d370651;p=debian%2Famanda diff --git a/common-src/util.c b/common-src/util.c index eed9d98..9d5ffca 100644 --- a/common-src/util.c +++ b/common-src/util.c @@ -1,6 +1,7 @@ /* * Amanda, The Advanced Maryland Automatic Network Disk Archiver * Copyright (c) 1999 University of Maryland at College Park + * Copyright (c) 2007-2012 Zmanda, Inc. All Rights Reserved. * All Rights Reserved. * * Permission to use, copy, modify, distribute, and sell this software and its @@ -1059,7 +1060,7 @@ int copy_file( { int infd, outfd; int save_errno; - size_t nb; + ssize_t nb; char buf[32768]; char *quoted; @@ -1083,7 +1084,7 @@ int copy_file( } while((nb=read(infd, &buf, SIZEOF(buf))) > 0) { - if(full_write(outfd,&buf,nb) < nb) { + if(full_write(outfd,&buf,nb) < (size_t)nb) { save_errno = errno; quoted = quote_string(dst); *errmsg = vstrallocf(_("Error writing to '%s': %s"), @@ -1678,15 +1679,44 @@ get_first_line( out = fdopen(outpipe[0],"r"); err = fdopen(errpipe[0],"r"); - output_string = agets(out); - if (!output_string) - output_string = agets(err); + if (out) { + output_string = agets(out); + fclose(out); + } - fclose(out); - fclose(err); + if (err) { + if (!output_string) + output_string = agets(err); + fclose(err); + } waitpid(pid, NULL, 0); return output_string; } +gboolean +make_amanda_tmpdir(void) +{ + struct stat stat_buf; + + if (stat(AMANDA_TMPDIR, &stat_buf) != 0) { + if (errno != ENOENT) { + g_debug("Error doing a stat of AMANDA_TMPDIR (%s): %s", AMANDA_TMPDIR, strerror(errno)); + return FALSE; + } + /* create it */ + if (mkdir(AMANDA_TMPDIR,0700) != 0) { + g_debug("Error mkdir of AMANDA_TMPDIR (%s): %s", AMANDA_TMPDIR, strerror(errno)); + return FALSE; + } + if (chown(AMANDA_TMPDIR, (int)get_client_uid(), (int)get_client_gid()) < 0) { + g_debug("Error chown of AMANDA_TMPDIR (%s): %s", AMANDA_TMPDIR, strerror(errno)); + return FALSE; + } + return TRUE; + } else { + /* check permission */ + return TRUE; + } +}