chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
add REMOTE_ADDR and REMOTE_PORT for Accept=yes
[elogind.git]
/
src
/
shared
/
util.c
diff --git
a/src/shared/util.c
b/src/shared/util.c
index ba035caed064315363af1f2358fb6a5b16f246ad..b90e10ffb2f05726f0e1dd80cead5de5fd3f9ab0 100644
(file)
--- a/
src/shared/util.c
+++ b/
src/shared/util.c
@@
-19,12
+19,13
@@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
-#include <assert.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <stdlib.h>
#include <signal.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <stdlib.h>
#include <signal.h>
+#include <libintl.h>
+#include <locale.h>
#include <stdio.h>
#include <syslog.h>
#include <sched.h>
#include <stdio.h>
#include <syslog.h>
#include <sched.h>
@@
-46,7
+47,6
@@
#include <pwd.h>
#include <netinet/ip.h>
#include <linux/kd.h>
#include <pwd.h>
#include <netinet/ip.h>
#include <linux/kd.h>
-#include <dlfcn.h>
#include <sys/wait.h>
#include <sys/time.h>
#include <glob.h>
#include <sys/wait.h>
#include <sys/time.h>
#include <glob.h>
@@
-74,13
+74,13
@@
#include <sys/auxv.h>
#endif
#include <sys/auxv.h>
#endif
+#include "config.h"
#include "macro.h"
#include "util.h"
#include "ioprio.h"
#include "missing.h"
#include "log.h"
#include "strv.h"
#include "macro.h"
#include "util.h"
#include "ioprio.h"
#include "missing.h"
#include "log.h"
#include "strv.h"
-#include "label.h"
#include "mkdir.h"
#include "path-util.h"
#include "exit-status.h"
#include "mkdir.h"
#include "path-util.h"
#include "exit-status.h"
@@
-1689,6
+1689,7
@@
bool chars_intersect(const char *a, const char *b) {
bool fstype_is_network(const char *fstype) {
static const char table[] =
bool fstype_is_network(const char *fstype) {
static const char table[] =
+ "afs\0"
"cifs\0"
"smbfs\0"
"sshfs\0"
"cifs\0"
"smbfs\0"
"sshfs\0"
@@
-2325,6
+2326,17
@@
ssize_t loop_read(int fd, void *buf, size_t nbytes, bool do_poll) {
return n;
}
return n;
}
+int loop_read_exact(int fd, void *buf, size_t nbytes, bool do_poll) {
+ ssize_t n;
+
+ n = loop_read(fd, buf, nbytes, do_poll);
+ if (n < 0)
+ return n;
+ if ((size_t) n != nbytes)
+ return -EIO;
+ return 0;
+}
+
int loop_write(int fd, const void *buf, size_t nbytes, bool do_poll) {
const uint8_t *p = buf;
int loop_write(int fd, const void *buf, size_t nbytes, bool do_poll) {
const uint8_t *p = buf;
@@
-2579,8
+2591,9
@@
char* dirname_malloc(const char *path) {
int dev_urandom(void *p, size_t n) {
static int have_syscall = -1;
int dev_urandom(void *p, size_t n) {
static int have_syscall = -1;
- int r, fd;
- ssize_t k;
+
+ _cleanup_close_ int fd = -1;
+ int r;
/* Gathers some randomness from the kernel. This call will
* never block, and will always return some data from the
/* Gathers some randomness from the kernel. This call will
* never block, and will always return some data from the
@@
-2615,22
+2628,14
@@
int dev_urandom(void *p, size_t n) {
return -errno;
} else
/* too short read? */
return -errno;
} else
/* too short read? */
- return -E
IO
;
+ return -E
NODATA
;
}
fd = open("/dev/urandom", O_RDONLY|O_CLOEXEC|O_NOCTTY);
if (fd < 0)
return errno == ENOENT ? -ENOSYS : -errno;
}
fd = open("/dev/urandom", O_RDONLY|O_CLOEXEC|O_NOCTTY);
if (fd < 0)
return errno == ENOENT ? -ENOSYS : -errno;
- k = loop_read(fd, p, n, true);
- safe_close(fd);
-
- if (k < 0)
- return (int) k;
- if ((size_t) k != n)
- return -EIO;
-
- return 0;
+ return loop_read_exact(fd, p, n, true);
}
void initialize_srand(void) {
}
void initialize_srand(void) {
@@
-5782,6
+5787,11
@@
void *xbsearch_r(const void *key, const void *base, size_t nmemb, size_t size,
return NULL;
}
return NULL;
}
+void init_gettext(void) {
+ setlocale(LC_ALL, "");
+ textdomain(GETTEXT_PACKAGE);
+}
+
bool is_locale_utf8(void) {
const char *set;
static int cached_answer = -1;
bool is_locale_utf8(void) {
const char *set;
static int cached_answer = -1;
@@
-5993,7
+6003,7
@@
int on_ac_power(void) {
d = opendir("/sys/class/power_supply");
if (!d)
d = opendir("/sys/class/power_supply");
if (!d)
- return -errno;
+ return
errno == ENOENT ? true :
-errno;
for (;;) {
struct dirent *de;
for (;;) {
struct dirent *de;
@@
-8102,3
+8112,13
@@
ssize_t string_table_lookup(const char * const *table, size_t len, const char *k
return -1;
}
return -1;
}
+
+void cmsg_close_all(struct msghdr *mh) {
+ struct cmsghdr *cmsg;
+
+ assert(mh);
+
+ for (cmsg = CMSG_FIRSTHDR(mh); cmsg; cmsg = CMSG_NXTHDR(mh, cmsg))
+ if (cmsg->cmsg_level == SOL_SOCKET && cmsg->cmsg_type == SCM_RIGHTS)
+ close_many((int*) CMSG_DATA(cmsg), (cmsg->cmsg_len - CMSG_LEN(0)) / sizeof(int));
+}