McdeSys gains mcde_sys_print_file(path, printer): it looks for lp(1) (/usr/bin, /usr/local/bin, /usr/sbin, pkg prefix; MCDE_PRINT_COMMAND overrides it for tests), passes -d PRINTER when one is named, and runs it as the existing job (fd into the event loop, finish/cancel). dtpaint links libMcdeSys, adds File > Print... (Ctrl+P): it picks the default queue from mcde_sys_printers (or the first), writes the image to /tmp/dtpaint-PID.bmp, starts the job and removes the file when the job ends; errors and 'no printer is set up' go to the information dialog. Measured under Xvfb with MCDE_PRINT_COMMAND=fake lp: argv '-d HP_LaserJet_M110w_CC1016 /tmp/dtpaint-3543226.bmp', the fake copied a valid 640x480 BMP and the temporary file was gone; no physical page was printed (the real queue is the user's step).
795 lines
32 KiB
C
795 lines
32 KiB
C
/*
|
|
* McdeSys.h -- MCDE's layer between the desktop and the operating system
|
|
*
|
|
* License: CNCL 1.0 (Could Not Care Less), see LICENSE at the top of the tree.
|
|
*
|
|
* Programs of MCDE (the System Preferences first) change the system only
|
|
* through these functions; each operating system has one backend in
|
|
* lib/McdeSys/<system>.c that does it the system's own way (on NetBSD:
|
|
* useradd(8), /etc/rc.conf, ifconfig(8), wpa_supplicant(8) ...). See
|
|
* ext/src/mcde/AGENTS.md, "The philosophy".
|
|
*
|
|
* C99 and POSIX only. Every function returns MCDE_SYS_OK or a negative
|
|
* McdeSysStatus; on failure, mcde_sys_error() gives a sentence for the user.
|
|
* Functions that change the system need the privileges the backend documents
|
|
* (today: root); they do not raise privileges themselves.
|
|
*
|
|
* Status: lib/McdeSys implements mcde_sys_backend, mcde_sys_error,
|
|
* mcde_sys_info, mcde_sys_power, mcde_sys_interfaces, the sound, Bluetooth,
|
|
* battery, time zone, sharing, the network browser, disks, backup,
|
|
* user and software update functions (common.c, net.c, sound.c, users.c,
|
|
* netbsd.c, linux.c), and the security state (swap encryption, cgd, npf);
|
|
* the network setup and the host name setter are the contract still.
|
|
*/
|
|
|
|
#ifndef _Mcde_McdeSys_h
|
|
#define _Mcde_McdeSys_h
|
|
|
|
#include <stddef.h>
|
|
#include <sys/types.h>
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
typedef enum {
|
|
MCDE_SYS_OK = 0,
|
|
MCDE_SYS_ENOTSUP = -1, /* this backend cannot do it */
|
|
MCDE_SYS_EPERM = -2, /* not allowed (privileges) */
|
|
MCDE_SYS_EINVAL = -3, /* a bad argument (name, address ...) */
|
|
MCDE_SYS_EEXIST = -4, /* it exists already */
|
|
MCDE_SYS_ENOENT = -5, /* it does not exist */
|
|
MCDE_SYS_EFAIL = -6 /* the system tool failed; see mcde_sys_error() */
|
|
} McdeSysStatus;
|
|
|
|
/* the name of the backend ("netbsd", "linux"), for the About box and logs */
|
|
const char *mcde_sys_backend(void);
|
|
/* the last failure as a sentence for the user; never NULL */
|
|
const char *mcde_sys_error(void);
|
|
|
|
/*
|
|
* Users and groups
|
|
*/
|
|
typedef struct {
|
|
char login[32]; /* [a-z_][a-z0-9_-]*, as useradd(8) takes it */
|
|
char fullname[128];
|
|
uid_t uid;
|
|
int admin; /* may administer the computer (wheel/sudo) */
|
|
} McdeSysUser;
|
|
|
|
/* the people who use this computer (not the system accounts); returns count */
|
|
int mcde_sys_users(McdeSysUser *users, size_t max);
|
|
int mcde_sys_user_add(const McdeSysUser *user, const char *password);
|
|
int mcde_sys_user_delete(const char *login, int keep_home);
|
|
int mcde_sys_user_set_password(const char *login, const char *password);
|
|
int mcde_sys_user_set_admin(const char *login, int admin);
|
|
|
|
/*
|
|
* Network
|
|
*/
|
|
typedef enum {
|
|
MCDE_NET_WIRED,
|
|
MCDE_NET_WIFI,
|
|
MCDE_NET_OTHER
|
|
} McdeSysNetKind;
|
|
|
|
typedef struct {
|
|
char name[32]; /* the system's name: wm0, urtwn0, eth0 */
|
|
McdeSysNetKind kind;
|
|
int up; /* has an address */
|
|
char address[64]; /* the IPv4 or IPv6 address, or "" */
|
|
char ssid[33]; /* Wi-Fi: the network joined, or "" */
|
|
} McdeSysInterface;
|
|
|
|
typedef struct {
|
|
char ssid[33];
|
|
int signal; /* 0..100 */
|
|
int secured;
|
|
} McdeSysWifi;
|
|
|
|
/* the network interfaces; returns count */
|
|
int mcde_sys_interfaces(McdeSysInterface *ifs, size_t max);
|
|
|
|
/* how an interface gets its IPv4 and IPv6 addresses (System Settings >
|
|
* Network, TCP/IP); docs/reference/netconfig.txt in the Makronix tree */
|
|
typedef enum {
|
|
MCDE_IPV4_DHCP, /* Using DHCP */
|
|
MCDE_IPV4_DHCP_MANUAL, /* Using DHCP with manual address */
|
|
MCDE_IPV4_MANUAL, /* Manually */
|
|
MCDE_IPV4_OFF
|
|
} McdeSysIpv4;
|
|
|
|
typedef enum {
|
|
MCDE_IPV6_AUTO, /* Automatically (router advertisements) */
|
|
MCDE_IPV6_MANUAL,
|
|
MCDE_IPV6_OFF
|
|
} McdeSysIpv6;
|
|
|
|
#define MCDE_NET_DNS_MAX 4
|
|
|
|
typedef struct {
|
|
/* configured: what the interface gets at every start */
|
|
McdeSysIpv4 ipv4;
|
|
char address[48]; /* IPv4, dotted */
|
|
char netmask[48]; /* dotted: 255.255.255.0 */
|
|
char router[48];
|
|
char clientid[64]; /* the DHCP client ID, or "" */
|
|
McdeSysIpv6 ipv6;
|
|
char address6[64];
|
|
int prefix6; /* 1..128 */
|
|
char dns[MCDE_NET_DNS_MAX][48]; /* the DNS servers */
|
|
int ndns;
|
|
char search[MCDE_NET_DNS_MAX][96]; /* search domains */
|
|
int nsearch;
|
|
/* now, read only: what the interface has at this moment */
|
|
char cur_address[48];
|
|
char cur_netmask[48];
|
|
char cur_router[48];
|
|
char cur_address6[64];
|
|
int cur_prefix6;
|
|
char cur_dns[MCDE_NET_DNS_MAX][48];
|
|
int ncur_dns;
|
|
char mac[24]; /* the Ethernet ID, aa:bb:cc:dd:ee:ff */
|
|
int mtu;
|
|
char media[64]; /* "1000baseT full-duplex", or "" */
|
|
} McdeSysNetConfig;
|
|
|
|
/* the settings of IFNAME, configured and current */
|
|
int mcde_sys_net_config(const char *ifname, McdeSysNetConfig *config);
|
|
/* configure IFNAME (the "configured" part of CONFIG), now and at every
|
|
* start; the administrator only */
|
|
int mcde_sys_net_configure(const char *ifname,
|
|
const McdeSysNetConfig *config);
|
|
/* ask the DHCP server again (Renew DHCP Lease) */
|
|
int mcde_sys_net_renew(const char *ifname);
|
|
/* the Wi-Fi networks in reach; returns count */
|
|
int mcde_sys_wifi_scan(const char *ifname, McdeSysWifi *nets, size_t max);
|
|
/* join a Wi-Fi network, now and at every boot; passphrase NULL if open */
|
|
int mcde_sys_wifi_join(const char *ifname, const char *ssid,
|
|
const char *passphrase);
|
|
|
|
/*
|
|
* The computer
|
|
*/
|
|
typedef struct {
|
|
char system[64]; /* "Makronix", "Debian GNU/Linux" */
|
|
char version[64]; /* "0.99.9", "14" */
|
|
char kernel[128]; /* "NetBSD 11.99.9", "Linux 7.1.3" */
|
|
char model[128]; /* the machine, as the firmware names it */
|
|
char cpu[128]; /* the processor, as it names itself */
|
|
int cpus; /* processors online */
|
|
unsigned long long memory; /* bytes */
|
|
char disk[128]; /* the startup disk: the device of / */
|
|
unsigned long long diskSize; /* bytes of /, and free of them */
|
|
unsigned long long diskFree;
|
|
char hostname[256];
|
|
} McdeSysInfo;
|
|
|
|
/* what the About box shows; fields the system cannot tell are "" or 0 */
|
|
int mcde_sys_info(McdeSysInfo *info);
|
|
|
|
typedef enum {
|
|
MCDE_POWER_SLEEP,
|
|
MCDE_POWER_RESTART,
|
|
MCDE_POWER_SHUTDOWN
|
|
} McdeSysPower;
|
|
|
|
/* sleep, restart or shut down the computer, the system's own way */
|
|
int mcde_sys_power(McdeSysPower what);
|
|
|
|
/*
|
|
* Sound: the volume of the default output, through the sound server where
|
|
* one runs (PulseAudio), else the system's mixer
|
|
*/
|
|
int mcde_sys_volume_get(int *percent, int *muted); /* 0..100 */
|
|
int mcde_sys_volume_set(int percent);
|
|
int mcde_sys_volume_mute(int muted);
|
|
/* play a sound file (WAV) on the default output and return at once, the
|
|
* player left running on its own; MCDE_SYS_ENOTSUP when there is none */
|
|
int mcde_sys_sound_play(const char *file);
|
|
|
|
/*
|
|
* PCM streams, for the calls of dtchat: signed 16-bit samples, interleaved,
|
|
* one stream per direction. A frame is one sample per channel; COUNT in
|
|
* read/write is frames. The system's own device is used (ALSA on Linux,
|
|
* audio(4) with /dev/audio on NetBSD); MCDE_SYS_PCM_NULL is silence in and
|
|
* a discard out -- it is what a test, or a session without a device, uses.
|
|
* The handle is non-blocking: read/write answer 0 when no frame fits (a
|
|
* negative value is an error, see mcde_sys_error()), and mcde_sys_pcm_wait
|
|
* blocks until the stream can take or give frames.
|
|
*/
|
|
typedef struct McdeSysPcm McdeSysPcm;
|
|
|
|
enum {
|
|
MCDE_SYS_PCM_PLAYBACK = 0,
|
|
MCDE_SYS_PCM_CAPTURE = 1
|
|
};
|
|
|
|
enum {
|
|
MCDE_SYS_PCM_DEFAULT = 0,
|
|
MCDE_SYS_PCM_NULL = 1
|
|
};
|
|
|
|
int mcde_sys_pcm_open(McdeSysPcm **pcm, int direction, int backend,
|
|
unsigned rate, unsigned channels);
|
|
/* wait up to TIMEOUT_MS (0: do not wait, negative: no limit) */
|
|
int mcde_sys_pcm_wait(McdeSysPcm *pcm, int timeout_ms);
|
|
/* frames read or written; 0 when the stream would block */
|
|
ssize_t mcde_sys_pcm_read(McdeSysPcm *pcm, int16_t *frames, size_t count);
|
|
ssize_t mcde_sys_pcm_write(McdeSysPcm *pcm, const int16_t *frames,
|
|
size_t count);
|
|
void mcde_sys_pcm_close(McdeSysPcm *pcm);
|
|
/* "alsa", "audio(4)" or "null", for a status line and the tests */
|
|
const char *mcde_sys_pcm_backend(const McdeSysPcm *pcm);
|
|
|
|
/*
|
|
* Bluetooth: the first controller
|
|
*/
|
|
typedef struct {
|
|
int present; /* there is a controller */
|
|
int on; /* it is powered */
|
|
char name[32]; /* the system's name of it: ubt0, hci0 */
|
|
} McdeSysBluetooth;
|
|
|
|
int mcde_sys_bluetooth(McdeSysBluetooth *bt);
|
|
int mcde_sys_bluetooth_power(int on);
|
|
|
|
/*
|
|
* The battery: all batteries of the machine as one, and the mains
|
|
*/
|
|
typedef struct {
|
|
int present; /* there is a battery */
|
|
int percent; /* its charge, 0..100 */
|
|
int charging; /* it is being charged */
|
|
int ac; /* the machine runs on mains power */
|
|
int minutes; /* until it is empty, -1 when not known or
|
|
* not running on it */
|
|
} McdeSysBattery;
|
|
|
|
int mcde_sys_battery(McdeSysBattery *bat);
|
|
|
|
/*
|
|
* The keyboard: is the one attached a Macintosh keyboard (Command left of
|
|
* the space bar, Option left of that)? 1 yes, 0 no. dtkeys makes the key
|
|
* left of the space bar the Command key (Mod4) on every keyboard.
|
|
*/
|
|
int mcde_sys_keyboard_is_mac(void);
|
|
|
|
/*
|
|
* The touchpad (NetBSD: pms(4)/synaptics(4), the hw.synaptics.* sysctls):
|
|
* whether a tap is a click, whether two fingers are a button and which,
|
|
* two-finger scrolling, and three buttons through the pad's edges and
|
|
* corners. Writing needs root (the sysctls are CTLFLAG_READWRITE); the
|
|
* call answers MCDE_SYS_EPERM against a user. A system without the
|
|
* interface answers MCDE_SYS_ENOTSUP (Linux keeps this in libinput, per
|
|
* device, and not here).
|
|
*/
|
|
typedef struct {
|
|
int tap; /* a tap is a click */
|
|
int fingers; /* 0: no two-finger button, 1: right, 2: middle */
|
|
int scroll; /* two-finger scrolling */
|
|
} McdeSysTouchpad;
|
|
|
|
int mcde_sys_touchpad_get(McdeSysTouchpad *t);
|
|
int mcde_sys_touchpad_set(const McdeSysTouchpad *t);
|
|
|
|
/*
|
|
* Software update: the system and the packages, from the update source the
|
|
* system names (NetBSD: the URL in /etc/makronix/update, a release directory
|
|
* as build.sh makes it)
|
|
*/
|
|
typedef struct {
|
|
char current[64]; /* the version running */
|
|
char available[64]; /* the version the source has, or "" */
|
|
int packages; /* packages with a newer version, or -1: unknown */
|
|
char source[256]; /* where it looks, for the user */
|
|
char note[256]; /* a sentence for the user, or "" */
|
|
} McdeSysUpdate;
|
|
|
|
int mcde_sys_update_check(McdeSysUpdate *u);
|
|
/* bring the system and the packages up to what the source has (root) */
|
|
int mcde_sys_update_apply(void);
|
|
|
|
int mcde_sys_hostname_get(char *name, size_t len);
|
|
int mcde_sys_hostname_set(const char *name); /* now and at boot */
|
|
/*
|
|
* Sharing: the services that let others in, and the folders they share.
|
|
* SMB (Samba), NFS and AFP (netatalk) share the same folders; AppleTalk is
|
|
* netatalk's atalkd, the old network itself (NetBSD's kernel has it).
|
|
*/
|
|
typedef enum {
|
|
MCDE_SHARE_SSH, /* remote login */
|
|
MCDE_SHARE_SMB, /* file sharing for Windows and others */
|
|
MCDE_SHARE_NFS, /* file sharing for Unix */
|
|
MCDE_SHARE_AFP, /* file sharing by AFP over TCP */
|
|
MCDE_SHARE_APPLETALK, /* the AppleTalk network (atalkd, papd) */
|
|
MCDE_SHARE_COUNT
|
|
} McdeSysShareService;
|
|
|
|
typedef struct {
|
|
int installed; /* the server is there */
|
|
int enabled; /* it starts at boot */
|
|
int running; /* it runs now */
|
|
} McdeSysServiceState;
|
|
|
|
int mcde_sys_service_state(McdeSysShareService s, McdeSysServiceState *st);
|
|
/* on or off, now and at every boot (root) */
|
|
int mcde_sys_service_set(McdeSysShareService s, int on);
|
|
|
|
#define MCDE_SYS_SHARE_LEN 256
|
|
/* the shared folders (/etc/mcde-shares); how many */
|
|
int mcde_sys_shares(char (*paths)[MCDE_SYS_SHARE_LEN], size_t max);
|
|
/* share these folders by SMB, NFS and AFP: the list and the servers'
|
|
* configuration, which running servers read again (root) */
|
|
int mcde_sys_shares_set(char (*paths)[MCDE_SYS_SHARE_LEN], size_t n);
|
|
|
|
/*
|
|
* The network: the computers that announce what they offer (DNS-SD,
|
|
* multicast DNS), and connecting to what they share. A computer's kinds
|
|
* are bits of McdeSysNetKinds.
|
|
*/
|
|
enum {
|
|
MCDE_NET_HAS_SMB = 1 << 0, /* _smb._tcp */
|
|
MCDE_NET_HAS_AFP = 1 << 1, /* _afpovertcp._tcp */
|
|
MCDE_NET_HAS_NFS = 1 << 2, /* _nfs._tcp */
|
|
MCDE_NET_HAS_SSH = 1 << 3, /* _ssh._tcp or _sftp-ssh._tcp */
|
|
MCDE_NET_HAS_ANY = 1 << 4 /* _workstation._tcp, nothing shared */
|
|
};
|
|
|
|
typedef struct {
|
|
char name[128]; /* as it calls itself: "kitt" */
|
|
char host[256]; /* its address: "kitt.local" */
|
|
int kinds; /* MCDE_NET_HAS_* */
|
|
} McdeSysNetHost;
|
|
|
|
/* the computers found within about TIMEOUT_MS; how many */
|
|
int mcde_sys_net_browse(McdeSysNetHost *hosts, size_t max, int timeout_ms);
|
|
|
|
/*
|
|
* DNS-SD for dtchat's local mode: announce TYPE ("_dtchat._tcp") under NAME
|
|
* with PORT and the TXT record TXT ("k=v;k2=v2;"), and watch a TYPE. The
|
|
* announce publishes while it exists and says goodbye when stopped; the watch
|
|
* queues NEW and REMOVE events that the caller reads with
|
|
* mcde_sys_net_watch_next(). Both are driven by their poll call (0 waits not
|
|
* at all, negative for ever), so no thread and no second loop is needed.
|
|
* MCDE_SYS_ENOTSUP when the system has no mDNS client (no daemon, no library).
|
|
*/
|
|
typedef struct McdeSysAnnounce McdeSysAnnounce;
|
|
typedef struct McdeSysWatch McdeSysWatch;
|
|
|
|
#define MCDE_SYS_SERVICE_NAME 64
|
|
#define MCDE_SYS_SERVICE_HOST 256
|
|
#define MCDE_SYS_SERVICE_TXT 512
|
|
|
|
typedef struct {
|
|
int gone; /* 0: NEW, 1: the service went away */
|
|
char name[MCDE_SYS_SERVICE_NAME];
|
|
char type[MCDE_SYS_SERVICE_NAME];
|
|
char host[MCDE_SYS_SERVICE_HOST]; /* address, as mDNS gave it */
|
|
char txt[MCDE_SYS_SERVICE_TXT]; /* "k=v;k2=v2;" */
|
|
int port;
|
|
} McdeSysService;
|
|
|
|
int mcde_sys_net_announce(McdeSysAnnounce **announce, const char *type,
|
|
const char *name, int port, const char *txt);
|
|
int mcde_sys_net_announce_poll(McdeSysAnnounce *announce, int timeout_ms);
|
|
/* 1 once the name is taken on the network */
|
|
int mcde_sys_net_announce_ready(const McdeSysAnnounce *announce);
|
|
void mcde_sys_net_announce_stop(McdeSysAnnounce *announce);
|
|
|
|
int mcde_sys_net_watch(McdeSysWatch **watch, const char *type);
|
|
int mcde_sys_net_watch_poll(McdeSysWatch *watch, int timeout_ms);
|
|
/* 1: one event in SVC, 0: none, -1: the watch failed */
|
|
int mcde_sys_net_watch_next(McdeSysWatch *watch, McdeSysService *svc);
|
|
void mcde_sys_net_watch_close(McdeSysWatch *watch);
|
|
|
|
/* what HOST shares: NFS exports (showmount) or SMB shares (smbclient -L);
|
|
* KIND is MCDE_NET_HAS_NFS or _SMB; how many */
|
|
int mcde_sys_net_shares(const char *host, int kind, char (*names)[256],
|
|
size_t max);
|
|
/* connect URL -- sftp://[user@]host[/path], nfs://host/path,
|
|
* afp://[user@]host/volume -- to the folder MOUNTPOINT, which must exist;
|
|
* PASSWORD may be NULL */
|
|
int mcde_sys_net_mount(const char *url, const char *mountpoint,
|
|
const char *password);
|
|
/* The same without waiting: a server that is gone keeps sshfs or mount_afp
|
|
* busy for minutes, and a program that waits for it does not draw. The
|
|
* connection runs as a job in a process of its own. Its descriptor
|
|
* (mcde_sys_job_fd) becomes readable when the tool has ended: put it into the
|
|
* event loop (XtAppAddInput) and then call mcde_sys_job_finish, which gives
|
|
* the result as mcde_sys_net_mount would have and frees the job.
|
|
* mcde_sys_job_cancel ends the tool (and its helpers) instead and frees the
|
|
* job; a program that gives up (Cancel, a time-out) calls it with the REASON
|
|
* it gives the user, which becomes mcde_sys_error(); it returns a failure.
|
|
* NULL from _start: not started, mcde_sys_error() says why. */
|
|
typedef struct McdeSysJob McdeSysJob;
|
|
McdeSysJob *mcde_sys_net_mount_start(const char *url, const char *mountpoint,
|
|
const char *password);
|
|
int mcde_sys_job_fd(const McdeSysJob *job);
|
|
int mcde_sys_job_finish(McdeSysJob *job);
|
|
int mcde_sys_job_cancel(McdeSysJob *job, const char *reason);
|
|
/* disconnect what is mounted at MOUNTPOINT */
|
|
int mcde_sys_net_unmount(const char *mountpoint);
|
|
|
|
/*
|
|
* Disks: the drives and their partitions (NetBSD: wedges), where they are
|
|
* mounted, and what can be done to them. NAME is the system's: wd0, dk1,
|
|
* sd0 / nvme0n1, sda1. Changing a disk needs root.
|
|
*/
|
|
typedef struct {
|
|
char name[32];
|
|
char parent[32]; /* the drive of a partition; "" for a drive */
|
|
char model[96]; /* a drive's model, or "" */
|
|
char fstype[32]; /* ffs, msdos, ext2fs, swap, cd9660 ...; "" */
|
|
char label[96]; /* the partition's or volume's name, or "" */
|
|
unsigned long long bytes;
|
|
int removable; /* a stick, a card, a CD */
|
|
int system; /* holds / or swap: never erased */
|
|
char mountpoint[256]; /* where mounted, or "" */
|
|
unsigned long long used, avail; /* when mounted */
|
|
} McdeSysDisk;
|
|
|
|
/* the drives, each followed by its partitions; how many */
|
|
int mcde_sys_disks(McdeSysDisk *d, size_t max);
|
|
/* mount partition NAME on /media/LABEL (made); where, into MOUNTPOINT */
|
|
int mcde_sys_disk_mount(const char *name, char *mountpoint, size_t len);
|
|
int mcde_sys_disk_unmount(const char *name);
|
|
/* The device NAME (sdb1, sd0a, or the whole drive sdb) went away. If a
|
|
* partition of it is still in the mount table, its mountpoint is copied into
|
|
* MOUNTPOINT and the stale mount is detached the forced way (lazy on Linux,
|
|
* -f on NetBSD); returns 1. 0 when nothing of NAME was mounted, -1 on an
|
|
* error. What the computer runs from is never unmounted. */
|
|
int mcde_sys_disk_detached(const char *name, char *mountpoint,
|
|
size_t len);
|
|
/* check partition NAME without changing it (fsck -n); its report into LOG */
|
|
int mcde_sys_disk_check(const char *name, char *log, size_t len);
|
|
/* erase the whole drive NAME: one partition, FSTYPE ("ffs", "msdos";
|
|
* Linux also "ext4") named LABEL; the new partition's name into PART.
|
|
* Refused for a drive with a system partition or one that is mounted. */
|
|
int mcde_sys_disk_erase(const char *name, const char *fstype,
|
|
const char *label, char *part, size_t len);
|
|
|
|
/*
|
|
* Mounts: everything that is mounted, the local volumes and the network
|
|
* file systems alike. The desktop shows them as icons (WmMcdeDesktop.c);
|
|
* dtfile and the sidebar can ask the same list. NETWORK is 1 for a
|
|
* network file system (NFS, SMB/CIFS, AFP, sshfs, 9p, ...) and 0 for a
|
|
* volume of this computer. SYSTEM is 1 for what the computer starts from
|
|
* and cannot lose (/ , /usr, /var, /home, swap).
|
|
*/
|
|
typedef struct {
|
|
char source[256]; /* /dev/sda1, server:/export, //server/share,
|
|
user@host:/path */
|
|
char mountpoint[256];
|
|
char fstype[32]; /* ffs, ext4, iso9660, nfs, nfs4, cifs,
|
|
smbfs, afpfs, fuse.sshfs */
|
|
char label[96]; /* the volume's name, or "" */
|
|
int network; /* a network file system */
|
|
int removable; /* a stick, a card, a CD/DVD */
|
|
int system; /* the computer runs from it */
|
|
int volume; /* a real volume (ext4, ffs, iso9660 ...),
|
|
not a pseudo file system (proc, sysfs,
|
|
tmpfs, cgroup ...) */
|
|
} McdeSysMount;
|
|
|
|
/* every mount of the computer, local and network; how many */
|
|
int mcde_sys_mounts(McdeSysMount *m, size_t max);
|
|
|
|
/*
|
|
* The permissions of the system's files: compared with the list the system
|
|
* keeps of how they should be, and set back to it (REPAIR, root). What
|
|
* differs -- or what was set back -- goes into LOG, a line each; how many
|
|
* lines. NetBSD: mtree(8) against /etc/mtree/set.* (every installed set).
|
|
*/
|
|
int mcde_sys_permissions(int repair, char *log, size_t len);
|
|
|
|
/*
|
|
* Backup: the whole system, every hour, to a disk of its own, by BorgBackup
|
|
* -- encrypted (repokey-blake2), deduplicated; kept are, unless set
|
|
* otherwise, 24 hourly, 30 daily, 52 weekly and every monthly state, and
|
|
* when the disk's free space falls below a share (10 %), the oldest are
|
|
* deleted until it is back. Setting up, running, listing and restoring
|
|
* need root.
|
|
*/
|
|
typedef struct {
|
|
int configured; /* a disk and a repository are set up */
|
|
int enabled; /* it runs every hour */
|
|
char disk[32]; /* the partition it backs up to */
|
|
char repo[512]; /* the repository on it */
|
|
long long last; /* the last backup's time (time_t), or 0 */
|
|
char result[256]; /* how the last one ended */
|
|
/* how many are kept (-1: every one); and the free space below which
|
|
* the oldest backups are deleted, in percent of the disk */
|
|
int keepHourly, keepDaily, keepWeekly, keepMonthly;
|
|
int minFree;
|
|
} McdeSysBackup;
|
|
|
|
typedef struct {
|
|
char name[128];
|
|
char time[32]; /* "2026-11-11T14:00:03" */
|
|
} McdeSysBackupArchive;
|
|
|
|
int mcde_sys_backup_get(McdeSysBackup *b);
|
|
/* make PARTITION (mounted, or mountable) the backup disk: a repository on
|
|
* it, encrypted with PASSPHRASE, which is kept for the hourly runs */
|
|
int mcde_sys_backup_setup(const char *partition, const char *passphrase);
|
|
int mcde_sys_backup_enable(int on);
|
|
/* how many are kept and the free space to hold, from B (root) */
|
|
int mcde_sys_backup_policy(const McdeSysBackup *b);
|
|
/* one backup now (the hourly run does this); borg's report into LOG */
|
|
int mcde_sys_backup_run(char *log, size_t len);
|
|
/* the backups there are, oldest first; how many */
|
|
int mcde_sys_backup_archives(McdeSysBackupArchive *a, size_t max);
|
|
/* PATH (absolute, as it was) of backup ARCHIVE, into the folder DEST */
|
|
int mcde_sys_backup_restore(const char *archive, const char *path,
|
|
const char *dest);
|
|
|
|
/*
|
|
* A process: the command line it was started with, as one line a shell
|
|
* reads back (each argument in single quotes). For the front panel, which
|
|
* keeps a running program to start it again.
|
|
*/
|
|
int mcde_sys_process_command(pid_t pid, char *buf, size_t len);
|
|
/* 1 when the process is stopped (SIGSTOP, a debugger) or a zombie, 0 when
|
|
* it runs, -1 when it cannot be asked. The Force Quit dialog of dtbar
|
|
* marks the first kind "(not responding)". */
|
|
int mcde_sys_process_stopped(pid_t pid);
|
|
|
|
/*
|
|
* The processes of the computer, for the activity window (dtactivity, t0091):
|
|
* one McdeSysProcess each, in no particular order. Memory is in bytes, CPU
|
|
* time in milliseconds (all the CPU time the process has used: ps(1)'s
|
|
* TIME), the state one letter -- R running or runnable, S sleeping, D waiting
|
|
* on a disk (Linux), T stopped, Z a zombie, I being created, ? anything else.
|
|
* NetBSD: sysctl(3) KERN_PROC2, the way libkvm and ps(1) ask; Linux: /proc.
|
|
* *OUT is malloc'd (free(3)), also when *N is 0. A process that ends while
|
|
* the list is made is left out.
|
|
*/
|
|
typedef struct {
|
|
long pid, ppid;
|
|
unsigned long uid;
|
|
char user[32]; /* the login name, or the number */
|
|
char comm[32]; /* the name of the command */
|
|
char state;
|
|
int nlwp; /* threads */
|
|
unsigned long long rss; /* real memory in use, bytes */
|
|
unsigned long long vsz; /* virtual memory, bytes */
|
|
unsigned long long cpu_ms;
|
|
} McdeSysProcess;
|
|
|
|
int mcde_sys_processes(McdeSysProcess **out, size_t *n);
|
|
|
|
/*
|
|
* The load of the computer, for the activity window (t0091).
|
|
*
|
|
* mcde_sys_cpu_times: one McdeSysCpu for each processor. The numbers are the
|
|
* ticks each state has had since the system started, all of one length: only
|
|
* the proportions between two readings mean something (the share of "user" in
|
|
* the ticks that passed is "% User"). "other" is what is neither of the four
|
|
* (NetBSD: interrupts; Linux: waiting for the disk, interrupts, time stolen by
|
|
* a hypervisor). NetBSD: sysctl kern.cp_time with room for every CPU
|
|
* (sys/kern/init_sysctl.c); Linux: /proc/stat. *OUT is malloc'd (free(3)).
|
|
*
|
|
* mcde_sys_memory: bytes. "free" is not used at all; "cached" is what the
|
|
* system keeps from files and gives back when a program wants it (counted as
|
|
* available); "used" is the rest, what programs and the kernel really hold:
|
|
* total = free + cached + used. Swap in use and in all. NetBSD: sysctl
|
|
* vm.uvmexp2 (as top(1) reads it); Linux: /proc/meminfo.
|
|
*/
|
|
typedef struct {
|
|
unsigned long long user, nice, system, idle, other;
|
|
} McdeSysCpu;
|
|
|
|
int mcde_sys_cpu_times(McdeSysCpu **out, size_t *n);
|
|
|
|
typedef struct {
|
|
unsigned long long total, free, cached, used;
|
|
unsigned long long swap_total, swap_used;
|
|
} McdeSysMemory;
|
|
|
|
int mcde_sys_memory(McdeSysMemory *m);
|
|
|
|
/*
|
|
* What went over the network and the disks since the system started, for the
|
|
* Network and Disk Activity tabs: the difference of two readings, divided by
|
|
* the seconds between them, is the rate. One entry for each interface (the
|
|
* loopback too; the window may leave it out) and for each whole disk (not its
|
|
* partitions; not loop, ram or zram devices). Bytes and operations (a read or
|
|
* a write the disk completed); *OUT is malloc'd (free(3)), NULL when *N is 0.
|
|
* NetBSD: getifaddrs(3) link data, and sysctl hw.iostats (usr.bin/vmstat/
|
|
* drvstats.c, type IOSTAT_DISK); Linux: /proc/net/dev and /proc/diskstats
|
|
* (a sector is 512 bytes there).
|
|
*/
|
|
typedef struct {
|
|
char name[32];
|
|
unsigned long long rx_bytes, tx_bytes, rx_packets, tx_packets;
|
|
} McdeSysNetIo;
|
|
|
|
int mcde_sys_net_io(McdeSysNetIo **out, size_t *n);
|
|
|
|
typedef struct {
|
|
char name[32];
|
|
unsigned long long read_bytes, write_bytes, read_ops, write_ops;
|
|
} McdeSysDiskIo;
|
|
|
|
int mcde_sys_disk_io(McdeSysDiskIo **out, size_t *n);
|
|
|
|
/*
|
|
* Ends or stops a process (the activity window's Quit Process). Only these
|
|
* signals, and only a process of its own: PID must be above 1 -- never init,
|
|
* never "all my processes" or a group (kill(2) with 0 or a negative number).
|
|
* MCDE_SYS_EPERM when it is another user's (the system's answer), MCDE_SYS_ENOENT
|
|
* when there is no such process.
|
|
*/
|
|
typedef enum {
|
|
MCDE_SIGNAL_TERM, MCDE_SIGNAL_KILL, MCDE_SIGNAL_STOP,
|
|
MCDE_SIGNAL_CONT, MCDE_SIGNAL_HUP, MCDE_SIGNAL_INT
|
|
} McdeSysSignal;
|
|
|
|
int mcde_sys_signal(long pid, McdeSysSignal sig);
|
|
|
|
/*
|
|
* A file's comment and its lock, as the Info window of the file manager
|
|
* shows them. The comment is an extended attribute in the user namespace
|
|
* (user.mcde.comment on Linux, mcde.comment in EXTATTR_NAMESPACE_USER on
|
|
* NetBSD); an empty TEXT removes it; MCDE_SYS_ENOTSUP when the file system
|
|
* has no extended attributes. The lock is the immutable flag
|
|
* (FS_IMMUTABLE_FL on Linux, chflags(2) UF_IMMUTABLE on NetBSD).
|
|
*/
|
|
int mcde_sys_file_comment_get(const char *path, char *buf, size_t len);
|
|
int mcde_sys_file_comment_set(const char *path, const char *text);
|
|
int mcde_sys_file_locked_get(const char *path, int *locked);
|
|
int mcde_sys_file_locked_set(const char *path, int locked);
|
|
|
|
/*
|
|
* The time: the system's time service (NetBSD's ntpd from the base system
|
|
* through rc.conf and ntp.conf, on Linux systemd-timesyncd through
|
|
* timedatectl(1)), and the clock itself (settimeofday(2), root only).
|
|
*/
|
|
int mcde_sys_ntp_get(int *on, char *server, size_t len);
|
|
int mcde_sys_ntp_set(int on, const char *server);
|
|
int mcde_sys_time_set(time_t when);
|
|
|
|
/*
|
|
* Device events
|
|
*
|
|
* A medium inserted or removed is an event, not something to ask for in a
|
|
* loop: mcde_sys_disk_events() gives a non-blocking descriptor that is
|
|
* readable when the kernel reports a device change, so a program can hand it
|
|
* to XtAppAddInput and read it there (Linux: the kernel's uevent socket;
|
|
* NetBSD: drvctl(4) with DRVGETEVENT). The caller owns the descriptor and
|
|
* closes it. What a descriptor gives is read with
|
|
* mcde_sys_disk_event_read(): it never blocks, returns 1 when it put one
|
|
* event into BUF (a line, "event device"), 0 when nothing is queued and -1
|
|
* on an error (mcde_sys_error() says which). Linux keeps the kernel's text,
|
|
* NetBSD turns the property list into the same "device-attach sd0" line;
|
|
* the call is what the programs read, never read(2) alone, because NetBSD's
|
|
* events come as an ioctl on the descriptor.
|
|
*/
|
|
int mcde_sys_disk_events(void);
|
|
int mcde_sys_disk_event_read(int fd, char *buf, size_t len);
|
|
/* what an event says: ACTION and DEVICE (Linux "remove" and "sdb1",
|
|
* NetBSD "detach" and "sd0"). Returns 1 when the device went away, 0 for
|
|
* another event, -1 on bad arguments. */
|
|
int mcde_sys_disk_event_info(const char *event, char *action, size_t alen,
|
|
char *device, size_t dlen);
|
|
|
|
/*
|
|
* Logs
|
|
*
|
|
* The logs a person looks at without a terminal: the session's own
|
|
* (CDE's ~/.dt/errorlog and ~/.dt/startlog) and the system's files under
|
|
* /var/log. A log that cannot be read is listed as such (root would be
|
|
* needed); watching a file gives a descriptor that becomes readable when the
|
|
* file grows -- inotify on Linux, kqueue on NetBSD (the latter is the
|
|
* follow-up), never a timer.
|
|
*/
|
|
#define MCDE_SYS_LOG_NAME 96
|
|
#define MCDE_SYS_LOG_PATH 256
|
|
|
|
typedef struct {
|
|
char name[MCDE_SYS_LOG_NAME];
|
|
char path[MCDE_SYS_LOG_PATH];
|
|
int readable; /* the user may read it */
|
|
} McdeSysLog;
|
|
|
|
/* the logs on this computer; the count */
|
|
int mcde_sys_logs(McdeSysLog *list, size_t max);
|
|
/* a descriptor that is readable when PATH grows (MCDE_SYS_ENOTSUP where
|
|
* the system has no way to watch a file) */
|
|
int mcde_sys_log_watch(const char *path);
|
|
/* the last LINE lines of PATH (at most LEN-1 bytes) into BUF; 0 or -1 */
|
|
int mcde_sys_log_tail(const char *path, int lines, char *buf, size_t len);
|
|
|
|
/*
|
|
* Printers (CUPS)
|
|
*
|
|
* The queue list comes from libcups's cupsGetDests(3) -- loaded at run time,
|
|
* so a host without the CUPS development files still builds -- and the
|
|
* printers found on the network from mDNS (_ipp._tcp, avahi-browse(1) on
|
|
* Linux, DNS-SD on NetBSD: the latter is a follow-up). Creating or deleting
|
|
* a queue and setting the default need the administrator: the pane runs the
|
|
* command in a terminal where su(1) asks (dtsystemsettings -add-printer ...,
|
|
* -set-default-printer ...).
|
|
*/
|
|
#define MCDE_SYS_PRINTER_NAME 96
|
|
#define MCDE_SYS_PRINTER_TEXT 160
|
|
#define MCDE_SYS_PRINTER_URI 256
|
|
|
|
typedef struct {
|
|
char name[MCDE_SYS_PRINTER_NAME];
|
|
char state[MCDE_SYS_PRINTER_TEXT]; /* "idle", "processing", a
|
|
* stopped printer's reason */
|
|
char location[MCDE_SYS_PRINTER_TEXT];
|
|
char info[MCDE_SYS_PRINTER_TEXT]; /* the model/make */
|
|
int is_default;
|
|
int shared;
|
|
int accepting; /* printer-accepting-jobs */
|
|
} McdeSysPrinter;
|
|
|
|
/* the queues CUPS knows; the count, MCDE_SYS_ENOTSUP without libcups */
|
|
int mcde_sys_printers(McdeSysPrinter *list, size_t max);
|
|
/* the default queue for new jobs (root: needs the administrator) */
|
|
int mcde_sys_printer_default(const char *name);
|
|
|
|
/* Spool PATH to PRINTER (NULL or "" = the default queue) with lp(1), as a
|
|
* job for the event loop (mcde_sys_job_fd/_finish/_cancel). MCDE_PRINT_COMMAND
|
|
* names the tool instead, for tests with a fake lp. */
|
|
McdeSysJob *mcde_sys_print_file(const char *path, const char *printer);
|
|
|
|
/* a queue for URI with the driverless model (lpadmin -p NAME -E -v URI -m
|
|
* everywhere); root, a name without spaces or slashes, an ipp:// URI */
|
|
int mcde_sys_printer_add(const char *name, const char *uri);
|
|
/* take the queue NAME away (lpadmin -x; root) */
|
|
int mcde_sys_printer_remove(const char *name);
|
|
|
|
/* the printers found with mDNS: a display name and its ipp:// URI each;
|
|
* the count, MCDE_SYS_ENOTSUP where the system has no mDNS browser */
|
|
int mcde_sys_printers_discovered(char (*names)[MCDE_SYS_PRINTER_TEXT],
|
|
char (*uris)[MCDE_SYS_PRINTER_URI], size_t max);
|
|
|
|
/*
|
|
* Security
|
|
*
|
|
* Secure virtual memory is NetBSD's vm.swap_encrypt: the swap's pages are
|
|
* encrypted with a key in memory, so a powered-off disk does not show them.
|
|
* cgd(4) is NetBSD's encrypted disk; its volumes are listed in
|
|
* /etc/cgd/cgd.conf, and encrypting one is an install-time (sysinst)
|
|
* decision, not something a running system does. The packet filter is
|
|
* NetBSD's npf(7), configured in /etc/npf.conf and started by rc.conf's
|
|
* npf=YES; these functions read its state only.
|
|
*/
|
|
#define MCDE_SYS_CGD_ENTRY_LEN 192
|
|
|
|
/* 1 or 0 into ON: whether memory is encrypted in swap; MCDE_SYS_ENOTSUP on
|
|
* a system without vm.swap_encrypt */
|
|
int mcde_sys_swap_encrypt_get(int *on);
|
|
/* set it now and in /etc/sysctl.conf, for after the next start (root) */
|
|
int mcde_sys_swap_encrypt_set(int on);
|
|
/* the cgd(4) volumes as /etc/cgd/cgd.conf lists them ("wd0d /etc/cgd/wd0d"
|
|
* a line) into VOLS; the count, MCDE_SYS_ENOTSUP without cgd */
|
|
int mcde_sys_cgd_volumes(char (*vols)[MCDE_SYS_CGD_ENTRY_LEN], size_t max);
|
|
/* the packet filter's state: 1 on, 0 off into ON, its configuration file
|
|
* into CONF; MCDE_SYS_ENOTSUP on a system without npf */
|
|
int mcde_sys_firewall_get(int *on, char *conf, size_t len);
|
|
|
|
/*
|
|
* The time zone: names as the tz database has them ("Europe/Lisbon").
|
|
* /etc/localtime is a symbolic link into /usr/share/zoneinfo on NetBSD and
|
|
* on Linux alike (sysinst sets it so: src/usr.sbin/sysinst/util.c); the
|
|
* zones offered are the ones of zone1970.tab.
|
|
*/
|
|
#define MCDE_SYS_ZONE_LEN 64
|
|
/* the zone in use, "UTC" when none is set */
|
|
int mcde_sys_timezone_get(char *zone, size_t len);
|
|
/* up to MAX zones, sorted; how many */
|
|
int mcde_sys_timezones(char (*zones)[MCDE_SYS_ZONE_LEN], size_t max);
|
|
/* now and at boot (root); a running program sees it at its next tzset(3) */
|
|
int mcde_sys_timezone_set(const char *zone);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif /* _Mcde_McdeSys_h */
|