[systemd-commits] 4 commits - src/core src/shared
Michal Schmidt
michich at kemper.freedesktop.org
Fri Mar 8 01:59:46 PST 2013
src/core/path.c | 47 +++++++++++++++++++++++++----------------------
src/shared/set.c | 16 ----------------
src/shared/set.h | 10 ++++++++--
src/shared/strv.c | 8 --------
src/shared/strv.h | 5 ++++-
src/shared/util.c | 10 +---------
src/shared/util.h | 9 +++++++--
7 files changed, 45 insertions(+), 60 deletions(-)
New commits:
commit f620dff8dd8822b837f314b8cd74c88bc74226a0
Author: Michal Schmidt <mschmidt at redhat.com>
Date: Fri Mar 8 10:46:26 2013 +0100
util: fix printing of welcome message
Commit 984a2be4 failed to adjust this caller of status_printf().
diff --git a/src/shared/util.c b/src/shared/util.c
index 594f8de..dc2651f 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -2963,7 +2963,7 @@ int status_welcome(void) {
if (r < 0 && r != -ENOENT)
log_warning("Failed to read /etc/os-release: %s", strerror(-r));
- return status_printf(NULL, false,
+ return status_printf(NULL, false, false,
"\nWelcome to \x1B[%sm%s\x1B[0m!\n",
isempty(ansi_color) ? "1" : ansi_color,
isempty(pretty_name) ? "Linux" : pretty_name);
commit 180d6802e585e8a2826b76872438641b73e3fa6f
Author: Michal Schmidt <mschmidt at redhat.com>
Date: Wed Mar 6 19:28:55 2013 +0100
path: avoid an allocation in path_spec_watch
No need for strdup. We can slice the path in place if we always undo it
afterwards.
diff --git a/src/core/path.c b/src/core/path.c
index 01a2b08..295e5cd 100644
--- a/src/core/path.c
+++ b/src/core/path.c
@@ -53,7 +53,6 @@ int path_spec_watch(PathSpec *s, Unit *u) {
};
bool exists = false;
- char _cleanup_free_ *path = NULL;
char *slash, *oldslash = NULL;
int r;
@@ -62,10 +61,6 @@ int path_spec_watch(PathSpec *s, Unit *u) {
path_spec_unwatch(s, u);
- path = strdup(s->path);
- if (!path)
- return -ENOMEM;
-
s->inotify_fd = inotify_init1(IN_NONBLOCK|IN_CLOEXEC);
if (s->inotify_fd < 0) {
r = -errno;
@@ -78,25 +73,32 @@ int path_spec_watch(PathSpec *s, Unit *u) {
/* This assumes the path was passed through path_kill_slashes()! */
- for(slash = strchr(path, '/'); ; slash = strchr(slash+1, '/')) {
+ for (slash = strchr(s->path, '/'); ; slash = strchr(slash+1, '/')) {
+ char *cut = NULL;
int flags;
char tmp;
if (slash) {
- tmp = slash[slash == path];
- slash[slash == path] = '\0';
+ cut = slash + (slash == s->path);
+ tmp = *cut;
+ *cut = '\0';
+
flags = IN_MOVE_SELF | IN_DELETE_SELF | IN_ATTRIB | IN_CREATE | IN_MOVED_TO;
- } else {
+ } else
flags = flags_table[s->type];
- }
- r = inotify_add_watch(s->inotify_fd, path, flags);
+ r = inotify_add_watch(s->inotify_fd, s->path, flags);
if (r < 0) {
- if (errno == EACCES || errno == ENOENT)
+ if (errno == EACCES || errno == ENOENT) {
+ if (cut)
+ *cut = tmp;
break;
+ }
- log_warning("Failed to add watch on %s: %m", path);
+ log_warning("Failed to add watch on %s: %m", s->path);
r = -errno;
+ if (cut)
+ *cut = tmp;
goto fail;
} else {
exists = true;
@@ -104,29 +106,30 @@ int path_spec_watch(PathSpec *s, Unit *u) {
/* Path exists, we don't need to watch parent
too closely. */
if (oldslash) {
- char tmp2 = oldslash[oldslash == path];
- oldslash[oldslash == path] = '\0';
+ char *cut2 = oldslash + (oldslash == s->path);
+ char tmp2 = *cut2;
+ *cut2 = '\0';
- inotify_add_watch(s->inotify_fd, path, IN_MOVE_SELF);
+ inotify_add_watch(s->inotify_fd, s->path, IN_MOVE_SELF);
/* Error is ignored, the worst can happen is
we get spurious events. */
- oldslash[oldslash == path] = tmp2;
+ *cut2 = tmp2;
}
}
- if (slash) {
- slash[slash == path] = tmp;
+ if (cut)
+ *cut = tmp;
+
+ if (slash)
oldslash = slash;
- } else {
+ else {
/* whole path has been iterated over */
s->primary_wd = r;
break;
}
}
- assert(errno == EACCES || errno == ENOENT || streq(path, s->path));
-
if (!exists) {
log_error("Failed to add watch on any of the components of %s: %m",
s->path);
commit a740c14c59907f370a6b3a3ba5a86fada88cb07e
Author: Michal Schmidt <mschmidt at redhat.com>
Date: Wed Mar 6 14:44:51 2013 +0100
shared: inline trivial auto-cleanup functions
diff --git a/src/shared/set.c b/src/shared/set.c
index 111d53b..5f83c50 100644
--- a/src/shared/set.c
+++ b/src/shared/set.c
@@ -37,18 +37,10 @@ void set_free(Set* s) {
hashmap_free(MAKE_HASHMAP(s));
}
-void set_freep(Set **s) {
- set_free(*s);
-}
-
void set_free_free(Set *s) {
hashmap_free_free(MAKE_HASHMAP(s));
}
-void set_free_freep(Set **s) {
- set_free_free(*s);
-}
-
int set_ensure_allocated(Set **s, hash_func_t hash_func, compare_func_t compare_func) {
return hashmap_ensure_allocated((Hashmap**) s, hash_func, compare_func);
}
diff --git a/src/shared/set.h b/src/shared/set.h
index 2f79258..38c4b58 100644
--- a/src/shared/set.h
+++ b/src/shared/set.h
@@ -33,9 +33,15 @@ typedef struct Set Set;
Set *set_new(hash_func_t hash_func, compare_func_t compare_func);
void set_free(Set* s);
-void set_freep(Set **s);
+static inline void set_freep(Set **s) {
+ set_free(*s);
+}
+
void set_free_free(Set *s);
-void set_free_freep(Set **s);
+static inline void set_free_freep(Set **s) {
+ set_free_free(*s);
+}
+
Set* set_copy(Set *s);
int set_ensure_allocated(Set **s, hash_func_t hash_func, compare_func_t compare_func);
diff --git a/src/shared/strv.c b/src/shared/strv.c
index 117382e..7bcfabb 100644
--- a/src/shared/strv.c
+++ b/src/shared/strv.c
@@ -64,10 +64,6 @@ void strv_free(char **l) {
free(l);
}
-void strv_freep(char ***l) {
- strv_free(*l);
-}
-
char **strv_copy(char **l) {
char **r, **k;
diff --git a/src/shared/strv.h b/src/shared/strv.h
index 623f102..da9fae6 100644
--- a/src/shared/strv.h
+++ b/src/shared/strv.h
@@ -30,7 +30,10 @@ char *strv_find(char **l, const char *name);
char *strv_find_prefix(char **l, const char *name);
void strv_free(char **l);
-void strv_freep(char ***l);
+static inline void strv_freep(char ***l) {
+ strv_free(*l);
+}
+
char **strv_copy(char **l) _malloc_;
unsigned strv_length(char **l);
diff --git a/src/shared/util.c b/src/shared/util.c
index c493a34..594f8de 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -5237,10 +5237,6 @@ int get_shell(char **_sh) {
return 0;
}
-void freep(void *p) {
- free(*(void**) p);
-}
-
void fclosep(FILE **f) {
if (*f)
fclose(*f);
@@ -5261,10 +5257,6 @@ void closedirp(DIR **d) {
closedir(*d);
}
-void umaskp(mode_t *u) {
- umask(*u);
-}
-
bool filename_is_safe(const char *p) {
if (isempty(p))
diff --git a/src/shared/util.h b/src/shared/util.h
index 27b21f9..04c9fcd 100644
--- a/src/shared/util.h
+++ b/src/shared/util.h
@@ -519,12 +519,17 @@ void warn_melody(void);
int get_shell(char **ret);
int get_home_dir(char **ret);
-void freep(void *p);
+static inline void freep(void *p) {
+ free(*(void**) p);
+}
+
void fclosep(FILE **f);
void pclosep(FILE **f);
void closep(int *fd);
void closedirp(DIR **d);
-void umaskp(mode_t *u);
+static inline void umaskp(mode_t *u) {
+ umask(*u);
+}
_malloc_ static inline void *malloc_multiply(size_t a, size_t b) {
if (_unlikely_(b == 0 || a > ((size_t) -1) / b))
commit 5f1be48b264e4d556f688062cc6f4a1e03f9f455
Author: Michal Schmidt <mschmidt at redhat.com>
Date: Wed Mar 6 14:17:59 2013 +0100
shared: remove pointless checks in auto-cleanup functions
The argument given to the __attribute__((cleanup)) functions is the
address of the variable that's going out of scope. It cannot be NULL.
The "if (!s)" check in set_freep() is pointless.
Perhaps "if (!*s)" was intented. But that's pointless too, because
set_free()/set_free_free() are OK to call with a NULL argument (just
like free()).
Setting "*s = NULL" is pointless, because the variable that s points
to is about to go out of scope.
The same holds for strv_freep().
diff --git a/src/shared/set.c b/src/shared/set.c
index cd910d7..111d53b 100644
--- a/src/shared/set.c
+++ b/src/shared/set.c
@@ -38,11 +38,7 @@ void set_free(Set* s) {
}
void set_freep(Set **s) {
- if (!s)
- return;
-
set_free(*s);
- *s = NULL;
}
void set_free_free(Set *s) {
@@ -50,11 +46,7 @@ void set_free_free(Set *s) {
}
void set_free_freep(Set **s) {
- if (!*s)
- return;
-
set_free_free(*s);
- *s = NULL;
}
int set_ensure_allocated(Set **s, hash_func_t hash_func, compare_func_t compare_func) {
diff --git a/src/shared/strv.c b/src/shared/strv.c
index 60c4762..117382e 100644
--- a/src/shared/strv.c
+++ b/src/shared/strv.c
@@ -65,11 +65,7 @@ void strv_free(char **l) {
}
void strv_freep(char ***l) {
- if (!l)
- return;
-
strv_free(*l);
- *l = NULL;
}
char **strv_copy(char **l) {
More information about the systemd-commits
mailing list