1
0
mirror of https://github.com/systemd/systemd.git synced 2025-02-28 05:57:33 +03:00

Get rid of write_safe

Current glibc implementation is safe. Kernel does this atomically,
and write is actually implemented through writev. So if write is
async-signal-safe, than writev pretty much must be too.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2014-01-28 18:23:38 -05:00
parent 7b36bf82c4
commit 87b0284327
3 changed files with 7 additions and 25 deletions

View File

@ -314,7 +314,7 @@ _public_ int sd_journal_sendv(const struct iovec *iov, int n) {
if (buffer_fd < 0)
return buffer_fd;
n = writev_safe(buffer_fd, w, j);
n = writev(buffer_fd, w, j);
if (n < 0) {
close_nointr_nofail(buffer_fd);
return -errno;

View File

@ -6093,24 +6093,6 @@ int getpeersec(int fd, char **ret) {
return 0;
}
int writev_safe(int fd, const struct iovec *w, int j) {
for (int i = 0; i < j; i++) {
size_t written = 0;
while (written < w[i].iov_len) {
ssize_t r;
r = write(fd, (char*) w[i].iov_base + written, w[i].iov_len - written);
if (r < 0 && errno != -EINTR)
return -errno;
written += r;
}
}
return 0;
}
int mkostemp_safe(char *pattern, int flags) {
unsigned long tries = TMP_MAX;
char *s;

View File

@ -580,8 +580,8 @@ static void test_in_set(void) {
assert_se(!IN_SET(0, 1, 2, 3, 4));
}
static void test_writev_safe(void) {
char name[] = "/tmp/test-writev_safe.XXXXXX";
static void test_writing_tmpfile(void) {
char name[] = "/tmp/test-systemd_writing_tmpfile.XXXXXX";
_cleanup_free_ char *contents;
size_t size;
int fd, r;
@ -592,10 +592,10 @@ static void test_writev_safe(void) {
IOVEC_SET_STRING(iov[2], "");
fd = mkostemp_safe(name, O_RDWR|O_CLOEXEC);
printf("test_writev_safe: %s", name);
printf("tmpfile: %s", name);
r = writev_safe(fd, iov, 3);
assert(r == 0);
r = writev(fd, iov, 3);
assert(r >= 0);
r = read_full_file(name, &contents, &size);
assert(r == 0);
@ -640,7 +640,7 @@ int main(int argc, char *argv[]) {
test_fstab_node_to_udev_node();
test_get_files_in_directory();
test_in_set();
test_writev_safe();
test_writing_tmpfile();
return 0;
}