chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
util-lib: introduce parse_percent() for parsing percent specifications
[elogind.git]
/
src
/
basic
/
util.c
diff --git
a/src/basic/util.c
b/src/basic/util.c
index 8f2317f2852906c81cd21991ffbed22ae3593927..12f7e1b0512a900e9335582ae1045beb82e1f6c2 100644
(file)
--- a/
src/basic/util.c
+++ b/
src/basic/util.c
@@
-55,6
+55,7
@@
#include "string-util.h"
#include "strv.h"
#include "time-util.h"
#include "string-util.h"
#include "strv.h"
#include "time-util.h"
+#include "umask-util.h"
#include "user-util.h"
#include "util.h"
#include "user-util.h"
#include "util.h"
@@
-412,10
+413,10
@@
int fork_agent(pid_t *pid, const int except[], unsigned n_except, const char *pa
/* Detach from stdout/stderr. and reopen
* /dev/tty for them. This is important to
/* Detach from stdout/stderr. and reopen
* /dev/tty for them. This is important to
- * ensure that when
system
ctl is started via
+ * ensure that when
login
ctl is started via
* popen() or a similar call that expects to
* read EOF we actually do generate EOF and
* popen() or a similar call that expects to
* read EOF we actually do generate EOF and
- * not delay this indefinitely b
y b
ecause we
+ * not delay this indefinitely because we
* keep an unused copy of stdin around. */
fd = open("/dev/tty", O_WRONLY);
if (fd < 0) {
* keep an unused copy of stdin around. */
fd = open("/dev/tty", O_WRONLY);
if (fd < 0) {
@@
-423,13
+424,17
@@
int fork_agent(pid_t *pid, const int except[], unsigned n_except, const char *pa
_exit(EXIT_FAILURE);
}
_exit(EXIT_FAILURE);
}
- if (!stdout_is_tty)
- dup2(fd, STDOUT_FILENO);
+ if (!stdout_is_tty && dup2(fd, STDOUT_FILENO) < 0) {
+ log_error_errno(errno, "Failed to dup2 /dev/tty: %m");
+ _exit(EXIT_FAILURE);
+ }
- if (!stderr_is_tty)
- dup2(fd, STDERR_FILENO);
+ if (!stderr_is_tty && dup2(fd, STDERR_FILENO) < 0) {
+ log_error_errno(errno, "Failed to dup2 /dev/tty: %m");
+ _exit(EXIT_FAILURE);
+ }
- if (fd >
2
)
+ if (fd >
STDERR_FILENO
)
close(fd);
}
close(fd);
}
@@
-522,7
+527,7
@@
int on_ac_power(void) {
if (!de)
break;
if (!de)
break;
- if (hidden_file(de->d_name))
+ if (hidden_
or_backup_
file(de->d_name))
continue;
device = openat(dirfd(d), de->d_name, O_DIRECTORY|O_RDONLY|O_CLOEXEC|O_NOCTTY);
continue;
device = openat(dirfd(d), de->d_name, O_DIRECTORY|O_RDONLY|O_CLOEXEC|O_NOCTTY);
@@
-780,15
+785,25
@@
uint64_t physical_memory(void) {
}
#if 0 /// UNNEEDED by elogind
}
#if 0 /// UNNEEDED by elogind
-int update_reboot_param_file(const char *param) {
- int r = 0;
+int update_reboot_parameter_and_warn(const char *param) {
+ int r;
+
+ if (isempty(param)) {
+ if (unlink("/run/systemd/reboot-param") < 0) {
+ if (errno == ENOENT)
+ return 0;
- if (param) {
- r = write_string_file(REBOOT_PARAM_FILE, param, WRITE_STRING_FILE_CREATE);
+ return log_warning_errno(errno, "Failed to unlink reboot parameter file: %m");
+ }
+
+ return 0;
+ }
+
+ RUN_WITH_UMASK(0022) {
+ r = write_string_file("/run/systemd/reboot-param", param, WRITE_STRING_FILE_CREATE);
if (r < 0)
if (r < 0)
- return log_error_errno(r, "Failed to write reboot param to "REBOOT_PARAM_FILE": %m");
- } else
- (void) unlink(REBOOT_PARAM_FILE);
+ return log_warning_errno(r, "Failed to write reboot parameter file: %m");
+ }
return 0;
}
return 0;
}