// C# binding for system call wrappers in libsimpleio.so // Copyright (C)2017-2023, Philip Munts dba Munts Technologies. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: // // * Redistributions of source code must retain the above copyright notice, // this list of conditions and the following disclaimer. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE // POSSIBILITY OF SUCH DAMAGE. using System.Runtime.InteropServices; namespace IO.Bindings { public static partial class libsimpleio { /// /// Use the program name for the identity string. /// public const string LOG_PROGNAME = ""; // Facilities -- Extracted from syslog.h /// /// Kernel messages. /// public const int LOG_KERN = (0 << 3); /// /// Random user-level messages. /// public const int LOG_USER = (1 << 3); /// /// Mail system. /// public const int LOG_MAIL = (2 << 3); /// /// System daemons. /// public const int LOG_DAEMON = (3 << 3); /// /// Security/authorization messages. /// public const int LOG_AUTH = (4 << 3); /// /// Messages generated internally by syslogd /// public const int LOG_SYSLOG = (5 << 3); /// /// Line printer subsystem /// public const int LOG_LPR = (6 << 3); /// /// Network news subsystem /// public const int LOG_NEWS = (7 << 3); /// /// UUCP subsystem /// public const int LOG_UUCP = (8 << 3); /// /// cron daemon messages. /// public const int LOG_CRON = (9 << 3); /// /// Securit/authorization messages. /// public const int LOG_AUTHPRIV = (10 << 3); /// /// FTP daemon messages. /// public const int LOG_FTP = (11 << 3); /// /// Reserved for local use. /// public const int LOG_LOCAL0 = (16 << 3); /// /// Reserved for local use. /// public const int LOG_LOCAL1 = (17 << 3); /// /// Reserved for local use. /// public const int LOG_LOCAL2 = (18 << 3); /// /// Reserved for local use. /// public const int LOG_LOCAL3 = (19 << 3); /// /// Reserved for local use. /// public const int LOG_LOCAL4 = (20 << 3); /// /// Reserved for local use. /// public const int LOG_LOCAL5 = (21 << 3); /// /// Reserved for local use. /// public const int LOG_LOCAL6 = (22 << 3); /// /// Reserved for local use. /// public const int LOG_LOCAL7 = (23 << 3); // Options -- Extracted from syslog.h /// /// Write directly to the system console if there is an error while /// sending to the system logger. /// public const int LOG_CONS = 0x02; /// /// Open the connection immediately. Do not wait until syslog() /// is called for the first time. /// public const int LOG_NDELAY = 0x08; /// /// Don't wait for child processes that may have been created while /// logging the message. (Not applicable to glibc.) /// public const int LOG_NOWAIT = 0x10; /// /// Do not open the connection immediately. Wait until syslog() /// is called for the first time. /// public const int LOG_ODELAY = 0x04; /// /// Also log the message to stderr. /// public const int LOG_PERROR = 0x20; /// /// Include the caller's PID (process ID) with each message. /// public const int LOG_PID = 0x01; // Priorities -- Extracted from syslog.h /// /// System is unusable. /// public const int LOG_EMERG = 0; /// /// Action must be taken immediately. /// public const int LOG_ALERT = 1; /// /// Critical condition. /// public const int LOG_CRIT = 2; /// /// Error condition. /// public const int LOG_ERR = 3; /// /// Warning condition. /// public const int LOG_WARNING = 4; /// /// Normal but significant condition. /// public const int LOG_NOTICE = 5; /// /// Informational message. /// public const int LOG_INFO = 6; /// /// Debug message. /// public const int LOG_DEBUG = 7; /// /// Detach the process and run it in the background. /// /// Error code. Zero upon success or an /// errno value upon failure. [DllImport("simpleio")] public static extern void LINUX_detach(out int error); /// /// Drop process privileges to those of the specified user. /// Only a process running at superuser privilege is allowed /// to drop privileges. /// /// User privileges to assume. /// Error code. Zero upon success or an /// errno value upon failure. [DllImport("simpleio")] public static extern void LINUX_drop_privileges(string username, out int error); /// /// Open a connection to the syslog service. /// /// Program identifier. /// Logging options. /// Logging facility identifier. /// Error code. Zero upon success or an /// errno value upon failure. [DllImport("simpleio")] public static extern void LINUX_openlog(string id, int options, int facility, out int error); /// /// Send a message to the syslog service. /// /// Message priority /// Message to send. /// Error code. Zero upon success or an /// errno value upon failure. [DllImport("simpleio")] public static extern void LINUX_syslog(int priority, string msg, out int error); /// /// Close the connection to the syslog service. /// /// Error code. Zero upon success or an /// errno value upon failure. [DllImport("simpleio")] public static extern void LINUX_closelog(out int error); /// /// Fetch the value of errno. /// /// Current value of errno. [DllImport("simpleio")] public static extern int LINUX_errno(); /// /// Retrieve the error message for a particular errno /// error code. /// /// Error code. /// Destination buffer. /// Destination buffer size. [DllImport("simpleio")] public static extern void LINUX_strerror(int error, System.Text.StringBuilder buf, int bufsize); /// /// There is data to read. /// public const int POLLIN = 0x01; /// /// There is urgent data to read. /// public const int POLLPRI = 0x02; /// /// Writing is now possible. /// public const int POLLOUT = 0x04; /// /// An error occurred. /// public const int POLLERR = 0x08; /// /// Peer closed connection. /// public const int POLLHUP = 0x10; /// /// File descriptor is invalid. /// public const int POLLNVAL = 0x20; /// /// Wait for an event on one or more files. /// /// Number elements in each of the /// following arrays. /// File descriptors. /// Events to wait for on each file /// descriptor. /// Events that occurred on each file /// descriptor. /// Milliseconds to wait for an event /// to occur. A value of -1 means wait forever and a value /// of 0 means do not wait at all. /// Error code. [DllImport("simpleio")] public static extern void LINUX_poll(int numfiles, int[] files, int[] events, int[] results, int timeoutms, out int error); /// /// Sleep for the specified number of microseconds. /// /// Number of microseconds to sleep. /// Error code. [DllImport("simpleio")] public static extern void LINUX_usleep(int microsecs, out int error); /// /// Execute a shell command string. /// /// Command string. /// Error code. [DllImport("simpleio")] public static extern void LINUX_command(string cmd, out int error); } }