chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
update fixme
[elogind.git]
/
src
/
util.c
diff --git
a/src/util.c
b/src/util.c
index da8a6c33361863a08d32b60c39393e3675bec237..0b0063ee0e6078a48cdec42f053be97c42a7742a 100644
(file)
--- a/
src/util.c
+++ b/
src/util.c
@@
-1,4
+1,4
@@
-/*-*- Mode: C; c-basic-offset: 8 -*-*/
+/*-*- Mode: C; c-basic-offset: 8
; indent-tabs-mode: nil
-*-*/
/***
This file is part of systemd.
/***
This file is part of systemd.
@@
-48,6
+48,7
@@
#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 "macro.h"
#include "util.h"
#include "macro.h"
#include "util.h"
@@
-55,6
+56,7
@@
#include "missing.h"
#include "log.h"
#include "strv.h"
#include "missing.h"
#include "log.h"
#include "strv.h"
+#include "label.h"
bool streq_ptr(const char *a, const char *b) {
bool streq_ptr(const char *a, const char *b) {
@@
-969,7
+971,7
@@
char *file_in_same_dir(const char *path, const char *filename) {
int safe_mkdir(const char *path, mode_t mode, uid_t uid, gid_t gid) {
struct stat st;
int safe_mkdir(const char *path, mode_t mode, uid_t uid, gid_t gid) {
struct stat st;
- if (mkdir(path, mode) >= 0)
+ if (
label_
mkdir(path, mode) >= 0)
if (chmod_and_chown(path, mode, uid, gid) < 0)
return -errno;
if (chmod_and_chown(path, mode, uid, gid) < 0)
return -errno;
@@
-1012,7
+1014,7
@@
int mkdir_parents(const char *path, mode_t mode) {
if (!(t = strndup(path, e - path)))
return -ENOMEM;
if (!(t = strndup(path, e - path)))
return -ENOMEM;
- r = mkdir(t, mode);
+ r =
label_
mkdir(t, mode);
free(t);
if (r < 0 && errno != EEXIST)
free(t);
if (r < 0 && errno != EEXIST)
@@
-1028,7
+1030,7
@@
int mkdir_p(const char *path, mode_t mode) {
if ((r = mkdir_parents(path, mode)) < 0)
return r;
if ((r = mkdir_parents(path, mode)) < 0)
return r;
- if (mkdir(path, mode) < 0 && errno != EEXIST)
+ if (
label_
mkdir(path, mode) < 0 && errno != EEXIST)
return -errno;
return 0;
return -errno;
return 0;
@@
-1679,6
+1681,12
@@
char *format_timespan(char *buf, size_t l, usec_t t) {
if (t == (usec_t) -1)
return NULL;
if (t == (usec_t) -1)
return NULL;
+ if (t == 0) {
+ snprintf(p, l, "0");
+ p[l-1] = 0;
+ return p;
+ }
+
/* The result of this function can be parsed with parse_usec */
for (i = 0; i < ELEMENTSOF(table); i++) {
/* The result of this function can be parsed with parse_usec */
for (i = 0; i < ELEMENTSOF(table); i++) {
@@
-2485,18
+2493,6
@@
char* gethostname_malloc(void) {
return strdup(u.sysname);
}
return strdup(u.sysname);
}
-int getmachineid_malloc(char **b) {
- int r;
-
- assert(b);
-
- if ((r = read_one_line_file("/var/lib/dbus/machine-id", b)) < 0)
- return r;
-
- strstrip(*b);
- return 0;
-}
-
char* getlogname_malloc(void) {
uid_t uid;
long bufsize;
char* getlogname_malloc(void) {
uid_t uid;
long bufsize;
@@
-2535,11
+2531,12
@@
char* getlogname_malloc(void) {
int getttyname_malloc(char **r) {
char path[PATH_MAX], *p, *c;
int getttyname_malloc(char **r) {
char path[PATH_MAX], *p, *c;
+ int k;
assert(r);
assert(r);
- if (
ttyname_r(STDIN_FILENO, path, sizeof(path)) <
0)
- return -
errno
;
+ if (
(k = ttyname_r(STDIN_FILENO, path, sizeof(path))) !=
0)
+ return -
k
;
char_array_0(path);
char_array_0(path);
@@
-2822,18
+2819,18
@@
char *replace_env(const char *format, char **env) {
case VARIABLE:
if (*e == '}') {
case VARIABLE:
if (*e == '}') {
- char *t;
+ c
onst c
har *t;
- if ((t = strv_env_get_with_length(env, word+2, e-word-2))) {
- if (!(k = strappend(r, t)))
- goto fail;
+ if (!(t = strv_env_get_with_length(env, word+2, e-word-2)))
+ t = "";
- free(r);
-
r = k
;
+ if (!(k = strappend(r, t)))
+
goto fail
;
-
word = e+1
;
- }
+
free(r)
;
+ r = k;
+ word = e+1;
state = WORD;
}
break;
state = WORD;
}
break;
@@
-2863,36
+2860,39
@@
char **replace_env_argv(char **argv, char **env) {
STRV_FOREACH(i, argv) {
/* If $FOO appears as single word, replace it by the split up variable */
STRV_FOREACH(i, argv) {
/* If $FOO appears as single word, replace it by the split up variable */
- if ((*i)[0] == '$') {
- char *e = strv_env_get(env, *i+1);
+ if ((*i)[0] == '$' && (*i)[1] != '{') {
+ char *e;
+ char **w, **m;
+ unsigned q;
- if (e) {
- char **w, **m;
- unsigned q;
+ if ((e = strv_env_get(env, *i+1))) {
if (!(m = strv_split_quoted(e))) {
r[k] = NULL;
strv_free(r);
return NULL;
}
if (!(m = strv_split_quoted(e))) {
r[k] = NULL;
strv_free(r);
return NULL;
}
+ } else
+ m = NULL;
-
q = strv_length(m);
-
l = l + q - 1;
+ q = strv_length(m);
+ l = l + q - 1;
-
if (!(w = realloc(r, sizeof(char*) * (l+1)))) {
-
r[k] = NULL;
-
strv_free(r);
-
strv_free(m);
-
return NULL;
-
}
+ if (!(w = realloc(r, sizeof(char*) * (l+1)))) {
+ r[k] = NULL;
+ strv_free(r);
+ strv_free(m);
+ return NULL;
+ }
- r = w;
+ r = w;
+ if (m) {
memcpy(r + k, m, q * sizeof(char*));
free(m);
memcpy(r + k, m, q * sizeof(char*));
free(m);
-
- k += q;
- continue;
}
}
+
+ k += q;
+ continue;
}
/* If ${FOO} appears as part of a word, replace it by the variable as-is */
}
/* If ${FOO} appears as part of a word, replace it by the variable as-is */
@@
-2981,6
+2981,18
@@
char *ellipsize(const char *s, unsigned length, unsigned percent) {
return r;
}
return r;
}
+int touch(const char *path) {
+ int fd;
+
+ assert(path);
+
+ if ((fd = open(path, O_WRONLY|O_CREAT|O_CLOEXEC|O_NOCTTY, 0666)) < 0)
+ return -errno;
+
+ close_nointr_nofail(fd);
+ return 0;
+}
+
static const char *const ioprio_class_table[] = {
[IOPRIO_CLASS_NONE] = "none",
[IOPRIO_CLASS_RT] = "realtime",
static const char *const ioprio_class_table[] = {
[IOPRIO_CLASS_NONE] = "none",
[IOPRIO_CLASS_RT] = "realtime",