X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Futil.c;h=fecdee12e275b89f2b1220f9374142d550f13028;hb=1829dc9dc5f38cd1aaa43912de56c3bb5d8b5617;hp=973cee15e31a2d55fc49be2f2a9366d449f8a039;hpb=274914f99191e466bc523eadba74f52db8433189;p=elogind.git diff --git a/src/util.c b/src/util.c index 973cee15e..fecdee12e 100644 --- a/src/util.c +++ b/src/util.c @@ -2605,6 +2605,15 @@ int make_stdio(int fd) { return 0; } +int make_null_stdio(void) { + int null_fd; + + if ((null_fd = open("/dev/null", O_RDWR|O_NOCTTY)) < 0) + return -errno; + + return make_stdio(null_fd); +} + bool is_clean_exit(int code, int status) { if (code == CLD_EXITED) @@ -3380,7 +3389,7 @@ int ask_password_tty(const char *message, usec_t until, const char *flag_file, c assert(_passphrase); if (flag_file) { - if ((notify = inotify_init1(IN_CLOEXEC)) < 0) { + if ((notify = inotify_init1(IN_CLOEXEC|IN_NONBLOCK)) < 0) { r = -errno; goto finish; } @@ -3528,6 +3537,35 @@ finish: return r; } +void dual_timestamp_serialize(FILE *f, const char *name, dual_timestamp *t) { + + assert(f); + assert(name); + assert(t); + + if (!dual_timestamp_is_set(t)) + return; + + fprintf(f, "%s=%llu %llu\n", + name, + (unsigned long long) t->realtime, + (unsigned long long) t->monotonic); +} + +void dual_timestamp_deserialize(const char *value, dual_timestamp *t) { + unsigned long long a, b; + + assert(value); + assert(t); + + if (sscanf(value, "%lli %llu", &a, &b) != 2) + log_debug("Failed to parse finish timestamp value %s", value); + else { + t->realtime = a; + t->monotonic = b; + } +} + static const char *const ioprio_class_table[] = { [IOPRIO_CLASS_NONE] = "none", [IOPRIO_CLASS_RT] = "realtime",