summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2012-09-14 10:36:50 +0200
committerLennart Poettering <lennart@poettering.net>2012-09-14 10:36:50 +0200
commit73836c5c430f48838fec2606b1729dda371edd2d (patch)
tree2956da2256a07629144b201eacdcc321414cc0d8
parenta05f97b3ac590bc313e8c9d1613d06de0bf28ae2 (diff)
util: more modernizations
-rw-r--r--src/shared/util.c32
1 files changed, 21 insertions, 11 deletions
diff --git a/src/shared/util.c b/src/shared/util.c
index 007f15d680..6a40cf1d80 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -2050,7 +2050,7 @@ bool fstype_is_network(const char *fstype) {
"nfs\0"
"nfs4\0"
"gfs\0"
- "gfs2";
+ "gfs2\0";
return nulstr_contains(table, fstype);
}
@@ -2904,9 +2904,9 @@ int make_stdio(int fd) {
assert(fd >= 0);
- r = dup2(fd, STDIN_FILENO);
- s = dup2(fd, STDOUT_FILENO);
- t = dup2(fd, STDERR_FILENO);
+ r = dup3(fd, STDIN_FILENO, 0);
+ s = dup3(fd, STDOUT_FILENO, 0);
+ t = dup3(fd, STDERR_FILENO, 0);
if (fd >= 3)
close_nointr_nofail(fd);
@@ -2914,9 +2914,7 @@ int make_stdio(int fd) {
if (r < 0 || s < 0 || t < 0)
return -errno;
- fd_cloexec(STDIN_FILENO, false);
- fd_cloexec(STDOUT_FILENO, false);
- fd_cloexec(STDERR_FILENO, false);
+ /* We rely here that the new fd has O_CLOEXEC not set */
return 0;
}
@@ -3870,7 +3868,12 @@ int touch(const char *path) {
assert(path);
- if ((fd = open(path, O_WRONLY|O_CREAT|O_CLOEXEC|O_NOCTTY, 0644)) < 0)
+ /* This just opens the file for writing, ensuring it
+ * exists. It doesn't call utimensat() the way /usr/bin/touch
+ * does it. */
+
+ fd = open(path, O_WRONLY|O_CREAT|O_CLOEXEC|O_NOCTTY, 0644);
+ if (fd < 0)
return -errno;
close_nointr_nofail(fd);
@@ -3881,6 +3884,10 @@ char *unquote(const char *s, const char* quotes) {
size_t l;
assert(s);
+ /* This is rather stupid, simply removes the heading and
+ * trailing quotes if there is one. Doesn't care about
+ * escaping or anything. */
+
l = strlen(s);
if (l < 2)
return strdup(s);
@@ -4022,10 +4029,12 @@ DIR *xopendirat(int fd, const char *name, int flags) {
int nfd;
DIR *d;
- if ((nfd = openat(fd, name, O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC|flags)) < 0)
+ nfd = openat(fd, name, O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC|flags);
+ if (nfd < 0)
return NULL;
- if (!(d = fdopendir(nfd))) {
+ d = fdopendir(nfd);
+ if (!d) {
close_nointr_nofail(nfd);
return NULL;
}
@@ -4037,7 +4046,8 @@ int signal_from_string_try_harder(const char *s) {
int signo;
assert(s);
- if ((signo = signal_from_string(s)) <= 0)
+ signo = signal_from_string(s);
+ if (signo <= 0)
if (startswith(s, "SIG"))
return signal_from_string(s+3);