1 /// systemd/sd-daemon.h 2 module systemd.daemon; 3 4 import systemd.base; 5 6 import std.string : toStringz, format; 7 8 public alias pid_t = size_t; 9 public import core.sys.posix.sys.socket : sockaddr; 10 11 mixin SSLL_INIT; 12 13 @api("lib") @nogc 14 { 15 /// 16 int sd_listen_fds(int unset_environment) { mixin(SSLL_CALL); } 17 /// 18 int sd_listen_fds_with_names(int unset_environment, char*** names) { mixin(SSLL_CALL); } 19 /// 20 int sd_is_fifo(int fd, const char* path) { mixin(SSLL_CALL); } 21 /// 22 int sd_is_special(int fd, const char* path) { mixin(SSLL_CALL); } 23 /// 24 int sd_is_socket(int fd, int family, int type, int listening) { mixin(SSLL_CALL); } 25 /// 26 int sd_is_socket_inet(int fd, int family, int type, int listening, ushort port) { mixin(SSLL_CALL); } 27 /// 28 int sd_is_socket_sockaddr(int fd, int type, const sockaddr* addr, uint addr_len, int listening) { mixin(SSLL_CALL); } 29 /// 30 int sd_is_socket_unix(int fd, int type, int listening, const char* path, size_t length) { mixin(SSLL_CALL); } 31 /// 32 int sd_is_mq(int fd, const char* path) { mixin(SSLL_CALL); } 33 34 /// 35 int sd_notify(int unset_environment, const char* state) { mixin(SSLL_CALL); } 36 37 extern (C) // because variablic arguments 38 { 39 /// 40 pragma(mangle, "sdutil_sd_notifyf") // because extern(C) 41 int sd_notifyf(int unset_environment, const char* format, ...) { mixin(SSLL_CALL); } 42 43 /// 44 pragma(mangle, "sdutil_sd_pid_notifyf") 45 int sd_pid_notifyf(pid_t pid, int unset_environment, const char* format, ...) { mixin(SSLL_CALL); } 46 } 47 48 /// 49 int sd_pid_notify(pid_t pid, int unset_environment, const char* state) { mixin(SSLL_CALL); } 50 /// 51 int sd_pid_notify_with_fds(pid_t pid, int unset_environment, const char* state, const int* fds, uint n_fds) { mixin(SSLL_CALL); } 52 /// 53 int sd_booted() { mixin(SSLL_CALL); } 54 /// 55 int sd_watchdog_enabled(int unset_environment, ulong* usec) { mixin(SSLL_CALL); } 56 } 57 58 /// 59 int sdNotify(int unset_environment, string state) 60 { return sd_notify(unset_environment, state.toStringz); } 61 62 /// shortcut 63 int sdNotify_ready(int unset_environment=0) @nogc 64 { return sd_notify(unset_environment, "READY=1"); } 65 66 /// ditto 67 int sdNotify_reloading(int unset_environment=0) @nogc 68 { return sd_notify(unset_environment, "RELOADING=1"); } 69 70 /// ditto 71 int sdNotify_stopping(int unset_environment=0) @nogc 72 { return sd_notify(unset_environment, "STOPPING=1"); } 73 74 /// ditto 75 int sdNotify_watchdog(int unset_environment=0) @nogc 76 { return sd_notify(unset_environment, "WATCHDOG=1"); } 77 78 /// ditto 79 int sdNotify_status(int unset_environment, string status) 80 { return sd_notify(unset_environment, format!"STATUS=%s"(status).toStringz); } 81 82 /// ditto 83 int sdNotify_status(string status) { return sdNotify_status(0, status); } 84 85 /// 86 int sdPidNotify(pid_t pid, int unset_environment, string state) 87 { return sd_pid_notify(pid, unset_environment, state.toStringz); } 88 89 /// 90 int sdNotifyf(Args...)(int unset_environment, string fmt, Args args) 91 { return sd_notify(unset_environment, format(fmt, args).toStringz); } 92 93 /// 94 int sdPidNotifyf(Args...)(pid_t pid, int unset_environment, string fmt, Args args) 95 { return sd_pid_notify(pid, unset_environment, format(fmt, args).toStringz); } 96 97 /// 98 bool sdBooted() 99 { 100 const r = sd_booted(); 101 if (r == 0) return false; 102 else if (r > 0) return true; 103 else throw new Exception(format!"error (%d)"(r)); 104 } 105 106 import std.datetime : Duration; 107 108 /// 109 Duration sdWatchdogEnabled(int unset_environment=0) 110 { 111 import std.datetime : usecs; 112 113 ulong u; 114 const r = sd_watchdog_enabled(unset_environment, &u); 115 if (r == 0) return Duration.zero; 116 else if (r > 0) return u.usecs; 117 else throw new Exception(format!"error (%d)"(r)); 118 }