mirror of
https://github.com/systemd/systemd.git
synced 2024-12-23 21:35:11 +03:00
Merge pull request #32437 from keszybz/notify-fixups-split-out
Two fixups for sd-notify split out from #32093
This commit is contained in:
commit
5e1124b510
@ -104,8 +104,8 @@
|
||||
<para>If the <parameter>unset_environment</parameter> parameter is non-zero,
|
||||
<function>sd_notify()</function> will unset the <varname>$NOTIFY_SOCKET</varname> environment variable
|
||||
before returning (regardless of whether the function call itself succeeded or not). Further calls to
|
||||
<function>sd_notify()</function> will then fail, and the variable is no longer inherited by child
|
||||
processes.</para>
|
||||
<function>sd_notify()</function> will then silently do nothing, and the variable is no longer inherited
|
||||
by child processes.</para>
|
||||
|
||||
<para>The <parameter>state</parameter> parameter should contain a newline-separated list of variable
|
||||
assignments, similar in style to an environment block. A trailing newline is implied if none is
|
||||
|
@ -650,7 +650,7 @@ _public_ int sd_notify(int unset_environment, const char *state) {
|
||||
|
||||
_public_ int sd_pid_notifyf(pid_t pid, int unset_environment, const char *format, ...) {
|
||||
_cleanup_free_ char *p = NULL;
|
||||
int r;
|
||||
int r = 0, k;
|
||||
|
||||
if (format) {
|
||||
va_list ap;
|
||||
@ -659,16 +659,20 @@ _public_ int sd_pid_notifyf(pid_t pid, int unset_environment, const char *format
|
||||
r = vasprintf(&p, format, ap);
|
||||
va_end(ap);
|
||||
|
||||
if (r < 0 || !p)
|
||||
return -ENOMEM;
|
||||
if (r < 0 || !p) {
|
||||
r = -ENOMEM;
|
||||
p = mfree(p); /* If vasprintf failed, do not use the string,
|
||||
* even if something was returned. */
|
||||
}
|
||||
}
|
||||
|
||||
return sd_pid_notify(pid, unset_environment, p);
|
||||
k = sd_pid_notify(pid, unset_environment, p);
|
||||
return r < 0 ? r : k;
|
||||
}
|
||||
|
||||
_public_ int sd_notifyf(int unset_environment, const char *format, ...) {
|
||||
_cleanup_free_ char *p = NULL;
|
||||
int r;
|
||||
int r = 0, k;
|
||||
|
||||
if (format) {
|
||||
va_list ap;
|
||||
@ -677,11 +681,15 @@ _public_ int sd_notifyf(int unset_environment, const char *format, ...) {
|
||||
r = vasprintf(&p, format, ap);
|
||||
va_end(ap);
|
||||
|
||||
if (r < 0 || !p)
|
||||
return -ENOMEM;
|
||||
if (r < 0 || !p) {
|
||||
r = -ENOMEM;
|
||||
p = mfree(p); /* If vasprintf failed, do not use the string,
|
||||
* even if something was returned. */
|
||||
}
|
||||
}
|
||||
|
||||
return sd_pid_notify(0, unset_environment, p);
|
||||
k = sd_pid_notify(0, unset_environment, p);
|
||||
return r < 0 ? r : k;
|
||||
}
|
||||
|
||||
_public_ int sd_pid_notifyf_with_fds(
|
||||
@ -691,27 +699,31 @@ _public_ int sd_pid_notifyf_with_fds(
|
||||
const char *format, ...) {
|
||||
|
||||
_cleanup_free_ char *p = NULL;
|
||||
int r;
|
||||
int r = 0, k;
|
||||
|
||||
/* Paranoia check: we traditionally used 'unsigned' as array size, but we nowadays more correctly use
|
||||
* 'size_t'. sd_pid_notifyf_with_fds() and sd_pid_notify_with_fds() are from different eras, hence
|
||||
* differ in this. Let's catch resulting incompatibilites early, even though they are pretty much
|
||||
* theoretic only */
|
||||
if (n_fds > UINT_MAX)
|
||||
return -E2BIG;
|
||||
r = -E2BIG;
|
||||
|
||||
if (format) {
|
||||
else if (format) {
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, format);
|
||||
r = vasprintf(&p, format, ap);
|
||||
va_end(ap);
|
||||
|
||||
if (r < 0 || !p)
|
||||
return -ENOMEM;
|
||||
if (r < 0 || !p) {
|
||||
r = -ENOMEM;
|
||||
p = mfree(p); /* If vasprintf failed, do not use the string,
|
||||
* even if something was returned. */
|
||||
}
|
||||
}
|
||||
|
||||
return sd_pid_notify_with_fds(pid, unset_environment, p, fds, n_fds);
|
||||
k = sd_pid_notify_with_fds(pid, unset_environment, p, fds, n_fds);
|
||||
return r < 0 ? r : k;
|
||||
}
|
||||
|
||||
_public_ int sd_booted(void) {
|
||||
|
Loading…
Reference in New Issue
Block a user