aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2009-02-22 14:29:32 +0200
committerSergey Poznyakoff <gray@gnu.org.ua>2009-02-22 14:29:32 +0200
commitf09763f6b6e1e84ea9968457e6cc3e7af5360671 (patch)
tree39c0539d963d3553e4103bead25f22bd8a367f31 /src
parent97d84293615048b936d35250c89b21259acdb18f (diff)
downloadwydawca-f09763f6b6e1e84ea9968457e6cc3e7af5360671.tar.gz
wydawca-f09763f6b6e1e84ea9968457e6cc3e7af5360671.tar.bz2
Remove sendfile support
Diffstat (limited to 'src')
-rw-r--r--src/config.c3
-rw-r--r--src/diskio.c126
-rw-r--r--src/update-2.0.awk2
-rw-r--r--src/wydawca.c1
-rw-r--r--src/wydawca.h1
5 files changed, 45 insertions, 88 deletions
diff --git a/src/config.c b/src/config.c
index c4f50b2..dd444fe 100644
--- a/src/config.c
+++ b/src/config.c
@@ -1240,9 +1240,6 @@ static struct gconf_keyword wydawca_kw[] = {
{ "from-address", N_("email"), N_("Set sender email address"),
gconf_type_string, &from_address, 0, cb_email_address },
- { "enable-sendfile", N_("arg"), N_("Enable or disable sendfile(2) support"),
- gconf_type_bool, &enable_sendfile },
-
/* FIXME: Must be a built-in type? */
{ "file-sweep-time", N_("interval"), N_("Define file sweep time"),
gconf_type_string, &file_sweep_time, 0, cb_interval },
diff --git a/src/diskio.c b/src/diskio.c
index 9df7a1a..6e75ccd 100644
--- a/src/diskio.c
+++ b/src/diskio.c
@@ -16,13 +16,6 @@
#include "wydawca.h"
#include "save-cwd.h"
-#if defined USE_SENDFILE
-# if defined __linux__ && defined HAVE_SYS_SENDFILE_H
-# include <sys/sendfile.h>
-# else
-# undef USE_SENDFILE
-# endif
-#endif
/* Return true if ARG is NULL or is a sub-directory of DIR */
int
@@ -137,15 +130,17 @@ create_directory (const char *base, const char *name, uid_t uid, gid_t gid)
}
-/* Copy FILE to DST_FILE, creating the latter with owner UID and GID.
- Prefer sendfile(2), if available. Otherwise use plain old approach. */
+/* Copy FILE to DST_FILE, creating the latter with owner UID and GID. */
int
copy_file (const char *file, const char *dst_file, uid_t uid, gid_t gid)
{
int in_fd, out_fd;
struct stat st;
- enum { copy_ok, copy_fallback, copy_failed } rc = copy_fallback;
-
+ int rc;
+ char *buf;
+ size_t bufsize;
+ size_t fsize;
+
in_fd = open (file, O_RDONLY);
if (in_fd == -1)
@@ -172,87 +167,52 @@ copy_file (const char *file, const char *dst_file, uid_t uid, gid_t gid)
return 1;
}
-#ifdef USE_SENDFILE
- if (enable_sendfile)
+ buf = NULL;
+ fsize = st.st_size;
+
+ for (bufsize = fsize; bufsize > 0 && (buf = malloc (bufsize)) == NULL;
+ bufsize /= 2)
+ ;
+ if (bufsize == 0)
+ xalloc_die ();
+
+ rc = 0;
+ while (fsize > 0)
{
- off_t offset = 0;
- ssize_t count;
+ size_t rest;
+ size_t rdbytes;
- count = sendfile (out_fd, in_fd, &offset, st.st_size);
- if (count == -1)
+ rest = fsize > bufsize ? bufsize : fsize;
+ rdbytes = read (in_fd, buf, rest);
+ if (rdbytes == -1)
{
- if (errno == EINVAL || errno == ENOSYS)
- rc = copy_fallback;
- else
- rc = copy_failed;
- logmsg ((rc == copy_fallback) ? LOG_WARNING : LOG_ERR,
- "sendfile: copying %s to %s failed: %s",
- file, dst_file, strerror (errno));
+ logmsg (LOG_ERR, "unexpected error reading %s: %s",
+ file, strerror (errno));
+ rc = 1;
+ break;
}
- else if (count < st.st_size)
+ rest = write (out_fd, buf, rdbytes);
+ if (rest == -1)
{
- rc = copy_failed;
- logmsg (LOG_ERR, "copying %s to %s failed: short write",
- file, dst_file);
+ logmsg (LOG_ERR, "unexpected error writing to %s: %s",
+ dst_file, strerror (errno));
+ rc = 1;
+ break;
}
- else
- rc = copy_ok;
- }
-
- if (rc == copy_fallback)
-#endif
- {
- char *buf = NULL;
- size_t bufsize;
- size_t fsize = st.st_size;
-
- for (bufsize = fsize; bufsize > 0 && (buf = malloc (bufsize)) == NULL;
- bufsize /= 2)
- ;
- if (bufsize == 0)
- xalloc_die ();
-
- rc = copy_ok;
- while (fsize > 0)
- {
- size_t rest;
- size_t rdbytes;
-
- rest = fsize > bufsize ? bufsize : fsize;
- rdbytes = read (in_fd, buf, rest);
- if (rdbytes == -1)
- {
- logmsg (LOG_ERR, "unexpected error reading %s: %s",
- file, strerror (errno));
- rc = copy_failed;
- break;
- }
- rest = write (out_fd, buf, rdbytes);
- if (rest == -1)
- {
- logmsg (LOG_ERR, "unexpected error writing to %s: %s",
- dst_file, strerror (errno));
- rc = copy_failed;
- break;
- }
- else if (rest != rdbytes)
- {
- logmsg (LOG_ERR, "short write on %s", dst_file);
- rc = copy_failed;
- }
- fsize -= rdbytes;
- }
- free (buf);
- }
+ else if (rest != rdbytes)
+ {
+ logmsg (LOG_ERR, "short write on %s", dst_file);
+ rc = 1;
+ }
+ fsize -= rdbytes;
+ }
+ free (buf);
close (in_fd);
close (out_fd);
- if (rc != copy_ok)
- {
- unlink (dst_file);
- return 1;
- }
- return 0;
+ if (rc)
+ unlink (dst_file);
+ return rc;
}
/* Move FILE to DST_FILE. If they reside on different devices, use copy_file
diff --git a/src/update-2.0.awk b/src/update-2.0.awk
index 3027275..7dfb7cd 100644
--- a/src/update-2.0.awk
+++ b/src/update-2.0.awk
@@ -59,6 +59,8 @@ function indent(len) {
printf(" ")
}
+$1 == "enable-sendfile" { next }
+
$1 == "file-sweep-time" || $1 == "tar-program" || $1 == "admin-address" ||
$1 == "from-address" || $1 == "host" || $1 == "database" ||
$1 == "user" || $1 == "password" ||
diff --git a/src/wydawca.c b/src/wydawca.c
index b95446c..2eb8fa2 100644
--- a/src/wydawca.c
+++ b/src/wydawca.c
@@ -29,7 +29,6 @@ int syslog_include_prio; /* syslog messages include priority */
unsigned long print_stats; /* Print final statistics output */
time_t file_sweep_time = 0;
char *tar_command_name = "tar";
-int enable_sendfile = 1; /* Use sendfile by default */
int archive_signatures = 1; /* Archive sig files by default */
int lint_mode = 0;
int preprocess_only = 0;
diff --git a/src/wydawca.h b/src/wydawca.h
index 948b609..eb420d0 100644
--- a/src/wydawca.h
+++ b/src/wydawca.h
@@ -302,7 +302,6 @@ extern time_t file_sweep_time; /* Unlink stale file after this amount of time
extern char *tar_command_name; /* Name of the tar command */
extern unsigned wydawca_stat[MAX_STAT];
extern unsigned long print_stats;
-extern int enable_sendfile;
extern int archive_signatures;
extern char *admin_stat_message;

Return to:

Send suggestions and report system problems to the System administrator.