X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Futil.c;h=4795dbcc6aca0358795bafb460ff5a032d58ee04;hb=9e58ff9c5c3bd46a796a20fc6c304cdab489f334;hp=8c22dbefa985b074bd8a945e1d81f65bf3d8b31f;hpb=c59760eedae9d9de3be1572b9b612dfd8cc37547;p=elogind.git diff --git a/src/util.c b/src/util.c index 8c22dbefa..4795dbcc6 100644 --- a/src/util.c +++ b/src/util.c @@ -601,6 +601,7 @@ int get_process_cmdline(pid_t pid, size_t max_length, char **line) { break; *(k++) = ' '; + left--; space = false; } @@ -608,6 +609,7 @@ int get_process_cmdline(pid_t pid, size_t max_length, char **line) { break; *(k++) = (char) c; + left--; } else space = true; } @@ -2625,6 +2627,30 @@ cpu_set_t* cpu_set_malloc(unsigned *ncpus) { } } +void status_vprintf(const char *format, va_list ap) { + char *s = NULL; + int fd = -1; + + assert(format); + + /* This independent of logging, as status messages are + * optional and go exclusively to the console. */ + + if (vasprintf(&s, format, ap) < 0) + goto finish; + + if ((fd = open_terminal("/dev/console", O_WRONLY|O_NOCTTY|O_CLOEXEC)) < 0) + goto finish; + + write(fd, s, strlen(s)); + +finish: + free(s); + + if (fd >= 0) + close_nointr_nofail(fd); +} + static const char *const ioprio_class_table[] = { [IOPRIO_CLASS_NONE] = "none", [IOPRIO_CLASS_RT] = "realtime",