~ubuntu-branches/debian/experimental/libeatmydata/experimental

« back to all changes in this revision

Viewing changes to .pc/bug-702711.patch/libeatmydata/libeatmydata.c

  • Committer: Package Import Robot
  • Author(s): Mattia Rizzolo
  • Date: 2014-10-03 20:48:40 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20141003204840-xyxqm6u7d2l72c3x
Tags: 82-1
* New upstream release (Closes: #700649).
  + fixes a issue with faketime (Closes: #747078).
* Add Multi-Arch support (Closes: #694314, LP: #1275932):
  + Upstream now has a basic multiarch support on its own, update packaging.
  + debian/control: split package to libeatmydata1 being Multi-Arch:same.
  + debian/rules: move shared library to /usr/lib/<triplet>/libeatmydata.
* debian/{bin,lib}: drop, included upstream.
* debian/control:
  + [19c31a7] Bump Standards-Version to 3.9.6. No changes required.
  + Bump debhelper version to 9.
  + Add autotools-dev and strace to Build-Depends.
  + [687e4b8] Add dpkg-dev to depends of eatmydata
  + [8083867] wrap-and sort maintenance.
  + [64b0f93] Add myself as uploader.
  + [e74b025] Add Breaks/Replaces relations to libeatmydata1.
  + [d46838e,512aabc] Update Vcs-* links to collab-maint.
* debian/copyright:
  + Update accordingly the new upstream release.
  + Update to the debian-copyright format 1.0.
  + Update the homepage to launchpad.net/libeatmydata.
  + Add myself to copyright owners.
* debian/compat: bump to 9.
* debian/rules:
  + use dh with autotools_dev addon.
  + [71e3563] remove the override_dh_makeshilibs.
* [db986b8] debian/libeatmydata1.lintian-overrides: add
  non-dev-pkg-with-shlib-symlink.
* debian/patches:
  + executable-not-elf-or-script.patch. add to fix omonim
    lintian warning.
  + [6eba479,bce9c1d] multiarch-issue: add to fix a issue with multiarch (a
    script refers to a fixed position, non multiarch-compatible).
  + bug-702711.patch: update headers. Thanks Petter for the NMU.
* [ad63684] debian/eatmydata.install:
  + Drop eatmydata.sh, now installed in libeatmydata1.
  + Change source to debian/tmp.
* debian/libmydata1.install: add, it installs all /usr/lib/* stuff.
* [9908ebb] debian/eatmydata.manpages: add to install the manpage.
* debian/watch, debian/upstream/signing-key.asc
  + [42f1561] add.
  + [86912da] fix debian-watch-may-check-gpg-signature lintian tag.
* debian/README.debian: drop, it's useless.

* Upload sponsored by Petter Reinholdtsen.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* BEGIN LICENSE
 
2
 * Copyright (C) 2008-2012 Stewart Smith <stewart@flamingspork.com>
 
3
 * This program is free software: you can redistribute it and/or modify it 
 
4
 * under the terms of the GNU General Public License version 3, as published 
 
5
 * by the Free Software Foundation.
 
6
 * 
 
7
 * This program is distributed in the hope that it will be useful, but 
 
8
 * WITHOUT ANY WARRANTY; without even the implied warranties of 
 
9
 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR 
 
10
 * PURPOSE.  See the GNU General Public License for more details.
 
11
 * 
 
12
 * You should have received a copy of the GNU General Public License along 
 
13
 * with this program.  If not, see <http://www.gnu.org/licenses/>.
 
14
 * END LICENSE */
 
15
 
 
16
#include "config.h"
 
17
#include "libeatmydata/visibility.h"
 
18
 
 
19
#undef _FILE_OFFSET_BITS // Hack to get open and open64 on 32bit
 
20
#undef __USE_FILE_OFFSET64
 
21
#include <sys/types.h>
 
22
#include <unistd.h>
 
23
#include <errno.h>
 
24
#include <sys/stat.h>
 
25
#include <fcntl.h>
 
26
#include <dlfcn.h>
 
27
#include <stdarg.h>
 
28
#include <pthread.h>
 
29
 
 
30
/* 
 
31
#define CHECK_FILE "/tmp/eatmydata"
 
32
*/
 
33
 
 
34
/*
 
35
 * Mac OS X 10.7 doesn't declare fdatasync().
 
36
 */
 
37
#if defined HAVE_DECL_FDATASYNC && !HAVE_DECL_FDATASYNC
 
38
int fdatasync(int fd);
 
39
#endif
 
40
 
 
41
typedef int (*libc_open_t)(const char*, int, ...);
 
42
typedef int (*libc_open64_t)(const char*, int, ...);
 
43
typedef int (*libc_fsync_t)(int);
 
44
typedef int (*libc_sync_t)(void);
 
45
typedef int (*libc_fdatasync_t)(int);
 
46
typedef int (*libc_msync_t)(void*, size_t, int);
 
47
#ifdef HAVE_SYNC_FILE_RANGE
 
48
typedef int (*libc_sync_file_range_t)(int, off64_t, off64_t, unsigned int);
 
49
#endif
 
50
 
 
51
static libc_open_t libc_open= NULL;
 
52
static libc_open64_t libc_open64= NULL;
 
53
static libc_fsync_t libc_fsync= NULL;
 
54
static libc_sync_t libc_sync= NULL;
 
55
static libc_fdatasync_t libc_fdatasync= NULL;
 
56
static libc_msync_t libc_msync= NULL;
 
57
#ifdef HAVE_SYNC_FILE_RANGE
 
58
static libc_sync_file_range_t libc_sync_file_range= NULL;
 
59
#endif
 
60
 
 
61
#define ASSIGN_DLSYM_OR_DIE(name)                       \
 
62
        libc_##name = (libc_##name##_##t)(intptr_t)dlsym(RTLD_NEXT, #name);                     \
 
63
        if (!libc_##name || dlerror())                          \
 
64
                _exit(1);
 
65
 
 
66
#define ASSIGN_DLSYM_IF_EXIST(name)                     \
 
67
        libc_##name = (libc_##name##_##t)(intptr_t)dlsym(RTLD_NEXT, #name);                     \
 
68
                                                   dlerror();
 
69
 
 
70
 
 
71
int LIBEATMYDATA_API msync(void *addr, size_t length, int flags);
 
72
 
 
73
void __attribute__ ((constructor)) eatmydata_init(void);
 
74
 
 
75
void __attribute__ ((constructor)) eatmydata_init(void)
 
76
{
 
77
        ASSIGN_DLSYM_OR_DIE(open);
 
78
        ASSIGN_DLSYM_OR_DIE(open64);
 
79
        ASSIGN_DLSYM_OR_DIE(fsync);
 
80
        ASSIGN_DLSYM_OR_DIE(sync);
 
81
        ASSIGN_DLSYM_OR_DIE(fdatasync);
 
82
        ASSIGN_DLSYM_OR_DIE(msync);
 
83
#ifdef HAVE_SYNC_FILE_RANGE
 
84
        ASSIGN_DLSYM_IF_EXIST(sync_file_range);
 
85
#endif
 
86
}
 
87
 
 
88
static int eatmydata_is_hungry(void)
 
89
{
 
90
        /* Init here, as it is called before any libc functions */
 
91
        if(!libc_open)
 
92
                eatmydata_init();
 
93
 
 
94
#ifdef CHECK_FILE
 
95
        static struct stat buf;
 
96
        int old_errno, stat_ret;
 
97
 
 
98
        old_errno= errno;
 
99
        stat_ret= stat(CHECK_FILE, &buf);
 
100
        errno= old_errno;
 
101
 
 
102
        /* Treat any error as if file doesn't exist, for safety */
 
103
        return !stat_ret;
 
104
#else
 
105
        /* Always hungry! */
 
106
        return 1;
 
107
#endif
 
108
}
 
109
 
 
110
int LIBEATMYDATA_API fsync(int fd)
 
111
{
 
112
        if (eatmydata_is_hungry()) {
 
113
                pthread_testcancel();
 
114
                errno= 0;
 
115
                return 0;
 
116
        }
 
117
 
 
118
        return (*libc_fsync)(fd);
 
119
}
 
120
 
 
121
/* no errors are defined for this function */
 
122
void LIBEATMYDATA_API sync(void)
 
123
{
 
124
        if (eatmydata_is_hungry()) {
 
125
                pthread_testcancel();
 
126
                return;
 
127
        }
 
128
 
 
129
        (*libc_sync)();
 
130
}
 
131
 
 
132
int LIBEATMYDATA_API open(const char* pathname, int flags, ...)
 
133
{
 
134
        va_list ap;
 
135
        mode_t mode;
 
136
 
 
137
        va_start(ap, flags);
 
138
#if SIZEOF_MODE_T < SIZEOF_INT
 
139
        mode= (mode_t) va_arg(ap, int);
 
140
#else
 
141
        mode= va_arg(ap, mode_t);
 
142
#endif
 
143
        va_end(ap);
 
144
 
 
145
        /* In pthread environments the dlsym() may call our open(). */
 
146
        /* We simply ignore it because libc is already loaded       */
 
147
        if (!libc_open) {
 
148
                errno = EFAULT;
 
149
                return -1;
 
150
        }
 
151
 
 
152
        if (eatmydata_is_hungry())
 
153
                flags &= ~(O_SYNC|O_DSYNC);
 
154
 
 
155
        return (*libc_open)(pathname,flags,mode);
 
156
}
 
157
 
 
158
#ifndef __USE_FILE_OFFSET64
 
159
int LIBEATMYDATA_API open64(const char* pathname, int flags, ...)
 
160
{
 
161
        va_list ap;
 
162
        mode_t mode;
 
163
 
 
164
        va_start(ap, flags);
 
165
#if SIZEOF_MODE_T < SIZEOF_INT
 
166
        mode= (mode_t) va_arg(ap, int);
 
167
#else
 
168
        mode= va_arg(ap, mode_t);
 
169
#endif
 
170
        va_end(ap);
 
171
 
 
172
        /* In pthread environments the dlsym() may call our open(). */
 
173
        /* We simply ignore it because libc is already loaded       */
 
174
        if (!libc_open64) {
 
175
                errno = EFAULT;
 
176
                return -1;
 
177
        }
 
178
 
 
179
        if (eatmydata_is_hungry())
 
180
                flags &= ~(O_SYNC|O_DSYNC);
 
181
 
 
182
        return (*libc_open64)(pathname,flags,mode);
 
183
}
 
184
#endif
 
185
 
 
186
int LIBEATMYDATA_API fdatasync(int fd)
 
187
{
 
188
        if (eatmydata_is_hungry()) {
 
189
                pthread_testcancel();
 
190
                errno= 0;
 
191
                return 0;
 
192
        }
 
193
 
 
194
        return (*libc_fdatasync)(fd);
 
195
}
 
196
 
 
197
int LIBEATMYDATA_API msync(void *addr, size_t length, int flags)
 
198
{
 
199
        if (eatmydata_is_hungry()) {
 
200
                pthread_testcancel();
 
201
                errno= 0;
 
202
                return 0;
 
203
        }
 
204
 
 
205
        return (*libc_msync)(addr, length, flags);
 
206
}
 
207
 
 
208
#ifdef HAVE_SYNC_FILE_RANGE
 
209
int sync_file_range(int fd, off64_t offset, off64_t nbytes, unsigned int flags)
 
210
{
 
211
        if (eatmydata_is_hungry()) {
 
212
                pthread_testcancel();
 
213
                errno= 0;
 
214
                return 0;
 
215
        }
 
216
 
 
217
        return (libc_sync_file_range)(fd, offset, nbytes, flags);
 
218
}
 
219
#endif